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

  $(".formButton").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "" || name == "Enter Name...") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		if (email == "" || email == "Enter Email..." || emailPattern.test(email) == false) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
		var comments = $("textarea#comments").val();
		if (comments == "" || comments == "Enter Comments...") {
      $("label#comments_error").show();
      $("textarea#comments").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&comments=' + comments;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("")
        .append("")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
//runOnLoad(function(){
  //$("input#name").select().focus();
//});