function resetForm(empty_fields){
	$('#comment_form input:text').attr({
		style: ""
	});
	
	if(empty_fields) $('#comment_form input:text, textarea').val("");
}

$(document).ready(function(){	
	//prepare passcode form for AJAX submission
	var options = { 
		target:     '#form_response',
		dataType: "script",
		success:    function() { 
			resetForm(true); 
		} 
	}; 

	// bind to the form's submit event 
    $('#comment_form').submit(function() {
									   
		//reset styles
		resetForm(false);
		
		$("#form_response").html("Whisking your info away...").show("slow"); 
		
		//validate
		var valid = true;
		$("input:text", this).each(function(){
		
			if($(this).attr("name") == "email"){
				if($(this).val().indexOf("@") == -1 || $(this).val().indexOf(".")== -1){
					$("#form_response").html("Please enter a valid email address.").show("slow");
					$(this).css({border: "2px solid #990000"});
					valid = false;
				}
			}
			
			if($(this).val() == "") {
				$("#form_response").html("Please enter your first name, last name and email address.").show("slow");
				$(this).css({border: "2px solid #990000"});
				valid = false;
			}

		});
		
		if(!valid) return false;
 		
		$(this).ajaxSubmit(options);
		
        // return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
	
	//SETUP EVENT HANDLERS	
	$("#submit_btn").click(function(){
		$("#comment_form").submit(); 							
	});

	
});