function trim(str) { return str.replace(" ", ""); };

function XMLHttp()
	{
		var Object;
		if (typeof XMLHttpRequest == "undefined")
			{
				if(navigator.userAgent.indexOf("MSIE 5") >= 0)
					{
						 Object= new ActiveXObject("Microsoft.XMLHTTP");
						 }
						else
							{
								 Object=new ActiveXObject("Msxml2.XMLHTTP");
								 }
					}
					else
						{
						 Object=new XMLHttpRequest();}
		return Object;
	}


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

function ValidarFormulario()
{
	var ok=true;
	document.getElementById("t_identificacion").style.background="#FFFFFF";
	document.getElementById("t_nombres").style.background="#FFFFFF";
	document.getElementById("t_apellidos").style.background="#FFFFFF";
	document.getElementById("t_genero").style.background="#FFFFFF";
	document.getElementById("t_fecha_nacimiento").style.background="#FFFFFF";
	document.getElementById("t_email").style.background="#FFFFFF";
	document.getElementById("t_ciudad").style.background="#FFFFFF";
	
	document.getElementById("error1").innerHTML="";
	document.getElementById("error2").innerHTML="";
	document.getElementById("error3").innerHTML="";
	document.getElementById("error4").innerHTML="";
	document.getElementById("error5").innerHTML="";
	document.getElementById("error6").innerHTML="";
	document.getElementById("error7").innerHTML="";
	document.getElementById("error8").innerHTML="";
	
	
	
	
	if(document.getElementById("identificacion").value==""||document.getElementById("identificacion").value==" "){
				
				document.getElementById("t_identificacion").style.background="#CFD3E8";
				document.getElementById("error1").innerHTML="<p><font color='red'>Debe ingresar su identificaci&oacute;n.</font></p>";
				ok=false;
	}
	else
	{
		
		if(isNaN(document.getElementById("identificacion").value)){
				
				document.getElementById("t_identificacion").style.background="#CFD3E8";
				document.getElementById("error1").innerHTML="<p><font color='red'>La identificaci&oacute;n debe ser n&uacute;merica.</font></p>";
				ok=false;
				}
				else
				{
					id=document.getElementById("identificacion").value;
					
					for(i=0;i<id.length;i++)
						{
							if(id[i]==".")
								{
									document.getElementById("t_identificacion").style.background="#CFD3E8";
									document.getElementById("error1").innerHTML="<p><font color='red'>La identificaci&oacute;n no debe tener puntos ni espacios.</font></p>";
									ok=false;
									break;
									}
							
							}
					
					
					
					
					}
		
		}
		
		if(document.getElementById("nombres").value==""||document.getElementById("nombres").value==" "){
				
				document.getElementById("t_nombres").style.background="#CFD3E8";
				document.getElementById("error2").innerHTML="<p><font color='red'>Debe ingresar su nombre.</font></p>";
				ok=false;
		}
		if(document.getElementById("apellidos").value==""||document.getElementById("apellidos").value==" "){
				
				document.getElementById("t_apellidos").style.background="#CFD3E8";
				document.getElementById("error3").innerHTML="<p><font color='red'>Debe ingresar su apellido.</font></p>";
				ok=false;
		}
		
		if(!document.getElementById("genero1").checked&&!document.getElementById("genero2").checked){
				
				document.getElementById("t_genero").style.background="#CFD3E8";
				document.getElementById("error4").innerHTML="<p><font color='red'>Debe seleccionar su genero. </font></p>";
				ok=false;
		}
		
		if(document.getElementById("dianac").value==""||document.getElementById("mesnac").value==""||document.getElementById("anonac").value==""){
				
				document.getElementById("t_fecha_nacimiento").style.background="#CFD3E8";
				document.getElementById("error5").innerHTML="<p><font color='red'>Debe ingresar su fecha de nacimiento completa. </font></p>";
				ok=false;
		}
		
		correo=document.getElementById("correo").value;
		if(validarEmail(trim(correo))==false)
		{
				document.getElementById("t_email").style.background="#CFD3E8";
				document.getElementById("error6").innerHTML="<p><font color='red'>El corroe electr&oacute;nico ingresado no es v&aacute;lido. </font></p>";
				ok=false;	
			}
			
			if(document.getElementById("ciudad").value==""||document.getElementById("ciudad").value==" "){
				
				document.getElementById("t_ciudad").style.background="#CFD3E8";
				document.getElementById("error8").innerHTML="<p><font color='red'>Debe ingresar su ciudad. </font></p>";
				ok=false;
		}

		
		return ok;
	
	
	}

