$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#fbfbfb"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#fbfbfb"});
  });
  $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
 

  $("#submit_btn").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();

		var message = $("textarea#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;
		
		$.ajax({
      type: "POST",
      url: "scripts/contact/contact.php",
      data: dataString,
      success: function() {
		$('#contact_form:hover').css("border","6px solid #81C499");
        $('#contact_form').html("<div id='feedback'></div>");
        $('#feedback').html("<h1>Contact Form Submitted!</h1>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#feedback').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
	$(':input','#contact_form')
	.not(':button, :submit, :reset, :hidden')
 	.val('')
 	.removeAttr('checked')
 	.removeAttr('selected');

    return false;
	});
});


/*runOnLoad(function(){
  $("input#name").select().focus();
});
*/
