 $(document).ready(function(){
 	
	jQuery.validator.addMethod("password", function( value, element ) {
		var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
		if (!result) {
			element.value = "";
			var validator = this;
			setTimeout(function() {
				validator.blockFocusCleanup = true;
				element.focus();
				validator.blockFocusCleanup = false;
			}, 1);
		}
		return result;
	}, "Your password must be at least 6 characters long and contain at least one number and one character.");
	
	// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
	jQuery.validator.addMethod("defaultInvalid", function(value, element) {
		return value != element.defaultValue;
	}, "");
	
	jQuery.validator.addMethod("billingRequired", function(value, element) {
		if ($("#bill_to_co").is(":checked"))
			return $(element).parents(".subTable").length;
		return !this.optional(element);
	}, "");
	
	jQuery.validator.messages.required = "";
	 $("#myform").bind("invalid-form.validate", function(e, validator) {
		var errors = validator.numberOfInvalids();
		if (errors) {
			var message = errors == 1
				? 'A mandatory field has been missed.'
				: 'Some mandatory fields have been missed.';
			$("div.error span").html(message);
			$("div.error").fadeIn("slow");
		} else {
			
			$("div.error").fadeOut("slow");
		}
	}).validate({
		//focusInvalid: false,
		//focusCleanup: true,
		onkeyup: false,
		submitHandler: function() {
			$("div.error span").html("Yay well done");
			$("div.error").fadeOut("slow");
			document.catalo.submit();
		},
		messages: {
			email: {
				required: " ",
				email: ""
			}
		},
		debug:true
	});

});