function activar_decimales(promedio)
{ 
	if(promedio.value!="")
	{
		var prom = parseInt(promedio.value);
		if(prom<10)
		{
			document.getElementById("prom2").disabled="";	
		}
		else
		{
			document.getElementById("prom2").disabled="disabled";
			document.getElementById("prom2").value="0";	
		}
		
		if(document.getElementById("prom2").value=="")
			document.getElementById("prom2").value="0";
	}
	else
	{
		document.getElementById("prom2").disabled="disabled";
		document.getElementById("prom2").value="";
	}
}

function fecha_valida(hoy)
{
	var ban=0;
	
	if(document.getElementById("dia").value!=""&&document.getElementById("mes").value!="")
	{
		if(document.getElementById("dia").value=="31")
		{
			if(document.getElementById("mes").value!="01"&&document.getElementById("mes").value!="03"&&document.getElementById("mes").value!="05"&&document.getElementById("mes").value!="07"&&document.getElementById("mes").value!="08"&&document.getElementById("mes").value!="10"&&document.getElementById("mes").value!="12")
			{
				ban=1;
				alert("Este mes tiene menos de 31 días, favor de rectificar el día.");
				document.getElementById("dia").focus();
				return(false);
			}
		}
		
		if(document.getElementById("mes").value=="02")
		{
			if(document.getElementById("dia").value=="30")
			{
				ban=1;
				alert("Este mes tiene menos de 30 días, favor de rectificar el día.");
				document.getElementById("dia").focus();
				return(false);
			}
			if(document.getElementById("anio").value!="")
			{
				if((parseInt(document.getElementById("anio").value)%4)!=0&&document.getElementById("dia").value=="29")
				{
					ban=1;
					alert("Este mes tiene menos de 29 días, favor de rectificar el día.");
					document.getElementById("dia").focus();
					return(false);
				}
			}
		}
		
		if(ban==0&&document.getElementById("dia").value!=""&&document.getElementById("mes").value!=""&&document.getElementById("anio").value!="")
		{
			var fecha_hoy= new String(hoy);
			var parte_fecha = fecha_hoy.split("/"); 	
			var edad;			
			if(parseInt(parte_fecha[0])>parseInt(document.getElementById("mes").value, 10))
			{
				edad = parseInt(parte_fecha[2]) - parseInt(document.getElementById("anio").value);
			}
			else
			{
				if(parseInt(parte_fecha[0])==parseInt(document.getElementById("mes").value, 10)&&parseInt(parte_fecha[1])>=parseInt(document.getElementById("dia").value))
				{
					edad = parseInt(parte_fecha[2]) - parseInt(document.getElementById("anio").value);
				}
				else
				{
					edad = parseInt(parte_fecha[2]) - parseInt(document.getElementById("anio").value);
					edad = edad -1;
				}
			}
			document.getElementById("edad").value = edad;
		}
	}
}

function validar_opcion(opciones)
{
	var ban=0;
	var y;
	
	if(opciones.plts.value==1)
	{
		if(opciones.plantel_opcion.checked==false)
		{
			alert("Selecciona el plantel de tu elección.");
			opciones.plantel_opcion.focus();
			return(false)
		}
	}
	else
	{
		for(y=0;y<opciones.plts.value;y++)
		{
			if(opciones.plantel_opcion[y].checked==false)
				ban = ban + 1;
		}
	
		if(ban==y)
		{
			alert("Selecciona el plantel de tu elección.");
			opciones.plantel_opcion[0].focus();
			return(false)
		}
	}
}

function validar_opcion_aspnuevo(forma)
{
	if(forma.plantelSELECCIONADO.value=="")	
	{
		alert("Favor de seleccionar alguna de las localidades disponibles.");
		return(false);
	}
}

function validar_consulta_solicitud()
{
	if(Trim(document.getElementById("fl").value)==""&&Trim(document.getElementById("nombre").value)==""&&Trim(document.getElementById("apP").value)=="")
	{
		alert("Para poder consultar el resultado tienes que ingresar el número de tu ficha ó tu nombre completo.");
		document.getElementById("fl").focus();
		return(false);
	}
	
	if(Trim(document.getElementById("nombre").value)==""&&Trim(document.getElementById("apP").value)!="")
	{
		alert("Ingresa tu nombre.");
		document.getElementById("nombre").focus();
		return(false);
	}
	if(Trim(document.getElementById("nombre").value)!=""&&Trim(document.getElementById("apP").value)=="")
	{
		alert("Ingresa tu apellido paterno.");
		document.getElementById("apP").focus();
		return(false);
	}
}

