/* * jQuery validation plug-in 1.5.5 * * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ * http://docs.jquery.com/Plugins/Validation * * Copyright (c) 2006 - 2008 Jörn Zaefferer * * $Id: jquery.validate.js,v 1.1 2011/01/18 19:07:55 \sheree Exp $ * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ (function($) { $.extend($.fn, { // http://docs.jquery.com/Plugins/Validation/validate validate: function( options ) { // if nothing is selected, return nothing; can't chain anyway if (!this.length) { options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" ); return; } // check if a validator for this form was already created var validator = $.data(this[0], 'validator'); if ( validator ) { return validator; } validator = new $.validator( options, this[0] ); $.data(this[0], 'validator', validator); if ( validator.settings.onsubmit ) { // allow suppresing validation by adding a cancel class to the submit button this.find("input, button").filter(".cancel").click(function() { validator.cancelSubmit = true; }); // when a submitHandler is used, capture the submitting button if (validator.settings.submitHandler) { this.find("input, button").filter(":submit").click(function() { validator.submitButton = this; }); } // validate the form on submit this.submit( function( event ) { if ( validator.settings.debug ) // prevent form submit to be able to see console output event.preventDefault(); function handle() { if ( validator.settings.submitHandler ) { if (validator.submitButton) { // insert a hidden input as a replacement for the missing submit button var hidden = $("").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm); } validator.settings.submitHandler.call( validator, validator.currentForm ); if (validator.submitButton) { // and clean up afterwards; thanks to no-block-scope, hidden can be referenced hidden.remove(); } return false; } return true; } // prevent submit for invalid forms or custom submit handlers if ( validator.cancelSubmit ) { validator.cancelSubmit = false; return handle(); } if ( validator.form() ) { if ( validator.pendingRequest ) { validator.formSubmitted = true; return false; } return handle(); } else { validator.focusInvalid(); return false; } }); } return validator; }, // http://docs.jquery.com/Plugins/Validation/valid valid: function() { if ( $(this[0]).is('form')) { return this.validate().form(); } else { var valid = true; var validator = $(this[0].form).validate(); this.each(function() { valid &= validator.element(this); }); return valid; } }, // attributes: space seperated list of attributes to retrieve and remove removeAttrs: function(attributes) { var result = {}, $element = this; $.each(attributes.split(/\s/), function(index, value) { result[value] = $element.attr(value); $element.removeAttr(value); }); return result; }, // http://docs.jquery.com/Plugins/Validation/rules rules: function(command, argument) { var element = this[0]; if (command) { var settings = $.data(element.form, 'validator').settings; var staticRules = settings.rules; var existingRules = $.validator.staticRules(element); switch(command) { case "add": $.extend(existingRules, $.validator.normalizeRule(argument)); staticRules[element.name] = existingRules; if (argument.messages) settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages ); break; case "remove": if (!argument) { delete staticRules[element.name]; return existingRules; } var filtered = {}; $.each(argument.split(/\s/), function(index, method) { filtered[method] = existingRules[method]; delete existingRules[method]; }); return filtered; } } var data = $.validator.normalizeRules( $.extend( {}, $.validator.metadataRules(element), $.validator.classRules(element), $.validator.attributeRules(element), $.validator.staticRules(element) ), element); // make sure required is at front if (data.required) { var param = data.required; delete data.required; data = $.extend({required: param}, data); } return data; } }); // Custom selectors $.extend($.expr[":"], { // http://docs.jquery.com/Plugins/Validation/blank blank: function(a) {return !$.trim(a.value);}, // http://docs.jquery.com/Plugins/Validation/filled filled: function(a) {return !!$.trim(a.value);}, // http://docs.jquery.com/Plugins/Validation/unchecked unchecked: function(a) {return !a.checked;} }); // constructor for validator $.validator = function( options, form ) { this.settings = $.extend( {}, $.validator.defaults, options ); this.currentForm = form; this.init(); }; $.validator.format = function(source, params) { if ( arguments.length == 1 ) return function() { var args = $.makeArray(arguments); args.unshift(source); return $.validator.format.apply( this, args ); }; if ( arguments.length > 2 && params.constructor != Array ) { params = $.makeArray(arguments).slice(1); } if ( params.constructor != Array ) { params = [ params ]; } $.each(params, function(i, n) { source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); }); return source; }; $.extend($.validator, { defaults: { messages: {}, groups: {}, rules: {}, errorClass: "error", validClass: "valid", errorElement: "label", focusInvalid: true, errorContainer: $( [] ), errorLabelContainer: $( [] ), onsubmit: true, ignore: [], ignoreTitle: false, onfocusin: function(element) { this.lastActive = element; // hide error label and remove error class on focus if enabled if ( this.settings.focusCleanup && !this.blockFocusCleanup ) { this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass ); this.errorsFor(element).hide(); } }, onfocusout: function(element) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { this.element(element); } }, onkeyup: function(element) { if ( element.name in this.submitted || element == this.lastElement ) { this.element(element); } }, onclick: function(element) { if ( element.name in this.submitted ) this.element(element); }, highlight: function( element, errorClass, validClass ) { $(element).addClass(errorClass).removeClass(validClass); }, unhighlight: function( element, errorClass, validClass ) { $(element).removeClass(errorClass).addClass(validClass); } }, // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults setDefaults: function(settings) { $.extend( $.validator.defaults, settings ); }, messages: { required: "This field is required.", remote: "Please fix this field.", email: "Please enter a valid email address.", url: "Please enter a valid URL.", date: "Please enter a valid date.", dateISO: "Please enter a valid date (ISO).", dateDE: "Bitte geben Sie ein gültiges Datum ein.", number: "Please enter a valid number.", numberDE: "Bitte geben Sie eine Nummer ein.", digits: "Please enter only digits", creditcard: "Please enter a valid credit card number.", equalTo: "Please enter the same value again.", accept: "Please enter a value with a valid extension.", maxlength: $.validator.format("Please enter no more than {0} characters."), minlength: $.validator.format("Please enter at least {0} characters."), rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."), range: $.validator.format("Please enter a value between {0} and {1}."), max: $.validator.format("Please enter a value less than or equal to {0}."), min: $.validator.format("Please enter a value greater than or equal to {0}.") }, autoCreateRanges: false, prototype: { init: function() { this.labelContainer = $(this.settings.errorLabelContainer); this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm); this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer ); this.submitted = {}; this.valueCache = {}; this.pendingRequest = 0; this.pending = {}; this.invalid = {}; this.reset(); var groups = (this.groups = {}); $.each(this.settings.groups, function(key, value) { $.each(value.split(/\s/), function(index, name) { groups[name] = key; }); }); var rules = this.settings.rules; $.each(rules, function(key, value) { rules[key] = $.validator.normalizeRule(value); }); function delegate(event) { var validator = $.data(this[0].form, "validator"); validator.settings["on" + event.type] && validator.settings["on" + event.type].call(validator, this[0] ); } $(this.currentForm) .delegate("focusin focusout keyup", ":text, :password, :file, select, textarea", delegate) .delegate("click", ":radio, :checkbox", delegate); if (this.settings.invalidHandler) $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler); }, // http://docs.jquery.com/Plugins/Validation/Validator/form form: function() { this.checkForm(); $.extend(this.submitted, this.errorMap); this.invalid = $.extend({}, this.errorMap); if (!this.valid()) $(this.currentForm).triggerHandler("invalid-form", [this]); this.showErrors(); return this.valid(); }, checkForm: function() { this.prepareForm(); for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) { this.check( elements[i] ); } return this.valid(); }, // http://docs.jquery.com/Plugins/Validation/Validator/element element: function( element ) { element = this.clean( element ); this.lastElement = element; this.prepareElement( element ); this.currentElements = $(element); var result = this.check( element ); if ( result ) { delete this.invalid[element.name]; } else { this.invalid[element.name] = true; } if ( !this.numberOfInvalids() ) { // Hide error containers on last error this.toHide = this.toHide.add( this.containers ); } this.showErrors(); return result; }, // http://docs.jquery.com/Plugins/Validation/Validator/showErrors showErrors: function(errors) { if(errors) { // add items to error list and map $.extend( this.errorMap, errors ); this.errorList = []; for ( var name in errors ) { this.errorList.push({ message: errors[name], element: this.findByName(name)[0] }); } // remove items from success list this.successList = $.grep( this.successList, function(element) { return !(element.name in errors); }); } this.settings.showErrors ? this.settings.showErrors.call( this, this.errorMap, this.errorList ) : this.defaultShowErrors(); }, // http://docs.jquery.com/Plugins/Validation/Validator/resetForm resetForm: function() { if ( $.fn.resetForm ) $( this.currentForm ).resetForm(); this.submitted = {}; this.prepareForm(); this.hideErrors(); this.elements().removeClass( this.settings.errorClass ); }, numberOfInvalids: function() { return this.objectLength(this.invalid); }, objectLength: function( obj ) { var count = 0; for ( var i in obj ) count++; return count; }, hideErrors: function() { this.addWrapper( this.toHide ).hide(); }, valid: function() { return this.size() == 0; }, size: function() { return this.errorList.length; }, focusInvalid: function() { if( this.settings.focusInvalid ) { try { $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []).filter(":visible").focus(); } catch(e) { // ignore IE throwing errors when focusing hidden elements } } }, findLastActive: function() { var lastActive = this.lastActive; return lastActive && $.grep(this.errorList, function(n) { return n.element.name == lastActive.name; }).length == 1 && lastActive; }, elements: function() { var validator = this, rulesCache = {}; // select all valid inputs inside the form (no submit or reset buttons) // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved return $([]).add(this.currentForm.elements) .filter(":input") .not(":submit, :reset, :image, [disabled]") .not( this.settings.ignore ) .filter(function() { !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this); // select only the first element for each name, and only those with rules specified if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) return false; rulesCache[this.name] = true; return true; }); }, clean: function( selector ) { return $( selector )[0]; }, errors: function() { return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext ); }, reset: function() { this.successList = []; this.errorList = []; this.errorMap = {}; this.toShow = $([]); this.toHide = $([]); this.formSubmitted = false; this.currentElements = $([]); }, prepareForm: function() { this.reset(); this.toHide = this.errors().add( this.containers ); }, prepareElement: function( element ) { this.reset(); this.toHide = this.errorsFor(element); }, check: function( element ) { element = this.clean( element ); // if radio/checkbox, validate first element in group instead if (this.checkable(element)) { element = this.findByName( element.name )[0]; } var rules = $(element).rules(); var dependencyMismatch = false; for( method in rules ) { var rule = { method: method, parameters: rules[method] }; try { var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters ); // if a method indicates that the field is optional and therefore valid, // don't mark it as valid when there are no other rules if ( result == "dependency-mismatch" ) { dependencyMismatch = true; continue; } dependencyMismatch = false; if ( result == "pending" ) { this.toHide = this.toHide.not( this.errorsFor(element) ); return; } if( !result ) { this.formatAndAdd( element, rule ); return false; } } catch(e) { this.settings.debug && window.console && console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method"); throw e; } } if (dependencyMismatch) return; if ( this.objectLength(rules) ) this.successList.push(element); return true; }, // return the custom message for the given element and validation method // specified in the element's "messages" metadata customMetaMessage: function(element, method) { if (!$.metadata) return; var meta = this.settings.meta ? $(element).metadata()[this.settings.meta] : $(element).metadata(); return meta && meta.messages && meta.messages[method]; }, // return the custom message for the given element name and validation method customMessage: function( name, method ) { var m = this.settings.messages[name]; return m && (m.constructor == String ? m : m[method]); }, // return the first defined argument, allowing empty strings findDefined: function() { for(var i = 0; i < arguments.length; i++) { if (arguments[i] !== undefined) return arguments[i]; } return undefined; }, defaultMessage: function( element, method) { return this.findDefined( this.customMessage( element.name, method ), this.customMetaMessage( element, method ), // title is never undefined, so handle empty string as undefined !this.settings.ignoreTitle && element.title || undefined, $.validator.messages[method], "Warning: No message defined for " + element.name + "" ); }, formatAndAdd: function( element, rule ) { var message = this.defaultMessage( element, rule.method ); if ( typeof message == "function" ) message = message.call(this, rule.parameters, element); this.errorList.push({ message: message, element: element }); this.errorMap[element.name] = message; this.submitted[element.name] = message; }, addWrapper: function(toToggle) { if ( this.settings.wrapper ) toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) ); return toToggle; }, defaultShowErrors: function() { for ( var i = 0; this.errorList[i]; i++ ) { var error = this.errorList[i]; this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass ); this.showLabel( error.element, error.message ); } if( this.errorList.length ) { this.toShow = this.toShow.add( this.containers ); } if (this.settings.success) { for ( var i = 0; this.successList[i]; i++ ) { this.showLabel( this.successList[i] ); } } if (this.settings.unhighlight) { for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) { this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass ); } } this.toHide = this.toHide.not( this.toShow ); this.hideErrors(); this.addWrapper( this.toShow ).show(); }, validElements: function() { return this.currentElements.not(this.invalidElements()); }, invalidElements: function() { return $(this.errorList).map(function() { return this.element; }); }, showLabel: function(element, message) { var label = this.errorsFor( element ); if ( label.length ) { // refresh error/success class label.removeClass().addClass( this.settings.errorClass ); // check if we have a generated label, replace the message then label.attr("generated") && label.html(message); } else { // create label label = $("<" + this.settings.errorElement + "/>") .attr({"for": this.idOrName(element), generated: true}) .addClass(this.settings.errorClass) .html(message || ""); if ( this.settings.wrapper ) { // make sure the element is visible, even in IE // actually showing the wrapped element is handled elsewhere label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent(); } if ( !this.labelContainer.append(label).length ) this.settings.errorPlacement ? this.settings.errorPlacement(label, $(element) ) : label.insertAfter(element); } if ( !message && this.settings.success ) { label.text(""); typeof this.settings.success == "string" ? label.addClass( this.settings.success ) : this.settings.success( label ); } this.toShow = this.toShow.add(label); }, errorsFor: function(element) { return this.errors().filter("[for='" + this.idOrName(element) + "']"); }, idOrName: function(element) { return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); }, checkable: function( element ) { return /radio|checkbox/i.test(element.type); }, findByName: function( name ) { // select by name and filter by form for performance over form.find("[name=...]") var form = this.currentForm; return $(document.getElementsByName(name)).map(function(index, element) { return element.form == form && element.name == name && element || null; }); }, getLength: function(value, element) { switch( element.nodeName.toLowerCase() ) { case 'select': return $("option:selected", element).length; case 'input': if( this.checkable( element) ) return this.findByName(element.name).filter(':checked').length; } return value.length; }, depend: function(param, element) { return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true; }, dependTypes: { "boolean": function(param, element) { return param; }, "string": function(param, element) { return !!$(param, element.form).length; }, "function": function(param, element) { return param(element); } }, optional: function(element) { return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch"; }, startRequest: function(element) { if (!this.pending[element.name]) { this.pendingRequest++; this.pending[element.name] = true; } }, stopRequest: function(element, valid) { this.pendingRequest--; // sometimes synchronization fails, make sure pendingRequest is never < 0 if (this.pendingRequest < 0) this.pendingRequest = 0; delete this.pending[element.name]; if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) { $(this.currentForm).submit(); } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) { $(this.currentForm).triggerHandler("invalid-form", [this]); } }, previousValue: function(element) { return $.data(element, "previousValue") || $.data(element, "previousValue", previous = { old: null, valid: true, message: this.defaultMessage( element, "remote" ) }); } }, classRuleSettings: { required: {required: true}, email: {email: true}, url: {url: true}, date: {date: true}, dateISO: {dateISO: true}, dateDE: {dateDE: true}, number: {number: true}, numberDE: {numberDE: true}, digits: {digits: true}, creditcard: {creditcard: true} }, addClassRules: function(className, rules) { className.constructor == String ? this.classRuleSettings[className] = rules : $.extend(this.classRuleSettings, className); }, classRules: function(element) { var rules = {}; var classes = $(element).attr('class'); classes && $.each(classes.split(' '), function() { if (this in $.validator.classRuleSettings) { $.extend(rules, $.validator.classRuleSettings[this]); } }); return rules; }, attributeRules: function(element) { var rules = {}; var $element = $(element); for (method in $.validator.methods) { var value = $element.attr(method); if (value) { rules[method] = value; } } // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) { delete rules.maxlength; } return rules; }, metadataRules: function(element) { if (!$.metadata) return {}; var meta = $.data(element.form, 'validator').settings.meta; return meta ? $(element).metadata()[meta] : $(element).metadata(); }, staticRules: function(element) { var rules = {}; var validator = $.data(element.form, 'validator'); if (validator.settings.rules) { rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {}; } return rules; }, normalizeRules: function(rules, element) { // handle dependency check $.each(rules, function(prop, val) { // ignore rule when param is explicitly false, eg. required:false if (val === false) { delete rules[prop]; return; } if (val.param || val.depends) { var keepRule = true; switch (typeof val.depends) { case "string": keepRule = !!$(val.depends, element.form).length; break; case "function": keepRule = val.depends.call(element, element); break; } if (keepRule) { rules[prop] = val.param !== undefined ? val.param : true; } else { delete rules[prop]; } } }); // evaluate parameters $.each(rules, function(rule, parameter) { rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter; }); // clean number parameters $.each(['minlength', 'maxlength', 'min', 'max'], function() { if (rules[this]) { rules[this] = Number(rules[this]); } }); $.each(['rangelength', 'range'], function() { if (rules[this]) { rules[this] = [Number(rules[this][0]), Number(rules[this][1])]; } }); if ($.validator.autoCreateRanges) { // auto-create ranges if (rules.min && rules.max) { rules.range = [rules.min, rules.max]; delete rules.min; delete rules.max; } if (rules.minlength && rules.maxlength) { rules.rangelength = [rules.minlength, rules.maxlength]; delete rules.minlength; delete rules.maxlength; } } // To support custom messages in metadata ignore rule methods titled "messages" if (rules.messages) { delete rules.messages } return rules; }, // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} normalizeRule: function(data) { if( typeof data == "string" ) { var transformed = {}; $.each(data.split(/\s/), function() { transformed[this] = true; }); data = transformed; } return data; }, // http://docs.jquery.com/Plugins/Validation/Validator/addMethod addMethod: function(name, method, message) { $.validator.methods[name] = method; $.validator.messages[name] = message || $.validator.messages[name]; if (method.length < 3) { $.validator.addClassRules(name, $.validator.normalizeRule(name)); } }, methods: { // http://docs.jquery.com/Plugins/Validation/Methods/required required: function(value, element, param) { // check if dependency is met if ( !this.depend(param, element) ) return "dependency-mismatch"; switch( element.nodeName.toLowerCase() ) { case 'select': var options = $("option:selected", element); return options.length > 0 && ( element.type == "select-multiple" || ($.browser.msie && !(options[0].attributes['value'].specified) ? options[0].text : options[0].value).length > 0); case 'input': if ( this.checkable(element) ) return this.getLength(value, element) > 0; default: return $.trim(value).length > 0; } }, // http://docs.jquery.com/Plugins/Validation/Methods/remote remote: function(value, element, param) { if ( this.optional(element) ) return "dependency-mismatch"; var previous = this.previousValue(element); if (!this.settings.messages[element.name] ) this.settings.messages[element.name] = {}; this.settings.messages[element.name].remote = typeof previous.message == "function" ? previous.message(value) : previous.message; param = typeof param == "string" && {url:param} || param; if ( previous.old !== value ) { previous.old = value; var validator = this; this.startRequest(element); var data = {}; data[element.name] = value; $.ajax($.extend(true, { url: param, mode: "abort", port: "validate" + element.name, dataType: "json", data: data, success: function(response) { var valid = response === true; if ( valid ) { var submitted = validator.formSubmitted; validator.prepareElement(element); validator.formSubmitted = submitted; validator.successList.push(element); validator.showErrors(); } else { var errors = {}; errors[element.name] = previous.message = response || validator.defaultMessage( element, "remote" ); validator.showErrors(errors); } previous.valid = valid; validator.stopRequest(element, valid); } }, param)); return "pending"; } else if( this.pending[element.name] ) { return "pending"; } return previous.valid; }, // http://docs.jquery.com/Plugins/Validation/Methods/minlength minlength: function(value, element, param) { return this.optional(element) || this.getLength($.trim(value), element) >= param; }, // http://docs.jquery.com/Plugins/Validation/Methods/maxlength maxlength: function(value, element, param) { return this.optional(element) || this.getLength($.trim(value), element) <= param; }, // http://docs.jquery.com/Plugins/Validation/Methods/rangelength rangelength: function(value, element, param) { var length = this.getLength($.trim(value), element); return this.optional(element) || ( length >= param[0] && length <= param[1] ); }, // http://docs.jquery.com/Plugins/Validation/Methods/min min: function( value, element, param ) { return this.optional(element) || value >= param; }, // http://docs.jquery.com/Plugins/Validation/Methods/max max: function( value, element, param ) { return this.optional(element) || value <= param; }, // http://docs.jquery.com/Plugins/Validation/Methods/range range: function( value, element, param ) { return this.optional(element) || ( value >= param[0] && value <= param[1] ); }, // http://docs.jquery.com/Plugins/Validation/Methods/email email: function(value, element) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/url url: function(value, element) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/ return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/date date: function(value, element) { return this.optional(element) || !/Invalid|NaN/.test(new Date(value)); }, // http://docs.jquery.com/Plugins/Validation/Methods/dateISO dateISO: function(value, element) { return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/dateDE dateDE: function(value, element) { return this.optional(element) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/number number: function(value, element) { return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/numberDE numberDE: function(value, element) { return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/digits digits: function(value, element) { return this.optional(element) || /^\d+$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/creditcard // based on http://en.wikipedia.org/wiki/Luhn creditcard: function(value, element) { if ( this.optional(element) ) return "dependency-mismatch"; // accept only digits and dashes if (/[^0-9-]+/.test(value)) return false; var nCheck = 0, nDigit = 0, bEven = false; value = value.replace(/\D/g, ""); for (n = value.length - 1; n >= 0; n--) { var cDigit = value.charAt(n); var nDigit = parseInt(cDigit, 10); if (bEven) { if ((nDigit *= 2) > 9) nDigit -= 9; } nCheck += nDigit; bEven = !bEven; } return (nCheck % 10) == 0; }, // http://docs.jquery.com/Plugins/Validation/Methods/accept accept: function(value, element, param) { param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif"; return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i")); }, // http://docs.jquery.com/Plugins/Validation/Methods/equalTo equalTo: function(value, element, param) { return value == $(param).val(); } } }); // deprecated, use $.validator.format instead $.format = $.validator.format; })(jQuery); // ajax mode: abort // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() ;(function($) { var ajax = $.ajax; var pendingRequests = {}; $.ajax = function(settings) { // create settings for compatibility with ajaxSetup settings = $.extend(settings, $.extend({}, $.ajaxSettings, settings)); var port = settings.port; if (settings.mode == "abort") { if ( pendingRequests[port] ) { pendingRequests[port].abort(); } return (pendingRequests[port] = ajax.apply(this, arguments)); } return ajax.apply(this, arguments); }; })(jQuery); // provides cross-browser focusin and focusout events // IE has native support, in other browsers, use event caputuring (neither bubbles) // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target // provides triggerEvent(type: String, target: Element) to trigger delegated events ;(function($) { $.each({ focus: 'focusin', blur: 'focusout' }, function( original, fix ){ $.event.special[fix] = { setup:function() { if ( $.browser.msie ) return false; this.addEventListener( original, $.event.special[fix].handler, true ); }, teardown:function() { if ( $.browser.msie ) return false; this.removeEventListener( original, $.event.special[fix].handler, true ); }, handler: function(e) { arguments[0] = $.event.fix(e); arguments[0].type = fix; return $.event.handle.apply(this, arguments); } }; }); $.extend($.fn, { delegate: function(type, delegate, handler) { return this.bind(type, function(event) { var target = $(event.target); if (target.is(delegate)) { return handler.apply(target, arguments); } }); }, triggerEvent: function(type, target) { return this.triggerHandler(type, [$.event.fix({ type: type, target: target })]); } }) })(jQuery); /* * Metadata - jQuery plugin for parsing metadata from elements * * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: $Id: jquery.metadata.js,v 1.1 2011/01/18 19:07:55 \sheree Exp $ * */ /** * Sets the type of metadata to use. Metadata is encoded in JSON, and each property * in the JSON will become a property of the element itself. * * There are three supported types of metadata storage: * * attr: Inside an attribute. The name parameter indicates *which* attribute. * * class: Inside the class attribute, wrapped in curly braces: { } * * elem: Inside a child element (e.g. a script tag). The * name parameter indicates *which* element. * * The metadata for an element is loaded the first time the element is accessed via jQuery. * * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements * matched by expr, then redefine the metadata type and run another $(expr) for other elements. * * @name $.metadata.setType * * @example

This is a p

* @before $.metadata.setType("class") * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label" * @desc Reads metadata from the class attribute * * @example

This is a p

* @before $.metadata.setType("attr", "data") * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label" * @desc Reads metadata from a "data" attribute * * @example

This is a p

* @before $.metadata.setType("elem", "script") * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label" * @desc Reads metadata from a nested script element * * @param String type The encoding type * @param String name The name of the attribute to be used to get metadata (optional) * @cat Plugins/Metadata * @descr Sets the type of encoding to be used when loading metadata for the first time * @type undefined * @see metadata() */ (function($) { $.extend({ metadata : { defaults : { type: 'class', name: 'metadata', cre: /({.*})/, single: 'metadata' }, setType: function( type, name ){ this.defaults.type = type; this.defaults.name = name; }, get: function( elem, opts ){ var settings = $.extend({},this.defaults,opts); // check for empty string in single property if ( !settings.single.length ) settings.single = 'metadata'; var data = $.data(elem, settings.single); // returned cached data if it already exists if ( data ) return data; data = "{}"; if ( settings.type == "class" ) { var m = settings.cre.exec( elem.className ); if ( m ) data = m[1]; } else if ( settings.type == "elem" ) { if( !elem.getElementsByTagName ) return undefined; var e = elem.getElementsByTagName(settings.name); if ( e.length ) data = $.trim(e[0].innerHTML); } else if ( elem.getAttribute != undefined ) { var attr = elem.getAttribute( settings.name ); if ( attr ) data = attr; } if ( data.indexOf( '{' ) <0 ) data = "{" + data + "}"; data = eval("(" + data + ")"); $.data( elem, settings.single, data ); return data; } } }); /** * Returns the metadata object for the first member of the jQuery object. * * @name metadata * @descr Returns element's metadata object * @param Object opts An object contianing settings to override the defaults * @type jQuery * @cat Plugins/Metadata */ $.fn.metadata = function( opts ){ return $.metadata.get( this[0], opts ); }; })(jQuery); jQuery.noConflict(); /*============================================================================== Parameters: toCheck - VAT number be checked. This function checks the value of the parameter for a valid European VAT number. If the number is found to be invalid format, the function returns a value of false. Otherwise it returns the VAT number re-formatted. Example call: if (checkVATNumber (myVATNumber)) alert ("VAT number has a valid format") else alert ("VAT number has invalid format"); ------------------------------------------------------------------------------*/ function isvat (fieldvalue) { validvatnum = checkVATNumber (fieldvalue); return validvatnum; } function checkVATNumber (toCheck) { // Array holds the regular expressions for the valid VAT number var vatexp = new Array (); // To change the default country (e.g. from the UK to Germany - DE): // 1. Change the country code in the defCCode variable below to "DE". // 2. Remove the question mark from the regular expressions associated // with the UK VAT number: i.e. "(GB)?" -> "(GB)" // 3. Add a question mark into the regular expression associated with // Germany's number following the country code: i.e. "(DE)" -> "(DE)?" var defCCode = "GB"; // Note - VAT codes without the "**" in the comment do not have check digit // checking. vatexp.push (/^(AT)U(\d{8})$/); //** Austria vatexp.push (/^(BE)(\d{9,10})$/); //** Belgium vatexp.push (/^(BG)(\d{9,10})$/); // Bulgaria vatexp.push (/^(CY)(\d{8}[A-Z])$/); //** Cyprus vatexp.push (/^(CZ)(\d{8,10})(\d{3})?$/); //** Czech Republic vatexp.push (/^(DE)(\d{9})$/); //** Germany vatexp.push (/^(DK)((\d{8}))$/); //** Denmark vatexp.push (/^(EE)(\d{9})$/); //** Estonia vatexp.push (/^(EL)(\d{8,9})$/); //** Greece vatexp.push (/^(ES)([A-Z]\d{8})$/); //** Spain (1) vatexp.push (/^(ES)(\d{8}[A-Z])$/); // Spain (2) vatexp.push (/^(ES)([A-Z]\d{7}[A-Z])$/); //** Spain (3) vatexp.push (/^(EU)(\d{9})$/); //** EU-type vatexp.push (/^(FI)(\d{8})$/); //** Finland vatexp.push (/^(FR)(\d{11})$/); //** France (1) vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]\d{10}$/); // France (2) vatexp.push (/^(FR)\d[(A-H)|(J-N)|(P-Z)]\d{9}$/); // France (3) vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]{2}\d{9}$/); // France (4) vatexp.push (/^(GB)?(\d{9})$/); //** UK (standard) vatexp.push (/^(GB)?(\d{10})$/); //** UK (Commercial) vatexp.push (/^(GB)?(\d{12})$/); //UK (IOM standard) vatexp.push (/^(GB)?(\d{13})$/); //UK (IOM commercial) vatexp.push (/^(GB)?(GD\d{3})$/); //** UK (Government) vatexp.push (/^(GB)?(HA\d{3})$/); //** UK (Health authority) vatexp.push (/^(GR)(\d{8,9})$/); //** Greece vatexp.push (/^(HU)(\d{8})$/); //** Hungary vatexp.push (/^(IE)(\d{7}[A-W])$/); //** Ireland (1) vatexp.push (/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/); //** Ireland (2) vatexp.push (/^(IT)(\d{11})$/); //** Italy vatexp.push (/^(LV)(\d{11})$/); //** Latvia vatexp.push (/^(LT)(\d{9}|\d{12})$/); //** Lithunia vatexp.push (/^(LU)(\d{8})$/); //** Luxembourg vatexp.push (/^(MT)(\d{8})$/); //** Malta vatexp.push (/^(NL)(\d{9})B\d{2}$/); //** Netherlands vatexp.push (/^(PL)(\d{10})$/); //** Poland vatexp.push (/^(PT)(\d{9})$/); //** Portugal vatexp.push (/^(RO)(\d{2,10})$/); //** Romania vatexp.push (/^(SI)(\d{8})$/); //** Slovenia vatexp.push (/^(SK)(\d{9}|\d{10})$/); // Slovakia Republic vatexp.push (/^(SE)(\d{10}\d[1-4])$/); //** Sweden // Load up the string to check var VATNumber = toCheck.toUpperCase(); // Remove spaces from the VAT number to help validation var chars = [" ","-",",","."]; for ( var i=0; i < chars.length; i++) { while (VATNumber.indexOf(chars[i])!= -1) { VATNumber = VATNumber.slice (0,VATNumber.indexOf(chars[i])) + VATNumber.slice (VATNumber.indexOf(chars[i])+1); } } // Assume we're not going to find a valid VAT number var valid = false; // Check the string against the types of VAT numbers for (i=0; i < vatexp.length; i++) { if (vatexp[i].test(VATNumber)) { var cCode = RegExp.$1; // Isolate country code var cNumber = RegExp.$2; // Isolate the number if (cCode.length == 0) cCode = defCCode; // Set up default country code // Now look at the check digits for those countries we know about. switch (cCode) { case "AT": valid = ATVATCheckDigit (cNumber); break; case "BE": valid = BEVATCheckDigit (cNumber); break; case "BG": // The SIMA validation rules are incorrect for Bulgarian numbers. //valid = BGVATCheckDigit (cNumber) valid = true; break; case "CY": valid = CYVATCheckDigit (cNumber); break; case "CZ": valid = CZVATCheckDigit (cNumber); break; case "DE": valid = DEVATCheckDigit (cNumber); break; case "DK": valid = DKVATCheckDigit (cNumber); break; case "EE": valid = EEVATCheckDigit (cNumber); break; case "EL": valid = ELVATCheckDigit (cNumber); break; case "ES": valid = ESVATCheckDigit (cNumber); break; case "EU": valid = EUVATCheckDigit (cNumber); break; case "FI": valid = FIVATCheckDigit (cNumber); break; case "FR": valid = FRVATCheckDigit (cNumber); break; case "GB": valid = UKVATCheckDigit (cNumber); break; case "GR": valid = ELVATCheckDigit (cNumber); break; case "HU": valid = HUVATCheckDigit (cNumber); break; case "IE": valid = IEVATCheckDigit (cNumber); break; case "IT": valid = ITVATCheckDigit (cNumber); break; case "LT": valid = LTVATCheckDigit (cNumber); break; case "LU": valid = LUVATCheckDigit (cNumber); break; case "LV": valid = LVVATCheckDigit (cNumber); break; case "MT": valid = MTVATCheckDigit (cNumber); break; case "NL": valid = NLVATCheckDigit (cNumber); break; case "PL": valid = PLVATCheckDigit (cNumber); break; case "PT": valid = PTVATCheckDigit (cNumber); break; case "RO": valid = ROVATCheckDigit (cNumber); break; case "SE": valid = SEVATCheckDigit (cNumber); break; case "SI": valid = SIVATCheckDigit (cNumber); break; default: valid = true; } // Load new VAT number back into the form element if (valid) valid = VATNumber; // We have found that the number is valid - break from loop break; } } // Return with either an error or the reformatted VAT number return valid; } function ATVATCheckDigit (vatnumber) { // Checks the check digits of an Austrian VAT number. var total = 0; var multipliers = [1,2,1,2,1,2,1]; var temp = 0; // Extract the next digit and multiply by the appropriate multiplier. for (var i = 0; i < 7; i++) { temp = Number(vatnumber.charAt(i)) * multipliers[i]; if (temp > 9) total = total + Math.floor(temp/10) + temp%10 else total = total + temp; } // Establish check digit. total = 10 - (total+4) % 10; if (total == 10) total = 0; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (7,8)) return true else return false; } function BEVATCheckDigit (vatnumber) { // Checks the check digits of a Belgium VAT number. // First character of 10 digit numbers should be 0 if (vatnumber.length == 10 && vatnumber.slice(0,1) != "0") return false; // Nine digit numbers have a 0 inserted at the front. if (vatnumber.length == 9) vatnumber = "0" + vatnumber; // Modulus 97 check on last nine digits if (97 - vatnumber.slice (0,8) % 97 == vatnumber.slice (8,10)) return true else return false; } function BGVATCheckDigit (vatnumber) { // Check the check digit of 10 digit Bulgarian VAT numbers. if (vatnumber.length != 10) return true; var total = 0; var multipliers = [4,3,2,7,6,5,4,3,2]; var temp = 0; // Extract the next digit and multiply by the appropriate multiplier. for (var i = 0; i < 9; i++) { temp = temp + Number(vatnumber.charAt(i)) * multipliers[i]; } // Establish check digit. total = 11 - total % 11; if (total == 10) total = 0; if (total == 11) total = 1; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (9,10)) return true else return false; } function CYVATCheckDigit (vatnumber) { // Checks the check digits of a Cypriot VAT number. // Extract the next digit and multiply by the counter. var total = 0; for (var i = 0; i < 8; i++) { var temp = Number(vatnumber.charAt(i)); if (i % 2 == 0) { switch (temp) { case 0: temp = 1; break; case 1: temp = 0; break; case 2: temp = 5; break; case 3: temp = 7; break; case 4: temp = 9; break; default: temp = temp*2 + 3; } } total = total + temp; } // Establish check digit using modulus 26, and translate to char. equivalent. total = total % 26; total = String.fromCharCode(total+65); // Check to see if the check digit given is correct if (total == vatnumber.substr (8,1)) return true else return false; } function CZVATCheckDigit (vatnumber) { // Checks the check digits of a Czech Republic VAT number. var total = 0; var multipliers = [8,7,6,5,4,3,2]; // Only do check digit validation for standard VAT numbers if (vatnumber.length != 8) return true; // Extract the next digit and multiply by the counter. for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digit. total = 11 - total % 11; if (total == 10) total = 0; if (total == 11) total = 1; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (7,8)) return true else return false; } function DEVATCheckDigit (vatnumber) { // Checks the check digits of a German VAT number. var product = 10; var sum = 0; var checkdigit = 0; for (var i = 0; i < 8; i++) { // Extract the next digit and implement perculiar algorithm!. sum = (Number(vatnumber.charAt(i)) + product) % 10; if (sum == 0) {sum = 10}; product = (2 * sum) % 11; } // Establish check digit. if (11 - product == 10) {checkdigit = 0} else {checkdigit = 11 - product}; // Compare it with the last two characters of the VAT number. If the same, // then it is a valid check digit. if (checkdigit == vatnumber.slice (8,9)) return true else return false; } function DKVATCheckDigit (vatnumber) { // Checks the check digits of a Danish VAT number. var total = 0; var multipliers = [2,7,6,5,4,3,2,1]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digit. total = total % 11; // The remainder should be 0 for it to be valid.. if (total == 0) return true else return false; } function EEVATCheckDigit (vatnumber) { // Checks the check digits of an Estonian VAT number. var total = 0; var multipliers = [3,7,1,3,7,1,3,7]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits using modulus 10. total = 10 - total % 10; if (total == 10) total = 0; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (8,9)) return true else return false; } function ELVATCheckDigit (vatnumber) { // Checks the check digits of a Greek VAT number. var total = 0; var multipliers = [256,128,64,32,16,8,4,2]; //eight character numbers should be prefixed with an 0. if (vatnumber.length == 8) {vatnumber = "0" + vatnumber}; // Extract the next digit and multiply by the counter. for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digit. total = total % 11; if (total > 9) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (8,9)) return true else return false; } function ESVATCheckDigit (vatnumber) { // Checks the check digits of a Spanish VAT number. var total = 0; var temp = 0; var multipliers = [2,1,2,1,2,1,2]; var esexp = new Array (); esexp.push (/^[A-H]\d{8}$/); esexp.push (/^[N|P|Q|S]\d{7}[A-Z]$/); esexp.push (/^[0-9]{8}[A-Z]$/); var i = 0; // With profit companies if (esexp[0].test(vatnumber)) { // Extract the next digit and multiply by the counter. for (i = 0; i < 7; i++) { temp = Number(vatnumber.charAt(i+1)) * multipliers[i]; if (temp > 9) total = total + Math.floor(temp/10) + temp%10 else total = total + temp; } // Now calculate the check digit itself. total = 10 - total % 10; if (total == 10) {total = 0;} // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (8,9)) return true else return false; } // Non-profit companies else if (esexp[1].test(vatnumber)) { // Extract the next digit and multiply by the counter. for (i = 0; i < 7; i++) { temp = Number(vatnumber.charAt(i+1)) * multipliers[i]; if (temp > 9) total = total + Math.floor(temp/10) + temp%10 else total = total + temp; } // Now calculate the check digit itself. total = 10 - total % 10; total = String.fromCharCode(total+64); // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (8,9)) return true else return false; } // Personal number (NIF) else if (esexp[2].test(vatnumber)) { return vatnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(vatnumber.substring(0, 8)) % 23); } else return true; } function EUVATCheckDigit (vatnumber) { // We know litle about EU numbers apart from the fact that the first 3 digits // represent the country, and that there are nine digits in total. return true; } function FIVATCheckDigit (vatnumber) { // Checks the check digits of a Finnish VAT number. var total = 0; var multipliers = [7,9,10,5,8,4,2]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digit. total = 11 - total % 11; if (total > 9) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (7,8)) return true else return false; } function FRVATCheckDigit (vatnumber) { // Checks the check digits of a French VAT number. if (!(/^\d{11}$/).test(vatnumber)) return true; // Extract the last nine digits as an integer. var total = vatnumber.substring(2); // Establish check digit. total = (total*100+12) % 97; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (0,2)) return true else return false; } function HUVATCheckDigit (vatnumber) { // Checks the check digits of a Hungarian VAT number. var total = 0; var multipliers = [9,7,3,1,9,7,3]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digit. total = 10 - total % 10; if (total == 10) total = 0; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (7,8)) return true else return false; } function IEVATCheckDigit (vatnumber) { // Checks the check digits of an Irish VAT number. var total = 0; var multipliers = [8,7,6,5,4,3,2]; // If the code is in the old format, we need to convert it to the new. if (/^\d[A-Z\*\+]/.test(vatnumber)) { vatnumber = "0" + vatnumber.substring(2,7) + vatnumber.substring(0,1) + vatnumber.substring(7,8); } // Extract the next digit and multiply by the counter. for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digit using modulus 23, and translate to char. equivalent. total = total % 23; if (total == 0) total = "W" else total = String.fromCharCode(total+64); // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (7,8)) return true else return false; } function ITVATCheckDigit (vatnumber) { // Checks the check digits of an Italian VAT number. var total = 0; var multipliers = [1,2,1,2,1,2,1,2,1,2]; var temp; // The last three digits are the issuing office, and cannot exceed more 201 temp=Number(vatnumber.slice(0,7)); if (temp==0) return false; temp=Number(vatnumber.slice(7,10)); if ((temp<1) || (temp>201)) return false; // Extract the next digit and multiply by the appropriate for (var i = 0; i < 10; i++) { temp = Number(vatnumber.charAt(i)) * multipliers[i]; if (temp > 9) total = total + Math.floor(temp/10) + temp%10 else total = total + temp; } // Establish check digit. total = 10 - total % 10; if (total > 9) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (10,11)) return true else return false; } function LTVATCheckDigit (vatnumber) { // Checks the check digits of a Lithuanian VAT number. // Only do check digit validation for standard VAT numbers if (vatnumber.length != 9) return true; // Extract the next digit and multiply by the counter+1. var total = 0; for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * (i+1); // Can have a double check digit calculation! if (total % 11 == 10) { var multipliers = [3,4,5,6,7,8,9,1]; total = 0; for (i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; } // Establish check digit. total = total % 11; if (total == 10) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (8,9)) return true else return false; } function LUVATCheckDigit (vatnumber) { // Checks the check digits of a Luxembourg VAT number. if (vatnumber.slice (0,6) % 89 == vatnumber.slice (6,8)) return true else return false; } function LVVATCheckDigit (vatnumber) { // Checks the check digits of a Latvian VAT number. // Only check the legal bodies if ((/^[0-3]/).test(vatnumber)) return true; var total = 0; var multipliers = [9,1,4,8,3,10,2,5,7,6]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 10; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits by getting modulus 11. if (total%11 == 4 && vatnumber[0] ==9) total = total - 45; if (total%11 == 4) total = 4 - total%11 else if (total%11 > 4) total = 14 - total%11 else if (total%11 < 4) total = 3 - total%11; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (10,11)) return true else return false; } function MTVATCheckDigit (vatnumber) { // Checks the check digits of a Maltese VAT number. var total = 0; var multipliers = [3,4,6,7,8,9]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 6; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits by getting modulus 37. total = 37 - total % 37; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (6,8) * 1) return true else return false; } function NLVATCheckDigit (vatnumber) { // Checks the check digits of a Dutch VAT number. var total = 0; // var multipliers = [9,8,7,6,5,4,3,2]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits by getting modulus 11. total = total % 11; if (total > 9) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (8,9)) return true else return false; } function PLVATCheckDigit (vatnumber) { // Checks the check digits of a Polish VAT number. var total = 0; var multipliers = [6,5,7,2,3,4,5,6,7]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 9; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits subtracting modulus 11 from 11. total = total % 11; if (total > 9) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, then it's a valid // check digit. if (total == vatnumber.slice (9,10)) return true else return false; } function PTVATCheckDigit (vatnumber) { // Checks the check digits of a Portugese VAT number. var total = 0; var multipliers = [9,8,7,6,5,4,3,2]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 8; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits subtracting modulus 11 from 11. total = 11 - total % 11; if (total > 9) {total = 0;}; // Compare it with the last character of the VAT number. If it is the same, then it's a valid // check digit. if (total == vatnumber.slice (8,9)) return true else return false; } function ROVATCheckDigit (vatnumber) { // Checks the check digits of a Romanian VAT number. var multipliers = [7,5,3,2,1,7,5,3,2,1]; // Extract the next digit and multiply by the counter. var VATlen = vatnumber.length; multipliers = multipliers.slice (10-VATlen); var total = 0; for (var i = 0; i < vatnumber.length-1; i++) { total = total + Number(vatnumber.charAt(i)) * multipliers[i]; } // Establish check digits by getting modulus 11. total = (10 * total) % 11; if (total == 10) total = 0; // Compare it with the last character of the VAT number. If it is the same, then it's a valid // check digit. if (total == vatnumber.slice (vatnumber.length-1, vatnumber.length)) return true else return false; } function SEVATCheckDigit (vatnumber) { // Checks the check digits of a Swedish VAT number. var total = 0; var multipliers = [2,1,2,1,2,1,2,1,2]; var temp = 0; // Extract the next digit and multiply by the appropriate multiplier. for (var i = 0; i < 9; i++) { temp = Number(vatnumber.charAt(i)) * multipliers[i]; if (temp > 9) total = total + Math.floor(temp/10) + temp%10 else total = total + temp; } // Establish check digits by subtracting mod 10 of total from 10. total = 10 - (total % 10); if (total == 10) total = 0; // Compare it with the 10th character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (9,10)) return true else return false; } function SKVATCheckDigit (vatnumber) { // Checks the check digits of a Slovak VAT number. var total = 0; var multipliers = [8,7,6,5,4,3,2]; // Extract the next digit and multiply by the counter. for (var i = 3; i < 9; i++) { total = total + Number(vatnumber.charAt(i)) * multipliers[i-3]; } // Establish check digits by getting modulus 11. total = 11 - total % 11; if (total > 9) total = total - 10; // Compare it with the last character of the VAT number. If it is the same, // then it's a valid check digit. if (total == vatnumber.slice (9,10)) return true else return false; } function SIVATCheckDigit (vatnumber) { // Checks the check digits of a Slovenian VAT number. var total = 0; var multipliers = [8,7,6,5,4,3,2]; // Extract the next digit and multiply by the counter. for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Establish check digits by subtracting 97 from total until negative. total = 11 - total % 11; if (total > 9) {total = 0;}; // Compare the number with the last character of the VAT number. If it is the // same, then it's a valid check digit. if (total == vatnumber.slice (7,8)) return true else return false; } function UKVATCheckDigit (vatnumber) { // Checks the check digits of a UK VAT number. var multipliers = [8,7,6,5,4,3,2]; // Government departments if (vatnumber.substr(0,2) == 'GD') { if (vatnumber.substr(2,3) < 500) return true else return false; } // Health authorities if (vatnumber.substr(0,2) == 'HA') { if (vatnumber.substr(2,3) > 499) return true else return false; } // Standard and commercial numbers if (vatnumber.length == 9 || vatnumber.length == 10) { var total = 0; if (vatnumber.length == 10 && vatnumber.slice (9,10) != '3') return false; // Extract the next digit and multiply by the counter. for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i]; // Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less // 55). Our VAT number could use either system, so we check it against both. // Establish check digits by subtracting 97 from total until negative. var cd = total; while (cd > 0) {cd = cd - 97;} // Get the absolute value and compare it with the last two characters of the // VAT number. If the same, then it is a valid traditional check digit. cd = Math.abs(cd); if (cd == vatnumber.slice (7,9)) return true; // Now try the new method by subtracting 55 from the check digit if we can - else add 42 if (cd >= 55) cd = cd - 55 else cd = cd + 42; if (cd == vatnumber.slice (7,9)) return true else return false; } // We don't check 12 and 13 digit UK numbers - not only can we not find any, // but the information found on the format is contradictory. return true; } var passwordstrengthlevel = ''; jQuery.validator.setDefaults({ ignore: ':hidden', rules: { username: { required: true, minlength: 2, remote: "./includes/scripts/ajax_affdetails.asp" }, emailaddress: { minlength: 2, remote: "../includes/scripts/ajax_affdetails.asp" }, verificationimg: { minlength: 1, remote: "./includes/scripts/ajax_affdetails.asp" }, passwordretype: { required: true, equalTo: "#password" } }, messages:{ verificationimg:"Please enter the text as it appears in the image above." }, /*submitHandler: function(form) { alert("Validation has completed - submit form now"); form.submit(); },*/ // the errorPlacement has to take the table layout into account errorPlacement: function(error, element) { error.appendTo(jQuery("#" + element.attr('id') + "status")); var thislabel = "#" + element.attr('id') + "req"; jQuery(thislabel).addClass("error"); var Adderrorfield = ""; if (element.attr('id') =="securityquestion"){ Adderrorfield = "securityquestioncustom";} //if (element.attr('id') =="securityquestioncustom"){ Adderrorfield = "securityquestion";} if (Adderrorfield.length>0){ error.appendTo(jQuery("#" + Adderrorfield + "status")); var thislabel = "#" + Adderrorfield + "req"; jQuery(thislabel).addClass("error"); } }, // set this class to error-labels to indicate valid fields success: function(label) { // set   as text for IE label.html(" ").addClass("checked"); var Adderrorfield = ""; if (label.attr('for') =="securityquestion"){ Adderrorfield = "securityquestioncustom";} if (label.attr('for') =="securityquestioncustom"){ Adderrorfield = "securityquestion";} if (Adderrorfield.length>0){ var thislabel = "#" + Adderrorfield + "status"; jQuery(thislabel).html(" ").addClass("checked"); } } }); jQuery.extend(jQuery.validator.messages, { required: "This field is required.", remote: "Already exists - Please enter a Different value.", email: "Please enter a valid email address", url: "Please enter a valid URL", date: "Please enter a valid date.", dateISO: "Please enter a valid date (ISO).", number: "Please enter a valid number.", digits: "Please enter only digits.", creditcard: "Please enter a valid credit card number.", equalTo: "Please enter the same value again", accept: "Please enter a value with a valid extension.", maxlength: jQuery.validator.format("Please enter no more than {0} characters."), minlength: jQuery.validator.format("Please enter at least {0} characters. No spaces allowed"), rangelength: jQuery.validator.format("Please enter a value between {0} and {1} characters long."), range: jQuery.validator.format("Please enter a value between {0} and {1}."), max: jQuery.validator.format("Please enter a value less than or equal to {0}."), min: jQuery.validator.format("Please enter a value greater than or equal to {0}.") }); jQuery(function() { // Add Program Specific validation jQuery.validator.addMethod("alphaNumeric", function (value, element) { return this.optional(element) || /^[0-9a-zA-Z ]+$/.test(value); }, "Field can only contain only letters, numbers." ); jQuery.validator.addMethod("allowedstring", function(value, element) { return this.optional(element) || (/^[a-zA-Z0-9 ._@#*&,\/-]+$/i.test(value)); },jQuery.validator.format("Field can contain only letters and numbers."," ._@#*&,\/-") ); jQuery.validator.addMethod("isphone", function(value, element) { return this.optional(element) || /^[ .+()0-9-]+$/.test(value); },jQuery.validator.format("Please check the Phone number") ); jQuery.validator.addMethod("isvat", function(value, element) { return this.optional(element) || checkVATNumber (value); },"Check the VAT value" ); jQuery.validator.addMethod("ispassword", function(value, element) { if (passwordstrengthlevel>0) { var checkstrength = testPassword(value); if (passwordstrengthlevel> (checkstrength+1)){ return false; } else{ return true; } } else{ return true; } } ,"The Password is too weak - try using both upper and lower case letters, numbers and include Characters like !@#$_~" ); jQuery.validator.addMethod("securityquestions", function (value, element) { var securityquestiondropdown = jQuery("#securityquestion").val(); var securityquestioncustom = jQuery("#securityquestioncustom").val(); if(securityquestiondropdown.length==0 && securityquestioncustom.length==0 ) { return false; }else { return true; } }, "Please Select a Security Question." ); jQuery.validator.addMethod("securityquestions2", function (value, element) { var securityquestiondropdown = jQuery("#securityquestion").val(); var securityquestioncustom = jQuery("#securityquestioncustom").val(); if( ((securityquestiondropdown.length>0) || (securityquestioncustom.length>0)) && (value.length==0) ) { return false; }else { return true; } }, "Check security question answer" ); }); // jQuery.validator.addClassRules function testPassword(passwd) { var description = new Array(); description[0] = "
  Weakest
"; description[1] = "
  Weak
"; description[2] = "
  Improving
"; description[3] = "
  Strong
"; description[4] = "
  Strongest
"; description[5] = "
"; var intScore = 0;var strVerdict = 0; passwd = jQuery.trim(passwd); if (passwd.length==0 || !passwd.length) {intScore = -1;} else if (passwd.length>0 && passwd.length<4){intScore = (intScore+1);} else if (passwd.length>0 && passwd.length<5){intScore = (intScore+3);} else if (passwd.length>4 && passwd.length<8){intScore = (intScore+6);} else if (passwd.length>7 && passwd.length<12){intScore = (intScore+12);} else if (passwd.length>11){intScore = (intScore+18);} if (passwd.match(/[a-z]/)){intScore = (intScore+1);} if (passwd.match(/[A-Z]/)){intScore = (intScore+5);} if (passwd.match(/\d+/)){intScore = (intScore+5);} if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)){intScore = (intScore+5);} if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)){intScore = (intScore+5);} if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){intScore = (intScore+5);} if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){intScore = (intScore+2);} if (passwd.match(/(\d.*\D)|(\D.*\d)/)){intScore = (intScore+2);} if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)){intScore = (intScore+2);} if(intScore == -1){strVerdict = description[5]; }else if(intScore > -1 && intScore < 16){strVerdict = 0; //description[0]; }else if (intScore > 15 && intScore < 25){strVerdict = 1; // description[1]; }else if (intScore > 24 && intScore < 35){strVerdict = 2; // description[2]; }else if (intScore > 34 && intScore < 45){strVerdict = 3; // description[3]; }else{strVerdict = 4;} // description[4];} document.getElementById("passtestindicator").innerHTML= (description[strVerdict]); return strVerdict; }