$(function(){
	$( "#commentForm input, #commentForm textarea, #user, #pass" ).each(function(){
		if( $( this ).val() != "" )
		{
			$( this ).parent().find( "label" ).css({display:"none"});
		}
		else
		{
			$( this ).parent().find( "label" ).css({display:"block"});
		}
	});
	$('p label.error').hide();
	
	$('input.text-input').css({backgroundColor:"#FFFFFF"});

	$( "#commentForm input, #commentForm textarea, #login input" ).focus(function(){
		$( this ).parents( "p" ).find( ".overlabel" ).css({display:"none"});
	});
	
	$( "#commentForm input, #commentForm textarea, #login input" ).blur(function(){
		if( $( this ).val() == "" )
		{
			$( this ).parents( "p" ).find( ".overlabel" ).css({display:"block"});
		}
	});
	
	$('input.text-input').focus(function(){
		$(this).css({backgroundColor:"#FFDDAA"});
	});
	
	$('input.text-input').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
	});
	
	$( "#commentForm" ).submit( function( e ) {
		e.preventDefault();
		
		var name		= $( "#namefield" ).val();
		var email		= $( "#emailfield" ).val();
		var phone		= $( "#phonefield" ).val();
		var comment		= $( "#commentfield" ).val();
		var security	= $( "#skey" ).val();
		
		if( security !== "4" )
		{
			$( "#security_error" ).show();
			alert( "Security question is incorrect.\n\nYou answered " + security );
			return false;
		}

		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comment=' + comment + '&security=' + security;

		$.ajax({
			type:		"POST",
			url:		postUrl + "/bin/process.php",
			data:		dataString,
			success:	function( response )
			{
				$('#requestinfo').html("<div id='message'></div>");
				$('#message').html("<h2>Contact Form Submitted!</h2>")
					.append("<p>"+response+"</p>")
					.hide()
					.fadeIn(1500, function()
					{
						$('#message').append("<img id='checkmark' src='images/check.png' />");
					});
			}
		});
		return false;
	})
	//validate form.
	.validate();
});

