function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function eliminaEspacios(cadena)
{
	// Funcion para eliminar espacios delante y detras de cada cadena
	while(cadena.charAt(cadena.length-1)==" ") cadena=cadena.substr(0, cadena.length-1);
	while(cadena.charAt(0)==" ") cadena=cadena.substr(1, cadena.length-1);
	return cadena;
}

function validaIngreso(valor)
{
	/* Funcion encargada de validar lo ingresado por el usuario. Se devuelve TRUE en caso de ser 
	valido, FALSE en caso contrario */
/*	var reg=/(^[a-zA-Z0-9.@ ]{4,40}$)/;
	if(reg.test(valor)) return true;
	else return false;
*/	
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (valor.length == 0 ) return true;
	if (filter.test(valor))
		return true;
	else
		//alert("Ingrese una dirección de correo válida");
		return false;
}



function actualizar2(){
	window.parent.top.location.reload(); 
//	window.opener.parent.top.location.reload(); 
}

function suscripcionboletin(evento)
{
	var divMensaje=document.getElementById("mensaje");

	/* Dependiendo de cual sea el evento que ejecuto esta funcion (ingreso o verificacion) se setean
	distintas variables */	
	if(evento=="ingreso")
	{
		var input=document.getElementById("ingreso");
		var boton=document.getElementById("boton_1");
		var valor=input.value;
		var accion="Procesando...";
	}
/*	else
	{
		var input=document.getElementById("verificacion");
		var boton=document.getElementById("boton_2");
		var valor=input.value;
		var accion="Comprobando...";
	}
	*/
	// Elimino espacios por delante y detras de lo ingresado por el usuario
	valor=eliminaEspacios(valor);
	// Si el ingreso es invalido...
	if(!validaIngreso(valor)) 
	{
		divMensaje.innerHTML="E-mail ingresado incorrecto";
	}
	else
	{
		// Deshabilito inputs y botones para evitar dobles ingresos
//		boton.disabled=true; input.disabled=true;
		input.value=accion;
		
		var ajax=nuevoAjax();
		ajax.open("POST", "boletinproceso.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(evento+"="+valor);
		
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4)
			{
				// Habilito nuevamente botones e inputs
				input.value="";
				//boton.disabled=false; input.disabled=false;
				// Muestro el mensaje enviado desde el servidor
				divMensaje.innerHTML=ajax.responseText;
			}
		}
	}
}

function irA(url){ 
 document.location.href = url; 
}

function cargaContenido()
{
	var valor=document.getElementById("select_0").options[document.getElementById("select_0").selectedIndex].value;
	if(valor==0)
	{
		// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo todo por defecto
		combo=document.getElementById("select_1");
		combo.length=0;
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar Evento...";
		combo.appendChild(nuevaOpcion);	combo.disabled=true;
	}
	else
	{
		ajax=nuevoAjax();
		ajax.open("GET", "buscar_descarga.php?seleccionado="+valor, true);
		//ajax.open("GET", "establecimientoscarne.php?seleccionado="+valor, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				combo=document.getElementById("select_1");
				combo.length=0;
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
				combo.appendChild(nuevaOpcion); combo.disabled=true;	
			}
			if (ajax.readyState==4)
			{ 
				document.getElementById("fila_2").innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}
}

////////////// form pacientes //////////////////



function cargaform_datos_prueba()
{
	var v_nombre=document.form.f_nombre.value;
	var v_edad = document.form.f_edad.value;
	//var v_sexo = document.form.f_sexo.value;
	var v_domicilio = document.form.f_domicilio.value;
	var v_localidad = document.form.f_localidad.value;
	var v_provincia=document.form.f_provincia.value;
	var v_pais = document.form.f_pais.value;
	var v_email  = document.form.f_email.value;
	var v_telefono = document.form.f_telefono.value;
	var v_consulta =document.form.f_consulta.value;
	var tmptxt =document.form.tmptxt.value;
	var action =document.form.action.value;

	

	for(i=0;i<2;i++){
	    if(document.form.f_sexo[i].checked)
		{
		var v_sexo =document.form.f_sexo[i].value;
		}
	}
	
	
	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_edad=="") 
	{ 
		alert("El campo Edad esta vacio");
		document.form.f_edad.focus();
	}else if(v_localidad=="") 
	{ 
		alert("El campo Localidad esta vacio");
		document.form.f_localidad.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(tmptxt == "") 
	{ 
		alert("El Codigo de control esta vacio");
		document.form.tmptxt.focus();
	}
	else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_pacientes_prueba.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_edad="+v_edad+"&v_sexo="+v_sexo+"&v_domicilio="+v_domicilio+"&v_localidad="+v_localidad+"&v_provincia="+v_provincia+"&v_pais="+v_pais+"&v_email="+v_email+"&v_telefono="+v_telefono+"&v_consulta="+v_consulta+"&tmptxt="+tmptxt+"&action="+action)

	}
}



