$(function() {
  $('.error').hide();
  $('.text-input').css({backgroundColor:"#FFFFFF"});
  $('.text-input').focus(function(){
    $(this).css({backgroundColor:"#F1F1F1"});
  });
  $('.text-input').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 street = $("input#street").val();
		if (street == "") {
      $("label#street_error").show();
      $("input#street").focus();
      return false;
    }
    	var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		var desc = $("textarea#desc").val();
		if (desc == "") {
      $("label#desc_error").show();
      $("input#desc").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&street=' + street + '&phone=' + phone + '&desc=' + desc;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/wp-content/themes/baca/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Form Submitted!<br />Thanks!</h2><script>_gaq.push(['_trackPageview', '/form-submitted.php'])</script>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append(); //"<img id='checkmark' src='<?php bloginfo('template_url'); ?>/images/check.png' />"
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

