//validaciones de formulario 
//
//
//

//**************************************************************************
// esto valida el correo
function EmailCheck(emailStr) {
if(emailStr!=""){
	emailPat=/^(.+)@(.+)$/
	specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	validChars="\[^\\s" + specialChars + "\]"
	quotedUser="(\"[^\"]*\")"
	ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	atom=validChars + '+'
	word="(" + atom + "|" + quotedUser + ")"
	userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("E-mail incorrecto!");
		return false;
	}
	user=matchArray[1]
	domain=matchArray[2]
	if (user.match(userPat)==null) {
	    alert("Ingrese el nombre de usuario!");
	   return false;
	}
	IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("El numero de IP es incorrecto!!");
			return false;
		    }
	    }
	    return true;
	}
	domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("El nombre de dominio es incorrecto!");
	    return false;
	}
	atomPat=new RegExp(atom,"g")
	domArr=domain.match(atomPat)
	len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
		alert("El nombre de dominio es incorrecto!");
	   return false;
	}
	if (len<2) {
	   errStr="Ingrese el Dominio!"
	   alert(errStr);
	   return false;
	}
	return true;
}
}

//**************************************************************************
//esto valida numeros

function Valida_Numero(field) {
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Ingrese solo numeros!");
		/*field.value="";*/
		field.focus();
		return false;
      }
	return true;	
}
//**************************************************************************

var sfilter="123456780%&#'"+'"';
function StringFilter(input,filteredValues) {
returnString="";
s=input.value;
	for (i=0; i < s.length; i++) {
		var c=s.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
	}
	input.value=returnString;
}

var sfilterOnly="%&#'"+'"';
function StringFilterOnly(input,filteredValues) {
	returnString="";
	s=input.value;
	for (i=0; i < s.length; i++) {
		var c=s.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
	}
	input.value=returnString;
}
// -------------------------------------------------------
function borrarform(){
	document.frmdocumento.reset();
	}

// esta funcion es la que valida el formulario de la pagina

function frmaccion(){	   
	
	if (document.frmdocumento.txt_nom.value=="")
	{	alert("Write your name");        
			document.frmdocumento.txt_nom.focus();
			 return false;
	}	
	
	if (document.frmdocumento.txt_ape.value=="")
	{	alert("Write your family name");        
			document.frmdocumento.txt_ape.focus();
			return false;
	}    	
	
      if (document.frmdocumento.cmb_pais.value=="")
	{	alert("Choose your nationality");        
			document.frmdocumento.txt_pais.focus();
			return false;
	}    
    	    
    if (document.frmdocumento.txt_mail.value=="")
	{	alert("Write your e-mail");        
			document.frmdocumento.txt_mail.focus();
			return false;
	}	
	
	return_email = EmailCheck(document.frmdocumento.txt_mail.value);
	if (return_email == false){
		document.frmdocumento.txt_mail.focus();
		return false;
	}	
	 
 
    
	//----------------------------------------------------
	
	//alert("Validacion Terminada")

	//abracadabra enviate cesamo
	document.frmdocumento.action="scripts/enviar.php"
	document.frmdocumento.submit();

}
//**************************************************************************