jQuery(function($) {
	var container = $('div#errors');
	var theform = 'div#theform form';
	$(theform).validate({
		showErrors: function(errors, errorList) {
			var numerr = errorList.length;
			if (numerr == 0)
			{
				container.css('visibility', 'hidden');
				$(theform + ' label').removeClass('error');
			}
			else
			{
				var errtxt = (numerr > 1) ? ' errors' : ' error';
				var errhtml = "Your form contains " + numerr + errtxt + ". Please check: ";
				var count = 1;
				for (var err in errors)
				{
					$('label[for="'+err+'"]').addClass('error');
					errhtml = errhtml + '<strong>' + err + '</strong>';
					if (count < numerr) errhtml = errhtml + ', ';
					count++;
				}
				container.css('visibility', 'visible').html(errhtml);
			}
		},
		rules: {
			name: {
				required: true,
				minLength: 3
			},
			email: {
				required: true,
				email: true
			},
			reason: 'required',
			subject: {
				required: true,
				minLength: 3
			},
			message: {
				required: true,
				minLength: 3
			}
		}		
	});
});