function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}

function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}

function cerrar_ventana_identidad()
{
	if(document.getElementById("click1").value=="0")
	{
		window.opener.location.href='salida.asp?msg=10';
		//self.close();
	}
}

function cerrar_ventana_principal(nom_campo)
{
	if(document.getElementById(nom_campo).value=="0")
	{
		window.location.href='salida.asp?msg=10';
		//self.close();
	}
}

function bloquear_teclas(e)
{ 
	var curElement = document.activeElement;
	if(curElement.name=="undefined")
	{
	var ev=(!e)?window.event:e;//IE:Moz
	
	if(ev.keyCode == 8)
	{
		alert("La tecla backspace ha sido bloqueada.\nSi deseas borrar algún dato registrado puedes hacerlo \nhaciendo uso de la tecla \"Supr\" ó \"Del\" según sea el caso \nen tu teclado.Para mover el cursor hacia atrás o adelante \npresiona las teclas de desplazamiento (flechas izq. y der.).")
	}
	
	if((ev.keyCode == 8) || ((ev.keyCode >= 113) && (ev.keyCode <= 123)))
	{
		//Bloquear Backspace
		//Bloquear Teclas Fxx (excepto F1)
		ev.cancelBubble = true;//ev.stopPropagation = true;
		ev.returnValue = false;
		ev.keyCode = 505;
		return false;		
	}
	

	if(ev.altLeft)
	{
		if((ev.keyCode == 37) || (ev.keyCode == 39)) 
		{
			//Bloquear Alt + Cursor Izq/Der.
			return false;
		}
	}

	if(event.ctrlKey)
	{
		//Bloquear Ctrl
		return false;
	}
	
	return true;
	}
}

function mostrar_elementos(municipio)
{
	
	//<input type="hidden" name="coloni" value="<%=info_asp(16)%>" /> hay que limpiar estos campos
//		<input type="hidden" name="sector" value="<%=info_asp(24)%>" />
	if(municipio=="")
	{
		//document.getElementById('instruccion').style.display = 'block';
		//document.getElementById('busqueda').style.display = 'none';
		//document.getElementById('otra_colonia1').style.display = 'none';
		//document.getElementById('instruccion2').style.display = 'none';
		//document.getElementById('mostrar_result_ajax1').style.display = 'block';
		document.getElementById('mostrar_result_ajaxDISP').style.display = 'none';
		document.getElementById('inst_locdisp').style.display = 'block';
	}
	else
	{
		//document.getElementById('instruccion').style.display='none';
		//document.getElementById('busqueda').style.display='block';
		//document.getElementById('otra_colonia1').style.display='block';
		//document.getElementById('instruccion2').style.display = 'block';
		//document.getElementById('mostrar_result_ajax1').style.display = 'none';
		document.getElementById('mostrar_result_ajaxDISP').style.display = 'block';
		document.getElementById('inst_locdisp').style.display = 'none';
	}
	document.getElementById('info_aspirant').cp.value = '';
	document.getElementById('info_aspirant').coloni.value = '';
	document.getElementById('info_aspirant').sector.value = '';
	document.getElementById('info_aspirant').plantelSELECCIONADO.value = '';
}

function asignar_codpostal(col_seleccionada)
{
	var cadena = new String(col_seleccionada);
	var codigo = cadena.split("|");	
	document.getElementById('info_aspirant').cp.value = codigo[0];
	document.getElementById('info_aspirant').coloni.value = codigo[1]+"|"+codigo[2];
	document.getElementById('info_aspirant').sector.value = codigo[3];
}

function asignar_municipio(mun_seleccionado)
{
	document.getElementById('info_aspirant').municip_plantel.value = mun_seleccionado;
}

function validar_telefono(tel,campo)
{
	if(soloNumeros(tel)==false)
	{
		alert("Favor de registrar sólo números para el "+campo+".");
		tel.value = "";
    	tel.focus();
		return(false);
	}
}

