function solo_num(res,evt)
{ 
var valor=document.getElementById(res).value.length;
var band=46;
for(var i=0; i<valor;i++) 
{  
   if(document.getElementById(res).value.charAt(i)==".")
   band=13;  
} 
key = (document.all) ? evt.keyCode : evt.which;
if ( (key < 48 || key > 57) && key!=127 && key!=13 && key!=8 && key!=9 && key!=band)
     {return false;
     }
  return true; 
}

function solo_letra(res,evt)
{ 
var valor=document.getElementById(res).value.length;//evt.document.forms[0].recuperado.value.length;
var band=46;

key = (document.all) ? evt.keyCode : evt.which;
if ( (key < 65 || key > 90) && (key<97 || key>122) && key!=127 && key!=13 && key!=8 && key!=9)
     {return false;
     }
  return true; 
}

function emailCheck (emailStr) {
	/* Verificar si el email tiene el formato user@dominio. */
	var emailPat=/^(.+)@(.+)$/; 
	/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; 
	/* Verifica los caracteres que son válidos en una dirección de email */
	var validChars="\[^\\s" + specialChars + "\]"; 
	var quotedUser="(\"[^\"]*\")"; 
	/* Verifica si la dirección de email está representada con una dirección IP Válida */ 
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* Verificar caracteres inválidos */ 
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	//domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Direccion email parace ser incorrecta (verifique @ y .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Si el user "user" es valido 
	if (user.match(userPat)==null) {
		// Si no
		alert("El nombre de usuario no es valido.");
		return false;
	}
	/* Si la dirección IP es válida */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("IP de destino invalida");
				return false;
			}
		}
	return true;
	}
	
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("El dominio parece no ser valido.");
		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) { 
		alert("La direccion debe tener 3 letras si es .'com' o 2 si en de algun pais.");
		return false;
	}
	if (len<2) {
		var errStr="La dirección es erronea";
		alert(errStr);
		return false;
	}
// La dirección de email ingresada es Válida
return true;
}




function validalo()
 {
	d=document.formita;
   d.nombre.style.backgroundColor="#ffffff";
   d.apellido.style.backgroundColor="#ffffff";  
   d.email.style.backgroundColor="#ffffff";   
   d.clave.style.backgroundColor="#ffffff";   
   d.clave2.style.backgroundColor="#ffffff";   
			  
  if(d.nombre.value=="")
   {
    alert("Debes Ingresar el Nombre para continuar");
	d.nombre.style.backgroundColor="#ffffcc";
	d.nombre.focus();
	return false;
   }
  if(d.apellido.value=="")
   {
    alert("Debes Ingresar el Apellido para continuar");
	d.apellido.style.backgroundColor="#ffffcc";
	d.apellido.focus();
	return false;
   }
 
 if(d.email.value=="")
   {
    alert("Debes Ingresar el Email para continuar");
	d.email.style.backgroundColor="#ffffcc";	
	d.email.focus();
	return false;
   } 
 else{
 	 var error=emailCheck(d.email.value);
	 if(!error)
	 	return false;
 }   
 if(d.clave.value=="")
   {
    alert("Debes Ingresar la Clave para continuar");
	d.clave.style.backgroundColor="#ffffcc";	
	d.clave.focus();
	return false;
   }
 if(d.clave2.value=="")
   {
    alert("Debes Ingresar Nuevamente la Clave para continuar");
	d.clave2.style.backgroundColor="#ffffcc";	
	d.clave2.focus();
	return false;
   }   
 if(d.clave.value!=d.clave2.value)
   {
    alert("Las claves no coinciden");
	d.clave.style.backgroundColor="#ffffcc";	
	d.clave.value="";
	d.clave2.value="";
	d.clave.focus();	
	return false;
   }   
   verifica_aliado();
 }

function validalo2()
 {
	d=document.formita;
   d.nombre.style.backgroundColor="#ffffff";
   d.apellido.style.backgroundColor="#ffffff";  
   d.email.style.backgroundColor="#ffffff";   
   d.asunto.style.backgroundColor="#ffffff";   
   d.mensaje.style.backgroundColor="#ffffff";   
			  
  if(d.nombre.value=="")
   {
    alert("Debes Ingresar el Nombre para continuar");
	d.nombre.style.backgroundColor="#ffffcc";
	d.nombre.focus();
	return false;
   }
  if(d.apellido.value=="")
   {
    alert("Debes Ingresar el Apellido para continuar");
	d.apellido.style.backgroundColor="#ffffcc";
	d.apellido.focus();
	return false;
   }
 
 if(d.email.value=="")
   {
    alert("Debes Ingresar el Email para continuar");
	d.email.style.backgroundColor="#ffffcc";	
	d.email.focus();
	return false;
   } 
 else{
 	 var error=emailCheck(d.email.value);
	 if(!error)
	 	return false;
 }   
 if(d.asunto.value=="")
   {
    alert("Debes Ingresar el asunto para continuar");
	d.asunto.style.backgroundColor="#ffffcc";	
	d.asunto.focus();
	return false;
   }
 if(d.mensaje.value=="")
   {
    alert("Debes Ingresar el mensaje para continuar");
	d.mensaje.style.backgroundColor="#ffffcc";	
	d.mensaje.focus();
	return false;
   }   
 d.submit();
 }

