<!--
//***************************************************
//***************************************************
//FUNCIONES PERSONALIZADAS
function AbrirVentana(url, name, w, h, scrollsn) {	//funcion para abrir ventanas, reemplaza a JavaWindow
	window.open(url, name, 'width='+w+',height='+h+',scrollbars='+scrollsn);
}

function VeriContacto() {
	

	if (contacto.nombres.value!="") {
		if (contacto.apellidos.value!="") {
			if (contacto.rut.value!="") {
				if (contacto.telefono.value!="") {				
					if (contacto.e_mail.value!="") {	
						if ((contacto.e_mail.value.indexOf ('@',0) == -1 || contacto.e_mail.value.indexOf ('.',0) == -1) &&  contacto.e_mail.value != "")
 							{							
									alert('El email debe ser válido');
									contacto.e_mail.focus();													
										} else {									
										contacto.mailok.value="ok";
										contacto.submit();												
										}
							} else {
						alert("Por favor, escribe tu email");
						contacto.e_mail.focus();
					}
				} else {
					alert("Por favor, escribe tu teléfono");
					contacto.telefono.focus();
				}
			} else {
				alert("Por favor, escribe tu rut");
				contacto.rut.focus();
			}
		} else {
			alert("Por favor, escribe tus apellidos");
			contacto.apellidos.focus();
		}
	} else {
		alert("Por favor, escribe tus nombres");
		contacto.nombres.focus();
	}
}



function VeriMail() {
	if (document.getElementById("nombres").value!="") {
		if (document.getElementById("apellidos").value!="") {
			if (document.getElementById("rut").value!="") {
				if (document.getElementById("e_mail").value!="") {	
						if ((document.getElementById("e_mail").value.indexOf ('@',0) == -1 || document.getElementById("e_mail").value.indexOf ('.',0) == -1) &&  document.getElementById("e_mail").value != "")
 							{							
									alert('El email debe ser válido');
									document.getElementById("e_mail").focus();													
										} else {									
										document.getElementById("mailok").value="ok";
										document.getElementById("contacto").submit();												
										}
							} else {
						alert("Por favor, escribe tu email");
						document.getElementById("e_mail").focus();
					}
				
			} else {
				alert("Por favor, escribe tu rut");
				document.getElementById("rut").focus();
			}
		} else {
			alert("Por favor, escribe tus apellidos");
			document.getElementById("apellidos").focus();
		}
	} else {
		alert("Por favor, escribe tus nombres");
		document.getElementById("nombres").focus();
	}
}
//*************************************************************************************************
//*************************************************************************************************
//*************************************************************************************************
function VeriIngresa()
{
	frm = document.ingresa;
	if (frm.nombres.value == "") errmsg("Ingrese nombres", frm.nombres);
	else if (frm.apellido_paterno.value == "") errmsg("Ingrese apellido paterno", frm.apellido_paterno);
	else if (frm.apellido_materno.value == "") errmsg("Ingrese apellido materno", frm.apellido_materno);
	else if (!RunCheck(frm.rut.value)) errmsg("R.U.T. no valido", frm.rut);
	else if (frm.direccion.value == "") errmsg("Ingrese direccion", frm.direccion);
	else if (frm.actividad.value == "") errmsg("Ingrese profesion o actividad", frm.actividad);
	else if (!DateCheck(frm.fecha_nacimiento.value)) errmsg("Fecha de nacimiento no valida", frm.fecha_nacimiento);
	else if (frm.telefono.value == "") errmsg("Ingrese telefono", frm.telefono);
	else if (!EmailCheck(frm.mail.value)) errmsg("Email no valido", frm.email);
	else if (frm.tipo_diabetes.selectedIndex == 0) errmsg("Seleccione tipo de diabetes", frm.tipo_diabetes);
	else if (!frm.medicamentos_no.checked && frm.medicamentos_si.value == "") errmsg("Ingrese los medicamentos que usa para la diabetes", frm.medicamentos_si);
	else if (!frm.auge[0].checked && !frm.auge[1].checked) errmsg("Seleccione si es beneficiario de AUGE", frm.auge[0]);
	else if (!frm.prevision[0].checked && !frm.prevision[1].checked) errmsg("Seleccione prevision", frm.prevision[0]);
	else if (!frm.prevision[0].checked && frm.prevision[1].checked && frm.prevision_otra.value == "") errmsg("Ingrese ISAPRE", frm.prevision_otra);
	else if (!frm.insulina_no.checked && frm.insulina_si.value == "") errmsg("Ingrese la insulina que usa para la diabetes", frm.insulina_si);
	else if (!frm.monitor_roche[0].checked && !frm.monitor_roche[1].checked && !frm.monitor_roche[2].checked && !frm.monitor_roche[3].checked && frm.monitor_otro.value == "") errmsg("Seleccione monitor de autocontrol", frm.monitor_roche[0]);
	else if (frm.numero_serie.value == "") errmsg("Ingrese numero de serie de su monitor", frm.numero_serie);
	else if (frm.compro_accu.selectedIndex == 0) errmsg("Seleccione lugar de compra del monitor", frm.compro_accu);
	else if (frm.compro_accu.selectedIndex == 7 && frm.monitor_otro_lugar.value == "") errmsg("Ingrese lugar de compra del monitor", frm.monitor_otro_lugar);
	else if (frm.atiende_en.selectedIndex == 0) errmsg("Seleccione lugar donde se atiende", frm.atiende_en);
	else if (frm.frecuencia_glicemia.selectedIndex == 0) errmsg("Seleccione frecuencia en que se mide la glicemia", frm.frecuencia_glicemia);
	else if (!frm.condiciones.checked) errmsg("Debe leer y aceptar los terminos y condiciones", frm.condiciones);
	else frm.submit();
}

