$(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"});
  });

  $(".btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name1 = $("input#first_name").val();
		if (name1 == "") {
      $("label#name_error1").show();
      $("input#first_name").focus();
      return false;
    }
        var name2 = $("input#last_name").val();
		if (name2 == "") {
      $("label#name_error2").show();
      $("input#last_name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }

		
		var dataString = 'firstName='+ name1 + '&email=' + email + '&lastName=' + name2;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/webformmailer.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='img/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#first_name").select().focus();
});
