$(document).ready(function(){ 
	
	$("#psm_form").submit(function() {
		if ($("#captcha").val() != "") {
			// create json object of form variables
			var formval = { fname:$("#fname").val(), lname:$("#lname").val(), title:$("#title").val(), org:$("#org").val(), email:$("#email").val(), phone1:$("#phone1").val(), phone2:$("#phone2").val(), phone3:$("#phone3").val(), comment:$("#comment").val(), captcha:$("#captcha").val(), captchaHash:$("#captchaHash").val() };

			// validate server side
			$.ajax({
				type: "POST",
				url: "contact_action.cfm",
				dataType: "json",
				data: formval,
				success: function(response){				
					if (response.captchatext == "true")
						{ $("#msg_captcha").text("Required").show().fadeOut(1000); }
					if ((response.fname == "true") || (response.lname == "true"))
						{ $("#msg_name").text("Required").show().fadeOut(1000); }							
					if (response.title == "true")
						{ $("#msg_title").text("Required").show().fadeOut(1000); }						
					if (response.org == "true")
						{ $("#msg_org").text("Required").show().fadeOut(1000); }	
					if (response.email == "true")
						{ $("#msg_email").text("Required").show().fadeOut(1000); }
					if ((response.captchatext == "false") && (response.fname == "false") && (response.lname == "false") && (response.title == "false")&& (response.org == "false")&& (response.email == "false"))
						{
						// html for thank you message
						$('#content-main').html('<h1>Thank you</h1><p>Thank you for contacting The Patient Safety Monitor Online. Our Client Relations Manager or another member of our support staff will contact you to discuss your inquiry. We look forward to discussing the membership program with you and answering any other questions you may have about our consulting services.</p><p><a href="/index.cfm">Return to homepage.</a></p>');
						}
				}
			});		
			return false;
			}
		$("#msg_captcha").text("Required").show().fadeOut(1000);
		return false;
	});

 });