// JavaScript Document
function Validarform(form) {
	/*var emailRegEx = /^((\w|\.){2,}@)\w{3,}\.\w{2,4}((\.(\w{2}))?)?$/*/
	var numericoRegEx = /^\d*$/
 	function vacio(q) {  
			for ( i = 0; i < q.length; i++ ) {  
					if ( q.charAt(i) != " " ) {  
							return true  
					}  
			}  
			return false  
	} 

	
	if(vacio(form.Contact_Person_Name.value)==false){
		form.Contact_Person_Name.focus();
		mostrar("The Name field is required");
		return false;
	}
	
	if(vacio(form.Contact_Person_LastName.value)==false){
		form.Contact_Person_LastName.focus();
		mostrar("The Last Name field is required");
		return false;
	}
	
	
	if(vacio(form.Contact_Person_email.value) == false) {
		form.Contact_Person_email.focus();
		mostrar("The E-mail field is required");
		return false;
	}else {
		val = validacion(form.Contact_Person_email.value);
		if(!val) {
			form.Contact_Person_email.focus();
			//form.email.value = "";
			mostrar("Insert a valid E-mail addresss");
			return false;
		}
	}
	
		
	/*encontrar el valor option seleccionado*/	
	
	
	for(i=0; i <form.May_we_contact_you_by_telephone.length; i++){
    	if(form.May_we_contact_you_by_telephone[i].checked){
      		valorSeleccionado = form.May_we_contact_you_by_telephone[i].value;
    	}
  	}
	//alert(valorSeleccionado);
	//alert(vacio(form.Contact_Person_Telephone.value));
	
	if((valorSeleccionado=='Yes') && (vacio(form.Contact_Person_Telephone.value)==false) ){
		form.Contact_Person_Telephone.focus();
		mostrar("If you have chosen the option for us to call you, please be sure to give us a telephone number. Thank you.");
		return false;
						
	}
	
	if(vacio(form.Contact_Person_Telephone.value)==true) {
		var patron = /\d{3}/; //validar que almenos haya 3 numeros
		var expreg = new RegExp (patron);
		
		if (!expreg.test(form.Contact_Person_Telephone.value) ) {
			mostrar("Invalid Phone Number.");
			form.Contact_Person_Telephone.focus();
			return false;
		}
	}
	
	
	
/*	if(vacio(form.Contact_Person_email_alternate.value)==true) {
		
		val = validacion(form.Contact_Person_email_alternate.value);
		if(!val) {
			form.Contact_Person_email_alternate.focus();
			//form.email.value = "";
			mostrar("Insert a valid Alternate E-mail addresss");
			return false;
		}
	}*/

	return true;
}


function mostrar(error) {
	alert(error);
}

function validacion(email){
	//var email = document.formulario.EMAIL.value;
	//var verif = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/
	var verif = /^([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$/
	if (verif.exec(email) == null){
		//alert("Su email es incorrecto");
		return false;
		}
		else{
		//alert("Su email es correcto");
		return true;
		}
} 
