// JavaScript Document

function validateContactForm() {
	var isValid = 1;
	if (document.getElementById("First").value == "" || document.getElementById("First").value == null || document.getElementById("First").value == "* Required") {
		document.getElementById("First").value = "* Required";
		isValid = 0;
	}
	
	if (document.getElementById("Last").value == "" || document.getElementById("Last").value == null || document.getElementById("Last").value == "* Required") {
		document.getElementById("Last").value = "* Required";
		isValid = 0;
	}
	
	if (document.getElementById("Company").value == "" || document.getElementById("Company").value == null || document.getElementById("Company").value == "* Required") {
		document.getElementById("Company").value = "* Required";
		isValid = 0;
	}
	
	if (document.getElementById("Address").value == "" || document.getElementById("Address").value == null || document.getElementById("Address").value == "* Required") {
		document.getElementById("Address").value = "* Required";
		isValid = 0;
	}
	
	if (document.getElementById("Post").value == "" || document.getElementById("Post").value == null || document.getElementById("Post").value == "* Required") {
		document.getElementById("Post").value = "* Required";
		isValid = 0;
	}
	
	if (document.getElementById("Phone").value == "" || document.getElementById("Phone").value == null || document.getElementById("Phone").value == "* Required") {
		document.getElementById("Phone").value = "* Required";
		isValid = 0;
	}
	
	if (document.getElementById("Enquiry").value == "" || document.getElementById("Enquiry").value == null || document.getElementById("Enquiry").value == "* Required") {
		document.getElementById("Enquiry").value = "* Required";
		isValid = 0;
	}
	
	if (eValidate(document.getElementById("Email")) == false) {
		document.getElementById("Email").value = "Please enter a valid email";
		isValid = 0;
	}
	
	if (isValid == 1) {
		document.getElementById("enquirySubmit").click();
	}
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){return false;
		 }
		
		 if (str.indexOf(" ")!=-1){return false;
		 }

 		 return true;				
}

function eValidate(emailID){
	
	if (echeck(emailID.value)==false){
		emailID.value="";
		return false;
	}
	return true;
 }