$(function() {
  $('.error').hide();
  $('input.text-input').css({borderColor:"#779db7"});
  $('input.text-input').focus(function(){
    $(this).css({borderColor:"#484848"});
  });
  $('input.text-input').blur(function(){
    $(this).css({borderColor:"#779db7"});
  });
  
  $('input.text-input2').css({backgroundColor:"#FFFFFF"});
  $('input.text-input2').focus(function(){
    $(this).css({backgroundColor:"#e9eedc"});
  });
  $('input.text-input2').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  $('select.text-input').css({backgroundColor:"#FFFFFF"});
  $('select.text-input').focus(function(){
    $(this).css({backgroundColor:"#e9eedc"});
  });
  $('select.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#e9eedc"});
  });
  $('textarea.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 organization = $("input#organization").val();
		if (organization == "") {
      $("label#organization_error").show();
      $("input#organization").focus();
      return false;
    }
	
	 var address = $("input#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("input#address").focus();
      return false;
    }
	
	
	var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
	var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
	
	
	var my_comment = $("textarea#my_comment").val();
		
		
		var dataString = 'name='+ name + '&organization='+ organization + '&address='+ address + '&phone='+ phone + '&email='+ email;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/dockwalker.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<p>Thank you for registering for</p>")
        .append("<p><b>Dockwalker Training</b></p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
