$(function() {
  $('.error').hide();
  
  // Style single line
  $('input.text-input').css({backgroundColor:"#ffffff"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#f2f2f2"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#ffffff"});
  });
  
  // Style multi-line
  $('textarea.text-input').css({backgroundColor:"#ffffff"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#f2f2f2"});
  });
  $('textarea.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 telephone = $("input#telephone").val();
		if (telephone == "") {
      // $("label#telephone_error").show();
      $("input#telephone").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      // $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var comments = $("textarea#comments").val();
		if (comments == "") {
      // $("label#comments_error").show();
      $("textarea#comments").focus();
      return false;
    }
		
		var dataString = 'name=' + name + '&telephone=' + telephone + '&email=' + email + '&comments=' + comments;
		// alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#miniFormContact').html("<div id='message'></div>");
        $('#message').html("<h2>Your enquiry has been submitted...</h2>")
        .append("<p>Thank you for your enquiry. We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("&nbsp;");
        });
      }
     });
    return false;
	});
});

$("input#name").select().focus();

