jQuery.validator.addMethod(
	"captcha",
	function(value, element) {
	
		var checker = false;
		
		jQuery.ajax({
			type: 'POST',
			url: '/ajax/captchacode',
			data: {'captchacode' : value, 'method' : 'normal'},
			success: function(data,textStatus){																								
				checker = data.Captcha;
			},
			dataType:'json',
			async:false 
		 });
		return this.optional(element) || checker;	
	}, 
	"Please check you have entered the correct letters/numbers"
);

jQuery.validator.addMethod( 
	"selectNone", 
	function(value, element) { 
			if (element.value == "none") 
		{ 
	return false; 
	} 
	else return true; 
	}, 
	"Please select an option." 
); 


jQuery(document).ready(function(){							
	
	jQuery.validator.passwordRating.messages = {
		"similar-to-username": "Too similar to username",
		"too-short": "Too short",
		"very-weak": "Very weak (Use a combination of numbers, uppercase and lowercase)",
		"weak": "Weak (Use a combination of numbers, uppercase and lowercase)",
		"good": "Acceptable you may confirm and submit (to improve use a combination of numbers, uppercase and lowercase)",
		"strong": "Strong please confirm below"
	}

	jQuery('#formValidate').validate({ 
		rules: { 
			HowTheSiteWasFound: { 
	        	selectNone: true 
	      	},
		  	captchacode: {
				required: true,
				captcha: true
			},
			HBSPassword: {
				password: "#HBSEmail"
			},
			HBSpassword_confirm: {
				required: true,
				equalTo: "#HBSPassword"
			},
			HBSOrganisationType: {
				selectNone: true
			}
	    }, //rules		
		messages: {
			HBSpassword_confirm: {
				required: "Repeat your password",
				minlength: jQuery.format("Enter at least {0} characters"),
				equalTo: "Enter the same password as above"
			}
		}		
	});
	jQuery('#changeCaptcha').click(function(){

		jQuery.ajax({
			type: 'POST',
			url: '/ajax/captchacode',
			data: {'method' : 'reset'},
			success: function(data,textStatus){	
				var now = new Date();
				jQuery('#imgCaptcha').attr('src','/images/captcha.jpg?x='+now.toUTCString());
			},
			dataType:'json',
			async:false 
		 });												
	});	
});
 