
/* 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="#FF0000";
			
	}else{	
		document.getElementById("first").style.color="#000";
	}
	
	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="#FF0000";
	}else{	
		document.getElementById("last").style.color="#000";
	}

	//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="#FF0000";
	}else{	
		document.getElementById("cty").style.color="#000";
	}
	
	//check state ininfoFormation
	if(document.infoForm.state.selectedIndex <0){
		error_string += "Missing or invalid state.\n";
		document.getElementById("ste").style.color="#FF0000";
	}
	
	//check country field
	if ((document.infoForm.country.value =='')||(document.infoForm.country.value.length <=1)){
		error_string += "Missing or invalid country.\n";
		document.getElementById("ctry").style.color="#FF0000";
	}else{	
		document.getElementById("ctry").style.color="#000";
	}
	//check e-mail
		
		if (checkEmail(document.infoForm.email.value) == true){
			error_string += "Missing or invalid e-mail address.\n";	
			document.getElementById("eml").style.color="#FF0000";
		}else{	
		document.getElementById("eml").style.color="#000";
	}
		

		
	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;
	}



}