$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.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 phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
	var company = $("input#company").val();
	var title = $("input#title").val();
	var role = $("select#role").val();
	var address = $("input#address").val();
	var city = $("input#city").val();
	var state = $("select#state").val();
	var date = $("input#date").val();
	var group = $("input#group").val();
	var purpose = $("input#purpose").val();
	var etime = $("input#etime").val();
	var attendees = $("input#attendees").val();
	var message =$("textarea#message").val();
		
		var dataString = '&name='+ name + '&email=' + email + '&phone=' + phone + '&company=' + company + '&title=' + title+ '&role=' + role + '&address=' + address + '&city=' + city + '&state=' + state + '&date=' + date + '&group=' + group + '&purpose=' + purpose + '&etime=' + etime + '&attendees=' + attendees + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "a/bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Event Request Contact Form Submitted!</h2>")
        .append("<p> A representative will contact you right away.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='a/images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});