
	function validate() {
		var f = document.contact;
		var errors = [];

		if (f.name.value == ""){
			errors.push("You did not enter a name.");
			f.name.style.backgroundColor = "#FFCCCC";
		} else {
			f.name.style.backgroundColor = "#EEEEEE";
		}
		if (!isValidEmailAddress(f.email.value)){
			errors.push("You did not enter a valid email address.");
			f.email.style.backgroundColor = "#FFCCCC";
		} else {
			f.email.style.backgroundColor = "#EEEEEE";
		}
		if (f.phone.value != ""){
			if (!isValidPhoneNumber(f.phone.value)){
				errors.push("You did not enter a valid phone number with area code.\n        example: (999) Phone Number");
				f.phone.style.backgroundColor = "#FFCCCC";
			} else {
				f.phone.style.backgroundColor = "#EEEEEE";
			}
		}
		if (errors.length > 0) {
			alert(STD_ERROR_PREFIX + errors.join("\n"))
			return false;
		}
		return true;
	}


function isValidPhoneNumber(s) {
	var temp = s.replace(/\D/g, "")
	return temp.length > 9 && temp.length < 26
}

function isValidEmailAddress(s) {
	var temp = s.replace(/\s/g, "")
	return (temp.match(/^[\w\.\-]+\x40[\w\.\-]+\.\w{3}$/)) && 
			temp.charAt(0) != "." && !(temp.match(/\.\./))
}

// masking functions - attempt to parse and reformat 
// element's values as a specific datatype
// to use, tack them to the form field's onblur handler.
// document.myForm.phone_number.onblur = phoneFieldBlurHandler	
//   -> this field will now mask for phone numbers onblur
function textFieldBlurHandler() {
	this.value = this.value.trim()
}

function phoneFieldBlurHandler(phone) {
	var temp = phone.value.replace(/\D/g, "")

	if (temp.length > 9 && temp.length < 26)
		if (temp.length == 10) {
			phone.value = "(" + temp.substring(0,3) + ") " 
			phone.value += temp.substring(3,6) + "-" + temp.substring(6,10)
		}
	}

// as convenient a place as any to store this...
var STD_ERROR_PREFIX = "There were one or more problems with the form values "
STD_ERROR_PREFIX += "you entered.\nPlease check the following and try submitting "
STD_ERROR_PREFIX += "the form again:\n\n"


// like Trim( ) in vbscript. removes trailing and 
// leading whitespace from a string
String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, "")
}


// push is a quite useful method of arrays in newer 
// javascript implementations, but not in ie5-
Array.prototype.push = function(v) {
	this[this.length] = v
	return v
}