$(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 email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("select#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("select#phone").focus();
      return false;
    }

var enqtype = $("input#enqtype").val();
var enqtype1 = $("input#enqtype1").val();
var enqtype2 = $("input#enqtype2").val();
var enqtype3 = $("select#enqtype3").val();
var enqtype4 = $("input#enqtype4").val();
var enquiry = $("textarea#enquiry").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&enqtype=' + enqtype + '&enqtype1=' + enqtype1 + '&enqtype2=' + enqtype2 + '&enqtype3=' + enqtype3 + '&enqtype4=' + enqtype4 + '&enquiry=' + enquiry;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thankyou for your enquiry</h2>")
        .append("<p>We will be in touch soon.</p><a style='color:white;font-family:Verdana, Helvetica, sans-serif;font-weight:bold;font-size:0.8em;' href='index.php'>Return to Home page</a>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
