$(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"});
  });

  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
 $('textarea.text-input').focus(function(){
  $(this).css({backgroundColor:"#FFDDAA"});
	
  });
  $('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 email = $("input#email").val();
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 					
		if (!filter(email)) {		
	$("label#email_error").show();
     $("input#email").focus();
      return false;
    }
	
	
		var msg = $("textarea#msg").val();
		if (msg == "") {
      $("label#msg_error").show();
      $("textarea#msg").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&msg=' + msg;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h3>Thank You!</h3>")
        .append("<p>I will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='img/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