//////////////// compartir news /////////////////////


function cargaform_compartir()
{
	var v_nombre=document.form.f_nombre.value;
	var v_email  = document.form.f_email.value;
	
	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}
	else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_compartir.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_email="+v_email)
	}
}


//////////////////////////////////////////////


function cargaform_datos()
{
	var v_nombre=document.form.f_nombre.value;
	var v_edad = document.form.f_edad.value;
	//var v_sexo = document.form.f_sexo.value;
	var v_domicilio = document.form.f_domicilio.value;
	var v_localidad = document.form.f_localidad.value;
	var v_provincia=document.form.f_provincia.value;
	var v_pais = document.form.f_pais.value;
	var v_email  = document.form.f_email.value;
	var v_telefono = document.form.f_telefono.value;
	var v_consulta =document.form.f_consulta.value;
	//var tmptxt =document.form.tmptxt.value;
	//var action =document.form.action.value;
	
/*	alert(v_nombre);
	alert(v_edad);
	*/
	//alert(tmptxt+" - "+action);
	
	for(i=0;i<2;i++){
	    if(document.form.f_sexo[i].checked)
		{
		var v_sexo =document.form.f_sexo[i].value;
		}
	}
	

	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_edad=="") 
	{ 
		alert("El campo Edad esta vacio");
		document.form.f_edad.focus();
	}else if(v_localidad=="") 
	{ 
		alert("El campo Localidad esta vacio");
		document.form.f_localidad.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}
	
/*	else if(tmptxt == "") 
	{ 
		alert("El Codigo de control esta vacio");
		document.form.tmptxt.focus();
	}else if(tmptxt != action) 
	{ 
		alert("El Codigo de control es incorrecto");
		document.form.tmptxt.focus();
	}*/
	else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_pacientes.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_edad="+v_edad+"&v_sexo="+v_sexo+"&v_domicilio="+v_domicilio+"&v_localidad="+v_localidad+"&v_provincia="+v_provincia+"&v_pais="+v_pais+"&v_email="+v_email+"&v_telefono="+v_telefono+"&v_consulta="+v_consulta)
		//+"&tmptxt="+tmptxt+"&action="+action
	}
}



////////////// form turnos //////////////////

