$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#75daff"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#75daff"});
  });
  $('select.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('select.text-input').css({backgroundColor:"#FFFFFF"});
  $('select.text-input').focus(function(){
    $(this).css({backgroundColor:"#75daff"});
  });
  $('select.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 email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var address = $("textarea#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("textarea#address").focus();
      return false;
    }
	var telephone = $("input#telephone").val();
		if (telephone == "") {
      $("label#telephone_error").show();
      $("input#telephone").focus();
      return false;
    }
	var reason = $("select#reason").val();
		if (reason == "") {
      $("label#reason_error").show();
      $("select#select").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&address=' + address + '&telephone=' + telephone + '&reason=' + reason;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/cgi-bin/contact.pl",
      data: dataString,
      success: function() {
        $('#locator').html("<div id='thankyou'></div>");
        $('#thankyou').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>Your form was successfully submitted! We will contact you shortly.</p>")
		.append("<p>Thank you,</p>")
		.append("<span>Arctic Air, Inc.</span>")
		.hide()
        .fadeIn(1500, function() {
          $('#thankyou').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
