


$(function(){

	$("input:not('#submit')").addClass("gray");
	$("textarea").addClass("gray");
	
	var inputVal = null;
	
	$("input").focus(function(){
		inputVal = $(this).val();
		var grayClass = $(this).attr("class");
		if (grayClass.indexOf("gray") > -1) {
			$(this).removeClass("gray").val("");
		}
	});
	
	$("textarea").focus(function(){
		inputVal = $(this).val();
		var grayClass = $(this).attr("class");
		if (grayClass.indexOf("gray") > -1) {
			$(this).removeClass("gray").val("");
		}
	});
	
	//clear errors if new text is input
	$("input:not('#submit')").blur(function(){
		//put labels back
		inputVal_temp = $(this).val();
		if (inputVal_temp == "First Name" || inputVal_temp == "Last Name" || inputVal_temp == "Email Address" || inputVal_temp == ""){
			 $(this).addClass('gray').val(inputVal);	
		}
		
		var errorClass = $(this).attr("class");
		if (errorClass.indexOf("error") > -1) {
			if ($(this).val() != "First Name" || $(this).val() != "Last Name" || $(this).val() != "Email Address" || $(this).val() != "") $(this).removeClass("error");
		}
	});
	
	$("form").live("submit",function(event){
		//event.preventDefault();
		var errors = false;
		//validate fields
		if ($("#first_name").val() == "First Name" || $("#first_name").val() == "") {
			$("#first_name").addClass("error");
			errors = true;
		}
		if ($("#last_name").val() == "Last Name" || $("#last_name").val() == "") {
			$("#last_name").addClass("error");
			errors = true;
		}
		if ($("#email").val() == "Email Address" || $("#email").val() == "") {
			$("#email").addClass("error");
			errors = true;
		}
		
		$(".error:first").focus();
		
		//submit form if no errors
		if (errors == false){
			if ($("#comments").val() == "Comments") $("#comments").val("");
			return true;
		}else{
			return false;
		}
		
	});

});