function cargaform_turnos(sid,div)
{
	var v_nombre=document.form.f_nombre.value;
	var v_edad = document.form.f_edad.value;
	var v_unidad = document.form.f_unidad.value;
	var v_medico = document.form.f_medico.value;
	var v_fecha_comienzo=document.form.f_fecha_comienzo.value;
	var v_causa = document.form.f_causa.value;
	var v_numhd = document.form.f_numhd.value;
	var v_fecha_primera =document.form.f_fecha_primera.value;
	var v_tel = document.form.f_tel.value;
	var v_mail = document.form.f_mail.value;	
/*
	alert("v_nombre : "+v_nombre);
	alert("v_edad : "+v_edad);
	alert("v_unidad : "+v_unidad);
	alert("v_medico : "+v_medico);
	
	alert("v_fecha_comienzo : "+v_fecha_comienzo);
	alert("v_causa : "+v_causa);
	alert("v_numhd : "+v_numhd);
	alert("v_fecha_primera : "+v_fecha_primera);

*/
	for(i=0;i<2;i++){
	    if(document.form.f_sexo[i].checked)
		{
		var v_sexo =document.form.f_sexo[i].value;
		}
	}

	for(x=0;x<4;x++){
	    if(document.form.f_motivo[x].checked)
		{
		var v_motivo =document.form.f_motivo[x].value;
		}
	}
	var v_dias2=0;
	for(j=0;j<2;j++){
	    if(document.form.f_dias[j].checked)
		{
		var v_dias =document.form.f_dias[j].value;
		var v_dias2=1;
		}
	}
	var v_turno2=0;
	for(t=0;t<3;t++){
	    if(document.form.f_turno[t].checked)
		{
		var v_turno =document.form.f_turno[t].value;	
		v_turno2=1;
		}
	}
	
	for(y=0;y<4;y++){
	    if(document.form.f_serologia[y].checked)
		{
		var v_serologia =document.form.f_serologia[y].value;
		}
	}
	
	//var v_serologia =document.form.f_serologia.value;
	//alert("f_serologia : "+v_serologia)
	
	/*
	alert("v_sexo : "+v_sexo);	
	alert("v_motivo : "+v_motivo);	
	alert("v_dias : "+v_dias);	
	alert("v_turno : "+v_turno);
	*/
	valor=eliminaEspacios(v_nombre);
	
	
	
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_dias2==0){	
		alert("Ingrese los dias de tratamiento");
		//document.form.f_dias.focus();		
	}else if(v_turno2==0){	
		alert("Ingrese el horario preferido");
		//document.form.f_turno.focus();		
	}else if(v_mail=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_mail.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_mail))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_mail.focus();
	}else if(v_mail.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_mail.focus();
	}else{
		ajax=nuevoAjax();
		ajax.open("POST", "enviar_turno.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById(div).innerHTML = ajax.responseText;
				 alert("Se ha registrado con éxito");
                 document.getElementById(div).style.display="block";
	 		}else{
				document.getElementById(div).style.display="block";
				document.getElementById(div).innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_edad="+v_edad+"&v_sexo="+v_sexo+"&v_unidad="+v_unidad+"&v_medico="+v_medico+"&v_fecha_comienzo="+v_fecha_comienzo+"&v_causa="+v_causa+"&v_numhd="+v_numhd+"&v_fecha_primera="+v_fecha_primera+"&v_sexo="+v_sexo+"&v_motivo="+v_motivo+"&v_dias="+v_dias+"&v_turno="+v_turno+"&v_serologia="+v_serologia+"&v_tel="+v_tel+"&v_mail="+v_mail)
	}
}


