function actualizarEstado(objetoDiv, objetoSelect, pais)
{
	$(objetoDiv).innerHTML= "<img src='../images/cargando.gif'>";

  new Ajax.Request('seleccionaEstado.php',{  
    method: 'post',
	parameters:'pais=' + pais + '&objeto=' + objetoSelect,
	onSuccess: function (t)
	{
		$(objetoDiv).innerHTML= t.responseText;
		actualizaMunicipio('areaMunicipio','', 'comboMunicipios.php')
	}	
  });  
}

function actualizarNivel(objetoDiv,  pais, objetoDiv2)
{
	$(objetoDiv).innerHTML= "<img src='../images/cargando.gif'>";
	  new Ajax.Request('nivel.php',{  
		method: 'post',
		parameters:'nivel=' + pais + '&objeto=' + Math.random(),
		onSuccess: function (t)
		{
			$(objetoDiv).innerHTML= t.responseText;
		}	
	  });  
	try	{	
		$(objetoDiv2).innerHTML= "<img src='../images/cargando.gif'>";
		  new Ajax.Request('sesion_nivel.php',{  
			method: 'post',
			parameters:'nivel=' + pais + '&objeto=' + Math.random(),
			onSuccess: function (t)
			{
				$(objetoDiv2).innerHTML= t.responseText;
			}	
		  });  
	}catch(e){}

  
}


function revisaForma1()
{
	
	if ($("titulo").value==0) {
		alert("Selecciona tu titulo");
		$("edoCivil").focus();
		return false;	
	}
	
	if (revisaCampo($("nombre").value)==0) {
		alert("Escribe tu nombre");
		$("nombre").focus();
	return false;	
	}
	if (revisaCampo($("apa").value)==0) {
		alert("Escribe tu apellido paterno");
		$("apa").focus();
	return false;	
	}
	if (revisaCampo($("ama").value)==0) {
		alert("Escribe tu apellido materno");
		$("ama").focus();
	return false;	
	}
	
///////
	if (telefonos()==0 ) {
		return false;	
	}
//////
	
	if (validarEmail($("mail").value)==0)	{
		alert("Escribe tu correo electrónico");
		$("mail").focus();
	return false;			
	}
	
	if ( validaNivelProg('nivel', 'maestria')==0) {
		return false;	
	}
	
   if ( ($('ren1') != null) || ($('ren2') != null) ){
	if ($('ren1') != null) {
	 if (checaReunion('ren1')==0) return false;
	}
	if(($('ren2') != null)){
	 if (checaReunion('ren2')==0) return false;
	}
   }

   	try	{	
			if ($("edoCivil").value==0) {
				alert("Selecciona tu estado civil");
				$("edoCivil").focus();
			return false;	
		}
	}catch(e){}

	if ($("sexo").value==0) {
		alert("Selecciona tu género");
		$("sexo").focus();
	return false;	
	}
	
	if ($("estado").value==0) {
		alert("Selecciona tu estado de origen");
		$("estado").focus();
	return false;	
	}
	

	if (revisaCampo($("ciudad").value)==0) {
		alert("Escribe tu ciudad de origen");
		$("ciudad").focus();
	return false;	
	}

	
	fecha=isDate($('mes').value+"/"+$('dia').value+"/"+$('anio').value );
    if (!fecha){
		alert("Introduce tu fecha de nacimiento");
		$("anio").focus();
      return false;
	}
	

    return true; 	
}
function checaReunion(obj){
	if(($(obj).checked)) {
		if ($("Entero").value==0) {
			alert("Seleccione como se entero de la reunion");
			$("Entero").focus();
		return 0;	
		}
     }
  return 1;
}

 function revisaCampo(campo)
 { var i, fin, bandera;
   bandera=0;
    for (i=0; i<campo.length; i++)
     { fin= i+1;
	   if (campo.substring(i,fin) != " ")
	   { bandera=1;
	   }
     }   
   return bandera;
 }
 
 function soloNum(campo,vacio){
  valor = parseInt(campo);
	 if (vacio) {
		 if (campo.length == 0 ) return 1;
//		 if (isNaN(valor+"0")) return 0;
   		 if(/^[0-9]+$/.test(campo))return 1		 
		 else return 0; 		 
	 }
	 else {
	 if (campo.length<=0 ) return 0;  
//     if (isNaN(valor)) return 0;
     if(/^[0-9]+$/.test(campo))return 1
      else return 0; 
	 }
 }
 