function RegistrarEstudiante()
	{
		if(ValidarFormulario())
		{
			
			document.formulario.submit();
			}
			else
			{
				alert("Verifique los datos ingresados.");	
				}
		
	}
	
	

function CargarControles()
	{
			
			dia=document.getElementById("dianac");
			dia.options.add(new Option("-",""));	
			for(i=01;i<32;i++)
			{
				if(i<10)
				{
					dia.options.add(new Option("0"+i,"0"+i));	
					}
				else
					{
					dia.options.add(new Option(i,i));
				}
				
				}

			mes=document.getElementById("mesnac");
			mes.options.add(new Option("-",""));
			meses=new Array();
			meses[0]="Enero";
			meses[1]="Febrero";
			meses[2]="Marzo";
			meses[3]="Abril";
			meses[4]="Mayo";
			meses[5]="Junio";
			meses[6]="Julio";
			meses[7]="Agosto";
			meses[8]="Septiembre";
			meses[9]="Octubre";
			meses[10]="Noviembre";
			meses[11]="Diciembre";

			for(i=0;i<12;i++)
			{
				if(i<10)
				{
					mes.options.add(new Option(meses[i],"0"+(i+1)));	
					}
				else
					{
					mes.options.add(new Option(meses[i],i+1));
				}
				
				}
			

			ano=document.getElementById("anonac");
			ano.options.add(new Option("-",""));
			fecha=new Date();
			anoactual=fecha.getFullYear();
			for(i=anoactual;i>1950;i--)
			{
				ano.options.add(new Option(i,i));				

				}

	}


function efectuarPago()
{
	
	var ajax=XMLHttp();
	var identificacion=document.getElementById('identificacion').value;
	var nombres=document.getElementById('nombres').value;
	var apellidos=document.getElementById('apellidos').value;
	var genero=document.getElementById('genero').value;
	var anonac=document.getElementById('anonac').value;
	var mesnac=document.getElementById('mesnac').value;
	var dianac=document.getElementById('dianac').value;
	var correo=document.getElementById('correo').value;
	var telefono=document.getElementById('telefono').value;
	var ciudad=document.getElementById('ciudad').value;
	var usuarioId=document.getElementById('usuarioId').value;
	var firma=document.getElementById('firma').value;
	var usuarioId=document.getElementById('usuarioId').value;
	var extra1=document.getElementById('extra1').value;
	var extra2=document.getElementById('extra2').value;
	var refVenta=document.getElementById('refVenta').value;
	
	var param="identificacion="+identificacion+"&nombres="+nombres+"&apellidos="+apellidos+"&genero="+genero+"&anonac="+anonac+"&mesnac="+mesnac+"&dianac="+dianac+"&correo="+correo+"&telefono="+telefono+"&ciudad="+ciudad+"&refVenta="+refVenta+"";
	ajax.open("POST","./lib/lib/EV_Pagos.php",true);
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajax.setRequestHeader("Content-length", param.length);
    ajax.setRequestHeader("Connection", "close");
    ajax.send(param);
		ajax.onreadystatechange=function(){
	if(ajax.readyState==4)
		{
			var respuesta=ajax.responseText;	
			if(respuesta=="ok")
			{
				document.form1.submit();
				}
				else
				{
					
					document.getElementById("mensaje").innerHTML=respuesta;
					}			
			
									
			}
	
	}
	}
	
function cancelarPago()
{
	
	//document.location='registro1.html'
	history.go(-1);
	}