function cargaform_turnos2(sid,div)
{
	var v_nombre=document.form.f_nombre.value;
	var v_mail = document.form.f_mail.value;
	var v_tel = document.form.f_tel.value;
	var v_domicilio = document.form.f_domicilio.value;
	var v_ciudad = document.form.f_ciudad.value;
	var v_pcia = document.form.f_pcia.value;
	var v_pais = document.form.f_pais.value;	
	var v_edad = document.form.f_edad.value;

	/*  Sexo  */
	for(i=0;i<2;i++){
	    if(document.form.f_sexo[i].checked)
		{
		var v_sexo =document.form.f_sexo[i].value;
		}
	}
	
	var v_obra = document.form.f_obra.value;
	var v_unidad = document.form.f_unidad.value;
	var v_medico = document.form.f_medico.value;
	var v_fecha_comienzo=document.form.f_fecha_comienzo.value;
	var v_causa = document.form.f_causa.value;
	
	/*  Motivo  */
	for(x=0;x<4;x++){
	    if(document.form.f_motivo[x].checked)
		{
		var v_motivo =document.form.f_motivo[x].value;
		}
	}
	
	
	var v_numhd = document.form.f_numhd.value;
	//alert(v_numhd);
	/*  Dias  */
	var v_dias2=0;
	for(j=0;j<2;j++){
	    if(document.form.f_dias[j].checked)
		{
		var v_dias =document.form.f_dias[j].value;
		var v_dias2=1;
		}
	}
	
	/*  Turno  */
	var v_turno2=0;
	for(t=0;t<3;t++){
	    if(document.form.f_turno[t].checked)
		{
		var v_turno =document.form.f_turno[t].value;	
		v_turno2=1;
		}		
	}
	var v_fecha_primera =document.form.f_fecha_primera.value;			
		
	/*  Serología   */
	if (document.form.f_HepaC.checked==true)
	{
		//alert("checkbox Seleccionado")
		var v_HepaC=1;
		var v_HepaCmm = document.form.f_HepaCmm.value;		
		//alert(v_HepaCmm);
		
	} else 
	{
		var f_HepaC=2;
		//alert("checkbox NO seleccionado")	
	}
	
	if (document.form.f_HepaB.checked==true)
	{
		//alert("checkbox Seleccionado")
		var v_HepaB=1;
		var v_HepaBmm = document.form.f_HepaBmm.value;		
		//alert(v_HepaBmm);
		
	} else 
	{
		//alert("checkbox NO seleccionado")	
		var v_HepaB=2;		
	}
	
	if (document.form.f_Hyv.checked==true)
	{
		//alert("checkbox Seleccionado")
		var v_Hyv=1;
		var v_Hyvmm = document.form.f_Hyvmm.value;		
		//alert(v_Hyvmm);
		
	} else 
	{
		var v_Hyv=2;		
		//alert("checkbox NO seleccionado")	
	}		

	if (document.form.f_ninguno.checked==true)
	{
		//alert("Ninguno")
		var v_ninguno=1;	
		
	} else 
	{
		var v_ninguno=2;		
		//alert("Alguno")	
	}	
	
	v_nombre=eliminaEspacios(v_nombre);
	v_domicilio=eliminaEspacios(v_domicilio);
	v_ciudad=eliminaEspacios(v_ciudad);
	v_pcia=eliminaEspacios(v_pcia);
	v_pais=eliminaEspacios(v_pais);
	
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_domicilio==""){	
		alert("Ingrese su Domicilio");
		document.form.f_domicilio.focus();		
	}else if(v_ciudad==""){	
		alert("Ingrese su ciudad");
		document.form.f_ciudad.focus();		
	}else if(v_pcia==""){	
		alert("Ingrese su pais");
		document.form.f_pcia.focus();		
	}else if(v_pais==""){	
		alert("Ingrese su pais");
		document.form.f_pais.focus();		
	}else if(v_tel==""){	
		alert("Ingrese su numero telefónico o de un contacto");
		document.form.f_tel.focus();		
	}else if(v_dias2==0){	
		alert("Ingrese los dias de tratamiento");
		document.form.f_dias.focus();		
	}else if(v_turno2==0){	
		alert("Ingrese el horario preferido");
		document.form.f_turno.focus();		
	}else if(v_mail=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_mail.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_mail))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_mail.focus();
	}else if(v_mail.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_mail.focus();
	}else if(v_fecha_primera=="")	
	{	
		alert("fecha vacia");
		document.form.v_fecha_primera.focus();
	}else{
		ajax=nuevoAjax();
		ajax.open("POST", "enviar_turno_hemo.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById(div).innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById(div).innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_mail="+v_mail+"&v_tel="+v_tel+"&v_domicilio="+v_domicilio+"&v_ciudad="+v_ciudad+"&v_pcia="+v_pcia+"&v_pais="+v_pais+"&v_edad="+v_edad+"&v_sexo="+v_sexo+"&v_obra="+v_obra+"&v_unidad="+v_unidad+"&v_medico="+v_medico+"&v_fecha_comienzo="+v_fecha_comienzo+"&v_causa="+v_causa+"&v_motivo="+v_motivo+"&v_numhd="+v_numhd+"&v_dias="+v_dias+"&v_turno="+v_turno+"&v_fecha_primera="+v_fecha_primera+"&v_HepaC="+v_HepaC+"&v_HepaCmm="+v_HepaCmm+"&v_HepaB="+v_HepaB+"&v_HepaBmm="+v_HepaBmm+"&v_Hyv="+v_Hyv+"&v_Hyvmm="+v_Hyvmm+"&v_ninguno="+v_ninguno )
	}
}



////////////// form profesionales //////////////////

function cargaform_datosProf()
{
	var v_nombre = document.form.f_nombre.value;
	var v_especialidad = document.form.f_especialidad.value;
	var v_lugartrabajo = document.form.f_lugartrabajo.value;
	var v_domicilio = document.form.f_domicilio.value;
	var v_localidad = document.form.f_localidad.value;
	var v_provincia=document.form.f_provincia.value;
	var v_pais = document.form.f_pais.value;
	var v_email  = document.form.f_email.value;
	var v_telefono = document.form.f_telefono.value;
	var v_consulta =document.form.f_consulta.value;
//	var tmptxt =document.form.tmptxt.value;
//	var action =document.form.action.value;
	
	
	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_localidad=="") 
	{ 
		alert("El campo Localidad esta vacio");
		document.form.f_localidad.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	/*}else if(tmptxt == "") 
	{ 
		alert("El Codigo de control esta vacio");
		document.form.tmptxt.focus();
	}else if(tmptxt != action) 
	{ 
		alert("El Codigo de control es incorrecto");
		document.form.tmptxt.focus();*/
	}else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_profesioanles.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_especialidad="+v_especialidad+"&v_lugartrabajo="+v_lugartrabajo+"&v_domicilio="+v_domicilio+"&v_localidad="+v_localidad+"&v_provincia="+v_provincia+"&v_pais="+v_pais+"&v_email="+v_email+"&v_telefono="+v_telefono+"&v_consulta="+v_consulta)
		//+"&tmptxt="+tmptxt+"&action="+action
		
	}
}


