$(function() {
  $('.error').hide();
  $('.text-input').css({backgroundColor:"#FFFFFF"});
  $('.text-input').focus(function(){
    $(this).css({backgroundColor:"#F4FBFF"});
  });
  $('.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("#name").val();
		if (name == "") {
      $("#name_error").show();
      $("#name").focus();
      return false;
    }
		var email = $("#email").val();
		if (email == "") {
      $("#email_error").show();
      $("#email").focus();
      return false;
    }
		var phone = $("#phone").val();
		if (phone == "") {
      $("#phone_error").show();
      $("#phone").focus();
      return false;
    }
		var meet = $("#meet").val();
		if (meet == "") {
      $("#meet_error").show();
      $("#meet").focus();
      return false;
    }
		var comment = $("#comment").val();
		var referrer = $("#referrer").val();
		
		var dataString = 'name='+ name.replace(/ /gi,'_') + '&email=' + email + '&phone=' + phone.replace(/ /gi,'_') + '&meet=' + meet.replace(/ /gi,'_') + '&comment=' + comment.replace(/ /gi,'_')+ '&referrer=' + referrer.replace(/ /gi,'_');
		//alert (dataString);return true;
		
		$.ajax({
      type: "POST",
      url: "formProcessing.asp",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Your request for a free consultation has been received.</h2>")
        .append("<p>Thank you for your trust and confidence. Joel Sanders's assistant (Jaeda) will be in touch with you shortly.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<p>Raise your expectations.</p>");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("#name2").select().focus();
});