function validaPaisEstado(pais, estado)
 {
	 if ($(pais).value == 1)
	  {
		  if ($(estado).value == 0)
		   { alert("Selecciona tu estado");
		     $(estado).focus();
			 return 0;
		   }
		  else
		   { return 1; }
	  }
	 else
	  {
		  if  (revisaCampo($(estado).value) == 0)  
		   { alert("Escribe el estado");
		     $(estado).focus();
		     return 0;
		   }
		  else
		   { return 1;}
	  }
 }

function validaNivelProg(pais, estado)
 {
	 if ($(pais).value > 0)
	  {
		  if ($(estado).value == 0)
		   { alert("Selecciona un programa");
		     $(estado).focus();
			 return 0;
		   }
		  else
		   { return 1; }
	  }
	 else
	  {
		  alert("Selecciona un nivel");
		  $(pais).focus();
		  return 0;
	  }
 }


function validarEmail(valor) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) return 1;
else return 0;
}

function telefonos() {
 if( soloNum( $('lada2C').value,false) == 0){
  alert("Escribe la lada de casa, sólo números");
  $('lada2C').focus();
  return 0;	 
 }
 if( soloNum( $('telC').value,false) == 0){
  alert("Escribe el teléfono de casa, sólo números");
  $('telC').focus();
  return 0;	 
 }
 if( soloNum( $('lada2Cel').value,false) == 0){
  alert("Escribe la lada de celular, sólo números");
  $('lada2Cel').focus();
  return 0;	 
 }
 if( soloNum( $('telCel').value,false) == 0){
  alert("Escribe el teléfono de celular, sólo números");
  $('telCel').focus();
  return 0;	 
 }
 
return 1;
}

function revisaForma3(){
	if (revisaCampo($("TuNombre").value)==0) {
		alert("Escribe tu nombre");
		$("TuNombre").focus();
	return false;	
	}
	
	if (validarEmail($("TuCorreo").value)==0)	{
		alert("Escribe tu correo electrónico");
		$("TuCorreo").focus();
	return false;			
	}

	if (revisaCampo($("SuNombre").value)==0) {
		alert("Escribe el nombre del destinatario");
		$("SuNombre").focus();
	return false;	
	}
	
	if (validarEmail($("SuCorreo").value)==0)	{
		alert("Escribe el correo electrónico del destinatario");
		$("SuCorreo").focus();
	return false;			
	}
	
	if (revisaCampo($("Asunto").value)==0) {
		alert("Escribe el asunto");
		$("Asunto").focus();
	return false;	
	}

	if (revisaCampo($("Comentarios").value)==0) {
		alert("Escribe tus comentarios");
		//$("Comentarios").focus();
	return false;	
	}

return true;
}

function revisaForma2(){
	if (revisaCampo($("calle").value)==0) {
		alert("Escribe tu calle");
		$("calle").focus();
	return false;	
	}

	if (revisaCampo($("numero").value)==0) {
		alert("Escribe tu número de calle");
		$("numero").focus();
	return false;	
	}

	if (revisaCampo($("calle1").value)==0) {
		alert("Escribe la calle 1");
		$("calle1").focus();
	return false;	
	}

	if (revisaCampo($("calle2").value)==0) {
		alert("Escribe la calle 2");
		$("calle2").focus();
	return false;	
	}

	if (revisaCampo($("refe").value)==0) {
		alert("Escribe una referencia de tu domicilio");
		$("refe").focus();
	return false;	
	}

	if (revisaCampo($("col").value)==0) {
		alert("Escribe tu colonia");
		$("col").focus();
	return false;	
	}

	if (revisaCampo($("cp").value)==0) {
		alert("Escribe tu código postal");
		$("cp").focus();
	return false;	
	}
	
	if (validaPaisEstado("Pais","Estado") == 0)	
    {   return false;   } 	

	if (revisaCampo($("ciudad").value)==0) {
		alert("Escribe tu ciudad");
		$("ciudad").focus();
	return false;	
	}

	return true;
}

function isDate(s){
// make sure it is in the expected format
if (s.search(/^\d{1,2}[\/|\-|\.|_]\d{1,2}[\/|\-|\.|_]\d{4}/g) != 0)
return false;
 
// remove other separators that are not valid with the Date class
s = s.replace(/[\-|\.|_]/g, "/");

// convert it into a date instance
var dt = new Date(Date.parse(s));
 
// check the components of the date
// since Date instance automatically rolls over each component

var arrDateParts = s.split("/");
return (
dt.getMonth() == arrDateParts[0]-1 &&
dt.getDate() == arrDateParts[1] &&
dt.getFullYear() == arrDateParts[2]
);

} 