////////////// form contacto //////////////////

function cargaform_datosCont()
{
	var v_nombre = document.form.f_nombre.value;
	var v_email  = document.form.f_email.value;
	var v_telefono = document.form.f_telefono.value;
	var v_consulta =document.form.f_consulta.value;
	
	valor=eliminaEspacios(v_nombre);
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_email=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_contactos.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_email="+v_email+"&v_telefono="+v_telefono+"&v_consulta="+v_consulta)
	}
}

////////////// form inscripcion ////////////////////



function cargaform_datosinscp()
{
	var v_apellidos = document.form.f_apellidos.value;
	var v_nombres = document.form.f_nombres.value;
	var v_direccion = document.form.f_direccion.value;
	var v_cpostal = document.form.f_cpostal.value;	
	var v_localidad = document.form.f_localidad.value;
	var v_provincia = document.form.f_provincia.value;
	var v_pais = document.form.f_pais.value;
	var v_institucion = document.form.f_institucion.value;
	var v_especialidad = document.form.f_especialidad.value;
	var v_telefono = document.form.f_telefono.value;
	var v_email  = document.form.f_email.value;
/*
	alert(v_apellidos);
	alert(v_nombres);
	alert(v_direccion);
	alert(v_cpostal);
	alert(v_localidad);
	alert(v_provincia);
	alert(v_pais);
	alert(v_institucion);
	alert(v_especialidad);
	alert(v_telefono);
	alert(v_email);	
	*/
	v_apellidos=eliminaEspacios(v_apellidos);
	v_nombres=eliminaEspacios(v_nombres);
	v_email=eliminaEspacios(v_email);	
	if(v_apellidos=="") 
	{ 
		alert("Ingrese su Apellido");
		document.form.f_apellidos.focus();
	}else if(v_nombres=="") 
	{ 
		alert("Ingrese Nombre");
		document.form.f_nombres.focus();
	}else if(v_telefono=="") 
	{ 
		alert("Ingrese su Teléfono");
		document.form.f_telefono.focus();
	}else if(v_email=="") 
	{ 
		alert("Ingrese su Email");
		document.form.f_email.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_email))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_email.focus();
	}else if(v_email.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_email.focus();
	}else	
	{
		ajax=nuevoAjax();
		ajax.open("POST", "alta_form_inscripciones.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById('formulario').innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById("formulario").innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_apellidos="+v_apellidos+"&v_nombres="+v_nombres+"&v_direccion="+v_direccion+"&v_cpostal="+v_cpostal+"&v_localidad="+v_localidad+"&v_provincia="+v_provincia+"&v_pais="+v_pais+"&v_institucion="+v_institucion+"&v_especialidad="+v_especialidad+"&v_telefono="+v_telefono+"&v_email="+v_email)
	}
}


///// Noticias //////////////////


