function validateFields() {
var frmEl = document.getElementById('cForm');
var posName = document.getElementById('posName');
var posPhone = document.getElementById('posPhone');
var posBusiness = document.getElementById('posBusiness');
var posDomain = document.getElementById('posDomain');
var posHelp = document.getElementById('posHelp');
var posEmail = document.getElementById('posEmail');
var posText = document.getElementById('posText');
var whiteSpace = /^[\s]+$/;

posName.focus();

	if ( posName.value == '' || whiteSpace.test(posName.value) ) {
		alert("Please enter your full name.");
		posName.focus();
	}	
	else if ( posEmail.value == '' || whiteSpace.test(posEmail.value) ) {
		alert("Please enter your email address.");
		posEmail.focus();
	}	
	else if ( posPhone.value == '' || whiteSpace.test(posPhone.value) ) {
		alert("Please enter your phone number.");
		posPhone.focus();
	}	
	else if ( posBusiness.value == '' || whiteSpace.test(posBusiness.value) ) {
		alert("Please provide us with your business name.");
		posBusiness.focus();
	}
	else if ( posDomain.value == '' || whiteSpace.test(posDomain.value) ) {
		alert("Please provide us with your domain name.");
		posDomain.focus();
	}	
	else if ( posHelp.value == '' || whiteSpace.test(posHelp.value) ) {
		alert("Please tell us what type of help you need so that your request may be forwarded to the correct department.");
		posHelp.focus();
	}
	else if ( posText.value == '' || whiteSpace.test(posText.value) ) {
		alert("Please describe the issues you are experiencing in as much detail as possible.");
		posText.focus();
	}
	else {
		showData();
	}

}

function showContactTimer () {
	var loader = document.getElementById('loadBar');
	loader.style.display = 'block';
	sentTimer = setTimeout("hideContactTimer()",4000);
}

function hideContactTimer () {
	var loader = document.getElementById('loadBar');
	var success = document.getElementById('emailSuccess');
	// Hide the load bar alas! Done Loading
	loader.style.display = "none";
	success.style.display = "block";
	
}

var xmlHttp

function showData()
{ 
//this shows the "working" graphic when the query page is retrieving data
showContactTimer(); // quickly begin the load bar

//by setting these values to "" it prevents an undefined error. Also defining these outside of the function will add existing data to the variable which will cause an error.
var theForm = ""
var howManyElement = ""
var daString = ""


theForm = document.leadForm
//this finds the number of elements on the form and assigns the number to the howManyElement variable.
howManyElement = theForm.elements.length;


xmlHttp=GetXmlHttpObject();

//this for block creates the string with all the data in the url. The loop goes through each element and assigns the form name and the value to the string creating a "first=brian&last=collier' string if the form contains a 'first' field and a 'last' field.

for (i=0; i<howManyElement; i++){
	
 daString = daString + theForm.elements[i].name+ "="+theForm.elements[i].value+"&";

}
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
 
//the 'whichLink' variable is assigned on the page making the request. 
var url=whichLink;
url=url+"?"+daString;
url=url+"sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

//alert(url)//this is used to view the URL being sent to the query page.
}

function stateChanged() 
{ 

if (xmlHttp.readyState==4)
{ 

//document.getElementById(whichElement).innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function ajaxContact() {
var frmEl = document.getElementById('leadForm');
addEvent(frmEl, 'submit', validateFields, false);
frmEl.onsubmit = function() { return false; }
}
addEvent(window, 'load',ajaxContact, false);
