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

  $(".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();
	var website = $("input#website").val();
	var txt = $("textarea#txt").val();
		if (txt == "") {
      $("label#txt_error").show();
      $("textarea#txt").focus();
      return false;
    }
		
	var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&txt=' + txt;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/emailerprocess.php",
      data: dataString,
      success: function() {
        $('#contactForm').html("<div id='message'></div>");
        $('#message').html("<h4>Contact Form Submitted!</h4>")
        .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();
});

