$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('select.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('select.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 == "" || name == "Name...") {
      $("label#name_error").show();
      $("input#Name").focus();
      $("input#Name").val("");
      return false;
    }
		var tel = $("input#Telephone").val();
		if (tel == "") {
      $("label#tel_error").show();
      $("input#Telephone").focus();
      $("input#Telephone").val("");
      return false;
    }
		var mail = $("input#Email").val();
		if (mail == "") {
      $("label#email_error").show();
      $("input#Email").focus();
      $("input#Email").val("");
      return false;
    }
		var type = $("select#Type").val();
		if (type == "") {
      $("label#type_error").show();
      $("select#Type").focus();
      $("select#Type").val("");
      return false;
    }
		var call = $("input#Call").val();
		if (call == "") {
      $("label#call_error").show();
      $("input#Call").focus();
      $("input#Call").val("");
      return false;
    }
	  $(".button").attr("disabled", "true"); 
      $(".button").attr("src", "/images/please-wait.gif");
		
		var dataString = 'Name='+ name + '&Telephone=' + tel + '&Email=' + mail + '&Type=' + type + '&Call=' + call;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<p>Thank you for requesting a call-back, we will contact you shortly to discuss your needs.</p>")
        .hide()
        .fadeIn(1500, function() {
          //$('#message').append("<img id='checkmark' src='/images/check.png' />");
        });
      }
     });
    return false;
	});
});
//runOnLoad(function(){
  //$("input#Name").select().focus();
//});
