function validateFields() {
var frmEl = document.getElementById('cForm');
var posName = document.getElementById('posName');
var posEmail = document.getElementById('posEmail');
var posRegard = document.getElementById('reason');
var posbudget = document.getElementById('budget');
var possecurity = document.getElementById('security_code');
var posText = document.getElementById('posText');
var whiteSpace = /^[\s]+$/;
	if ( posName.value == '') {
		alert("Name should not be blank");
		posName.focus();
	}
	else if ( posEmail.value == '') {
		alert("Email should not be blank");
		posEmail.focus();
	}
	else if ( posRegard.value == 0) {
		alert("Please select atleast one reason for contact");
		posRegard.focus();
	}
	else if ( (posRegard.value == "Programming / Design" || posRegard.value == "Internet Marketing") && posbudget.value==0 ) {
		alert("Please select your budget");
		budget.focus();
	}
	else if ( posText.value == '' || whiteSpace.test(posText.value) ) {
		alert("You're trying to send an Empty Email. Please type something.");
	}
else if ( possecurity.value == '')  {
		alert("Security code should not be blank.");
		possecurity.focus();
	}
	
	else {
		sendPosEmail();
	}
}
function sendPosEmail () {
	var success = document.getElementById('emailSuccess');
	var posName = document.getElementById('posName');
	var posEmail = document.getElementById('posEmail');
	var posRegard = document.getElementById('reason');
	var posbudget = document.getElementById('budget');
	var possecurity = document.getElementById('security_code');
	var posText = document.getElementById('posText');
	
	var page = "xmlHttpRequest.php?contact=true&xml=true";
	
	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.
	//alert(possecurity.value);
	
	var stuff = "posName="+posName.value+"&posEmail="+posEmail.value+"&posReason="+posRegard.value+"&posBudget="+posbudget.value+"&possecurity="+possecurity.value+"&posText="+posText.value;
	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";
if(grabPosXML("confirmation")=="Thank you for contacting us. One of our specialists will contact you back shortly.")
{
	success.innerHTML = '<strong style="color:green;">'+grabPosXML("confirmation")+'</strong>';
}
else
{
       success.innerHTML = '<strong style="color:red;">'+grabPosXML("confirmation")+'</strong>';
}
	// Now Hijack the form elements
	for ( i=0;i<inputsLen;i++ ) {
		if ( inputs[i].getAttribute('type') == 'text' ) {
			if(grabPosXML("confirmation")=="Thank you for contacting us. One of our specialists will contact you back shortly.")
			inputs[i].value = '';
		}
	}
	for ( j=0;j<tAreasLen;j++ ) {
		if(grabPosXML("confirmation")=="Thank you for contacting us. One of our specialists will contact you back shortly.")
		{
		tAreas[j].value = '';
		}
	}
if(grabPosXML("confirmation")=="Thank you for contacting us. One of our specialists will contact you back shortly.")
{
   document.getElementById('reason').value=0;
  document.getElementById('budget').value=0;
}

}

function ajaxContact() {
var frmEl = document.getElementById('cForm');
addEvent(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEvent(window, 'load',ajaxContact, false);