$(function() {
  $('.error').hide();

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
	var product = $("input#product").val();
		if (product == "") {
      $("label#product_error").show();
      $("input#product").focus();
      return false;
    }
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phonenumber = $("input#phonenumber").val();
		if (phonenumber == "") {
      $("label#phonenumber_error").show();
      $("input#phonenumber").focus();
      return false;
    }
     
	    var enquiry = $("textarea#enquiry").val();
		if (enquiry == "") {
      $("label#enquiry_error").show();
      $("textarea#enquiry").focus();
      return false;
    }

		
		var dataString = 'product='+ product + '&name='+ name + '&email=' + email + '&phonenumber=' + phonenumber + '&enquiry=' + enquiry;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/wp-content/themes/Brown/bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Enquiry Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='/wp-content/themes/brown/images/check.png' />");
        });
      }
     });
    return false;
	});
	
   runOnLoad(function(){
  
});
	
});