function cargafor_noticias(SID)
{
	var v_fecha=document.form.f_fecha.value;
	var v_categoria=document.form.f_categoria.value;
//	var v_titulo=document.form.f_titulo.value;	
	var v_titulo= parent.iframe_f_titulo.document.form_iframe.info3.value;	
//	var v_copete=document.form.f_copete2.value;
//	var v_copete= parent.iframe_f_copete2.document.form_iframe.info3.value;	
//	var v_texto=document.form.f_texto.value;
	var v_texto= parent.iframe_edit.document.form_iframe.info3.value;		
	var v_autor=document.form.f_autor.value;
	var v_url=document.form.f_url.value;
	var v_destacar=document.form.f_destacar.value;	
	var v_novedad=document.form.f_novedad.value;	
	var v_publicar=document.form.f_publicar.value;
//	alert(v_titulo);
	v_titulo = encodeURIComponent(v_titulo);
	v_copete = encodeURIComponent("vacio");
	v_texto = encodeURIComponent(v_texto);
	v_autor = encodeURIComponent(v_autor);
	v_url = encodeURIComponent(v_url);
	//alert(v_titulo);
	
	/*
	La solución es utilizar unicode:

\u00e1 -> á
\u00e9 -> é
\u00ed -> í
\u00f3 -> ó
\u00fa -> ú
\u00c1 -> Á
\u00c9 -> É
\u00cd -> Í
\u00d3 -> Ó
\u00da -> Ú
\u00f1 -> ñ
\u00d1 -> Ñ 
	*/
	
	if(v_titulo==""){
		alert("Debe colocar un t"+'\u00ed'+"tulo para la nota");
	}else{
		ajax=nuevoAjax();
		ajax.open("POST", "noticia_alta.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
     			 document.getElementById("error").style.display="none";				
				 document.getElementById("formulario").style.display="none";
				 document.getElementById("consulta").innerHTML = ajax.responseText;
 				 actualizar2();
				 
	 		}else{
				document.getElementById("error").style.display="none";
				document.getElementById("consulta").innerHTML = "<br><br><br><div align=center><br><br><br><div align=center><img src=indicator.gif width=16 height=16 /><br><p>Procesando</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(SID+"&v_fecha="+v_fecha+"&v_categoria="+v_categoria+"&v_titulo="+v_titulo+"&v_copete="+v_copete+"&v_texto="+v_texto+"&v_publicar="+v_publicar+"&v_destacar="+v_destacar+"&v_autor="+v_autor+"&v_url="+v_url+"&v_novedad="+v_novedad)
	}
}

function modificar_noticias(SID)
{

	var v_id=document.form.id.value;	
	var v_fecha=document.form.f_fecha.value;
	var v_categoria=document.form.f_categoria.value;
	//var v_titulo=document.form.f_titulo.value;
	var v_titulo= parent.iframe_f_titulo.document.form_iframe.info3.value;		
	//var v_copete=document.form.f_copete.value;
	//var v_copete= parent.iframe_f_copete.document.form_iframe.info3.value;	
//	var v_texto=document.form.f_texto.value;
	var v_texto= parent.iframe_edit.document.form_iframe.info3.value;	
	var v_autor=document.form.f_autor.value;
	var v_url=document.form.f_url.value;
	var v_destacar=document.form.f_destacar.value;		
	var v_novedad=document.form.f_novedad.value;			
	var v_publicar=document.form.f_publicar.value;

	//alert("copete : " + v_copete);
	//alert("texto : " + v_texto);	
	
	v_titulo = encodeURIComponent(v_titulo);
	v_copete = encodeURIComponent("vacio");
	v_texto = encodeURIComponent(v_texto);
	v_autor = encodeURIComponent(v_autor);
	v_url = encodeURIComponent(v_url);

		ajax=nuevoAjax();
		ajax.open("POST", "noticia_modi.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
     			 document.getElementById("error").style.display="none";				
				 document.getElementById("formulario").style.display="none";
				 document.getElementById("consulta").innerHTML = ajax.responseText;
				 actualizar2();
				 
	 		}else{
				document.getElementById("error").style.display="none";
				document.getElementById("consulta").innerHTML = "<br><br><br><div align=center><br><br><br><div align=center><img src=indicator.gif width=16 height=16 /><br><p>Procesando</p></div>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(SID+"&v_fecha="+v_fecha+"&v_categoria="+v_categoria+"&v_titulo="+v_titulo+"&v_copete="+v_copete+"&v_texto="+v_texto+"&v_publicar="+v_publicar+"&v_destacar="+v_destacar+"&v_autor="+v_autor+"&v_url="+v_url+"&v_id="+v_id+"&v_novedad="+v_novedad)
		
}


///////// Fin Noticias //////////////

function verformulario(div_name,valor,SID)
{
	if (valor==1)
	{
		document.getElementById(div_name).style.display="block";	
	}else{
		document.getElementById(div_name).style.display="none";
	}
}


//////////////////// Formulario /////////////////////////////


function carga_respuesta(SID, pregunta, respuesta, div, usuario)
{
	/*
	alert("preg : " + pregunta);
	alert("respuesta" + respuesta);
	alert("div" + div);		
	*/
	
		ajax=nuevoAjax();
		ajax.open("POST", "prueba.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				document.getElementById(div).innerHTML = ajax.responseText;				 
				actualizarR(SID, 'respuestas', usuario);
	 		}else{		
				document.getElementById(div).innerHTML = "<p><img src=img/indicador.gif width=100 height=9 alt=Guardando Respuesta /></p>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(SID+"&pregunta="+pregunta+"&respuesta="+respuesta+"&usuario="+usuario)
		
}



function borrar_respuesta(SID, id, div)
{
	alert("entro");
		ajax=nuevoAjax();
		ajax.open("POST", "borrar_respuesta.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				document.getElementById(div).innerHTML = ajax.responseText;				 
				//actualizarR(SID, 'respuestas', usuario);
				actualizar2();
	 		}else{		
				document.getElementById(div).innerHTML = "<p><img src=img/indicador.gif width=100 height=9 alt=Guardando Respuesta /></p>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(SID+"&v_Id_respuesta="+id)
		
}


function actualizarR(SID, div, usuario)
{	
		ajax=nuevoAjax();
		ajax.open("POST", "actualizar_respuestas.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				document.getElementById(div).innerHTML = ajax.responseText;
	 		}else{		
				document.getElementById(div).innerHTML = "<p><br><img src=img/indicador.gif width=100 height=9 alt=Actualizando /></p>";
			}	
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(SID+"&usuario="+usuario)
		
}

/////-------------------- libro 

function cargaform_turnos2(sid,div)
{
	var v_nombre=document.form.f_nombre.value;
	var v_mail = document.form.f_mail.value;
	var v_unidad = document.form.f_unidad.value;
	var v_tel = document.form.f_tel.value;
	var v_domicilio = document.form.f_domicilio.value;
	var v_ciudad = document.form.f_ciudad.value;
	var v_pcia = document.form.f_pcia.value;
	var v_pais = document.form.f_pais.value;
	var v_cantidad = document.form.f_cantidad.value;
	var v_pago = document.form.f_pago.value;
	var v_comentario = document.form.f_comentario.value;
	
	
	
	v_nombre=eliminaEspacios(v_nombre);
	v_unidad=eliminaEspacios(v_unidad);
	v_domicilio=eliminaEspacios(v_domicilio);
	v_ciudad=eliminaEspacios(v_ciudad);
	v_pcia=eliminaEspacios(v_pcia);
	v_pais=eliminaEspacios(v_pais);
	
	if(v_nombre=="") 
	{ 
		alert("El campo Nombre y Apellido esta vacio");
		document.form.f_nombre.focus();
	}else if(v_unidad==""){	
		alert("Ingrese su Unidad");
		document.form.F_unidad.focus();			
	}else if(v_domicilio==""){	
		alert("Ingrese su Domicilio");
		document.form.f_domicilio.focus();		
	}else if(v_ciudad==""){	
		alert("Ingrese su ciudad");
		document.form.f_ciudad.focus();		
	}else if(v_pcia==""){	
		alert("Ingrese su provincia");
		document.form.f_pcia.focus();		
	}else if(v_pais==""){	
		alert("Ingrese su pais");
		document.form.f_pais.focus();		
	}else if(v_cantidad < 10){	
		alert("Compra minima 10 unidades");
		document.form.f_pais.focus();		
	}else if(v_tel==""){	
		alert("Ingrese su numero telefónico o de un contacto");
		document.form.f_tel.focus();		
	}else if(v_mail=="") 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_mail.focus();
	}else if(!(/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test(v_mail))) 
	{	
		alert("El campo Email No es Correcto");
		document.form.f_mail.focus();
	}else if(v_mail.length == 0) 
	{ 
		alert("El campo Email esta vacio");
		document.form.f_mail.focus();
	}else{
		ajax=nuevoAjax();
		ajax.open("POST", "enviar_libro.php",true);
		ajax.onreadystatechange=function() 
		{
			if (ajax.readyState==4) 
			{
				 document.getElementById(div).innerHTML = ajax.responseText;
				 
	 		}else{
				document.getElementById(div).innerHTML = "<br><br><div align=center><img src=img/indicador.gif width=220 height=19 /><br><p class=txt_requerido>Procesando Datos</p></div>";
			}	
		}

	
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("v_nombre="+v_nombre+"&v_mail="+v_mail+"&v_unidad="+v_unidad+"&v_tel="+v_tel+"&v_domicilio="+v_domicilio+"&v_ciudad="+v_ciudad+"&v_pcia="+v_pcia+"&v_pais="+v_pais+"&v_cantidad="+v_cantidad+	"&v_pago="+v_pago+"&v_comentario="+v_comentario )
		}
}

