
	function clearText(field){
	    if (field.defaultValue == field.value) field.value = '';
	    else if (field.value == '') field.value = field.defaultValue;
	}	

	function checkEmail(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);
	}


$(function(){



	$(".submit-button").click(function() {

		var title = $("input#title").val();
		var firstname = $("input#firstname").val();
		var lastname = $("input#lastname").val();
		var telephone = $("input#telephone").val();
		var email = $("input#email").val();
		var house = $("input#house").val();
		var address = $("input#address").val();
		var postcode = $("input#postcode").val();
    var emailValid = checkEmail(email);

		if (title == "Title" || title=="") {
          $("input#title").focus();
          $("input#title").css("border","1px solid red");
          $("input#title").css("background-color","pink");
          $("input#title").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#title").css("border","1px solid #00274C");
          $("input#title").css("background-color","white");
          $("input#title").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	
		if (firstname == "First Name" || firstname=="") {
          $("input#firstname").focus();
          $("input#firstname").css("border","1px solid red");
          $("input#firstname").css("background-color","pink");
          $("input#firstname").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#firstname").css("border","1px solid #00274C");
          $("input#firstname").css("background-color","white");
          $("input#firstname").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	var lastname = $("input#lastname").val();
		if (lastname == "Last Name" || lastname=="") {
          $("input#lastname").focus();
          $("input#lastname").css("border","1px solid red");
          $("input#lastname").css("background-color","pink");
          $("input#lastname").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#lastname").css("border","1px solid #00274C");
          $("input#lastname").css("background-color","white");
          $("input#lastname").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	var telephone = $("input#telephone").val();
		if (telephone == "Phone Number" || telephone=="") {
          $("input#telephone").focus();
          $("input#telephone").css("border","1px solid red");
          $("input#telephone").css("background-color","pink");
          $("input#telephone").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#telephone").css("border","1px solid #00274C");
          $("input#telephone").css("background-color","white");
          $("input#telephone").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	var email = $("input#email").val();
		if (email == "Email Address" || email=="" || emailValid==false) {
          $("input#email").focus();
          $("input#email").css("border","1px solid red");
          $("input#email").css("background-color","pink");
          $("input#email").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#email").css("border","1px solid #00274C");
          $("input#email").css("background-color","white");
          $("input#email").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	var house = $("input#house").val();
		if (house == "House No." || house=="") {
          $("input#house").focus();
          $("input#house").css("border","1px solid red");
          $("input#house").css("background-color","pink");
          $("input#house").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#house").css("border","1px solid #00274C");
          $("input#house").css("background-color","white");
          $("input#house").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	var address = $("input#address").val();
		if (address == "Address" || address=="") {
          $("input#address").focus();
          $("input#address").css("border","1px solid red");
          $("input#address").css("background-color","pink");
          $("input#address").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#address").css("border","1px solid #00274C");
          $("input#address").css("background-color","white");
          $("input#address").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	var postcode = $("input#postcode").val();
		if (postcode == "Postcode" || postcode=="") {
          $("input#postcode").focus();
          $("input#postcode").css("border","1px solid red");
          $("input#postcode").css("background-color","pink");
          $("input#postcode").css("background","url(../images/exclamation.png) no-repeat right pink");
          return false;
      	} else {
      	  $("input#postcode").css("border","1px solid #00274C");
          $("input#postcode").css("background-color","white");
          $("input#postcode").css("background","url(../images/asterisk.png) no-repeat right white");
      	}

      	

	});

});

