$(function() {
  $('.error').hide();
  $('.text-input, .phone-text-input').css({backgroundColor:"#FFFFFF"});
  $('.text-input, .phone-text-input').focus(function(){
    $(this).css({backgroundColor:"#ffff00"});
  });
  $('.text-input, .phone-text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".submit-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 phone1 = $("input#phone1").val();
		
		var phone2 = $("input#phone2").val();
		
		var phone3 = $("input#phone3").val();
	
		var message = $("textarea#message").val();
		if (message == "") {
      $("label#message_error").show();
      $("textarea#message").focus();
      return false;
    }
	
		var hidden = $("input.hidden").val();
		if (hidden != "") {
      return false;
    }
	
	
		
		var dataString = 'name='+ name + '&email=' + email + '&phone1=' + phone1 + '&phone2=' + phone2 + '&phone3=' + phone3 + '&message=' + message;
		//var htmlStr = $('#contact_form').html();

		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "contact/contactengine.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<img id='checkmark' src='images/wrench.png' /><div id='thanks'></div>");
        $('#thanks').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(500);
		/*
		$('a.reload').click(function(){
			  $('#contact_form').html(htmlStr);
		});
		*/
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

