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 friend1 = document.getElementById('friend1');

	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 ( friend1.value == '' || whiteSpace.test(friend1.value) ) {
		alert("Please enter at least 1 friend's email address.");
		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 posFriend1 = document.getElementById('friend1');
	var posFriend2 = document.getElementById('friend2');
	var posFriend3 = document.getElementById('friend3');
	var posMessage = document.getElementById('message');

	// the page on the server that sends the email
	var page = "includes/emailer/sendEmailTellAFriendBigEvent.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 friend1 = cleanString(posFriend1.value);
	var friend2 = cleanString(posFriend2.value);
	var friend3 = cleanString(posFriend3.value);
	var message = cleanString(posMessage.value);

	// create the data that is to be sent
	var data = "name="+name+"&email="+email+"&message="+message+"&friend1="+friend1+"&friend2="+friend2+"&friend3="+friend3;
	// 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('tellAFriendBigEvent');
addEventForForms(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEventForForms(window, 'load',ajaxContact, false);