
function SendFeedback(){
	sendMail();
}


function sendMail(){
	if(contactFormModuleValidate()){
	
		var sURL 					= $('#scontactFormModuleURL').val()+'_templates/contactForm/act_emailSentConfirmation.cfm';
		
		
		$.get(sURL, {sUserEmail: $('#sUserEmail').val(), sMessage: $('#sMessage').val()}, function(data){
		    $("#emailThisContent").html(data);
		});

	}
}

function contactFormModuleValidate() {
	var bValid = true;
	$(document).ready(function() {
		// validate sent to a friend form on keyup and submit
		$("#frmcontactFormModule").validate({
			onsubmit:		true,
			onfocusout: 	false,
			onkeyup:		false,
			onclick:		false,
			
			// error messages will be displayed as paragraphs with class "error"
			errorElement: "p",
			
			// place the error labels before .formRow
			errorPlacement: function(error, element) 
			{
				error.insertBefore(element);
			},
			
			rules: {
				sUserEmail: {
					required: 		true,
					email: 			true
				},
				
				recaptcha_response_field:{
					recaptchaCheck:	$('#recaptcha_challenge_field')
				}
			},
			messages: {
				sUserEmail: "Please enter a valid email address",
				recaptcha_response_field:{recaptchaCheck: jQuery.format("Invalid captcha. Please try again")}
			}
		});
		
		bValid = $("#frmcontactFormModule").valid();
	});
	
	return bValid;
};

//this is the validate method which checks the Captcha
//this does an Ajax request which takes the two fields, performs the check, 
//then returns a 1 if it passed the check and a 0 if it fails
//also if it does fail the captcha refreshes with a new pair of words 

jQuery.validator.addMethod('recaptchaCheck', function(value) {
	var sURL 							= $('#scontactFormModuleURL').val();
	var thedata = "";

	$.ajax({
		async: false,
		url: sURL+'_templates/contactForm/act_AJAXCaptureCheck.cfm',
		dataType: 'json',
		data: {
				recaptcha_challenge_field: 	$('#recaptcha_challenge_field').val(),
				recaptcha_response_field: 	$('#recaptcha_response_field').val() 
				},
		success: function(data) {
			thedata = data;
		}
	});

	if(thedata.success == 1){
		// reload captcha, so that if other fields fail, we have a new captcha to check on!
		Recaptcha.reload(); 
		return true;
	}else if(thedata.success == 0){
		Recaptcha.reload();
		return false;
	}
}, '' );
