
// regular expressions used by the contact form validation function

re = /\S+/;
reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
reArea = /^\d\d\d$/;
rePhone = /^\d\d\d\d$/;
reZip1 = /^\d\d\d\d\d$/;
reZip2 = /^\d\d\d\d\d\-\d\d\d\d$/;

// messages used by the contact form validation function

noSubMssg = "Your message could not be sent because\nyou did not complete the ";
noSubMssg2 = "Your message could not be sent because\nwhat you entered in the ";
tryAgain = " field.\n\nPlease do so and try again.";
tryAgain2 = " field\nis not a valid entry for that field.\n\nPlease change your entry in that field and try again.";

// validation function for the contact form

function validate(theForm) { 

	if (!re.test(theForm.fname.value)) {
		alert(noSubMssg + "Name" + tryAgain);
		theForm.fname.focus();
		return false;
	}
	if (!re.test(theForm.femail.value)) {
		alert(noSubMssg + "Email" + tryAgain);
		theForm.femail.focus();
		return false;
	}
	if(re.test(theForm.femail.value) && !reEmail.test(theForm.femail.value)) {
		alert(noSubMssg2 + "Email" + tryAgain2);
		theForm.femail.focus();
		return false;
	}		
	if (!re.test(theForm.fsubject.value)) {
		alert(noSubMssg + "Subject" + tryAgain);
		theForm.fsubject.focus();
		return false;
	}
	if (!re.test(theForm.fcomments.value)) {
		alert(noSubMssg + "Comments" + tryAgain);
		theForm.fcomments.focus();
		return false;
	}
	if (theForm.appsend.checked == true || theForm.infosend.checked == true || theForm.addtolist.checked == true) {
			if(!re.test(theForm.faddress.value)) {
				alert(noSubMssg + "Street Address" + tryAgain);
				theForm.faddress.focus();
				return false;
			}
			if(!re.test(theForm.fcity.value)) {
				alert(noSubMssg + "City" + tryAgain);
				theForm.fcity.focus();
				return false;
			}
			if(theForm.fstate.value == "") {
				alert(noSubMssg + "State" + tryAgain);
				theForm.fstate.focus();
				return false;
			}
			if(!re.test(theForm.fzip.value)) {
				alert(noSubMssg + "Zip Code" + tryAgain);
				theForm.fzip.focus();
				return false;
			}
			if(re.test(theForm.fzip.value)) {
				if(!reZip1.test(theForm.fzip.value) && !reZip2.test(theForm.fzip.value)) {
					alert(noSubMssg + "Zip Code" + tryAgain);
					theForm.fzip.focus();
					return false;
				}
			}
	}
	
	if (theForm.phoneme.checked == true) {
		if (!re.test(theForm.phone1.value)) {
			alert(noSubMssg + "Voice Area Code" + tryAgain);
			theForm.phone1.focus();
			return false;
		}
		if (!re.test(theForm.phone2.value)) {
			alert(noSubMssg + "Voice Number" + tryAgain);
			theForm.phone2.focus();
			return false;
		}
		if (!re.test(theForm.phone3.value)) {
			alert(noSubMssg + "Voice Number" + tryAgain);
			theForm.phone3.focus();
			return false;
		}
		if (!reArea.test(theForm.phone1.value)) {
			alert(noSubMssg2 + "Voice Area Code" + tryAgain2);
			theForm.phone1.focus();
			return false;
		}
		if (!reArea.test(theForm.phone2.value)) {
			alert(noSubMssg2 + "Voice Number" + tryAgain2);
			theForm.phone2.focus();
			return false;
		}
		if (!rePhone.test(theForm.phone3.value)) {
			alert(noSubMssg2 + "Voice Number" + tryAgain2);
			theForm.phone3.focus();
			return false;
		}
	}
	
	if (theForm.faxme.checked == true) {
		if (!re.test(theForm.fax1.value)) {
			alert(noSubMssg + "Fax Area Code" + tryAgain);
			theForm.fax1.focus();
			return false;
		}
		if (!re.test(theForm.fax2.value)) {
			alert(noSubMssg + "Fax Number" + tryAgain);
			theForm.fax2.focus();
			return false;
		}
		if (!re.test(theForm.fax3.value)) {
			alert(noSubMssg + "Fax Number" + tryAgain);
			theForm.fax3.focus();
			return false;
		}
		if (!reArea.test(theForm.fax1.value)) {
			alert(noSubMssg2 + "Fax Area Code" + tryAgain2);
			theForm.fax1.focus();
			return false;
		}
		if (!reArea.test(theForm.fax2.value)) {
			alert(noSubMssg2 + "Fax Number" + tryAgain2);
			theForm.fax2.focus();
			return false;
		}
		if (!rePhone.test(theForm.fax3.value)) {
			alert(noSubMssg2 + "Fax Number" + tryAgain2);
			theForm.fax3.focus();
			return false;
		}
	}
return true;
}


