$(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"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var first_name = $("input#first_name").val();
		if (first_name == "") {
      $("label#first_name_error").show();
      $("input#first_name").focus();
      return false;
    }
		var last_name = $("input#last_name").val();
		if (last_name == "") {
      $("label#last_name_error").show();
      $("input#last_name").focus();
      return false;
    }
		var address = $("input#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("input#address").focus();
      return false;
    }
		
		var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }
		
		
		var state = $("select#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("select#state").focus();
      return false;
    }
		
		var zip = $("input#zip").val();
		if (zip == "") {
      $("label#zip_error").show();
      $("input#zip").focus();
      return false;
    }
			
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
		var submit_by = $("input#submit_by").val();
		if (submit_by == "") {
      $("label#submit_by_error").show();
      $("input#submit_by").focus();
      return false;
    }
		
		
		var dataString = 'first_name='+ first_name + '&last_name=' + last_name + '&address=' + address + '&city=' + city + '&state=' + state + '&zip=' + zip + '&phone=' + phone + '&submit_by=' + submit_by;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/contact/bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thank you for registering</h2>")
        .append("<p>for more information about New Hampshire Commons. We will be contacting you soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#first_name").select().focus();
});
