/*
	captcha/jquery.captcha.startup.js 
	Carl Jagt, March 2011
*/

jQuery.fn.captcha = function() {
	var o = $(this[0]);
	jQuery('#refreshImage').click(function() {
		var date = new Date();
		jQuery('#captchaImage').attr('src','/captcha/captcha.generate.asp?d=' + date.getTime());
		jQuery('input[name$="captchaVal"]').val('');
	});
	var validator = jQuery(o).validate({
		rules: {
			firstname: {
				required: true,
				minlength: 3
			},
			lastname: {
				required: true,
				minlength: 3
			},
			captchaVal: {
				required: true,
				remote: {
					url: '/captcha/captcha.validate.asp',
					type: 'post'
				}
			},
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			captchaVal: 'Correct captcha is required. Click the captcha to generate a new one',
			firstname: {
				required: 'Enter your first name',
				minlength: jQuery.format('Enter at least {0} characters')
			},
			lastname: {
				required: 'Enter your last name',
				minlength: jQuery.format('Enter at least {0} characters')
			},
			email: {
				required: 'Please enter a valid email address',
				minlength: 'Please enter a valid email address'
			}
		},
		submitHandler: function(form){
			jQuery(form).ajaxSubmit({
				target: "#contact"
			});
		}
	});
};