function errmsg(msg, obj)
{
	obj.focus();
	alert(msg);
}

function EmailCheck(email)
{
	var punto;
	var arroba;
	arroba = email.lastIndexOf("@");
	punto = email.lastIndexOf(".");
	if (punto < arroba)
	{
		return false
	}
	else
	{
		if (email.indexOf("@") != -1 && email.indexOf("@") != 0)
		{
			if (punto != -1)
			{
				if (punto < (email.length - 2) && punto > (email.length - 5))
				{
					return true
				}
				else
				{
					return false
				}
			}
			else
			{
				return false
			}
		}
		else
		{
			return false
		}
	}
}

function RunCheck(strRut)
{
	arrCheckDigit = new Array(11)
	arrCheckDigit[1] = "1"
	arrCheckDigit[2] = "2"
	arrCheckDigit[3] = "3"
	arrCheckDigit[4] = "4"
	arrCheckDigit[5] = "5"
	arrCheckDigit[6] = "6"
	arrCheckDigit[7] = "7"
	arrCheckDigit[8] = "8"
	arrCheckDigit[9] = "9"
	arrCheckDigit[10] = "K"
	arrCheckDigit[11] = "0"
	strRut = strRut.replace('.', '');
	strRut = strRut.replace('.', '');
	var intPos = strRut.search("-")
	intPos = intPos - 1;
	var intPonderador = new Number(2);
	var intSuma = new Number(0);
	if (intPos == strRut.length - 3)
	{
		for (i = intPos; i > -1; i--)
		{
			var strCharacter = strRut.charAt(i);
			if (strCharacter != "-")
			{
				var intCharacter = new Number(strCharacter);
				var intResto = intCharacter * intPonderador;
				intSuma = intSuma + intResto;
				if (intPonderador == 7)
				{
					intPonderador = 2;
				}
				else
				{
					intPonderador = intPonderador + 1;
				}
			}
		}
		var intAux = intSuma / 11;
		var strAux = String(intAux);
		var arrAux = strAux.split(".");
		intAux = Number(arrAux[0]);
		intAux = intAux * 11;
		intAux = intSuma - intAux;
		var intValorFinal = 11 - intAux;
		if (intSuma == 0)
		{
			return (false);
		}
		var strDigito = strRut.charAt(intPos + 2);
		strDigito = strDigito.toUpperCase();
		if (strDigito == arrCheckDigit[intValorFinal])
		{
			return (true);
		}
		else
		{
			return (false);
		}
	}
	else
	{
		return (false);
	}
}
//*************************************************************************************************
//*************************************************************************************************
//*************************************************************************************************
function FinalIngresa() {
	
	var datos_ingresa;
	datos_ingresa = window.document.datos_ingresa; 
	
	datos_ingresa.finalizar.value="ok";
	datos_ingresa.action = "ingresa_mail01.php";
	datos_ingresa.submit();
}

