$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#F3F3F3"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#B5B3B3"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#F3F3F3"});
  });
  $('textarea.text-input').css({backgroundColor:"#F3F3F3"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#B5B3B3"});
  });
  $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#F3F3F3"});
  });



  $(".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 dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "func/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Hey, thanks for reaching out.</h2>")
        .append("<p>Most likely you&rsquo;ll hear from me quickly, but it&rsquo;s possible I might be out. So if you don&rsquo;t hear from me immediately, <strong>don&rsquo;t lose hope...</strong></p>")
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
