
/* JavaScript functions for validating infoForm */

function validData(infoForm){
	
	var error_string = "";
	
	// check the name fields
	if ((document.infoForm.first_name.value == '')|| (document.infoForm.first_name.value.length <=1)){
		error_string += "Missing or invalid first name.\n";
		document.getElementById("first").style.color="#F5AAED";
			
	}else{	
		document.getElementById("first").style.color="#FEFEFE";
	}
	
	if ((document.infoForm.last_name.value == '')|| (document.infoForm.last_name.value.length <=1)){
		error_string += "Missing or invalid last name.\n";
		document.getElementById("last").style.color="#F5AAED";
	}else{	
		document.getElementById("last").style.color="#FEFEFE";
	}

	//check city field
	if ((document.infoForm.city.value =='')||(document.infoForm.city.value.length <=1)){
		error_string += "Missing or invalid city.\n";
		document.getElementById("cty").style.color="#F5AAED";
	}else{	
		document.getElementById("cty").style.color="#FEFEFE";
	}
	
	//check state ininfoFormation
	if(document.infoForm.state.selectedIndex <0){
		error_string += "Missing or invalid state.\n";
		document.getElementById("ste").style.color="#F5AAED";
	}
	

	//check phone
	if (checkPhone(document.infoForm.phone.value) == true){
		error_string += "Missing or invalid phone number.\n";
		document.getElementById("phn").style.color="#F5AAED";	
	}else{	
		document.getElementById("phn").style.color="#FEFEFE";
	} 
	//check e-mail
		
		if (checkEmail(document.infoForm.email.value) == true){
			error_string += "Missing or invalid e-mail address.\n";	
			document.getElementById("eml").style.color="#F5AAED";
		}else{	
		document.getElementById("eml").style.color="#FEFEFE";
	}
		

		
	if(error_string ==""){


		return true;
	}
	
	else{
		error_string = "We found the following items missing from your Request Form: \n" +error_string;
		alert(error_string);
		return false;
	}
}	
	
	
function checkEmail(addy){

	var emailFilter = /^[a-z][\w\.]*@[\w\.]+\.[a-z]{2,3}/i;
	var illegalChars = /[\(\)\<\>\,\;\:\\\"[\]]/;
	
	
	if((addy == "") || (!(emailFilter.test(addy))) || (addy.match(illegalChars))){
		return true;
	}



}

function checkPhone(numString){
	
	var i;
	var legalChars = "0123456789()-+ " 
	
	if((numString=="") || (numString<7) || (numString >19)){
		return true;
	}
	
	for (i =0; i <= numString.length -1; i++) {
		if (legalChars.indexOf(numString.charAt(i)) == -1) {
		
		return true;
		}
	}
}
