/**
 * 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){
		 //  alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


$(document).ready(function(){
	
	$("#brochure_request").submit(function(){
		if($("#sHouseNumber").val()==""){
			alert("Please enter a house number");
			return false;
		}else if($("#sStreet").val()==""){
			alert("Please enter a street name");
			return false;
		}else if($("#sTown").val()==""){
			alert("Please enter a town name");
			return false;
		}else if($("#sPostcode").val()==""){
			alert("Please enter a postcode");
			return false;
		}else{
			return true;
		}
	});
	
	$("#contact_form").submit(function(){
		if($("#sName").val()=="" || $("#sName").val()=="Enter your name here" ){
			alert("Please enter a name");
			return false;
		}else if($("#sEmail").val()=="" || !echeck($("#sEmail").val()) || $("#sEmail").val()=="Enter your email here" ){
			alert("Please enter a valid email address");
			return false;
		}else if($("#sQuery").val()==""){
			alert("Please enter some details for your enquiry");
			return false;
		}else{
			return true;
		}
	});

});//end $(document).ready
