var onCaptchaEventComplete = new YAHOO.util.CustomEvent("CaptchaValidationComplete");

function validateCaptcha (oForm) {

	var validateUrl="/common_scripts/cfm/validateCaptcha.cfm?captcha=" + document.getElementById("captcha").value + "&hash=" + document.getElementById("hash").value;

	YAHOO.util.Connect.asyncRequest('GET', validateUrl, {
		success: function (oResponse) {
			var response = oResponse.responseText.replace(/^\s+|\s+$/g,"");
			var CaptchaResponse = {oForm: oForm, ValidationPassed:false, CaptchaInputString:document.getElementById("captcha").value, errorMessage: "You have entered an invalid Spam Validation code.  Please re-enter the new code."};

			if ( response == 'Success') {
				CaptchaResponse.ValidationPassed = true;
			} else {
				refreshCaptcha();
			}

			onCaptchaEventComplete.fire(CaptchaResponse);
		},
		failure: function (oResponse) {
			alert('Unable To Validate Captcha.');
		}
	});

}

function refreshCaptcha() {
	var refreshUrl = "/common_scripts/cfm/rebuildCaptcha.cfm?x="+Math.random();

		YAHOO.util.Connect.asyncRequest('GET', refreshUrl,
			{
				success: function (oResponse) {

					var response = oResponse.responseText.replace(/^\s+|\s+$/g,"");

					document.getElementById("hash").value = response;
					document.getElementById("captchaImage").src = "/common_scripts/cfm/captcha.cfm?hash=" + response;
					document.getElementById("captcha").value = '';

				},
				failure: function (oResponse) {
					alert('Unable To Refresh Captcha.');
				}
			},
		null);
}

function dspCaptchaHelp(){
	if (document.getElementById("captcha_instructions").style.display=='none') {
		document.getElementById("captcha_instructions").style.display = '';
	} else {
		document.getElementById("captcha_instructions").style.display = 'none';
	}
}