function validateFields() {
var frmEl = document.getElementById('cForm');
var posName = document.getElementById('posName');
var posEmail = document.getElementById('posEmail');
var posText = document.getElementById('posText');
var posPhone = document.getElementById('posPhone');
var posAddyA = document.getElementById('posAddyA');
var posAddyB = document.getElementById('posAddyB');
var posCPref = "";
var whiteSpace = /^[\s]+$/;
	
	if ( posName.value == '' ) {
		alert("One or more of the fields on the Contact Form is empty. Please make sure you have entered your name and then resubmit.");
	}
	else if ( posPhone.value == '' ) {
		alert("One or more of the fields on the Contact Form is empty. Please make sure you have entered your phone number and then resubmit.");
	}
	else if ( posAddyA.value == '' ) {
		alert("One or more of the fields on the Contact Form is empty. Please make sure you have entered your complete address and then resubmit.");
	}
	else if ( posAddyB.value == '' ) {
		alert("One or more of the fields on the Contact Form is empty. Please make sure you have entered your complete address and then resubmit.");
	}
	else if ( posEmail.value == '' ) {
		alert("One or more of the fields on the Contact Form is empty. Please make sure you have entered your email address and then resubmit.");
	}
	else if ( posText.value == '' || whiteSpace.test(posText.value) ) {
		alert("One or more of the fields on the Contact Form is empty. Please make sure you have entered a message and then resubmit.");
	}
	else {
		sendPosEmail();
	}
}
function sendPosEmail () {
	var frmEl = document.getElementById('cForm');
	var success = document.getElementById('emailSuccess');
	var posName = document.getElementById('posName');
	var posEmail = document.getElementById('posEmail');
	var posText = document.getElementById('posText');
	var posPhone = document.getElementById('posPhone');
	var posAddyA = document.getElementById('posAddyA');
	var posAddyB = document.getElementById('posAddyB');
	var posCPref = document.getElementById('RadioGroup1_0');
	var page = "forms/scripts/xmlHttpRequest.php?contact=true&xml=true";
	
	if ( document.cForm.RadioGroup1[1].checked ) {
		posCPref = document.getElementById('RadioGroup1_1');
		}
	
	showContactTimer(); // quickly begin the load bar
	success.style.display = 'none'; // hide the success bar (incase this is a multi-email
	
	// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
	var str1 = posName.value;
	str1 = str1.replace(/&/g,"**am**");
	str1 = str1.replace(/=/g,"**eq**");
	str1 = str1.replace(/\+/g,"**pl**");
	var str2 = posEmail.value;
	str2 = str2.replace(/&/g,"**am**");
	str2 = str2.replace(/=/g,"**eq**");
	str2 = str2.replace(/\+/g,"**pl**");
	var str3 = posText.value;
	str3 = str3.replace(/&/g,"**am**");
	str3 = str3.replace(/=/g,"**eq**");
	str3 = str3.replace(/\+/g,"**pl**");
	var str4 = posPhone.value;
	str4 = str4.replace(/&/g,"**am**");
	str4 = str4.replace(/=/g,"**eq**");
	str4 = str4.replace(/\+/g,"**pl**");
	var str5 = posAddyA.value;
	str5 = str5.replace(/&/g,"**am**");
	str5 = str5.replace(/=/g,"**eq**");
	str5 = str5.replace(/\+/g,"**pl**");
	var str6 = posAddyB.value;
	str6 = str6.replace(/&/g,"**am**");
	str6 = str6.replace(/=/g,"**eq**");
	str6 = str6.replace(/\+/g,"**pl**");
	var str7 = posCPref.value;
	str7 = str7.replace(/&/g,"**am**");
	str7 = str7.replace(/=/g,"**eq**");
	str7 = str7.replace(/\+/g,"**pl**");
	
	var stuff = "&posName="+str1+"&posEmail="+str2+"&posText="+str3+"&posPhone="+str4+"&posAddyA="+str5+"&posAddyB="+str6+"&posCPref="+str7;
	loadXMLPosDoc(page,stuff)
}
function showContactTimer () {
	var loader = document.getElementById('loadBar');
	loader.style.display = 'block';
	sentTimer = setTimeout("hideContactTimer()",6000);
}

function hideContactTimer () {
	var loader = document.getElementById('loadBar');
	var success = document.getElementById('emailSuccess');
	var fieldArea = document.getElementById('contactFormArea');
	var inputs = fieldArea.getElementsByTagName('input');
	var inputsLen = inputs.length;
	var tAreas = fieldArea.getElementsByTagName('textarea');
	var tAreasLen = tAreas.length;
	// Hide the load bar alas! Done Loading
	loader.style.display = "none";
	success.style.display = "block";
	success.innerHTML = '<strong style="color:green;">'+grabPosXML("confirmation")+'</strong>';
	// Now Hijack the form elements
	for ( i=0;i<inputsLen;i++ ) {
		if ( inputs[i].getAttribute('type') == 'text' ) {
			inputs[i].value = '';
		}
	}
	for ( j=0;j<tAreasLen;j++ ) {
		tAreas[j].value = '';
	}
}

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