function VeriInscribe() {
	//inscribe.elements[0].focus();
	var cont2 = 0;
	for(i=0;i<document.inscribe.length-1;i++) {
		if (inscribe.elements[i].value!="") {
			cont2++;
		} else {
			alert("Por favor completa todos los campos");
			inscribe.elements[i].focus();
			break;
		}
	}
	if (cont2==11) {
		inscribe.mailok.value="ok";
		inscribe.action = "inscribe.php";
		inscribe.submit();
	}
}

function FinalInscribe() {
	datos_inscribe.finalizar.value="ok";
	datos_inscribe.action = "inscribe.php";
	datos_inscribe.submit();
}

function pedir_descarga(file_d) {
	document.descargar.archivo.value = file_d;
	document.descargar.submit();
}


//
// Validador de Rut
// Descargado desde http://juque.f2o.org/
//
function revisarDigito( dvr )
{	
	dv = dvr + ""	
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')	
	{		
		alert("Debe ingresar un digito verificador valido");		
		window.document.contacto.rut.focus();		
		window.document.contacto.rut.select();		
		return false;	
	}	
	return true;
}

function revisarDigito2( crut )
{	
	largo = crut.length;	
	if ( largo < 2 )	
	{		
		alert("Debe ingresar el rut completo")		
		window.document.contacto.rut.focus();		
		window.document.contacto.rut.select();		
		return false;	
	}	
	if ( largo > 2 )		
		rut = crut.substring(0, largo - 1);	
	else		
		rut = crut.charAt(0);	
	dv = crut.charAt(largo-1);	
	revisarDigito( dv );	

	if ( rut == null || dv == null )
		return 0	

	var dvr = '0'	
	suma = 0	
	mul  = 2	

	for (i= rut.length -1 ; i >= 0; i--)	
	{	
		suma = suma + rut.charAt(i) * mul		
		if (mul == 7)			
			mul = 2		
		else    			
			mul++	
	}	
	res = suma % 11	
	if (res==1)		
		dvr = 'k'	
	else if (res==0)		
		dvr = '0'	
	else	
	{		
		dvi = 11-res		
		dvr = dvi + ""	
	}
	if ( dvr != dv.toLowerCase() )	
	{		
		alert("EL rut es incorrecto")		
		window.document.contacto.rut.focus();		
		window.document.contacto.rut.select();		
		return false	
	}

	return true
}

function Rut(texto)
{	
	var tmpstr = "";	
	for ( i=0; i < texto.length ; i++ )		
		if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
			tmpstr = tmpstr + texto.charAt(i);	
	texto = tmpstr;	
	largo = texto.length;	

	if ( largo < 2 )	
	{		
		alert("Debe ingresar el rut completo")		
		window.document.contacto.rut.focus();		
		window.document.contacto.rut.select();		
		return false;	
	}	

	for (i=0; i < largo ; i++ )	
	{			
		if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
 		{			
			alert("El valor ingresado no corresponde a un R.U.T valido");			
			window.document.contacto.rut.focus();			
			window.document.contacto.rut.select();			
			return false;		
		}	
	}	

	var invertido = "";	
	for ( i=(largo-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + texto.charAt(i);	
	var dtexto = "";	
	dtexto = dtexto + invertido.charAt(0);	
	dtexto = dtexto + '-';	
	cnt = 0;	

	for ( i=1,j=2; i<largo; i++,j++ )	
	{		
		//alert("i=[" + i + "] j=[" + j +"]" );		
		if ( cnt == 3 )		
		{			
			dtexto = dtexto + '.';			
			j++;			
			dtexto = dtexto + invertido.charAt(i);			
			cnt = 1;		
		}		
		else		
		{				
			dtexto = dtexto + invertido.charAt(i);			
			cnt++;		
		}	
	}	

	invertido = "";	
	for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + dtexto.charAt(i);	

	window.document.contacto.rut.value = invertido.toUpperCase()		

	if ( revisarDigito2(texto) )		
		return true;	

	return false;
}




-->
