$(document).ready(function(){
	
	//add click handler to submit button	
	$("#imageSubmit").click(function(e){
		e.preventDefault();
		var formName = document.forms[0].name;
		validateForm(formName)
	});
	
	function validateForm(formid){
		
		var datastring=$('form#'+formid).serialize();
		$.ajax({
			type: "POST",
			url: "/com/assets/formValidator/formValidator.cfm",
			data: datastring,
			async:false,
			success: function(response){
				var resp = jQuery.trim(response);
				if (resp != "") {
					//show error message in sliding div
					scroll(0,0);
					$('#errorDisplayText').html(response);
					$('#errorDisplayText').append("<div id='sliderClose'></div>");
					$("#errorDisplayText").slideDown("slow");

					//add click handler to error close slider	
					$("#sliderClose").click(function(){
						$("#errorDisplayText").slideUp("slow");
					});
				}else{
					//submit form
					$('#errorDisplayText').hide();
					$('form#'+formid).submit();
				}
			}
		});
	}

	
	
});
