$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".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 e_mail = $("input#e_mail").val();
		if (e_mail == "") {
      $("label#e_mail_error").show();
      $("input#e_mail").focus();
      return false;
    }
		var tel = $("input#tel").val();
		if (tel == "") {
      $("label#tel_error").show();
      $("input#tel").focus();
      return false;
    }
	
		    var make = $("input#make").val();
		if (make == "") {
      $("label#make_error").show();
      $("input#make").focus();
      return false;

    }
		var model = $("input#model").val();
		if (model == "") {
      $("label#model_error").show();
      $("input#model").focus();
      return false;
    }
		var dropoff = $("input#dropoff").val();
		if (dropoff == "") {
      $("label#dropoff_error").show();
      $("input#dropoff").focus();
      return false;
    }
		
		var comment = $("textarea#comment").val();
		if (comment == "") {
      $("label#comment_error").show();
      $("textarea#comment").focus();
      return false;
    }	
		var dataString = '&name=' + name + '&e_mail=' + e_mail + '&tel=' + tel + '&make=' + make + '&model=' + model + '&dropoff=' + dropoff + '&comment=' + comment;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/booking-form.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Booking sent.</h2>")
        .append("<p>Thank you for your booking enquiry 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();
});

