// JavaScript Document

function FrontPage_Form1_Validator(theForm)
{

	if (theForm.name.value == "" || theForm.name.value == "First Name *"){
		alert("Please enter a value for the \"First Name\" field.");
		theForm.name.focus();
		return (false);
	}
	
	if (theForm.name.value.length > 50){
		alert("Please enter at most 50 characters in the \"First Name\" field.");
		theForm.name.focus();
		return (false);
	}
	
	if (theForm.nameLast.value == "" || theForm.nameLast.value == "Last Name *"){
		alert("Please enter a value for the \"Last Name\" field.");
		theForm.nameLast.focus();
		return (false);
	}
	
	if (theForm.nameLast.value.length > 50){
		alert("Please enter at most 50 characters in the \"Last Name\" field.");
		theForm.nameLast.focus();
		return (false);
	}
	
	if (theForm.EmailAddress.value == "" || theForm.EmailAddress.value == "Email Address *"){
		alert("Please enter a value for the \"Email Address\" field.");
		theForm.EmailAddress.focus();
		return (false);
	}
	
	if (theForm.EmailAddress.value.length > 50){
		alert("Please enter at most 50 characters in the \"Email Address\" field.");
		theForm.EmailAddress.focus();
		return (false);
	}
	
	var bval=true;
	bval=emailCheck(theForm.EmailAddress.value);
	if(!bval){
		theForm.EmailAddress.focus();
		return (false);
	}
	
	if (theForm.Procedure0.selectedIndex < 0){
		alert("Please select one of the \"Procedure\" options.");
		theForm.Procedure0.focus();
		return (false);
	}
	
	if (theForm.Procedure0.selectedIndex == 0){
		alert("The first \"Procedure\" option is not a valid selection.  Please choose one of the other options.");
		theForm.Procedure0.focus();
		return (false);
	}		
	
	if(theForm.Comment.value == "Questions/Comment"){
		theForm.Comment.value="";
	}
	
	return (true);
}

function FrontPage_Contact_Form2_Validator(theForm)
{

	if (theForm.name.value == ""){
		alert("Please enter a value for the \"First Name\" field.");
		theForm.name.focus();
		return (false);
	}
	
	if (theForm.name.value.length > 50){
		alert("Please enter at most 50 characters in the \"First Name\" field.");
		theForm.name.focus();
		return (false);
	}
	
	if (theForm.nameLast.value == ""){
		alert("Please enter a value for the \"Last Name\" field.");
		theForm.nameLast.focus();
		return (false);
	}
	
	if (theForm.nameLast.value.length > 50){
		alert("Please enter at most 50 characters in the \"Last Name\" field.");
		theForm.nameLast.focus();
		return (false);
	}
	
	var bval=true;
	
	if (theForm.ZipCode.value == ""){
		alert("Please enter a value for the \"Zip Code\" field.");
		theForm.ZipCode.focus();
		return (false);
	}
	
	bval=ZipCheck(theForm.ZipCode.value);
	if(!bval){
		theForm.ZipCode.focus();
		return (false);
	}
	
	if (theForm.EmailAddress.value == ""){
		alert("Please enter a value for the \"Email Address\" field.");
		theForm.EmailAddress.focus();
		return (false);
	}
	
	if (theForm.EmailAddress.value.length > 50){
		alert("Please enter at most 50 characters in the \"Email Address\" field.");
		theForm.EmailAddress.focus();
		return (false);
	}
	
	
	bval=emailCheck(theForm.EmailAddress.value);
	if(!bval){
		theForm.EmailAddress.focus();
		return (false);
	}
	
	if (theForm.Procedure.selectedIndex < 0){
		alert("Please select one of the \"Procedure\" options.");
		theForm.Procedure.focus();
		return (false);
	}
	
	if (theForm.Procedure.selectedIndex == 0){
		alert("The first \"Procedure\" option is not a valid selection.  Please choose one of the other options.");
		theForm.Procedure.focus();
		return (false);
	}
	
	if (theForm.Referral.selectedIndex < 0){
		alert("Please select one of the \"How did you hear about us?\" options.");
		theForm.Referral.focus();
		return (false);
	}
	
	if (theForm.Referral.selectedIndex == 0){
		alert("The first \"How did you hear about us?\" option is not a valid selection.  Please choose one of the other options.");
		theForm.Referral.focus();
		return (false);
	}
	
	return (true);
}

function emailCheck(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var matchArray;	
	
	if(emailStr.length > 1)	{  	  	
		matchArray = emailStr.match(emailPat);
		if (matchArray == null){
			alert("Please enter correct email address"); 
			return false;
		}else{
			return true;
		}  		
	}				
}

function PhoneCheck(strPhone){  	  		  	  		
	strPhone=strPhone.replace(/[^0-9]/g, ''); 
	//if(strPhone.length
	if(strPhone.length!=10){
		alert("Invalid phone number");
		return false;
	}
	return true;	  	  	
}

function ZipCheck(zipStr){
	var zipPat=/[0-9]{5}/; 		

	if(zipStr.length > 0)	{  	  	
	var matchArray = zipStr.match(zipPat);
		if (matchArray == null) {
			alert("Please enter valid 5 digit Zip Code"); 
			return false;
		}	
		else{
			return true;
		}  
	}
}
