 $(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 subject = $("input#subject").val();
		if (subject == "") {
      $("label#subject_error").show();
      $("input#subject").focus();
      return false;
    }
	
	var message = $("textarea[name='message']").val();
		if (message == "") {
      $("label#message_error").show();
      $("textarea#message").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message;
		//alert (dataString);return false;
	//$(".button").attr("disabled", "disabled"); //disable submit button to prevent rapid submission
	$(".button").hide(); //after consideration, hiding the button will be better. no visiable change visually in diasbled and normal buttons
	$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact-form').html("<div id='message'></div>");
        $('#message').html("<p>&nbsp;</p><h2><img id='checkmark' src='../img/success.png' />&nbsp;Thank you for your message.</h2>")
        .append("<p>I will be in touch as soon as I can.</p>")
		.append("<p><a href='/'>Return to the homepage</a></p>")
        .hide()
        .fadeIn(1000, function() {
          $('#message').show();
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