function soloNumeros(cadena)
{
	var numeros = "0123456789"; 
  	var numero = cadena.value; 
  	var solo_numeros = true; 
  	var todosNum = "";
	var ch,j,i;
	
  	for(i = 0; i < numero.length; i++)
	{ 
    	ch = numero.charAt(i); 
    	for(j = 0; j < numeros.length; j++) 
      		if(ch == numeros.charAt(j))
        		break; 
    		if(j == numeros.length)
			{	 
      			solo_numeros = false; 
      			break; 
    		} 
    		todosNum += ch; 
  	} 
  	if(!solo_numeros) 
	{ 
    	return (false); 
  	}
}

function email_incorrecto()
{
	alert("El email que registraste es incorrecto.\nPuedes corregir el email o dejar en blanco\nel campo para poder continuar.");
	document.getElementById('info_aspirant').email.focus();
	return(false);
}

function asigna_valores_INFOASPIRANT(informacion)
{
	var cadena= new String(informacion)
	var infoASP = cadena.split("|")
	
	document.getElementById("clave_plantel").value=infoASP[3];
	document.getElementById("nom_plantel").value=infoASP[0];
	document.getElementById("domicilio_plantel").value=infoASP[1];
	document.getElementById("entidad_plantel").value="02";
	document.getElementById("municip_plantel").value=infoASP[2];
	document.getElementById("validar_sec").value="0";
}

function cambiar_validar_sec(infoCAP)
{
	if(Trim(infoCAP)=="")
	{
		document.getElementById("validar_sec").value="2";
	}
	else
	{
		document.getElementById("clave_plantel").value=Trim(infoCAP);
	}
}

function validar_cancelacion(msg)
{
	if(msg=="1")
	{
		if(confirm("¿Deseas salir del sistema?"))
		{
			document.getElementById("click2").value=1;
			window.location="salida.asp?out=1";
			return(true);
		}
		else
		{
			return(false);
		}
	}
	else
	{
		if(confirm("¿Deseas cancelar tu solicitud de ficha?"))
		{
			document.getElementById("click3").value=1;
			window.location="salida.asp?out=1";
			return(true);
		}
		else
		{
			return(false);
		}
	}
}

