$(function() {
  $('.error').hide();
  $('input.text-input, textarea').css({backgroundColor:"#ffffff"});
  $('input.text-input, textarea').focus(function(){
    $(this).css({backgroundColor:"#ffffff"});
  });
  $('input.text-input, textarea').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();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
	
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").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 zip = $("input#zip").val();
		if (zip == "") {
      $("label#zip_error").show();
      $("input#zip").focus();
      return false;
    }
		var comments = $("textarea#comments").val();
		var hear = $("select#hear").val();
	
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&address=' + address + '&city=' + city + '&zip=' + zip + '&comments=' + comments + '&hear=' + hear;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "php/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thank You!</h2>")
        .append("<p>Your message was sent.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='imgs/check.gif' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
