

$(document).ready(function(){
    
	$("#contact_form").submit( function(){ return validate(); });	
		
	function validate()
	{
		$("#FName_error").html("");
		$("#LName_error").html("");
		$("#Email_error").html("");
		$("#CEmail_error").html("");
		var valid=true;
		if($("#FName").val()==""){
			$("#FName_error").html("Please enter your first name");
			valid=false;
		}
		if($("#LName").val()==""){
			$("#LName_error").html("Please enter your last name");
			valid=false;
		}
		if($("#Email").val()==""){
			$("#Email_error").html("Please enter your email address");
			valid=false;
		}
		else if(!isValidEmailAddress($("#Email").val())){
			$("#Email_error").html("Please enter a valid email address");
			valid=false;
		}
		if($("#CEmail").val()==""){
			$("#CEmail_error").html("Please confirm your email address");
			valid=false;
		}
		return valid;
	}
  });  
  
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	};
	
