function checkForm() {

	var first = document.getElementById("first").value;
	
	var last = document.getElementById("last").value;

	var email = document.getElementById("email").value;

	var comment = document.getElementById("comment").value;

	if (first == "") {

		hideAllErrors();

		document.getElementById("firstError").style.display = "inline";

		document.getElementById("first").select();

		document.getElementById("first").focus();

		return false;

	} if (last == "") {

		hideAllErrors();

		document.getElementById("lastError").style.display = "inline";

		document.getElementById("last").select();

		document.getElementById("last").focus();

		return false;

	}if (email == "" || email.indexOf("@") == -1 || email.indexOf(".") == -1) {

		hideAllErrors();

		document.getElementById("emailError").style.display = "inline";

		document.getElementById("email").select();

		document.getElementById("email").focus();

		return false;

	} if (comment == "") {

		hideAllErrors();

		document.getElementById("commentError").style.display = "inline";

		document.getElementById("comment").select();

		document.getElementById("comment").focus();

		return false;

	} else {

	    hideAllErrors();

        document.getElementById("loading_gif").style.display = "block";

	    sendemail();

		return true;

		

	}

}

function hideAllErrors() {

	document.getElementById("firstError").style.display = "none";
	
	document.getElementById("lastError").style.display = "none";

	document.getElementById("emailError").style.display = "none";

	document.getElementById("commentError").style.display = "none";

}



/* AJAX CALL*/

function createRequestObject() {

	var ro;

	var browser = navigator.appName;

	if (browser == "Microsoft Internet Explorer") {

		ro = new ActiveXObject("Microsoft.XMLHTTP");

	} else {

		ro = new XMLHttpRequest();

	}

	return ro;

}

var http = createRequestObject();

function sendemail() {

	var first = document.contactform.first.value;
	
	var last = document.contactform.last.value;
		
	var phone = document.contactform.phone.value;

	var email = document.contactform.email.value;
	
	var comment = document.contactform.comment.value;

	document.contactform.send.disabled = true;

	document.contactform.send.value = 'Sending....';

	http.open('get', 'contact.php?first='+first+'&last='+last+'&phone='+phone+'&email='+email+'&comment='+comment+'&action=send');

	http.onreadystatechange = handleResponse;

	http.send(null);

}

function handleResponse() {

	if (http.readyState == 4) {

		var response = http.responseText;

		var update = new Array();

		if (response.indexOf('|' != -1)) {

			update = response.split('|');

			document.getElementById(update[0]).innerHTML = update[1];

		}

	}

}
