function validateFields() {
	// grab the fields in the form and the form itself
	var frmEl = document.getElementById('contactUs');
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	var message = document.getElementById('message');

	var whiteSpace = /^[\s]+$/;
	var okToSend = true;
	
	// Check to see if a required field is blank or null. If so, set an error message.
	if ( name.value == '' || whiteSpace.test(name.value) ) {
		alert("Please enter your name.");
		okToSend = false;
	} else if ( message.value == '' || whiteSpace.test(message.value) ) {
		alert("Please enter a message.");
		okToSend = false;
	} else if(!emailCheck(email.value)){
		okToSend = false;
	}

	// If any of the checks for required information failed, 	
	if(okToSend == true){
		sendPosEmail();
	}
}

/**
 * Sends the actual data in the form to the server via an AJAX request.
 * Change this method to extract whatever data you need to be taken from
 * the form and uploaded to the server.
**/
function sendPosEmail () {
	// grab the fields in the form and the form itself
	var frmEl = document.getElementById('contactUs');
	var posName = document.getElementById('name');
	var posEmail = document.getElementById('email');
	var posCompany = document.getElementById('company');
	var posPhone = document.getElementById('phone');
	var posAddress = document.getElementById('address');
	var posMessage = document.getElementById('message');

	// the page on the server that sends the email
	var page = "includes/emailer/sendEmailContactUs.php?contact=true&xml=true";
	showContactTimer(); // quickly begin the load bar
	
	// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
	var name = cleanString(posName.value);
	var email = cleanString(posEmail.value);
	var company = cleanString(posCompany.value);
	var phone = cleanString(posPhone.value);
	var address = cleanString(posAddress.value);
	var message = cleanString(posMessage.value);

	// create the data that is to be sent
	var data = "name="+name+"&email="+email+"&company="+company+"&phone="+phone+"&address="+address+"&message="+message;
	// put the data into the request to be sent to the server

	loadXMLPosDoc(page,data);
}

/**
 * Cleans a string so that it can go in a string
**/
function cleanString(str){
	str = str.replace(/&/g,"**am**");
	str = str.replace(/=/g,"**eq**");
	str = str.replace(/\+/g,"**pl**");
	return str;
}

function showContactTimer () {
	var loader = document.getElementById('formSubmitButton');
	loader.innerHTML = "<img src=\"images/site/ajax-loader.gif\">";
	sentTimer = setTimeout("hideContactTimer()",6000);
}

function hideContactTimer () {
	// Replace the load bar with whatever the server sent back
	var mainPage = document.getElementById('formSubmitButton');
	mainPage.style.color="#FFFFFF";
	mainPage.innerHTML = ''+grabPosXML("confirmation");
}

function ajaxContact() {
var frmEl = document.getElementById('contactUs');
addEventForForms(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEventForForms(window, 'load',ajaxContact, false);