function validate(theForm) {
	var eMailField = theForm.email;
	var subjectField = theForm.subject;
	var messageField = theForm.message;
	// validate email first
	var eMailPattern = /\w{2,}@\w{2,}\.\w{2,}/i;
	var eMailInput = eMailField.value;
	var goodAddy = eMailInput.match(eMailPattern);
	if(eMailInput == null || eMailInput == ""){
		alert("Please enter your email address.");
		eMailField.focus();
		return false;
	}else if (goodAddy == null) {
		alert("Please enter a valid email address.");
		eMailField.focus();
		return false;
	} else if(subjectField.value == null || subjectField.value == ""){
		alert("Please enter a subject for your message.");
		subjectField.focus();
		return false;
	}else if(messageField.value == null || messageField.value == ""){
		alert("Please include a message or I won't know why you are contacting me.");
		messageField.focus();
		return false;
	}else if(messageField.value.length < 40){
		alert("Please include a message at least 40 characters long.");
		messageField.focus();
		return false;
	}else {
		return true;
	}
}

function phoneTest(theForm) {
	var fName = theForm.fName.value;
	var lName = theForm.lName.value;
	var title = theForm.title.value;
	var cName = theForm.cName.value;
	var city = theForm.city.value;
	var state = theForm.state.value;
	var country = theForm.country.value;
	var phone = theForm.phone.value;
	var eMailv = theForm.eMail.value;
	var chk1 = phone.indexOf("1",1);
	var chk2 = phone.indexOf("2",1);
	var chk3 = phone.indexOf("3",1);
	var chk4 = phone.indexOf("4",1);
	var chk5 = phone.indexOf("5",1);
	var chk6 = phone.indexOf("6",1);
	var chk7 = phone.indexOf("7",1);
	var chk8 = phone.indexOf("8",1);
	var chk9 = phone.indexOf("9",1);
	var chk0 = phone.indexOf("0",1);
	var chkA = phone.indexOf(".",3);

		if ((chk1 == -1) && (chk2 == -1) && (chk3 == -1) && (chk3 == -1) && (chk4 == -1) && (chk5 == -1) &&
			 (chk6 == -1) && (chk7 == -1) && (chk8 == -1) && (chk9 == -1) && (chk0 == -1)){
				alert("Please enter your phone number in the format 123.456.7890.");
				theForm.phone.focus();
			}
		else if (chkA == -1){
				alert("Please enter your phone number in the format 123.456.7890.");
				theForm.phone.focus();
			}
		else if (phone == "123.456.7890") {
				alert("Please enter your phone number in the format 123.456.7890.");
				theForm.phone.focus();
			}
		else if (fName.length == 0) {
				alert("Please enter your first name.");
				theForm.fName.focus();
			}
		else if (lName.length == 0) {
				alert("Please enter your last name.");
				theForm.lName.focus();
			}
		else if (title.length == 0) {
				alert("Please enter your title or position.");
				theForm.title.focus();
			}
		else if (cName.length == 0) {
				alert("Please enter the name of your company.");
				theForm.cName.focus();
			}
		else if (city.length == 0) {
				alert("Please enter your city.");
				theForm.city.focus();
			}
		else if (state.length == 0) {
				alert("Please enter your state or province. If not applicable, simply enter 'na'.");
				theForm.state.focus();
			}
		else if (country.length == 0) {
				alert("Please enter your country.");
				theForm.country.focus();
			}
		else if (eMailv.length == 0) {
				alert("Please enter your email address.");
				theForm.eMail.focus();
			}
		else theForm.submit();
}

function clearField(theFormField) {
	theFormField.value = "";
}
	
	