$(document).ready(function () {
	$.validator.addMethod("checkCaptcha"
		, function(value, element) {
			var isMatch = $.ajax({ url: "/_ui/RemoteService.cfc?"+Math.random()
							     , async: false
								 , data: {method:"checkCaptchaText", securityText:value, captchaTextHash:$("#captchaTextHash").val()}
								 , dataType: "json"
								 }).responseText;
			return isMatch == "true";
		}
		, "Security text entered does not match."
	);

	$("#forgetPasswordBlock form").validate({
		rules: {
			emailAddress: {
				required: true,
				email: true
			},
			securityText: {
				required: true,
				minlength: 6,
				checkCaptcha: true
			}
		},
		messages: {
			emailAddress: {
				required: "Please enter your email address."
			},
			securityText: {
				required: "Please enter the security text displayed.",
				minlength: ""
			}
		}	
	});
	
	$("#submit img").hover(
		function () {
			$(this).attr("src", "/img/submit_btn_over.gif");
		},
		function () {
			$(this).attr("src", "/img/submit_btn.gif");
		}
	);
	
	$("#submit img").click(function () {
		$("#forgetPasswordBlock form").submit();
	});

	$("#forgetPasswordBlock form input").keydown(function (event) {
		if (event.keyCode == 13) {
			$("#forgetPasswordBlock form").submit();
		}
	});

	$("#captchaImageBlock span").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		}
	);
	
	$("#regenerate").click(function () {
		$.getJSON( "/_ui/RemoteService.cfc?"+Math.random()
				 , {method:"regenerateCaptchaImage"}
				 , function (data) {
					$("#captchaImageBlock img").attr({src:data.IMGSRC});
					$("#captchaTextHash").val(data.HASH);		
				 });
	});
	
});
