RUSSEL86

bootstrap form validator

Apr 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 399.49 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html lang="en-US">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title></title>
  6.     <!-- Latest compiled and minified CSS -->
  7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  8.  
  9. <!-- Optional theme -->
  10. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
  11. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  12. <!-- Latest compiled and minified JavaScript -->
  13. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  14.    
  15.     <style type="text/css">
  16.     .has-error .help-block, .has-error .control-label, .has-error .radio, .has-error .checkbox, .has-error .radio-inline, .has-error .checkbox-inline, .has-error.radio label, .has-error.checkbox label, .has-error.radio-inline label, .has-error.checkbox-inline label {
  17.     color: #a94442; }
  18.     .has-error .form-control-feedback {
  19.     color: #a94442;}
  20.     .glyphicon-remove:before {
  21.     content: "\e014";
  22. }
  23.  
  24.     </style>
  25. </head>
  26. <body>
  27.    
  28.    
  29.     <div class="container">
  30.    
  31.     <form id="contactForm" class="form-horizontal">
  32.     <div class="form-group">
  33.         <label class="col-xs-3 control-label">Full name</label>
  34.         <div class="col-xs-4">
  35.             <input type="text" class="form-control" name="firstName" placeholder="First name" />
  36.         </div>
  37.         <div class="col-xs-4">
  38.             <input type="text" class="form-control" name="lastName" placeholder="Last name" />
  39.         </div>
  40.     </div>
  41.  
  42.     <div class="form-group">
  43.         <label class="col-xs-3 control-label">Phone number</label>
  44.         <div class="col-xs-5">
  45.             <input type="text" class="form-control" name="phoneNumber" />
  46.         </div>
  47.     </div>
  48.  
  49.     <div class="form-group">
  50.         <label class="col-xs-3 control-label">Email address</label>
  51.         <div class="col-xs-5">
  52.             <input type="text" class="form-control" name="email" />
  53.         </div>
  54.     </div>
  55.  
  56.     <div class="form-group">
  57.         <label class="col-xs-3 control-label">Message</label>
  58.         <div class="col-xs-9">
  59.             <textarea class="form-control" name="message" rows="7"></textarea>
  60.         </div>
  61.     </div>
  62.  
  63.     <div class="form-group">
  64.         <label class="col-xs-3 control-label" id="captchaOperation"></label>
  65.         <div class="col-xs-3">
  66.             <input type="text" class="form-control" name="captcha" />
  67.         </div>
  68.     </div>
  69.  
  70.     <div class="form-group">
  71.         <div class="col-xs-9 col-xs-offset-3">
  72.             <button type="submit" class="btn btn-primary">Submit</button>
  73.         </div>
  74.     </div>
  75. </form>
  76.  
  77.     </div>
  78.  
  79.  
  80.  <script type="text/javascript">
  81.  /*!
  82.  * FormValidation (http://formvalidation.io)
  83.  * The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
  84.  *
  85.  * @version     v0.6.1-dev, built on 2015-02-17 8:51:23 PM
  86.  * @author      https://twitter.com/nghuuphuoc
  87.  * @copyright   (c) 2013 - 2015 Nguyen Huu Phuoc
  88.  * @license     http://formvalidation.io/license/
  89.  */
  90. // Register the namespace
  91. window.FormValidation = {
  92.     AddOn:     {},  // Add-ons
  93.     Framework: {},  // Supported frameworks
  94.     I18n:      {},  // i18n
  95.     Validator: {}   // Available validators
  96. };
  97.  
  98. if (typeof jQuery === 'undefined') {
  99.     throw new Error('FormValidation requires jQuery');
  100. }
  101.  
  102. (function($) {
  103.     var version = $.fn.jquery.split(' ')[0].split('.');
  104.     if ((+version[0] < 2 && +version[1] < 9) || (+version[0] === 1 && +version[1] === 9 && +version[2] < 1)) {
  105.        throw new Error('FormValidation requires jQuery version 1.9.1 or higher');
  106.    }
  107. }(jQuery));
  108.  
  109. (function($) {
  110.    // TODO: Remove backward compatibility in v0.7.0
  111.    /**
  112.     * Constructor
  113.     *
  114.     * @param {jQuery|String} form The form element or selector
  115.     * @param {Object} options The options
  116.     * @param {String} [namespace] The optional namespace which is used for data-{namespace}-xxx attributes and internal data.
  117.     * Currently, it's used to support backward version
  118.     * @constructor
  119.     */
  120.    FormValidation.Base = function(form, options, namespace) {
  121.        this.$form      = $(form);
  122.        this.options    = $.extend({}, $.fn.formValidation.DEFAULT_OPTIONS, options);
  123.        this._namespace = namespace || 'fv';
  124.        this.$invalidFields = $([]);    // Array of invalid fields
  125.        this.$submitButton  = null;     // The submit button which is clicked to submit form
  126.        this.$hiddenButton  = null;
  127.        // Validating status
  128.        this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
  129.        this.STATUS_VALIDATING    = 'VALIDATING';
  130.        this.STATUS_INVALID       = 'INVALID';
  131.        this.STATUS_VALID         = 'VALID';
  132.        // Determine the event that is fired when user change the field value
  133.        // Most modern browsers supports input event except IE 7, 8.
  134.        // IE 9 supports input event but the event is still not fired if I press the backspace key.
  135.        // Get IE version
  136.        // https://gist.github.com/padolsey/527683/#comment-7595
  137.        var ieVersion = (function() {
  138.            var v = 3, div = document.createElement('div'), a = div.all || [];
  139.            while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]) {}
  140.             return v > 4 ? v : !v;
  141.         }());
  142.  
  143.         var el = document.createElement('div');
  144.         this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';
  145.  
  146.         // The flag to indicate that the form is ready to submit when a remote/callback validator returns
  147.         this._submitIfValid = null;
  148.  
  149.         // Field elements
  150.         this._cacheFields = {};
  151.  
  152.         this._init();
  153.     };
  154.  
  155.     FormValidation.Base.prototype = {
  156.         constructor: FormValidation.Base,
  157.  
  158.         /**
  159.          * Check if the number of characters of field value exceed the threshold or not
  160.          *
  161.          * @param {jQuery} $field The field element
  162.          * @returns {Boolean}
  163.          */
  164.         _exceedThreshold: function($field) {
  165.             var ns        = this._namespace,
  166.                 field     = $field.attr('data-' + ns + '-field'),
  167.                 threshold = this.options.fields[field].threshold || this.options.threshold;
  168.             if (!threshold) {
  169.                 return true;
  170.             }
  171.             var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
  172.             return (cannotType || $field.val().length >= threshold);
  173.         },
  174.  
  175.         /**
  176.          * Init form
  177.          */
  178.         _init: function() {
  179.             var that    = this,
  180.                 ns      = this._namespace,
  181.                 options = {
  182.                     addOns:         {},
  183.                     autoFocus:      this.$form.attr('data-' + ns + '-autofocus'),
  184.                     button: {
  185.                         selector: this.$form.attr('data-' + ns + '-button-selector') || this.$form.attr('data-' + ns + '-submitbuttons'), // Support backward
  186.                         disabled: this.$form.attr('data-' + ns + '-button-disabled')
  187.                     },
  188.                     control: {
  189.                         valid:   this.$form.attr('data-' + ns + '-control-valid'),
  190.                         invalid: this.$form.attr('data-' + ns + '-control-invalid')
  191.                     },
  192.                     err: {
  193.                         clazz:     this.$form.attr('data-' + ns + '-err-clazz'),
  194.                         container: this.$form.attr('data-' + ns + '-err-container') || this.$form.attr('data-' + ns + '-container'), // Support backward
  195.                         parent:    this.$form.attr('data-' + ns + '-err-parent')
  196.                     },
  197.                     events: {
  198.                         formInit:         this.$form.attr('data-' + ns + '-events-form-init'),
  199.                         formError:        this.$form.attr('data-' + ns + '-events-form-error'),
  200.                         formSuccess:      this.$form.attr('data-' + ns + '-events-form-success'),
  201.                         fieldAdded:       this.$form.attr('data-' + ns + '-events-field-added'),
  202.                         fieldRemoved:     this.$form.attr('data-' + ns + '-events-field-removed'),
  203.                         fieldInit:        this.$form.attr('data-' + ns + '-events-field-init'),
  204.                         fieldError:       this.$form.attr('data-' + ns + '-events-field-error'),
  205.                         fieldSuccess:     this.$form.attr('data-' + ns + '-events-field-success'),
  206.                         fieldStatus:      this.$form.attr('data-' + ns + '-events-field-status'),
  207.                         localeChanged:    this.$form.attr('data-' + ns + '-events-locale-changed'),
  208.                         validatorError:   this.$form.attr('data-' + ns + '-events-validator-error'),
  209.                         validatorSuccess: this.$form.attr('data-' + ns + '-events-validator-success')
  210.                     },
  211.                     excluded:      this.$form.attr('data-' + ns + '-excluded'),
  212.                     icon: {
  213.                         valid:      this.$form.attr('data-' + ns + '-icon-valid')      || this.$form.attr('data-' + ns + '-feedbackicons-valid'),      // Support backward
  214.                         invalid:    this.$form.attr('data-' + ns + '-icon-invalid')    || this.$form.attr('data-' + ns + '-feedbackicons-invalid'),    // Support backward
  215.                         validating: this.$form.attr('data-' + ns + '-icon-validating') || this.$form.attr('data-' + ns + '-feedbackicons-validating'), // Support backward
  216.                         feedback:   this.$form.attr('data-' + ns + '-icon-feedback')
  217.                     },
  218.                     live:          this.$form.attr('data-' + ns + '-live'),
  219.                     locale:        this.$form.attr('data-' + ns + '-locale'),
  220.                     message:       this.$form.attr('data-' + ns + '-message'),
  221.                     onError:       this.$form.attr('data-' + ns + '-onerror'),
  222.                     onSuccess:     this.$form.attr('data-' + ns + '-onsuccess'),
  223.                     row: {
  224.                         selector: this.$form.attr('data-' + ns + '-row-selector') || this.$form.attr('data-' + ns + '-group'), // Support backward
  225.                         valid:    this.$form.attr('data-' + ns + '-row-valid'),
  226.                         invalid:  this.$form.attr('data-' + ns + '-row-invalid'),
  227.                         feedback: this.$form.attr('data-' + ns + '-row-feedback')
  228.                     },
  229.                     threshold:     this.$form.attr('data-' + ns + '-threshold'),
  230.                     trigger:       this.$form.attr('data-' + ns + '-trigger'),
  231.                     verbose:       this.$form.attr('data-' + ns + '-verbose'),
  232.                     fields:        {}
  233.                 };
  234.  
  235.             this.$form
  236.                 // Disable client side validation in HTML 5
  237.                 .attr('novalidate', 'novalidate')
  238.                 .addClass(this.options.elementClass)
  239.                 // Disable the default submission first
  240.                 .on('submit.' + ns, function(e) {
  241.                     e.preventDefault();
  242.                     that.validate();
  243.                 })
  244.                 .on('click.' + ns, this.options.button.selector, function() {
  245.                     that.$submitButton  = $(this);
  246.                     // The user just click the submit button
  247.                     that._submitIfValid = true;
  248.                 });
  249.  
  250.             if (this.options.declarative === true || this.options.declarative === 'true') {
  251.                 // Find all fields which have either "name" or "data-{namespace}-field" attribute
  252.                 this.$form
  253.                     .find('[name], [data-' + ns + '-field]')
  254.                     .each(function () {
  255.                         var $field = $(this),
  256.                             field  = $field.attr('name') || $field.attr('data-' + ns + '-field'),
  257.                             opts   = that._parseOptions($field);
  258.                         if (opts) {
  259.                             $field.attr('data-' + ns + '-field', field);
  260.                             options.fields[field] = $.extend({}, opts, options.fields[field]);
  261.                         }
  262.                     });
  263.             }
  264.  
  265.             this.options = $.extend(true, this.options, options);
  266.  
  267.             // Normalize the err.parent option
  268.             if ('string' === typeof this.options.err.parent) {
  269.                 this.options.err.parent = new RegExp(this.options.err.parent);
  270.             }
  271.  
  272.             // Support backward
  273.             if (this.options.container) {
  274.                 this.options.err.container = this.options.container;
  275.                 delete this.options.container;
  276.             }
  277.             if (this.options.feedbackIcons) {
  278.                 this.options.icon = $.extend(true, this.options.icon, this.options.feedbackIcons);
  279.                 delete this.options.feedbackIcons;
  280.             }
  281.             if (this.options.group) {
  282.                 this.options.row.selector = this.options.group;
  283.                 delete this.options.group;
  284.             }
  285.             if (this.options.submitButtons) {
  286.                 this.options.button.selector = this.options.submitButtons;
  287.                 delete this.options.submitButtons;
  288.             }
  289.  
  290.             // If the locale is not found, reset it to default one
  291.             if (!FormValidation.I18n[this.options.locale]) {
  292.                 this.options.locale = $.fn.formValidation.DEFAULT_OPTIONS.locale;
  293.             }
  294.  
  295.             // Parse the add-on options from HTML attributes
  296.             if (this.options.declarative === true || this.options.declarative === 'true') {
  297.                 this.options = $.extend(true, this.options, { addOns: this._parseAddOnOptions() });
  298.             }
  299.  
  300.             // When pressing Enter on any field in the form, the first submit button will do its job.
  301.             // The form then will be submitted.
  302.             // I create a first hidden submit button
  303.             this.$hiddenButton = $('<button/>')
  304.                                     .attr('type', 'submit')
  305.                                     .prependTo(this.$form)
  306.                                     .addClass('fv-hidden-submit')
  307.                                     .css({ display: 'none', width: 0, height: 0 });
  308.  
  309.             this.$form
  310.                 .on('click.' +  this._namespace, '[type="submit"]', function(e) {
  311.                     // #746: Check if the button click handler returns false
  312.                     if (!e.isDefaultPrevented()) {
  313.                         var $target = $(e.target),
  314.                             // The button might contain HTML tag
  315.                             $button = $target.is('[type="submit"]') ? $target.eq(0) : $target.parent('[type="submit"]').eq(0);
  316.  
  317.                         // Don't perform validation when clicking on the submit button/input
  318.                         // which aren't defined by the 'button.selector' option
  319.                         if (that.options.button.selector && !$button.is(that.options.button.selector) && !$button.is(that.$hiddenButton)) {
  320.                            that.$form.off('submit.' + that._namespace).submit();
  321.                         }
  322.                     }
  323.                 });
  324.  
  325.             for (var field in this.options.fields) {
  326.                 this._initField(field);
  327.             }
  328.  
  329.             // Init the add-ons
  330.             for (var addOn in this.options.addOns) {
  331.                 if ('function' === typeof FormValidation.AddOn[addOn].init) {
  332.                     FormValidation.AddOn[addOn].init(this, this.options.addOns[addOn]);
  333.                 }
  334.             }
  335.  
  336.             this.$form.trigger($.Event(this.options.events.formInit), {
  337.                 bv: this,   // Support backward
  338.                 fv: this,
  339.                 options: this.options
  340.             });
  341.  
  342.             // Prepare the events
  343.             if (this.options.onSuccess) {
  344.                 this.$form.on(this.options.events.formSuccess, function(e) {
  345.                     FormValidation.Helper.call(that.options.onSuccess, [e]);
  346.                 });
  347.             }
  348.             if (this.options.onError) {
  349.                 this.$form.on(this.options.events.formError, function(e) {
  350.                     FormValidation.Helper.call(that.options.onError, [e]);
  351.                 });
  352.             }
  353.         },
  354.  
  355.         /**
  356.          * Init field
  357.          *
  358.          * @param {String|jQuery} field The field name or field element
  359.          */
  360.         _initField: function(field) {
  361.             var ns     = this._namespace,
  362.                 fields = $([]);
  363.             switch (typeof field) {
  364.                 case 'object':
  365.                     fields = field;
  366.                     field  = field.attr('data-' + ns + '-field');
  367.                     break;
  368.                 case 'string':
  369.                     fields = this.getFieldElements(field);
  370.                     fields.attr('data-' + ns + '-field', field);
  371.                     break;
  372.                 default:
  373.                     break;
  374.             }
  375.  
  376.             // We don't need to validate non-existing fields
  377.             if (fields.length === 0) {
  378.                 return;
  379.             }
  380.  
  381.             if (this.options.fields[field] === null || this.options.fields[field].validators === null) {
  382.                 return;
  383.             }
  384.  
  385.             var validatorName;
  386.             for (validatorName in this.options.fields[field].validators) {
  387.                 if (!FormValidation.Validator[validatorName]) {
  388.                     delete this.options.fields[field].validators[validatorName];
  389.                 }
  390.             }
  391.             if (this.options.fields[field].enabled === null) {
  392.                 this.options.fields[field].enabled = true;
  393.             }
  394.  
  395.             var that      = this,
  396.                 total     = fields.length,
  397.                 type      = fields.attr('type'),
  398.                 updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
  399.                 trigger   = this._getFieldTrigger(fields.eq(0)),
  400.                 events    = $.map(trigger, function(item) {
  401.                     return item + '.update.' + ns;
  402.                 }).join(' ');
  403.  
  404.             for (var i = 0; i < total; i++) {
  405.                var $field    = fields.eq(i),
  406.                    row       = this.options.fields[field].row || this.options.row.selector,
  407.                    $parent   = $field.closest(row),
  408.                    // Allow user to indicate where the error messages are shown
  409.                    // Support backward
  410.                    container = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container))
  411.                                ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this)
  412.                                : (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container),
  413.                    $message  = (container && container !== 'tooltip' && container !== 'popover') ? $(container) : this._getMessageContainer($field, row);
  414.  
  415.                if (container && container !== 'tooltip' && container !== 'popover') {
  416.                    $message.addClass(this.options.err.clazz);
  417.                }
  418.  
  419.                // Remove all error messages and feedback icons
  420.                $message.find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove();
  421.                $parent.find('i[data-' + ns + '-icon-for="' + field + '"]').remove();
  422.  
  423.                // Whenever the user change the field value, mark it as not validated yet
  424.                $field.off(events).on(events, function() {
  425.                    that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
  426.                });
  427.  
  428.                // Create help block elements for showing the error messages
  429.                $field.data(ns + '.messages', $message);
  430.                for (validatorName in this.options.fields[field].validators) {
  431.                    $field.data(ns + '.result.' + validatorName, this.STATUS_NOT_VALIDATED);
  432.  
  433.                    if (!updateAll || i === total - 1) {
  434.                        $('<small/>')
  435.                             .css('display', 'none')
  436.                             .addClass(this.options.err.clazz)
  437.                             .attr('data-' + ns + '-validator', validatorName)
  438.                             .attr('data-' + ns + '-for', field)
  439.                             .attr('data-' + ns + '-result', this.STATUS_NOT_VALIDATED)
  440.                             .html(this._getMessage(field, validatorName))
  441.                             .appendTo($message);
  442.                     }
  443.  
  444.                     // Init the validator
  445.                     if ('function' === typeof FormValidation.Validator[validatorName].init) {
  446.                         FormValidation.Validator[validatorName].init(this, $field, this.options.fields[field].validators[validatorName]);
  447.                     }
  448.                 }
  449.  
  450.                 // Prepare the feedback icons
  451.                 // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
  452.                 if (this.options.fields[field].icon !== false && this.options.fields[field].icon !== 'false'
  453.                    && this.options.icon
  454.                    && this.options.icon.valid && this.options.icon.invalid && this.options.icon.validating
  455.                    && (!updateAll || i === total - 1))
  456.                {
  457.                    // $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid).addClass(this.options.row.feedback);
  458.                     // Keep error messages which are populated from back-end
  459.                     $parent.addClass(this.options.row.feedback);
  460.                     var $icon = $('<i/>')
  461.                                     .css('display', 'none')
  462.                                     .addClass(this.options.icon.feedback)
  463.                                     .attr('data-' + ns + '-icon-for', field)
  464.                                     .insertAfter($field);
  465.  
  466.                     // Store the icon as a data of field element
  467.                     (!updateAll ? $field : fields).data(ns + '.icon', $icon);
  468.  
  469.                     if ('tooltip' === container || 'popover' === container) {
  470.                         (!updateAll ? $field : fields)
  471.                             .on(this.options.events.fieldError, function() {
  472.                                 $parent.addClass('fv-has-tooltip');
  473.                             })
  474.                             .on(this.options.events.fieldSuccess, function() {
  475.                                 $parent.removeClass('fv-has-tooltip');
  476.                             });
  477.  
  478.                         $field
  479.                             // Show tooltip/popover message when field gets focus
  480.                             .off('focus.container.' + ns)
  481.                             .on('focus.container.' + ns, function() {
  482.                                 that._showTooltip($field, container);
  483.                             })
  484.                             // and hide them when losing focus
  485.                             .off('blur.container.' + ns)
  486.                             .on('blur.container.' + ns, function() {
  487.                                 that._hideTooltip($field, container);
  488.                             });
  489.                     }
  490.  
  491.                     if ('string' === typeof this.options.fields[field].icon && this.options.fields[field].icon !== 'true') {
  492.                        $icon.appendTo($(this.options.fields[field].icon));
  493.                     } else {
  494.                         this._fixIcon($field, $icon);
  495.                     }
  496.                 }
  497.             }
  498.  
  499.             // Prepare the events
  500.             fields
  501.                 .on(this.options.events.fieldSuccess, function(e, data) {
  502.                     var onSuccess = that.getOptions(data.field, null, 'onSuccess');
  503.                     if (onSuccess) {
  504.                         FormValidation.Helper.call(onSuccess, [e, data]);
  505.                     }
  506.                 })
  507.                 .on(this.options.events.fieldError, function(e, data) {
  508.                     var onError = that.getOptions(data.field, null, 'onError');
  509.                     if (onError) {
  510.                         FormValidation.Helper.call(onError, [e, data]);
  511.                     }
  512.                 })
  513.                 .on(this.options.events.fieldStatus, function(e, data) {
  514.                     var onStatus = that.getOptions(data.field, null, 'onStatus');
  515.                     if (onStatus) {
  516.                         FormValidation.Helper.call(onStatus, [e, data]);
  517.                     }
  518.                 })
  519.                 .on(this.options.events.validatorError, function(e, data) {
  520.                     var onError = that.getOptions(data.field, data.validator, 'onError');
  521.                     if (onError) {
  522.                         FormValidation.Helper.call(onError, [e, data]);
  523.                     }
  524.                 })
  525.                 .on(this.options.events.validatorSuccess, function(e, data) {
  526.                     var onSuccess = that.getOptions(data.field, data.validator, 'onSuccess');
  527.                     if (onSuccess) {
  528.                         FormValidation.Helper.call(onSuccess, [e, data]);
  529.                     }
  530.                 });
  531.  
  532.             // Set live mode
  533.             this.onLiveChange(fields, 'live', function() {
  534.                 if (that._exceedThreshold($(this))) {
  535.                     that.validateField($(this));
  536.                 }
  537.             });
  538.  
  539.             fields.trigger($.Event(this.options.events.fieldInit), {
  540.                 bv: this,   // Support backward
  541.                 fv: this,
  542.                 field: field,
  543.                 element: fields
  544.             });
  545.         },
  546.  
  547.         /**
  548.          * Check if the field is excluded.
  549.          * Returning true means that the field will not be validated
  550.          *
  551.          * @param {jQuery} $field The field element
  552.          * @returns {Boolean}
  553.          */
  554.         _isExcluded: function($field) {
  555.             var ns           = this._namespace,
  556.                 excludedAttr = $field.attr('data-' + ns + '-excluded'),
  557.                 // I still need to check the 'name' attribute while initializing the field
  558.                 field        = $field.attr('data-' + ns + '-field') || $field.attr('name');
  559.  
  560.             switch (true) {
  561.                 case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'true' || this.options.fields[field].excluded === true)):
  562.                case (excludedAttr === 'true'):
  563.                case (excludedAttr === ''):
  564.                    return true;
  565.  
  566.                 case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'false' || this.options.fields[field].excluded === false)):
  567.                case (excludedAttr === 'false'):
  568.                    return false;
  569.  
  570.                 default:
  571.                     if (this.options.excluded) {
  572.                         // Convert to array first
  573.                         if ('string' === typeof this.options.excluded) {
  574.                             this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
  575.                                 // Trim the spaces
  576.                                 return $.trim(item);
  577.                             });
  578.                         }
  579.  
  580.                         var length = this.options.excluded.length;
  581.                         for (var i = 0; i < length; i++) {
  582.                            if (('string' === typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
  583.                                || ('function' === typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) === true))
  584.                            {
  585.                                return true;
  586.                            }
  587.                        }
  588.                    }
  589.                    return false;
  590.            }
  591.        },
  592.  
  593.        /**
  594.         * Get a field changed trigger event
  595.         *
  596.         * @param {jQuery} $field The field element
  597.         * @returns {String[]} The event names triggered on field change
  598.         */
  599.        _getFieldTrigger: function($field) {
  600.            var ns      = this._namespace,
  601.                trigger = $field.data(ns + '.trigger');
  602.            if (trigger) {
  603.                return trigger;
  604.            }
  605.  
  606.            var type  = $field.attr('type'),
  607.                name  = $field.attr('data-' + ns + '-field'),
  608.                event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === $field.get(0).tagName) ? 'change' : this._changeEvent;
  609.            trigger   = ((this.options.fields[name] ? this.options.fields[name].trigger : null) || this.options.trigger || event).split(' ');
  610.  
  611.            // Since the trigger data is used many times, I need to cache it to use later
  612.            $field.data(ns + '.trigger', trigger);
  613.  
  614.            return trigger;
  615.        },
  616.  
  617.        /**
  618.         * Get the error message for given field and validator
  619.         *
  620.         * @param {String} field The field name
  621.         * @param {String} validatorName The validator name
  622.         * @returns {String}
  623.         */
  624.        _getMessage: function(field, validatorName) {
  625.            if (!this.options.fields[field] || !FormValidation.Validator[validatorName]
  626.                || !this.options.fields[field].validators || !this.options.fields[field].validators[validatorName])
  627.            {
  628.                return '';
  629.            }
  630.  
  631.            switch (true) {
  632.                case !!this.options.fields[field].validators[validatorName].message:
  633.                    return this.options.fields[field].validators[validatorName].message;
  634.                case !!this.options.fields[field].message:
  635.                    return this.options.fields[field].message;
  636.                case (!!FormValidation.I18n[this.options.locale] && !!FormValidation.I18n[this.options.locale][validatorName] && !!FormValidation.I18n[this.options.locale][validatorName]['default']):
  637.                    return FormValidation.I18n[this.options.locale][validatorName]['default'];
  638.                default:
  639.                    return this.options.message;
  640.            }
  641.        },
  642.  
  643.        /**
  644.         * Get the element to place the error messages
  645.         *
  646.         * @param {jQuery} $field The field element
  647.         * @param {String} row
  648.         * @returns {jQuery}
  649.         */
  650.        _getMessageContainer: function($field, row) {
  651.            if (!this.options.err.parent) {
  652.                throw new Error('The err.parent option is not defined');
  653.            }
  654.  
  655.            var $parent = $field.parent();
  656.            if ($parent.is(row)) {
  657.                return $parent;
  658.            }
  659.  
  660.            var cssClasses = $parent.attr('class');
  661.            if (!cssClasses) {
  662.                return this._getMessageContainer($parent, row);
  663.            }
  664.  
  665.            if (this.options.err.parent.test(cssClasses)) {
  666.                return $parent;
  667.            }
  668.  
  669.            return this._getMessageContainer($parent, row);
  670.        },
  671.  
  672.        /**
  673.         * Parse the add-on options from HTML attributes
  674.         *
  675.         * @returns {Object}
  676.         */
  677.        _parseAddOnOptions: function() {
  678.            var ns     = this._namespace,
  679.                names  = this.$form.attr('data-' + ns + '-addons'),
  680.                addOns = this.options.addOns || {};
  681.  
  682.            if (names) {
  683.                names = names.replace(/\s/g, '').split(',');
  684.                for (var i = 0; i < names.length; i++) {
  685.                    if (!addOns[names[i]]) {
  686.                        addOns[names[i]] = {};
  687.                    }
  688.                }
  689.            }
  690.  
  691.            // Try to parse each add-on options
  692.            var addOn, attrMap, attr, option;
  693.            for (addOn in addOns) {
  694.                if (!FormValidation.AddOn[addOn]) {
  695.                    // Add-on is not found
  696.                    delete addOns[addOn];
  697.                    continue;
  698.                }
  699.  
  700.                attrMap = FormValidation.AddOn[addOn].html5Attributes;
  701.                if (attrMap) {
  702.                    for (attr in attrMap) {
  703.                        option = this.$form.attr('data-' + ns + '-addons-' + addOn.toLowerCase() + '-' + attr.toLowerCase());
  704.                        if (option) {
  705.                            addOns[addOn][attrMap[attr]] = option;
  706.                        }
  707.                    }
  708.                }
  709.            }
  710.  
  711.            return addOns;
  712.        },
  713.  
  714.        /**
  715.         * Parse the validator options from HTML attributes
  716.         *
  717.         * @param {jQuery} $field The field element
  718.         * @returns {Object}
  719.         */
  720.        _parseOptions: function($field) {
  721.            var ns         = this._namespace,
  722.                field      = $field.attr('name') || $field.attr('data-' + ns + '-field'),
  723.                validators = {},
  724.                validator,
  725.                v,          // Validator name
  726.                attrName,
  727.                enabled,
  728.                optionName,
  729.                optionAttrName,
  730.                optionValue,
  731.                html5AttrName,
  732.                html5AttrMap;
  733.  
  734.            for (v in FormValidation.Validator) {
  735.                validator    = FormValidation.Validator[v];
  736.                attrName     = 'data-' + ns + '-' + v.toLowerCase(),
  737.                enabled      = $field.attr(attrName) + '';
  738.                html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
  739.  
  740.                if ((html5AttrMap && enabled !== 'false')
  741.                    || (html5AttrMap !== true && ('' === enabled || 'true' === enabled || attrName === enabled.toLowerCase())))
  742.                {
  743.                    // Try to parse the options via attributes
  744.                    validator.html5Attributes = $.extend({}, {
  745.                                                    message: 'message',
  746.                                                    onerror: 'onError',
  747.                                                    onsuccess: 'onSuccess',
  748.                                                    transformer: 'transformer'
  749.                                                }, validator.html5Attributes);
  750.                    validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]);
  751.  
  752.                    for (html5AttrName in validator.html5Attributes) {
  753.                        optionName  = validator.html5Attributes[html5AttrName];
  754.                        optionAttrName = 'data-' + ns + '-' + v.toLowerCase() + '-' + html5AttrName,
  755.                        optionValue = $field.attr(optionAttrName);
  756.                        if (optionValue) {
  757.                            if ('true' === optionValue || optionAttrName === optionValue.toLowerCase()) {
  758.                                optionValue = true;
  759.                            } else if ('false' === optionValue) {
  760.                                optionValue = false;
  761.                            }
  762.                            validators[v][optionName] = optionValue;
  763.                        }
  764.                    }
  765.                }
  766.            }
  767.  
  768.            var opts = {
  769.                    autoFocus:   $field.attr('data-' + ns + '-autofocus'),
  770.                    err:         $field.attr('data-' + ns + '-err-container') || $field.attr('data-' + ns + '-container'), // Support backward
  771.                    excluded:    $field.attr('data-' + ns + '-excluded'),
  772.                    icon:        $field.attr('data-' + ns + '-icon') || $field.attr('data-' + ns + '-feedbackicons') || (this.options.fields && this.options.fields[field] ? this.options.fields[field].feedbackIcons : null), // Support backward
  773.                    message:     $field.attr('data-' + ns + '-message'),
  774.                    onError:     $field.attr('data-' + ns + '-onerror'),
  775.                    onStatus:    $field.attr('data-' + ns + '-onstatus'),
  776.                    onSuccess:   $field.attr('data-' + ns + '-onsuccess'),
  777.                    row:         $field.attr('data-' + ns + '-row') || $field.attr('data-' + ns + '-group') || (this.options.fields && this.options.fields[field] ? this.options.fields[field].group : null), // Support backward
  778.                    selector:    $field.attr('data-' + ns + '-selector'),
  779.                    threshold:   $field.attr('data-' + ns + '-threshold'),
  780.                    transformer: $field.attr('data-' + ns + '-transformer'),
  781.                    trigger:     $field.attr('data-' + ns + '-trigger'),
  782.                    verbose:     $field.attr('data-' + ns + '-verbose'),
  783.                    validators:  validators
  784.                },
  785.                emptyOptions    = $.isEmptyObject(opts),        // Check if the field options are set using HTML attributes
  786.                emptyValidators = $.isEmptyObject(validators);  // Check if the field validators are set using HTML attributes
  787.  
  788.            if (!emptyValidators || (!emptyOptions && this.options.fields && this.options.fields[field])) {
  789.                opts.validators = validators;
  790.                return opts;
  791.            } else {
  792.                return null;
  793.            }
  794.        },
  795.  
  796.        /**
  797.         * Called when all validations are completed
  798.         */
  799.        _submit: function() {
  800.            var isValid = this.isValid();
  801.            if (isValid === null) {
  802.                return;
  803.            }
  804.  
  805.            var eventType = isValid ? this.options.events.formSuccess : this.options.events.formError,
  806.                e         = $.Event(eventType);
  807.  
  808.            this.$form.trigger(e);
  809.  
  810.            // Call default handler
  811.            // Check if whether the submit button is clicked
  812.            if (this.$submitButton) {
  813.                isValid ? this._onSuccess(e) : this._onError(e);
  814.            }
  815.        },
  816.  
  817.        // ~~~~~~
  818.        // Events
  819.        // ~~~~~~
  820.  
  821.        /**
  822.         * The default handler of error.form.fv event.
  823.         * It will be called when there is a invalid field
  824.         *
  825.         * @param {jQuery.Event} e The jQuery event object
  826.         */
  827.        _onError: function(e) {
  828.            if (e.isDefaultPrevented()) {
  829.                return;
  830.            }
  831.  
  832.            if ('submitted' === this.options.live) {
  833.                // Enable live mode
  834.                this.options.live = 'enabled';
  835.  
  836.                var that = this;
  837.                for (var field in this.options.fields) {
  838.                    (function(f) {
  839.                        var fields  = that.getFieldElements(f);
  840.                        if (fields.length) {
  841.                            that.onLiveChange(fields, 'live', function() {
  842.                                if (that._exceedThreshold($(this))) {
  843.                                    that.validateField($(this));
  844.                                }
  845.                            });
  846.                        }
  847.                    })(field);
  848.                }
  849.            }
  850.  
  851.            // Determined the first invalid field which will be focused on automatically
  852.            var ns = this._namespace;
  853.            for (var i = 0; i < this.$invalidFields.length; i++) {
  854.                var $field    = this.$invalidFields.eq(i),
  855.                    autoFocus = this.isOptionEnabled($field.attr('data-' + ns + '-field'), 'autoFocus');
  856.                if (autoFocus) {
  857.                    // Focus the field
  858.                    $field.focus();
  859.                    break;
  860.                }
  861.            }
  862.        },
  863.  
  864.        /**
  865.         * Called after validating a field element
  866.         *
  867.         * @param {jQuery} $field The field element
  868.         * @param {String} [validatorName] The validator name
  869.         */
  870.        _onFieldValidated: function($field, validatorName) {
  871.            var ns            = this._namespace,
  872.                field         = $field.attr('data-' + ns + '-field'),
  873.                validators    = this.options.fields[field].validators,
  874.                counter       = {},
  875.                numValidators = 0,
  876.                data          = {
  877.                    bv: this,   // Support backward
  878.                    fv: this,
  879.                    field: field,
  880.                    element: $field,
  881.                    validator: validatorName,
  882.                    result: $field.data(ns + '.response.' + validatorName)
  883.                };
  884.  
  885.            // Trigger an event after given validator completes
  886.            if (validatorName) {
  887.                switch ($field.data(ns + '.result.' + validatorName)) {
  888.                    case this.STATUS_INVALID:
  889.                        $field.trigger($.Event(this.options.events.validatorError), data);
  890.                        break;
  891.                    case this.STATUS_VALID:
  892.                        $field.trigger($.Event(this.options.events.validatorSuccess), data);
  893.                        break;
  894.                    default:
  895.                        break;
  896.                }
  897.            }
  898.  
  899.            counter[this.STATUS_NOT_VALIDATED] = 0;
  900.            counter[this.STATUS_VALIDATING]    = 0;
  901.            counter[this.STATUS_INVALID]       = 0;
  902.            counter[this.STATUS_VALID]         = 0;
  903.  
  904.            for (var v in validators) {
  905.                if (validators[v].enabled === false) {
  906.                    continue;
  907.                }
  908.  
  909.                numValidators++;
  910.                var result = $field.data(ns + '.result.' + v);
  911.                if (result) {
  912.                    counter[result]++;
  913.                }
  914.            }
  915.  
  916.            if (counter[this.STATUS_VALID] === numValidators) {
  917.                // Remove from the list of invalid fields
  918.                this.$invalidFields = this.$invalidFields.not($field);
  919.  
  920.                $field.trigger($.Event(this.options.events.fieldSuccess), data);
  921.            }
  922.            // If all validators are completed and there is at least one validator which doesn't pass
  923.            else if ((counter[this.STATUS_NOT_VALIDATED] === 0 || !this.isOptionEnabled(field, 'verbose')) && counter[this.STATUS_VALIDATING] === 0 && counter[this.STATUS_INVALID] > 0) {
  924.                 // Add to the list of invalid fields
  925.                 this.$invalidFields = this.$invalidFields.add($field);
  926.  
  927.                 $field.trigger($.Event(this.options.events.fieldError), data);
  928.             }
  929.         },
  930.  
  931.         /**
  932.          * The default handler of success.form.fv event.
  933.          * It will be called when all the fields are valid
  934.          *
  935.          * @param {jQuery.Event} e The jQuery event object
  936.          */
  937.         _onSuccess: function(e) {
  938.             if (e.isDefaultPrevented()) {
  939.                 return;
  940.             }
  941.  
  942.             // Submit the form
  943.             this.disableSubmitButtons(true).defaultSubmit();
  944.         },
  945.  
  946.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  947.         // Abstract methods
  948.         // Need to be implemented by sub-class that supports specific framework
  949.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  950.  
  951.         /**
  952.          * Specific framework might need to adjust the icon position
  953.          *
  954.          * @param {jQuery} $field The field element
  955.          * @param {jQuery} $icon The icon element
  956.          */
  957.         _fixIcon: function($field, $icon) {
  958.         },
  959.  
  960.         /**
  961.          * Create a tooltip or popover
  962.          * It will be shown when focusing on the field
  963.          *
  964.          * @param {jQuery} $field The field element
  965.          * @param {String} message The message
  966.          * @param {String} type Can be 'tooltip' or 'popover'
  967.          */
  968.         _createTooltip: function($field, message, type) {
  969.         },
  970.  
  971.         /**
  972.          * Destroy the tooltip or popover
  973.          *
  974.          * @param {jQuery} $field The field element
  975.          * @param {String} type Can be 'tooltip' or 'popover'
  976.          */
  977.         _destroyTooltip: function($field, type) {
  978.         },
  979.  
  980.         /**
  981.          * Hide a tooltip or popover
  982.          *
  983.          * @param {jQuery} $field The field element
  984.          * @param {String} type Can be 'tooltip' or 'popover'
  985.          */
  986.         _hideTooltip: function($field, type) {
  987.         },
  988.  
  989.         /**
  990.          * Show a tooltip or popover
  991.          *
  992.          * @param {jQuery} $field The field element
  993.          * @param {String} type Can be 'tooltip' or 'popover'
  994.          */
  995.         _showTooltip: function($field, type) {
  996.         },
  997.  
  998.         // ~~~~~~~~~~~~~~
  999.         // Public methods
  1000.         // ~~~~~~~~~~~~~~
  1001.  
  1002.         /**
  1003.          * Submit the form using default submission.
  1004.          * It also does not perform any validations when submitting the form
  1005.          */
  1006.         defaultSubmit: function() {
  1007.             var ns = this._namespace;
  1008.             if (this.$submitButton) {
  1009.                 // Create hidden input to send the submit buttons
  1010.                 $('<input/>')
  1011.                     .attr({
  1012.                         'type': 'hidden',
  1013.                         name: this.$submitButton.attr('name')
  1014.                     })
  1015.                     .attr('data-' + ns + '-submit-hidden', '')
  1016.                     .val(this.$submitButton.val())
  1017.                     .appendTo(this.$form);
  1018.             }
  1019.  
  1020.             // Submit form
  1021.             this.$form.off('submit.' + ns).submit();
  1022.         },
  1023.  
  1024.         /**
  1025.          * Disable/enable submit buttons
  1026.          *
  1027.          * @param {Boolean} disabled Can be true or false
  1028.          * @returns {FormValidation.Base}
  1029.          */
  1030.         disableSubmitButtons: function(disabled) {
  1031.             if (!disabled) {
  1032.                 this.$form
  1033.                     .find(this.options.button.selector)
  1034.                         .removeAttr('disabled')
  1035.                         .removeClass(this.options.button.disabled);
  1036.             } else if (this.options.live !== 'disabled') {
  1037.                 // Don't disable if the live validating mode is disabled
  1038.                 this.$form
  1039.                     .find(this.options.button.selector)
  1040.                         .attr('disabled', 'disabled')
  1041.                         .addClass(this.options.button.disabled);
  1042.             }
  1043.  
  1044.             return this;
  1045.         },
  1046.  
  1047.         /**
  1048.          * Retrieve the field elements by given name
  1049.          *
  1050.          * @param {String} field The field name
  1051.          * @returns {null|jQuery[]}
  1052.          */
  1053.         getFieldElements: function(field) {
  1054.             if (!this._cacheFields[field]) {
  1055.                 if (this.options.fields[field] && this.options.fields[field].selector) {
  1056.                    // Look for the field inside the form first
  1057.                    var f = this.$form.find(this.options.fields[field].selector);
  1058.                     // If not found, search in entire document
  1059.                     this._cacheFields[field] = f.length ? f : $(this.options.fields[field].selector);
  1060.                 } else {
  1061.                     this._cacheFields[field] = this.$form.find('[name="' + field + '"]');
  1062.                 }
  1063.             }
  1064.  
  1065.             return this._cacheFields[field];
  1066.         },
  1067.  
  1068.         /**
  1069.          * Get the field value after applying transformer
  1070.          *
  1071.          * @param {String|jQuery} field The field name or field element
  1072.          * @param {String} validatorName The validator name
  1073.          * @returns {String}
  1074.          */
  1075.         getFieldValue: function(field, validatorName) {
  1076.             var $field, ns = this._namespace;
  1077.             if ('string' === typeof field) {
  1078.                 $field = this.getFieldElements(field);
  1079.                 if ($field.length === 0) {
  1080.                     return null;
  1081.                 }
  1082.             } else {
  1083.                 $field = field;
  1084.                 field  = $field.attr('data-' + ns + '-field');
  1085.             }
  1086.  
  1087.             if (!field || !this.options.fields[field]) {
  1088.                 return $field.val();
  1089.             }
  1090.  
  1091.             var transformer = (this.options.fields[field].validators && this.options.fields[field].validators[validatorName]
  1092.                                ? this.options.fields[field].validators[validatorName].transformer : null)
  1093.                                || this.options.fields[field].transformer;
  1094.             return transformer ? FormValidation.Helper.call(transformer, [$field, validatorName, this]) : $field.val();
  1095.         },
  1096.  
  1097.         /**
  1098.          * Get the namespace
  1099.          *
  1100.          * @returns {String}
  1101.          */
  1102.         getNamespace: function() {
  1103.             return this._namespace;
  1104.         },
  1105.  
  1106.         /**
  1107.          * Get the field options
  1108.          *
  1109.          * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
  1110.          * @param {String} [validator] The name of validator. It null, the method returns form options
  1111.          * @param {String} [option] The option name
  1112.          * @return {String|Object}
  1113.          */
  1114.         getOptions: function(field, validator, option) {
  1115.             var ns = this._namespace;
  1116.             if (!field) {
  1117.                 return option ? this.options[option] : this.options;
  1118.             }
  1119.             if ('object' === typeof field) {
  1120.                 field = field.attr('data-' + ns + '-field');
  1121.             }
  1122.             if (!this.options.fields[field]) {
  1123.                 return null;
  1124.             }
  1125.  
  1126.             var options = this.options.fields[field];
  1127.             if (!validator) {
  1128.                 return option ? options[option] : options;
  1129.             }
  1130.             if (!options.validators || !options.validators[validator]) {
  1131.                 return null;
  1132.             }
  1133.  
  1134.             return option ? options.validators[validator][option] : options.validators[validator];
  1135.         },
  1136.  
  1137.         /**
  1138.          * Get the validating result of field
  1139.          *
  1140.          * @param {String|jQuery} field The field name or field element
  1141.          * @param {String} validatorName The validator name
  1142.          * @returns {String} The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  1143.          */
  1144.         getStatus: function(field, validatorName) {
  1145.             var ns = this._namespace;
  1146.             switch (typeof field) {
  1147.                 case 'object':
  1148.                     return field.data(ns + '.result.' + validatorName);
  1149.                 case 'string':
  1150.                 /* falls through */
  1151.                 default:
  1152.                     return this.getFieldElements(field).eq(0).data(ns + '.result.' + validatorName);
  1153.             }
  1154.         },
  1155.  
  1156.         /**
  1157.          * Check whether or not a field option is enabled
  1158.          *
  1159.          * @param {String} field The field name
  1160.          * @param {String} option The option name, "verbose", "autoFocus", for example
  1161.          * @returns {Boolean}
  1162.          */
  1163.         isOptionEnabled: function(field, option) {
  1164.             if (this.options.fields[field] && (this.options.fields[field][option] === 'true' || this.options.fields[field][option] === true)) {
  1165.                return true;
  1166.             }
  1167.             if (this.options.fields[field] && (this.options.fields[field][option] === 'false' || this.options.fields[field][option] === false)) {
  1168.                return false;
  1169.             }
  1170.             return this.options[option] === 'true' || this.options[option] === true;
  1171.         },
  1172.  
  1173.         /**
  1174.          * Check the form validity
  1175.          *
  1176.          * @returns {Boolean|null} Returns one of three values
  1177.          * - true, if all fields are valid
  1178.          * - false, if there is one invalid field
  1179.          * - null, if there is at least one field which is not validated yet or being validated
  1180.          */
  1181.         isValid: function() {
  1182.             for (var field in this.options.fields) {
  1183.                 var isValidField = this.isValidField(field);
  1184.                 if (isValidField === null) {
  1185.                     return null;
  1186.                 }
  1187.                 if (isValidField === false) {
  1188.                     return false;
  1189.                 }
  1190.             }
  1191.  
  1192.             return true;
  1193.         },
  1194.  
  1195.         /**
  1196.          * Check if all fields inside a given container are valid.
  1197.          * It's useful when working with a wizard-like such as tab, collapse
  1198.          *
  1199.          * @param {String|jQuery} container The container selector or element
  1200.          * @returns {Boolean|null} Returns one of three values
  1201.          * - true, if all fields inside the container are valid
  1202.          * - false, if there is one invalid field inside the container
  1203.          * - null, if the container consists of at least one field which is not validated yet or being validated
  1204.          */
  1205.         isValidContainer: function(container) {
  1206.             var that       = this,
  1207.                 ns         = this._namespace,
  1208.                 fields     = [],
  1209.                 $container = ('string' === typeof container) ? $(container) : container;
  1210.             if ($container.length === 0) {
  1211.                 return true;
  1212.             }
  1213.  
  1214.             $container.find('[data-' + ns + '-field]').each(function() {
  1215.                 var $field = $(this);
  1216.                 if (!that._isExcluded($field)) {
  1217.                     fields.push($field);
  1218.                 }
  1219.             });
  1220.  
  1221.             var total = fields.length;
  1222.             for (var i = 0; i < total; i++) {
  1223.                var $f      = fields[i],
  1224.                    field   = $f.attr('data-' + ns + '-field'),
  1225.                    $errors = $f.data(ns + '.messages')
  1226.                                .find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]');
  1227.  
  1228.                if ($errors.filter('[data-' + ns + '-result="' + this.STATUS_INVALID + '"]').length > 0) {
  1229.                     return false;
  1230.                 }
  1231.  
  1232.                 // If the field is not validated
  1233.                 if ($errors.filter('[data-' + ns + '-result="' + this.STATUS_NOT_VALIDATED + '"]').length > 0
  1234.                     || $errors.filter('[data-' + ns + '-result="' + this.STATUS_VALIDATING + '"]').length > 0)
  1235.                 {
  1236.                     return null;
  1237.                 }
  1238.             }
  1239.  
  1240.             return true;
  1241.         },
  1242.  
  1243.         /**
  1244.          * Check if the field is valid or not
  1245.          *
  1246.          * @param {String|jQuery} field The field name or field element
  1247.          * @returns {Boolean|null} Returns one of three values
  1248.          * - true, if the field passes all validators
  1249.          * - false, if the field doesn't pass any validator
  1250.          * - null, if there is at least one validator which isn't validated yet or being validated
  1251.          */
  1252.         isValidField: function(field) {
  1253.             var ns     = this._namespace,
  1254.                 fields = $([]);
  1255.             switch (typeof field) {
  1256.                 case 'object':
  1257.                     fields = field;
  1258.                     field  = field.attr('data-' + ns + '-field');
  1259.                     break;
  1260.                 case 'string':
  1261.                     fields = this.getFieldElements(field);
  1262.                     break;
  1263.                 default:
  1264.                     break;
  1265.             }
  1266.             if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
  1267.                 return true;
  1268.             }
  1269.  
  1270.             var type  = fields.attr('type'),
  1271.                 total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  1272.                 $field, validatorName, status;
  1273.             for (var i = 0; i < total; i++) {
  1274.                $field = fields.eq(i);
  1275.                if (this._isExcluded($field)) {
  1276.                    continue;
  1277.                }
  1278.  
  1279.                for (validatorName in this.options.fields[field].validators) {
  1280.                    if (this.options.fields[field].validators[validatorName].enabled === false) {
  1281.                        continue;
  1282.                    }
  1283.  
  1284.                    status = $field.data(ns + '.result.' + validatorName);
  1285.                    if (status === this.STATUS_VALIDATING || status === this.STATUS_NOT_VALIDATED) {
  1286.                        return null;
  1287.                    } else if (status === this.STATUS_INVALID) {
  1288.                        return false;
  1289.                    }
  1290.                }
  1291.            }
  1292.  
  1293.            return true;
  1294.        },
  1295.  
  1296.        /**
  1297.         * Detach a handler function for a field live change event
  1298.         *
  1299.         * @param {jQuery[]} $fields The field elements
  1300.         * @param {String} namespace The event namespace
  1301.         * @returns {FormValidation.Base}
  1302.         */
  1303.        offLiveChange: function($fields, namespace) {
  1304.            if ($fields === null || $fields.length === 0) {
  1305.                return this;
  1306.            }
  1307.  
  1308.            var ns      = this._namespace,
  1309.                trigger = this._getFieldTrigger($fields.eq(0)),
  1310.                events  = $.map(trigger, function(item) {
  1311.                    return item + '.' + namespace + '.' + ns;
  1312.                }).join(' ');
  1313.  
  1314.            $fields.off(events);
  1315.            return this;
  1316.        },
  1317.  
  1318.        /**
  1319.         * Attach a handler function for a field live change event
  1320.         *
  1321.         * @param {jQuery[]} $fields The field elements
  1322.         * @param {String} namespace The event namespace
  1323.         * @param {Function} handler The handler function
  1324.         * @returns {FormValidation.Base}
  1325.         */
  1326.        onLiveChange: function($fields, namespace, handler) {
  1327.            if ($fields === null || $fields.length === 0) {
  1328.                return this;
  1329.            }
  1330.  
  1331.            var ns      = this._namespace,
  1332.                trigger = this._getFieldTrigger($fields.eq(0)),
  1333.                events  = $.map(trigger, function(item) {
  1334.                    return item + '.' + namespace + '.' + ns;
  1335.                }).join(' ');
  1336.  
  1337.            switch (this.options.live) {
  1338.                case 'submitted':
  1339.                    break;
  1340.                case 'disabled':
  1341.                    $fields.off(events);
  1342.                    break;
  1343.                case 'enabled':
  1344.                /* falls through */
  1345.                default:
  1346.                    $fields.off(events).on(events, function(e) {
  1347.                        handler.apply(this, arguments);
  1348.                    });
  1349.                    break;
  1350.            }
  1351.  
  1352.            return this;
  1353.        },
  1354.  
  1355.        /**
  1356.         * Update the error message
  1357.         *
  1358.         * @param {String|jQuery} field The field name or field element
  1359.         * @param {String} validator The validator name
  1360.         * @param {String} message The message
  1361.         * @returns {FormValidation.Base}
  1362.         */
  1363.        updateMessage: function(field, validator, message) {
  1364.            var that    = this,
  1365.                ns      = this._namespace,
  1366.                $fields = $([]);
  1367.            switch (typeof field) {
  1368.                case 'object':
  1369.                    $fields = field;
  1370.                    field   = field.attr('data-' + ns + '-field');
  1371.                    break;
  1372.                case 'string':
  1373.                    $fields = this.getFieldElements(field);
  1374.                    break;
  1375.                default:
  1376.                    break;
  1377.            }
  1378.  
  1379.            $fields.each(function() {
  1380.                $(this)
  1381.                    .data(ns + '.messages')
  1382.                    .find('.' + that.options.err.clazz + '[data-' + ns + '-validator="' + validator + '"][data-' + ns + '-for="' + field + '"]').html(message);
  1383.            });
  1384.        },
  1385.  
  1386.        /**
  1387.         * Update all validating results of field
  1388.         *
  1389.         * @param {String|jQuery} field The field name or field element
  1390.         * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  1391.         * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  1392.         * @returns {FormValidation.Base}
  1393.         */
  1394.        updateStatus: function(field, status, validatorName) {
  1395.            var ns     = this._namespace,
  1396.                fields = $([]);
  1397.            switch (typeof field) {
  1398.                case 'object':
  1399.                    fields = field;
  1400.                    field  = field.attr('data-' + ns + '-field');
  1401.                    break;
  1402.                case 'string':
  1403.                    fields = this.getFieldElements(field);
  1404.                    break;
  1405.                default:
  1406.                    break;
  1407.            }
  1408.  
  1409.            if (!field || !this.options.fields[field]) {
  1410.                return this;
  1411.            }
  1412.  
  1413.            if (status === this.STATUS_NOT_VALIDATED) {
  1414.                // Reset the flag
  1415.                // To prevent the form from doing submit when a deferred validator returns true while typing
  1416.                this._submitIfValid = false;
  1417.            }
  1418.  
  1419.            var that  = this,
  1420.                type  = fields.attr('type'),
  1421.                row   = this.options.fields[field].row || this.options.row.selector,
  1422.                total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1423.  
  1424.            for (var i = 0; i < total; i++) {
  1425.                var $field       = fields.eq(i);
  1426.                if (this._isExcluded($field)) {
  1427.                    continue;
  1428.                }
  1429.  
  1430.                var $parent      = $field.closest(row),
  1431.                    $message     = $field.data(ns + '.messages'),
  1432.                    $allErrors   = $message.find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]'),
  1433.                    $errors      = validatorName ? $allErrors.filter('[data-' + ns + '-validator="' + validatorName + '"]') : $allErrors,
  1434.                    $icon        = $field.data(ns + '.icon'),
  1435.                    // Support backward
  1436.                    container    = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container))
  1437.                                    ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this)
  1438.                                    : (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container),
  1439.                    isValidField = null;
  1440.  
  1441.                // Update status
  1442.                if (validatorName) {
  1443.                    $field.data(ns + '.result.' + validatorName, status);
  1444.                } else {
  1445.                    for (var v in this.options.fields[field].validators) {
  1446.                        $field.data(ns + '.result.' + v, status);
  1447.                    }
  1448.                }
  1449.  
  1450.                // Show/hide error elements and feedback icons
  1451.                $errors.attr('data-' + ns + '-result', status);
  1452.  
  1453.                switch (status) {
  1454.                    case this.STATUS_VALIDATING:
  1455.                        isValidField = null;
  1456.                        this.disableSubmitButtons(true);
  1457.                        $field.removeClass(this.options.control.valid).removeClass(this.options.control.invalid);
  1458.                        $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid);
  1459.                        if ($icon) {
  1460.                            $icon.removeClass(this.options.icon.valid).removeClass(this.options.icon.invalid).addClass(this.options.icon.validating).show();
  1461.                        }
  1462.                        break;
  1463.  
  1464.                    case this.STATUS_INVALID:
  1465.                        isValidField = false;
  1466.                        this.disableSubmitButtons(true);
  1467.                        $field.removeClass(this.options.control.valid).addClass(this.options.control.invalid);
  1468.                        $parent.removeClass(this.options.row.valid).addClass(this.options.row.invalid);
  1469.                        if ($icon) {
  1470.                            $icon.removeClass(this.options.icon.valid).removeClass(this.options.icon.validating).addClass(this.options.icon.invalid).show();
  1471.                        }
  1472.                        break;
  1473.  
  1474.                    case this.STATUS_VALID:
  1475.                        var isValidating   = ($allErrors.filter('[data-' + ns + '-result="' + this.STATUS_VALIDATING +'"]').length > 0),
  1476.                             isNotValidated = ($allErrors.filter('[data-' + ns + '-result="' + this.STATUS_NOT_VALIDATED +'"]').length > 0);
  1477.  
  1478.                         // If the field is valid (passes all validators)
  1479.                         isValidField = (isValidating || isNotValidated)     // There are some validators that have not done
  1480.                                      ? null
  1481.                                      : ($allErrors.filter('[data-' + ns + '-result="' + this.STATUS_VALID +'"]').length === $allErrors.length); // All validators are completed
  1482.  
  1483.                         $field.removeClass(this.options.control.valid).removeClass(this.options.control.invalid);
  1484.  
  1485.                         if (isValidField === true) {
  1486.                             var isValid = this.isValid();
  1487.                             if (isValid !== null) {
  1488.                                 this.disableSubmitButtons(!isValid);
  1489.                             }
  1490.  
  1491.                             $field.addClass(this.options.control.valid);
  1492.                         } else if (isValidField === false) {
  1493.                             this.disableSubmitButtons(true);
  1494.                             $field.addClass(this.options.control.invalid);
  1495.                         }
  1496.  
  1497.                         if ($icon) {
  1498.                             $icon
  1499.                                 .removeClass(this.options.icon.invalid).removeClass(this.options.icon.validating).removeClass(this.options.icon.valid)
  1500.                                 .addClass(isValidField === null ? '' : (isValidField ? this.options.icon.valid
  1501.                                                                                      : (isValidating ? this.options.icon.validating : this.options.icon.invalid)))
  1502.                                 .show();
  1503.                         }
  1504.  
  1505.                         var isValidContainer = this.isValidContainer($parent);
  1506.                         if (isValidContainer !== null) {
  1507.                             $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid).addClass(isValidContainer ? this.options.row.valid : this.options.row.invalid);
  1508.                         }
  1509.                         break;
  1510.  
  1511.                     case this.STATUS_NOT_VALIDATED:
  1512.                     /* falls through */
  1513.                     default:
  1514.                         isValidField = null;
  1515.                         this.disableSubmitButtons(false);
  1516.                         $field.removeClass(this.options.control.valid).removeClass(this.options.control.invalid);
  1517.                         $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid);
  1518.                         if ($icon) {
  1519.                             $icon.removeClass(this.options.icon.valid).removeClass(this.options.icon.invalid).removeClass(this.options.icon.validating).hide();
  1520.                         }
  1521.                         break;
  1522.                 }
  1523.  
  1524.                 if ($icon && ('tooltip' === container || 'popover' === container)) {
  1525.                    (isValidField === false)
  1526.                        // Only show the first error message
  1527.                        ? this._createTooltip($field, $allErrors.filter('[data-' + ns + '-result="' + that.STATUS_INVALID + '"]').eq(0).html(), container)
  1528.                        : this._destroyTooltip($field, container);
  1529.                 } else {
  1530.                     (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
  1531.                 }
  1532.  
  1533.                 // Trigger an event
  1534.                 $field.trigger($.Event(this.options.events.fieldStatus), {
  1535.                     bv: this,   // Support backward
  1536.                     fv: this,
  1537.                     field: field,
  1538.                     element: $field,
  1539.                     status: status
  1540.                 });
  1541.                 this._onFieldValidated($field, validatorName);
  1542.             }
  1543.  
  1544.             return this;
  1545.         },
  1546.  
  1547.         /**
  1548.          * Validate the form
  1549.          *
  1550.          * @returns {FormValidation.Base}
  1551.          */
  1552.         validate: function() {
  1553.             if ($.isEmptyObject(this.options.fields)) {
  1554.                 this._submit();
  1555.                 return this;
  1556.             }
  1557.             this.disableSubmitButtons(true);
  1558.  
  1559.             this._submitIfValid = false;
  1560.             for (var field in this.options.fields) {
  1561.                 this.validateField(field);
  1562.             }
  1563.  
  1564.             this._submit();
  1565.             this._submitIfValid = true;
  1566.  
  1567.             return this;
  1568.         },
  1569.  
  1570.         /**
  1571.          * Validate given field
  1572.          *
  1573.          * @param {String|jQuery} field The field name or field element
  1574.          * @returns {FormValidation.Base}
  1575.          */
  1576.         validateField: function(field) {
  1577.             var ns     = this._namespace,
  1578.                 fields = $([]);
  1579.             switch (typeof field) {
  1580.                 case 'object':
  1581.                     fields = field;
  1582.                     field  = field.attr('data-' + ns + '-field');
  1583.                     break;
  1584.                 case 'string':
  1585.                     fields = this.getFieldElements(field);
  1586.                     break;
  1587.                 default:
  1588.                     break;
  1589.             }
  1590.  
  1591.             if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
  1592.                 return this;
  1593.             }
  1594.  
  1595.             var that       = this,
  1596.                 type       = fields.attr('type'),
  1597.                 total      = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  1598.                 updateAll  = ('radio' === type || 'checkbox' === type),
  1599.                 validators = this.options.fields[field].validators,
  1600.                 verbose    = this.isOptionEnabled(field, 'verbose'),
  1601.                 validatorName,
  1602.                 validateResult;
  1603.  
  1604.             for (var i = 0; i < total; i++) {
  1605.                var $field = fields.eq(i);
  1606.                if (this._isExcluded($field)) {
  1607.                    continue;
  1608.                }
  1609.  
  1610.                var stop = false;
  1611.                for (validatorName in validators) {
  1612.                    if ($field.data(ns + '.dfs.' + validatorName)) {
  1613.                        $field.data(ns + '.dfs.' + validatorName).reject();
  1614.                    }
  1615.                    if (stop) {
  1616.                        break;
  1617.                    }
  1618.  
  1619.                    // Don't validate field if it is already done
  1620.                    var result = $field.data(ns + '.result.' + validatorName);
  1621.                    if (result === this.STATUS_VALID || result === this.STATUS_INVALID) {
  1622.                        this._onFieldValidated($field, validatorName);
  1623.                        continue;
  1624.                    } else if (validators[validatorName].enabled === false) {
  1625.                        this.updateStatus(updateAll ? field : $field, this.STATUS_VALID, validatorName);
  1626.                        continue;
  1627.                    }
  1628.                    $field.data(ns + '.result.' + validatorName, this.STATUS_VALIDATING);
  1629.                    validateResult = FormValidation.Validator[validatorName].validate(this, $field, validators[validatorName]);
  1630.                    // validateResult can be a $.Deferred object ...
  1631.                    if ('object' === typeof validateResult && validateResult.resolve) {
  1632.                        this.updateStatus(updateAll ? field : $field, this.STATUS_VALIDATING, validatorName);
  1633.                        $field.data(ns + '.dfs.' + validatorName, validateResult);
  1634.                        validateResult.done(function($f, v, response) {
  1635.                            // v is validator name
  1636.                            $f.removeData(ns + '.dfs.' + v).data(ns + '.response.' + v, response);
  1637.                            if (response.message) {
  1638.                                that.updateMessage($f, v, response.message);
  1639.                            }
  1640.                            that.updateStatus(updateAll ? $f.attr('data-' + ns + '-field') : $f, response.valid ? that.STATUS_VALID : that.STATUS_INVALID, v);
  1641.                            if (response.valid && that._submitIfValid === true) {
  1642.                                // If a remote validator returns true and the form is ready to submit, then do it
  1643.                                that._submit();
  1644.                            } else if (!response.valid && !verbose) {
  1645.                                stop = true;
  1646.                            }
  1647.                        });
  1648.                    }
  1649.                    // ... or object { valid: true/false, message: 'dynamic message', otherKey: value, ... }
  1650.                    else if ('object' === typeof validateResult && validateResult.valid !== undefined) {
  1651.                        $field.data(ns + '.response.' + validatorName, validateResult);
  1652.                        if (validateResult.message) {
  1653.                            this.updateMessage(updateAll ? field : $field, validatorName, validateResult.message);
  1654.                        }
  1655.                        this.updateStatus(updateAll ? field : $field, validateResult.valid ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  1656.                        if (!validateResult.valid && !verbose) {
  1657.                            break;
  1658.                        }
  1659.                    }
  1660.                    // ... or a boolean value
  1661.                    else if ('boolean' === typeof validateResult) {
  1662.                        $field.data(ns + '.response.' + validatorName, validateResult);
  1663.                        this.updateStatus(updateAll ? field : $field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  1664.                        if (!validateResult && !verbose) {
  1665.                            break;
  1666.                        }
  1667.                    }
  1668.                }
  1669.            }
  1670.            return this;
  1671.        },
  1672.        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1673.        // Useful APIs which aren't used internally
  1674.        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1675.  
  1676.        /**
  1677.         * Add a new field
  1678.         *
  1679.         * @param {String|jQuery} field The field name or field element
  1680.         * @param {Object} [options] The validator rules
  1681.         * @returns {FormValidation.Base}
  1682.         */
  1683.        addField: function(field, options) {
  1684.            var ns     = this._namespace,
  1685.                fields = $([]);
  1686.            switch (typeof field) {
  1687.                case 'object':
  1688.                    fields = field;
  1689.                    field  = field.attr('data-' + ns + '-field') || field.attr('name');
  1690.                    break;
  1691.                case 'string':
  1692.                    delete this._cacheFields[field];
  1693.                    fields = this.getFieldElements(field);
  1694.                    break;
  1695.                default:
  1696.                    break;
  1697.            }
  1698.  
  1699.            fields.attr('data-' + ns + '-field', field);
  1700.  
  1701.            var type  = fields.attr('type'),
  1702.                total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1703.  
  1704.            for (var i = 0; i < total; i++) {
  1705.                var $field = fields.eq(i);
  1706.  
  1707.                // Try to parse the options from HTML attributes
  1708.                var opts = this._parseOptions($field);
  1709.                opts = (opts === null) ? options : $.extend(true, options, opts);
  1710.  
  1711.                this.options.fields[field] = $.extend(true, this.options.fields[field], opts);
  1712.  
  1713.                // Update the cache
  1714.                this._cacheFields[field] = this._cacheFields[field] ? this._cacheFields[field].add($field) : $field;
  1715.  
  1716.                // Init the element
  1717.                this._initField(('checkbox' === type || 'radio' === type) ? field : $field);
  1718.            }
  1719.  
  1720.            this.disableSubmitButtons(false);
  1721.            // Trigger an event
  1722.            this.$form.trigger($.Event(this.options.events.fieldAdded), {
  1723.                field: field,
  1724.                element: fields,
  1725.                options: this.options.fields[field]
  1726.            });
  1727.  
  1728.            return this;
  1729.        },
  1730.  
  1731.        /**
  1732.         * Destroy the plugin
  1733.         * It will remove all error messages, feedback icons and turn off the events
  1734.         */
  1735.        destroy: function() {
  1736.            var ns = this._namespace, i, field, fields, $field, validator, $icon, row;
  1737.  
  1738.            // Destroy the validators first
  1739.            for (field in this.options.fields) {
  1740.                fields = this.getFieldElements(field);
  1741.                for (i = 0; i < fields.length; i++) {
  1742.                    $field = fields.eq(i);
  1743.                    for (validator in this.options.fields[field].validators) {
  1744.                        if ($field.data(ns + '.dfs.' + validator)) {
  1745.                            $field.data(ns + '.dfs.' + validator).reject();
  1746.                        }
  1747.                        $field.removeData(ns + '.result.' + validator)
  1748.                              .removeData(ns + '.response.' + validator)
  1749.                              .removeData(ns + '.dfs.' + validator);
  1750.  
  1751.                        // Destroy the validator
  1752.                        if ('function' === typeof FormValidation.Validator[validator].destroy) {
  1753.                            FormValidation.Validator[validator].destroy(this, $field, this.options.fields[field].validators[validator]);
  1754.                        }
  1755.                    }
  1756.                }
  1757.            }
  1758.  
  1759.            // Remove messages and icons
  1760.            for (field in this.options.fields) {
  1761.                fields = this.getFieldElements(field);
  1762.                row    = this.options.fields[field].row || this.options.row.selector;
  1763.                for (i = 0; i < fields.length; i++) {
  1764.                    $field = fields.eq(i);
  1765.                    $field
  1766.                        // Remove all error messages
  1767.                        .data(ns + '.messages')
  1768.                            .find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove().end()
  1769.                            .end()
  1770.                        .removeData(ns + '.messages')
  1771.                        // Remove feedback classes
  1772.                        .closest(row)
  1773.                            .removeClass(this.options.row.valid)
  1774.                            .removeClass(this.options.row.invalid)
  1775.                            .removeClass(this.options.row.feedback)
  1776.                            .end()
  1777.                        // Turn off events
  1778.                        .off('.' + ns)
  1779.                        .removeAttr('data-' + ns + '-field');
  1780.  
  1781.                    // Remove feedback icons, tooltip/popover container
  1782.                    // Support backward
  1783.                    var container = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container))
  1784.                                    ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this)
  1785.                                    : (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container);
  1786.                    if ('tooltip' === container || 'popover' === container) {
  1787.                        this._destroyTooltip($field, container);
  1788.                    }
  1789.  
  1790.                    $icon = $field.data(ns + '.icon');
  1791.                    if ($icon) {
  1792.                        $icon.remove();
  1793.                    }
  1794.                    $field.removeData(ns + '.icon')
  1795.                          // It's safe to remove trigger data here, because it might be used when destroying the validator
  1796.                          .removeData(ns + '.trigger');
  1797.                }
  1798.            }
  1799.            // Destroy the add-ons
  1800.            for (var addOn in this.options.addOns) {
  1801.                if ('function' === typeof FormValidation.AddOn[addOn].destroy) {
  1802.                    FormValidation.AddOn[addOn].destroy(this, this.options.addOns[addOn]);
  1803.                }
  1804.            }
  1805.            this.disableSubmitButtons(false);   // Enable submit buttons
  1806.            this.$hiddenButton.remove();        // Remove the hidden button
  1807.            this.$form
  1808.                .removeClass(this.options.elementClass)
  1809.                .off('.' + ns)
  1810.                .removeData('bootstrapValidator')   // Support backward
  1811.                .removeData('formValidation')
  1812.                // Remove generated hidden elements
  1813.                .find('[data-' + ns + '-submit-hidden]').remove().end()
  1814.                .find('[type="submit"]')
  1815.                    .off('click.' + ns);
  1816.        },
  1817.        /**
  1818.         * Enable/Disable all validators to given field
  1819.         *
  1820.         * @param {String} field The field name
  1821.         * @param {Boolean} enabled Enable/Disable field validators
  1822.         * @param {String} [validatorName] The validator name. If null, all validators will be enabled/disabled
  1823.         * @returns {FormValidation.Base}
  1824.         */
  1825.        enableFieldValidators: function(field, enabled, validatorName) {
  1826.            var validators = this.options.fields[field].validators;
  1827.            // Enable/disable particular validator
  1828.            if (validatorName
  1829.                && validators
  1830.                && validators[validatorName] && validators[validatorName].enabled !== enabled)
  1831.            {
  1832.                this.options.fields[field].validators[validatorName].enabled = enabled;
  1833.                this.updateStatus(field, this.STATUS_NOT_VALIDATED, validatorName);
  1834.            }
  1835.            // Enable/disable all validators
  1836.            else if (!validatorName && this.options.fields[field].enabled !== enabled) {
  1837.                this.options.fields[field].enabled = enabled;
  1838.                for (var v in validators) {
  1839.                    this.enableFieldValidators(field, enabled, v);
  1840.                }
  1841.            }
  1842.            return this;
  1843.        },
  1844.        /**
  1845.         * Some validators have option which its value is dynamic.
  1846.         * For example, the zipCode validator has the country option which might be changed dynamically by a select element.
  1847.         *
  1848.         * @param {jQuery|String} field The field name or element
  1849.         * @param {String|Function} option The option which can be determined by:
  1850.         * - a string
  1851.         * - name of field which defines the value
  1852.         * - name of function which returns the value
  1853.         * - a function returns the value
  1854.         *
  1855.         * The callback function has the format of
  1856.         *      callback: function(value, validator, $field) {
  1857.         *          // value is the value of field
  1858.         *          // validator is the BootstrapValidator instance
  1859.         *          // $field is the field element
  1860.         *      }
  1861.         *
  1862.         * @returns {String}
  1863.         */
  1864.        getDynamicOption: function(field, option) {
  1865.            var $field = ('string' === typeof field) ? this.getFieldElements(field) : field,
  1866.                value  = $field.val();
  1867.            // Option can be determined by
  1868.            // ... a function
  1869.            if ('function' === typeof option) {
  1870.                return FormValidation.Helper.call(option, [value, this, $field]);
  1871.            }
  1872.            // ... value of other field
  1873.            else if ('string' === typeof option) {
  1874.                var $f = this.getFieldElements(option);
  1875.                if ($f.length) {
  1876.                    return $f.val();
  1877.                }
  1878.                // ... return value of callback
  1879.                else {
  1880.                    return FormValidation.Helper.call(option, [value, this, $field]) || option;
  1881.                }
  1882.            }
  1883.            return null;
  1884.        },
  1885.        /**
  1886.         * Get the form element
  1887.         *
  1888.         * @returns {jQuery}
  1889.         */
  1890.        getForm: function() {
  1891.            return this.$form;
  1892.        },
  1893.        /**
  1894.         * Get the list of invalid fields
  1895.         *
  1896.         * @returns {jQuery[]}
  1897.         */
  1898.        getInvalidFields: function() {
  1899.            return this.$invalidFields;
  1900.        },
  1901.        /**
  1902.         * Get the current locale
  1903.         *
  1904.         * @return {String}
  1905.         */
  1906.        getLocale: function() {
  1907.            return this.options.locale;
  1908.        },
  1909.        /**
  1910.         * Get the error messages
  1911.         *
  1912.         * @param {String|jQuery} [field] The field name or field element
  1913.         * If the field is not defined, the method returns all error messages of all fields
  1914.         * @param {String} [validator] The name of validator
  1915.         * If the validator is not defined, the method returns error messages of all validators
  1916.         * @returns {String[]}
  1917.         */
  1918.        getMessages: function(field, validator) {
  1919.            var that     = this,
  1920.                ns       = this._namespace,
  1921.                messages = [],
  1922.                $fields  = $([]);
  1923.            switch (true) {
  1924.                case (field && 'object' === typeof field):
  1925.                    $fields = field;
  1926.                    break;
  1927.                case (field && 'string' === typeof field):
  1928.                    var f = this.getFieldElements(field);
  1929.                    if (f.length > 0) {
  1930.                         var type = f.attr('type');
  1931.                         $fields = ('radio' === type || 'checkbox' === type) ? f.eq(0) : f;
  1932.                     }
  1933.                     break;
  1934.                 default:
  1935.                     $fields = this.$invalidFields;
  1936.                     break;
  1937.             }
  1938.  
  1939.             var filter = validator ? '[data-' + ns + '-validator="' + validator + '"]' : '';
  1940.             $fields.each(function() {
  1941.                 messages = messages.concat(
  1942.                     $(this)
  1943.                         .data(ns + '.messages')
  1944.                         .find('.' + that.options.err.clazz + '[data-' + ns + '-for="' + $(this).attr('data-' + ns + '-field') + '"][data-' + ns + '-result="' + that.STATUS_INVALID + '"]' + filter)
  1945.                         .map(function() {
  1946.                             var v = $(this).attr('data-' + ns + '-validator'),
  1947.                                 f = $(this).attr('data-' + ns + '-for');
  1948.                             return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html();
  1949.                         })
  1950.                         .get()
  1951.                 );
  1952.             });
  1953.  
  1954.             return messages;
  1955.         },
  1956.  
  1957.         /**
  1958.          * Returns the clicked submit button
  1959.          *
  1960.          * @returns {jQuery}
  1961.          */
  1962.         getSubmitButton: function() {
  1963.             return this.$submitButton;
  1964.         },
  1965.  
  1966.         /**
  1967.          * Remove a given field
  1968.          *
  1969.          * @param {String|jQuery} field The field name or field element
  1970.          * @returns {FormValidation.Base}
  1971.          */
  1972.         removeField: function(field) {
  1973.             var ns     = this._namespace,
  1974.                 fields = $([]);
  1975.             switch (typeof field) {
  1976.                 case 'object':
  1977.                     fields = field;
  1978.                     field  = field.attr('data-' + ns + '-field') || field.attr('name');
  1979.                     fields.attr('data-' + ns + '-field', field);
  1980.                     break;
  1981.                 case 'string':
  1982.                     fields = this.getFieldElements(field);
  1983.                     break;
  1984.                 default:
  1985.                     break;
  1986.             }
  1987.  
  1988.             if (fields.length === 0) {
  1989.                 return this;
  1990.             }
  1991.  
  1992.             var type  = fields.attr('type'),
  1993.                 total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1994.  
  1995.             for (var i = 0; i < total; i++) {
  1996.                var $field = fields.eq(i);
  1997.  
  1998.                // Remove from the list of invalid fields
  1999.                this.$invalidFields = this.$invalidFields.not($field);
  2000.  
  2001.                // Update the cache
  2002.                this._cacheFields[field] = this._cacheFields[field].not($field);
  2003.            }
  2004.  
  2005.            if (!this._cacheFields[field] || this._cacheFields[field].length === 0) {
  2006.                delete this.options.fields[field];
  2007.            }
  2008.            if ('checkbox' === type || 'radio' === type) {
  2009.                this._initField(field);
  2010.            }
  2011.  
  2012.            this.disableSubmitButtons(false);
  2013.            // Trigger an event
  2014.            this.$form.trigger($.Event(this.options.events.fieldRemoved), {
  2015.                field: field,
  2016.                element: fields
  2017.            });
  2018.  
  2019.            return this;
  2020.        },
  2021.  
  2022.        /**
  2023.         * Reset given field
  2024.         *
  2025.         * @param {String|jQuery} field The field name or field element
  2026.         * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  2027.         * @returns {FormValidation.Base}
  2028.         */
  2029.        resetField: function(field, resetValue) {
  2030.            var ns      = this._namespace,
  2031.                $fields = $([]);
  2032.            switch (typeof field) {
  2033.                case 'object':
  2034.                    $fields = field;
  2035.                    field   = field.attr('data-' + ns + '-field');
  2036.                    break;
  2037.                case 'string':
  2038.                    $fields = this.getFieldElements(field);
  2039.                    break;
  2040.                default:
  2041.                    break;
  2042.            }
  2043.  
  2044.            var total = $fields.length;
  2045.            if (this.options.fields[field]) {
  2046.                for (var i = 0; i < total; i++) {
  2047.                    for (var validator in this.options.fields[field].validators) {
  2048.                        $fields.eq(i).removeData(ns + '.dfs.' + validator);
  2049.                    }
  2050.                }
  2051.            }
  2052.  
  2053.            // Mark field as not validated yet
  2054.            this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  2055.  
  2056.            if (resetValue) {
  2057.                var type = $fields.attr('type');
  2058.                ('radio' === type || 'checkbox' === type) ? $fields.prop('checked', false).removeAttr('selected') : $fields.val('');
  2059.            }
  2060.  
  2061.            return this;
  2062.        },
  2063.  
  2064.        /**
  2065.         * Reset the form
  2066.         *
  2067.         * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  2068.         * @returns {FormValidation.Base}
  2069.         */
  2070.        resetForm: function(resetValue) {
  2071.            for (var field in this.options.fields) {
  2072.                this.resetField(field, resetValue);
  2073.            }
  2074.  
  2075.            this.$invalidFields = $([]);
  2076.            this.$submitButton  = null;
  2077.  
  2078.            // Enable submit buttons
  2079.            this.disableSubmitButtons(false);
  2080.  
  2081.            return this;
  2082.        },
  2083.  
  2084.        /**
  2085.         * Revalidate given field
  2086.         * It's used when you need to revalidate the field which its value is updated by other plugin
  2087.         *
  2088.         * @param {String|jQuery} field The field name of field element
  2089.         * @returns {FormValidation.Base}
  2090.         */
  2091.        revalidateField: function(field) {
  2092.            this.updateStatus(field, this.STATUS_NOT_VALIDATED)
  2093.                .validateField(field);
  2094.            return this;
  2095.        },
  2096.        /**
  2097.         * Set the locale
  2098.         *
  2099.         * @param {String} locale The locale in format of countrycode_LANGUAGECODE
  2100.         * @returns {FormValidation.Base}
  2101.         */
  2102.        setLocale: function(locale) {
  2103.            this.options.locale = locale;
  2104.            this.$form.trigger($.Event(this.options.events.localeChanged), {
  2105.                locale: locale,
  2106.                bv: this,   // Support backward
  2107.                fv: this
  2108.            });
  2109.            return this;
  2110.        },
  2111.        /**
  2112.         * Update the option of a specific validator
  2113.         *
  2114.         * @param {String|jQuery} field The field name or field element
  2115.         * @param {String} validator The validator name
  2116.         * @param {String} option The option name
  2117.         * @param {String} value The value to set
  2118.         * @returns {FormValidation.Base}
  2119.         */
  2120.        updateOption: function(field, validator, option, value) {
  2121.            var ns = this._namespace;
  2122.            if ('object' === typeof field) {
  2123.                field = field.attr('data-' + ns + '-field');
  2124.            }
  2125.            if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
  2126.                this.options.fields[field].validators[validator][option] = value;
  2127.                this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
  2128.            }
  2129.            return this;
  2130.        },
  2131.        /**
  2132.         * Validate given container
  2133.         * It can be used with isValidContainer() when you want to work with wizard form
  2134.         *
  2135.         * @param {String|jQuery} container The container selector or element
  2136.         * @returns {FormValidation.Base}
  2137.         */
  2138.        validateContainer: function(container) {
  2139.            var that       = this,
  2140.                ns         = this._namespace,
  2141.                fields     = [],
  2142.                $container = ('string' === typeof container) ? $(container) : container;
  2143.            if ($container.length === 0) {
  2144.                return this;
  2145.            }
  2146.            $container.find('[data-' + ns + '-field]').each(function() {
  2147.                var $field = $(this);
  2148.                if (!that._isExcluded($field)) {
  2149.                    fields.push($field);
  2150.                }
  2151.            });
  2152.            var total = fields.length;
  2153.            for (var i = 0; i < total; i++) {
  2154.                this.validateField(fields[i]);
  2155.            }
  2156.            return this;
  2157.        }
  2158.    };
  2159.    // Plugin definition
  2160.    $.fn.formValidation = function(option) {
  2161.        var params = arguments;
  2162.        return this.each(function() {
  2163.            var $this   = $(this),
  2164.                data    = $this.data('formValidation'),
  2165.                options = 'object' === typeof option && option;
  2166.            if (!data) {
  2167.                var framework = (options.framework || $this.attr('data-fv-framework') || 'bootstrap').toLowerCase(),
  2168.                    clazz     = framework.substr(0, 1).toUpperCase() + framework.substr(1);
  2169.                if (typeof FormValidation.Framework[clazz] === 'undefined') {
  2170.                    throw new Error('The class FormValidation.Framework.' + clazz + ' is not implemented');
  2171.                }
  2172.                data = new FormValidation.Framework[clazz](this, options);
  2173.                $this.addClass('fv-form-' + framework)
  2174.                     .data('formValidation', data);
  2175.            }
  2176.            // Allow to call plugin method
  2177.            if ('string' === typeof option) {
  2178.                data[option].apply(data, Array.prototype.slice.call(params, 1));
  2179.            }
  2180.        });
  2181.    };
  2182.    $.fn.formValidation.Constructor = FormValidation.Base;
  2183.    // The default options
  2184.    // Sorted in alphabetical order
  2185.    $.fn.formValidation.DEFAULT_OPTIONS = {
  2186.        // The first invalid field will be focused automatically
  2187.        autoFocus: true,
  2188.        // Support declarative usage (setting options via HTML 5 attributes)
  2189.        // Setting to false can improve the performance
  2190.        declarative: true,
  2191.        // The form CSS class
  2192.        elementClass: 'fv-form',
  2193.        // Use custom event name to avoid window.onerror being invoked by jQuery
  2194.        // See #630
  2195.        events: {
  2196.            // Support backward
  2197.            formInit: 'init.form.fv',
  2198.            formError: 'err.form.fv',
  2199.            formSuccess: 'success.form.fv',
  2200.            fieldAdded: 'added.field.fv',
  2201.            fieldRemoved: 'removed.field.fv',
  2202.            fieldInit: 'init.field.fv',
  2203.            fieldError: 'err.field.fv',
  2204.            fieldSuccess: 'success.field.fv',
  2205.            fieldStatus: 'status.field.fv',
  2206.            localeChanged: 'changed.locale.fv',
  2207.            validatorError: 'err.validator.fv',
  2208.            validatorSuccess: 'success.validator.fv'
  2209.        },
  2210.        // Indicate fields which won't be validated
  2211.        // By default, the plugin will not validate the following kind of fields:
  2212.        // - disabled
  2213.        // - hidden
  2214.        // - invisible
  2215.        //
  2216.        // The setting consists of jQuery filters. Accept 3 formats:
  2217.        // - A string. Use a comma to separate filter
  2218.        // - An array. Each element is a filter
  2219.        // - An array. Each element can be a callback function
  2220.        //      function($field, validator) {
  2221.        //          $field is jQuery object representing the field element
  2222.        //          validator is the BootstrapValidator instance
  2223.        //          return true or false;
  2224.        //      }
  2225.        //
  2226.        // The 3 following settings are equivalent:
  2227.        //
  2228.        // 1) ':disabled, :hidden, :not(:visible)'
  2229.        // 2) [':disabled', ':hidden', ':not(:visible)']
  2230.        // 3) [':disabled', ':hidden', function($field) {
  2231.        //        return !$field.is(':visible');
  2232.        //    }]
  2233.        excluded: [':disabled', ':hidden', ':not(:visible)'],
  2234.  
  2235.        // Map the field name with validator rules
  2236.        fields: null,
  2237.  
  2238.        // Live validating option
  2239.        // Can be one of 3 values:
  2240.        // - enabled: The plugin validates fields as soon as they are changed
  2241.        // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
  2242.        // - submitted: The live validating is enabled after the form is submitted
  2243.        live: 'enabled',
  2244.  
  2245.        // Locale in the format of languagecode_COUNTRYCODE
  2246.        locale: 'en_US',
  2247.  
  2248.        // Default invalid message
  2249.        message: 'This value is not valid',
  2250.  
  2251.        // The field will not be live validated if its length is less than this number of characters
  2252.        threshold: null,
  2253.  
  2254.        // Whether to be verbose when validating a field or not.
  2255.        // Possible values:
  2256.        // - true:  when a field has multiple validators, all of them will be checked, and respectively - if errors occur in
  2257.        //          multiple validators, all of them will be displayed to the user
  2258.        // - false: when a field has multiple validators, validation for this field will be terminated upon the first encountered error.
  2259.        //          Thus, only the very first error message related to this field will be displayed to the user
  2260.        verbose: true,
  2261.  
  2262.        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2263.        // These options mostly are overridden by specific framework
  2264.        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2265.  
  2266.        button: {
  2267.            // The submit buttons selector
  2268.            // These buttons will be disabled to prevent the valid form from multiple submissions
  2269.            selector: '[type="submit"]',
  2270.  
  2271.            // The disabled class
  2272.            disabled: ''
  2273.        },
  2274.  
  2275.        control: {
  2276.            // The CSS class for valid control
  2277.            valid: '',
  2278.  
  2279.            // The CSS class for invalid control
  2280.            invalid: ''
  2281.        },
  2282.  
  2283.        err: {
  2284.            // The CSS class of each message element
  2285.            clazz: '',
  2286.  
  2287.            // The error messages container. It can be:
  2288.            // - 'tooltip' if you want to use Bootstrap tooltip to show error messages
  2289.            // - 'popover' if you want to use Bootstrap popover to show error messages
  2290.            // - a CSS selector indicating the container
  2291.            // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
  2292.            // You also can define the message container for particular field
  2293.            container: null,
  2294.  
  2295.            // Used to determine where the messages are placed
  2296.            parent: null
  2297.        },
  2298.  
  2299.        // Shows ok/error/loading icons based on the field validity.
  2300.        icon: {
  2301.            valid: null,
  2302.            invalid: null,
  2303.            validating: null,
  2304.            feedback: ''
  2305.        },
  2306.  
  2307.        row: {
  2308.            // The CSS selector for indicating the element consists of the field
  2309.            // You should adjust this option if your form group consists of many fields which not all of them need to be validated
  2310.            selector: null,
  2311.            valid: '',
  2312.            invalid: '',
  2313.            feedback: ''
  2314.        }
  2315.    };
  2316. }(jQuery));
  2317. ;(function($) {
  2318.    // Helper methods, which can be used in validator class
  2319.    FormValidation.Helper = {
  2320.        /**
  2321.         * Execute a callback function
  2322.         *
  2323.         * @param {String|Function} functionName Can be
  2324.         * - name of global function
  2325.         * - name of namespace function (such as A.B.C)
  2326.         * - a function
  2327.         * @param {Array} args The callback arguments
  2328.         */
  2329.        call: function(functionName, args) {
  2330.            if ('function' === typeof functionName) {
  2331.                return functionName.apply(this, args);
  2332.            } else if ('string' === typeof functionName) {
  2333.                if ('()' === functionName.substring(functionName.length - 2)) {
  2334.                    functionName = functionName.substring(0, functionName.length - 2);
  2335.                }
  2336.                var ns      = functionName.split('.'),
  2337.                    func    = ns.pop(),
  2338.                    context = window;
  2339.                for (var i = 0; i < ns.length; i++) {
  2340.                    context = context[ns[i]];
  2341.                }
  2342.  
  2343.                return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
  2344.            }
  2345.        },
  2346.  
  2347.        /**
  2348.         * Validate a date
  2349.         *
  2350.         * @param {Number} year The full year in 4 digits
  2351.         * @param {Number} month The month number
  2352.         * @param {Number} day The day number
  2353.         * @param {Boolean} [notInFuture] If true, the date must not be in the future
  2354.         * @returns {Boolean}
  2355.         */
  2356.        date: function(year, month, day, notInFuture) {
  2357.            if (isNaN(year) || isNaN(month) || isNaN(day)) {
  2358.                return false;
  2359.            }
  2360.            if (day.length > 2 || month.length > 2 || year.length > 4) {
  2361.                 return false;
  2362.             }
  2363.  
  2364.             day   = parseInt(day, 10);
  2365.             month = parseInt(month, 10);
  2366.             year  = parseInt(year, 10);
  2367.  
  2368.             if (year < 1000 || year > 9999 || month <= 0 || month > 12) {
  2369.                 return false;
  2370.             }
  2371.             var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  2372.             // Update the number of days in Feb of leap year
  2373.             if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
  2374.                numDays[1] = 29;
  2375.             }
  2376.  
  2377.             // Check the day
  2378.             if (day <= 0 || day > numDays[month - 1]) {
  2379.                 return false;
  2380.             }
  2381.  
  2382.             if (notInFuture === true) {
  2383.                 var currentDate  = new Date(),
  2384.                     currentYear  = currentDate.getFullYear(),
  2385.                     currentMonth = currentDate.getMonth(),
  2386.                     currentDay   = currentDate.getDate();
  2387.                 return (year < currentYear
  2388.                || (year === currentYear && month - 1 < currentMonth)
  2389.                || (year === currentYear && month - 1 === currentMonth && day < currentDay));
  2390.            }
  2391.  
  2392.            return true;
  2393.        },
  2394.  
  2395.        /**
  2396.         * Format a string
  2397.         * It's used to format the error message
  2398.         * format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
  2399.         *
  2400.         * @param {String} message
  2401.         * @param {Array} parameters
  2402.         * @returns {String}
  2403.         */
  2404.        format: function(message, parameters) {
  2405.            if (!$.isArray(parameters)) {
  2406.                parameters = [parameters];
  2407.            }
  2408.            for (var i in parameters) {
  2409.                message = message.replace('%s', parameters[i]);
  2410.            }
  2411.            return message;
  2412.        },
  2413.        /**
  2414.         * Implement Luhn validation algorithm
  2415.         * Credit to https://gist.github.com/ShirtlessKirk/2134376
  2416.         *
  2417.         * @see http://en.wikipedia.org/wiki/Luhn
  2418.         * @param {String} value
  2419.         * @returns {Boolean}
  2420.         */
  2421.        luhn: function(value) {
  2422.            var length  = value.length,
  2423.                mul     = 0,
  2424.                prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
  2425.                sum     = 0;
  2426.            while (length--) {
  2427.                sum += prodArr[mul][parseInt(value.charAt(length), 10)];
  2428.                mul ^= 1;
  2429.            }
  2430.            return (sum % 10 === 0 && sum > 0);
  2431.         },
  2432.  
  2433.         /**
  2434.          * Implement modulus 11, 10 (ISO 7064) algorithm
  2435.          *
  2436.          * @param {String} value
  2437.          * @returns {Boolean}
  2438.          */
  2439.         mod11And10: function(value) {
  2440.             var check  = 5,
  2441.                 length = value.length;
  2442.             for (var i = 0; i < length; i++) {
  2443.                check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
  2444.            }
  2445.            return (check === 1);
  2446.        },
  2447.  
  2448.        /**
  2449.         * Implements Mod 37, 36 (ISO 7064) algorithm
  2450.         * Usages:
  2451.         * mod37And36('A12425GABC1234002M')
  2452.         * mod37And36('002006673085', '0123456789')
  2453.         *
  2454.         * @param {String} value
  2455.         * @param {String} [alphabet]
  2456.         * @returns {Boolean}
  2457.         */
  2458.        mod37And36: function(value, alphabet) {
  2459.            alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  2460.            var modulus = alphabet.length,
  2461.                length  = value.length,
  2462.                check   = Math.floor(modulus / 2);
  2463.            for (var i = 0; i < length; i++) {
  2464.                check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
  2465.            }
  2466.            return (check === 1);
  2467.        }
  2468.    };
  2469. }(jQuery));
  2470. ;(function($) {
  2471.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2472.        'en_US': {
  2473.            base64: {
  2474.                'default': 'Please enter a valid base 64 encoded'
  2475.            }
  2476.        }
  2477.    });
  2478.  
  2479.    FormValidation.Validator.base64 = {
  2480.        /**
  2481.         * Return true if the input value is a base 64 encoded string.
  2482.         *
  2483.         * @param {FormValidation.Base} validator The validator plugin instance
  2484.         * @param {jQuery} $field Field element
  2485.         * @param {Object} options Can consist of the following keys:
  2486.         * - message: The invalid message
  2487.         * @returns {Boolean}
  2488.         */
  2489.        validate: function(validator, $field, options) {
  2490.            var value = validator.getFieldValue($field, 'base64');
  2491.            if (value === '') {
  2492.                return true;
  2493.            }
  2494.  
  2495.            return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  2496.        }
  2497.    };
  2498. }(jQuery));
  2499. ;(function($) {
  2500.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2501.        'en_US': {
  2502.            between: {
  2503.                'default': 'Please enter a value between %s and %s',
  2504.                notInclusive: 'Please enter a value between %s and %s strictly'
  2505.            }
  2506.        }
  2507.    });
  2508.  
  2509.    FormValidation.Validator.between = {
  2510.        html5Attributes: {
  2511.            message: 'message',
  2512.            min: 'min',
  2513.            max: 'max',
  2514.            inclusive: 'inclusive'
  2515.        },
  2516.  
  2517.        enableByHtml5: function($field) {
  2518.            if ('range' === $field.attr('type')) {
  2519.                return {
  2520.                    min: $field.attr('min'),
  2521.                    max: $field.attr('max')
  2522.                };
  2523.            }
  2524.  
  2525.            return false;
  2526.        },
  2527.  
  2528.        /**
  2529.         * Return true if the input value is between (strictly or not) two given numbers
  2530.         *
  2531.         * @param {FormValidation.Base} validator The validator plugin instance
  2532.         * @param {jQuery} $field Field element
  2533.         * @param {Object} options Can consist of the following keys:
  2534.         * - min
  2535.         * - max
  2536.         *
  2537.         * The min, max keys define the number which the field value compares to. min, max can be
  2538.         *      - A number
  2539.         *      - Name of field which its value defines the number
  2540.         *      - Name of callback function that returns the number
  2541.         *      - A callback function that returns the number
  2542.         *
  2543.         * - inclusive [optional]: Can be true or false. Default is true
  2544.         * - message: The invalid message
  2545.         * @returns {Boolean|Object}
  2546.         */
  2547.        validate: function(validator, $field, options) {
  2548.            var value = validator.getFieldValue($field, 'between');
  2549.            if (value === '') {
  2550.                return true;
  2551.            }
  2552.  
  2553.             value = this._format(value);
  2554.            if (!$.isNumeric(value)) {
  2555.                return false;
  2556.            }
  2557.  
  2558.            var locale   = validator.getLocale(),
  2559.                min      = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  2560.                max      = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  2561.                minValue = this._format(min),
  2562.                maxValue = this._format(max);
  2563.  
  2564.            value = parseFloat(value);
  2565.             return (options.inclusive === true || options.inclusive === undefined)
  2566.                    ? {
  2567.                        valid: value >= minValue && value <= maxValue,
  2568.                        message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].between['default'], [min, max])
  2569.                    }
  2570.                    : {
  2571.                        valid: value > minValue  && value <  maxValue,
  2572.                        message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].between.notInclusive, [min, max])
  2573.                    };
  2574.         },
  2575.  
  2576.         _format: function(value) {
  2577.             return (value + '').replace(',', '.');
  2578.         }
  2579.     };
  2580. }(jQuery));
  2581. ;(function($) {
  2582.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2583.         'en_US': {
  2584.             bic: {
  2585.                 'default': 'Please enter a valid BIC number'
  2586.             }
  2587.         }
  2588.     });
  2589.  
  2590.     FormValidation.Validator.bic = {
  2591.         /**
  2592.          * Validate an Business Identifier Code (BIC), also known as ISO 9362, SWIFT-BIC, SWIFT ID or SWIFT code
  2593.          *
  2594.          * For more information see http://en.wikipedia.org/wiki/ISO_9362
  2595.          *
  2596.          * @todo The 5 and 6 characters are an ISO 3166-1 country code, this could also be validated
  2597.          * @param {FormValidation.Base} validator The validator plugin instance
  2598.          * @param {jQuery} $field Field element
  2599.          * @param {Object} options Can consist of the following keys:
  2600.          * - message: The invalid message
  2601.          * @returns {Object}
  2602.          */
  2603.         validate: function(validator, $field, options) {
  2604.             var value = validator.getFieldValue($field, 'bic');
  2605.             if (value === '') {
  2606.                 return true;
  2607.             }
  2608.             return /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value);
  2609.         }
  2610.     };
  2611. }(jQuery));
  2612. ;(function($) {
  2613.     FormValidation.Validator.blank = {
  2614.         /**
  2615.          * Placeholder validator that can be used to display a custom validation message
  2616.          * returned from the server
  2617.          * Example:
  2618.          *
  2619.          * (1) a "blank" validator is applied to an input field.
  2620.          * (2) data is entered via the UI that is unable to be validated client-side.
  2621.          * (3) server returns a 400 with JSON data that contains the field that failed
  2622.          *     validation and an associated message.
  2623.          * (4) ajax 400 call handler does the following:
  2624.          *
  2625.          *      bv.updateMessage(field, 'blank', errorMessage);
  2626.          *      bv.updateStatus(field, 'INVALID');
  2627.          *
  2628.          * @see https://github.com/formvalidation/formvalidation/issues/542
  2629.          * @see https://github.com/formvalidation/formvalidation/pull/666
  2630.          * @param {FormValidation.Base} validator The validator plugin instance
  2631.          * @param {jQuery} $field Field element
  2632.          * @param {Object} options Can consist of the following keys:
  2633.          * - message: The invalid message
  2634.          * @returns {Boolean}
  2635.          */
  2636.         validate: function(validator, $field, options) {
  2637.             return true;
  2638.         }
  2639.     };
  2640. }(jQuery));
  2641. ;(function($) {
  2642.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2643.         'en_US': {
  2644.             callback: {
  2645.                 'default': 'Please enter a valid value'
  2646.             }
  2647.         }
  2648.     });
  2649.  
  2650.     FormValidation.Validator.callback = {
  2651.         html5Attributes: {
  2652.             message: 'message',
  2653.             callback: 'callback'
  2654.         },
  2655.  
  2656.         /**
  2657.          * Return result from the callback method
  2658.          *
  2659.          * @param {FormValidation.Base} validator The validator plugin instance
  2660.          * @param {jQuery} $field Field element
  2661.          * @param {Object} options Can consist of the following keys:
  2662.          * - callback: The callback method that passes 2 parameters:
  2663.          *      callback: function(fieldValue, validator, $field) {
  2664.          *          // fieldValue is the value of field
  2665.          *          // validator is instance of BootstrapValidator
  2666.          *          // $field is the field element
  2667.          *      }
  2668.          * - message: The invalid message
  2669.          * @returns {Deferred}
  2670.          */
  2671.         validate: function(validator, $field, options) {
  2672.             var value  = validator.getFieldValue($field, 'callback'),
  2673.                 dfd    = new $.Deferred(),
  2674.                 result = { valid: true };
  2675.  
  2676.             if (options.callback) {
  2677.                 var response = FormValidation.Helper.call(options.callback, [value, validator, $field]);
  2678.                 result = ('boolean' === typeof response) ? { valid: response } : response;
  2679.             }
  2680.  
  2681.             dfd.resolve($field, 'callback', result);
  2682.             return dfd;
  2683.         }
  2684.     };
  2685. }(jQuery));
  2686. ;(function($) {
  2687.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2688.         'en_US': {
  2689.             choice: {
  2690.                 'default': 'Please enter a valid value',
  2691.                 less: 'Please choose %s options at minimum',
  2692.                 more: 'Please choose %s options at maximum',
  2693.                 between: 'Please choose %s - %s options'
  2694.             }
  2695.         }
  2696.     });
  2697.  
  2698.     FormValidation.Validator.choice = {
  2699.         html5Attributes: {
  2700.             message: 'message',
  2701.             min: 'min',
  2702.             max: 'max'
  2703.         },
  2704.  
  2705.         /**
  2706.          * Check if the number of checked boxes are less or more than a given number
  2707.          *
  2708.          * @param {FormValidation.Base} validator The validator plugin instance
  2709.          * @param {jQuery} $field Field element
  2710.          * @param {Object} options Consists of following keys:
  2711.          * - min
  2712.          * - max
  2713.          *
  2714.          * At least one of two keys is required
  2715.          * The min, max keys define the number which the field value compares to. min, max can be
  2716.          *      - A number
  2717.          *      - Name of field which its value defines the number
  2718.          *      - Name of callback function that returns the number
  2719.          *      - A callback function that returns the number
  2720.          *
  2721.          * - message: The invalid message
  2722.          * @returns {Object}
  2723.          */
  2724.         validate: function(validator, $field, options) {
  2725.             var locale     = validator.getLocale(),
  2726.                 ns         = validator.getNamespace(),
  2727.                 numChoices = $field.is('select')
  2728.                             ? validator.getFieldElements($field.attr('data-' + ns + '-field')).find('option').filter(':selected').length
  2729.                             : validator.getFieldElements($field.attr('data-' + ns + '-field')).filter(':checked').length,
  2730.                 min        = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
  2731.                 max        = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
  2732.                 isValid    = true,
  2733.                 message    = options.message || FormValidation.I18n[locale].choice['default'];
  2734.  
  2735.             if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
  2736.                isValid = false;
  2737.             }
  2738.  
  2739.             switch (true) {
  2740.                 case (!!min && !!max):
  2741.                    message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.between, [parseInt(min, 10), parseInt(max, 10)]);
  2742.                     break;
  2743.  
  2744.                 case (!!min):
  2745.                     message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.less, parseInt(min, 10));
  2746.                     break;
  2747.  
  2748.                 case (!!max):
  2749.                     message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.more, parseInt(max, 10));
  2750.                     break;
  2751.  
  2752.                 default:
  2753.                     break;
  2754.             }
  2755.  
  2756.             return { valid: isValid, message: message };
  2757.         }
  2758.     };
  2759. }(jQuery));
  2760. ;(function($) {
  2761.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2762.         'en_US': {
  2763.             color: {
  2764.                 'default': 'Please enter a valid color'
  2765.             }
  2766.         }
  2767.     });
  2768.  
  2769.     FormValidation.Validator.color = {
  2770.         html5Attributes: {
  2771.             message: 'message',
  2772.             type: 'type'
  2773.         },
  2774.  
  2775.         enableByHtml5: function($field) {
  2776.             return ('color' === $field.attr('type'));
  2777.         },
  2778.  
  2779.         SUPPORTED_TYPES: [
  2780.             'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'keyword'
  2781.         ],
  2782.  
  2783.         KEYWORD_COLORS: [
  2784.             // Colors start with A
  2785.             'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
  2786.             // B
  2787.             'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood',
  2788.             // C
  2789.             'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan',
  2790.             // D
  2791.             'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta',
  2792.             'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue',
  2793.             'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray',
  2794.             'dimgrey', 'dodgerblue',
  2795.             // F
  2796.             'firebrick', 'floralwhite', 'forestgreen', 'fuchsia',
  2797.             // G
  2798.             'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey',
  2799.             // H
  2800.             'honeydew', 'hotpink',
  2801.             // I
  2802.             'indianred', 'indigo', 'ivory',
  2803.             // K
  2804.             'khaki',
  2805.             // L
  2806.             'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
  2807.             'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
  2808.             'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen',
  2809.             'linen',
  2810.             // M
  2811.             'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen',
  2812.             'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream',
  2813.             'mistyrose', 'moccasin',
  2814.             // N
  2815.             'navajowhite', 'navy',
  2816.             // O
  2817.             'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid',
  2818.             // P
  2819.             'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink',
  2820.             'plum', 'powderblue', 'purple',
  2821.             // R
  2822.             'red', 'rosybrown', 'royalblue',
  2823.             // S
  2824.             'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
  2825.             'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue',
  2826.             // T
  2827.             'tan', 'teal', 'thistle', 'tomato', 'transparent', 'turquoise',
  2828.             // V
  2829.             'violet',
  2830.             // W
  2831.             'wheat', 'white', 'whitesmoke',
  2832.             // Y
  2833.             'yellow', 'yellowgreen'
  2834.         ],
  2835.  
  2836.         /**
  2837.          * Return true if the input value is a valid color
  2838.          *
  2839.          * @param {FormValidation.Base} validator The validator plugin instance
  2840.          * @param {jQuery} $field Field element
  2841.          * @param {Object} options Can consist of the following keys:
  2842.          * - message: The invalid message
  2843.          * - type: The array of valid color types
  2844.          * @returns {Boolean}
  2845.          */
  2846.         validate: function(validator, $field, options) {
  2847.             var value = validator.getFieldValue($field, 'color');
  2848.             if (value === '') {
  2849.                 return true;
  2850.             }
  2851.  
  2852.             // Only accept 6 hex character values due to the HTML 5 spec
  2853.             // See http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
  2854.             if (this.enableByHtml5($field)) {
  2855.                 return /^#[0-9A-F]{6}$/i.test(value);
  2856.             }
  2857.  
  2858.             var types = options.type || this.SUPPORTED_TYPES;
  2859.             if (!$.isArray(types)) {
  2860.                 types = types.replace(/s/g, '').split(',');
  2861.             }
  2862.  
  2863.             var method,
  2864.                 type,
  2865.                 isValid = false;
  2866.  
  2867.             for (var i = 0; i < types.length; i++) {
  2868.                type    = types[i];
  2869.                method  = '_' + type.toLowerCase();
  2870.                isValid = isValid || this[method](value);
  2871.                if (isValid) {
  2872.                    return true;
  2873.                }
  2874.            }
  2875.  
  2876.            return false;
  2877.        },
  2878.  
  2879.        _hex: function(value) {
  2880.            return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2881.        },
  2882.  
  2883.        _hsl: function(value) {
  2884.            return /^hsl\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/.test(value);
  2885.        },
  2886.  
  2887.        _hsla: function(value) {
  2888.            return /^hsla\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/.test(value);
  2889.        },
  2890.  
  2891.        _keyword: function(value) {
  2892.            return $.inArray(value, this.KEYWORD_COLORS) >= 0;
  2893.         },
  2894.  
  2895.         _rgb: function(value) {
  2896.             var regexInteger = /^rgb\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){2}(\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*)\)$/,
  2897.                 regexPercent = /^rgb\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/;
  2898.             return regexInteger.test(value) || regexPercent.test(value);
  2899.         },
  2900.  
  2901.         _rgba: function(value) {
  2902.             var regexInteger = /^rgba\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/,
  2903.                 regexPercent = /^rgba\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/;
  2904.             return regexInteger.test(value) || regexPercent.test(value);
  2905.         }
  2906.     };
  2907. }(jQuery));
  2908. ;(function($) {
  2909.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2910.         'en_US': {
  2911.             creditCard: {
  2912.                 'default': 'Please enter a valid credit card number'
  2913.             }
  2914.         }
  2915.     });
  2916.  
  2917.     FormValidation.Validator.creditCard = {
  2918.         /**
  2919.          * Return true if the input value is valid credit card number
  2920.          * Based on https://gist.github.com/DiegoSalazar/4075533
  2921.          *
  2922.          * @param {FormValidation.Base} validator The validator plugin instance
  2923.          * @param {jQuery} $field Field element
  2924.          * @param {Object} [options] Can consist of the following key:
  2925.          * - message: The invalid message
  2926.          * @returns {Boolean|Object}
  2927.          */
  2928.         validate: function(validator, $field, options) {
  2929.             var value = validator.getFieldValue($field, 'creditCard');
  2930.             if (value === '') {
  2931.                 return true;
  2932.             }
  2933.  
  2934.             // Accept only digits, dashes or spaces
  2935.             if (/[^0-9-\s]+/.test(value)) {
  2936.                 return false;
  2937.             }
  2938.             value = value.replace(/\D/g, '');
  2939.  
  2940.             if (!FormValidation.Helper.luhn(value)) {
  2941.                 return false;
  2942.             }
  2943.  
  2944.             // Validate the card number based on prefix (IIN ranges) and length
  2945.             var cards = {
  2946.                 AMERICAN_EXPRESS: {
  2947.                     length: [15],
  2948.                     prefix: ['34', '37']
  2949.                 },
  2950.                 DINERS_CLUB: {
  2951.                     length: [14],
  2952.                     prefix: ['300', '301', '302', '303', '304', '305', '36']
  2953.                 },
  2954.                 DINERS_CLUB_US: {
  2955.                     length: [16],
  2956.                     prefix: ['54', '55']
  2957.                 },
  2958.                 DISCOVER: {
  2959.                     length: [16],
  2960.                     prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2961.                              '62214', '62215', '62216', '62217', '62218', '62219',
  2962.                              '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2963.                              '62290', '62291', '622920', '622921', '622922', '622923',
  2964.                              '622924', '622925', '644', '645', '646', '647', '648',
  2965.                              '649', '65']
  2966.                 },
  2967.                 JCB: {
  2968.                     length: [16],
  2969.                     prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2970.                 },
  2971.                 LASER: {
  2972.                     length: [16, 17, 18, 19],
  2973.                     prefix: ['6304', '6706', '6771', '6709']
  2974.                 },
  2975.                 MAESTRO: {
  2976.                     length: [12, 13, 14, 15, 16, 17, 18, 19],
  2977.                     prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2978.                 },
  2979.                 MASTERCARD: {
  2980.                     length: [16],
  2981.                     prefix: ['51', '52', '53', '54', '55']
  2982.                 },
  2983.                 SOLO: {
  2984.                     length: [16, 18, 19],
  2985.                     prefix: ['6334', '6767']
  2986.                 },
  2987.                 UNIONPAY: {
  2988.                     length: [16, 17, 18, 19],
  2989.                     prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2990.                              '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2991.                              '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2992.                              '622920', '622921', '622922', '622923', '622924', '622925']
  2993.                 },
  2994.                 VISA: {
  2995.                     length: [16],
  2996.                     prefix: ['4']
  2997.                 }
  2998.             };
  2999.  
  3000.             var type, i;
  3001.             for (type in cards) {
  3002.                 for (i in cards[type].prefix) {
  3003.                     if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i]     // Check the prefix
  3004.                         && $.inArray(value.length, cards[type].length) !== -1)                      // and length
  3005.                    {
  3006.                        return {
  3007.                            valid: true,
  3008.                            type: type
  3009.                        };
  3010.                     }
  3011.                 }
  3012.             }
  3013.  
  3014.             return false;
  3015.         }
  3016.     };
  3017. }(jQuery));
  3018. ;(function($) {
  3019.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3020.         'en_US': {
  3021.             cusip: {
  3022.                 'default': 'Please enter a valid CUSIP number'
  3023.             }
  3024.         }
  3025.     });
  3026.  
  3027.     FormValidation.Validator.cusip = {
  3028.         /**
  3029.          * Validate a CUSIP number
  3030.          * Examples:
  3031.          * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  3032.          * - Invalid: 31430F200, 022615AC2
  3033.          *
  3034.          * @see http://en.wikipedia.org/wiki/CUSIP
  3035.          * @param {FormValidation.Base} validator The validator plugin instance
  3036.          * @param {jQuery} $field Field element
  3037.          * @param {Object} [options] Can consist of the following keys:
  3038.          * - message: The invalid message
  3039.          * @returns {Boolean}
  3040.          */
  3041.         validate: function(validator, $field, options) {
  3042.             var value = validator.getFieldValue($field, 'cusip');
  3043.             if (value === '') {
  3044.                 return true;
  3045.             }
  3046.  
  3047.             value = value.toUpperCase();
  3048.             if (!/^[0-9A-Z]{9}$/.test(value)) {
  3049.                 return false;
  3050.             }
  3051.  
  3052.             var converted = $.map(value.split(''), function(item) {
  3053.                                 var code = item.charCodeAt(0);
  3054.                                 return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  3055.                                            // Replace A, B, C, ..., Z with 10, 11, ..., 35
  3056.                                            ? (code - 'A'.charCodeAt(0) + 10)
  3057.                                            : item;
  3058.                             }),
  3059.                 length    = converted.length,
  3060.                 sum       = 0;
  3061.             for (var i = 0; i < length - 1; i++) {
  3062.                var num = parseInt(converted[i], 10);
  3063.                if (i % 2 !== 0) {
  3064.                    num *= 2;
  3065.                }
  3066.                if (num > 9) {
  3067.                     num -= 9;
  3068.                 }
  3069.                 sum += num;
  3070.             }
  3071.  
  3072.             sum = (10 - (sum % 10)) % 10;
  3073.             return sum === parseInt(converted[length - 1], 10);
  3074.         }
  3075.     };
  3076. }(jQuery));
  3077. ;(function($) {
  3078.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3079.         'en_US': {
  3080.             cvv: {
  3081.                 'default': 'Please enter a valid CVV number'
  3082.             }
  3083.         }
  3084.     });
  3085.  
  3086.     FormValidation.Validator.cvv = {
  3087.         html5Attributes: {
  3088.             message: 'message',
  3089.             ccfield: 'creditCardField'
  3090.         },
  3091.  
  3092.         /**
  3093.          * Bind the validator on the live change of the credit card field
  3094.          *
  3095.          * @param {FormValidation.Base} validator The validator plugin instance
  3096.          * @param {jQuery} $field Field element
  3097.          * @param {Object} options Consists of the following key:
  3098.          * - creditCardField: The credit card number field
  3099.          */
  3100.         init: function(validator, $field, options) {
  3101.             if (options.creditCardField) {
  3102.                 var creditCardField = validator.getFieldElements(options.creditCardField);
  3103.                 validator.onLiveChange(creditCardField, 'live_cvv', function() {
  3104.                     var status = validator.getStatus($field, 'cvv');
  3105.                     if (status !== validator.STATUS_NOT_VALIDATED) {
  3106.                         validator.revalidateField($field);
  3107.                     }
  3108.                 });
  3109.             }
  3110.         },
  3111.  
  3112.         /**
  3113.          * Unbind the validator on the live change of the credit card field
  3114.          *
  3115.          * @param {FormValidation.Base} validator The validator plugin instance
  3116.          * @param {jQuery} $field Field element
  3117.          * @param {Object} options Consists of the following key:
  3118.          * - creditCardField: The credit card number field
  3119.          */
  3120.         destroy: function(validator, $field, options) {
  3121.             if (options.creditCardField) {
  3122.                 var creditCardField = validator.getFieldElements(options.creditCardField);
  3123.                 validator.offLiveChange(creditCardField, 'live_cvv');
  3124.             }
  3125.         },
  3126.  
  3127.         /**
  3128.          * Return true if the input value is a valid CVV number.
  3129.          *
  3130.          * @param {FormValidation.Base} validator The validator plugin instance
  3131.          * @param {jQuery} $field Field element
  3132.          * @param {Object} options Can consist of the following keys:
  3133.          * - creditCardField: The credit card number field. It can be null
  3134.          * - message: The invalid message
  3135.          * @returns {Boolean}
  3136.          */
  3137.         validate: function(validator, $field, options) {
  3138.             var value = validator.getFieldValue($field, 'cvv');
  3139.             if (value === '') {
  3140.                 return true;
  3141.             }
  3142.  
  3143.             if (!/^[0-9]{3,4}$/.test(value)) {
  3144.                 return false;
  3145.             }
  3146.  
  3147.             if (!options.creditCardField) {
  3148.                 return true;
  3149.             }
  3150.  
  3151.             // Get the credit card number
  3152.             var creditCard = validator.getFieldElements(options.creditCardField).val();
  3153.             if (creditCard === '') {
  3154.                 return true;
  3155.             }
  3156.            
  3157.             creditCard = creditCard.replace(/\D/g, '');
  3158.  
  3159.             // Supported credit card types
  3160.             var cards = {
  3161.                 AMERICAN_EXPRESS: {
  3162.                     length: [15],
  3163.                     prefix: ['34', '37']
  3164.                 },
  3165.                 DINERS_CLUB: {
  3166.                     length: [14],
  3167.                     prefix: ['300', '301', '302', '303', '304', '305', '36']
  3168.                 },
  3169.                 DINERS_CLUB_US: {
  3170.                     length: [16],
  3171.                     prefix: ['54', '55']
  3172.                 },
  3173.                 DISCOVER: {
  3174.                     length: [16],
  3175.                     prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  3176.                              '62214', '62215', '62216', '62217', '62218', '62219',
  3177.                              '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  3178.                              '62290', '62291', '622920', '622921', '622922', '622923',
  3179.                              '622924', '622925', '644', '645', '646', '647', '648',
  3180.                              '649', '65']
  3181.                 },
  3182.                 JCB: {
  3183.                     length: [16],
  3184.                     prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  3185.                 },
  3186.                 LASER: {
  3187.                     length: [16, 17, 18, 19],
  3188.                     prefix: ['6304', '6706', '6771', '6709']
  3189.                 },
  3190.                 MAESTRO: {
  3191.                     length: [12, 13, 14, 15, 16, 17, 18, 19],
  3192.                     prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  3193.                 },
  3194.                 MASTERCARD: {
  3195.                     length: [16],
  3196.                     prefix: ['51', '52', '53', '54', '55']
  3197.                 },
  3198.                 SOLO: {
  3199.                     length: [16, 18, 19],
  3200.                     prefix: ['6334', '6767']
  3201.                 },
  3202.                 UNIONPAY: {
  3203.                     length: [16, 17, 18, 19],
  3204.                     prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  3205.                              '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  3206.                              '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  3207.                              '622920', '622921', '622922', '622923', '622924', '622925']
  3208.                 },
  3209.                 VISA: {
  3210.                     length: [16],
  3211.                     prefix: ['4']
  3212.                 }
  3213.             };
  3214.             var type, i, creditCardType = null;
  3215.             for (type in cards) {
  3216.                 for (i in cards[type].prefix) {
  3217.                     if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i]    // Check the prefix
  3218.                         && $.inArray(creditCard.length, cards[type].length) !== -1)                     // and length
  3219.                    {
  3220.                        creditCardType = type;
  3221.                         break;
  3222.                     }
  3223.                 }
  3224.             }
  3225.  
  3226.             return (creditCardType === null)
  3227.                         ? false
  3228.                         : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  3229.         }
  3230.     };
  3231. }(jQuery));
  3232. ;(function($) {
  3233.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3234.         'en_US': {
  3235.             date: {
  3236.                 'default': 'Please enter a valid date',
  3237.                 min: 'Please enter a date after %s',
  3238.                 max: 'Please enter a date before %s',
  3239.                 range: 'Please enter a date in the range %s - %s'
  3240.             }
  3241.         }
  3242.     });
  3243.  
  3244.     FormValidation.Validator.date = {
  3245.         html5Attributes: {
  3246.             message: 'message',
  3247.             format: 'format',
  3248.             min: 'min',
  3249.             max: 'max',
  3250.             separator: 'separator'
  3251.         },
  3252.  
  3253.         /**
  3254.          * Return true if the input value is valid date
  3255.          *
  3256.          * @param {FormValidation.Base} validator The validator plugin instance
  3257.          * @param {jQuery} $field Field element
  3258.          * @param {Object} options Can consist of the following keys:
  3259.          * - message: The invalid message
  3260.          * - min: the minimum date
  3261.          * - max: the maximum date
  3262.          * - separator: Use to separate the date, month, and year.
  3263.          * By default, it is /
  3264.          * - format: The date format. Default is MM/DD/YYYY
  3265.          * The format can be:
  3266.          *
  3267.          * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  3268.          * ii) date and time:
  3269.          * The time can consist of h, m, s parts which are separated by :
  3270.          * ii) date, time and A (indicating AM or PM)
  3271.          * @returns {Boolean|Object}
  3272.          */
  3273.         validate: function(validator, $field, options) {
  3274.             var value = validator.getFieldValue($field, 'date');
  3275.             if (value === '') {
  3276.                 return true;
  3277.             }
  3278.  
  3279.             options.format = options.format || 'MM/DD/YYYY';
  3280.  
  3281.             // #683: Force the format to YYYY-MM-DD as the default browser behaviour when using type="date" attribute
  3282.             if ($field.attr('type') === 'date') {
  3283.                 options.format = 'YYYY-MM-DD';
  3284.             }
  3285.  
  3286.             var locale     = validator.getLocale(),
  3287.                 message    = options.message || FormValidation.I18n[locale].date['default'],
  3288.                 formats    = options.format.split(' '),
  3289.                 dateFormat = formats[0],
  3290.                 timeFormat = (formats.length > 1) ? formats[1] : null,
  3291.                 amOrPm     = (formats.length > 2) ? formats[2] : null,
  3292.                 sections   = value.split(' '),
  3293.                 date       = sections[0],
  3294.                 time       = (sections.length > 1) ? sections[1] : null;
  3295.  
  3296.             if (formats.length !== sections.length) {
  3297.                 return {
  3298.                     valid: false,
  3299.                     message: message
  3300.                 };
  3301.             }
  3302.  
  3303.             // Determine the separator
  3304.             var separator = options.separator;
  3305.             if (!separator) {
  3306.                 separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
  3307.             }
  3308.             if (separator === null || date.indexOf(separator) === -1) {
  3309.                 return {
  3310.                     valid: false,
  3311.                     message: message
  3312.                 };
  3313.             }
  3314.  
  3315.             // Determine the date
  3316.             date       = date.split(separator);
  3317.             dateFormat = dateFormat.split(separator);
  3318.             if (date.length !== dateFormat.length) {
  3319.                 return {
  3320.                     valid: false,
  3321.                     message: message
  3322.                 };
  3323.             }
  3324.  
  3325.             var year  = date[$.inArray('YYYY', dateFormat)],
  3326.                 month = date[$.inArray('MM', dateFormat)],
  3327.                 day   = date[$.inArray('DD', dateFormat)];
  3328.  
  3329.             if (!year || !month || !day || year.length !== 4) {
  3330.                 return {
  3331.                     valid: false,
  3332.                     message: message
  3333.                 };
  3334.             }
  3335.  
  3336.             // Determine the time
  3337.             var minutes = null, hours = null, seconds = null;
  3338.             if (timeFormat) {
  3339.                 timeFormat = timeFormat.split(':');
  3340.                 time       = time.split(':');
  3341.  
  3342.                 if (timeFormat.length !== time.length) {
  3343.                     return {
  3344.                         valid: false,
  3345.                         message: message
  3346.                     };
  3347.                 }
  3348.  
  3349.                 hours   = time.length > 0 ? time[0] : null;
  3350.                 minutes = time.length > 1 ? time[1] : null;
  3351.                 seconds = time.length > 2 ? time[2] : null;
  3352.  
  3353.                 if (hours === '' || minutes === '' || seconds === '') {
  3354.                     return {
  3355.                         valid: false,
  3356.                         message: message
  3357.                     };
  3358.                 }
  3359.  
  3360.                 // Validate seconds
  3361.                 if (seconds) {
  3362.                     if (isNaN(seconds) || seconds.length > 2) {
  3363.                         return {
  3364.                             valid: false,
  3365.                             message: message
  3366.                         };
  3367.                     }
  3368.                     seconds = parseInt(seconds, 10);
  3369.                     if (seconds < 0 || seconds > 60) {
  3370.                         return {
  3371.                             valid: false,
  3372.                             message: message
  3373.                         };
  3374.                     }
  3375.                 }
  3376.  
  3377.                 // Validate hours
  3378.                 if (hours) {
  3379.                     if (isNaN(hours) || hours.length > 2) {
  3380.                         return {
  3381.                             valid: false,
  3382.                             message: message
  3383.                         };
  3384.                     }
  3385.                     hours = parseInt(hours, 10);
  3386.                     if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  3387.                        return {
  3388.                            valid: false,
  3389.                            message: message
  3390.                        };
  3391.                     }
  3392.                 }
  3393.  
  3394.                 // Validate minutes
  3395.                 if (minutes) {
  3396.                     if (isNaN(minutes) || minutes.length > 2) {
  3397.                         return {
  3398.                             valid: false,
  3399.                             message: message
  3400.                         };
  3401.                     }
  3402.                     minutes = parseInt(minutes, 10);
  3403.                     if (minutes < 0 || minutes > 59) {
  3404.                         return {
  3405.                             valid: false,
  3406.                             message: message
  3407.                         };
  3408.                     }
  3409.                 }
  3410.             }
  3411.  
  3412.             // Validate day, month, and year
  3413.             var valid     = FormValidation.Helper.date(year, month, day),
  3414.                 // declare the date, min and max objects
  3415.                 min       = null,
  3416.                 max       = null,
  3417.                 minOption = options.min,
  3418.                 maxOption = options.max;
  3419.  
  3420.             if (minOption) {
  3421.                 if (isNaN(Date.parse(minOption))) {
  3422.                     minOption = validator.getDynamicOption($field, minOption);
  3423.                 }
  3424.  
  3425.                 min       = minOption instanceof Date ? minOption : this._parseDate(minOption, dateFormat, separator);
  3426.                 // In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)"
  3427.                 minOption = minOption instanceof Date ? this._formatDate(minOption, options.format) : minOption;
  3428.             }
  3429.  
  3430.             if (maxOption) {
  3431.                 if (isNaN(Date.parse(maxOption))) {
  3432.                     maxOption = validator.getDynamicOption($field, maxOption);
  3433.                 }
  3434.  
  3435.                 max       = maxOption instanceof Date ? maxOption : this._parseDate(maxOption, dateFormat, separator);
  3436.                 // In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)"
  3437.                 maxOption = maxOption instanceof Date ? this._formatDate(maxOption, options.format) : maxOption;
  3438.             }
  3439.  
  3440.             date = new Date(year, month -1, day, hours, minutes, seconds);
  3441.  
  3442.             switch (true) {
  3443.                 case (minOption && !maxOption && valid):
  3444.                    valid   = date.getTime() >= min.getTime();
  3445.                     message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.min, minOption);
  3446.                     break;
  3447.  
  3448.                 case (maxOption && !minOption && valid):
  3449.                    valid   = date.getTime() <= max.getTime();
  3450.                     message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.max, maxOption);
  3451.                     break;
  3452.  
  3453.                 case (maxOption && minOption && valid):
  3454.                    valid   = date.getTime() <= max.getTime() && date.getTime() >= min.getTime();
  3455.                     message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.range, [minOption, maxOption]);
  3456.                     break;
  3457.  
  3458.                 default:
  3459.                     break;
  3460.             }
  3461.  
  3462.             return {
  3463.                 valid: valid,
  3464.                 message: message
  3465.             };
  3466.         },
  3467.  
  3468.         /**
  3469.          * Return a date object after parsing the date string
  3470.          *
  3471.          * @param {String} date   The date string to parse
  3472.          * @param {String} format The date format
  3473.          * The format can be:
  3474.          *   - date: Consist of DD, MM, YYYY parts which are separated by the separator option
  3475.          *   - date and time:
  3476.          *     The time can consist of h, m, s parts which are separated by :
  3477.          * @param {String} separator The separator used to separate the date, month, and year
  3478.          * @returns {Date}
  3479.          */
  3480.         _parseDate: function(date, format, separator) {
  3481.             var minutes     = 0, hours = 0, seconds = 0,
  3482.                 sections    = date.split(' '),
  3483.                 dateSection = sections[0],
  3484.                 timeSection = (sections.length > 1) ? sections[1] : null;
  3485.  
  3486.             dateSection = dateSection.split(separator);
  3487.             var year  = dateSection[$.inArray('YYYY', format)],
  3488.                 month = dateSection[$.inArray('MM', format)],
  3489.                 day   = dateSection[$.inArray('DD', format)];
  3490.             if (timeSection) {
  3491.                 timeSection = timeSection.split(':');
  3492.                 hours       = timeSection.length > 0 ? timeSection[0] : null;
  3493.                 minutes     = timeSection.length > 1 ? timeSection[1] : null;
  3494.                 seconds     = timeSection.length > 2 ? timeSection[2] : null;
  3495.             }
  3496.  
  3497.             return new Date(year, month -1, day, hours, minutes, seconds);
  3498.         },
  3499.  
  3500.         /**
  3501.          * Format date
  3502.          *
  3503.          * @param {Date} date The date object to format
  3504.          * @param {String} format The date format
  3505.          * The format can consist of the following tokens:
  3506.          *      d       Day of the month without leading zeros (1 through 31)
  3507.          *      dd      Day of the month with leading zeros (01 through 31)
  3508.          *      m       Month without leading zeros (1 through 12)
  3509.          *      mm      Month with leading zeros (01 through 12)
  3510.          *      yy      Last two digits of year (for example: 14)
  3511.          *      yyyy    Full four digits of year (for example: 2014)
  3512.          *      h       Hours without leading zeros (1 through 12)
  3513.          *      hh      Hours with leading zeros (01 through 12)
  3514.          *      H       Hours without leading zeros (0 through 23)
  3515.          *      HH      Hours with leading zeros (00 through 23)
  3516.          *      M       Minutes without leading zeros (0 through 59)
  3517.          *      MM      Minutes with leading zeros (00 through 59)
  3518.          *      s       Seconds without leading zeros (0 through 59)
  3519.          *      ss      Seconds with leading zeros (00 through 59)
  3520.          * @returns {String}
  3521.          */
  3522.         _formatDate: function(date, format) {
  3523.             format = format
  3524.                         .replace(/Y/g, 'y')
  3525.                         .replace(/M/g, 'm')
  3526.                         .replace(/D/g, 'd')
  3527.                         .replace(/:m/g, ':M')
  3528.                         .replace(/:mm/g, ':MM')
  3529.                         .replace(/:S/, ':s')
  3530.                         .replace(/:SS/, ':ss');
  3531.  
  3532.             var replacer = {
  3533.                 d: function(date) {
  3534.                     return date.getDate();
  3535.                 },
  3536.                 dd: function(date) {
  3537.                     var d = date.getDate();
  3538.                     return (d < 10) ? '0' + d : d;
  3539.                },
  3540.                m: function(date) {
  3541.                    return date.getMonth() + 1;
  3542.                },
  3543.                mm: function(date) {
  3544.                    var m = date.getMonth() + 1;
  3545.                    return m < 10 ? '0' + m : m;
  3546.                },
  3547.                yy: function(date) {
  3548.                    return ('' + date.getFullYear()).substr(2);
  3549.                },
  3550.                yyyy: function(date) {
  3551.                    return date.getFullYear();
  3552.                },
  3553.                h: function(date) {
  3554.                    return date.getHours() % 12 || 12;
  3555.                },
  3556.                hh: function(date) {
  3557.                    var h = date.getHours() % 12 || 12;
  3558.                    return h < 10 ? '0' + h : h;
  3559.                },
  3560.                H: function(date) {
  3561.                    return date.getHours();
  3562.                },
  3563.                HH: function(date) {
  3564.                    var H = date.getHours();
  3565.                    return H < 10 ? '0' + H : H;
  3566.                },
  3567.                M: function(date) {
  3568.                    return date.getMinutes();
  3569.                },
  3570.                MM: function(date) {
  3571.                    var M = date.getMinutes();
  3572.                    return M < 10 ? '0' + M : M;
  3573.                },
  3574.                s: function(date) {
  3575.                    return date.getSeconds();
  3576.                },
  3577.                ss: function(date) {
  3578.                    var s = date.getSeconds();
  3579.                    return s < 10 ? '0' + s : s;
  3580.                }
  3581.            };
  3582.  
  3583.            return format.replace(/d{1,4}|m{1,4}|yy(?:yy)?|([HhMs])\1?|"[^"]*"|'[^']*'/g, function(match) {
  3584.                return replacer[match] ? replacer[match](date) : match.slice(1, match.length - 1);
  3585.            });
  3586.        }
  3587.    };
  3588. }(jQuery));
  3589. ;(function($) {
  3590.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3591.        'en_US': {
  3592.            different: {
  3593.                'default': 'Please enter a different value'
  3594.            }
  3595.        }
  3596.    });
  3597.    FormValidation.Validator.different = {
  3598.        html5Attributes: {
  3599.            message: 'message',
  3600.            field: 'field'
  3601.        },
  3602.        /**
  3603.         * Bind the validator on the live change of the field to compare with current one
  3604.         *
  3605.         * @param {FormValidation.Base} validator The validator plugin instance
  3606.         * @param {jQuery} $field Field element
  3607.         * @param {Object} options Consists of the following key:
  3608.         * - field: The name of field that will be used to compare with current one
  3609.         */
  3610.        init: function(validator, $field, options) {
  3611.            var fields = options.field.split(',');
  3612.            for (var i = 0; i < fields.length; i++) {
  3613.                var compareWith = validator.getFieldElements(fields[i]);
  3614.                validator.onLiveChange(compareWith, 'live_different', function() {
  3615.                    var status = validator.getStatus($field, 'different');
  3616.                    if (status !== validator.STATUS_NOT_VALIDATED) {
  3617.                        validator.revalidateField($field);
  3618.                    }
  3619.                });
  3620.            }
  3621.        },
  3622.        /**
  3623.         * Unbind the validator on the live change of the field to compare with current one
  3624.         *
  3625.         * @param {FormValidation.Base} validator The validator plugin instance
  3626.         * @param {jQuery} $field Field element
  3627.         * @param {Object} options Consists of the following key:
  3628.         * - field: The name of field that will be used to compare with current one
  3629.         */
  3630.        destroy: function(validator, $field, options) {
  3631.            var fields = options.field.split(',');
  3632.            for (var i = 0; i < fields.length; i++) {
  3633.                var compareWith = validator.getFieldElements(fields[i]);
  3634.                validator.offLiveChange(compareWith, 'live_different');
  3635.            }
  3636.        },
  3637.        /**
  3638.         * Return true if the input value is different with given field's value
  3639.         *
  3640.         * @param {FormValidation.Base} validator The validator plugin instance
  3641.         * @param {jQuery} $field Field element
  3642.         * @param {Object} options Consists of the following key:
  3643.         * - field: The name of field that will be used to compare with current one
  3644.         * - message: The invalid message
  3645.         * @returns {Boolean}
  3646.         */
  3647.        validate: function(validator, $field, options) {
  3648.            var value = validator.getFieldValue($field, 'different');
  3649.            if (value === '') {
  3650.                return true;
  3651.            }
  3652.            var fields  = options.field.split(','),
  3653.                isValid = true;
  3654.            for (var i = 0; i < fields.length; i++) {
  3655.                var compareWith = validator.getFieldElements(fields[i]);
  3656.                if (compareWith == null || compareWith.length === 0) {
  3657.                    continue;
  3658.                }
  3659.                var compareValue = validator.getFieldValue(compareWith, 'different');
  3660.                if (value === compareValue) {
  3661.                    isValid = false;
  3662.                } else if (compareValue !== '') {
  3663.                    validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
  3664.                }
  3665.            }
  3666.            return isValid;
  3667.        }
  3668.    };
  3669. }(jQuery));
  3670. ;(function($) {
  3671.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3672.        'en_US': {
  3673.            digits: {
  3674.                'default': 'Please enter only digits'
  3675.            }
  3676.        }
  3677.    });
  3678.    FormValidation.Validator.digits = {
  3679.        /**
  3680.         * Return true if the input value contains digits only
  3681.         *
  3682.         * @param {FormValidation.Base} validator Validate plugin instance
  3683.         * @param {jQuery} $field Field element
  3684.         * @param {Object} [options]
  3685.         * @returns {Boolean}
  3686.         */
  3687.        validate: function(validator, $field, options) {
  3688.            var value = validator.getFieldValue($field, 'digits');
  3689.            if (value === '') {
  3690.                return true;
  3691.            }
  3692.            return /^\d+$/.test(value);
  3693.        }
  3694.    };
  3695. }(jQuery));
  3696. ;(function($) {
  3697.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3698.        'en_US': {
  3699.            ean: {
  3700.                'default': 'Please enter a valid EAN number'
  3701.            }
  3702.        }
  3703.    });
  3704.    FormValidation.Validator.ean = {
  3705.        /**
  3706.         * Validate EAN (International Article Number)
  3707.         * Examples:
  3708.         * - Valid: 73513537, 9780471117094, 4006381333931
  3709.         * - Invalid: 73513536
  3710.         *
  3711.         * @see http://en.wikipedia.org/wiki/European_Article_Number
  3712.         * @param {FormValidation.Base} validator The validator plugin instance
  3713.         * @param {jQuery} $field Field element
  3714.         * @param {Object} options Can consist of the following keys:
  3715.         * - message: The invalid message
  3716.         * @returns {Boolean}
  3717.         */
  3718.        validate: function(validator, $field, options) {
  3719.            var value = validator.getFieldValue($field, 'ean');
  3720.            if (value === '') {
  3721.                return true;
  3722.            }
  3723.            if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  3724.                return false;
  3725.            }
  3726.            var length = value.length,
  3727.                sum    = 0,
  3728.                weight = (length === 8) ? [3, 1] : [1, 3];
  3729.            for (var i = 0; i < length - 1; i++) {
  3730.                sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3731.            }
  3732.            sum = (10 - sum % 10) % 10;
  3733.            return (sum + '' === value.charAt(length - 1));
  3734.        }
  3735.    };
  3736. }(jQuery));
  3737. ;(function($) {
  3738.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3739.        'en_US': {
  3740.            ein: {
  3741.                'default': 'Please enter a valid EIN number'
  3742.            }
  3743.        }
  3744.    });
  3745.    FormValidation.Validator.ein = {
  3746.        // The first two digits are called campus
  3747.        // See http://en.wikipedia.org/wiki/Employer_Identification_Number
  3748.        // http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes
  3749.        CAMPUS: {
  3750.            ANDOVER: ['10', '12'],
  3751.            ATLANTA: ['60', '67'],
  3752.            AUSTIN: ['50', '53'],
  3753.            BROOKHAVEN: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
  3754.            CINCINNATI: ['30', '32', '35', '36', '37', '38', '61'],
  3755.            FRESNO: ['15', '24'],
  3756.            KANSAS_CITY: ['40', '44'],
  3757.            MEMPHIS: ['94', '95'],
  3758.            OGDEN: ['80', '90'],
  3759.            PHILADELPHIA: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
  3760.            INTERNET: ['20', '26', '27', '45', '46'],
  3761.            SMALL_BUSINESS_ADMINISTRATION: ['31']
  3762.        },
  3763.        /**
  3764.         * Validate EIN (Employer Identification Number) which is also known as
  3765.         * Federal Employer Identification Number (FEIN) or Federal Tax Identification Number
  3766.         *
  3767.         * @param {FormValidation.Base} validator The validator plugin instance
  3768.         * @param {jQuery} $field Field element
  3769.         * @param {Object} options Can consist of the following keys:
  3770.         * - message: The invalid message
  3771.         * @returns {Object|Boolean}
  3772.         */
  3773.        validate: function(validator, $field, options) {
  3774.            var value = validator.getFieldValue($field, 'ein');
  3775.            if (value === '') {
  3776.                return true;
  3777.            }
  3778.            if (!/^[0-9]{2}-?[0-9]{7}$/.test(value)) {
  3779.                return false;
  3780.            }
  3781.            // Check the first two digits
  3782.            var campus = value.substr(0, 2) + '';
  3783.            for (var key in this.CAMPUS) {
  3784.                if ($.inArray(campus, this.CAMPUS[key]) !== -1) {
  3785.                    return {
  3786.                        valid: true,
  3787.                        campus: key
  3788.                    };
  3789.                }
  3790.            }
  3791.            return false;
  3792.        }
  3793.    };
  3794. }(jQuery));
  3795. ;(function($) {
  3796.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3797.        'en_US': {
  3798.            emailAddress: {
  3799.                'default': 'Please enter a valid email address'
  3800.            }
  3801.        }
  3802.    });
  3803.    FormValidation.Validator.emailAddress = {
  3804.        html5Attributes: {
  3805.            message: 'message',
  3806.            multiple: 'multiple',
  3807.            separator: 'separator'
  3808.        },
  3809.        enableByHtml5: function($field) {
  3810.            return ('email' === $field.attr('type'));
  3811.        },
  3812.        /**
  3813.         * Return true if and only if the input value is a valid email address
  3814.         *
  3815.         * @param {FormValidation.Base} validator Validate plugin instance
  3816.         * @param {jQuery} $field Field element
  3817.         * @param {Object} [options]
  3818.         * - multiple: Allow multiple email addresses, separated by a comma or semicolon; default is false.
  3819.         * - separator: Regex for character or characters expected as separator between addresses; default is comma /[,;]/, i.e. comma or semicolon.
  3820.         * @returns {Boolean}
  3821.         */
  3822.        validate: function(validator, $field, options) {
  3823.            var value = validator.getFieldValue($field, 'emailAddress');
  3824.            if (value === '') {
  3825.                return true;
  3826.            }
  3827.            // Email address regular expression
  3828.            // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  3829.            var emailRegExp   = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
  3830.                 allowMultiple = options.multiple === true || options.multiple === 'true';
  3831.  
  3832.             if (allowMultiple) {
  3833.                 var separator = options.separator || /[,;]/,
  3834.                     addresses = this._splitEmailAddresses(value, separator);
  3835.  
  3836.                 for (var i = 0; i < addresses.length; i++) {
  3837.                    if (!emailRegExp.test(addresses[i])) {
  3838.                        return false;
  3839.                    }
  3840.                }
  3841.  
  3842.                return true;
  3843.            } else {
  3844.                return emailRegExp.test(value);
  3845.            }
  3846.        },
  3847.  
  3848.        _splitEmailAddresses: function(emailAddresses, separator) {
  3849.            var quotedFragments     = emailAddresses.split(/"/),
  3850.                quotedFragmentCount = quotedFragments.length,
  3851.                emailAddressArray   = [],
  3852.                nextEmailAddress    = '';
  3853.            for (var i = 0; i < quotedFragmentCount; i++) {
  3854.                if (i % 2 === 0) {
  3855.                    var splitEmailAddressFragments     = quotedFragments[i].split(separator),
  3856.                        splitEmailAddressFragmentCount = splitEmailAddressFragments.length;
  3857.                    if (splitEmailAddressFragmentCount === 1) {
  3858.                        nextEmailAddress += splitEmailAddressFragments[0];
  3859.                    } else {
  3860.                        emailAddressArray.push(nextEmailAddress + splitEmailAddressFragments[0]);
  3861.                        for (var j = 1; j < splitEmailAddressFragmentCount - 1; j++) {
  3862.                            emailAddressArray.push(splitEmailAddressFragments[j]);
  3863.                        }
  3864.                        nextEmailAddress = splitEmailAddressFragments[splitEmailAddressFragmentCount - 1];
  3865.                    }
  3866.                } else {
  3867.                    nextEmailAddress += '"' + quotedFragments[i];
  3868.                    if (i < quotedFragmentCount - 1) {
  3869.                        nextEmailAddress += '"';
  3870.                    }
  3871.                }
  3872.            }
  3873.            emailAddressArray.push(nextEmailAddress);
  3874.            return emailAddressArray;
  3875.        }
  3876.    };
  3877. }(jQuery));
  3878. ;(function($) {
  3879.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3880.        'en_US': {
  3881.            file: {
  3882.                'default': 'Please choose a valid file'
  3883.            }
  3884.        }
  3885.    });
  3886.    FormValidation.Validator.file = {
  3887.        html5Attributes: {
  3888.            extension: 'extension',
  3889.            maxfiles: 'maxFiles',
  3890.            minfiles: 'minFiles',
  3891.            maxsize: 'maxSize',
  3892.            minsize: 'minSize',
  3893.            maxtotalsize: 'maxTotalSize',
  3894.            mintotalsize: 'minTotalSize',
  3895.            message: 'message',
  3896.            type: 'type'
  3897.        },
  3898.        /**
  3899.         * Validate upload file. Use HTML 5 API if the browser supports
  3900.         *
  3901.         * @param {FormValidation.Base} validator The validator plugin instance
  3902.         * @param {jQuery} $field Field element
  3903.         * @param {Object} options Can consist of the following keys:
  3904.         * - extension: The allowed extensions, separated by a comma
  3905.         * - maxFiles: The maximum number of files
  3906.         * - minFiles: The minimum number of files
  3907.         * - maxSize: The maximum size in bytes
  3908.         * - minSize: The minimum size in bytes
  3909.         * - maxTotalSize: The maximum size in bytes for all files
  3910.         * - minTotalSize: The minimum size in bytes for all files
  3911.         * - message: The invalid message
  3912.         * - type: The allowed MIME type, separated by a comma
  3913.         * @returns {Boolean}
  3914.         */
  3915.        validate: function(validator, $field, options) {
  3916.            var value = validator.getFieldValue($field, 'file');
  3917.            if (value === '') {
  3918.                return true;
  3919.            }
  3920.            var ext,
  3921.                extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  3922.                types      = options.type      ? options.type.toLowerCase().split(',')      : null,
  3923.                html5      = (window.File && window.FileList && window.FileReader);
  3924.            if (html5) {
  3925.                // Get FileList instance
  3926.                var files     = $field.get(0).files,
  3927.                    total     = files.length,
  3928.                    totalSize = 0;
  3929.                if ((options.maxFiles && total > parseInt(options.maxFiles, 10))        // Check the maxFiles
  3930.                     || (options.minFiles && total < parseInt(options.minFiles, 10)))    // Check the minFiles
  3931.                {
  3932.                    return false;
  3933.                 }
  3934.  
  3935.                 for (var i = 0; i < total; i++) {
  3936.                    totalSize += files[i].size;
  3937.                    ext        = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  3938.  
  3939.                    if ((options.minSize && files[i].size < parseInt(options.minSize, 10))                      // Check the minSize
  3940.                        || (options.maxSize && files[i].size > parseInt(options.maxSize, 10))                   // Check the maxSize
  3941.                         || (extensions && $.inArray(ext.toLowerCase(), extensions) === -1)                      // Check file extension
  3942.                        || (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1))    // Check file type
  3943.                    {
  3944.                        return false;
  3945.                     }
  3946.                 }
  3947.  
  3948.                 if ((options.maxTotalSize && totalSize > parseInt(options.maxTotalSize, 10))        // Check the maxTotalSize
  3949.                    || (options.minTotalSize && totalSize < parseInt(options.minTotalSize, 10)))    // Check the minTotalSize
  3950.                {
  3951.                    return false;
  3952.                 }
  3953.             } else {
  3954.                 // Check file extension
  3955.                 ext = value.substr(value.lastIndexOf('.') + 1);
  3956.                 if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  3957.                    return false;
  3958.                 }
  3959.             }
  3960.  
  3961.             return true;
  3962.         }
  3963.     };
  3964. }(jQuery));
  3965. ;(function($) {
  3966.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3967.         'en_US': {
  3968.             greaterThan: {
  3969.                 'default': 'Please enter a value greater than or equal to %s',
  3970.                 notInclusive: 'Please enter a value greater than %s'
  3971.             }
  3972.         }
  3973.     });
  3974.  
  3975.     FormValidation.Validator.greaterThan = {
  3976.         html5Attributes: {
  3977.             message: 'message',
  3978.             value: 'value',
  3979.             inclusive: 'inclusive'
  3980.         },
  3981.  
  3982.         enableByHtml5: function($field) {
  3983.             var type = $field.attr('type'),
  3984.                 min  = $field.attr('min');
  3985.             if (min && type !== 'date') {
  3986.                return {
  3987.                    value: min
  3988.                };
  3989.             }
  3990.  
  3991.             return false;
  3992.         },
  3993.  
  3994.         /**
  3995.          * Return true if the input value is greater than or equals to given number
  3996.          *
  3997.          * @param {FormValidation.Base} validator Validate plugin instance
  3998.          * @param {jQuery} $field Field element
  3999.          * @param {Object} options Can consist of the following keys:
  4000.          * - value: Define the number to compare with. It can be
  4001.          *      - A number
  4002.          *      - Name of field which its value defines the number
  4003.          *      - Name of callback function that returns the number
  4004.          *      - A callback function that returns the number
  4005.          *
  4006.          * - inclusive [optional]: Can be true or false. Default is true
  4007.          * - message: The invalid message
  4008.          * @returns {Boolean|Object}
  4009.          */
  4010.         validate: function(validator, $field, options) {
  4011.             var value = validator.getFieldValue($field, 'greaterThan');
  4012.             if (value === '') {
  4013.                 return true;
  4014.             }
  4015.            
  4016.             value = this._format(value);
  4017.             if (!$.isNumeric(value)) {
  4018.                 return false;
  4019.             }
  4020.  
  4021.             var locale         = validator.getLocale(),
  4022.                 compareTo      = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
  4023.                 compareToValue = this._format(compareTo);
  4024.  
  4025.             value = parseFloat(value);
  4026.             return (options.inclusive === true || options.inclusive === undefined)
  4027.                     ? {
  4028.                         valid: value >= compareToValue,
  4029.                         message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].greaterThan['default'], compareTo)
  4030.                     }
  4031.                     : {
  4032.                         valid: value > compareToValue,
  4033.                         message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].greaterThan.notInclusive, compareTo)
  4034.                     };
  4035.         },
  4036.  
  4037.         _format: function(value) {
  4038.             return (value + '').replace(',', '.');
  4039.         }
  4040.     };
  4041. }(jQuery));
  4042. ;(function($) {
  4043.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  4044.         'en_US': {
  4045.             grid: {
  4046.                 'default': 'Please enter a valid GRId number'
  4047.             }
  4048.         }
  4049.     });
  4050.  
  4051.     FormValidation.Validator.grid = {
  4052.         /**
  4053.          * Validate GRId (Global Release Identifier)
  4054.          * Examples:
  4055.          * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  4056.          * - Invalid: A1-2425G-ABC1234002-Q
  4057.          *
  4058.          * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  4059.          * @param {FormValidation.Base} validator The validator plugin instance
  4060.          * @param {jQuery} $field Field element
  4061.          * @param {Object} options Can consist of the following keys:
  4062.          * - message: The invalid message
  4063.          * @returns {Boolean}
  4064.          */
  4065.         validate: function(validator, $field, options) {
  4066.             var value = validator.getFieldValue($field, 'grid');
  4067.             if (value === '') {
  4068.                 return true;
  4069.             }
  4070.  
  4071.             value = value.toUpperCase();
  4072.             if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  4073.                 return false;
  4074.             }
  4075.             value = value.replace(/\s/g, '').replace(/-/g, '');
  4076.             if ('GRID:' === value.substr(0, 5)) {
  4077.                 value = value.substr(5);
  4078.             }
  4079.             return FormValidation.Helper.mod37And36(value);
  4080.         }
  4081.     };
  4082. }(jQuery));
  4083. ;(function($) {
  4084.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  4085.         'en_US': {
  4086.             hex: {
  4087.                 'default': 'Please enter a valid hexadecimal number'
  4088.             }
  4089.         }
  4090.     });
  4091.  
  4092.     FormValidation.Validator.hex = {
  4093.         /**
  4094.          * Return true if and only if the input value is a valid hexadecimal number
  4095.          *
  4096.          * @param {FormValidation.Base} validator The validator plugin instance
  4097.          * @param {jQuery} $field Field element
  4098.          * @param {Object} options Consist of key:
  4099.          * - message: The invalid message
  4100.          * @returns {Boolean}
  4101.          */
  4102.         validate: function(validator, $field, options) {
  4103.             var value = validator.getFieldValue($field, 'hex');
  4104.             if (value === '') {
  4105.                 return true;
  4106.             }
  4107.  
  4108.             return /^[0-9a-fA-F]+$/.test(value);
  4109.         }
  4110.     };
  4111. }(jQuery));
  4112. ;(function($) {
  4113.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  4114.         'en_US': {
  4115.             iban: {
  4116.                 'default': 'Please enter a valid IBAN number',
  4117.                 country: 'Please enter a valid IBAN number in %s',
  4118.                 countries: {
  4119.                     AD: 'Andorra',
  4120.                     AE: 'United Arab Emirates',
  4121.                     AL: 'Albania',
  4122.                     AO: 'Angola',
  4123.                     AT: 'Austria',
  4124.                     AZ: 'Azerbaijan',
  4125.                     BA: 'Bosnia and Herzegovina',
  4126.                     BE: 'Belgium',
  4127.                     BF: 'Burkina Faso',
  4128.                     BG: 'Bulgaria',
  4129.                     BH: 'Bahrain',
  4130.                     BI: 'Burundi',
  4131.                     BJ: 'Benin',
  4132.                     BR: 'Brazil',
  4133.                     CH: 'Switzerland',
  4134.                     CI: 'Ivory Coast',
  4135.                     CM: 'Cameroon',
  4136.                     CR: 'Costa Rica',
  4137.                     CV: 'Cape Verde',
  4138.                     CY: 'Cyprus',
  4139.                     CZ: 'Czech Republic',
  4140.                     DE: 'Germany',
  4141.                     DK: 'Denmark',
  4142.                     DO: 'Dominican Republic',
  4143.                     DZ: 'Algeria',
  4144.                     EE: 'Estonia',
  4145.                     ES: 'Spain',
  4146.                     FI: 'Finland',
  4147.                     FO: 'Faroe Islands',
  4148.                     FR: 'France',
  4149.                     GB: 'United Kingdom',
  4150.                     GE: 'Georgia',
  4151.                     GI: 'Gibraltar',
  4152.                     GL: 'Greenland',
  4153.                     GR: 'Greece',
  4154.                     GT: 'Guatemala',
  4155.                     HR: 'Croatia',
  4156.                     HU: 'Hungary',
  4157.                     IE: 'Ireland',
  4158.                     IL: 'Israel',
  4159.                     IR: 'Iran',
  4160.                     IS: 'Iceland',
  4161.                     IT: 'Italy',
  4162.                     JO: 'Jordan',
  4163.                     KW: 'Kuwait',
  4164.                     KZ: 'Kazakhstan',
  4165.                     LB: 'Lebanon',
  4166.                     LI: 'Liechtenstein',
  4167.                     LT: 'Lithuania',
  4168.                     LU: 'Luxembourg',
  4169.                     LV: 'Latvia',
  4170.                     MC: 'Monaco',
  4171.                     MD: 'Moldova',
  4172.                     ME: 'Montenegro',
  4173.                     MG: 'Madagascar',
  4174.                     MK: 'Macedonia',
  4175.                     ML: 'Mali',
  4176.                     MR: 'Mauritania',
  4177.                     MT: 'Malta',
  4178.                     MU: 'Mauritius',
  4179.                     MZ: 'Mozambique',
  4180.                     NL: 'Netherlands',
  4181.                     NO: 'Norway',
  4182.                     PK: 'Pakistan',
  4183.                     PL: 'Poland',
  4184.                     PS: 'Palestine',
  4185.                     PT: 'Portugal',
  4186.                     QA: 'Qatar',
  4187.                     RO: 'Romania',
  4188.                     RS: 'Serbia',
  4189.                     SA: 'Saudi Arabia',
  4190.                     SE: 'Sweden',
  4191.                     SI: 'Slovenia',
  4192.                     SK: 'Slovakia',
  4193.                     SM: 'San Marino',
  4194.                     SN: 'Senegal',
  4195.                     TN: 'Tunisia',
  4196.                     TR: 'Turkey',
  4197.                     VG: 'Virgin Islands, British'
  4198.                 }
  4199.             }
  4200.         }
  4201.     });
  4202.  
  4203.     FormValidation.Validator.iban = {
  4204.         html5Attributes: {
  4205.             message: 'message',
  4206.             country: 'country'
  4207.         },
  4208.  
  4209.         // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  4210.         // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  4211.         REGEX: {
  4212.             AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}',                       // Andorra
  4213.             AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}',                                  // United Arab Emirates
  4214.             AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}',                               // Albania
  4215.             AO: 'AO[0-9]{2}[0-9]{21}',                                          // Angola
  4216.             AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}',                                  // Austria
  4217.             AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}',                               // Azerbaijan
  4218.             BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}',                   // Bosnia and Herzegovina
  4219.             BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}',                           // Belgium
  4220.             BF: 'BF[0-9]{2}[0-9]{23}',                                          // Burkina Faso
  4221.             BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}',                // Bulgaria
  4222.             BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}',                               // Bahrain
  4223.             BI: 'BI[0-9]{2}[0-9]{12}',                                          // Burundi
  4224.             BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Benin
  4225.             BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]',             // Brazil
  4226.             CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}',                               // Switzerland
  4227.             CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Ivory Coast
  4228.             CM: 'CM[0-9]{2}[0-9]{23}',                                          // Cameroon
  4229.             CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}',                                  // Costa Rica
  4230.             CV: 'CV[0-9]{2}[0-9]{21}',                                          // Cape Verde
  4231.             CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}',                       // Cyprus
  4232.             CZ: 'CZ[0-9]{2}[0-9]{20}',                                          // Czech Republic
  4233.             DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}',                                  // Germany
  4234.             DK: 'DK[0-9]{2}[0-9]{14}',                                          // Denmark
  4235.             DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}',                               // Dominican Republic
  4236.             DZ: 'DZ[0-9]{2}[0-9]{20}',                                          // Algeria
  4237.             EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}',                  // Estonia
  4238.             ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}',          // Spain
  4239.             FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}',                           // Finland
  4240.             FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}',                           // Faroe Islands
  4241.             FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}',               // France
  4242.             GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}',                           // United Kingdom
  4243.             GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}',                                  // Georgia
  4244.             GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}',                               // Gibraltar
  4245.             GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}',                           // Greenland
  4246.             GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}',                       // Greece
  4247.             GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}',                            // Guatemala
  4248.             HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}',                                  // Croatia
  4249.             HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}',          // Hungary
  4250.             IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}',                           // Ireland
  4251.             IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}',                          // Israel
  4252.             IR: 'IR[0-9]{2}[0-9]{22}',                                          // Iran
  4253.             IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}',                  // Iceland
  4254.             IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}',               // Italy
  4255.             JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}',                 // Jordan
  4256.             KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}',                                  // Kuwait
  4257.             KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}',                               // Kazakhstan
  4258.             LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}',                               // Lebanon
  4259.             LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}',                               // Liechtenstein
  4260.             LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}',                                  // Lithuania
  4261.             LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}',                               // Luxembourg
  4262.             LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}',                               // Latvia
  4263.             MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}',               // Monaco
  4264.             MD: 'MD[0-9]{2}[A-Z0-9]{20}',                                       // Moldova
  4265.             ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}',                          // Montenegro
  4266.             MG: 'MG[0-9]{2}[0-9]{23}',                                          // Madagascar
  4267.             MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}',                       // Macedonia
  4268.             ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Mali
  4269.             MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}',                        // Mauritania
  4270.             MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}',                       // Malta
  4271.             MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}',  // Mauritius
  4272.             MZ: 'MZ[0-9]{2}[0-9]{21}',                                          // Mozambique
  4273.             NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}',                                  // Netherlands
  4274.             NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}',                           // Norway
  4275.             PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}',                               // Pakistan
  4276.             PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}',                                  // Poland
  4277.             PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}',                               // Palestinian
  4278.             PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}',                  // Portugal
  4279.             QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}',                               // Qatar
  4280.             RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}',                               // Romania
  4281.             RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}',                          // Serbia
  4282.             SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}',                               // Saudi Arabia
  4283.             SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}',                          // Sweden
  4284.             SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}',                           // Slovenia
  4285.             SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}',                          // Slovakia
  4286.             SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}',               // San Marino
  4287.             SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Senegal
  4288.             TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}',                        // Tunisia
  4289.             TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}',                    // Turkey
  4290.             VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}'                                   // Virgin Islands, British
  4291.         },
  4292.  
  4293.         /**
  4294.          * Validate an International Bank Account Number (IBAN)
  4295.          * To test it, take the sample IBAN from
  4296.          * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  4297.          *
  4298.          * @param {FormValidation.Base} validator The validator plugin instance
  4299.          * @param {jQuery} $field Field element
  4300.          * @param {Object} options Can consist of the following keys:
  4301.          * - message: The invalid message
  4302.          * - country: The ISO 3166-1 country code. It can be
  4303.          *      - A country code
  4304.          *      - Name of field which its value defines the country code
  4305.          *      - Name of callback function that returns the country code
  4306.          *      - A callback function that returns the country code
  4307.          * @returns {Boolean|Object}
  4308.          */
  4309.         validate: function(validator, $field, options) {
  4310.             var value = validator.getFieldValue($field, 'iban');
  4311.             if (value === '') {
  4312.                 return true;
  4313.             }
  4314.  
  4315.             value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  4316.             var country = options.country;
  4317.             if (!country) {
  4318.                 country = value.substr(0, 2);
  4319.             } else if (typeof country !== 'string' || !this.REGEX[country]) {
  4320.                 // Determine the country code
  4321.                 country = validator.getDynamicOption($field, country);
  4322.             }
  4323.  
  4324.             var locale = validator.getLocale();
  4325.             if (!this.REGEX[country]) {
  4326.                 return true;
  4327.             }
  4328.  
  4329.             if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  4330.                 return {
  4331.                     valid: false,
  4332.                     message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].iban.country, FormValidation.I18n[locale].iban.countries[country])
  4333.                 };
  4334.             }
  4335.  
  4336.             value = value.substr(4) + value.substr(0, 4);
  4337.             value = $.map(value.split(''), function(n) {
  4338.                 var code = n.charCodeAt(0);
  4339.                 return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  4340.                        // Replace A, B, C, ..., Z with 10, 11, ..., 35
  4341.                        ? (code - 'A'.charCodeAt(0) + 10)
  4342.                        : n;
  4343.             });
  4344.             value = value.join('');
  4345.  
  4346.             var temp   = parseInt(value.substr(0, 1), 10),
  4347.                 length = value.length;
  4348.             for (var i = 1; i < length; ++i) {
  4349.                temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  4350.            }
  4351.  
  4352.            return {
  4353.                valid: (temp === 1),
  4354.                message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].iban.country, FormValidation.I18n[locale].iban.countries[country])
  4355.            };
  4356.        }
  4357.    };
  4358. }(jQuery));
  4359. ;(function($) {
  4360.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  4361.        'en_US': {
  4362.            id: {
  4363.                'default': 'Please enter a valid identification number',
  4364.                country: 'Please enter a valid identification number in %s',
  4365.                countries: {
  4366.                    BA: 'Bosnia and Herzegovina',
  4367.                    BG: 'Bulgaria',
  4368.                    BR: 'Brazil',
  4369.                    CH: 'Switzerland',
  4370.                    CL: 'Chile',
  4371.                    CN: 'China',
  4372.                    CZ: 'Czech Republic',
  4373.                    DK: 'Denmark',
  4374.                    EE: 'Estonia',
  4375.                    ES: 'Spain',
  4376.                    FI: 'Finland',
  4377.                    HR: 'Croatia',
  4378.                    IE: 'Ireland',
  4379.                    IS: 'Iceland',
  4380.                    LT: 'Lithuania',
  4381.                    LV: 'Latvia',
  4382.                    ME: 'Montenegro',
  4383.                    MK: 'Macedonia',
  4384.                    NL: 'Netherlands',
  4385.                    PL: 'Poland',
  4386.                    RO: 'Romania',
  4387.                    RS: 'Serbia',
  4388.                    SE: 'Sweden',
  4389.                    SI: 'Slovenia',
  4390.                    SK: 'Slovakia',
  4391.                    SM: 'San Marino',
  4392.                    TH: 'Thailand',
  4393.                    ZA: 'South Africa'
  4394.                }
  4395.            }
  4396.        }
  4397.    });
  4398.  
  4399.    FormValidation.Validator.id = {
  4400.        html5Attributes: {
  4401.            message: 'message',
  4402.            country: 'country'
  4403.        },
  4404.  
  4405.        // Supported country codes
  4406.        COUNTRY_CODES: [
  4407.            'BA', 'BG', 'BR', 'CH', 'CL', 'CN', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
  4408.            'PL', 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TH', 'ZA'
  4409.        ],
  4410.  
  4411.        /**
  4412.         * Validate identification number in different countries
  4413.         *
  4414.         * @see http://en.wikipedia.org/wiki/National_identification_number
  4415.         * @param {FormValidation.Base} validator The validator plugin instance
  4416.         * @param {jQuery} $field Field element
  4417.         * @param {Object} options Consist of key:
  4418.         * - message: The invalid message
  4419.         * - country: The ISO 3166-1 country code. It can be
  4420.         *      - One of country code defined in COUNTRY_CODES
  4421.         *      - Name of field which its value defines the country code
  4422.         *      - Name of callback function that returns the country code
  4423.         *      - A callback function that returns the country code
  4424.         * @returns {Boolean|Object}
  4425.         */
  4426.        validate: function(validator, $field, options) {
  4427.            var value = validator.getFieldValue($field, 'id');
  4428.            if (value === '') {
  4429.                return true;
  4430.            }
  4431.  
  4432.            var locale  = validator.getLocale(),
  4433.                country = options.country;
  4434.            if (!country) {
  4435.                country = value.substr(0, 2);
  4436.            } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  4437.                // Determine the country code
  4438.                country = validator.getDynamicOption($field, country);
  4439.            }
  4440.  
  4441.            if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  4442.                return true;
  4443.            }
  4444.  
  4445.            var method  = ['_', country.toLowerCase()].join('');
  4446.            return this[method](value)
  4447.                    ? true
  4448.                    : {
  4449.                        valid: false,
  4450.                        message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].id.country, FormValidation.I18n[locale].id.countries[country.toUpperCase()])
  4451.                    };
  4452.        },
  4453.  
  4454.        /**
  4455.         * Validate Unique Master Citizen Number which uses in
  4456.         * - Bosnia and Herzegovina (country code: BA)
  4457.         * - Macedonia (MK)
  4458.         * - Montenegro (ME)
  4459.         * - Serbia (RS)
  4460.         * - Slovenia (SI)
  4461.         *
  4462.         * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  4463.         * @param {String} value The ID
  4464.         * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  4465.         * @returns {Boolean}
  4466.         */
  4467.        _validateJMBG: function(value, countryCode) {
  4468.            if (!/^\d{13}$/.test(value)) {
  4469.                return false;
  4470.            }
  4471.            var day   = parseInt(value.substr(0, 2), 10),
  4472.                month = parseInt(value.substr(2, 2), 10),
  4473.                year  = parseInt(value.substr(4, 3), 10),
  4474.                rr    = parseInt(value.substr(7, 2), 10),
  4475.                k     = parseInt(value.substr(12, 1), 10);
  4476.  
  4477.            // Validate date of birth
  4478.            // FIXME: Validate the year of birth
  4479.            if (day > 31 || month > 12) {
  4480.                 return false;
  4481.             }
  4482.  
  4483.             // Validate checksum
  4484.             var sum = 0;
  4485.             for (var i = 0; i < 6; i++) {
  4486.                sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  4487.            }
  4488.            sum = 11 - sum % 11;
  4489.            if (sum === 10 || sum === 11) {
  4490.                sum = 0;
  4491.            }
  4492.            if (sum !== k) {
  4493.                return false;
  4494.            }
  4495.  
  4496.            // Validate political region
  4497.            // rr is the political region of birth, which can be in ranges:
  4498.            // 10-19: Bosnia and Herzegovina
  4499.            // 20-29: Montenegro
  4500.            // 30-39: Croatia (not used anymore)
  4501.            // 41-49: Macedonia
  4502.            // 50-59: Slovenia (only 50 is used)
  4503.            // 70-79: Central Serbia
  4504.            // 80-89: Serbian province of Vojvodina
  4505.            // 90-99: Kosovo
  4506.            switch (countryCode.toUpperCase()) {
  4507.                case 'BA':
  4508.                    return (10 <= rr && rr <= 19);
  4509.                case 'MK':
  4510.                    return (41 <= rr && rr <= 49);
  4511.                case 'ME':
  4512.                    return (20 <= rr && rr <= 29);
  4513.                case 'RS':
  4514.                    return (70 <= rr && rr <= 99);
  4515.                case 'SI':
  4516.                    return (50 <= rr && rr <= 59);
  4517.                default:
  4518.                    return true;
  4519.            }
  4520.        },
  4521.  
  4522.        _ba: function(value) {
  4523.            return this._validateJMBG(value, 'BA');
  4524.        },
  4525.        _mk: function(value) {
  4526.            return this._validateJMBG(value, 'MK');
  4527.        },
  4528.        _me: function(value) {
  4529.            return this._validateJMBG(value, 'ME');
  4530.        },
  4531.        _rs: function(value) {
  4532.            return this._validateJMBG(value, 'RS');
  4533.        },
  4534.  
  4535.        /**
  4536.         * Examples: 0101006500006
  4537.         */
  4538.        _si: function(value) {
  4539.            return this._validateJMBG(value, 'SI');
  4540.        },
  4541.  
  4542.        /**
  4543.         * Validate Bulgarian national identification number (EGN)
  4544.         * Examples:
  4545.         * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  4546.         * - Invalid: 8019010008
  4547.         *
  4548.         * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  4549.         * @param {String} value The ID
  4550.         * @returns {Boolean}
  4551.         */
  4552.        _bg: function(value) {
  4553.            if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  4554.                return false;
  4555.            }
  4556.            value = value.replace(/\s/g, '');
  4557.            // Check the birth date
  4558.            var year  = parseInt(value.substr(0, 2), 10) + 1900,
  4559.                month = parseInt(value.substr(2, 2), 10),
  4560.                day   = parseInt(value.substr(4, 2), 10);
  4561.            if (month > 40) {
  4562.                 year += 100;
  4563.                 month -= 40;
  4564.             } else if (month > 20) {
  4565.                 year -= 100;
  4566.                 month -= 20;
  4567.             }
  4568.  
  4569.             if (!FormValidation.Helper.date(year, month, day)) {
  4570.                 return false;
  4571.             }
  4572.  
  4573.             var sum    = 0,
  4574.                 weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  4575.             for (var i = 0; i < 9; i++) {
  4576.                sum += parseInt(value.charAt(i), 10) * weight[i];
  4577.            }
  4578.            sum = (sum % 11) % 10;
  4579.            return (sum + '' === value.substr(9, 1));
  4580.        },
  4581.  
  4582.        /**
  4583.         * Validate Brazilian national identification number (CPF)
  4584.         * Examples:
  4585.         * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  4586.         * - Invalid: 231.002.999-00
  4587.         *
  4588.         * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  4589.         * @param {String} value The ID
  4590.         * @returns {Boolean}
  4591.         */
  4592.        _br: function(value) {
  4593.            value = value.replace(/\D/g, '');
  4594.  
  4595.            if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  4596.                return false;
  4597.            }
  4598.  
  4599.            var d1 = 0;
  4600.            for (var i = 0; i < 9; i++) {
  4601.                d1 += (10 - i) * parseInt(value.charAt(i), 10);
  4602.            }
  4603.            d1 = 11 - d1 % 11;
  4604.            if (d1 === 10 || d1 === 11) {
  4605.                d1 = 0;
  4606.            }
  4607.            if (d1 + '' !== value.charAt(9)) {
  4608.                return false;
  4609.            }
  4610.  
  4611.            var d2 = 0;
  4612.            for (i = 0; i < 10; i++) {
  4613.                d2 += (11 - i) * parseInt(value.charAt(i), 10);
  4614.            }
  4615.            d2 = 11 - d2 % 11;
  4616.            if (d2 === 10 || d2 === 11) {
  4617.                d2 = 0;
  4618.            }
  4619.  
  4620.            return (d2 + '' === value.charAt(10));
  4621.        },
  4622.  
  4623.        /**
  4624.         * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  4625.         * Examples:
  4626.         * - Valid: 756.1234.5678.95, 7561234567895
  4627.         *
  4628.         * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  4629.         * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  4630.         * @param {String} value The ID
  4631.         * @returns {Boolean}
  4632.         */
  4633.        _ch: function(value) {
  4634.            if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  4635.                return false;
  4636.            }
  4637.            value = value.replace(/\D/g, '').substr(3);
  4638.            var length = value.length,
  4639.                sum    = 0,
  4640.                weight = (length === 8) ? [3, 1] : [1, 3];
  4641.            for (var i = 0; i < length - 1; i++) {
  4642.                sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  4643.            }
  4644.            sum = 10 - sum % 10;
  4645.            return (sum + '' === value.charAt(length - 1));
  4646.        },
  4647.  
  4648.        /**
  4649.         * Validate Chilean national identification number (RUN/RUT)
  4650.         * Examples:
  4651.         * - Valid: 76086428-5, 22060449-7, 12531909-2
  4652.         *
  4653.         * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  4654.         * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  4655.         * @param {String} value The ID
  4656.         * @returns {Boolean}
  4657.         */
  4658.        _cl: function(value) {
  4659.            if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
  4660.                return false;
  4661.            }
  4662.            value = value.replace(/\-/g, '');
  4663.            while (value.length < 9) {
  4664.                value = '0' + value;
  4665.            }
  4666.            var sum    = 0,
  4667.                weight = [3, 2, 7, 6, 5, 4, 3, 2];
  4668.            for (var i = 0; i < 8; i++) {
  4669.                sum += parseInt(value.charAt(i), 10) * weight[i];
  4670.            }
  4671.            sum = 11 - sum % 11;
  4672.            if (sum === 11) {
  4673.                sum = 0;
  4674.            } else if (sum === 10) {
  4675.                sum = 'K';
  4676.            }
  4677.            return sum + '' === value.charAt(8).toUpperCase();
  4678.        },
  4679.  
  4680.        /**
  4681.         * Validate Chinese citizen identification number
  4682.         *
  4683.         * Rules:
  4684.         * - For current 18-digit system (since 1st Oct 1999, defined by GB11643—1999 national standard):
  4685.         *     - Digit 0-5: Must be a valid administrative division code of China PR.
  4686.         *     - Digit 6-13: Must be a valid YYYYMMDD date of birth. A future date is tolerated.
  4687.         *     - Digit 14-16: Order code, any integer.
  4688.         *     - Digit 17: An ISO 7064:1983, MOD 11-2 checksum.
  4689.         *       Both upper/lower case of X are tolerated.
  4690.         * - For deprecated 15-digit system:
  4691.         *     - Digit 0-5: Must be a valid administrative division code of China PR.
  4692.         *     - Digit 6-11: Must be a valid YYMMDD date of birth, indicating the year of 19XX.
  4693.         *     - Digit 12-14: Order code, any integer.
  4694.         * Lists of valid administrative division codes of China PR can be seen here:
  4695.         * <http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/>
  4696.          * Published and maintained by National Bureau of Statistics of China PR.
  4697.          * NOTE: Current and deprecated codes MUST BOTH be considered valid.
  4698.          * Many Chinese citizens born in once existed administrative divisions!
  4699.          *
  4700.          * @see http://en.wikipedia.org/wiki/Resident_Identity_Card#Identity_card_number
  4701.          * @param {String} value The ID
  4702.          * @returns {Boolean}
  4703.          */
  4704.         _cn: function(value) {
  4705.             // Basic format check (18 or 15 digits, considering X in checksum)
  4706.             value = value.trim();
  4707.             if (!/^\d{15}$/.test(value) && !/^\d{17}[\dXx]{1}$/.test(value)) {
  4708.                return false;
  4709.             }
  4710.            
  4711.             // Check China PR Administrative division code
  4712.             var adminDivisionCodes = {
  4713.                 11: {
  4714.                     0: [0],
  4715.                     1: [[0, 9], [11, 17]],
  4716.                     2: [0, 28, 29]
  4717.                 },
  4718.                 12: {
  4719.                     0: [0],
  4720.                     1: [[0, 16]],
  4721.                     2: [0, 21, 23, 25]
  4722.                 },
  4723.                 13: {
  4724.                     0: [0],
  4725.                     1: [[0, 5], 7, 8, 21, [23, 33], [81, 85]],
  4726.                     2: [[0, 5], [7, 9], [23, 25], 27, 29, 30, 81, 83],
  4727.                     3: [[0, 4], [21, 24]],
  4728.                     4: [[0, 4], 6, 21, [23, 35], 81],
  4729.                     5: [[0, 3], [21, 35], 81, 82],
  4730.                     6: [[0, 4], [21, 38], [81, 84]],
  4731.                     7: [[0, 3], 5, 6, [21, 33]],
  4732.                     8: [[0, 4], [21, 28]],
  4733.                     9: [[0, 3], [21, 30], [81, 84]],
  4734.                     10: [[0, 3], [22, 26], 28, 81, 82],
  4735.                     11: [[0, 2], [21, 28], 81, 82]
  4736.                 },
  4737.                 14: {
  4738.                     0: [0],
  4739.                     1: [0, 1, [5, 10], [21, 23], 81],
  4740.                     2: [[0, 3], 11, 12, [21, 27]],
  4741.                     3: [[0, 3], 11, 21, 22],
  4742.                     4: [[0, 2], 11, 21, [23, 31], 81],
  4743.                     5: [[0, 2], 21, 22, 24, 25, 81],
  4744.                     6: [[0, 3], [21, 24]],
  4745.                     7: [[0, 2], [21, 29], 81],
  4746.                     8: [[0, 2], [21, 30], 81, 82],
  4747.                     9: [[0, 2], [21, 32], 81],
  4748.                     10: [[0, 2], [21, 34], 81, 82],
  4749.                     11: [[0, 2], [21, 30], 81, 82],
  4750.                     23: [[0, 3], 22, 23, [25, 30], 32, 33]
  4751.                 },
  4752.                 15: {
  4753.                     0: [0],
  4754.                     1: [[0, 5], [21, 25]],
  4755.                     2: [[0, 7], [21, 23]],
  4756.                     3: [[0, 4]],
  4757.                     4: [[0, 4], [21, 26], [28, 30]],
  4758.                     5: [[0, 2], [21, 26], 81],
  4759.                     6: [[0, 2], [21, 27]],
  4760.                     7: [[0, 3], [21, 27], [81, 85]],
  4761.                     8: [[0, 2], [21, 26]],
  4762.                     9: [[0, 2], [21, 29], 81],
  4763.                     22: [[0, 2], [21, 24]],
  4764.                     25: [[0, 2], [22, 31]],
  4765.                     26: [[0, 2], [24, 27], [29, 32], 34],
  4766.                     28: [0, 1, [22, 27]],
  4767.                     29: [0, [21, 23]]
  4768.                 },
  4769.                 21: {
  4770.                     0: [0],
  4771.                     1: [[0, 6], [11, 14], [22, 24], 81],
  4772.                     2: [[0, 4], [11, 13], 24, [81, 83]],
  4773.                     3: [[0, 4], 11, 21, 23, 81],
  4774.                     4: [[0, 4], 11, [21, 23]],
  4775.                     5: [[0, 5], 21, 22],
  4776.                     6: [[0, 4], 24, 81, 82],
  4777.                     7: [[0, 3], 11, 26, 27, 81, 82],
  4778.                     8: [[0, 4], 11, 81, 82],
  4779.                     9: [[0, 5], 11, 21, 22],
  4780.                     10: [[0, 5], 11, 21, 81],
  4781.                     11: [[0, 3], 21, 22],
  4782.                     12: [[0, 2], 4, 21, 23, 24, 81, 82],
  4783.                     13: [[0, 3], 21, 22, 24, 81, 82],
  4784.                     14: [[0, 4], 21, 22, 81]
  4785.                 },
  4786.                 22: {
  4787.                     0: [0],
  4788.                     1: [[0, 6], 12, 22, [81, 83]],
  4789.                     2: [[0, 4], 11, 21, [81, 84]],
  4790.                     3: [[0, 3], 22, 23, 81, 82],
  4791.                     4: [[0, 3], 21, 22],
  4792.                     5: [[0, 3], 21, 23, 24, 81, 82],
  4793.                     6: [[0, 2], 4, 5, [21, 23], 25, 81],
  4794.                     7: [[0, 2], [21, 24], 81],
  4795.                     8: [[0, 2], 21, 22, 81, 82],
  4796.                     24: [[0, 6], 24, 26]
  4797.                 },
  4798.                 23: {
  4799.                     0: [0],
  4800.                     1: [[0, 12], 21, [23, 29], [81, 84]],
  4801.                     2: [[0, 8], 21, [23, 25], 27, [29, 31], 81],
  4802.                     3: [[0, 7], 21, 81, 82],
  4803.                     4: [[0, 7], 21, 22],
  4804.                     5: [[0, 3], 5, 6, [21, 24]],
  4805.                     6: [[0, 6], [21, 24]],
  4806.                     7: [[0, 16], 22, 81],
  4807.                     8: [[0, 5], 11, 22, 26, 28, 33, 81, 82],
  4808.                     9: [[0, 4], 21],
  4809.                     10: [[0, 5], 24, 25, 81, [83, 85]],
  4810.                     11: [[0, 2], 21, 23, 24, 81, 82],
  4811.                     12: [[0, 2], [21, 26], [81, 83]],
  4812.                     27: [[0, 4], [21, 23]]
  4813.                 },
  4814.                 31: {
  4815.                     0: [0],
  4816.                     1: [0, 1, [3, 10], [12, 20]],
  4817.                     2: [0, 30]
  4818.                 },
  4819.                 32: {
  4820.                     0: [0],
  4821.                     1: [[0, 7], 11, [13, 18], 24, 25],
  4822.                     2: [[0, 6], 11, 81, 82],
  4823.                     3: [[0, 5], 11, 12, [21, 24], 81, 82],
  4824.                     4: [[0, 2], 4, 5, 11, 12, 81, 82],
  4825.                     5: [[0, 9], [81, 85]],
  4826.                     6: [[0, 2], 11, 12, 21, 23, [81, 84]],
  4827.                     7: [0, 1, 3, 5, 6, [21, 24]],
  4828.                     8: [[0, 4], 11, 26, [29, 31]],
  4829.                     9: [[0, 3], [21, 25], 28, 81, 82],
  4830.                     10: [[0, 3], 11, 12, 23, 81, 84, 88],
  4831.                     11: [[0, 2], 11, 12, [81, 83]],
  4832.                     12: [[0, 4], [81, 84]],
  4833.                     13: [[0, 2], 11, [21, 24]]
  4834.                 },
  4835.                 33: {
  4836.                     0: [0],
  4837.                     1: [[0, 6], [8, 10], 22, 27, 82, 83, 85],
  4838.                     2: [0, 1, [3, 6], 11, 12, 25, 26, [81, 83]],
  4839.                     3: [[0, 4], 22, 24, [26, 29], 81, 82],
  4840.                     4: [[0, 2], 11, 21, 24, [81, 83]],
  4841.                     5: [[0, 3], [21, 23]],
  4842.                     6: [[0, 2], 21, 24, [81, 83]],
  4843.                     7: [[0, 3], 23, 26, 27, [81, 84]],
  4844.                     8: [[0, 3], 22, 24, 25, 81],
  4845.                     9: [[0, 3], 21, 22],
  4846.                     10: [[0, 4], [21, 24], 81, 82],
  4847.                     11: [[0, 2], [21, 27], 81]
  4848.                 },
  4849.                 34: {
  4850.                     0: [0],
  4851.                     1: [[0, 4], 11, [21, 24], 81],
  4852.                     2: [[0, 4], 7, 8, [21, 23], 25],
  4853.                     3: [[0, 4], 11, [21, 23]],
  4854.                     4: [[0, 6], 21],
  4855.                     5: [[0, 4], 6, [21, 23]],
  4856.                     6: [[0, 4], 21],
  4857.                     7: [[0, 3], 11, 21],
  4858.                     8: [[0, 3], 11, [22, 28], 81],
  4859.                     10: [[0, 4], [21, 24]],
  4860.                     11: [[0, 3], 22, [24, 26], 81, 82],
  4861.                     12: [[0, 4], 21, 22, 25, 26, 82],
  4862.                     13: [[0, 2], [21, 24]],
  4863.                     14: [[0, 2], [21, 24]],
  4864.                     15: [[0, 3], [21, 25]],
  4865.                     16: [[0, 2], [21, 23]],
  4866.                     17: [[0, 2], [21, 23]],
  4867.                     18: [[0, 2], [21, 25], 81]
  4868.                 },
  4869.                 35: {
  4870.                     0: [0],
  4871.                     1: [[0, 5], 11, [21, 25], 28, 81, 82],
  4872.                     2: [[0, 6], [11, 13]],
  4873.                     3: [[0, 5], 22],
  4874.                     4: [[0, 3], 21, [23, 30], 81],
  4875.                     5: [[0, 5], 21, [24, 27], [81, 83]],
  4876.                     6: [[0, 3], [22, 29], 81],
  4877.                     7: [[0, 2], [21, 25], [81, 84]],
  4878.                     8: [[0, 2], [21, 25], 81],
  4879.                     9: [[0, 2], [21, 26], 81, 82]
  4880.                 },
  4881.                 36: {
  4882.                     0: [0],
  4883.                     1: [[0, 5], 11, [21, 24]],
  4884.                     2: [[0, 3], 22, 81],
  4885.                     3: [[0, 2], 13, [21, 23]],
  4886.                     4: [[0, 3], 21, [23, 30], 81, 82],
  4887.                     5: [[0, 2], 21],
  4888.                     6: [[0, 2], 22, 81],
  4889.                     7: [[0, 2], [21, 35], 81, 82],
  4890.                     8: [[0, 3], [21, 30], 81],
  4891.                     9: [[0, 2], [21, 26], [81, 83]],
  4892.                     10: [[0, 2], [21, 30]],
  4893.                     11: [[0, 2], [21, 30], 81]
  4894.                 },
  4895.                 37: {
  4896.                     0: [0],
  4897.                     1: [[0, 5], 12, 13, [24, 26], 81],
  4898.                     2: [[0, 3], 5, [11, 14], [81, 85]],
  4899.                     3: [[0, 6], [21, 23]],
  4900.                     4: [[0, 6], 81],
  4901.                     5: [[0, 3], [21, 23]],
  4902.                     6: [[0, 2], [11, 13], 34, [81, 87]],
  4903.                     7: [[0, 5], 24, 25, [81, 86]],
  4904.                     8: [[0, 2], 11, [26, 32], [81, 83]],
  4905.                     9: [[0, 3], 11, 21, 23, 82, 83],
  4906.                     10: [[0, 2], [81, 83]],
  4907.                     11: [[0, 3], 21, 22],
  4908.                     12: [[0, 3]],
  4909.                     13: [[0, 2], 11, 12, [21, 29]],
  4910.                     14: [[0, 2], [21, 28], 81, 82],
  4911.                     15: [[0, 2], [21, 26], 81],
  4912.                     16: [[0, 2], [21, 26]],
  4913.                     17: [[0, 2], [21, 28]]
  4914.                 },
  4915.                 41: {
  4916.                     0: [0],
  4917.                     1: [[0, 6], 8, 22, [81, 85]],
  4918.                     2: [[0, 5], 11, [21, 25]],
  4919.                     3: [[0, 7], 11, [22, 29], 81],
  4920.                     4: [[0, 4], 11, [21, 23], 25, 81, 82],
  4921.                     5: [[0, 3], 5, 6, 22, 23, 26, 27, 81],
  4922.                     6: [[0, 3], 11, 21, 22],
  4923.                     7: [[0, 4], 11, 21, [24, 28], 81, 82],
  4924.                     8: [[0, 4], 11, [21, 23], 25, [81, 83]],
  4925.                     9: [[0, 2], 22, 23, [26, 28]],
  4926.                     10: [[0, 2], [23, 25], 81, 82],
  4927.                     11: [[0, 4], [21, 23]],
  4928.                     12: [[0, 2], 21, 22, 24, 81, 82],
  4929.                     13: [[0, 3], [21, 30], 81],
  4930.                     14: [[0, 3], [21, 26], 81],
  4931.                     15: [[0, 3], [21, 28]],
  4932.                     16: [[0, 2], [21, 28], 81],
  4933.                     17: [[0, 2], [21, 29]],
  4934.                     90: [0, 1]
  4935.                 },
  4936.                 42: {
  4937.                     0: [0],
  4938.                     1: [[0, 7], [11, 17]],
  4939.                     2: [[0, 5], 22, 81],
  4940.                     3: [[0, 3], [21, 25], 81],
  4941.                     5: [[0, 6], [25, 29], [81, 83]],
  4942.                     6: [[0, 2], 6, 7, [24, 26], [82, 84]],
  4943.                     7: [[0, 4]],
  4944.                     8: [[0, 2], 4, 21, 22, 81],
  4945.                     9: [[0, 2], [21, 23], 81, 82, 84],
  4946.                     10: [[0, 3], [22, 24], 81, 83, 87],
  4947.                     11: [[0, 2], [21, 27], 81, 82],
  4948.                     12: [[0, 2], [21, 24], 81],
  4949.                     13: [[0, 3], 21, 81],
  4950.                     28: [[0, 2], 22, 23, [25, 28]],
  4951.                     90: [0, [4, 6], 21]
  4952.                 },
  4953.                 43: {
  4954.                     0: [0],
  4955.                     1: [[0, 5], 11, 12, 21, 22, 24, 81],
  4956.                     2: [[0, 4], 11, 21, [23, 25], 81],
  4957.                     3: [[0, 2], 4, 21, 81, 82],
  4958.                     4: [0, 1, [5, 8], 12, [21, 24], 26, 81, 82],
  4959.                     5: [[0, 3], 11, [21, 25], [27, 29], 81],
  4960.                     6: [[0, 3], 11, 21, 23, 24, 26, 81, 82],
  4961.                     7: [[0, 3], [21, 26], 81],
  4962.                     8: [[0, 2], 11, 21, 22],
  4963.                     9: [[0, 3], [21, 23], 81],
  4964.                     10: [[0, 3], [21, 28], 81],
  4965.                     11: [[0, 3], [21, 29]],
  4966.                     12: [[0, 2], [21, 30], 81],
  4967.                     13: [[0, 2], 21, 22, 81, 82],
  4968.                     31: [0, 1, [22, 27], 30]
  4969.                 },
  4970.                 44: {
  4971.                     0: [0],
  4972.                     1: [[0, 7], [11, 16], 83, 84],
  4973.                     2: [[0, 5], 21, 22, 24, 29, 32, 33, 81, 82],
  4974.                     3: [0, 1, [3, 8]],
  4975.                     4: [[0, 4]],
  4976.                     5: [0, 1, [6, 15], 23, 82, 83],
  4977.                     6: [0, 1, [4, 8]],
  4978.                     7: [0, 1, [3, 5], 81, [83, 85]],
  4979.                     8: [[0, 4], 11, 23, 25, [81, 83]],
  4980.                     9: [[0, 3], 23, [81, 83]],
  4981.                     12: [[0, 3], [23, 26], 83, 84],
  4982.                     13: [[0, 3], [22, 24], 81],
  4983.                     14: [[0, 2], [21, 24], 26, 27, 81],
  4984.                     15: [[0, 2], 21, 23, 81],
  4985.                     16: [[0, 2], [21, 25]],
  4986.                     17: [[0, 2], 21, 23, 81],
  4987.                     18: [[0, 3], 21, 23, [25, 27], 81, 82],
  4988.                     19: [0],
  4989.                     20: [0],
  4990.                     51: [[0, 3], 21, 22],
  4991.                     52: [[0, 3], 21, 22, 24, 81],
  4992.                     53: [[0, 2], [21, 23], 81]
  4993.                 },
  4994.                 45: {
  4995.                     0: [0],
  4996.                     1: [[0, 9], [21, 27]],
  4997.                     2: [[0, 5], [21, 26]],
  4998.                     3: [[0, 5], 11, 12, [21, 32]],
  4999.                     4: [0, 1, [3, 6], 11, [21, 23], 81],
  5000.                     5: [[0, 3], 12, 21],
  5001.                     6: [[0, 3], 21, 81],
  5002.                     7: [[0, 3], 21, 22],
  5003.                     8: [[0, 4], 21, 81],
  5004.                     9: [[0, 3], [21, 24], 81],
  5005.                     10: [[0, 2], [21, 31]],
  5006.                     11: [[0, 2], [21, 23]],
  5007.                     12: [[0, 2], [21, 29], 81],
  5008.                     13: [[0, 2], [21, 24], 81],
  5009.                     14: [[0, 2], [21, 25], 81]
  5010.                 },
  5011.                 46: {
  5012.                     0: [0],
  5013.                     1: [0, 1, [5, 8]],
  5014.                     2: [0, 1],
  5015.                     3: [0, [21, 23]],
  5016.                     90: [[0, 3], [5, 7], [21, 39]]
  5017.                 },
  5018.                 50: {
  5019.                     0: [0],
  5020.                     1: [[0, 19]],
  5021.                     2: [0, [22, 38], [40, 43]],
  5022.                     3: [0, [81, 84]]
  5023.                 },
  5024.                 51: {
  5025.                     0: [0],
  5026.                     1: [0, 1, [4, 8], [12, 15], [21, 24], 29, 31, 32, [81, 84]],
  5027.                     3: [[0, 4], 11, 21, 22],
  5028.                     4: [[0, 3], 11, 21, 22],
  5029.                     5: [[0, 4], 21, 22, 24, 25],
  5030.                     6: [0, 1, 3, 23, 26, [81, 83]],
  5031.                     7: [0, 1, 3, 4, [22, 27], 81],
  5032.                     8: [[0, 2], 11, 12, [21, 24]],
  5033.                     9: [[0, 4], [21, 23]],
  5034.                     10: [[0, 2], 11, 24, 25, 28],
  5035.                     11: [[0, 2], [11, 13], 23, 24, 26, 29, 32, 33, 81],
  5036.                     13: [[0, 4], [21, 25], 81],
  5037.                     14: [[0, 2], [21, 25]],
  5038.                     15: [[0, 3], [21, 29]],
  5039.                     16: [[0, 3], [21, 23], 81],
  5040.                     17: [[0, 3], [21, 25], 81],
  5041.                     18: [[0, 3], [21, 27]],
  5042.                     19: [[0, 3], [21, 23]],
  5043.                     20: [[0, 2], 21, 22, 81],
  5044.                     32: [0, [21, 33]],
  5045.                     33: [0, [21, 38]],
  5046.                     34: [0, 1, [22, 37]]
  5047.                 },
  5048.                 52: {
  5049.                     0: [0],
  5050.                     1: [[0, 3], [11, 15], [21, 23], 81],
  5051.                     2: [0, 1, 3, 21, 22],
  5052.                     3: [[0, 3], [21, 30], 81, 82],
  5053.                     4: [[0, 2], [21, 25]],
  5054.                     5: [[0, 2], [21, 27]],
  5055.                     6: [[0, 3], [21, 28]],
  5056.                     22: [0, 1, [22, 30]],
  5057.                     23: [0, 1, [22, 28]],
  5058.                     24: [0, 1, [22, 28]],
  5059.                     26: [0, 1, [22, 36]],
  5060.                     27: [[0, 2], 22, 23, [25, 32]]
  5061.                 },
  5062.                 53: {
  5063.                     0: [0],
  5064.                     1: [[0, 3], [11, 14], 21, 22, [24, 29], 81],
  5065.                     3: [[0, 2], [21, 26], 28, 81],
  5066.                     4: [[0, 2], [21, 28]],
  5067.                     5: [[0, 2], [21, 24]],
  5068.                     6: [[0, 2], [21, 30]],
  5069.                     7: [[0, 2], [21, 24]],
  5070.                     8: [[0, 2], [21, 29]],
  5071.                     9: [[0, 2], [21, 27]],
  5072.                     23: [0, 1, [22, 29], 31],
  5073.                     25: [[0, 4], [22, 32]],
  5074.                     26: [0, 1, [21, 28]],
  5075.                     27: [0, 1, [22, 30]], 28: [0, 1, 22, 23],
  5076.                     29: [0, 1, [22, 32]],
  5077.                     31: [0, 2, 3, [22, 24]],
  5078.                     34: [0, [21, 23]],
  5079.                     33: [0, 21, [23, 25]],
  5080.                     35: [0, [21, 28]]
  5081.                 },
  5082.                 54: {
  5083.                     0: [0],
  5084.                     1: [[0, 2], [21, 27]],
  5085.                     21: [0, [21, 29], 32, 33],
  5086.                     22: [0, [21, 29], [31, 33]],
  5087.                     23: [0, 1, [22, 38]],
  5088.                     24: [0, [21, 31]],
  5089.                     25: [0, [21, 27]],
  5090.                     26: [0, [21, 27]]
  5091.                 },
  5092.                 61: {
  5093.                     0: [0],
  5094.                     1: [[0, 4], [11, 16], 22, [24, 26]],
  5095.                     2: [[0, 4], 22],
  5096.                     3: [[0, 4], [21, 24], [26, 31]],
  5097.                     4: [[0, 4], [22, 31], 81],
  5098.                     5: [[0, 2], [21, 28], 81, 82],
  5099.                     6: [[0, 2], [21, 32]],
  5100.                     7: [[0, 2], [21, 30]],
  5101.                     8: [[0, 2], [21, 31]],
  5102.                     9: [[0, 2], [21, 29]],
  5103.                     10: [[0, 2], [21, 26]]
  5104.                 },
  5105.                 62: {
  5106.                     0: [0],
  5107.                     1: [[0, 5], 11, [21, 23]],
  5108.                     2: [0, 1],
  5109.                     3: [[0, 2], 21],
  5110.                     4: [[0, 3], [21, 23]],
  5111.                     5: [[0, 3], [21, 25]],
  5112.                     6: [[0, 2], [21, 23]],
  5113.                     7: [[0, 2], [21, 25]],
  5114.                     8: [[0, 2], [21, 26]],
  5115.                     9: [[0, 2], [21, 24], 81, 82],
  5116.                     10: [[0, 2], [21, 27]],
  5117.                     11: [[0, 2], [21, 26]],
  5118.                     12: [[0, 2], [21, 28]],
  5119.                     24: [0, 21, [24, 29]],
  5120.                     26: [0, 21, [23, 30]],
  5121.                     29: [0, 1, [21, 27]],
  5122.                     30: [0, 1, [21, 27]]
  5123.                 },
  5124.                 63: {
  5125.                     0: [0],
  5126.                     1: [[0, 5], [21, 23]],
  5127.                     2: [0, 2, [21, 25]],
  5128.                     21: [0, [21, 23], [26, 28]],
  5129.                     22: [0, [21, 24]],
  5130.                     23: [0, [21, 24]],
  5131.                     25: [0, [21, 25]],
  5132.                     26: [0, [21, 26]],
  5133.                     27: [0, 1, [21, 26]],
  5134.                     28: [[0, 2], [21, 23]]
  5135.                 },
  5136.                 64: {
  5137.                     0: [0],
  5138.                     1: [0, 1, [4, 6], 21, 22, 81],
  5139.                     2: [[0, 3], 5, [21, 23]],
  5140.                     3: [[0, 3], [21, 24], 81],
  5141.                     4: [[0, 2], [21, 25]],
  5142.                     5: [[0, 2], 21, 22]
  5143.                 },
  5144.                 65: {
  5145.                     0: [0],
  5146.                     1: [[0, 9], 21],
  5147.                     2: [[0, 5]],
  5148.                     21: [0, 1, 22, 23],
  5149.                     22: [0, 1, 22, 23],
  5150.                     23: [[0, 3], [23, 25], 27, 28],
  5151.                     28: [0, 1, [22, 29]],
  5152.                     29: [0, 1, [22, 29]],
  5153.                     30: [0, 1, [22, 24]], 31: [0, 1, [21, 31]],
  5154.                     32: [0, 1, [21, 27]],
  5155.                     40: [0, 2, 3, [21, 28]],
  5156.                     42: [[0, 2], 21, [23, 26]],
  5157.                     43: [0, 1, [21, 26]],
  5158.                     90: [[0, 4]], 27: [[0, 2], 22, 23]
  5159.                 },
  5160.                 71: { 0: [0] },
  5161.                 81: { 0: [0] },
  5162.                 82: { 0: [0] }
  5163.             };
  5164.            
  5165.             var provincial  = parseInt(value.substr(0, 2), 10),
  5166.                 prefectural = parseInt(value.substr(2, 2), 10),
  5167.                 county      = parseInt(value.substr(4, 2), 10);
  5168.            
  5169.             if (!adminDivisionCodes[provincial] || !adminDivisionCodes[provincial][prefectural]) {
  5170.                 return false;
  5171.             }
  5172.             var inRange  = false,
  5173.                 rangeDef = adminDivisionCodes[provincial][prefectural];
  5174.             for (var i = 0; i < rangeDef.length; i++) {
  5175.                if (($.isArray(rangeDef[i]) && rangeDef[i][0] <= county && county <= rangeDef[i][1])
  5176.                    || (!$.isArray(rangeDef[i]) && county === rangeDef[i]))
  5177.                {
  5178.                    inRange = true;
  5179.                    break;
  5180.                }
  5181.            }
  5182.  
  5183.            if (!inRange) {
  5184.                return false;
  5185.            }
  5186.            
  5187.            // Check date of birth
  5188.            var dob;
  5189.            if (value.length === 18) {
  5190.                dob = value.substr(6, 8);
  5191.            } else /* length == 15 */ {
  5192.                dob = '19' + value.substr(6, 6);
  5193.            }
  5194.            var year  = parseInt(dob.substr(0, 4), 10),
  5195.                month = parseInt(dob.substr(4, 2), 10),
  5196.                day   = parseInt(dob.substr(6, 2), 10);
  5197.            if (!FormValidation.Helper.date(year, month, day)) {
  5198.                return false;
  5199.            }
  5200.            
  5201.            // Check checksum (18-digit system only)
  5202.            if (value.length === 18) {
  5203.                var sum    = 0,
  5204.                    weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  5205.                for (i = 0; i < 17; i++) {
  5206.                    sum += parseInt(value.charAt(i), 10) * weight[i];
  5207.                }
  5208.                sum = (12 - (sum % 11)) % 11;
  5209.                var checksum = (value.charAt(17).toUpperCase() !== 'X') ? parseInt(value.charAt(17), 10) : 10;
  5210.                return checksum === sum;
  5211.            }
  5212.            
  5213.            return true;
  5214.        },
  5215.        
  5216.        /**
  5217.         * Validate Czech national identification number (RC)
  5218.         * Examples:
  5219.         * - Valid: 7103192745, 991231123
  5220.         * - Invalid: 1103492745, 590312123
  5221.         *
  5222.         * @param {String} value The ID
  5223.         * @returns {Boolean}
  5224.         */
  5225.        _cz: function(value) {
  5226.            if (!/^\d{9,10}$/.test(value)) {
  5227.                return false;
  5228.            }
  5229.            var year  = 1900 + parseInt(value.substr(0, 2), 10),
  5230.                month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  5231.                day   = parseInt(value.substr(4, 2), 10);
  5232.            if (value.length === 9) {
  5233.                if (year >= 1980) {
  5234.                     year -= 100;
  5235.                 }
  5236.                 if (year > 1953) {
  5237.                     return false;
  5238.                 }
  5239.             } else if (year < 1954) {
  5240.                year += 100;
  5241.            }
  5242.  
  5243.            if (!FormValidation.Helper.date(year, month, day)) {
  5244.                return false;
  5245.            }
  5246.  
  5247.            // Check that the birth date is not in the future
  5248.            if (value.length === 10) {
  5249.                var check = parseInt(value.substr(0, 9), 10) % 11;
  5250.                if (year < 1985) {
  5251.                    check = check % 10;
  5252.                }
  5253.                return (check + '' === value.substr(9, 1));
  5254.            }
  5255.  
  5256.            return true;
  5257.        },
  5258.  
  5259.        /**
  5260.         * Validate Danish Personal Identification number (CPR)
  5261.         * Examples:
  5262.         * - Valid: 2110625629, 211062-5629
  5263.         * - Invalid: 511062-5629
  5264.         *
  5265.         * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  5266.         * @param {String} value The ID
  5267.         * @returns {Boolean}
  5268.         */
  5269.        _dk: function(value) {
  5270.            if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  5271.                return false;
  5272.            }
  5273.            value = value.replace(/-/g, '');
  5274.            var day   = parseInt(value.substr(0, 2), 10),
  5275.                month = parseInt(value.substr(2, 2), 10),
  5276.                year  = parseInt(value.substr(4, 2), 10);
  5277.  
  5278.            switch (true) {
  5279.                case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  5280.                     year += 1800;
  5281.                     break;
  5282.                 case ('0123'.indexOf(value.charAt(6)) !== -1):
  5283.                 case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  5284.                    year += 1900;
  5285.                     break;
  5286.                 default:
  5287.                     year += 2000;
  5288.                     break;
  5289.             }
  5290.  
  5291.             return FormValidation.Helper.date(year, month, day);
  5292.         },
  5293.  
  5294.         /**
  5295.          * Validate Estonian Personal Identification Code (isikukood)
  5296.          * Examples:
  5297.          * - Valid: 37605030299
  5298.          *
  5299.          * @see http://et.wikipedia.org/wiki/Isikukood
  5300.          * @param {String} value The ID
  5301.          * @returns {Boolean}
  5302.          */
  5303.         _ee: function(value) {
  5304.             // Use the same format as Lithuanian Personal Code
  5305.             return this._lt(value);
  5306.         },
  5307.  
  5308.         /**
  5309.          * Validate Spanish personal identity code (DNI)
  5310.          * Support i) DNI (for Spanish citizens), ii) NIE (for foreign people)
  5311.          * and iii) CIF (for legal entities)
  5312.          *
  5313.          * Examples:
  5314.          * - Valid:
  5315.          *      i) 54362315K, 54362315-K
  5316.          *      ii) X2482300W, X-2482300W, X-2482300-W
  5317.          *      iii) A58818501, A-58818501
  5318.          * - Invalid:
  5319.          *      i) 54362315Z
  5320.          *      ii) X-2482300A
  5321.          *      iii) K58818501, G58818507
  5322.          *
  5323.          * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  5324.          * @param {String} value The ID
  5325.          * @returns {Boolean}
  5326.          */
  5327.         _es: function(value) {
  5328.             var isDNI = /^[0-9]{8}[-]{0,1}[A-HJ-NP-TV-Z]$/.test(value),
  5329.                 isNIE = /^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[A-HJ-NP-TV-Z]$/.test(value),
  5330.                 isCIF = /^[A-HNPQS][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-J]$/.test(value);
  5331.             if (!isDNI && !isNIE && !isCIF) {
  5332.                return false;
  5333.             }
  5334.  
  5335.             value = value.replace(/-/g, '');
  5336.             var check;
  5337.             if (isDNI || isNIE) {
  5338.                 var index = 'XYZ'.indexOf(value.charAt(0));
  5339.                 if (index !== -1) {
  5340.                     // It is NIE number
  5341.                     value = index + value.substr(1) + '';
  5342.                 }
  5343.  
  5344.                 check = parseInt(value.substr(0, 8), 10);
  5345.                 check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5346.                 return (check === value.substr(8, 1));
  5347.             } else {
  5348.                 check = value.substr(1, 7);
  5349.                 var letter  = value[0],
  5350.                     control = value.substr(-1),
  5351.                     sum     = 0;
  5352.  
  5353.                 // The digits in the even positions are added to the sum directly.
  5354.                 // The ones in the odd positions are multiplied by 2 and then added to the sum.
  5355.                 // If the result of multiplying by 2 is 10 or higher, add the two digits
  5356.                 // together and add that to the sum instead
  5357.                 for (var i = 0; i < check.length; i++) {
  5358.                    if (i % 2 !== 0) {
  5359.                        sum += parseInt(check[i], 10);
  5360.                    } else {
  5361.                        var tmp = '' + (parseInt(check[i], 10) * 2);
  5362.                        sum += parseInt(tmp[0], 10);
  5363.                        if (tmp.length === 2) {
  5364.                            sum += parseInt(tmp[1], 10);
  5365.                        }
  5366.                    }
  5367.                }
  5368.  
  5369.                // The control digit is calculated from the last digit of the sum.
  5370.                // If that last digit is not 0, subtract it from 10
  5371.                var lastDigit = sum - (Math.floor(sum / 10) * 10);
  5372.                if (lastDigit !== 0) {
  5373.                    lastDigit = 10 - lastDigit;
  5374.                }
  5375.                
  5376.                if ('KQS'.indexOf(letter) !== -1) {
  5377.                    // If the CIF starts with a K, Q or S, the control digit must be a letter
  5378.                    return (control === 'JABCDEFGHI'[lastDigit]);
  5379.                } else if ('ABEH'.indexOf(letter) !== -1) {
  5380.                    // If it starts with A, B, E or H, it has to be a number
  5381.                    return (control === ('' + lastDigit));
  5382.                } else {
  5383.                    // In any other case, it doesn't matter
  5384.                    return (control === ('' + lastDigit) || control === 'JABCDEFGHI'[lastDigit]);
  5385.                }
  5386.            }
  5387.        },
  5388.        /**
  5389.         * Validate Finnish Personal Identity Code (HETU)
  5390.         * Examples:
  5391.         * - Valid: 311280-888Y, 131052-308T
  5392.         * - Invalid: 131052-308U, 310252-308Y
  5393.         *
  5394.         * @param {String} value The ID
  5395.         * @returns {Boolean}
  5396.         */
  5397.        _fi: function(value) {
  5398.            if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  5399.                return false;
  5400.            }
  5401.            var day       = parseInt(value.substr(0, 2), 10),
  5402.                month     = parseInt(value.substr(2, 2), 10),
  5403.                year      = parseInt(value.substr(4, 2), 10),
  5404.                centuries = {
  5405.                    '+': 1800,
  5406.                    '-': 1900,
  5407.                    'A': 2000
  5408.                };
  5409.            year = centuries[value.charAt(6)] + year;
  5410.            if (!FormValidation.Helper.date(year, month, day)) {
  5411.                return false;
  5412.            }
  5413.            var individual = parseInt(value.substr(7, 3), 10);
  5414.            if (individual < 2) {
  5415.                return false;
  5416.            }
  5417.            var n = value.substr(0, 6) + value.substr(7, 3) + '';
  5418.            n = parseInt(n, 10);
  5419.            return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  5420.        },
  5421.        /**
  5422.         * Validate Croatian personal identification number (OIB)
  5423.         * Examples:
  5424.         * - Valid: 33392005961
  5425.         * - Invalid: 33392005962
  5426.         *
  5427.         * @param {String} value The ID
  5428.         * @returns {Boolean}
  5429.         */
  5430.        _hr: function(value) {
  5431.            if (!/^[0-9]{11}$/.test(value)) {
  5432.                return false;
  5433.            }
  5434.            return FormValidation.Helper.mod11And10(value);
  5435.        },
  5436.        /**
  5437.         * Validate Irish Personal Public Service Number (PPS)
  5438.         * Examples:
  5439.         * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  5440.         * - Invalid: 6433435E, 6433435VH
  5441.         *
  5442.         * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  5443.         * @param {String} value The ID
  5444.         * @returns {Boolean}
  5445.         */
  5446.        _ie: function(value) {
  5447.            if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  5448.                return false;
  5449.            }
  5450.            var getCheckDigit = function(value) {
  5451.                while (value.length < 7) {
  5452.                    value = '0' + value;
  5453.                }
  5454.                var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  5455.                    sum      = 0;
  5456.                for (var i = 0; i < 7; i++) {
  5457.                    sum += parseInt(value.charAt(i), 10) * (8 - i);
  5458.                }
  5459.                sum += 9 * alphabet.indexOf(value.substr(7));
  5460.                return alphabet[sum % 23];
  5461.            };
  5462.            // 2013 format
  5463.            if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  5464.                return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  5465.            }
  5466.            // The old format
  5467.            else {
  5468.                return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  5469.            }
  5470.        },
  5471.        /**
  5472.         * Validate Iceland national identification number (Kennitala)
  5473.         * Examples:
  5474.         * - Valid: 120174-3399, 1201743399, 0902862349
  5475.         *
  5476.         * @see http://en.wikipedia.org/wiki/Kennitala
  5477.         * @param {String} value The ID
  5478.         * @returns {Boolean}
  5479.         */
  5480.        _is: function(value) {
  5481.            if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  5482.                return false;
  5483.            }
  5484.            value = value.replace(/-/g, '');
  5485.            var day     = parseInt(value.substr(0, 2), 10),
  5486.                month   = parseInt(value.substr(2, 2), 10),
  5487.                year    = parseInt(value.substr(4, 2), 10),
  5488.                century = parseInt(value.charAt(9), 10);
  5489.            year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  5490.            if (!FormValidation.Helper.date(year, month, day, true)) {
  5491.                return false;
  5492.            }
  5493.            // Validate the check digit
  5494.            var sum    = 0,
  5495.                weight = [3, 2, 7, 6, 5, 4, 3, 2];
  5496.            for (var i = 0; i < 8; i++) {
  5497.                sum += parseInt(value.charAt(i), 10) * weight[i];
  5498.            }
  5499.            sum = 11 - sum % 11;
  5500.            return (sum + '' === value.charAt(8));
  5501.        },
  5502.        /**
  5503.         * Validate Lithuanian Personal Code (Asmens kodas)
  5504.         * Examples:
  5505.         * - Valid: 38703181745
  5506.         * - Invalid: 38703181746, 78703181745, 38703421745
  5507.         *
  5508.         * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  5509.         * @see http://www.adomas.org/midi2007/pcode.html
  5510.         * @param {String} value The ID
  5511.         * @returns {Boolean}
  5512.         */
  5513.        _lt: function(value) {
  5514.            if (!/^[0-9]{11}$/.test(value)) {
  5515.                return false;
  5516.            }
  5517.            var gender  = parseInt(value.charAt(0), 10),
  5518.                year    = parseInt(value.substr(1, 2), 10),
  5519.                month   = parseInt(value.substr(3, 2), 10),
  5520.                day     = parseInt(value.substr(5, 2), 10),
  5521.                century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  5522.            year = century * 100 + year;
  5523.            if (!FormValidation.Helper.date(year, month, day, true)) {
  5524.                return false;
  5525.            }
  5526.            // Validate the check digit
  5527.            var sum    = 0,
  5528.                weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  5529.            for (var i = 0; i < 10; i++) {
  5530.                sum += parseInt(value.charAt(i), 10) * weight[i];
  5531.            }
  5532.            sum = sum % 11;
  5533.            if (sum !== 10) {
  5534.                return sum + '' === value.charAt(10);
  5535.            }
  5536.            // Re-calculate the check digit
  5537.            sum    = 0;
  5538.            weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  5539.            for (i = 0; i < 10; i++) {
  5540.                sum += parseInt(value.charAt(i), 10) * weight[i];
  5541.            }
  5542.            sum = sum % 11;
  5543.            if (sum === 10) {
  5544.                sum = 0;
  5545.            }
  5546.            return (sum + '' === value.charAt(10));
  5547.        },
  5548.        /**
  5549.         * Validate Latvian Personal Code (Personas kods)
  5550.         * Examples:
  5551.         * - Valid: 161175-19997, 16117519997
  5552.         * - Invalid: 161375-19997
  5553.         *
  5554.         * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  5555.         * @param {String} value The ID
  5556.         * @returns {Boolean}
  5557.         */
  5558.        _lv: function(value) {
  5559.            if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  5560.                return false;
  5561.            }
  5562.            value = value.replace(/\D/g, '');
  5563.            // Check birth date
  5564.            var day   = parseInt(value.substr(0, 2), 10),
  5565.                month = parseInt(value.substr(2, 2), 10),
  5566.                year  = parseInt(value.substr(4, 2), 10);
  5567.            year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  5568.            if (!FormValidation.Helper.date(year, month, day, true)) {
  5569.                return false;
  5570.            }
  5571.            // Check personal code
  5572.            var sum    = 0,
  5573.                weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  5574.            for (var i = 0; i < 10; i++) {
  5575.                sum += parseInt(value.charAt(i), 10) * weight[i];
  5576.            }
  5577.            sum = (sum + 1) % 11 % 10;
  5578.            return (sum + '' === value.charAt(10));
  5579.        },
  5580.        /**
  5581.         * Validate Dutch national identification number (BSN)
  5582.         * Examples:
  5583.         * - Valid: 111222333, 941331490, 9413.31.490
  5584.         * - Invalid: 111252333
  5585.         *
  5586.         * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  5587.         * @param {String} value The ID
  5588.         * @returns {Boolean}
  5589.         */
  5590.        _nl: function(value) {
  5591.            while (value.length < 9) {
  5592.                value = '0' + value;
  5593.            }
  5594.            if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  5595.                return false;
  5596.            }
  5597.            value = value.replace(/\./g, '');
  5598.            if (parseInt(value, 10) === 0) {
  5599.                return false;
  5600.            }
  5601.            var sum    = 0,
  5602.                length = value.length;
  5603.            for (var i = 0; i < length - 1; i++) {
  5604.                sum += (9 - i) * parseInt(value.charAt(i), 10);
  5605.            }
  5606.            sum = sum % 11;
  5607.            if (sum === 10) {
  5608.                sum = 0;
  5609.            }
  5610.            return (sum + '' === value.charAt(length - 1));
  5611.        },
  5612.        
  5613.        /**
  5614.         * Validate Poland citizen number (PESEL)
  5615.         *
  5616.         * @see http://en.wikipedia.org/wiki/National_identification_number#Poland
  5617.         * @see http://en.wikipedia.org/wiki/PESEL
  5618.         * @param {String} value The ID
  5619.         * @returns {Boolean}
  5620.         */
  5621.        _pl: function(value) {
  5622.            if (!/^[0-9]{11}$/.test(value)) {
  5623.                return false;
  5624.            }
  5625.            var sum    = 0,
  5626.                length = value.length,
  5627.                weight = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 7];
  5628.            for (var i = 0; i < length - 1; i++) {
  5629.                sum += weight[i] * parseInt(value.charAt(i), 10);
  5630.            }
  5631.            sum = sum % 10;
  5632.            if (sum === 0) {
  5633.                sum = 10;
  5634.            }
  5635.            sum = 10 - sum;
  5636.            return (sum + '' === value.charAt(length - 1));
  5637.        },
  5638.        /**
  5639.         * Validate Romanian numerical personal code (CNP)
  5640.         * Examples:
  5641.         * - Valid: 1630615123457, 1800101221144
  5642.         * - Invalid: 8800101221144, 1632215123457, 1630615123458
  5643.         *
  5644.         * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  5645.         * @param {String} value The ID
  5646.         * @returns {Boolean}
  5647.         */
  5648.        _ro: function(value) {
  5649.            if (!/^[0-9]{13}$/.test(value)) {
  5650.                return false;
  5651.            }
  5652.            var gender = parseInt(value.charAt(0), 10);
  5653.            if (gender === 0 || gender === 7 || gender === 8) {
  5654.                return false;
  5655.            }
  5656.            // Determine the date of birth
  5657.            var year      = parseInt(value.substr(1, 2), 10),
  5658.                month     = parseInt(value.substr(3, 2), 10),
  5659.                day       = parseInt(value.substr(5, 2), 10),
  5660.                // The year of date is determined base on the gender
  5661.                centuries = {
  5662.                    '1': 1900,  // Male born between 1900 and 1999
  5663.                    '2': 1900,  // Female born between 1900 and 1999
  5664.                    '3': 1800,  // Male born between 1800 and 1899
  5665.                    '4': 1800,  // Female born between 1800 and 1899
  5666.                    '5': 2000,  // Male born after 2000
  5667.                    '6': 2000   // Female born after 2000
  5668.                };
  5669.            if (day > 31 && month > 12) {
  5670.                return false;
  5671.             }
  5672.             if (gender !== 9) {
  5673.                 year = centuries[gender + ''] + year;
  5674.                 if (!FormValidation.Helper.date(year, month, day)) {
  5675.                     return false;
  5676.                 }
  5677.             }
  5678.  
  5679.             // Validate the check digit
  5680.             var sum    = 0,
  5681.                 weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  5682.                 length = value.length;
  5683.             for (var i = 0; i < length - 1; i++) {
  5684.                sum += parseInt(value.charAt(i), 10) * weight[i];
  5685.            }
  5686.            sum = sum % 11;
  5687.            if (sum === 10) {
  5688.                sum = 1;
  5689.            }
  5690.            return (sum + '' === value.charAt(length - 1));
  5691.        },
  5692.  
  5693.        /**
  5694.         * Validate Swedish personal identity number (personnummer)
  5695.         * Examples:
  5696.         * - Valid: 8112289874, 811228-9874, 811228+9874
  5697.         * - Invalid: 811228-9873
  5698.         *
  5699.         * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  5700.         * @param {String} value The ID
  5701.         * @returns {Boolean}
  5702.         */
  5703.        _se: function(value) {
  5704.            if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  5705.                return false;
  5706.            }
  5707.            value = value.replace(/[^0-9]/g, '');
  5708.  
  5709.            var year  = parseInt(value.substr(0, 2), 10) + 1900,
  5710.                month = parseInt(value.substr(2, 2), 10),
  5711.                day   = parseInt(value.substr(4, 2), 10);
  5712.            if (!FormValidation.Helper.date(year, month, day)) {
  5713.                return false;
  5714.            }
  5715.  
  5716.            // Validate the last check digit
  5717.            return FormValidation.Helper.luhn(value);
  5718.        },
  5719.  
  5720.        /**
  5721.         * Validate Slovak national identifier number (RC)
  5722.         * Examples:
  5723.         * - Valid: 7103192745, 991231123
  5724.         * - Invalid: 7103192746, 1103492745
  5725.         *
  5726.         * @param {String} value The ID
  5727.         * @returns {Boolean}
  5728.         */
  5729.        _sk: function(value) {
  5730.            // Slovakia uses the same format as Czech Republic
  5731.            return this._cz(value);
  5732.        },
  5733.  
  5734.        /**
  5735.         * Validate San Marino citizen number
  5736.         *
  5737.         * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  5738.         * @param {String} value The ID
  5739.         * @returns {Boolean}
  5740.         */
  5741.        _sm: function(value) {
  5742.            return /^\d{5}$/.test(value);
  5743.        },
  5744.  
  5745.        /**
  5746.         * Validate Thailand citizen number
  5747.         * Examples:
  5748.         * - Valid: 7145620509547, 3688699975685, 2368719339716
  5749.         * - Invalid: 1100800092310
  5750.         *
  5751.         * @see http://en.wikipedia.org/wiki/National_identification_number#Thailand
  5752.         * @param {String} value The ID
  5753.         * @returns {Boolean}
  5754.         */
  5755.        _th: function(value) {
  5756.            if (value.length !== 13) {
  5757.                return false;
  5758.            }
  5759.  
  5760.            var sum = 0;
  5761.            for (var i = 0; i < 12; i++) {
  5762.                sum += parseInt(value.charAt(i), 10) * (13 - i);
  5763.            }
  5764.  
  5765.            return (11 - sum % 11) % 10 === parseInt(value.charAt(12), 10);
  5766.        },
  5767.  
  5768.        /**
  5769.         * Validate South African ID
  5770.         * Example:
  5771.         * - Valid: 8001015009087
  5772.         * - Invalid: 8001015009287, 8001015009086
  5773.         *
  5774.         * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  5775.         * @param {String} value The ID
  5776.         * @returns {Boolean}
  5777.         */
  5778.        _za: function(value) {
  5779.            if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  5780.                return false;
  5781.            }
  5782.            var year        = parseInt(value.substr(0, 2), 10),
  5783.                currentYear = new Date().getFullYear() % 100,
  5784.                month       = parseInt(value.substr(2, 2), 10),
  5785.                day         = parseInt(value.substr(4, 2), 10);
  5786.            year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  5787.  
  5788.             if (!FormValidation.Helper.date(year, month, day)) {
  5789.                 return false;
  5790.             }
  5791.  
  5792.             // Validate the last check digit
  5793.             return FormValidation.Helper.luhn(value);
  5794.         }
  5795.     };
  5796. }(jQuery));
  5797. ;(function($) {
  5798.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5799.         'en_US': {
  5800.             identical: {
  5801.                 'default': 'Please enter the same value'
  5802.             }
  5803.         }
  5804.     });
  5805.  
  5806.     FormValidation.Validator.identical = {
  5807.         html5Attributes: {
  5808.             message: 'message',
  5809.             field: 'field'
  5810.         },
  5811.  
  5812.         /**
  5813.          * Bind the validator on the live change of the field to compare with current one
  5814.          *
  5815.          * @param {FormValidation.Base} validator The validator plugin instance
  5816.          * @param {jQuery} $field Field element
  5817.          * @param {Object} options Consists of the following key:
  5818.          * - field: The name of field that will be used to compare with current one
  5819.          */
  5820.         init: function(validator, $field, options) {
  5821.             var compareWith = validator.getFieldElements(options.field);
  5822.             validator.onLiveChange(compareWith, 'live_identical', function() {
  5823.                 var status = validator.getStatus($field, 'identical');
  5824.                 if (status !== validator.STATUS_NOT_VALIDATED) {
  5825.                     validator.revalidateField($field);
  5826.                 }
  5827.             });
  5828.         },
  5829.  
  5830.         /**
  5831.          * Unbind the validator on the live change of the field to compare with current one
  5832.          *
  5833.          * @param {FormValidation.Base} validator The validator plugin instance
  5834.          * @param {jQuery} $field Field element
  5835.          * @param {Object} options Consists of the following key:
  5836.          * - field: The name of field that will be used to compare with current one
  5837.          */
  5838.         destroy: function(validator, $field, options) {
  5839.             var compareWith = validator.getFieldElements(options.field);
  5840.             validator.offLiveChange(compareWith, 'live_identical');
  5841.         },
  5842.  
  5843.         /**
  5844.          * Check if input value equals to value of particular one
  5845.          *
  5846.          * @param {FormValidation.Base} validator The validator plugin instance
  5847.          * @param {jQuery} $field Field element
  5848.          * @param {Object} options Consists of the following key:
  5849.          * - field: The name of field that will be used to compare with current one
  5850.          * @returns {Boolean}
  5851.          */
  5852.         validate: function(validator, $field, options) {
  5853.             var value       = validator.getFieldValue($field, 'identical'),
  5854.                 compareWith = validator.getFieldElements(options.field);
  5855.             if (compareWith === null || compareWith.length === 0) {
  5856.                 return true;
  5857.             }
  5858.  
  5859.             var compareValue = validator.getFieldValue(compareWith, 'identical');
  5860.             if (value === compareValue) {
  5861.                 validator.updateStatus(compareWith, validator.STATUS_VALID, 'identical');
  5862.                 return true;
  5863.             }
  5864.  
  5865.             return false;
  5866.         }
  5867.     };
  5868. }(jQuery));
  5869. ;(function($) {
  5870.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5871.         'en_US': {
  5872.             imei: {
  5873.                 'default': 'Please enter a valid IMEI number'
  5874.             }
  5875.         }
  5876.     });
  5877.  
  5878.     FormValidation.Validator.imei = {
  5879.         /**
  5880.          * Validate IMEI (International Mobile Station Equipment Identity)
  5881.          * Examples:
  5882.          * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  5883.          * - Invalid: 490154203237517
  5884.          *
  5885.          * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  5886.          * @param {FormValidation.Base} validator The validator plugin instance
  5887.          * @param {jQuery} $field Field element
  5888.          * @param {Object} options Can consist of the following keys:
  5889.          * - message: The invalid message
  5890.          * @returns {Boolean}
  5891.          */
  5892.         validate: function(validator, $field, options) {
  5893.             var value = validator.getFieldValue($field, 'imei');
  5894.             if (value === '') {
  5895.                 return true;
  5896.             }
  5897.  
  5898.             switch (true) {
  5899.                 case /^\d{15}$/.test(value):
  5900.                 case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  5901.                 case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  5902.                     value = value.replace(/[^0-9]/g, '');
  5903.                     return FormValidation.Helper.luhn(value);
  5904.  
  5905.                 case /^\d{14}$/.test(value):
  5906.                 case /^\d{16}$/.test(value):
  5907.                 case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  5908.                 case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  5909.                     return true;
  5910.  
  5911.                 default:
  5912.                     return false;
  5913.             }
  5914.         }
  5915.     };
  5916. }(jQuery));
  5917. ;(function($) {
  5918.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5919.         'en_US': {
  5920.             imo: {
  5921.                 'default': 'Please enter a valid IMO number'
  5922.             }
  5923.         }
  5924.     });
  5925.  
  5926.     FormValidation.Validator.imo = {
  5927.         /**
  5928.          * Validate IMO (International Maritime Organization)
  5929.          * Examples:
  5930.          * - Valid: IMO 8814275, IMO 9176187
  5931.          * - Invalid: IMO 8814274
  5932.          *
  5933.          * @see http://en.wikipedia.org/wiki/IMO_Number
  5934.          * @param {FormValidation.Base} validator The validator plugin instance
  5935.          * @param {jQuery} $field Field element
  5936.          * @param {Object} options Can consist of the following keys:
  5937.          * - message: The invalid message
  5938.          * @returns {Boolean}
  5939.          */
  5940.         validate: function(validator, $field, options) {
  5941.             var value = validator.getFieldValue($field, 'imo');
  5942.             if (value === '') {
  5943.                 return true;
  5944.             }
  5945.  
  5946.             if (!/^IMO \d{7}$/i.test(value)) {
  5947.                 return false;
  5948.             }
  5949.            
  5950.             // Grab just the digits
  5951.             var sum    = 0,
  5952.                 digits = value.replace(/^.*(\d{7})$/, '$1');
  5953.            
  5954.             // Go over each char, multiplying by the inverse of it's position
  5955.             // IMO 9176187
  5956.             // (9 * 7) + (1 * 6) + (7 * 5) + (6 * 4) + (1 * 3) + (8 * 2) = 147
  5957.             // Take the last digit of that, that's the check digit (7)
  5958.             for (var i = 6; i >= 1; i--) {
  5959.                 sum += (digits.slice((6 - i), -i) * (i + 1));
  5960.             }
  5961.  
  5962.             return sum % 10 === parseInt(digits.charAt(6), 10);
  5963.         }
  5964.     };
  5965. }(jQuery));
  5966. ;(function($) {
  5967.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5968.         'en_US': {
  5969.             integer: {
  5970.                 'default': 'Please enter a valid number'
  5971.             }
  5972.         }
  5973.     });
  5974.  
  5975.     FormValidation.Validator.integer = {
  5976.         enableByHtml5: function($field) {
  5977.             return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
  5978.         },
  5979.  
  5980.         /**
  5981.          * Return true if the input value is an integer
  5982.          *
  5983.          * @param {FormValidation.Base} validator The validator plugin instance
  5984.          * @param {jQuery} $field Field element
  5985.          * @param {Object} options Can consist of the following key:
  5986.          * - message: The invalid message
  5987.          * @returns {Boolean}
  5988.          */
  5989.         validate: function(validator, $field, options) {
  5990.             if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  5991.                return false;
  5992.             }
  5993.  
  5994.             var value = validator.getFieldValue($field, 'integer');
  5995.             if (value === '') {
  5996.                 return true;
  5997.             }
  5998.             return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  5999.         }
  6000.     };
  6001. }(jQuery));
  6002. ;(function($) {
  6003.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6004.         'en_US': {
  6005.             ip: {
  6006.                 'default': 'Please enter a valid IP address',
  6007.                 ipv4: 'Please enter a valid IPv4 address',
  6008.                 ipv6: 'Please enter a valid IPv6 address'
  6009.             }
  6010.         }
  6011.     });
  6012.  
  6013.     FormValidation.Validator.ip = {
  6014.         html5Attributes: {
  6015.             message: 'message',
  6016.             ipv4: 'ipv4',
  6017.             ipv6: 'ipv6'
  6018.         },
  6019.  
  6020.         /**
  6021.          * Return true if the input value is a IP address.
  6022.          *
  6023.          * @param {FormValidation.Base} validator The validator plugin instance
  6024.          * @param {jQuery} $field Field element
  6025.          * @param {Object} options Can consist of the following keys:
  6026.          * - ipv4: Enable IPv4 validator, default to true
  6027.          * - ipv6: Enable IPv6 validator, default to true
  6028.          * - message: The invalid message
  6029.          * @returns {Boolean|Object}
  6030.          */
  6031.         validate: function(validator, $field, options) {
  6032.             var value = validator.getFieldValue($field, 'ip');
  6033.             if (value === '') {
  6034.                 return true;
  6035.             }
  6036.             options = $.extend({}, { ipv4: true, ipv6: true }, options);
  6037.  
  6038.             var locale    = validator.getLocale(),
  6039.                 ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
  6040.                 ipv6Regex = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,
  6041.                 valid     = false,
  6042.                 message;
  6043.  
  6044.             switch (true) {
  6045.                 case (options.ipv4 && !options.ipv6):
  6046.                    valid   = ipv4Regex.test(value);
  6047.                     message = options.message || FormValidation.I18n[locale].ip.ipv4;
  6048.                     break;
  6049.  
  6050.                 case (!options.ipv4 && options.ipv6):
  6051.                    valid   = ipv6Regex.test(value);
  6052.                     message = options.message || FormValidation.I18n[locale].ip.ipv6;
  6053.                     break;
  6054.  
  6055.                 case (options.ipv4 && options.ipv6):
  6056.                /* falls through */
  6057.                default:
  6058.                    valid   = ipv4Regex.test(value) || ipv6Regex.test(value);
  6059.                     message = options.message || FormValidation.I18n[locale].ip['default'];
  6060.                     break;
  6061.             }
  6062.  
  6063.             return {
  6064.                 valid: valid,
  6065.                 message: message
  6066.             };
  6067.         }
  6068.     };
  6069. }(jQuery));
  6070. ;(function($) {
  6071.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6072.         'en_US': {
  6073.             isbn: {
  6074.                 'default': 'Please enter a valid ISBN number'
  6075.             }
  6076.         }
  6077.     });
  6078.  
  6079.     FormValidation.Validator.isbn = {
  6080.         /**
  6081.          * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  6082.          * Examples:
  6083.          * - Valid:
  6084.          * ISBN 10: 99921-58-10-7, 9971-5-0210-0, 960-425-059-0, 80-902734-1-6, 85-359-0277-5, 1-84356-028-3, 0-684-84328-5, 0-8044-2957-X, 0-85131-041-9, 0-943396-04-2, 0-9752298-0-X
  6085.          * ISBN 13: 978-0-306-40615-7
  6086.          * - Invalid:
  6087.          * ISBN 10: 99921-58-10-6
  6088.          * ISBN 13: 978-0-306-40615-6
  6089.          *
  6090.          * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  6091.          * @param {FormValidation.Base} validator The validator plugin instance
  6092.          * @param {jQuery} $field Field element
  6093.          * @param {Object} [options] Can consist of the following keys:
  6094.          * - message: The invalid message
  6095.          * @returns {Boolean}
  6096.          */
  6097.         validate: function(validator, $field, options) {
  6098.             var value = validator.getFieldValue($field, 'isbn');
  6099.             if (value === '') {
  6100.                 return true;
  6101.             }
  6102.  
  6103.             // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  6104.             // Groups are separated by a hyphen or a space
  6105.             var type;
  6106.             switch (true) {
  6107.                 case /^\d{9}[\dX]$/.test(value):
  6108.                 case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  6109.                case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  6110.                    type = 'ISBN10';
  6111.                     break;
  6112.                 case /^(978|979)\d{9}[\dX]$/.test(value):
  6113.                 case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  6114.                case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  6115.                    type = 'ISBN13';
  6116.                     break;
  6117.                 default:
  6118.                     return false;
  6119.             }
  6120.  
  6121.             // Replace all special characters except digits and X
  6122.             value = value.replace(/[^0-9X]/gi, '');
  6123.             var chars  = value.split(''),
  6124.                 length = chars.length,
  6125.                 sum    = 0,
  6126.                 i,
  6127.                 checksum;
  6128.  
  6129.             switch (type) {
  6130.                 case 'ISBN10':
  6131.                     sum = 0;
  6132.                     for (i = 0; i < length - 1; i++) {
  6133.                        sum += parseInt(chars[i], 10) * (10 - i);
  6134.                    }
  6135.                    checksum = 11 - (sum % 11);
  6136.                    if (checksum === 11) {
  6137.                        checksum = 0;
  6138.                    } else if (checksum === 10) {
  6139.                        checksum = 'X';
  6140.                    }
  6141.                    return (checksum + '' === chars[length - 1]);
  6142.  
  6143.                case 'ISBN13':
  6144.                    sum = 0;
  6145.                    for (i = 0; i < length - 1; i++) {
  6146.                        sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  6147.                    }
  6148.                    checksum = 10 - (sum % 10);
  6149.                    if (checksum === 10) {
  6150.                        checksum = '0';
  6151.                    }
  6152.                    return (checksum + '' === chars[length - 1]);
  6153.  
  6154.                default:
  6155.                    return false;
  6156.            }
  6157.        }
  6158.    };
  6159. }(jQuery));
  6160. ;(function($) {
  6161.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6162.        'en_US': {
  6163.            isin: {
  6164.                'default': 'Please enter a valid ISIN number'
  6165.            }
  6166.        }
  6167.    });
  6168.  
  6169.    FormValidation.Validator.isin = {
  6170.        // Available country codes
  6171.        // See http://isin.net/country-codes/
  6172.        COUNTRY_CODES: 'AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW',
  6173.  
  6174.        /**
  6175.         * Validate an ISIN (International Securities Identification Number)
  6176.         * Examples:
  6177.         * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  6178.         * - Invalid: US0378331004, AA0000XVGZA3
  6179.         *
  6180.         * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  6181.         * @param {FormValidation.Base} validator The validator plugin instance
  6182.         * @param {jQuery} $field Field element
  6183.         * @param {Object} options Can consist of the following keys:
  6184.         * - message: The invalid message
  6185.         * @returns {Boolean}
  6186.         */
  6187.        validate: function(validator, $field, options) {
  6188.            var value = validator.getFieldValue($field, 'isin');
  6189.            if (value === '') {
  6190.                return true;
  6191.            }
  6192.  
  6193.            value = value.toUpperCase();
  6194.            var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  6195.            if (!regex.test(value)) {
  6196.                return false;
  6197.            }
  6198.  
  6199.            var converted = '',
  6200.                length    = value.length;
  6201.            // Convert letters to number
  6202.            for (var i = 0; i < length - 1; i++) {
  6203.                var c = value.charCodeAt(i);
  6204.                converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  6205.             }
  6206.  
  6207.             var digits = '',
  6208.                 n      = converted.length,
  6209.                 group  = (n % 2 !== 0) ? 0 : 1;
  6210.             for (i = 0; i < n; i++) {
  6211.                digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  6212.            }
  6213.  
  6214.            var sum = 0;
  6215.            for (i = 0; i < digits.length; i++) {
  6216.                sum += parseInt(digits.charAt(i), 10);
  6217.            }
  6218.            sum = (10 - (sum % 10)) % 10;
  6219.            return sum + '' === value.charAt(length - 1);
  6220.        }
  6221.    };
  6222. }(jQuery));
  6223. ;(function($) {
  6224.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6225.        'en_US': {
  6226.            ismn: {
  6227.                'default': 'Please enter a valid ISMN number'
  6228.            }
  6229.        }
  6230.    });
  6231.  
  6232.    FormValidation.Validator.ismn = {
  6233.        /**
  6234.         * Validate ISMN (International Standard Music Number)
  6235.         * Examples:
  6236.         * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  6237.         * - Invalid: 9790060115614
  6238.         *
  6239.         * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  6240.         * @param {FormValidation.Base} validator The validator plugin instance
  6241.         * @param {jQuery} $field Field element
  6242.         * @param {Object} options Can consist of the following keys:
  6243.         * - message: The invalid message
  6244.         * @returns {Boolean}
  6245.         */
  6246.        validate: function(validator, $field, options) {
  6247.            var value = validator.getFieldValue($field, 'ismn');
  6248.            if (value === '') {
  6249.                return true;
  6250.            }
  6251.  
  6252.            // Groups are separated by a hyphen or a space
  6253.            var type;
  6254.            switch (true) {
  6255.                case /^M\d{9}$/.test(value):
  6256.                case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  6257.                case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  6258.                    type = 'ISMN10';
  6259.                    break;
  6260.                case /^9790\d{9}$/.test(value):
  6261.                case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  6262.                case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  6263.                    type = 'ISMN13';
  6264.                    break;
  6265.                default:
  6266.                    return false;
  6267.            }
  6268.  
  6269.            if ('ISMN10' === type) {
  6270.                value = '9790' + value.substr(1);
  6271.            }
  6272.  
  6273.            // Replace all special characters except digits
  6274.            value = value.replace(/[^0-9]/gi, '');
  6275.            var length = value.length,
  6276.                sum    = 0,
  6277.                weight = [1, 3];
  6278.            for (var i = 0; i < length - 1; i++) {
  6279.                sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  6280.            }
  6281.            sum = 10 - sum % 10;
  6282.            return (sum + '' === value.charAt(length - 1));
  6283.        }
  6284.    };
  6285. }(jQuery));
  6286. ;(function($) {
  6287.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6288.        'en_US': {
  6289.            issn: {
  6290.                'default': 'Please enter a valid ISSN number'
  6291.            }
  6292.        }
  6293.    });
  6294.  
  6295.    FormValidation.Validator.issn = {
  6296.        /**
  6297.         * Validate ISSN (International Standard Serial Number)
  6298.         * Examples:
  6299.         * - Valid: 0378-5955, 0024-9319, 0032-1478
  6300.         * - Invalid: 0032-147X
  6301.         *
  6302.         * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  6303.         * @param {FormValidation.Base} validator The validator plugin instance
  6304.         * @param {jQuery} $field Field element
  6305.         * @param {Object} options Can consist of the following keys:
  6306.         * - message: The invalid message
  6307.         * @returns {Boolean}
  6308.         */
  6309.        validate: function(validator, $field, options) {
  6310.            var value = validator.getFieldValue($field, 'issn');
  6311.            if (value === '') {
  6312.                return true;
  6313.            }
  6314.  
  6315.            // Groups are separated by a hyphen or a space
  6316.            if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  6317.                return false;
  6318.            }
  6319.  
  6320.            // Replace all special characters except digits and X
  6321.            value = value.replace(/[^0-9X]/gi, '');
  6322.            var chars  = value.split(''),
  6323.                length = chars.length,
  6324.                sum    = 0;
  6325.  
  6326.            if (chars[7] === 'X') {
  6327.                chars[7] = 10;
  6328.            }
  6329.            for (var i = 0; i < length; i++) {
  6330.                sum += parseInt(chars[i], 10) * (8 - i);
  6331.            }
  6332.            return (sum % 11 === 0);
  6333.        }
  6334.    };
  6335. }(jQuery));
  6336. ;(function($) {
  6337.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6338.        'en_US': {
  6339.            lessThan: {
  6340.                'default': 'Please enter a value less than or equal to %s',
  6341.                notInclusive: 'Please enter a value less than %s'
  6342.            }
  6343.        }
  6344.    });
  6345.  
  6346.    FormValidation.Validator.lessThan = {
  6347.        html5Attributes: {
  6348.            message: 'message',
  6349.            value: 'value',
  6350.            inclusive: 'inclusive'
  6351.        },
  6352.  
  6353.        enableByHtml5: function($field) {
  6354.            var type = $field.attr('type'),
  6355.                max  = $field.attr('max');
  6356.            if (max && type !== 'date') {
  6357.                return {
  6358.                    value: max
  6359.                };
  6360.            }
  6361.  
  6362.            return false;
  6363.        },
  6364.  
  6365.        /**
  6366.         * Return true if the input value is less than or equal to given number
  6367.         *
  6368.         * @param {FormValidation.Base} validator The validator plugin instance
  6369.         * @param {jQuery} $field Field element
  6370.         * @param {Object} options Can consist of the following keys:
  6371.         * - value: The number used to compare to. It can be
  6372.         *      - A number
  6373.         *      - Name of field which its value defines the number
  6374.         *      - Name of callback function that returns the number
  6375.         *      - A callback function that returns the number
  6376.         *
  6377.         * - inclusive [optional]: Can be true or false. Default is true
  6378.         * - message: The invalid message
  6379.         * @returns {Boolean|Object}
  6380.         */
  6381.        validate: function(validator, $field, options) {
  6382.            var value = validator.getFieldValue($field, 'lessThan');
  6383.            if (value === '') {
  6384.                return true;
  6385.            }
  6386.            
  6387.             value = this._format(value);
  6388.            if (!$.isNumeric(value)) {
  6389.                return false;
  6390.            }
  6391.  
  6392.            var locale         = validator.getLocale(),
  6393.                compareTo      = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
  6394.                compareToValue = this._format(compareTo);
  6395.  
  6396.            value = parseFloat(value);
  6397.            return (options.inclusive === true || options.inclusive === undefined)
  6398.                    ? {
  6399.                        valid: value <= compareToValue,
  6400.                        message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].lessThan['default'], compareTo)
  6401.                    }
  6402.                    : {
  6403.                        valid: value < compareToValue,
  6404.                        message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].lessThan.notInclusive, compareTo)
  6405.                    };
  6406.        },
  6407.  
  6408.        _format: function(value) {
  6409.            return (value + '').replace(',', '.');
  6410.        }
  6411.    };
  6412. }(jQuery));
  6413. ;(function($) {
  6414.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6415.        'en_US': {
  6416.            mac: {
  6417.                'default': 'Please enter a valid MAC address'
  6418.            }
  6419.        }
  6420.    });
  6421.  
  6422.    FormValidation.Validator.mac = {
  6423.        /**
  6424.         * Return true if the input value is a MAC address.
  6425.         *
  6426.         * @param {FormValidation.Base} validator The validator plugin instance
  6427.         * @param {jQuery} $field Field element
  6428.         * @param {Object} options Can consist of the following keys:
  6429.         * - message: The invalid message
  6430.         * @returns {Boolean}
  6431.         */
  6432.        validate: function(validator, $field, options) {
  6433.            var value = validator.getFieldValue($field, 'mac');
  6434.            if (value === '') {
  6435.                return true;
  6436.            }
  6437.  
  6438.            return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  6439.        }
  6440.    };
  6441. }(jQuery));
  6442. ;(function($) {
  6443.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6444.        'en_US': {
  6445.            meid: {
  6446.                'default': 'Please enter a valid MEID number'
  6447.            }
  6448.        }
  6449.    });
  6450.  
  6451.    FormValidation.Validator.meid = {
  6452.        /**
  6453.         * Validate MEID (Mobile Equipment Identifier)
  6454.         * Examples:
  6455.         * - Valid: 293608736500703710, 29360-87365-0070-3710, AF0123450ABCDE, AF-012345-0ABCDE
  6456.         * - Invalid: 2936087365007037101
  6457.         *
  6458.         * @see http://en.wikipedia.org/wiki/Mobile_equipment_identifier
  6459.         * @param {FormValidation.Base} validator The validator plugin instance
  6460.         * @param {jQuery} $field Field element
  6461.         * @param {Object} options Can consist of the following keys:
  6462.         * - message: The invalid message
  6463.         * @returns {Boolean}
  6464.         */
  6465.        validate: function(validator, $field, options) {
  6466.            var value = validator.getFieldValue($field, 'meid');
  6467.            if (value === '') {
  6468.                return true;
  6469.            }
  6470.  
  6471.            switch (true) {
  6472.                // 14 digit hex representation (no check digit)
  6473.                case /^[0-9A-F]{15}$/i.test(value):
  6474.                // 14 digit hex representation + dashes or spaces (no check digit)
  6475.                case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}[- ][0-9A-F]$/i.test(value):
  6476.                // 18 digit decimal representation (no check digit)
  6477.                case /^\d{19}$/.test(value):
  6478.                // 18 digit decimal representation + dashes or spaces (no check digit)
  6479.                case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}[- ]\d$/.test(value):
  6480.                    // Grab the check digit
  6481.                    var cd = value.charAt(value.length - 1);
  6482.  
  6483.                    // Strip any non-hex chars
  6484.                    value = value.replace(/[- ]/g, '');
  6485.  
  6486.                    // If it's all digits, luhn base 10 is used
  6487.                    if (value.match(/^\d*$/i)) {
  6488.                        return FormValidation.Helper.luhn(value);
  6489.                    }
  6490.                    // Strip the check digit
  6491.                    value = value.slice(0, -1);
  6492.                    // Get every other char, and double it
  6493.                    var cdCalc = '';
  6494.                    for (var i = 1; i <= 13; i += 2) {
  6495.                        cdCalc += (parseInt(value.charAt(i), 16) * 2).toString(16);
  6496.                    }
  6497.                    // Get the sum of each char in the string
  6498.                    var sum = 0;
  6499.                    for (i = 0; i < cdCalc.length; i++) {
  6500.                        sum += parseInt(cdCalc.charAt(i), 16);
  6501.                    }
  6502.                    // If the last digit of the calc is 0, the check digit is 0
  6503.                    return (sum % 10 === 0)
  6504.                            ? (cd === '0')
  6505.                            // Subtract it from the next highest 10s number (64 goes to 70) and subtract the sum
  6506.                            // Double it and turn it into a hex char
  6507.                            : (cd === ((Math.floor((sum + 10) / 10) * 10 - sum) * 2).toString(16));
  6508.                // 14 digit hex representation (no check digit)
  6509.                case /^[0-9A-F]{14}$/i.test(value):
  6510.                // 14 digit hex representation + dashes or spaces (no check digit)
  6511.                case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}$/i.test(value):
  6512.                // 18 digit decimal representation (no check digit)
  6513.                case /^\d{18}$/.test(value):
  6514.                // 18 digit decimal representation + dashes or spaces (no check digit)
  6515.                case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}$/.test(value):
  6516.                    return true;
  6517.                default:
  6518.                    return false;
  6519.            }
  6520.        }
  6521.    };
  6522. }(jQuery));
  6523. ;(function($) {
  6524.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6525.        'en_US': {
  6526.            notEmpty: {
  6527.                'default': 'Please enter a value'
  6528.            }
  6529.        }
  6530.    });
  6531.    FormValidation.Validator.notEmpty = {
  6532.        enableByHtml5: function($field) {
  6533.            var required = $field.attr('required') + '';
  6534.            return ('required' === required || 'true' === required);
  6535.        },
  6536.        /**
  6537.         * Check if input value is empty or not
  6538.         *
  6539.         * @param {FormValidation.Base} validator The validator plugin instance
  6540.         * @param {jQuery} $field Field element
  6541.         * @param {Object} options
  6542.         * @returns {Boolean}
  6543.         */
  6544.        validate: function(validator, $field, options) {
  6545.            var type = $field.attr('type');
  6546.            if ('radio' === type || 'checkbox' === type) {
  6547.                var ns = validator.getNamespace();
  6548.                return validator
  6549.                            .getFieldElements($field.attr('data-' + ns + '-field'))
  6550.                            .filter(':checked')
  6551.                            .length > 0;
  6552.             }
  6553.  
  6554.             if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  6555.                return true;
  6556.             }
  6557.  
  6558.             var value = validator.getFieldValue($field, 'notEmpty');
  6559.             return $.trim(value) !== '';
  6560.         }
  6561.     };
  6562. }(jQuery));
  6563. ;(function($) {
  6564.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6565.         'en_US': {
  6566.             numeric: {
  6567.                 'default': 'Please enter a valid float number'
  6568.             }
  6569.         }
  6570.     });
  6571.  
  6572.     FormValidation.Validator.numeric = {
  6573.         html5Attributes: {
  6574.             message: 'message',
  6575.             separator: 'separator'
  6576.         },
  6577.  
  6578.         enableByHtml5: function($field) {
  6579.             return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
  6580.         },
  6581.  
  6582.         /**
  6583.          * Validate decimal number
  6584.          *
  6585.          * @param {FormValidation.Base} validator The validator plugin instance
  6586.          * @param {jQuery} $field Field element
  6587.          * @param {Object} options Consist of key:
  6588.          * - message: The invalid message
  6589.          * - separator: The decimal separator. Can be "." (default), ","
  6590.          * @returns {Boolean}
  6591.          */
  6592.         validate: function(validator, $field, options) {
  6593.             if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  6594.                return false;
  6595.             }
  6596.  
  6597.             var value = validator.getFieldValue($field, 'numeric');
  6598.             if (value === '') {
  6599.                 return true;
  6600.             }
  6601.             var separator = options.separator || '.';
  6602.             if (separator !== '.') {
  6603.                 value = value.replace(separator, '.');
  6604.             }
  6605.  
  6606.             return !isNaN(parseFloat(value)) && isFinite(value);
  6607.         }
  6608.     };
  6609. }(jQuery));
  6610. ;(function($) {
  6611.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6612.         'en_US': {
  6613.             phone: {
  6614.                 'default': 'Please enter a valid phone number',
  6615.                 country: 'Please enter a valid phone number in %s',
  6616.                 countries: {
  6617.                     AE: 'United Arab Emirates',
  6618.                     BG: 'Bulgaria',
  6619.                     BR: 'Brazil',
  6620.                     CN: 'China',
  6621.                     CZ: 'Czech Republic',
  6622.                     DE: 'Germany',
  6623.                     DK: 'Denmark',
  6624.                     ES: 'Spain',
  6625.                     FR: 'France',
  6626.                     GB: 'United Kingdom',
  6627.                     IN: 'India',
  6628.                     MA: 'Morocco',
  6629.                     NL: 'Netherlands',
  6630.                     PK: 'Pakistan',
  6631.                     RO: 'Romania',
  6632.                     RU: 'Russia',
  6633.                     SK: 'Slovakia',
  6634.                     TH: 'Thailand',
  6635.                     US: 'USA',
  6636.                     VE: 'Venezuela'
  6637.                 }
  6638.             }
  6639.         }
  6640.     });
  6641.  
  6642.     FormValidation.Validator.phone = {
  6643.         html5Attributes: {
  6644.             message: 'message',
  6645.             country: 'country'
  6646.         },
  6647.  
  6648.         // The supported countries
  6649.         COUNTRY_CODES: ['AE', 'BG', 'BR', 'CN', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'IN', 'MA', 'NL', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
  6650.  
  6651.         /**
  6652.          * Return true if the input value contains a valid phone number for the country
  6653.          * selected in the options
  6654.          *
  6655.          * @param {FormValidation.Base} validator Validate plugin instance
  6656.          * @param {jQuery} $field Field element
  6657.          * @param {Object} options Consist of key:
  6658.          * - message: The invalid message
  6659.          * - country: The ISO-3166 country code. It can be
  6660.          *      - A country code
  6661.          *      - Name of field which its value defines the country code
  6662.          *      - Name of callback function that returns the country code
  6663.          *      - A callback function that returns the country code
  6664.          *
  6665.          * @returns {Boolean|Object}
  6666.          */
  6667.         validate: function(validator, $field, options) {
  6668.             var value = validator.getFieldValue($field, 'phone');
  6669.             if (value === '') {
  6670.                 return true;
  6671.             }
  6672.  
  6673.             var locale  = validator.getLocale(),
  6674.                 country = options.country;
  6675.             if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  6676.                 // Try to determine the country
  6677.                 country = validator.getDynamicOption($field, country);
  6678.             }
  6679.  
  6680.             if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  6681.                 return true;
  6682.             }
  6683.  
  6684.             var isValid = true;
  6685.             switch (country.toUpperCase()) {
  6686.                 case 'AE':
  6687.                     // http://regexr.com/39tak
  6688.                     value   = $.trim(value);
  6689.                     isValid = (/^(((\+|00)?971[\s\.-]?(\(0\)[\s\.-]?)?|0)(\(5(0|2|5|6)\)|5(0|2|5|6)|2|3|4|6|7|9)|60)([\s\.-]?[0-9]){7}$/).test(value);
  6690.                     break;
  6691.                    
  6692.                 case 'BG':
  6693.                     // https://regex101.com/r/yE6vN4/1
  6694.                     // See http://en.wikipedia.org/wiki/Telephone_numbers_in_Bulgaria
  6695.                     value   = value.replace(/\+|\s|-|\/|\(|\)/gi,'');
  6696.                     isValid = (/^(0|359|00)(((700|900)[0-9]{5}|((800)[0-9]{5}|(800)[0-9]{4}))|(87|88|89)([0-9]{7})|((2[0-9]{7})|(([3-9][0-9])(([0-9]{6})|([0-9]{5})))))$/).test(value);
  6697.                     break;
  6698.  
  6699.                 case 'BR':
  6700.                     // http://regexr.com/399m1
  6701.                     value   = $.trim(value);
  6702.                     isValid = (/^(([\d]{4}[-.\s]{1}[\d]{2,3}[-.\s]{1}[\d]{2}[-.\s]{1}[\d]{2})|([\d]{4}[-.\s]{1}[\d]{3}[-.\s]{1}[\d]{4})|((\(?\+?[0-9]{2}\)?\s?)?(\(?\d{2}\)?\s?)?\d{4,5}[-.\s]?\d{4}))$/).test(value);
  6703.                     break;
  6704.  
  6705.                 case 'CN':
  6706.                     // http://regexr.com/39dq4
  6707.                     value   = $.trim(value);
  6708.                     isValid = (/^((00|\+)?(86(?:-| )))?((\d{11})|(\d{3}[- ]{1}\d{4}[- ]{1}\d{4})|((\d{2,4}[- ]){1}(\d{7,8}|(\d{3,4}[- ]{1}\d{4}))([- ]{1}\d{1,4})?))$/).test(value);
  6709.                     break;
  6710.  
  6711.                 case 'CZ':
  6712.                     // http://regexr.com/39hhl
  6713.                     isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  6714.                     break;
  6715.  
  6716.                 case 'DE':
  6717.                     // http://regexr.com/39pkg
  6718.                     value   = $.trim(value);
  6719.                     isValid = (/^(((((((00|\+)49[ \-/]?)|0)[1-9][0-9]{1,4})[ \-/]?)|((((00|\+)49\()|\(0)[1-9][0-9]{1,4}\)[ \-/]?))[0-9]{1,7}([ \-/]?[0-9]{1,5})?)$/).test(value);
  6720.                     break;
  6721.  
  6722.                 case 'DK':
  6723.                     // Mathing DK phone numbers with country code in 1 of 3 formats and an
  6724.                     // 8 digit phone number not starting with a 0 or 1. Can have 1 space
  6725.                     // between each character except inside the country code.
  6726.                     // http://regex101.com/r/sS8fO4/1
  6727.                     value   = $.trim(value);
  6728.                     isValid = (/^(\+45|0045|\(45\))?\s?[2-9](\s?\d){7}$/).test(value);
  6729.                     break;
  6730.  
  6731.                 case 'ES':
  6732.                     // http://regex101.com/r/rB9mA9/1
  6733.                     // Telephone numbers in Spain go like this:
  6734.                     //     9: Landline phones and special prefixes.
  6735.                     //     6, 7: Mobile phones.
  6736.                     //     5: VoIP lines.
  6737.                     //     8: Premium-rate services.
  6738.                     // There are also special 5-digit and 3-digit numbers, but
  6739.                     // maybe it would be overkill to include them all.
  6740.                     value   = $.trim(value);
  6741.                     isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:5|6|7|8|9)(?:\d\D?){8}$/).test(value);
  6742.                     break;
  6743.  
  6744.                 case 'FR':
  6745.                     // http://regexr.com/39a2p
  6746.                     value   = $.trim(value);
  6747.                     isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
  6748.                     break;
  6749.  
  6750.                 case 'GB':
  6751.                     // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  6752.                     // http://regexr.com/38uhv
  6753.                     value   = $.trim(value);
  6754.                     isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
  6755.                     break;
  6756.            
  6757.                 case 'IN':
  6758.                     // http://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number
  6759.                     // http://regex101.com/r/qL6eZ5/1
  6760.                     // May begin with +91. Supports mobile and land line numbers
  6761.                     value   = $.trim(value);
  6762.                     isValid = (/((\+?)((0[ -]+)*|(91 )*)(\d{12}|\d{10}))|\d{5}([- ]*)\d{6}/).test(value);
  6763.                     break;
  6764.                    
  6765.                 case 'MA':
  6766.                     // http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
  6767.                     // http://regexr.com/399n8
  6768.                     value   = $.trim(value);
  6769.                     isValid = (/^(?:(?:(?:\+|00)212[\s]?(?:[\s]?\(0\)[\s]?)?)|0){1}(?:5[\s.-]?[2-3]|6[\s.-]?[13-9]){1}[0-9]{1}(?:[\s.-]?\d{2}){3}$/).test(value);
  6770.                     break;
  6771.                
  6772.                 case 'NL':
  6773.                     // https://regex101.com/r/mX2wJ2/1
  6774.                     value   = $.trim(value);
  6775.                     isValid = (/(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/).test(value);
  6776.                     break;
  6777.                
  6778.                 case 'PK':
  6779.                     // http://regex101.com/r/yH8aV9/2
  6780.                     value   = $.trim(value);
  6781.                     isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
  6782.                     break;
  6783.  
  6784.                 case 'RO':
  6785.                     // All mobile network and land line
  6786.                     // http://regexr.com/39fv1
  6787.                     isValid = (/^(\+4|)?(07[0-8]{1}[0-9]{1}|02[0-9]{2}|03[0-9]{2}){1}?(\s|\.|\-)?([0-9]{3}(\s|\.|\-|)){2}$/g).test(value);
  6788.                     break;
  6789.  
  6790.                 case 'RU':
  6791.                     // http://regex101.com/r/gW7yT5/5
  6792.                     isValid = (/^((8|\+7|007)[\-\.\/ ]?)?([\(\/\.]?\d{3}[\)\/\.]?[\-\.\/ ]?)?[\d\-\.\/ ]{7,10}$/g).test(value);
  6793.                     break;
  6794.  
  6795.                 case 'SK':
  6796.                     // http://regexr.com/3a95f
  6797.                     isValid = /^(((00)([- ]?)|\+)(421)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  6798.                     break;
  6799.  
  6800.                 case 'TH':
  6801.                     // http://regex101.com/r/vM5mZ4/2
  6802.                     isValid = (/^0\(?([6|8-9]{2})*-([0-9]{3})*-([0-9]{4})$/).test(value);
  6803.                     break;
  6804.  
  6805.                 case 'VE':
  6806.                     // http://regex101.com/r/eM2yY0/6
  6807.                     value   = $.trim(value);
  6808.                     isValid = (/^0(?:2(?:12|4[0-9]|5[1-9]|6[0-9]|7[0-8]|8[1-35-8]|9[1-5]|3[45789])|4(?:1[246]|2[46]))\d{7}$/).test(value);
  6809.                     break;
  6810.  
  6811.                 case 'US':
  6812.                 /* falls through */
  6813.                 default:
  6814.                     // Make sure US phone numbers have 10 digits
  6815.                     // May start with 1, +1, or 1-; should discard
  6816.                     // Area code may be delimited with (), & sections may be delimited with . or -
  6817.                    // http://regexr.com/38mqi
  6818.                    isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
  6819.                     break;
  6820.             }
  6821.  
  6822.             return {
  6823.                 valid: isValid,
  6824.                 message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].phone.country, FormValidation.I18n[locale].phone.countries[country])
  6825.             };
  6826.         }
  6827.     };
  6828. }(jQuery));
  6829. ;(function($) {
  6830.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6831.         'en_US': {
  6832.             regexp: {
  6833.                 'default': 'Please enter a value matching the pattern'
  6834.             }
  6835.         }
  6836.     });
  6837.  
  6838.     FormValidation.Validator.regexp = {
  6839.         html5Attributes: {
  6840.             message: 'message',
  6841.             regexp: 'regexp'
  6842.         },
  6843.  
  6844.         enableByHtml5: function($field) {
  6845.             var pattern = $field.attr('pattern');
  6846.             if (pattern) {
  6847.                 return {
  6848.                     regexp: pattern
  6849.                 };
  6850.             }
  6851.  
  6852.             return false;
  6853.         },
  6854.  
  6855.         /**
  6856.          * Check if the element value matches given regular expression
  6857.          *
  6858.          * @param {FormValidation.Base} validator The validator plugin instance
  6859.          * @param {jQuery} $field Field element
  6860.          * @param {Object} options Consists of the following key:
  6861.          * - regexp: The regular expression you need to check
  6862.          * @returns {Boolean}
  6863.          */
  6864.         validate: function(validator, $field, options) {
  6865.             var value = validator.getFieldValue($field, 'regexp');
  6866.             if (value === '') {
  6867.                 return true;
  6868.             }
  6869.  
  6870.             var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  6871.             return regexp.test(value);
  6872.         }
  6873.     };
  6874. }(jQuery));
  6875. ;(function($) {
  6876.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6877.         'en_US': {
  6878.             remote: {
  6879.                 'default': 'Please enter a valid value'
  6880.             }
  6881.         }
  6882.     });
  6883.  
  6884.     FormValidation.Validator.remote = {
  6885.         html5Attributes: {
  6886.             crossdomain: 'crossDomain',
  6887.             data: 'data',
  6888.             datatype: 'dataType',
  6889.             delay: 'delay',
  6890.             message: 'message',
  6891.             name: 'name',
  6892.             type: 'type',
  6893.             url: 'url',
  6894.             validkey: 'validKey'
  6895.         },
  6896.  
  6897.         /**
  6898.          * Destroy the timer when destroying the FormValidation (using validator.destroy() method)
  6899.          */
  6900.         destroy: function(validator, $field, options) {
  6901.             var ns    = validator.getNamespace(),
  6902.                 timer = $field.data(ns + '.remote.timer');
  6903.             if (timer) {
  6904.                 clearTimeout(timer);
  6905.                 $field.removeData(ns + '.remote.timer');
  6906.             }
  6907.         },
  6908.  
  6909.         /**
  6910.          * Request a remote server to check the input value
  6911.          *
  6912.          * @param {FormValidation.Base} validator Plugin instance
  6913.          * @param {jQuery} $field Field element
  6914.          * @param {Object} options Can consist of the following keys:
  6915.          * - crossDomain {Boolean} [optional]
  6916.          * - data {Object|Function} [optional]: By default, it will take the value
  6917.          *  {
  6918.          *      <fieldName>: <fieldValue>
  6919.          *  }
  6920.          * - dataType {String} [optional]: The type of data which is returned by remote server.
  6921.          * It can be json (default), text, script
  6922.          * - delay {Number} [optional]
  6923.          * - headers {String[]} [optional]: Additional headers
  6924.          * - message {String} [optional]: The invalid message
  6925.          * - name {String} [optional]: Override the field name for the request.
  6926.          * - type {String} [optional] Can be GET or POST (default)
  6927.          * - url {String|Function}
  6928.          * - validKey {String} [optional]: The valid key. It's "valid" by default
  6929.          * This is useful when connecting to external remote server or APIs provided by 3rd parties
  6930.          * @returns {Deferred}
  6931.          */
  6932.         validate: function(validator, $field, options) {
  6933.             var ns    = validator.getNamespace(),
  6934.                 value = validator.getFieldValue($field, 'remote'),
  6935.                 dfd   = new $.Deferred();
  6936.             if (value === '') {
  6937.                 dfd.resolve($field, 'remote', { valid: true });
  6938.                 return dfd;
  6939.             }
  6940.             var name     = $field.attr('data-' + ns + '-field'),
  6941.                 data     = options.data || {},
  6942.                 url      = options.url,
  6943.                 validKey = options.validKey || 'valid';
  6944.  
  6945.             // Support dynamic data
  6946.             if ('function' === typeof data) {
  6947.                 data = data.call(this, validator);
  6948.             }
  6949.  
  6950.             // Parse string data from HTML5 attribute
  6951.             if ('string' === typeof data) {
  6952.                 data = JSON.parse(data);
  6953.             }
  6954.  
  6955.             // Support dynamic url
  6956.             if ('function' === typeof url) {
  6957.                 url = url.call(this, validator);
  6958.             }
  6959.  
  6960.             data[options.name || name] = value;
  6961.  
  6962.             var ajaxOptions = {
  6963.                 data: data,
  6964.                 dataType: options.dataType || 'json',
  6965.                 headers: options.headers || {},
  6966.                 type: options.type || 'GET',
  6967.                 url: url
  6968.             };
  6969.             if (options.crossDomain !== null) {
  6970.                 ajaxOptions.crossDomain = (options.crossDomain === true || options.crossDomain === 'true');
  6971.             }
  6972.  
  6973.             function runCallback() {
  6974.                 var xhr = $.ajax(ajaxOptions);
  6975.  
  6976.                 xhr
  6977.                     .success(function(response) {
  6978.                         response.valid = response[validKey] === true || response[validKey] === 'true';
  6979.                         dfd.resolve($field, 'remote', response);
  6980.                     })
  6981.                     .error(function(response) {
  6982.                         dfd.resolve($field, 'remote', {
  6983.                             valid: false
  6984.                         });
  6985.                     });
  6986.  
  6987.                 dfd.fail(function() {
  6988.                     xhr.abort();
  6989.                 });
  6990.  
  6991.                 return dfd;
  6992.             }
  6993.            
  6994.             if (options.delay) {
  6995.                 // Since the form might have multiple fields with the same name
  6996.                 // I have to attach the timer to the field element
  6997.                 if ($field.data(ns + '.remote.timer')) {
  6998.                     clearTimeout($field.data(ns + '.remote.timer'));
  6999.                 }
  7000.  
  7001.                 $field.data(ns + '.remote.timer', setTimeout(runCallback, options.delay));
  7002.                 return dfd;
  7003.             } else {
  7004.                 return runCallback();
  7005.             }
  7006.         }
  7007.     };
  7008. }(jQuery));
  7009. ;(function($) {
  7010.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7011.         'en_US': {
  7012.             rtn: {
  7013.                 'default': 'Please enter a valid RTN number'
  7014.             }
  7015.         }
  7016.     });
  7017.  
  7018.     FormValidation.Validator.rtn = {
  7019.         /**
  7020.          * Validate a RTN (Routing transit number)
  7021.          * Examples:
  7022.          * - Valid: 021200025, 789456124
  7023.          *
  7024.          * @see http://en.wikipedia.org/wiki/Routing_transit_number
  7025.          * @param {FormValidation.Base} validator The validator plugin instance
  7026.          * @param {jQuery} $field Field element
  7027.          * @param {Object} options Can consist of the following keys:
  7028.          * - message: The invalid message
  7029.          * @returns {Boolean}
  7030.          */
  7031.         validate: function(validator, $field, options) {
  7032.             var value = validator.getFieldValue($field, 'rtn');
  7033.             if (value === '') {
  7034.                 return true;
  7035.             }
  7036.  
  7037.             if (!/^\d{9}$/.test(value)) {
  7038.                 return false;
  7039.             }
  7040.  
  7041.             var sum = 0;
  7042.             for (var i = 0; i < value.length; i += 3) {
  7043.                sum += parseInt(value.charAt(i),     10) * 3
  7044.                    +  parseInt(value.charAt(i + 1), 10) * 7
  7045.                    +  parseInt(value.charAt(i + 2), 10);
  7046.            }
  7047.            return (sum !== 0 && sum % 10 === 0);
  7048.        }
  7049.    };
  7050. }(jQuery));
  7051. ;(function($) {
  7052.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7053.        'en_US': {
  7054.            sedol: {
  7055.                'default': 'Please enter a valid SEDOL number'
  7056.            }
  7057.        }
  7058.    });
  7059.  
  7060.    FormValidation.Validator.sedol = {
  7061.        /**
  7062.         * Validate a SEDOL (Stock Exchange Daily Official List)
  7063.         * Examples:
  7064.         * - Valid: 0263494, B0WNLY7
  7065.         *
  7066.         * @see http://en.wikipedia.org/wiki/SEDOL
  7067.         * @param {FormValidation.Base} validator The validator plugin instance
  7068.         * @param {jQuery} $field Field element
  7069.         * @param {Object} options Can consist of the following keys:
  7070.         * - message: The invalid message
  7071.         * @returns {Boolean}
  7072.         */
  7073.        validate: function(validator, $field, options) {
  7074.            var value = validator.getFieldValue($field, 'sedol');
  7075.            if (value === '') {
  7076.                return true;
  7077.            }
  7078.  
  7079.            value = value.toUpperCase();
  7080.            if (!/^[0-9A-Z]{7}$/.test(value)) {
  7081.                return false;
  7082.            }
  7083.  
  7084.            var sum    = 0,
  7085.                weight = [1, 3, 1, 7, 3, 9, 1],
  7086.                length = value.length;
  7087.            for (var i = 0; i < length - 1; i++) {
  7088.                 sum += weight[i] * parseInt(value.charAt(i), 36);
  7089.             }
  7090.             sum = (10 - sum % 10) % 10;
  7091.            return sum + '' === value.charAt(length - 1);
  7092.        }
  7093.    };
  7094. }(jQuery));
  7095. ;(function($) {
  7096.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7097.         'en_US': {
  7098.             siren: {
  7099.                 'default': 'Please enter a valid SIREN number'
  7100.             }
  7101.         }
  7102.    });
  7103.  
  7104.     FormValidation.Validator.siren = {
  7105.         /**
  7106.          * Check if a string is a siren number
  7107.          *
  7108.          * @param {FormValidation.Base} validator The validator plugin instance
  7109.          * @param {jQuery} $field Field element
  7110.          * @param {Object} options Consist of key:
  7111.         * - message: The invalid message
  7112.          * @returns {Boolean}
  7113.          */
  7114.         validate: function(validator, $field, options) {
  7115.             var value = validator.getFieldValue($field, 'siren');
  7116.             if (value === '') {
  7117.                 return true;
  7118.             }
  7119.  
  7120.            if (!/^\d{9}$/.test(value)) {
  7121.                return false;
  7122.            }
  7123.            return FormValidation.Helper.luhn(value);
  7124.         }
  7125.     };
  7126. }(jQuery));
  7127. ;(function($) {
  7128.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7129.         'en_US': {
  7130.             siret: {
  7131.                 'default': 'Please enter a valid SIRET number'
  7132.             }
  7133.         }
  7134.    });
  7135.  
  7136.     FormValidation.Validator.siret = {
  7137.        /**
  7138.         * Check if a string is a siret number
  7139.         *
  7140.         * @param {FormValidation.Base} validator The validator plugin instance
  7141.         * @param {jQuery} $field Field element
  7142.         * @param {Object} options Consist of key:
  7143.         * - message: The invalid message
  7144.         * @returns {Boolean}
  7145.         */
  7146.         validate: function(validator, $field, options) {
  7147.             var value = validator.getFieldValue($field, 'siret');
  7148.             if (value === '') {
  7149.                 return true;
  7150.             }
  7151.  
  7152.             var sum    = 0,
  7153.                length = value.length,
  7154.                tmp;
  7155.             for (var i = 0; i < length; i++) {
  7156.                tmp = parseInt(value.charAt(i), 10);
  7157.                 if ((i % 2) === 0) {
  7158.                     tmp = tmp * 2;
  7159.                     if (tmp > 9) {
  7160.                         tmp -= 9;
  7161.                     }
  7162.                 }
  7163.                 sum += tmp;
  7164.             }
  7165.             return (sum % 10 === 0);
  7166.         }
  7167.     };
  7168. }(jQuery));
  7169. ;(function($) {
  7170.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7171.         'en_US': {
  7172.             step: {
  7173.                 'default': 'Please enter a valid step of %s'
  7174.             }
  7175.         }
  7176.     });
  7177.  
  7178.     FormValidation.Validator.step = {
  7179.         html5Attributes: {
  7180.             message: 'message',
  7181.             base: 'baseValue',
  7182.             step: 'step'
  7183.         },
  7184.  
  7185.         /**
  7186.          * Return true if the input value is valid step one
  7187.          *
  7188.          * @param {FormValidation.Base} validator The validator plugin instance
  7189.          * @param {jQuery} $field Field element
  7190.          * @param {Object} options Can consist of the following keys:
  7191.          * - baseValue: The base value
  7192.          * - step: The step
  7193.          * - message: The invalid message
  7194.          * @returns {Boolean|Object}
  7195.          */
  7196.         validate: function(validator, $field, options) {
  7197.             var value = validator.getFieldValue($field, 'step');
  7198.             if (value === '') {
  7199.                 return true;
  7200.             }
  7201.  
  7202.             options = $.extend({}, { baseValue: 0, step: 1 }, options);
  7203.             value   = parseFloat(value);
  7204.             if (!$.isNumeric(value)) {
  7205.                 return false;
  7206.             }
  7207.  
  7208.             var round = function(x, precision) {
  7209.                     var m = Math.pow(10, precision);
  7210.                     x = x * m;
  7211.                     var sign   = (x > 0) | -(x < 0),
  7212.                        isHalf = (x % 1 === 0.5 * sign);
  7213.                    if (isHalf) {
  7214.                        return (Math.floor(x) + (sign > 0)) / m;
  7215.                     } else {
  7216.                         return Math.round(x) / m;
  7217.                     }
  7218.                 },
  7219.                 floatMod = function(x, y) {
  7220.                     if (y === 0.0) {
  7221.                         return 1.0;
  7222.                     }
  7223.                     var dotX      = (x + '').split('.'),
  7224.                         dotY      = (y + '').split('.'),
  7225.                         precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  7226.                     return round(x - y * Math.floor(x / y), precision);
  7227.                 };
  7228.  
  7229.             var locale = validator.getLocale(),
  7230.                 mod    = floatMod(value - options.baseValue, options.step);
  7231.             return {
  7232.                 valid: mod === 0.0 || mod === options.step,
  7233.                 message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].step['default'], [options.step])
  7234.             };
  7235.         }
  7236.     };
  7237. }(jQuery));
  7238. ;(function($) {
  7239.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7240.         'en_US': {
  7241.             stringCase: {
  7242.                 'default': 'Please enter only lowercase characters',
  7243.                 upper: 'Please enter only uppercase characters'
  7244.             }
  7245.         }
  7246.     });
  7247.  
  7248.     FormValidation.Validator.stringCase = {
  7249.         html5Attributes: {
  7250.             message: 'message',
  7251.             'case': 'case'
  7252.         },
  7253.  
  7254.         /**
  7255.          * Check if a string is a lower or upper case one
  7256.          *
  7257.          * @param {FormValidation.Base} validator The validator plugin instance
  7258.          * @param {jQuery} $field Field element
  7259.          * @param {Object} options Consist of key:
  7260.          * - message: The invalid message
  7261.          * - case: Can be 'lower' (default) or 'upper'
  7262.          * @returns {Object}
  7263.          */
  7264.         validate: function(validator, $field, options) {
  7265.             var value = validator.getFieldValue($field, 'stringCase');
  7266.             if (value === '') {
  7267.                 return true;
  7268.             }
  7269.  
  7270.             var locale     = validator.getLocale(),
  7271.                 stringCase = (options['case'] || 'lower').toLowerCase();
  7272.             return {
  7273.                 valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
  7274.                 message: options.message || (('upper' === stringCase) ? FormValidation.I18n[locale].stringCase.upper : FormValidation.I18n[locale].stringCase['default'])
  7275.             };
  7276.         }
  7277.     };
  7278. }(jQuery));
  7279. ;(function($) {
  7280.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7281.         'en_US': {
  7282.             stringLength: {
  7283.                 'default': 'Please enter a value with valid length',
  7284.                 less: 'Please enter less than %s characters',
  7285.                 more: 'Please enter more than %s characters',
  7286.                 between: 'Please enter value between %s and %s characters long'
  7287.             }
  7288.         }
  7289.     });
  7290.  
  7291.     FormValidation.Validator.stringLength = {
  7292.         html5Attributes: {
  7293.             message: 'message',
  7294.             min: 'min',
  7295.             max: 'max',
  7296.             trim: 'trim',
  7297.             utf8bytes: 'utf8Bytes'
  7298.         },
  7299.  
  7300.         enableByHtml5: function($field) {
  7301.             var options   = {},
  7302.                 maxLength = $field.attr('maxlength'),
  7303.                 minLength = $field.attr('minlength');
  7304.             if (maxLength) {
  7305.                 options.max = parseInt(maxLength, 10);
  7306.             }
  7307.             if (minLength) {
  7308.                 options.min = parseInt(minLength, 10);
  7309.             }
  7310.  
  7311.             return $.isEmptyObject(options) ? false : options;
  7312.         },
  7313.  
  7314.         /**
  7315.          * Check if the length of element value is less or more than given number
  7316.          *
  7317.          * @param {FormValidation.Base} validator The validator plugin instance
  7318.          * @param {jQuery} $field Field element
  7319.          * @param {Object} options Consists of following keys:
  7320.          * - min
  7321.          * - max
  7322.          * At least one of two keys is required
  7323.          * The min, max keys define the number which the field value compares to. min, max can be
  7324.          *      - A number
  7325.          *      - Name of field which its value defines the number
  7326.          *      - Name of callback function that returns the number
  7327.          *      - A callback function that returns the number
  7328.          *
  7329.          * - message: The invalid message
  7330.          * - trim: Indicate the length will be calculated after trimming the value or not. It is false, by default
  7331.          * - utf8bytes: Evaluate string length in UTF-8 bytes, default to false
  7332.          * @returns {Object}
  7333.          */
  7334.         validate: function(validator, $field, options) {
  7335.             var value = validator.getFieldValue($field, 'stringLength');
  7336.             if (options.trim === true || options.trim === 'true') {
  7337.                 value = $.trim(value);
  7338.             }
  7339.  
  7340.             if (value === '') {
  7341.                 return true;
  7342.             }
  7343.  
  7344.             var locale     = validator.getLocale(),
  7345.                 min        = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  7346.                 max        = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  7347.                 // Credit to http://stackoverflow.com/a/23329386 (@lovasoa) for UTF-8 byte length code
  7348.                 utf8Length = function(str) {
  7349.                                  var s = str.length;
  7350.                                  for (var i = str.length - 1; i >= 0; i--) {
  7351.                                      var code = str.charCodeAt(i);
  7352.                                      if (code > 0x7f && code <= 0x7ff) {
  7353.                                         s++;
  7354.                                      } else if (code > 0x7ff && code <= 0xffff) {
  7355.                                         s += 2;
  7356.                                      }
  7357.                                      if (code >= 0xDC00 && code <= 0xDFFF) {
  7358.                                         i--;
  7359.                                      }
  7360.                                  }
  7361.                                  return s;
  7362.                              },
  7363.                 length     = options.utf8Bytes ? utf8Length(value) : value.length,
  7364.                 isValid    = true,
  7365.                 message    = options.message || FormValidation.I18n[locale].stringLength['default'];
  7366.  
  7367.             if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
  7368.                isValid = false;
  7369.             }
  7370.  
  7371.             switch (true) {
  7372.                 case (!!min && !!max):
  7373.                    message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
  7374.                     break;
  7375.  
  7376.                 case (!!min):
  7377.                     message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.more, parseInt(min, 10));
  7378.                     break;
  7379.  
  7380.                 case (!!max):
  7381.                     message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.less, parseInt(max, 10));
  7382.                     break;
  7383.  
  7384.                 default:
  7385.                     break;
  7386.             }
  7387.  
  7388.             return {
  7389.                 valid: isValid,
  7390.                 message: message
  7391.             };
  7392.         }
  7393.     };
  7394. }(jQuery));
  7395. ;(function($) {
  7396.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7397.         'en_US': {
  7398.             uri: {
  7399.                 'default': 'Please enter a valid URI'
  7400.             }
  7401.         }
  7402.     });
  7403.  
  7404.     FormValidation.Validator.uri = {
  7405.         html5Attributes: {
  7406.             message: 'message',
  7407.             allowlocal: 'allowLocal',
  7408.             allowemptyprotocol: 'allowEmptyProtocol',
  7409.             protocol: 'protocol'
  7410.         },
  7411.  
  7412.         enableByHtml5: function($field) {
  7413.             return ('url' === $field.attr('type'));
  7414.         },
  7415.  
  7416.         /**
  7417.          * Return true if the input value is a valid URL
  7418.          *
  7419.          * @param {FormValidation.Base} validator The validator plugin instance
  7420.          * @param {jQuery} $field Field element
  7421.          * @param {Object} options
  7422.          * - message: The error message
  7423.          * - allowLocal: Allow the private and local network IP. Default to false
  7424.          * - allowEmptyProtocol: Allow the URI without protocol. Default to false
  7425.          * - protocol: The protocols, separated by a comma. Default to "http, https, ftp"
  7426.          * @returns {Boolean}
  7427.          */
  7428.         validate: function(validator, $field, options) {
  7429.             var value = validator.getFieldValue($field, 'uri');
  7430.             if (value === '') {
  7431.                 return true;
  7432.             }
  7433.  
  7434.             // Credit to https://gist.github.com/dperini/729294
  7435.             //
  7436.             // Regular Expression for URL validation
  7437.             //
  7438.             // Author: Diego Perini
  7439.             // Updated: 2010/12/05
  7440.             //
  7441.             // the regular expression composed & commented
  7442.            // could be easily tweaked for RFC compliance,
  7443.            // it was expressly modified to fit & satisfy
  7444.            // these test for an URL shortener:
  7445.            //
  7446.            //   http://mathiasbynens.be/demo/url-regex
  7447.            //
  7448.            // Notes on possible differences from a standard/generic validation:
  7449.            //
  7450.            // - utf-8 char class take in consideration the full Unicode range
  7451.            // - TLDs are mandatory unless `allowLocal` is true
  7452.            // - protocols have been restricted to ftp, http and https only as requested
  7453.            //
  7454.            // Changes:
  7455.            //
  7456.            // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  7457.            //   first and last IP address of each class is considered invalid
  7458.            //   (since they are broadcast/network addresses)
  7459.            //
  7460.            // - Added exclusion of private, reserved and/or local networks ranges
  7461.            //   unless `allowLocal` is true
  7462.            //
  7463.            // - Added possibility of choosing a custom protocol
  7464.            //
  7465.            // - Add option to validate without protocol
  7466.            //
  7467.            var allowLocal         = options.allowLocal === true || options.allowLocal === 'true',
  7468.                allowEmptyProtocol = options.allowEmptyProtocol === true || options.allowEmptyProtocol === 'true',
  7469.                protocol           = (options.protocol || 'http, https, ftp').split(',').join('|').replace(/\s/g, ''),
  7470.                urlExp             = new RegExp(
  7471.                    "^" +
  7472.                    // protocol identifier
  7473.                    "(?:(?:" + protocol + ")://)" +
  7474.                    // allow empty protocol
  7475.                    (allowEmptyProtocol ? '?' : '') +
  7476.                    // user:pass authentication
  7477.                    "(?:\\S+(?::\\S*)?@)?" +
  7478.                    "(?:" +
  7479.                    // IP address exclusion
  7480.                    // private & local networks
  7481.                    (allowLocal
  7482.                        ? ''
  7483.                        : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  7484.                           "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  7485.                           "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  7486.                    // IP address dotted notation octets
  7487.                    // excludes loopback network 0.0.0.0
  7488.                    // excludes reserved space >= 224.0.0.0
  7489.                    // excludes network & broadcast addresses
  7490.                    // (first & last IP address of each class)
  7491.                    "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  7492.                    "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  7493.                    "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  7494.                    "|" +
  7495.                    // host name
  7496.                    "(?:(?:[a-z\\u00a1-\\uffff0-9]-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  7497.                    // domain name
  7498.                    "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-?)*[a-z\\u00a1-\\uffff0-9])*" +
  7499.                    // TLD identifier
  7500.                    "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  7501.                    // Allow intranet sites (no TLD) if `allowLocal` is true
  7502.                    (allowLocal ? '?' : '') +
  7503.                    ")" +
  7504.                    // port number
  7505.                    "(?::\\d{2,5})?" +
  7506.                    // resource path
  7507.                    "(?:/[^\\s]*)?" +
  7508.                    "$", "i"
  7509.                );
  7510.  
  7511.             return urlExp.test(value);
  7512.         }
  7513.     };
  7514. }(jQuery));
  7515. ;(function($) {
  7516.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7517.         'en_US': {
  7518.             uuid: {
  7519.                 'default': 'Please enter a valid UUID number',
  7520.                 version: 'Please enter a valid UUID version %s number'
  7521.             }
  7522.         }
  7523.     });
  7524.  
  7525.     FormValidation.Validator.uuid = {
  7526.         html5Attributes: {
  7527.             message: 'message',
  7528.             version: 'version'
  7529.         },
  7530.  
  7531.         /**
  7532.          * Return true if and only if the input value is a valid UUID string
  7533.          *
  7534.          * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  7535.          * @param {FormValidation.Base} validator The validator plugin instance
  7536.          * @param {jQuery} $field Field element
  7537.          * @param {Object} options Consist of key:
  7538.          * - message: The invalid message
  7539.          * - version: Can be 3, 4, 5, null
  7540.          * @returns {Boolean|Object}
  7541.          */
  7542.         validate: function(validator, $field, options) {
  7543.             var value = validator.getFieldValue($field, 'uuid');
  7544.             if (value === '') {
  7545.                 return true;
  7546.             }
  7547.  
  7548.             // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  7549.             var locale   = validator.getLocale(),
  7550.                 patterns = {
  7551.                     '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  7552.                     '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  7553.                     '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  7554.                     all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  7555.                 },
  7556.                 version = options.version ? (options.version + '') : 'all';
  7557.             return {
  7558.                 valid: (null === patterns[version]) ? true : patterns[version].test(value),
  7559.                 message: options.version
  7560.                             ? FormValidation.Helper.format(options.message || FormValidation.I18n[locale].uuid.version, options.version)
  7561.                             : (options.message || FormValidation.I18n[locale].uuid['default'])
  7562.             };
  7563.         }
  7564.     };
  7565. }(jQuery));
  7566. ;(function($) {
  7567.     FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  7568.         'en_US': {
  7569.             vat: {
  7570.                 'default': 'Please enter a valid VAT number',
  7571.                 country: 'Please enter a valid VAT number in %s',
  7572.                 countries: {
  7573.                     AT: 'Austria',
  7574.                     BE: 'Belgium',
  7575.                     BG: 'Bulgaria',
  7576.                     BR: 'Brazil',
  7577.                     CH: 'Switzerland',
  7578.                     CY: 'Cyprus',
  7579.                     CZ: 'Czech Republic',
  7580.                     DE: 'Germany',
  7581.                     DK: 'Denmark',
  7582.                     EE: 'Estonia',
  7583.                     ES: 'Spain',
  7584.                     FI: 'Finland',
  7585.                     FR: 'France',
  7586.                     GB: 'United Kingdom',
  7587.                     GR: 'Greek',
  7588.                     EL: 'Greek',
  7589.                     HU: 'Hungary',
  7590.                     HR: 'Croatia',
  7591.                     IE: 'Ireland',
  7592.                     IS: 'Iceland',
  7593.                     IT: 'Italy',
  7594.                     LT: 'Lithuania',
  7595.                     LU: 'Luxembourg',
  7596.                     LV: 'Latvia',
  7597.                     MT: 'Malta',
  7598.                     NL: 'Netherlands',
  7599.                     NO: 'Norway',
  7600.                     PL: 'Poland',
  7601.                     PT: 'Portugal',
  7602.                     RO: 'Romania',
  7603.                     RU: 'Russia',
  7604.                     RS: 'Serbia',
  7605.                     SE: 'Sweden',
  7606.                     SI: 'Slovenia',
  7607.                     SK: 'Slovakia',
  7608.                     VE: 'Venezuela',
  7609.                     ZA: 'South Africa'
  7610.                 }
  7611.             }
  7612.         }
  7613.     });
  7614.  
  7615.     FormValidation.Validator.vat = {
  7616.         html5Attributes: {
  7617.             message: 'message',
  7618.             country: 'country'
  7619.         },
  7620.  
  7621.         // Supported country codes
  7622.         COUNTRY_CODES: [
  7623.             'AT', 'BE', 'BG', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU',
  7624.             'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SE', 'SK', 'SI', 'VE',
  7625.             'ZA'
  7626.         ],
  7627.  
  7628.         /**
  7629.          * Validate an European VAT number
  7630.          *
  7631.          * @param {FormValidation.Base} validator The validator plugin instance
  7632.          * @param {jQuery} $field Field element
  7633.          * @param {Object} options Consist of key:
  7634.          * - message: The invalid message
  7635.          * - country: The ISO 3166-1 country code. It can be
  7636.          *      - One of country code defined in COUNTRY_CODES
  7637.          *      - Name of field which its value defines the country code
  7638.          *      - Name of callback function that returns the country code
  7639.          *      - A callback function that returns the country code
  7640.          * @returns {Boolean|Object}
  7641.          */
  7642.         validate: function(validator, $field, options) {
  7643.             var value = validator.getFieldValue($field, 'vat');
  7644.             if (value === '') {
  7645.                 return true;
  7646.             }
  7647.  
  7648.             var locale  = validator.getLocale(),
  7649.                 country = options.country;
  7650.             if (!country) {
  7651.                 country = value.substr(0, 2);
  7652.             } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  7653.                 // Determine the country code
  7654.                 country = validator.getDynamicOption($field, country);
  7655.             }
  7656.  
  7657.             if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  7658.                 return true;
  7659.             }
  7660.  
  7661.             var method  = ['_', country.toLowerCase()].join('');
  7662.             return this[method](value)
  7663.                 ? true
  7664.                 : {
  7665.                     valid: false,
  7666.                     message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].vat.country, FormValidation.I18n[locale].vat.countries[country.toUpperCase()])
  7667.                 };
  7668.         },
  7669.  
  7670.         // VAT validators
  7671.  
  7672.         /**
  7673.          * Validate Austrian VAT number
  7674.          * Example:
  7675.          * - Valid: ATU13585627
  7676.          * - Invalid: ATU13585626
  7677.          *
  7678.          * @param {String} value VAT number
  7679.          * @returns {Boolean}
  7680.          */
  7681.         _at: function(value) {
  7682.             if (/^ATU[0-9]{8}$/.test(value)) {
  7683.                 value = value.substr(2);
  7684.             }
  7685.             if (!/^U[0-9]{8}$/.test(value)) {
  7686.                 return false;
  7687.             }
  7688.  
  7689.             value = value.substr(1);
  7690.             var sum    = 0,
  7691.                 weight = [1, 2, 1, 2, 1, 2, 1],
  7692.                 temp   = 0;
  7693.             for (var i = 0; i < 7; i++) {
  7694.                temp = parseInt(value.charAt(i), 10) * weight[i];
  7695.                if (temp > 9) {
  7696.                     temp = Math.floor(temp / 10) + temp % 10;
  7697.                 }
  7698.                 sum += temp;
  7699.             }
  7700.  
  7701.             sum = 10 - (sum + 4) % 10;
  7702.             if (sum === 10) {
  7703.                 sum = 0;
  7704.             }
  7705.  
  7706.             return (sum + '' === value.substr(7, 1));
  7707.         },
  7708.  
  7709.         /**
  7710.          * Validate Belgian VAT number
  7711.          * Example:
  7712.          * - Valid: BE0428759497
  7713.          * - Invalid: BE431150351
  7714.          *
  7715.          * @param {String} value VAT number
  7716.          * @returns {Boolean}
  7717.          */
  7718.         _be: function(value) {
  7719.             if (/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  7720.                 value = value.substr(2);
  7721.             }
  7722.             if (!/^[0]{0,1}[0-9]{9}$/.test(value)) {
  7723.                 return false;
  7724.             }
  7725.  
  7726.             if (value.length === 9) {
  7727.                 value = '0' + value;
  7728.             }
  7729.             if (value.substr(1, 1) === '0') {
  7730.                 return false;
  7731.             }
  7732.  
  7733.             var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  7734.             return (sum % 97 === 0);
  7735.         },
  7736.  
  7737.         /**
  7738.          * Validate Bulgarian VAT number
  7739.          * Example:
  7740.          * - Valid: BG175074752,
  7741.          * BG7523169263, BG8032056031,
  7742.          * BG7542011030,
  7743.          * BG7111042925
  7744.          * - Invalid: BG175074753, BG7552A10004, BG7111042922
  7745.          *
  7746.          * @param {String} value VAT number
  7747.          * @returns {Boolean}
  7748.          */
  7749.         _bg: function(value) {
  7750.             if (/^BG[0-9]{9,10}$/.test(value)) {
  7751.                 value = value.substr(2);
  7752.             }
  7753.             if (!/^[0-9]{9,10}$/.test(value)) {
  7754.                 return false;
  7755.             }
  7756.  
  7757.             var sum = 0, i = 0;
  7758.  
  7759.             // Legal entities
  7760.             if (value.length === 9) {
  7761.                 for (i = 0; i < 8; i++) {
  7762.                    sum += parseInt(value.charAt(i), 10) * (i + 1);
  7763.                }
  7764.                sum = sum % 11;
  7765.                if (sum === 10) {
  7766.                    sum = 0;
  7767.                    for (i = 0; i < 8; i++) {
  7768.                        sum += parseInt(value.charAt(i), 10) * (i + 3);
  7769.                    }
  7770.                }
  7771.                sum = sum % 10;
  7772.                return (sum + '' === value.substr(8));
  7773.            }
  7774.            // Physical persons, foreigners and others
  7775.            else if (value.length === 10) {
  7776.                // Validate Bulgarian national identification numbers
  7777.                var egn = function(value) {
  7778.                        // Check the birth date
  7779.                        var year  = parseInt(value.substr(0, 2), 10) + 1900,
  7780.                            month = parseInt(value.substr(2, 2), 10),
  7781.                            day   = parseInt(value.substr(4, 2), 10);
  7782.                        if (month > 40) {
  7783.                             year += 100;
  7784.                             month -= 40;
  7785.                         } else if (month > 20) {
  7786.                             year -= 100;
  7787.                             month -= 20;
  7788.                         }
  7789.  
  7790.                         if (!FormValidation.Helper.date(year, month, day)) {
  7791.                             return false;
  7792.                         }
  7793.  
  7794.                         var sum    = 0,
  7795.                             weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  7796.                         for (var i = 0; i < 9; i++) {
  7797.                            sum += parseInt(value.charAt(i), 10) * weight[i];
  7798.                        }
  7799.                        sum = (sum % 11) % 10;
  7800.                        return (sum + '' === value.substr(9, 1));
  7801.                    },
  7802.                    // Validate Bulgarian personal number of a foreigner
  7803.                    pnf = function(value) {
  7804.                        var sum    = 0,
  7805.                            weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  7806.                        for (var i = 0; i < 9; i++) {
  7807.                            sum += parseInt(value.charAt(i), 10) * weight[i];
  7808.                        }
  7809.                        sum = sum % 10;
  7810.                        return (sum + '' === value.substr(9, 1));
  7811.                    },
  7812.                    // Finally, consider it as a VAT number
  7813.                    vat = function(value) {
  7814.                        var sum    = 0,
  7815.                            weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  7816.                        for (var i = 0; i < 9; i++) {
  7817.                            sum += parseInt(value.charAt(i), 10) * weight[i];
  7818.                        }
  7819.                        sum = 11 - sum % 11;
  7820.                        if (sum === 10) {
  7821.                            return false;
  7822.                        }
  7823.                        if (sum === 11) {
  7824.                            sum = 0;
  7825.                        }
  7826.                        return (sum + '' === value.substr(9, 1));
  7827.                    };
  7828.                return (egn(value) || pnf(value) || vat(value));
  7829.            }
  7830.  
  7831.            return false;
  7832.        },
  7833.        
  7834.        /**
  7835.         * Validate Brazilian VAT number (CNPJ)
  7836.         *
  7837.         * @param {String} value VAT number
  7838.         * @returns {Boolean}
  7839.         */
  7840.        _br: function(value) {
  7841.            if (value === '') {
  7842.                return true;
  7843.            }
  7844.            var cnpj = value.replace(/[^\d]+/g, '');
  7845.            if (cnpj === '' || cnpj.length !== 14) {
  7846.                return false;
  7847.            }
  7848.  
  7849.            // Remove invalids CNPJs
  7850.            if (cnpj === '00000000000000' || cnpj === '11111111111111' || cnpj === '22222222222222' ||
  7851.                cnpj === '33333333333333' || cnpj === '44444444444444' || cnpj === '55555555555555' ||
  7852.                cnpj === '66666666666666' || cnpj === '77777777777777' || cnpj === '88888888888888' ||
  7853.                cnpj === '99999999999999')
  7854.            {
  7855.                return false;
  7856.            }
  7857.  
  7858.            // Validate verification digits
  7859.            var length  = cnpj.length - 2,
  7860.                numbers = cnpj.substring(0, length),
  7861.                digits  = cnpj.substring(length),
  7862.                sum     = 0,
  7863.                pos     = length - 7;
  7864.  
  7865.            for (var i = length; i >= 1; i--) {
  7866.                 sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  7867.                 if (pos < 2) {
  7868.                    pos = 9;
  7869.                }
  7870.            }
  7871.  
  7872.            var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  7873.            if (result !== parseInt(digits.charAt(0), 10)) {
  7874.                return false;
  7875.            }
  7876.  
  7877.            length  = length + 1;
  7878.            numbers = cnpj.substring(0, length);
  7879.            sum     = 0;
  7880.            pos     = length - 7;
  7881.            for (i = length; i >= 1; i--) {
  7882.                 sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  7883.                 if (pos < 2) {
  7884.                    pos = 9;
  7885.                }
  7886.            }
  7887.  
  7888.            result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  7889.            return (result === parseInt(digits.charAt(1), 10));
  7890.        },
  7891.  
  7892.        /**
  7893.         * Validate Swiss VAT number
  7894.         *
  7895.         * @param {String} value VAT number
  7896.         * @returns {Boolean}
  7897.         */
  7898.        _ch: function(value) {
  7899.            if (/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  7900.                value = value.substr(2);
  7901.            }
  7902.            if (!/^E[0-9]{9}(MWST)?$/.test(value)) {
  7903.                return false;
  7904.            }
  7905.  
  7906.            value = value.substr(1);
  7907.            var sum    = 0,
  7908.                weight = [5, 4, 3, 2, 7, 6, 5, 4];
  7909.            for (var i = 0; i < 8; i++) {
  7910.                sum += parseInt(value.charAt(i), 10) * weight[i];
  7911.            }
  7912.  
  7913.            sum = 11 - sum % 11;
  7914.            if (sum === 10) {
  7915.                return false;
  7916.            }
  7917.            if (sum === 11) {
  7918.                sum = 0;
  7919.            }
  7920.  
  7921.            return (sum + '' === value.substr(8, 1));
  7922.        },
  7923.  
  7924.        /**
  7925.         * Validate Cypriot VAT number
  7926.         * Examples:
  7927.         * - Valid: CY10259033P
  7928.         * - Invalid: CY10259033Z
  7929.         *
  7930.         * @param {String} value VAT number
  7931.         * @returns {Boolean}
  7932.         */
  7933.        _cy: function(value) {
  7934.            if (/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  7935.                value = value.substr(2);
  7936.            }
  7937.            if (!/^[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  7938.                return false;
  7939.            }
  7940.  
  7941.            // Do not allow to start with "12"
  7942.            if (value.substr(0, 2) === '12') {
  7943.                return false;
  7944.            }
  7945.  
  7946.            // Extract the next digit and multiply by the counter.
  7947.            var sum         = 0,
  7948.                translation = {
  7949.                    '0': 1,  '1': 0,  '2': 5,  '3': 7,  '4': 9,
  7950.                    '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  7951.                };
  7952.            for (var i = 0; i < 8; i++) {
  7953.                var temp = parseInt(value.charAt(i), 10);
  7954.                if (i % 2 === 0) {
  7955.                    temp = translation[temp + ''];
  7956.                }
  7957.                sum += temp;
  7958.            }
  7959.  
  7960.            sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  7961.            return (sum + '' === value.substr(8, 1));
  7962.        },
  7963.  
  7964.        /**
  7965.         * Validate Czech Republic VAT number
  7966.         * Can be:
  7967.         * i) Legal entities (8 digit numbers)
  7968.         * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  7969.         * iii) Individuals without a RC (9 digit numbers beginning with 6)
  7970.         *
  7971.         * Examples:
  7972.         * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  7973.         * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  7974.         *
  7975.         * @param {String} value VAT number
  7976.         * @returns {Boolean}
  7977.         */
  7978.        _cz: function(value) {
  7979.            if (/^CZ[0-9]{8,10}$/.test(value)) {
  7980.                value = value.substr(2);
  7981.            }
  7982.            if (!/^[0-9]{8,10}$/.test(value)) {
  7983.                return false;
  7984.            }
  7985.  
  7986.            var sum = 0,
  7987.                i   = 0;
  7988.            if (value.length === 8) {
  7989.                // Do not allow to start with '9'
  7990.                if (value.charAt(0) + '' === '9') {
  7991.                    return false;
  7992.                }
  7993.  
  7994.                sum = 0;
  7995.                for (i = 0; i < 7; i++) {
  7996.                    sum += parseInt(value.charAt(i), 10) * (8 - i);
  7997.                }
  7998.                sum = 11 - sum % 11;
  7999.                if (sum === 10) {
  8000.                    sum = 0;
  8001.                }
  8002.                if (sum === 11) {
  8003.                    sum = 1;
  8004.                }
  8005.  
  8006.                return (sum + '' === value.substr(7, 1));
  8007.            } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  8008.                sum = 0;
  8009.                // Skip the first (which is 6)
  8010.                for (i = 0; i < 7; i++) {
  8011.                    sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  8012.                }
  8013.                sum = 11 - sum % 11;
  8014.                if (sum === 10) {
  8015.                    sum = 0;
  8016.                }
  8017.                if (sum === 11) {
  8018.                    sum = 1;
  8019.                }
  8020.                sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  8021.                return (sum + '' === value.substr(8, 1));
  8022.            } else if (value.length === 9 || value.length === 10) {
  8023.                // Validate Czech birth number (Rodné číslo), which is also national identifier
  8024.                var year  = 1900 + parseInt(value.substr(0, 2), 10),
  8025.                    month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  8026.                    day   = parseInt(value.substr(4, 2), 10);
  8027.                if (value.length === 9) {
  8028.                    if (year >= 1980) {
  8029.                         year -= 100;
  8030.                     }
  8031.                     if (year > 1953) {
  8032.                         return false;
  8033.                     }
  8034.                 } else if (year < 1954) {
  8035.                    year += 100;
  8036.                }
  8037.  
  8038.                if (!FormValidation.Helper.date(year, month, day)) {
  8039.                    return false;
  8040.                }
  8041.  
  8042.                // Check that the birth date is not in the future
  8043.                if (value.length === 10) {
  8044.                    var check = parseInt(value.substr(0, 9), 10) % 11;
  8045.                    if (year < 1985) {
  8046.                        check = check % 10;
  8047.                    }
  8048.                    return (check + '' === value.substr(9, 1));
  8049.                }
  8050.  
  8051.                return true;
  8052.            }
  8053.  
  8054.            return false;
  8055.        },
  8056.  
  8057.        /**
  8058.         * Validate German VAT number
  8059.         * Examples:
  8060.         * - Valid: DE136695976
  8061.         * - Invalid: DE136695978
  8062.         *
  8063.         * @param {String} value VAT number
  8064.         * @returns {Boolean}
  8065.         */
  8066.        _de: function(value) {
  8067.            if (/^DE[0-9]{9}$/.test(value)) {
  8068.                value = value.substr(2);
  8069.            }
  8070.            if (!/^[0-9]{9}$/.test(value)) {
  8071.                return false;
  8072.            }
  8073.  
  8074.            return FormValidation.Helper.mod11And10(value);
  8075.        },
  8076.  
  8077.        /**
  8078.         * Validate Danish VAT number
  8079.         * Example:
  8080.         * - Valid: DK13585628
  8081.         * - Invalid: DK13585627
  8082.         *
  8083.         * @param {String} value VAT number
  8084.         * @returns {Boolean}
  8085.         */
  8086.        _dk: function(value) {
  8087.            if (/^DK[0-9]{8}$/.test(value)) {
  8088.                value = value.substr(2);
  8089.            }
  8090.            if (!/^[0-9]{8}$/.test(value)) {
  8091.                return false;
  8092.            }
  8093.  
  8094.            var sum    = 0,
  8095.                weight = [2, 7, 6, 5, 4, 3, 2, 1];
  8096.            for (var i = 0; i < 8; i++) {
  8097.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8098.            }
  8099.  
  8100.            return (sum % 11 === 0);
  8101.        },
  8102.  
  8103.        /**
  8104.         * Validate Estonian VAT number
  8105.         * Examples:
  8106.         * - Valid: EE100931558, EE100594102
  8107.         * - Invalid: EE100594103
  8108.         *
  8109.         * @param {String} value VAT number
  8110.         * @returns {Boolean}
  8111.         */
  8112.        _ee: function(value) {
  8113.            if (/^EE[0-9]{9}$/.test(value)) {
  8114.                value = value.substr(2);
  8115.            }
  8116.            if (!/^[0-9]{9}$/.test(value)) {
  8117.                return false;
  8118.            }
  8119.  
  8120.            var sum    = 0,
  8121.                weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  8122.            for (var i = 0; i < 9; i++) {
  8123.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8124.            }
  8125.  
  8126.            return (sum % 10 === 0);
  8127.        },
  8128.  
  8129.        /**
  8130.         * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  8131.         * Can be:
  8132.         * i) DNI (Documento nacional de identidad), for Spaniards
  8133.         * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  8134.         * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  8135.         *
  8136.         * Examples:
  8137.         * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  8138.         * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  8139.         *
  8140.         * @param {String} value VAT number
  8141.         * @returns {Boolean}
  8142.         */
  8143.        _es: function(value) {
  8144.            if (/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  8145.                value = value.substr(2);
  8146.            }
  8147.            if (!/^[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  8148.                return false;
  8149.            }
  8150.  
  8151.            var dni = function(value) {
  8152.                    var check = parseInt(value.substr(0, 8), 10);
  8153.                    check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  8154.                    return (check + '' === value.substr(8, 1));
  8155.                },
  8156.                nie = function(value) {
  8157.                    var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  8158.                    check = parseInt(check, 10);
  8159.                    check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  8160.                    return (check + '' === value.substr(8, 1));
  8161.                },
  8162.                cif = function(value) {
  8163.                    var first = value.charAt(0), check;
  8164.                    if ('KLM'.indexOf(first) !== -1) {
  8165.                        // K: Spanish younger than 14 year old
  8166.                        // L: Spanish living outside Spain without DNI
  8167.                        // M: Granted the tax to foreigners who have no NIE
  8168.                        check = parseInt(value.substr(1, 8), 10);
  8169.                        check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  8170.                        return (check + '' === value.substr(8, 1));
  8171.                    } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  8172.                        var sum    = 0,
  8173.                            weight = [2, 1, 2, 1, 2, 1, 2],
  8174.                            temp   = 0;
  8175.  
  8176.                        for (var i = 0; i < 7; i++) {
  8177.                            temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  8178.                            if (temp > 9) {
  8179.                                 temp = Math.floor(temp / 10) + temp % 10;
  8180.                             }
  8181.                             sum += temp;
  8182.                         }
  8183.                         sum = 10 - sum % 10;
  8184.                         return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  8185.                     }
  8186.  
  8187.                     return false;
  8188.                 };
  8189.  
  8190.             var first = value.charAt(0);
  8191.             if (/^[0-9]$/.test(first)) {
  8192.                 return dni(value);
  8193.             } else if (/^[XYZ]$/.test(first)) {
  8194.                 return nie(value);
  8195.             } else {
  8196.                 return cif(value);
  8197.             }
  8198.         },
  8199.  
  8200.         /**
  8201.          * Validate Finnish VAT number
  8202.          * Examples:
  8203.          * - Valid: FI20774740
  8204.          * - Invalid: FI20774741
  8205.          *
  8206.          * @param {String} value VAT number
  8207.          * @returns {Boolean}
  8208.          */
  8209.         _fi: function(value) {
  8210.             if (/^FI[0-9]{8}$/.test(value)) {
  8211.                 value = value.substr(2);
  8212.             }
  8213.             if (!/^[0-9]{8}$/.test(value)) {
  8214.                 return false;
  8215.             }
  8216.  
  8217.             var sum    = 0,
  8218.                 weight = [7, 9, 10, 5, 8, 4, 2, 1];
  8219.             for (var i = 0; i < 8; i++) {
  8220.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8221.            }
  8222.  
  8223.            return (sum % 11 === 0);
  8224.        },
  8225.  
  8226.        /**
  8227.         * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  8228.         * It's constructed by a SIREN number, prefixed by two characters.
  8229.         *
  8230.         * Examples:
  8231.         * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  8232.         * - Invalid: FR84323140391
  8233.         *
  8234.         * @param {String} value VAT number
  8235.         * @returns {Boolean}
  8236.         */
  8237.        _fr: function(value) {
  8238.            if (/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  8239.                value = value.substr(2);
  8240.            }
  8241.            if (!/^[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  8242.                return false;
  8243.            }
  8244.            if (!FormValidation.Helper.luhn(value.substr(2))) {
  8245.                return false;
  8246.            }
  8247.            if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  8248.                // First two characters are digits
  8249.                return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  8250.            } else {
  8251.                // The first characters cann't be O and I
  8252.                var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  8253.                    check;
  8254.                // First one is digit
  8255.                if (/^[0-9]{1}$/.test(value.charAt(0))) {
  8256.                    check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  8257.                } else {
  8258.                    check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  8259.                }
  8260.                return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  8261.            }
  8262.        },
  8263.  
  8264.        /**
  8265.         * Validate United Kingdom VAT number
  8266.         * Example:
  8267.         * - Valid: GB980780684
  8268.         * - Invalid: GB802311781
  8269.         *
  8270.         * @param {String} value VAT number
  8271.         * @returns {Boolean}
  8272.         */
  8273.        _gb: function(value) {
  8274.            if (/^GB[0-9]{9}$/.test(value)             /* Standard */
  8275.                || /^GB[0-9]{12}$/.test(value)         /* Branches */
  8276.                || /^GBGD[0-9]{3}$/.test(value)        /* Government department */
  8277.                || /^GBHA[0-9]{3}$/.test(value)        /* Health authority */
  8278.                || /^GB(GD|HA)8888[0-9]{5}$/.test(value))
  8279.            {
  8280.                value = value.substr(2);
  8281.            }
  8282.            if (!/^[0-9]{9}$/.test(value)
  8283.                && !/^[0-9]{12}$/.test(value)
  8284.                && !/^GD[0-9]{3}$/.test(value)
  8285.                && !/^HA[0-9]{3}$/.test(value)
  8286.                && !/^(GD|HA)8888[0-9]{5}$/.test(value))
  8287.            {
  8288.                return false;
  8289.            }
  8290.  
  8291.            var length = value.length;
  8292.            if (length === 5) {
  8293.                var firstTwo  = value.substr(0, 2),
  8294.                    lastThree = parseInt(value.substr(2), 10);
  8295.                return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  8296.             } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  8297.                if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  8298.                    || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  8299.                {
  8300.                    return false;
  8301.                 }
  8302.                 return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  8303.             } else if (length === 9 || length === 12) {
  8304.                 var sum    = 0,
  8305.                     weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  8306.                 for (var i = 0; i < 9; i++) {
  8307.                    sum += parseInt(value.charAt(i), 10) * weight[i];
  8308.                }
  8309.                sum = sum % 97;
  8310.  
  8311.                if (parseInt(value.substr(0, 3), 10) >= 100) {
  8312.                     return (sum === 0 || sum === 42 || sum === 55);
  8313.                 } else {
  8314.                     return (sum === 0);
  8315.                 }
  8316.             }
  8317.  
  8318.             return true;
  8319.         },
  8320.  
  8321.         /**
  8322.          * Validate Greek VAT number
  8323.          * Examples:
  8324.          * - Valid: GR023456780, EL094259216
  8325.          * - Invalid: EL123456781
  8326.          *
  8327.          * @param {String} value VAT number
  8328.          * @returns {Boolean}
  8329.          */
  8330.         _gr: function(value) {
  8331.             if (/^(GR|EL)[0-9]{9}$/.test(value)) {
  8332.                 value = value.substr(2);
  8333.             }
  8334.             if (!/^[0-9]{9}$/.test(value)) {
  8335.                 return false;
  8336.             }
  8337.  
  8338.             if (value.length === 8) {
  8339.                 value = '0' + value;
  8340.             }
  8341.  
  8342.             var sum    = 0,
  8343.                 weight = [256, 128, 64, 32, 16, 8, 4, 2];
  8344.             for (var i = 0; i < 8; i++) {
  8345.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8346.            }
  8347.            sum = (sum % 11) % 10;
  8348.  
  8349.            return (sum + '' === value.substr(8, 1));
  8350.        },
  8351.  
  8352.        // EL is traditionally prefix of Greek VAT numbers
  8353.        _el: function(value) {
  8354.            return this._gr(value);
  8355.        },
  8356.  
  8357.        /**
  8358.         * Validate Hungarian VAT number
  8359.         * Examples:
  8360.         * - Valid: HU12892312
  8361.         * - Invalid: HU12892313
  8362.         *
  8363.         * @param {String} value VAT number
  8364.         * @returns {Boolean}
  8365.         */
  8366.        _hu: function(value) {
  8367.            if (/^HU[0-9]{8}$/.test(value)) {
  8368.                value = value.substr(2);
  8369.            }
  8370.            if (!/^[0-9]{8}$/.test(value)) {
  8371.                return false;
  8372.            }
  8373.  
  8374.            var sum    = 0,
  8375.                weight = [9, 7, 3, 1, 9, 7, 3, 1];
  8376.  
  8377.            for (var i = 0; i < 8; i++) {
  8378.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8379.            }
  8380.  
  8381.            return (sum % 10 === 0);
  8382.        },
  8383.  
  8384.        /**
  8385.         * Validate Croatian VAT number
  8386.         * Examples:
  8387.         * - Valid: HR33392005961
  8388.         * - Invalid: HR33392005962
  8389.         *
  8390.         * @param {String} value VAT number
  8391.         * @returns {Boolean}
  8392.         */
  8393.        _hr: function(value) {
  8394.            if (/^HR[0-9]{11}$/.test(value)) {
  8395.                value = value.substr(2);
  8396.            }
  8397.            if (!/^[0-9]{11}$/.test(value)) {
  8398.                return false;
  8399.            }
  8400.  
  8401.            return FormValidation.Helper.mod11And10(value);
  8402.        },
  8403.  
  8404.        /**
  8405.         * Validate Irish VAT number
  8406.         * Examples:
  8407.         * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  8408.         * - Invalid: IE8D79738J
  8409.         *
  8410.         * @param {String} value VAT number
  8411.         * @returns {Boolean}
  8412.         */
  8413.        _ie: function(value) {
  8414.            if (/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  8415.                value = value.substr(2);
  8416.            }
  8417.            if (!/^[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  8418.                return false;
  8419.            }
  8420.  
  8421.            var getCheckDigit = function(value) {
  8422.                while (value.length < 7) {
  8423.                    value = '0' + value;
  8424.                }
  8425.                var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  8426.                    sum      = 0;
  8427.                for (var i = 0; i < 7; i++) {
  8428.                    sum += parseInt(value.charAt(i), 10) * (8 - i);
  8429.                }
  8430.                sum += 9 * alphabet.indexOf(value.substr(7));
  8431.                return alphabet[sum % 23];
  8432.            };
  8433.  
  8434.            // The first 7 characters are digits
  8435.            if (/^[0-9]+$/.test(value.substr(0, 7))) {
  8436.                // New system
  8437.                return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  8438.            } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  8439.                // Old system
  8440.                return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  8441.            }
  8442.  
  8443.            return true;
  8444.        },
  8445.  
  8446.        /**
  8447.         * Validate Icelandic VAT (VSK) number
  8448.         * Examples:
  8449.         * - Valid: 12345, 123456
  8450.         * - Invalid: 1234567
  8451.         *
  8452.         * @params {String} value VAT number
  8453.         * @returns {Boolean}
  8454.         */
  8455.        _is: function(value) {
  8456.            if (/^IS[0-9]{5,6}$/.test(value)) {
  8457.                value = value.substr(2);
  8458.            }
  8459.            return /^[0-9]{5,6}$/.test(value);
  8460.        },
  8461.  
  8462.        /**
  8463.         * Validate Italian VAT number, which consists of 11 digits.
  8464.         * - First 7 digits are a company identifier
  8465.         * - Next 3 are the province of residence
  8466.         * - The last one is a check digit
  8467.         *
  8468.         * Examples:
  8469.         * - Valid: IT00743110157
  8470.         * - Invalid: IT00743110158
  8471.         *
  8472.         * @param {String} value VAT number
  8473.         * @returns {Boolean}
  8474.         */
  8475.        _it: function(value) {
  8476.            if (/^IT[0-9]{11}$/.test(value)) {
  8477.                value = value.substr(2);
  8478.            }
  8479.            if (!/^[0-9]{11}$/.test(value)) {
  8480.                return false;
  8481.            }
  8482.  
  8483.            if (parseInt(value.substr(0, 7), 10) === 0) {
  8484.                return false;
  8485.            }
  8486.  
  8487.            var lastThree = parseInt(value.substr(7, 3), 10);
  8488.            if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  8489.                return false;
  8490.             }
  8491.  
  8492.             return FormValidation.Helper.luhn(value);
  8493.         },
  8494.  
  8495.         /**
  8496.          * Validate Lithuanian VAT number
  8497.          * It can be:
  8498.          * - 9 digits, for legal entities
  8499.          * - 12 digits, for temporarily registered taxpayers
  8500.          *
  8501.          * Examples:
  8502.          * - Valid: LT119511515, LT100001919017, LT100004801610
  8503.          * - Invalid: LT100001919018
  8504.          *
  8505.          * @param {String} value VAT number
  8506.          * @returns {Boolean}
  8507.          */
  8508.         _lt: function(value) {
  8509.             if (/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  8510.                 value = value.substr(2);
  8511.             }
  8512.             if (!/^([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  8513.                 return false;
  8514.             }
  8515.  
  8516.             var length = value.length,
  8517.                 sum    = 0,
  8518.                 i;
  8519.             for (i = 0; i < length - 1; i++) {
  8520.                sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  8521.            }
  8522.            var check = sum % 11;
  8523.            if (check === 10) {
  8524.                sum = 0;
  8525.                for (i = 0; i < length - 1; i++) {
  8526.                    sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  8527.                }
  8528.            }
  8529.            check = check % 11 % 10;
  8530.            return (check + '' === value.charAt(length - 1));
  8531.        },
  8532.  
  8533.        /**
  8534.         * Validate Luxembourg VAT number
  8535.         * Examples:
  8536.         * - Valid: LU15027442
  8537.         * - Invalid: LU15027443
  8538.         *
  8539.         * @param {String} value VAT number
  8540.         * @returns {Boolean}
  8541.         */
  8542.        _lu: function(value) {
  8543.            if (/^LU[0-9]{8}$/.test(value)) {
  8544.                value = value.substr(2);
  8545.            }
  8546.            if (!/^[0-9]{8}$/.test(value)) {
  8547.                return false;
  8548.            }
  8549.  
  8550.            return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  8551.        },
  8552.  
  8553.        /**
  8554.         * Validate Latvian VAT number
  8555.         * Examples:
  8556.         * - Valid: LV40003521600, LV16117519997
  8557.         * - Invalid: LV40003521601, LV16137519997
  8558.         *
  8559.         * @param {String} value VAT number
  8560.         * @returns {Boolean}
  8561.         */
  8562.        _lv: function(value) {
  8563.            if (/^LV[0-9]{11}$/.test(value)) {
  8564.                value = value.substr(2);
  8565.            }
  8566.            if (!/^[0-9]{11}$/.test(value)) {
  8567.                return false;
  8568.            }
  8569.  
  8570.            var first  = parseInt(value.charAt(0), 10),
  8571.                sum    = 0,
  8572.                weight = [],
  8573.                i,
  8574.                length = value.length;
  8575.            if (first > 3) {
  8576.                 // Legal entity
  8577.                 sum    = 0;
  8578.                 weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  8579.                 for (i = 0; i < length; i++) {
  8580.                    sum += parseInt(value.charAt(i), 10) * weight[i];
  8581.                }
  8582.                sum = sum % 11;
  8583.                return (sum === 3);
  8584.            } else {
  8585.                // Check birth date
  8586.                var day   = parseInt(value.substr(0, 2), 10),
  8587.                    month = parseInt(value.substr(2, 2), 10),
  8588.                    year  = parseInt(value.substr(4, 2), 10);
  8589.                year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  8590.  
  8591.                if (!FormValidation.Helper.date(year, month, day)) {
  8592.                    return false;
  8593.                }
  8594.  
  8595.                // Check personal code
  8596.                sum    = 0;
  8597.                weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  8598.                for (i = 0; i < length - 1; i++) {
  8599.                    sum += parseInt(value.charAt(i), 10) * weight[i];
  8600.                }
  8601.                sum = (sum + 1) % 11 % 10;
  8602.                return (sum + '' === value.charAt(length - 1));
  8603.            }
  8604.        },
  8605.  
  8606.        /**
  8607.         * Validate Maltese VAT number
  8608.         * Examples:
  8609.         * - Valid: MT11679112
  8610.         * - Invalid: MT11679113
  8611.         *
  8612.         * @param {String} value VAT number
  8613.         * @returns {Boolean}
  8614.         */
  8615.        _mt: function(value) {
  8616.            if (/^MT[0-9]{8}$/.test(value)) {
  8617.                value = value.substr(2);
  8618.            }
  8619.            if (!/^[0-9]{8}$/.test(value)) {
  8620.                return false;
  8621.            }
  8622.  
  8623.            var sum    = 0,
  8624.                weight = [3, 4, 6, 7, 8, 9, 10, 1];
  8625.  
  8626.            for (var i = 0; i < 8; i++) {
  8627.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8628.            }
  8629.  
  8630.            return (sum % 37 === 0);
  8631.        },
  8632.  
  8633.        /**
  8634.         * Validate Dutch VAT number
  8635.         * Examples:
  8636.         * - Valid: NL004495445B01
  8637.         * - Invalid: NL123456789B90
  8638.         *
  8639.         * @param {String} value VAT number
  8640.         * @returns {Boolean}
  8641.         */
  8642.        _nl: function(value) {
  8643.            if (/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  8644.               value = value.substr(2);
  8645.            }
  8646.            if (!/^[0-9]{9}B[0-9]{2}$/.test(value)) {
  8647.               return false;
  8648.            }
  8649.  
  8650.            var sum    = 0,
  8651.                weight = [9, 8, 7, 6, 5, 4, 3, 2];
  8652.            for (var i = 0; i < 8; i++) {
  8653.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8654.            }
  8655.  
  8656.            sum = sum % 11;
  8657.            if (sum > 9) {
  8658.                 sum = 0;
  8659.             }
  8660.             return (sum + '' === value.substr(8, 1));
  8661.         },
  8662.  
  8663.         /**
  8664.          * Validate Norwegian VAT number
  8665.          *
  8666.          * @see http://www.brreg.no/english/coordination/number.html
  8667.          * @param {String} value VAT number
  8668.          * @returns {Boolean}
  8669.          */
  8670.         _no: function(value) {
  8671.             if (/^NO[0-9]{9}$/.test(value)) {
  8672.                value = value.substr(2);
  8673.             }
  8674.             if (!/^[0-9]{9}$/.test(value)) {
  8675.                return false;
  8676.             }
  8677.  
  8678.             var sum    = 0,
  8679.                 weight = [3, 2, 7, 6, 5, 4, 3, 2];
  8680.             for (var i = 0; i < 8; i++) {
  8681.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8682.            }
  8683.  
  8684.            sum = 11 - sum % 11;
  8685.            if (sum === 11) {
  8686.                sum = 0;
  8687.            }
  8688.            return (sum + '' === value.substr(8, 1));
  8689.        },
  8690.  
  8691.        /**
  8692.         * Validate Polish VAT number
  8693.         * Examples:
  8694.         * - Valid: PL8567346215
  8695.         * - Invalid: PL8567346216
  8696.         *
  8697.         * @param {String} value VAT number
  8698.         * @returns {Boolean}
  8699.         */
  8700.        _pl: function(value) {
  8701.            if (/^PL[0-9]{10}$/.test(value)) {
  8702.                value = value.substr(2);
  8703.            }
  8704.            if (!/^[0-9]{10}$/.test(value)) {
  8705.                return false;
  8706.            }
  8707.  
  8708.            var sum    = 0,
  8709.                weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  8710.  
  8711.            for (var i = 0; i < 10; i++) {
  8712.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8713.            }
  8714.  
  8715.            return (sum % 11 === 0);
  8716.        },
  8717.  
  8718.        /**
  8719.         * Validate Portuguese VAT number
  8720.         * Examples:
  8721.         * - Valid: PT501964843
  8722.         * - Invalid: PT501964842
  8723.         *
  8724.         * @param {String} value VAT number
  8725.         * @returns {Boolean}
  8726.         */
  8727.        _pt: function(value) {
  8728.            if (/^PT[0-9]{9}$/.test(value)) {
  8729.                value = value.substr(2);
  8730.            }
  8731.            if (!/^[0-9]{9}$/.test(value)) {
  8732.                return false;
  8733.            }
  8734.  
  8735.            var sum    = 0,
  8736.                weight = [9, 8, 7, 6, 5, 4, 3, 2];
  8737.  
  8738.            for (var i = 0; i < 8; i++) {
  8739.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8740.            }
  8741.            sum = 11 - sum % 11;
  8742.            if (sum > 9) {
  8743.                 sum = 0;
  8744.             }
  8745.             return (sum + '' === value.substr(8, 1));
  8746.         },
  8747.  
  8748.         /**
  8749.          * Validate Romanian VAT number
  8750.          * Examples:
  8751.          * - Valid: RO18547290
  8752.          * - Invalid: RO18547291
  8753.          *
  8754.          * @param {String} value VAT number
  8755.          * @returns {Boolean}
  8756.          */
  8757.         _ro: function(value) {
  8758.             if (/^RO[1-9][0-9]{1,9}$/.test(value)) {
  8759.                 value = value.substr(2);
  8760.             }
  8761.             if (!/^[1-9][0-9]{1,9}$/.test(value)) {
  8762.                 return false;
  8763.             }
  8764.  
  8765.             var length = value.length,
  8766.                 weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  8767.                 sum    = 0;
  8768.             for (var i = 0; i < length - 1; i++) {
  8769.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8770.            }
  8771.  
  8772.            sum = (10 * sum) % 11 % 10;
  8773.            return (sum + '' === value.substr(length - 1, 1));
  8774.        },
  8775.  
  8776.        /**
  8777.         * Validate Russian VAT number (Taxpayer Identification Number - INN)
  8778.         *
  8779.         * @param {String} value VAT number
  8780.         * @returns {Boolean}
  8781.         */
  8782.        _ru: function(value) {
  8783.            if (/^RU([0-9]{10}|[0-9]{12})$/.test(value)) {
  8784.                value = value.substr(2);
  8785.            }
  8786.            if (!/^([0-9]{10}|[0-9]{12})$/.test(value)) {
  8787.                return false;
  8788.            }
  8789.  
  8790.            var i = 0;
  8791.            if (value.length === 10) {
  8792.                var sum    = 0,
  8793.                    weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  8794.                for (i = 0; i < 10; i++) {
  8795.                    sum += parseInt(value.charAt(i), 10) * weight[i];
  8796.                }
  8797.                sum = sum % 11;
  8798.                if (sum > 9) {
  8799.                     sum = sum % 10;
  8800.                 }
  8801.  
  8802.                 return (sum + '' === value.substr(9, 1));
  8803.             } else if (value.length === 12) {
  8804.                 var sum1    = 0,
  8805.                     weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  8806.                     sum2    = 0,
  8807.                     weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  8808.  
  8809.                 for (i = 0; i < 11; i++) {
  8810.                    sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  8811.                    sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  8812.                }
  8813.                sum1 = sum1 % 11;
  8814.                if (sum1 > 9) {
  8815.                     sum1 = sum1 % 10;
  8816.                 }
  8817.                 sum2 = sum2 % 11;
  8818.                 if (sum2 > 9) {
  8819.                     sum2 = sum2 % 10;
  8820.                 }
  8821.  
  8822.                 return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  8823.             }
  8824.  
  8825.             return false;
  8826.         },
  8827.  
  8828.         /**
  8829.          * Validate Serbian VAT number
  8830.          *
  8831.          * @param {String} value VAT number
  8832.          * @returns {Boolean}
  8833.          */
  8834.         _rs: function(value) {
  8835.             if (/^RS[0-9]{9}$/.test(value)) {
  8836.                 value = value.substr(2);
  8837.             }
  8838.             if (!/^[0-9]{9}$/.test(value)) {
  8839.                 return false;
  8840.             }
  8841.  
  8842.             var sum  = 10,
  8843.                 temp = 0;
  8844.             for (var i = 0; i < 8; i++) {
  8845.                temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  8846.                if (temp === 0) {
  8847.                    temp = 10;
  8848.                }
  8849.                sum = (2 * temp) % 11;
  8850.            }
  8851.  
  8852.            return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  8853.        },
  8854.  
  8855.        /**
  8856.         * Validate Swedish VAT number
  8857.         * Examples:
  8858.         * - Valid: SE123456789701
  8859.         * - Invalid: SE123456789101
  8860.         *
  8861.         * @param {String} value VAT number
  8862.         * @returns {Boolean}
  8863.         */
  8864.        _se: function(value) {
  8865.            if (/^SE[0-9]{10}01$/.test(value)) {
  8866.                value = value.substr(2);
  8867.            }
  8868.            if (!/^[0-9]{10}01$/.test(value)) {
  8869.                return false;
  8870.            }
  8871.  
  8872.            value = value.substr(0, 10);
  8873.            return FormValidation.Helper.luhn(value);
  8874.        },
  8875.  
  8876.        /**
  8877.         * Validate Slovenian VAT number
  8878.         * Examples:
  8879.         * - Valid: SI50223054
  8880.         * - Invalid: SI50223055
  8881.         * - Invalid: SI09999990
  8882.         *
  8883.         * @param {String} value VAT number
  8884.         * @returns {Boolean}
  8885.         */
  8886.        _si: function(value) {
  8887.            // The Slovenian VAT numbers don't start with zero
  8888.            var res = value.match(/^(SI)?([1-9][0-9]{7})$/);
  8889.            if (!res) {
  8890.                return false;
  8891.            }
  8892.            if (res[1]) {
  8893.                value = value.substr(2);
  8894.            }
  8895.            var sum    = 0,
  8896.                weight = [8, 7, 6, 5, 4, 3, 2];
  8897.            for (var i = 0; i < 7; i++) {
  8898.                sum += parseInt(value.charAt(i), 10) * weight[i];
  8899.            }
  8900.            sum = 11 - sum % 11;
  8901.            if (sum === 10) {
  8902.                sum = 0;
  8903.            }
  8904.            return (sum + '' === value.substr(7, 1));
  8905.        },
  8906.        /**
  8907.         * Validate Slovak VAT number
  8908.         * Examples:
  8909.         * - Valid: SK2022749619
  8910.         * - Invalid: SK2022749618
  8911.         *
  8912.         * @param {String} value VAT number
  8913.         * @returns {Boolean}
  8914.         */
  8915.        _sk: function(value) {
  8916.            if (/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  8917.                value = value.substr(2);
  8918.            }
  8919.            if (!/^[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  8920.                return false;
  8921.            }
  8922.            return (parseInt(value, 10) % 11 === 0);
  8923.        },
  8924.        /**
  8925.         * Validate Venezuelan VAT number (RIF)
  8926.         * Examples:
  8927.         * - Valid: VEJ309272292, VEV242818101, VEJ000126518, VEJ000458324, J309272292, V242818101, J000126518, J000458324
  8928.         * - Invalid: VEJ309272293, VEV242818100, J000126519, J000458323
  8929.         *
  8930.         * @param {String} value VAT number
  8931.         * @returns {Boolean}
  8932.         */
  8933.        _ve: function(value) {
  8934.            if (/^VE[VEJPG][0-9]{9}$/.test(value)) {
  8935.                value = value.substr(2);
  8936.            }
  8937.            if (!/^[VEJPG][0-9]{9}$/.test(value)) {
  8938.                return false;
  8939.            }
  8940.            var types  = {
  8941.                    'V': 4,
  8942.                    'E': 8,
  8943.                    'J': 12,
  8944.                    'P': 16,
  8945.                    'G': 20
  8946.                },
  8947.                sum    = types[value.charAt(0)],
  8948.                weight = [3, 2, 7, 6, 5, 4, 3, 2];
  8949.            for (var i = 0; i < 8; i++) {
  8950.                sum += parseInt(value.charAt(i + 1), 10) * weight[i];
  8951.            }
  8952.            sum = 11 - sum % 11;
  8953.            if (sum === 11 || sum === 10) {
  8954.                sum = 0;
  8955.            }
  8956.            return (sum + '' === value.substr(9, 1));
  8957.        },
  8958.        /**
  8959.         * Validate South African VAT number
  8960.         * Examples:
  8961.         * - Valid: 4012345678
  8962.         * - Invalid: 40123456789, 3012345678
  8963.         *
  8964.         * @params {String} value VAT number
  8965.         * @returns {Boolean}
  8966.         */
  8967.         _za: function(value) {
  8968.            if (/^ZA4[0-9]{9}$/.test(value)) {
  8969.                value = value.substr(2);
  8970.            }
  8971.            return /^4[0-9]{9}$/.test(value);
  8972.        }
  8973.    };
  8974. }(jQuery));
  8975. ;(function($) {
  8976.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  8977.        'en_US': {
  8978.            vin: {
  8979.                'default': 'Please enter a valid VIN number'
  8980.            }
  8981.        }
  8982.    });
  8983.    FormValidation.Validator.vin = {
  8984.        /**
  8985.         * Validate an US VIN (Vehicle Identification Number)
  8986.         *
  8987.         * @param {FormValidation.Base} validator The validator plugin instance
  8988.         * @param {jQuery} $field Field element
  8989.         * @param {Object} options Consist of key:
  8990.         * - message: The invalid message
  8991.         * @returns {Boolean}
  8992.         */
  8993.        validate: function(validator, $field, options) {
  8994.            var value = validator.getFieldValue($field, 'vin');
  8995.            if (value === '') {
  8996.                return true;
  8997.            }
  8998.            // Don't accept I, O, Q characters
  8999.            if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  9000.                return false;
  9001.            }
  9002.  
  9003.            value = value.toUpperCase();
  9004.            var chars   = {
  9005.                    A: 1,   B: 2,   C: 3,   D: 4,   E: 5,   F: 6,   G: 7,   H: 8,
  9006.                    J: 1,   K: 2,   L: 3,   M: 4,   N: 5,           P: 7,           R: 9,
  9007.                            S: 2,   T: 3,   U: 4,   V: 5,   W: 6,   X: 7,   Y: 8,   Z: 9,
  9008.                    '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  9009.                },
  9010.                weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  9011.                sum     = 0,
  9012.                length  = value.length;
  9013.            for (var i = 0; i < length; i++) {
  9014.                sum += chars[value.charAt(i) + ''] * weights[i];
  9015.            }
  9016.  
  9017.            var reminder = sum % 11;
  9018.            if (reminder === 10) {
  9019.                reminder = 'X';
  9020.            }
  9021.  
  9022.            return (reminder + '') === value.charAt(8);
  9023.        }
  9024.    };
  9025. }(jQuery));
  9026. ;(function($) {
  9027.    FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  9028.        'en_US': {
  9029.            zipCode: {
  9030.                'default': 'Please enter a valid postal code',
  9031.                country: 'Please enter a valid postal code in %s',
  9032.                countries: {
  9033.                    AT: 'Austria',
  9034.                    BG: 'Bulgaria',
  9035.                    BR: 'Brazil',
  9036.                    CA: 'Canada',
  9037.                    CH: 'Switzerland',
  9038.                    CZ: 'Czech Republic',
  9039.                    DE: 'Germany',
  9040.                    DK: 'Denmark',
  9041.                    ES: 'Spain',
  9042.                    FR: 'France',
  9043.                    GB: 'United Kingdom',
  9044.                    IE: 'Ireland',
  9045.                    IN: 'India',
  9046.                    IT: 'Italy',
  9047.                    MA: 'Morocco',
  9048.                    NL: 'Netherlands',
  9049.                    PL: 'Poland',
  9050.                    PT: 'Portugal',
  9051.                    RO: 'Romania',
  9052.                    RU: 'Russia',
  9053.                    SE: 'Sweden',
  9054.                    SG: 'Singapore',
  9055.                    SK: 'Slovakia',
  9056.                    US: 'USA'
  9057.                }
  9058.            }
  9059.        }
  9060.    });
  9061.  
  9062.    FormValidation.Validator.zipCode = {
  9063.        html5Attributes: {
  9064.            message: 'message',
  9065.            country: 'country'
  9066.        },
  9067.  
  9068.        COUNTRY_CODES: ['AT', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'IE', 'IN', 'IT', 'MA', 'NL', 'PL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
  9069.  
  9070.        /**
  9071.         * Return true if and only if the input value is a valid country zip code
  9072.         *
  9073.         * @param {FormValidation.Base} validator The validator plugin instance
  9074.         * @param {jQuery} $field Field element
  9075.         * @param {Object} options Consist of key:
  9076.         * - message: The invalid message
  9077.         * - country: The country
  9078.         *
  9079.         * The country can be defined by:
  9080.         * - An ISO 3166 country code
  9081.         * - Name of field which its value defines the country code
  9082.         * - Name of callback function that returns the country code
  9083.         * - A callback function that returns the country code
  9084.         *
  9085.         *  callback: function(value, validator, $field) {
  9086.         *      // value is the value of field
  9087.         *      // validator is the BootstrapValidator instance
  9088.         *      // $field is jQuery element representing the field
  9089.         *  }
  9090.         *
  9091.         * @returns {Boolean|Object}
  9092.         */
  9093.        validate: function(validator, $field, options) {
  9094.            var value = validator.getFieldValue($field, 'zipCode');
  9095.            if (value === '' || !options.country) {
  9096.                return true;
  9097.            }
  9098.  
  9099.            var locale  = validator.getLocale(),
  9100.                country = options.country;
  9101.            if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  9102.                // Try to determine the country
  9103.                country = validator.getDynamicOption($field, country);
  9104.            }
  9105.  
  9106.            if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  9107.                return true;
  9108.            }
  9109.  
  9110.            var isValid = false;
  9111.            country = country.toUpperCase();
  9112.            switch (country) {
  9113.                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria
  9114.                case 'AT':
  9115.                    isValid = /^([1-9]{1})(\d{3})$/.test(value);
  9116.                    break;
  9117.  
  9118.                case 'BG':
  9119.                    isValid = /^([1-9]{1}[0-9]{3})$/.test($.trim(value));
  9120.                    break;
  9121.  
  9122.                case 'BR':
  9123.                    isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
  9124.                    break;
  9125.  
  9126.                case 'CA':
  9127.                    isValid = /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}[0-9]{1}$/i.test(value);
  9128.                    break;
  9129.  
  9130.                case 'CH':
  9131.                    isValid = /^([1-9]{1})(\d{3})$/.test(value);
  9132.                    break;
  9133.  
  9134.                case 'CZ':
  9135.                    // Test: http://regexr.com/39hhr
  9136.                    isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  9137.                    break;
  9138.  
  9139.                // http://stackoverflow.com/questions/7926687/regular-expression-german-zip-codes
  9140.                case 'DE':
  9141.                    isValid = /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$/.test(value);
  9142.                    break;
  9143.  
  9144.                case 'DK':
  9145.                    isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
  9146.                    break;
  9147.  
  9148.                // Zip codes in Spain go from 01XXX to 52XXX.
  9149.                // Test: http://refiddle.com/1ufo
  9150.                case 'ES':
  9151.                    isValid = /^(?:0[1-9]|[1-4][0-9]|5[0-2])\d{3}$/.test(value);
  9152.                    break;
  9153.  
  9154.                // http://en.wikipedia.org/wiki/Postal_codes_in_France
  9155.                case 'FR':
  9156.                    isValid = /^[0-9]{5}$/i.test(value);
  9157.                    break;
  9158.  
  9159.                case 'GB':
  9160.                    isValid = this._gb(value);
  9161.                    break;
  9162.  
  9163.                // Indian PIN (Postal Index Number) validation
  9164.                // http://en.wikipedia.org/wiki/Postal_Index_Number
  9165.                // Test: http://regex101.com/r/kV0vH3/1
  9166.                case 'IN':
  9167.                    isValid = /^\d{3}\s?\d{3}$/.test(value);
  9168.                    break;
  9169.  
  9170.                // http://www.eircode.ie/docs/default-source/Common/prepare-your-business-for-eircode---published-v2.pdf?sfvrsn=2
  9171.                // Test: http://refiddle.com/1kpl
  9172.                case 'IE':
  9173.                    isValid = /^(D6W|[ACDEFHKNPRTVWXY]\d{2})\s[0-9ACDEFHKNPRTVWXY]{4}$/.test(value);
  9174.                    break;
  9175.  
  9176.                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  9177.                case 'IT':
  9178.                    isValid = /^(I-|IT-)?\d{5}$/i.test(value);
  9179.                    break;
  9180.  
  9181.                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
  9182.                case 'MA':
  9183.                    isValid = /^[1-9][0-9]{4}$/i.test(value);
  9184.                    break;
  9185.  
  9186.                // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  9187.                case 'NL':
  9188.                    isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  9189.                    break;
  9190.  
  9191.                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Poland
  9192.                case 'PL':
  9193.                    isValid = /^[0-9]{2}\-[0-9]{3}$/.test(value);
  9194.                    break;
  9195.  
  9196.                // Test: http://refiddle.com/1l2t
  9197.                case 'PT':
  9198.                    isValid = /^[1-9]\d{3}-\d{3}$/.test(value);
  9199.                    break;
  9200.  
  9201.                case 'RO':
  9202.                    isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
  9203.                    break;
  9204.  
  9205.                case 'RU':
  9206.                    isValid = /^[0-9]{6}$/i.test(value);
  9207.                    break;
  9208.  
  9209.                case 'SE':
  9210.                    isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  9211.                    break;
  9212.  
  9213.                case 'SG':
  9214.                    isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  9215.                    break;
  9216.  
  9217.                case 'SK':
  9218.                    // Test: http://regexr.com/39hhr
  9219.                    isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  9220.                    break;
  9221.  
  9222.                case 'US':
  9223.                /* falls through */
  9224.                default:
  9225.                    isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
  9226.                    break;
  9227.            }
  9228.  
  9229.            return {
  9230.                valid: isValid,
  9231.                message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].zipCode.country, FormValidation.I18n[locale].zipCode.countries[country])
  9232.            };
  9233.        },
  9234.  
  9235.        /**
  9236.         * Validate United Kingdom postcode
  9237.         * Examples:
  9238.         * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  9239.         * - Special cases:
  9240.         * AI-2640, ASCN 1ZZ, GIR 0AA
  9241.         *
  9242.         * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  9243.         * @param {String} value The postcode
  9244.         * @returns {Boolean}
  9245.         */
  9246.        _gb: function(value) {
  9247.            var firstChar  = '[ABCDEFGHIJKLMNOPRSTUWYZ]',     // Does not accept QVX
  9248.                secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]',     // Does not accept IJZ
  9249.                thirdChar  = '[ABCDEFGHJKPMNRSTUVWXY]',
  9250.                fourthChar = '[ABEHMNPRVWXY]',
  9251.                fifthChar  = '[ABDEFGHJLNPQRSTUWXYZ]',
  9252.                regexps    = [
  9253.                    // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  9254.                    new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  9255.                    // ANA NAA
  9256.                    new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  9257.                    // AANA NAA
  9258.                    new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  9259.  
  9260.                    new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'),        // BFPO postcodes
  9261.                    /^(GIR)(\s*)(0AA)$/i,                       // Special postcode GIR 0AA
  9262.                    /^(BFPO)(\s*)([0-9]{1,4})$/i,               // Standard BFPO numbers
  9263.                    /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i,        // c/o BFPO numbers
  9264.                    /^([A-Z]{4})(\s*)(1ZZ)$/i,                  // Overseas Territories
  9265.                    /^(AI-2640)$/i                              // Anguilla
  9266.                ];
  9267.            for (var i = 0; i < regexps.length; i++) {
  9268.                if (regexps[i].test(value)) {
  9269.                    return true;
  9270.                }
  9271.            }
  9272.  
  9273.            return false;
  9274.        }
  9275.    };
  9276. }(jQuery));
  9277. ;/* =============================================================
  9278. * bootstrap-combobox.js v1.1.6
  9279. * =============================================================
  9280. * Copyright 2012 Daniel Farrell
  9281. *
  9282. * Licensed under the Apache License, Version 2.0 (the "License");
  9283. * you may not use this file except in compliance with the License.
  9284. * You may obtain a copy of the License at
  9285. *
  9286. * http://www.apache.org/licenses/LICENSE-2.0
  9287. *
  9288. * Unless required by applicable law or agreed to in writing, software
  9289. * distributed under the License is distributed on an "AS IS" BASIS,
  9290. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9291. * See the License for the specific language governing permissions and
  9292. * limitations under the License.
  9293. * ============================================================ */
  9294.  
  9295. !function( $ ) {
  9296.  
  9297. "use strict";
  9298.  
  9299. /* COMBOBOX PUBLIC CLASS DEFINITION
  9300.  * ================================ */
  9301.  
  9302.  var Combobox = function ( element, options ) {
  9303.    this.options = $.extend({}, $.fn.combobox.defaults, options);
  9304.    this.$source = $(element);
  9305.    this.$container = this.setup();
  9306.    this.$element = this.$container.find('input[type=text]');
  9307.    this.$target = this.$container.find('input[type=hidden]');
  9308.    this.$button = this.$container.find('.dropdown-toggle');
  9309.    this.$menu = $(this.options.menu).appendTo('body');
  9310.    this.template = this.options.template || this.template
  9311.    this.matcher = this.options.matcher || this.matcher;
  9312.    this.sorter = this.options.sorter || this.sorter;
  9313.    this.highlighter = this.options.highlighter || this.highlighter;
  9314.    this.shown = false;
  9315.    this.selected = false;
  9316.    this.refresh();
  9317.    this.transferAttributes();
  9318.    this.listen();
  9319.  };
  9320.  
  9321.  Combobox.prototype = {
  9322.  
  9323.    constructor: Combobox
  9324.  
  9325.  , setup: function () {
  9326.      var combobox = $(this.template());
  9327.      this.$source.before(combobox);
  9328.      this.$source.hide();
  9329.      return combobox;
  9330.    }
  9331.  
  9332.  , disable: function() {
  9333.      this.$element.prop('disabled', true);
  9334.      this.$button.attr('disabled', true);
  9335.      this.disabled = true;
  9336.      this.$container.addClass('combobox-disabled');
  9337.    }
  9338.  
  9339.  , enable: function() {
  9340.      this.$element.prop('disabled', false);
  9341.      this.$button.attr('disabled', false);
  9342.      this.disabled = false;
  9343.      this.$container.removeClass('combobox-disabled');
  9344.    }
  9345.  , parse: function () {
  9346.      var that = this
  9347.        , map = {}
  9348.        , source = []
  9349.        , selected = false
  9350.        , selectedValue = '';
  9351.      this.$source.find('option').each(function() {
  9352.         var current_project = $( this ).parents(".donation").find('.projects select option:selected').val();
  9353.         if( $(this).attr('data-parent') === current_project || $(this).val() === '0' || $(this).attr('data-selected') === "yes" || $(this).attr('data-parent') === "get_value"){
  9354.             var option = $(this);
  9355.             // console.log(option.val());
  9356.             if (option.val() === '0') {
  9357.               that.options.placeholder = option.text();
  9358.               that.options.value = "123";
  9359.               return;
  9360.             }
  9361.             map[option.text()] = option.val();
  9362.             source.push(option.text());
  9363.             if (option.prop('selected')) {
  9364.               selected = option.text();
  9365.               selectedValue = option.val();
  9366.             }
  9367.             //console.log(option.val());
  9368.         }
  9369.         else{
  9370.             //alert( $(this).attr('data-parent') );
  9371.         }
  9372.  
  9373.  
  9374.      })
  9375.      this.map = map;
  9376.      if (selected) {
  9377.        this.$element.val(selected);
  9378.        this.$target.val(selectedValue);
  9379.        this.$container.addClass('combobox-selected');
  9380.        this.selected = true;
  9381.      }
  9382.         //console.log(source);
  9383.      return source;
  9384.    }
  9385.  
  9386.  , transferAttributes: function() {
  9387.    this.options.placeholder = this.$source.attr('data-placeholder') || this.options.placeholder
  9388.    this.$element.attr('placeholder', this.options.placeholder)
  9389.    this.$target.prop('name', this.$source.prop('name'))
  9390.    this.$target.val(this.$source.val())
  9391.    this.$source.removeAttr('name')  // Remove from source otherwise form will pass parameter twice.
  9392.    this.$element.attr('required', this.$source.attr('required'))
  9393.    this.$element.attr('rel', this.$source.attr('rel'))
  9394.    this.$element.attr('title', this.$source.attr('title'))
  9395.    this.$element.attr('class', this.$source.attr('class'))
  9396.    this.$element.attr('tabindex', this.$source.attr('tabindex'))
  9397.    this.$source.removeAttr('tabindex')
  9398.    if (this.$source.attr('disabled')!==undefined)
  9399.      this.disable();
  9400.  }
  9401.  
  9402.  , select: function () {
  9403.      var val = this.$menu.find('.active').attr('data-value');
  9404.       console.log( this.map[val] );
  9405.      this.$element.val(this.map[val]).trigger('change');
  9406.      this.$target.val(this.map[val]).trigger('change');
  9407.      this.$source.val(this.map[val]).trigger('change');
  9408.      this.$container.addClass('combobox-selected');
  9409.      this.selected = true;
  9410.      return this.hide();
  9411.    }
  9412.  
  9413.  , updater: function (item) {
  9414.      return item;
  9415.    }
  9416.  
  9417.  , show: function () {
  9418.      var pos = $.extend({}, this.$element.position(), {
  9419.        height: this.$element[0].offsetHeight
  9420.      });
  9421.  
  9422.      this.$menu
  9423.        .insertAfter(this.$element)
  9424.        .css({
  9425.          top: pos.top + pos.height
  9426.        , left: pos.left
  9427.        })
  9428.        .show();
  9429.  
  9430.      $('.dropdown-menu').on('mousedown', $.proxy(this.scrollSafety, this));
  9431.  
  9432.      this.shown = true;
  9433.      return this;
  9434.    }
  9435.  
  9436.  , hide: function () {
  9437.      this.$menu.hide();
  9438.      $('.dropdown-menu').off('mousedown', $.proxy(this.scrollSafety, this));
  9439.      this.$element.on('blur', $.proxy(this.blur, this));
  9440.      this.shown = false;
  9441.      return this;
  9442.    }
  9443.  
  9444.  , lookup: function (event) {
  9445.      this.query = this.$element.val();
  9446.      
  9447.      return this.process(this.source);
  9448.    }
  9449.  
  9450.  , process: function (items) {
  9451.      
  9452.      var that = this;
  9453.  
  9454.      items = $.grep(items, function (item) {
  9455.        return that.matcher(item);
  9456.      })
  9457.  
  9458.      items = this.sorter(items);
  9459.      if (!items.length) {
  9460.        //return this.shown ? this.hide() : this;
  9461.      }
  9462.        
  9463.      return this.render(items.slice(0, this.options.items)).show();
  9464.    }
  9465.  
  9466.  , template: function() {
  9467.      if (this.options.bsVersion == '2') {
  9468.        return '<div class="combobox-container"><input type="hidden" /> <div class="input-append"> <input type="text" autocomplete="off" /> <span class="add-on dropdown-toggle" data-dropdown="dropdown"> <span class="caret"/> <i class="icon-remove"/> </span> </div> </div>'
  9469.       } else {
  9470.         return '<div class="combobox-container"> <input type="hidden" /> <div class="input-group"> <input type="text" autocomplete="off" /> <span class="input-group-addon dropdown-toggle" data-dropdown="dropdown"> <span class="caret" /> <span class="glyphicon glyphicon-remove" /> </span> </div> </div>'
  9471.       }
  9472.     }
  9473.  
  9474.   , matcher: function (item) {
  9475.       return ~item.toLowerCase().indexOf(this.query.toLowerCase());
  9476.     }
  9477.  
  9478.   , sorter: function (items) {
  9479.       var beginswith = []
  9480.         , caseSensitive = []
  9481.         , caseInsensitive = []
  9482.         , item;
  9483.  
  9484.       while (item = items.shift()) {
  9485.         if (!item.toLowerCase().indexOf(this.query.toLowerCase())) {beginswith.push(item);}
  9486.         else if (~item.indexOf(this.query)) {caseSensitive.push(item);}
  9487.         else {caseInsensitive.push(item);}
  9488.       }
  9489.  
  9490.       return beginswith.concat(caseSensitive, caseInsensitive);
  9491.     }
  9492.  
  9493.   , highlighter: function (item) {
  9494.       var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
  9495.       return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
  9496.         return match;
  9497.       })
  9498.     }
  9499.  
  9500.   , render: function (items) {
  9501.       var that = this;
  9502. //console.log(items);
  9503.       items = $(items).map(function (i, item) {
  9504.         i = $(that.options.item).attr('data-value', item);
  9505.         i.find('a').html(that.highlighter(item));
  9506.         return i[0];
  9507.       })
  9508.  
  9509.       items.first().addClass('active');
  9510.       this.$menu.html(items);
  9511.       return this;
  9512.     }
  9513.  
  9514.   , next: function (event) {
  9515.       var active = this.$menu.find('.active').removeClass('active')
  9516.         , next = active.next();
  9517.  
  9518.       if (!next.length) {
  9519.         next = $(this.$menu.find('li')[0]);
  9520.       }
  9521.  
  9522.       next.addClass('active');
  9523.     }
  9524.  
  9525.   , prev: function (event) {
  9526.       var active = this.$menu.find('.active').removeClass('active')
  9527.         , prev = active.prev();
  9528.  
  9529.       if (!prev.length) {
  9530.         prev = this.$menu.find('li').last();
  9531.       }
  9532.  
  9533.       prev.addClass('active');
  9534.     }
  9535.  
  9536.   , toggle: function () {
  9537.     if (!this.disabled) {
  9538.       if (this.$container.hasClass('combobox-selected')) {
  9539.         this.clearTarget();
  9540.         this.triggerChange();
  9541.         this.clearElement();
  9542.       } else {
  9543.         if (this.shown) {
  9544.           this.hide();
  9545.         } else {
  9546.           this.clearElement();
  9547.           this.lookup();
  9548.         }
  9549.       }
  9550.     }
  9551.   }
  9552.  
  9553.   , scrollSafety: function(e) {
  9554.       if (e.target.tagName == 'UL') {
  9555.           this.$element.off('blur');
  9556.       }
  9557.   }
  9558.   , clearElement: function () {
  9559.     this.$element.val('').focus();
  9560.   }
  9561.  
  9562.   , clearTarget: function () {
  9563.     this.$source.val('');
  9564.     this.$target.val('');
  9565.     this.$container.removeClass('combobox-selected');
  9566.     this.selected = false;
  9567.   }
  9568.  
  9569.   , triggerChange: function () {
  9570.     this.$source.trigger('change');
  9571.   }
  9572.  
  9573.   , refresh: function () {
  9574.     this.source = this.parse();
  9575.     this.options.items = this.source.length;
  9576.     //console.log(this.source);
  9577.   }
  9578.  
  9579.   , listen: function () {
  9580.       this.$element
  9581.         .on('focus',    $.proxy(this.focus, this))
  9582.         .on('blur',     $.proxy(this.blur, this))
  9583.         .on('keypress', $.proxy(this.keypress, this))
  9584.         .on('keyup',    $.proxy(this.keyup, this));
  9585.  
  9586.       if (this.eventSupported('keydown')) {
  9587.         this.$element.on('keydown', $.proxy(this.keydown, this));
  9588.       }
  9589.  
  9590.       this.$menu
  9591.         .on('click', $.proxy(this.click, this))
  9592.         .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
  9593.         .on('mouseleave', 'li', $.proxy(this.mouseleave, this));
  9594.  
  9595.       this.$button
  9596.         .on('click', $.proxy(this.toggle, this));
  9597.     }
  9598.  
  9599.   , eventSupported: function(eventName) {
  9600.       var isSupported = eventName in this.$element;
  9601.       if (!isSupported) {
  9602.         this.$element.setAttribute(eventName, 'return;');
  9603.         isSupported = typeof this.$element[eventName] === 'function';
  9604.       }
  9605.       return isSupported;
  9606.     }
  9607.  
  9608.   , move: function (e) {
  9609.       if (!this.shown) {return;}
  9610.  
  9611.       switch(e.keyCode) {
  9612.         //case 9: // tab
  9613.         //case 13: // enter
  9614.         case 27: // escape
  9615.           e.preventDefault();
  9616.           break;
  9617.  
  9618.         case 38: // up arrow
  9619.           e.preventDefault();
  9620.           this.prev();
  9621.           break;
  9622.  
  9623.         case 40: // down arrow
  9624.           e.preventDefault();
  9625.           this.next();
  9626.           break;
  9627.       }
  9628.  
  9629.       e.stopPropagation();
  9630.     }
  9631.  
  9632.   , keydown: function (e) {
  9633.       this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]);
  9634.       this.move(e);
  9635.     }
  9636.  
  9637.   , keypress: function (e) {
  9638.       if (this.suppressKeyPressRepeat) {return;}
  9639.       this.move(e);
  9640.     }
  9641.  
  9642.   , keyup: function (e) {
  9643.    
  9644.       switch(e.keyCode) {
  9645.         case 40: // down arrow
  9646.         case 39: // right arrow
  9647.         case 38: // up arrow
  9648.         case 37: // left arrow
  9649.         case 36: // home
  9650.         case 35: // end
  9651.         case 16: // shift
  9652.         case 17: // ctrl
  9653.         case 18: // alt
  9654.           break;
  9655.  
  9656.         case 9: // tab
  9657.             this.select();
  9658.             break;
  9659.         case 13: // enter
  9660.             this.select();
  9661.  
  9662.             break;
  9663.  
  9664.         case 27: // escape
  9665.           if (!this.shown) {return;}
  9666.           this.hide();
  9667.           break;
  9668.  
  9669.         default:
  9670.           this.clearTarget();
  9671.           this.lookup();
  9672.       }
  9673.  
  9674.       e.stopPropagation();
  9675.       e.preventDefault();
  9676.         this.$element.val( this.$element.val() ).trigger('change');
  9677.         this.$target.val( this.$element.val() ).trigger('change');
  9678.         //this.$source.val( this.$element.val() ).trigger('change');
  9679.   }
  9680.  
  9681.   , focus: function (e) {
  9682.       this.focused = true;
  9683.     }
  9684.  
  9685.   , blur: function (e) {
  9686.       var that = this;
  9687.       this.focused = false;
  9688.       var val = this.$element.val();
  9689.       if (!this.selected && val !== '' ) {
  9690.        //this.$element.val('');
  9691.         //this.$source.val('').trigger('change');
  9692.         //this.$target.val('').trigger('change');
  9693.         this.$element.val( this.$element.val() ).trigger('change');
  9694.         this.$target.val( this.$element.val() ).trigger('change');
  9695.         this.$source.val( this.$element.val() ).trigger('change');
  9696.       }
  9697.       if (!this.mousedover && this.shown) {setTimeout(function () { that.hide(); }, 200);}
  9698.     }
  9699.  
  9700.   , click: function (e) {
  9701.       e.stopPropagation();
  9702.       e.preventDefault();
  9703.       this.select();
  9704.       this.$element.focus();
  9705.     }
  9706.  
  9707.   , mouseenter: function (e) {
  9708.       this.mousedover = true;
  9709.       this.$menu.find('.active').removeClass('active');
  9710.       $(e.currentTarget).addClass('active');
  9711.     }
  9712.  
  9713.   , mouseleave: function (e) {
  9714.       this.mousedover = false;
  9715.     }
  9716.   };
  9717.  
  9718.   /* COMBOBOX PLUGIN DEFINITION
  9719.    * =========================== */
  9720.   $.fn.combobox = function ( option ) {
  9721.     return this.each(function () {
  9722.       var $this = $(this)
  9723.         , data = $this.data('combobox')
  9724.         , options = typeof option == 'object' && option;
  9725.       if(!data) {$this.data('combobox', (data = new Combobox(this, options)));}
  9726.       if (typeof option == 'string') {data[option]();}
  9727.     });
  9728.   };
  9729.  
  9730.   $.fn.combobox.defaults = {
  9731.     bsVersion: '3'
  9732.   , menu: '<ul class="typeahead typeahead-long dropdown-menu"></ul>'
  9733.   , item: '<li><a href="#"></a></li>'
  9734.   };
  9735.  
  9736.   $.fn.combobox.Constructor = Combobox;
  9737.  
  9738. }( window.jQuery );
  9739. ;/*!
  9740.  * FormValidation (http://formvalidation.io)
  9741.  * The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit frameworks
  9742.  *
  9743.  * @version     v0.6.1-dev, built on 2015-02-17 8:51:23 PM
  9744.  * @author      https://twitter.com/nghuuphuoc
  9745.  * @copyright   (c) 2013 - 2015 Nguyen Huu Phuoc
  9746.  * @license     http://formvalidation.io/license/
  9747.  */
  9748. /**
  9749.  * This class supports validating Bootstrap form (http://getbootstrap.com/)
  9750.  */
  9751. (function($) {
  9752.     FormValidation.Framework.Bootstrap = function(element, options, namespace) {
  9753.         options = $.extend(true, {
  9754.             button: {
  9755.                 selector: '[type="submit"]',
  9756.                 // The class of disabled button
  9757.                 // http://getbootstrap.com/css/#buttons-disabled
  9758.                 disabled: 'disabled'
  9759.             },
  9760.             err: {
  9761.                 // http://getbootstrap.com/css/#forms-help-text
  9762.                 clazz: 'help-block',
  9763.                 parent: '^(.*)col-(xs|sm|md|lg)-(offset-){0,1}[0-9]+(.*)$'
  9764.             },
  9765.             // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
  9766.             // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
  9767.             // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
  9768.             //
  9769.             // Examples:
  9770.             // - Use Glyphicons icons:
  9771.             //  icon: {
  9772.             //      valid: 'glyphicon glyphicon-ok',
  9773.             //      invalid: 'glyphicon glyphicon-remove',
  9774.             //      validating: 'glyphicon glyphicon-refresh',
  9775.             //      feedback: 'form-control-feedback'
  9776.             //  }
  9777.             // - Use FontAwesome icons:
  9778.             //  icon: {
  9779.             //      valid: 'fa fa-check',
  9780.             //      invalid: 'fa fa-times',
  9781.             //      validating: 'fa fa-refresh',
  9782.             //      feedback: 'form-control-feedback'
  9783.             //  }
  9784.             icon: {
  9785.                 valid: null,
  9786.                 invalid: null,
  9787.                 validating: null,
  9788.                 feedback: 'form-control-feedback'
  9789.             },
  9790.             row: {
  9791.                 // By default, each field is placed inside the <div class="form-group"></div>
  9792.                 // http://getbootstrap.com/css/#forms
  9793.                 selector: '.form-group',
  9794.                 valid: 'has-success',
  9795.                 invalid: 'has-error',
  9796.                 feedback: 'has-feedback'
  9797.             }
  9798.         }, options);
  9799.  
  9800.         FormValidation.Base.apply(this, [element, options, namespace]);
  9801.     };
  9802.  
  9803.     FormValidation.Framework.Bootstrap.prototype = $.extend({}, FormValidation.Base.prototype, {
  9804.         /**
  9805.          * Specific framework might need to adjust the icon position
  9806.          *
  9807.          * @param {jQuery} $field The field element
  9808.          * @param {jQuery} $icon The icon element
  9809.          */
  9810.         _fixIcon: function($field, $icon) {
  9811.             var ns      = this._namespace,
  9812.                 type    = $field.attr('type'),
  9813.                 field   = $field.attr('data-' + ns + '-field'),
  9814.                 row     = this.options.fields[field].row || this.options.row.selector,
  9815.                 $parent = $field.closest(row);
  9816.  
  9817.             // Place it after the container of checkbox/radio
  9818.             // so when clicking the icon, it doesn't effect to the checkbox/radio element
  9819.             if ('checkbox' === type || 'radio' === type) {
  9820.                 var $fieldParent = $field.parent();
  9821.                 if ($fieldParent.hasClass(type)) {
  9822.                     $icon.insertAfter($fieldParent);
  9823.                 } else if ($fieldParent.parent().hasClass(type)) {
  9824.                     $icon.insertAfter($fieldParent.parent());
  9825.                 }
  9826.             }
  9827.  
  9828.             // The feedback icon does not render correctly if there is no label
  9829.             // https://github.com/twbs/bootstrap/issues/12873
  9830.             if ($parent.find('label').length === 0) {
  9831.                 $icon.addClass('fv-icon-no-label');
  9832.             }
  9833.             // Fix feedback icons in input-group
  9834.             if ($parent.find('.input-group').length !== 0) {
  9835.                 $icon.addClass('fv-bootstrap-icon-input-group')
  9836.                      .insertAfter($parent.find('.input-group').eq(0));
  9837.             }
  9838.         },
  9839.  
  9840.         /**
  9841.          * Create a tooltip or popover
  9842.          * It will be shown when focusing on the field
  9843.          *
  9844.          * @param {jQuery} $field The field element
  9845.          * @param {String} message The message
  9846.          * @param {String} type Can be 'tooltip' or 'popover'
  9847.          */
  9848.         _createTooltip: function($field, message, type) {
  9849.             var ns    = this._namespace,
  9850.                 $icon = $field.data(ns + '.icon');
  9851.             if ($icon) {
  9852.                 switch (type) {
  9853.                     case 'popover':
  9854.                         $icon
  9855.                             .css({
  9856.                                 'cursor': 'pointer',
  9857.                                 'pointer-events': 'auto'
  9858.                             })
  9859.                             .popover('destroy')
  9860.                             .popover({
  9861.                                 container: 'body',
  9862.                                 content: message,
  9863.                                 html: true,
  9864.                                 placement: 'auto top',
  9865.                                 trigger: 'hover click'
  9866.                             });
  9867.                         break;
  9868.  
  9869.                     case 'tooltip':
  9870.                     /* falls through */
  9871.                     default:
  9872.                         $icon
  9873.                             .css({
  9874.                                 'cursor': 'pointer',
  9875.                                 'pointer-events': 'auto'
  9876.                             })
  9877.                             .tooltip('destroy')
  9878.                             .tooltip({
  9879.                                 container: 'body',
  9880.                                 html: true,
  9881.                                 placement: 'auto top',
  9882.                                 title: message
  9883.                             });
  9884.                         break;
  9885.                 }
  9886.             }
  9887.         },
  9888.  
  9889.         /**
  9890.          * Destroy the tooltip or popover
  9891.          *
  9892.          * @param {jQuery} $field The field element
  9893.          * @param {String} type Can be 'tooltip' or 'popover'
  9894.          */
  9895.         _destroyTooltip: function($field, type) {
  9896.             var ns    = this._namespace,
  9897.                 $icon = $field.data(ns + '.icon');
  9898.             if ($icon) {
  9899.                 switch (type) {
  9900.                     case 'popover':
  9901.                         $icon
  9902.                             .css({
  9903.                                 'cursor': '',
  9904.                                 'pointer-events': 'none'
  9905.                             })
  9906.                             .popover('destroy');
  9907.                         break;
  9908.  
  9909.                     case 'tooltip':
  9910.                     /* falls through */
  9911.                     default:
  9912.                         $icon
  9913.                             .css({
  9914.                                 'cursor': '',
  9915.                                 'pointer-events': 'none'
  9916.                             })
  9917.                             .tooltip('destroy');
  9918.                         break;
  9919.                 }
  9920.             }
  9921.         },
  9922.  
  9923.         /**
  9924.          * Hide a tooltip or popover
  9925.          *
  9926.          * @param {jQuery} $field The field element
  9927.          * @param {String} type Can be 'tooltip' or 'popover'
  9928.          */
  9929.         _hideTooltip: function($field, type) {
  9930.             var ns    = this._namespace,
  9931.                 $icon = $field.data(ns + '.icon');
  9932.             if ($icon) {
  9933.                 switch (type) {
  9934.                     case 'popover':
  9935.                         $icon.popover('hide');
  9936.                         break;
  9937.  
  9938.                     case 'tooltip':
  9939.                     /* falls through */
  9940.                     default:
  9941.                         $icon.tooltip('hide');
  9942.                         break;
  9943.                 }
  9944.             }
  9945.         },
  9946.  
  9947.         /**
  9948.          * Show a tooltip or popover
  9949.          *
  9950.          * @param {jQuery} $field The field element
  9951.          * @param {String} type Can be 'tooltip' or 'popover'
  9952.          */
  9953.         _showTooltip: function($field, type) {
  9954.             var ns    = this._namespace,
  9955.                 $icon = $field.data(ns + '.icon');
  9956.             if ($icon) {
  9957.                 switch (type) {
  9958.                     case 'popover':
  9959.                         $icon.popover('show');
  9960.                         break;
  9961.  
  9962.                     case 'tooltip':
  9963.                     /* falls through */
  9964.                     default:
  9965.                         $icon.tooltip('show');
  9966.                         break;
  9967.                 }
  9968.             }
  9969.         }
  9970.     });
  9971.  
  9972.     /**
  9973.      * Plugin definition
  9974.      * Support backward
  9975.      * @deprecated It will be removed soon. Instead of using $(form).bootstrapValidator(), use
  9976.      *  $(form).formValidation({
  9977.      *      framework: 'bootstrap'  // It's equivalent to use data-fv-framework="bootstrap" for <form>
  9978.      *  });
  9979.      */
  9980.     $.fn.bootstrapValidator = function(option) {
  9981.         var params = arguments;
  9982.         return this.each(function() {
  9983.             var $this   = $(this),
  9984.                 data    = $this.data('formValidation') || $this.data('bootstrapValidator'),
  9985.                 options = 'object' === typeof option && option;
  9986.             if (!data) {
  9987.                 data = new FormValidation.Framework.Bootstrap(this, $.extend({}, {
  9988.                     events: {
  9989.                         // Support backward
  9990.                         formInit: 'init.form.bv',
  9991.                         formError: 'error.form.bv',
  9992.                         formSuccess: 'success.form.bv',
  9993.                         fieldAdded: 'added.field.bv',
  9994.                         fieldRemoved: 'removed.field.bv',
  9995.                         fieldInit: 'init.field.bv',
  9996.                         fieldError: 'error.field.bv',
  9997.                         fieldSuccess: 'success.field.bv',
  9998.                         fieldStatus: 'status.field.bv',
  9999.                         localeChanged: 'changed.locale.bv',
  10000.                         validatorError: 'error.validator.bv',
  10001.                         validatorSuccess: 'success.validator.bv'
  10002.                     }
  10003.                 }, options), 'bv');
  10004.  
  10005.                 $this.addClass('fv-form-bootstrap')
  10006.                      .data('formValidation', data)
  10007.                      .data('bootstrapValidator', data);
  10008.             }
  10009.  
  10010.             // Allow to call plugin method
  10011.             if ('string' === typeof option) {
  10012.                 data[option].apply(data, Array.prototype.slice.call(params, 1));
  10013.             }
  10014.         });
  10015.     };
  10016.  
  10017.     $.fn.bootstrapValidator.Constructor = FormValidation.Framework.Bootstrap;
  10018. }(jQuery));
  10019. ;(function ($) {
  10020.     $.fn.countTo = function (options) {
  10021.         options = options || {};
  10022.  
  10023.         return $(this).each(function () {
  10024.             // set options for current element
  10025.             var settings = $.extend({}, $.fn.countTo.defaults, {
  10026.                 from:            $(this).data('from'),
  10027.                 to:              $(this).data('to'),
  10028.                 speed:           $(this).data('speed'),
  10029.                 refreshInterval: $(this).data('refresh-interval'),
  10030.                 decimals:        $(this).data('decimals')
  10031.             }, options);
  10032.  
  10033.             // how many times to update the value, and how much to increment the value on each update
  10034.             var loops = Math.ceil(settings.speed / settings.refreshInterval),
  10035.                 increment = (settings.to - settings.from) / loops;
  10036.  
  10037.             // references & variables that will change with each update
  10038.             var self = this,
  10039.                 $self = $(this),
  10040.                 loopCount = 0,
  10041.                 value = settings.from,
  10042.                 data = $self.data('countTo') || {};
  10043.  
  10044.             $self.data('countTo', data);
  10045.  
  10046.             // if an existing interval can be found, clear it first
  10047.             if (data.interval) {
  10048.                 clearInterval(data.interval);
  10049.             }
  10050.             data.interval = setInterval(updateTimer, settings.refreshInterval);
  10051.  
  10052.             // initialize the element with the starting value
  10053.             render(value);
  10054.  
  10055.             function updateTimer() {
  10056.                 value += increment;
  10057.                 loopCount++;
  10058.  
  10059.                 render(value);
  10060.  
  10061.                 if (typeof(settings.onUpdate) == 'function') {
  10062.                     settings.onUpdate.call(self, value);
  10063.                 }
  10064.  
  10065.                 if (loopCount >= loops) {
  10066.                     // remove the interval
  10067.                     $self.removeData('countTo');
  10068.                     clearInterval(data.interval);
  10069.                     value = settings.to;
  10070.  
  10071.                     if (typeof(settings.onComplete) == 'function') {
  10072.                         settings.onComplete.call(self, value);
  10073.                     }
  10074.                 }
  10075.             }
  10076.  
  10077.             function render(value) {
  10078.                 var formattedValue = settings.formatter.call(self, value, settings);
  10079.                 $self.text(formattedValue);
  10080.             }
  10081.         });
  10082.     };
  10083.  
  10084.     $.fn.countTo.defaults = {
  10085.         from: 0,               // the number the element should start at
  10086.         to: 0,                 // the number the element should end at
  10087.         speed: 1000,           // how long it should take to count between the target numbers
  10088.         refreshInterval: 100,  // how often the element should be updated
  10089.         decimals: 0,           // the number of decimal places to show
  10090.         formatter: formatter,  // handler for formatting the value before rendering
  10091.         onUpdate: null,        // callback method for every time the element is updated
  10092.         onComplete: null       // callback method for when the element finishes updating
  10093.     };
  10094.  
  10095.     function formatter(value, settings) {
  10096.         return value.toFixed(settings.decimals);
  10097.     }
  10098. }(jQuery));
  10099. ;
  10100.  
  10101.  </script>
  10102.  
  10103. <script>
  10104. $(document).ready(function() {
  10105.     // Generate a simple captcha
  10106.     function randomNumber(min, max) {
  10107.         return Math.floor(Math.random() * (max - min + 1) + min);
  10108.     }
  10109.  
  10110.     function generateCaptcha() {
  10111.         $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  10112.     }
  10113.  
  10114.     generateCaptcha();
  10115.  
  10116.     $('#contactForm')
  10117.         .formValidation({
  10118.             framework: 'bootstrap',
  10119.             icon: {
  10120.                 valid: 'glyphicon glyphicon-ok',
  10121.                 invalid: 'glyphicon glyphicon-remove',
  10122.                 validating: 'glyphicon glyphicon-refresh'
  10123.             },
  10124.             fields: {
  10125.                 firstName: {
  10126.                     row: '.col-xs-4',
  10127.                     validators: {
  10128.                         notEmpty: {
  10129.                             message: 'The first name is required'
  10130.                         }
  10131.                     }
  10132.                 },
  10133.                 lastName: {
  10134.                     row: '.col-xs-4',
  10135.                     validators: {
  10136.                         notEmpty: {
  10137.                             message: 'The last name is required'
  10138.                         }
  10139.                     }
  10140.                 },
  10141.                 phoneNumber: {
  10142.                     validators: {
  10143.                         notEmpty: {
  10144.                             message: 'The phone number is required'
  10145.                         },
  10146.                         regexp: {
  10147.                             message: 'The phone number can only contain the digits, spaces, -, (, ), + and .',
  10148.                             regexp: /^[0-9\s\-()+\.]+$/
  10149.                         }
  10150.                     }
  10151.                 },
  10152.                 email: {
  10153.                     validators: {
  10154.                         notEmpty: {
  10155.                             message: 'The email address is required'
  10156.                         },
  10157.                         emailAddress: {
  10158.                             message: 'The input is not a valid email address'
  10159.                         }
  10160.                     }
  10161.                 },
  10162.                 message: {
  10163.                     validators: {
  10164.                         notEmpty: {
  10165.                             message: 'The message is required'
  10166.                         },
  10167.                         stringLength: {
  10168.                             max: 700,
  10169.                             message: 'The message must be less than 700 characters long'
  10170.                         }
  10171.                     }
  10172.                 },
  10173.                 captcha: {
  10174.                     validators: {
  10175.                         callback: {
  10176.                             message: 'Wrong answer',
  10177.                             callback: function(value, validator, $field) {
  10178.                                 var items = $('#captchaOperation').html().split(' '),
  10179.                                     sum   = parseInt(items[0]) + parseInt(items[2]);
  10180.                                 return value == sum;
  10181.                             }
  10182.                         }
  10183.                     }
  10184.                 }
  10185.             }
  10186.         })
  10187.         .on('err.form.fv', function(e) {
  10188.             // Regenerate the captcha
  10189.             generateCaptcha();
  10190.         });
  10191. });
  10192. </script>
  10193.    
  10194. </body>
  10195. </html>
Add Comment
Please, Sign In to add comment