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(document).ready(function(){							

	jQuery('#formValidate').validate({ 
		rules: { 
			HowTheSiteWasFound: { 
	        	selectNone: true 
	      	},
		  	captchacode: {
				required: true,
				captcha: true
			}
	    } //rules		
	});
	
	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 
		 });												
	});	
});
 