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

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var firstname = $("input#firstname").val();
		if (firstname == "" || firstname == "First Name *") {
      $("label#firstname_error").show();
      $("input#firstname").focus();
      return false;
    }
	  var lastname = $("input#lastname").val();
		if (lastname == "" || lastname == "Last Name *") {
      $("label#lastname_error").show();
      $("input#lastname").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "" || email == "Email Address *") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phonenumber = $("input#phonenumber").val();
		if (phonenumber == "" || phonenumber == "Phone Number *") {
      $("label#phonenumber_error").show();
      $("input#phonenumber").focus();
      return false;
    }
		
		var comments = $("textarea#comments").val();
		
		var dataString = 'firstname='+ firstname + '&lastname=' + lastname + '&email=' + email + '&phonenumber=' + phonenumber + '&comments=' + comments;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "contact-form.php",
      data: dataString,
      success: function() {
        $('#contactusform').html("<div id='message'></div>");
        $('#message').html("<span class='style7'>Contact Form Submitted!</span>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='../img/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});


