$(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();
		
		// name reqd
	    var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		// organization
	    var organization = $("input#organization").val();
//		if (organization == "") {
//      $("label#organization_error").show();
//      $("input#organization").focus();
//      return false;
//    }
		// email reqd
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		// address1 reqd
		var address1 = $("input#address1").val();
		if (address1 == "") {
      $("label#address1_error").show();
      $("input#address1").focus();
      return false;
    }	
		// address2
		var address2 = $("input#address2").val();
//		if (address2 == "") {
//      $("label#address2_error").show();
//      $("input#address2").focus();
//      return false;
//    }	
		// city reqd
		var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }	
		// state reqd
		var state = $("input#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("input#state").focus();
      return false;
    }	
		// zip reqd
		var zip = $("input#zip").val();
		if (zip == "") {
      $("label#zip_error").show();
      $("input#zip").focus();
      return false;
    }	
		// phone reqd
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }	
		// comments reqd
		var comment = $("textarea#comment").val();
		if (comment == "") {
      $("label#comment_error").show();
      $("input#comment").focus();
      return false;
    }	
		
		var dataString = 'name='+ name + '&organization=' + organization + '&email=' + email + '&address1=' + address1 + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&zip=' + zip + '&phone=' + phone + '&comment=' + comment;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thanks for contacting W.L. Jaggars.</h2>")
        .append("<p>We will be in touch soon!</p>")
        .hide()
        .fadeIn(500, function() {
          $('#message').append("<img id='checkmark' src='img/other/check.gif' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

