
var mail=1;

function EEmailCheck (emailStr) {
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	return false;
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    return false;
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
			return false;
	    }
    }
    return true;
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
    return false;
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
	return false;
}

if (len<2) {
	return false;
}

return true;
}

function Validate(){
var chDay,chYear;
var varform=document.reg;



	
	if  (varform.nombre.value == ""){
		alert("Por favor falta tu Nombre");
		varform.nombre.focus()
		return false;
	}
	
	if  (varform.apellido.value == ""){
		alert("Por favor faltan tus apellidos");
		varform.apellido.focus()
		return false;
	}
	
	

	     if(varform.email.value == ""){
		  alert("Por favor falta tu Email");
          varform.email.focus();
		  return false;
    	  }
			else
			{	
			if(varform.email.value != "")
			  {
		  		if (!EEmailCheck(varform.email.value)) 
		  			{
         		 	  alert("Tu Email no es válido. Por favor intenta de nuevo");
       				   varform.email.focus();
				 	  return false;
					}
			   }
	  		}
	  
	  
	  

	
	

    if (!varform.genero[0].checked && !varform.genero[1].checked) 
 	{
		alert("Por favor selecciona tu Sexo");
		varform.genero[0].focus();
		return false;
	}

	  


	if (varform.dia.options[varform.dia.selectedIndex].value == "0") {
		alert("Por favor falta el Día de tu Cumpleaños");
		varform.dia.focus();
		return false;
	}
	
	if (varform.mes.options[varform.mes.selectedIndex].value == "0") {
		alert("Por favor falta el Mes de tu Cumpleaños");
		varform.mes.focus();
		return false;
	}
	
	if (varform.anio.options[varform.anio.selectedIndex].value == "0") {
		alert("Por favor falta el Año de tu Nacimiento");
		varform.anio.focus();
		return false;
	}
	


chDay=varform.dia.selectedIndex;
chYear=parseInt(varform.anio.value);

	
	
	
	if(varform.mes.selectedIndex==1 && varform.mes.selectedIndex==3 && varform.mes.selectedIndex==5 && varform.mes.selectedIndex==8 && varform.mes.selectedIndex==10) // impar
	{
						if(chDay>30){
							alert("El mes seleccionado no tiene esa cantidad de días!");
							varform.mes.focus();
							return false;
						}
	}
	else if(varform.mes.selectedIndex==2){
			
		
		
		if( ((chYear%4==0) && (chYear%100 !=0 )) ||	(chYear%400==0)){ //Es bisiesto
						if(chDay>29)              
						{
							alert("El mes seleccionado no tiene esa cantidad de días! \nPor favor selecciona el dia correcto");
							varform.dia.focus();
							return false;
						}
			}
		else{ // No es bisiesto
						if(chDay>28)
						{
							alert("El mes seleccionado no tiene esa cantidad de días! \n Por favor selecciona el dia correcto");
							varform.dia.focus();
							return false;
						}
			}	
				
	}
	
		
	
}