function validar_info_aspirante(forma)
{
  if(forma.boton1.value=="ACEPTAR")
  {
	if(Trim(forma.apellido_pat.value)=="")
	{
		alert("Favor de registrar tu apellido paterno.");
		forma.apellido_pat.focus();
		return(false);
	}
	if(Trim(forma.nombre.value)=="")
	{
		alert("Favor de registrar tu nombre.");
		forma.nombre.focus();
		return(false);
	}
	if(forma.dia.value==""||forma.mes.value==""||forma.anio.value=="")
	{
		alert("Favor de registrar tu fecha de nacimiento completa.");
		if(forma.dia.value=="")
			forma.dia.focus();
		else
			if(forma.mes.value=="")
				forma.mes.focus();
			else
				forma.anio.focus();
		return(false);
	}
	
	if(fecha_valida(forma.hoy.value)==false)
	{
		return(false);
	}
	
	if(forma.entidad.value=="")
	{
		alert("Favor de seleccionar tu Estado de nacimiento.");
		forma.entidad.focus();
		return(false);
	}
	if(forma.sexo.value=="")
	{
		alert("Favor de seleccionar tu sexo.");
		forma.sexo.focus();
		return(false);
	}
	
	if(forma.entidad.value!="NE|33")
	{
		if(Trim(forma.curp.value)=="")
		{
			alert("Favor de registrar tu CURP.");
			forma.curp.focus();
			return(false);
		}
	}
	
	if(forma.anio_egreso.value=="")
	{
		alert("Favor de seleccionar el año de egreso.");
		forma.anio_egreso.focus();
		return(false);
	}
	
	if(forma.prom1.value==""||forma.prom2.value=="")
	{
		alert("Favor de registrar tu promedio.");
		if(forma.prom1.value=="")
			forma.prom1.focus();
		else
			forma.prom2.focus();
		return(false);
	}
			
	if(forma.municipio.value=="")
	{
		alert("Favor de seleccionar el Municipio en donde vives.");
		forma.municipio.focus();
		return(false);
	}
	
	if(Trim(forma.calle.value)=="")
	{
		alert("Favor de registrar la calle de tu domicilio.");
		forma.calle.focus();
		return(false);
	}
	
	if(Trim(forma.numero.value)=="")
	{
		alert("Favor de registrar el número de tu domicilio.");
		forma.numero.focus();
		return(false);
	}
	
	if(Trim(forma.coloni.value)=="")
	{
		alert("Favor de ingresar la colonia de tu domicilio.");
		forma.coloni.focus();
		return(false);
	}
	
	/*if(Trim(forma.cp.value)=="")
	{
		alert("Favor de ingresar el codigo postal de tu domicilio.");
		forma.cp.focus();
		return(false);
	}*/
	
	
	if(forma.tel1.value!=""||forma.tel2.value!=""||forma.tel3.value!="")
	{
		var tel=0;
		
		if(forma.tel1.value.length<3)
		{
			tel=1;
			forma.tel1.focus();
		}
		else
			if(forma.tel2.value.length<2)
			{
				tel=2;
				forma.tel2.focus();
			}
			else
				if(forma.tel3.value.length<2)
				{
					tel=3;
					forma.tel3.focus();
				}
		
		if(tel>0)
		{
			alert("Favor de registrar tu número de teléfono completo.");
			return(false);
		}
		else
		{
			if(validar_telefono(forma.tel1,'teléfono')==false)
				return(false);
			if(validar_telefono(forma.tel2,'teléfono')==false)
				return(false);
			if(validar_telefono(forma.tel3,'teléfono')==false)
				return(false);	
		}
	}
 
  //alert(document.getElementById("validar_sec").value);
  if(document.getElementById("validar_sec").value=="2")
  {
	alert("Intruduce la clave de tu secundaria y presiona el icono de la lupa para iniciar la búsqueda.");
	forma.cve_plantel.focus();
	return(false);
  }
    	
  if(document.getElementById("validar_sec").value=="3")
  {
	alert("Si la información de tu secundaria esta disponible da click en 'MI SECUNDARIA' para asignar dicha información a tu solicitud, en caso contrario ingresa los datos de tu secundaria en los campos que aparecen en pantalla.");
	forma.cve_plantel.focus();
	return(false);
  }
  
  if(document.getElementById("validar_sec").value=="1")
  {
	if(Trim(forma.cve_plantel.value)=="")
	{
		alert("Favor de registrar la clave de la secundaria.");
		forma.cve_plantel.focus();
		return(false);
	}
	
	if(Trim(document.getElementById("nom_plt").value)=="")
	{
		alert("Favor de registrar el nombre de la secundaria.");
		document.getElementById("nom_plt").focus();
		return(false);
	}
	
	if(Trim(document.getElementById("domicilio_plt").value)=="")
	{
		alert("Favor de registrar el domicilio de la secundaria.");
		document.getElementById("domicilio_plt").focus();
		return(false);
	}
	 
	if(document.getElementById("entidad_plt").value=="")
	{
		alert("Favor de seleccionar el Estado donde se encuentra la secundaria.");
		document.getElementById("entidad_plt").focus();
		return(false);
	}
	else
	{
		if(document.getElementById("entidad_plt").value=="02")
		{
			if(document.getElementById("mp").value=="")
			{
				alert("Favor de seleccionar el Municipio donde se encuentra la secundaria.");
				//document.getElementById("mp").focus();
				return(false);
			}
		}
		else
		{
			if(document.getElementById("municip_plt").value=="")
			{
				alert("Favor de registrar el Municipio donde se encuentra la secundaria.");
				document.getElementById("municip_plt").focus();
				return(false);
			}
		}
	}
  }
	
	if(forma.plantelSELECCIONADO.value=="")	
	{
		alert("Favor de seleccionar alguna de las localidades disponibles.");
		return(false);
	}
	
	if(forma.terminos.checked==false)
	{
		alert("No has aceptado los términos del proceso de entrega de fichas.");
		forma.terminos.focus();
		return(false);
	}
	
	
  }//FIN IF PRINCIPAL
  
}

function ocultar_div(estado)
{
	if(estado=="02")
	{
		document.getElementById("registrar").style.display = "none";
	}
	else
	{
		document.getElementById("registrar").style.display = "block";
	}
		
	document.getElementById("info_aspirant").municip_plantel.value = "";
}
