// Adapted from http://snipplr.com/view/15563/jquery-validating-recaptcha-with-ajax/

// Validate the Recaptcha' Before continuing with POST ACTION
function ValidateCaptcha()
{
	challengeField = $("input#recaptcha_challenge_field").val();
	responseField = $("input#recaptcha_response_field").val();

	var html = $.ajax({
		type: "POST",
		url: "/ajax/recaptcha.php",
		data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
		async: false
	}).responseText;

	if(html == "success") {
		return true;
	} else {
		Recaptcha.reload();
		return false;
	}
}

function ValidateCaptchaMsg(msg)
{
	// if there are other errors then do not test the catcha out yet,
	// as the user would be forced to type in a new captcha when they try to fix the other errors on the form
	if (msg != '')
		return "";

	var captcha_msg = "";
	var is_valid_recaptcha = ValidateCaptcha();
	if (!is_valid_recaptcha)
		captcha_msg += "Please enter the correct security code.\n\n";

	return captcha_msg;
}


