function validateFields() {
	var whiteSpace = /^[\s]+$/;
	
	var frmName = document.getElementById('Name');
	var frmEmail = document.getElementById('Email');

	if (frmName.value == '' || whiteSpace.test(frmName.value)) {
		alert("Please complete the name field before submitting");
		frmName.focus();
	}
	else if (frmEmail.value == '' || whiteSpace.test(frmEmail.value)) {
		alert("Please provide an email address we can contact you at");
		frmEmail.focus();
	}
	else if (!validEmail(frmEmail.value)) {
		alert("The provided email address does not appear to be valid");
		frmEmail.focus();
	} 
	else {
		processForm();
	}
}

function processForm() {
	var dSuccess = document.getElementById('emailSuccess');
	var sContact = "/scripts/xmlHttpRequest.php?contact=true&xml=true";
	var sResult = false;
	
	showProgressBar();
	dSuccess.style.display = 'none';
	
	sResult = loadXMLPosDoc(sContact, "Name=" + ajaxUrlEncode(document.getElementById('Name').value) + "&Company=" + ajaxUrlEncode(document.getElementById('Company').value) + "&Email=" + ajaxUrlEncode(document.getElementById('Email').value) + "&Telephone=" + ajaxUrlEncode(document.getElementById('Telephone').value) + "&Address=" + ajaxUrlEncode(document.getElementById('Address').value) + "&Website=" + ajaxUrlEncode(document.getElementById('Website').value) + "&Consult=" + ajaxUrlEncode(document.getElementById('Consult').value) + "&Design=" + ajaxUrlEncode(document.getElementById('Design').value) + "&Develop=" + ajaxUrlEncode(document.getElementById('Develop').value) +  "&Implement=" + ajaxUrlEncode(document.getElementById('Implement').value) + "&Photo=" + ajaxUrlEncode(document.getElementById('Photo').value) + "&OtherService=" + ajaxUrlEncode(document.getElementById('OtherService').value) + "&Comments=" + ajaxUrlEncode(document.getElementById('Comments').value) + "&Referred=" + ajaxUrlEncode(document.getElementById('Referred').value));
	
	if (!sResult) document.cForm.submit();
}

addEvent(window, 'load', ajaxContactForm, false);

