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

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  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 phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
	}
	
	var query = $("#query").val();
		if (query == "") {
      $("label#query_error").show();
      $("#query").focus();
      return false;
	}
	
 
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&query=' + query;
		//alert (dataString); return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#emailform').html("<div id='message'></div>");
        $('#message').html("<ol><li>Thank you, we'll be in touch soon.</li><li>Feel free to call us in the meantime with any of your queries.</li></ol>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
