/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Tento soubor neupravujte !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*Změny jsou potřeba udělat ve zdrojových souborech v contrib/bootstrapvalidator a pak vygenerovat přes ./node_modules/grunt/bin/grunt
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Tento soubor neupravujte !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * BootstrapValidator (http://bootstrapvalidator.com)
 * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
 *
 * @version     v0.5.3, built on 2025-04-04 10:39:49 AM
 * @author      https://twitter.com/nghuuphuoc
 * @copyright   (c) 2013 - 2025 Nguyen Huu Phuoc
 * @license     Commercial: http://bootstrapvalidator.com/license/
 *              Non-commercial: http://creativecommons.org/licenses/by-nc-nd/3.0/
 */
if (typeof jQuery === 'undefined') {
    throw new Error('BootstrapValidator requires jQuery');
}

(function($) {
    var version = $.fn.jquery.split(' ')[0].split('.');
    if ((+version[0] < 2 && +version[1] < 9) || (+version[0] === 1 && +version[1] === 9 && +version[2] < 1)) {
        throw new Error('BootstrapValidator requires jQuery version 1.9.1 or higher');
    }
}(window.jQuery));

(function($) {
    var BootstrapValidator = function(form, options) {
        this.$form   = $(form);
        this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options);

        this.$invalidFields = $([]);    // Array of invalid fields
        this.$submitButton  = null;     // The submit button which is clicked to submit form
        this.$hiddenButton  = null;

        // Validating status
        this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
        this.STATUS_VALIDATING    = 'VALIDATING';
        this.STATUS_INVALID       = 'INVALID';
        this.STATUS_VALID         = 'VALID';

        // Determine the event that is fired when user change the field value
        // Most modern browsers supports input event except IE 7, 8.
        // IE 9 supports input event but the event is still not fired if I press the backspace key.
        // Get IE version
        // https://gist.github.com/padolsey/527683/#comment-7595
        var ieVersion = (function() {
            var v = 3, div = document.createElement('div'), a = div.all || [];
            while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]) {}
            return v > 4 ? v : !v;
        }());

        var el = document.createElement('div');
        this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';

        // The flag to indicate that the form is ready to submit when a remote/callback validator returns
        this._submitIfValid = null;

        // Field elements
        this._cacheFields = {};

        this._init();
    };

    BootstrapValidator.prototype = {
        constructor: BootstrapValidator,

        /**
         * Init form
         */
        _init: function() {
            var that    = this,
                options = {
                    autoFocus:      this.$form.attr('data-bv-autofocus'),
                    container:      this.$form.attr('data-bv-container'),
                    events: {
                        formInit:         this.$form.attr('data-bv-events-form-init'),
                        formError:        this.$form.attr('data-bv-events-form-error'),
                        formSuccess:      this.$form.attr('data-bv-events-form-success'),
                        fieldAdded:       this.$form.attr('data-bv-events-field-added'),
                        fieldRemoved:     this.$form.attr('data-bv-events-field-removed'),
                        fieldInit:        this.$form.attr('data-bv-events-field-init'),
                        fieldError:       this.$form.attr('data-bv-events-field-error'),
                        fieldSuccess:     this.$form.attr('data-bv-events-field-success'),
                        fieldStatus:      this.$form.attr('data-bv-events-field-status'),
                        validatorError:   this.$form.attr('data-bv-events-validator-error'),
                        validatorSuccess: this.$form.attr('data-bv-events-validator-success')
                    },
                    excluded:       this.$form.attr('data-bv-excluded'),
                    feedbackIcons: {
                        valid:      this.$form.attr('data-bv-feedbackicons-valid'),
                        invalid:    this.$form.attr('data-bv-feedbackicons-invalid'),
                        validating: this.$form.attr('data-bv-feedbackicons-validating')
                    },
                    group:          this.$form.attr('data-bv-group'),
                    live:           this.$form.attr('data-bv-live'),
                    message:        this.$form.attr('data-bv-message'),
                    onError:        this.$form.attr('data-bv-onerror'),
                    onSuccess:      this.$form.attr('data-bv-onsuccess'),
                    submitButtons:  this.$form.attr('data-bv-submitbuttons'),
                    threshold:      this.$form.attr('data-bv-threshold'),
                    trigger:        this.$form.attr('data-bv-trigger'),
                    verbose:        this.$form.attr('data-bv-verbose'),
                    fields:         {}
                };

            this.$form
                // Disable client side validation in HTML 5
                .attr('novalidate', 'novalidate')
                .addClass(this.options.elementClass)
                // Disable the default submission first
                .on('submit.bv', function(e) {
                    e.preventDefault();
                    that.validate();
                })
                .on('click.bv', this.options.submitButtons, function() {
                    that.$submitButton  = $(this);
					// The user just click the submit button
					that._submitIfValid = true;
                })
                // Find all fields which have either "name" or "data-bv-field" attribute
                .find('[name], [data-bv-field]')
                    .each(function() {
                        var $field = $(this),
                            field  = $field.attr('name') || $field.attr('data-bv-field'),
                            opts   = that._parseOptions($field);
                        if (opts) {
                            $field.attr('data-bv-field', field);
                            options.fields[field] = $.extend({}, opts, options.fields[field]);
                        }
                    });

            this.options = $.extend(true, this.options, options);

            // When pressing Enter on any field in the form, the first submit button will do its job.
            // The form then will be submitted.
            // I create a first hidden submit button
            this.$hiddenButton = $('<button/>')
                                    .attr('type', 'submit')
                                    .attr('name', this.$form.find('[type=submit]').attr('name'))
                                    .attr('value', this.$form.find('[type=submit]').attr('value'))
                                    .prependTo(this.$form)
                                    .addClass('bv-hidden-submit')
                                    .css({ display: 'none', width: 0, height: 0 });

            this.$form
                .on('click.bv', '[type="submit"]', function(e) {
                    // #746: Check if the button click handler returns false
                    if (!e.isDefaultPrevented()) {
                        var $target = $(e.target),
                            // The button might contain HTML tag
                            $button = $target.is('[type="submit"]') ? $target.eq(0) : $target.parent('[type="submit"]').eq(0);

                        // Don't perform validation when clicking on the submit button/input
                        // which aren't defined by the 'submitButtons' option
                        if (that.options.submitButtons && !$button.is(that.options.submitButtons) && !$button.is(that.$hiddenButton)) {
                            that.$form.off('submit.bv').submit();
                        }
                    }
                });

            for (var field in this.options.fields) {
                this._initField(field);
            }

            this.$form.trigger($.Event(this.options.events.formInit), {
                bv: this,
                options: this.options
            });

            // Prepare the events
            if (this.options.onSuccess) {
                this.$form.on(this.options.events.formSuccess, function(e) {
                    $.fn.bootstrapValidator.helpers.call(that.options.onSuccess, [e]);
                });
            }
            if (this.options.onError) {
                this.$form.on(this.options.events.formError, function(e) {
                    $.fn.bootstrapValidator.helpers.call(that.options.onError, [e]);
                });
            }
        },

        /**
         * Parse the validator options from HTML attributes
         *
         * @param {jQuery} $field The field element
         * @returns {Object}
         */
        _parseOptions: function($field) {
            var field      = $field.attr('name') || $field.attr('data-bv-field'),
                validators = {},
                validator,
                v,          // Validator name
                attrName,
                enabled,
                optionName,
                optionAttrName,
                optionValue,
                html5AttrName,
                html5AttrMap;

            for (v in $.fn.bootstrapValidator.validators) {
                validator    = $.fn.bootstrapValidator.validators[v];
                attrName     = 'data-bv-' + v.toLowerCase(),
                enabled      = $field.attr(attrName) + '';
                html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;

                if ((html5AttrMap && enabled !== 'false')
                    || (html5AttrMap !== true && ('' === enabled || 'true' === enabled || attrName === enabled.toLowerCase())))
                {
                    // Try to parse the options via attributes
                    validator.html5Attributes = $.extend({}, { message: 'message', onerror: 'onError', onsuccess: 'onSuccess' }, validator.html5Attributes);
                    validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]);

                    for (html5AttrName in validator.html5Attributes) {
                        optionName  = validator.html5Attributes[html5AttrName];
                        optionAttrName = 'data-bv-' + v.toLowerCase() + '-' + html5AttrName,
                        optionValue = $field.attr(optionAttrName);
                        if (optionValue) {
                            if ('true' === optionValue || optionAttrName === optionValue.toLowerCase()) {
                                optionValue = true;
                            } else if ('false' === optionValue) {
                                optionValue = false;
                            }
                            validators[v][optionName] = optionValue;
                        }
                    }
                }
            }

            var opts = {
                    autoFocus:     $field.attr('data-bv-autofocus'),
                    container:     $field.attr('data-bv-container'),
                    excluded:      $field.attr('data-bv-excluded'),
                    feedbackIcons: $field.attr('data-bv-feedbackicons'),
                    group:         $field.attr('data-bv-group'),
                    message:       $field.attr('data-bv-message'),
                    onError:       $field.attr('data-bv-onerror'),
                    onStatus:      $field.attr('data-bv-onstatus'),
                    onSuccess:     $field.attr('data-bv-onsuccess'),
                    selector:      $field.attr('data-bv-selector'),
                    threshold:     $field.attr('data-bv-threshold'),
                    trigger:       $field.attr('data-bv-trigger'),
                    verbose:       $field.attr('data-bv-verbose'),
                    validators:    validators
                },
                emptyOptions    = $.isEmptyObject(opts),        // Check if the field options are set using HTML attributes
                emptyValidators = $.isEmptyObject(validators);  // Check if the field validators are set using HTML attributes

            if (!emptyValidators || (!emptyOptions && this.options.fields && this.options.fields[field])) {
                opts.validators = validators;
                return opts;
            } else {
                return null;
            }
        },

        /**
         * Init field
         *
         * @param {String|jQuery} field The field name or field element
         */
        _initField: function(field) {
            var fields = $([]);
            switch (typeof field) {
                case 'object':
                    fields = field;
                    field  = field.attr('data-bv-field');
                    break;
                case 'string':
                    fields = this.getFieldElements(field);
                    fields.attr('data-bv-field', field);
                    break;
                default:
                    break;
            }

            // We don't need to validate non-existing fields
            if (fields.length === 0) {
                return;
            }

            if (this.options.fields[field] === null || this.options.fields[field].validators === null) {
                return;
            }

            var validatorName;
            for (validatorName in this.options.fields[field].validators) {
                if (!$.fn.bootstrapValidator.validators[validatorName]) {
                    delete this.options.fields[field].validators[validatorName];
                }
            }
            if (this.options.fields[field].enabled === null) {
                this.options.fields[field].enabled = true;
            }

            var that      = this,
                total     = fields.length,
                type      = fields.attr('type'),
                updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
                event     = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent,
                trigger   = (this.options.fields[field].trigger || this.options.trigger || event).split(' '),
                events    = $.map(trigger, function(item) {
                    return item + '.update.bv';
                }).join(' ');

            for (var i = 0; i < total; i++) {
                var $field    = fields.eq(i),
                    group     = this.options.fields[field].group || this.options.group,
                    $parent   = $field.parents(group),
                    // Allow user to indicate where the error messages are shown
                    container = ('function' === typeof (this.options.fields[field].container || this.options.container)) ? (this.options.fields[field].container || this.options.container).call(this, $field, this) : (this.options.fields[field].container || this.options.container),
                    $message  = (container && container !== 'tooltip' && container !== 'popover') ? $(container) : this._getMessageContainer($field, group);

                if (container && container !== 'tooltip' && container !== 'popover') {
                    $message.addClass('has-error');
                }

                // Remove all error messages and feedback icons
                $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove();
                $parent.find('i[data-bv-icon-for="' + field + '"]').remove();

                // Whenever the user change the field value, mark it as not validated yet
                $field.off(events).on(events, function() {
                    that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
                });
                
                // Create help block elements for showing the error messages
                $field.data('bv.messages', $message);
                for (validatorName in this.options.fields[field].validators) {
                    $field.data('bv.result.' + validatorName, this.STATUS_NOT_VALIDATED);

                    if (!updateAll || i === total - 1) {
                        $('<small/>')
                            .css('display', 'none')
                            .addClass('help-block')
                            .attr('data-bv-validator', validatorName)
                            .attr('data-bv-for', field)
                            .attr('data-bv-result', this.STATUS_NOT_VALIDATED)
                            .html(this._getMessage(field, validatorName))
                            .appendTo($message);
                    }

                    // Init the validator
                    if ('function' === typeof $.fn.bootstrapValidator.validators[validatorName].init) {
                        $.fn.bootstrapValidator.validators[validatorName].init(this, $field, this.options.fields[field].validators[validatorName]);
                    }
                }

                // Prepare the feedback icons
                // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
                if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
                    && this.options.feedbackIcons
                    && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
                    && (!updateAll || i === total - 1))
                {
                    // $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
                    // Keep error messages which are populated from back-end
                    $parent.addClass('has-feedback');
                    var $icon = $('<i/>')
                                    .css('display', 'none')
                                    .addClass('form-control-feedback')
                                    .attr('data-bv-icon-for', field)
                                    .insertAfter($field);

                    // Place it after the container of checkbox/radio
                    // so when clicking the icon, it doesn't effect to the checkbox/radio element
                    if ('checkbox' === type || 'radio' === type) {
                        var $fieldParent = $field.parent();
                        if ($fieldParent.hasClass(type)) {
                            $icon.insertAfter($fieldParent);
                        } else if ($fieldParent.parent().hasClass(type)) {
                            $icon.insertAfter($fieldParent.parent());
                        }
                    }

                    // The feedback icon does not render correctly if there is no label
                    // https://github.com/twbs/bootstrap/issues/12873
                    if ($parent.find('label').length === 0) {
                        $icon.addClass('bv-no-label');
                    }
                    // Fix feedback icons in input-group
                    if ($parent.find('.input-group').length !== 0) {
                        $icon.addClass('bv-icon-input-group')
                             .insertAfter($parent.find('.input-group').eq(0));
                    }

                    // Store the icon as a data of field element
                    if (!updateAll) {
                        $field.data('bv.icon', $icon);
                    } else if (i === total - 1) {
                        // All fields with the same name have the same icon
                        fields.data('bv.icon', $icon);
                    }
                    
                    if (container) {
                        $field
                            // Show tooltip/popover message when field gets focus
                            .off('focus.container.bv')
                            .on('focus.container.bv', function() {
                                switch (container) {
                                    case 'tooltip':
                                        $(this).data('bv.icon').tooltip('show');
                                        break;
                                    case 'popover':
                                        $(this).data('bv.icon').popover('show');
                                        break;
                                    default:
                                        break;
                                }
                            })
                            // and hide them when losing focus
                            .off('blur.container.bv')
                            .on('blur.container.bv', function() {
                                switch (container) {
                                    case 'tooltip':
                                        $(this).data('bv.icon').tooltip('hide');
                                        break;
                                    case 'popover':
                                        $(this).data('bv.icon').popover('hide');
                                        break;
                                    default:
                                        break;
                                }
                            });
                    }
                }
            }

            // Prepare the events
            fields
                .on(this.options.events.fieldSuccess, function(e, data) {
                    var onSuccess = that.getOptions(data.field, null, 'onSuccess');
                    if (onSuccess) {
                        $.fn.bootstrapValidator.helpers.call(onSuccess, [e, data]);
                    }
                })
                .on(this.options.events.fieldError, function(e, data) {
                    var onError = that.getOptions(data.field, null, 'onError');
                    if (onError) {
                        $.fn.bootstrapValidator.helpers.call(onError, [e, data]);
                    }
                })
                .on(this.options.events.fieldStatus, function(e, data) {
                    var onStatus = that.getOptions(data.field, null, 'onStatus');
                    if (onStatus) {
                        $.fn.bootstrapValidator.helpers.call(onStatus, [e, data]);
                    }
                })
                .on(this.options.events.validatorError, function(e, data) {
                    var onError = that.getOptions(data.field, data.validator, 'onError');
                    if (onError) {
                        $.fn.bootstrapValidator.helpers.call(onError, [e, data]);
                    }
                })
                .on(this.options.events.validatorSuccess, function(e, data) {
                    var onSuccess = that.getOptions(data.field, data.validator, 'onSuccess');
                    if (onSuccess) {
                        $.fn.bootstrapValidator.helpers.call(onSuccess, [e, data]);
                    }
                });

            // Set live mode
            events = $.map(trigger, function(item) {
                return item + '.live.bv';
            }).join(' ');
            switch (this.options.live) {
                case 'submitted':
                    break;
                case 'disabled':
                    fields.off(events);
                    break;
                case 'enabled':
                /* falls through */
                default:
                    fields.off(events).on(events, function() {
                        if (that._exceedThreshold($(this))) {
                            that.validateField($(this));
                        }
                    });
                    break;
            }

            fields.trigger($.Event(this.options.events.fieldInit), {
                bv: this,
                field: field,
                element: fields
            });
        },

        /**
         * Get the error message for given field and validator
         *
         * @param {String} field The field name
         * @param {String} validatorName The validator name
         * @returns {String}
         */
        _getMessage: function(field, validatorName) {
            if (!this.options.fields[field] || !$.fn.bootstrapValidator.validators[validatorName]
                || !this.options.fields[field].validators || !this.options.fields[field].validators[validatorName])
            {
                return '';
            }

            var options = this.options.fields[field].validators[validatorName];
            switch (true) {
                case (!!options.message):
                    return options.message;
                case (!!this.options.fields[field].message):
                    return this.options.fields[field].message;
                case (!!$.fn.bootstrapValidator.i18n[validatorName]):
                    return $.fn.bootstrapValidator.i18n[validatorName]['default'];
                default:
                    return this.options.message;
            }
        },

        /**
         * Get the element to place the error messages
         *
         * @param {jQuery} $field The field element
         * @param {String} group
         * @returns {jQuery}
         */
        _getMessageContainer: function($field, group) {
            var $originalField;
            var $parent = $field.parent();

            if (!$originalField) {
                $originalField = $field;
            }

            if ($parent.length === 0) {
                return $originalField.parent();
            }

            if ($parent.is(group)) {
                return $parent;
            }

            var cssClasses = $parent.attr('class');
            if (!cssClasses) {
                return this._getMessageContainer($parent, group);
            }

            cssClasses = cssClasses.split(' ');
            var n = cssClasses.length;
            for (var i = 0; i < n; i++) {
                if (/^col-(xs|sm|md|lg)-\d+$/.test(cssClasses[i]) || /^col-(xs|sm|md|lg)-offset-\d+$/.test(cssClasses[i])) {
                    return $parent;
                }
            }

            return this._getMessageContainer($parent, group);
        },

        /**
         * Called when all validations are completed
         */
        _submit: function() {
            var isValid   = this.isValid(),
                eventType = isValid ? this.options.events.formSuccess : this.options.events.formError,
                e         = $.Event(eventType);

            this.$form.trigger(e);

            // Call default handler
            // Check if whether the submit button is clicked
            if (this.$submitButton) {
                isValid ? this._onSuccess(e) : this._onError(e);
            }
        },

        /**
         * Check if the field is excluded.
         * Returning true means that the field will not be validated
         *
         * @param {jQuery} $field The field element
         * @returns {Boolean}
         */
        _isExcluded: function($field) {
            var excludedAttr = $field.attr('data-bv-excluded'),
                // I still need to check the 'name' attribute while initializing the field
                field        = $field.attr('data-bv-field') || $field.attr('name');

            switch (true) {
                case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'true' || this.options.fields[field].excluded === true)):
                case (excludedAttr === 'true'):
                case (excludedAttr === ''):
                    return true;

                case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'false' || this.options.fields[field].excluded === false)):
                case (excludedAttr === 'false'):
                    return false;

                default:
                    if (this.options.excluded) {
                        // Convert to array first
                        if ('string' === typeof this.options.excluded) {
                            this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
                                // Trim the spaces
                                return $.trim(item);
                            });
                        }

                        var length = this.options.excluded.length;
                        for (var i = 0; i < length; i++) {
                            if (('string' === typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
                                || ('function' === typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) === true))
                            {
                                return true;
                            }
                        }
                    }
                    return false;
            }
        },

        /**
         * Check if the number of characters of field value exceed the threshold or not
         *
         * @param {jQuery} $field The field element
         * @returns {Boolean}
         */
        _exceedThreshold: function($field) {
            var field     = $field.attr('data-bv-field'),
                threshold = this.options.fields[field].threshold || this.options.threshold;
            if (!threshold) {
                return true;
            }
            var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
            return (cannotType || $field.val().length >= threshold);
        },
        
        // ---
        // Events
        // ---

        /**
         * The default handler of error.form.bv event.
         * It will be called when there is a invalid field
         *
         * @param {jQuery.Event} e The jQuery event object
         */
        _onError: function(e) {
            if (e.isDefaultPrevented()) {
                return;
            }

            if ('submitted' === this.options.live) {
                // Enable live mode
                this.options.live = 'enabled';
                var that = this;
                for (var field in this.options.fields) {
                    (function(f) {
                        var fields  = that.getFieldElements(f);
                        if (fields.length) {
                            var type    = $(fields[0]).attr('type'),
                                event   = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === $(fields[0]).get(0).tagName) ? 'change' : that._changeEvent,
                                trigger = that.options.fields[field].trigger || that.options.trigger || event,
                                events  = $.map(trigger.split(' '), function(item) {
                                    return item + '.live.bv';
                                }).join(' ');

                            fields.off(events).on(events, function() {
                                if (that._exceedThreshold($(this))) {
                                    that.validateField($(this));
                                }
                            });
                        }
                    })(field);
                }
            }

            // Determined the first invalid field which will be focused on automatically
            for (var i = 0; i < this.$invalidFields.length; i++) {
                var $field    = this.$invalidFields.eq(i),
                    autoFocus = this._isOptionEnabled($field.attr('data-bv-field'), 'autoFocus');
                if (autoFocus) {
                    // Activate the tab containing the field if exists
                    var $tabPane = $field.parents('.tab-pane'), tabId;
                    if ($tabPane && (tabId = $tabPane.attr('id'))) {
                        $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
                    }

                    // Focus the field
                    $field.trigger("focus");
                    break;
                }
            }
        },

        /**
         * The default handler of success.form.bv event.
         * It will be called when all the fields are valid
         *
         * @param {jQuery.Event} e The jQuery event object
         */
        _onSuccess: function(e) {
            if (e.isDefaultPrevented()) {
                return;
            }

            // Submit the form
            this.disableSubmitButtons(true).defaultSubmit();
        },

        /**
         * Called after validating a field element
         *
         * @param {jQuery} $field The field element
         * @param {String} [validatorName] The validator name
         */
        _onFieldValidated: function($field, validatorName) {
            var field         = $field.attr('data-bv-field'),
                validators    = this.options.fields[field].validators,
                counter       = {},
                numValidators = 0,
                data          = {
                    bv: this,
                    field: field,
                    element: $field,
                    validator: validatorName,
                    result: $field.data('bv.response.' + validatorName)
                };

            // Trigger an event after given validator completes
            if (validatorName) {
                switch ($field.data('bv.result.' + validatorName)) {
                    case this.STATUS_INVALID:
                        $field.trigger($.Event(this.options.events.validatorError), data);
                        break;
                    case this.STATUS_VALID:
                        $field.trigger($.Event(this.options.events.validatorSuccess), data);
                        break;
                    default:
                        break;
                }
            }

            counter[this.STATUS_NOT_VALIDATED] = 0;
            counter[this.STATUS_VALIDATING]    = 0;
            counter[this.STATUS_INVALID]       = 0;
            counter[this.STATUS_VALID]         = 0;

            for (var v in validators) {
                if (validators[v].enabled === false) {
                    continue;
                }

                numValidators++;
                var result = $field.data('bv.result.' + v);
                if (result) {
                    counter[result]++;
                }
            }

            if (counter[this.STATUS_VALID] === numValidators) {
                // Remove from the list of invalid fields
                this.$invalidFields = this.$invalidFields.not($field);

                $field.trigger($.Event(this.options.events.fieldSuccess), data);
            }
            // If all validators are completed and there is at least one validator which doesn't pass
            else if ((counter[this.STATUS_NOT_VALIDATED] === 0 || !this._isOptionEnabled(field, 'verbose')) && counter[this.STATUS_VALIDATING] === 0 && counter[this.STATUS_INVALID] > 0) {
                // Add to the list of invalid fields
                this.$invalidFields = this.$invalidFields.add($field);

                $field.trigger($.Event(this.options.events.fieldError), data);
            }
        },

        /**
         * Check whether or not a field option is enabled
         *
         * @param {String} field The field name
         * @param {String} option The option name, "verbose", "autoFocus", for example
         * @returns {Boolean}
         */
        _isOptionEnabled: function(field, option) {
            if (this.options.fields[field] && (this.options.fields[field][option] === 'true' || this.options.fields[field][option] === true)) {
                return true;
            }
            if (this.options.fields[field] && (this.options.fields[field][option] === 'false' || this.options.fields[field][option] === false)) {
                return false;
            }
            return this.options[option] === 'true' || this.options[option] === true;
        },

        // ---
        // Public methods
        // ---

        /**
         * Retrieve the field elements by given name
         *
         * @param {String} field The field name
         * @returns {null|jQuery[]}
         */
        getFieldElements: function(field) {
            if (!this._cacheFields[field]) {
                this._cacheFields[field] = (this.options.fields[field] && this.options.fields[field].selector)
                                         ? $(this.options.fields[field].selector)
                                         : this.$form.find('[name="' + field + '"]');
            }

            return this._cacheFields[field];
        },

        /**
         * Get the field options
         *
         * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
         * @param {String} [validator] The name of validator. It null, the method returns form options
         * @param {String} [option] The option name
         * @return {String|Object}
         */
        getOptions: function(field, validator, option) {
            if (!field) {
                return option ? this.options[option] : this.options;
            }
            if ('object' === typeof field) {
                field = field.attr('data-bv-field');
            }
            if (!this.options.fields[field]) {
                return null;
            }

            var options = this.options.fields[field];
            if (!validator) {
                return option ? options[option] : options;
            }
            if (!options.validators || !options.validators[validator]) {
                return null;
            }

            return option ? options.validators[validator][option] : options.validators[validator];
        },

        /**
         * Disable/enable submit buttons
         *
         * @param {Boolean} disabled Can be true or false
         * @returns {BootstrapValidator}
         */
        disableSubmitButtons: function(disabled) {
            if (!disabled) {
                this.$form.find(this.options.submitButtons).removeAttr('disabled');
            } else if (this.options.live !== 'disabled') {
                // Don't disable if the live validating mode is disabled
                this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
            }

            return this;
        },

        /**
         * Validate the form
         *
         * @returns {BootstrapValidator}
         */
        validate: function() {
            if (!this.options.fields) {
                return this;
            }
            this.disableSubmitButtons(true);

            this._submitIfValid = false;
            for (var field in this.options.fields) {
                this.validateField(field);
            }

            this._submit();
            this._submitIfValid = true;

            return this;
        },

        /**
         * Validate given field
         *
         * @param {String|jQuery} field The field name or field element
         * @returns {BootstrapValidator}
         */
        validateField: function(field) {
            var fields = $([]);
            switch (typeof field) {
                case 'object':
                    fields = field;
                    field  = field.attr('data-bv-field');
                    break;
                case 'string':
                    fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }

            if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
                return this;
            }

            var that       = this,
                type       = fields.attr('type'),
                total      = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
                updateAll  = ('radio' === type || 'checkbox' === type),
                validators = this.options.fields[field].validators,
                verbose    = this._isOptionEnabled(field, 'verbose'),
                validatorName,
                validateResult;

            for (var i = 0; i < total; i++) {
                var $field = fields.eq(i);
                if (this._isExcluded($field)) {
                    continue;
                }

                var stop = false;
                for (validatorName in validators) {
                    if ($field.data('bv.dfs.' + validatorName)) {
                        $field.data('bv.dfs.' + validatorName).reject();
                    }
                    if (stop) {
                        break;
                    }

                    // Don't validate field if it is already done
                    var result = $field.data('bv.result.' + validatorName);
                    if (result === this.STATUS_VALID || result === this.STATUS_INVALID) {
                        this._onFieldValidated($field, validatorName);
                        continue;
                    } else if (validators[validatorName].enabled === false) {
                        this.updateStatus(updateAll ? field : $field, this.STATUS_VALID, validatorName);
                        continue;
                    }

                    $field.data('bv.result.' + validatorName, this.STATUS_VALIDATING);
                    validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);

                    // validateResult can be a $.Deferred object ...
                    if ('object' === typeof validateResult && validateResult.resolve) {
                        this.updateStatus(updateAll ? field : $field, this.STATUS_VALIDATING, validatorName);
                        $field.data('bv.dfs.' + validatorName, validateResult);

                        validateResult.done(function($f, v, response) {
                            // v is validator name
                            $f.removeData('bv.dfs.' + v).data('bv.response.' + v, response);
                            if (response.message) {
                                that.updateMessage($f, v, response.message);
                            }

                            that.updateStatus(updateAll ? $f.attr('data-bv-field') : $f, response.valid ? that.STATUS_VALID : that.STATUS_INVALID, v);

                            if (response.valid && that._submitIfValid === true) {
                                // If a remote validator returns true and the form is ready to submit, then do it
                                that._submit();
                            } else if (!response.valid && !verbose) {
                                stop = true;
                            }
                        });
                    }
                    // ... or object { valid: true/false, message: 'dynamic message' }
                    else if ('object' === typeof validateResult && validateResult.valid !== undefined && validateResult.message !== undefined) {
                        $field.data('bv.response.' + validatorName, validateResult);
                        this.updateMessage(updateAll ? field : $field, validatorName, validateResult.message);
                        this.updateStatus(updateAll ? field : $field, validateResult.valid ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
                        if (!validateResult.valid && !verbose) {
                            break;
                        }
                    }
                    // ... or a boolean value
                    else if ('boolean' === typeof validateResult) {
                        $field.data('bv.response.' + validatorName, validateResult);
                        this.updateStatus(updateAll ? field : $field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
                        if (!validateResult && !verbose) {
                            break;
                        }
                    }
                }
            }

            return this;
        },

        /**
         * Update the error message
         *
         * @param {String|jQuery} field The field name or field element
         * @param {String} validator The validator name
         * @param {String} message The message
         * @returns {BootstrapValidator}
         */
        updateMessage: function(field, validator, message) {
            var $fields = $([]);
            switch (typeof field) {
                case 'object':
                    $fields = field;
                    field   = field.attr('data-bv-field');
                    break;
                case 'string':
                    $fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }

            $fields.each(function() {
                $(this).data('bv.messages').find('.help-block[data-bv-validator="' + validator + '"][data-bv-for="' + field + '"]').html(message);
            });
        },
        
        /**
         * Update all validating results of field
         *
         * @param {String|jQuery} field The field name or field element
         * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
         * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
         * @returns {BootstrapValidator}
         */
        updateStatus: function(field, status, validatorName) {
            var fields = $([]);
            switch (typeof field) {
                case 'object':
                    fields = field;
                    field  = field.attr('data-bv-field');
                    break;
                case 'string':
                    fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }

            if (status === this.STATUS_NOT_VALIDATED) {
                // Reset the flag
                // To prevent the form from doing submit when a deferred validator returns true while typing
                this._submitIfValid = false;
            }

            var that  = this,
                type  = fields.attr('type'),
                group = this.options.fields[field].group || this.options.group,
                total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;

            for (var i = 0; i < total; i++) {
                var $field       = fields.eq(i);
                if (this._isExcluded($field)) {
                    continue;
                }

                var $parent      = $field.parents(group),
                    $message     = $field.data('bv.messages'),
                    $allErrors   = $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]'),
                    $errors      = validatorName ? $allErrors.filter('[data-bv-validator="' + validatorName + '"]') : $allErrors,
                    $icon        = $field.data('bv.icon'),
                    container    = ('function' === typeof (this.options.fields[field].container || this.options.container)) ? (this.options.fields[field].container || this.options.container).call(this, $field, this) : (this.options.fields[field].container || this.options.container),
                    isValidField = null;

                // Update status
                if (validatorName) {
                    $field.data('bv.result.' + validatorName, status);
                } else {
                    for (var v in this.options.fields[field].validators) {
                        $field.data('bv.result.' + v, status);
                    }
                }

                // Show/hide error elements and feedback icons
                $errors.attr('data-bv-result', status);

                // Determine the tab containing the element
                var $tabPane = $field.parents('.tab-pane'),
                    tabId, $tab;
                if ($tabPane && (tabId = $tabPane.attr('id'))) {
                    $tab = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent();
                }

                switch (status) {
                    case this.STATUS_VALIDATING:
                        isValidField = null;
                        this.disableSubmitButtons(true);
                        $parent.removeClass('has-success').removeClass('has-error');
                        if ($icon) {
                            $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();
                        }
                        if ($tab) {
                            $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
                        }
                        break;

                    case this.STATUS_INVALID:
                        isValidField = false;
                        this.disableSubmitButtons(true);
                        $parent.removeClass('has-success').addClass('has-error');
                        if ($icon) {
                            $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
                        }
                        if ($tab) {
                            $tab.removeClass('bv-tab-success').addClass('bv-tab-error');
                        }
                        break;

                    case this.STATUS_VALID:
                        // If the field is valid (passes all validators)
                        isValidField = ($allErrors.filter('[data-bv-result="' + this.STATUS_NOT_VALIDATED +'"]').length === 0)
                                     ? ($allErrors.filter('[data-bv-result="' + this.STATUS_VALID +'"]').length === $allErrors.length)  // All validators are completed
                                     : null;                                                                                            // There are some validators that have not done
                        if (isValidField !== null) {
                            this.disableSubmitButtons(this.$submitButton ? !this.isValid() : !isValidField);
                            if ($icon) {
                                $icon
                                    .removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).removeClass(this.options.feedbackIcons.valid)
                                    .addClass(isValidField ? this.options.feedbackIcons.valid : this.options.feedbackIcons.invalid)
                                    .show();
                            }
                        }

                        $parent.removeClass('has-error has-success').addClass(this.isValidContainer($parent) ? 'has-success' : 'has-error');
                        if ($tab) {
                            $tab.removeClass('bv-tab-success').removeClass('bv-tab-error').addClass(this.isValidContainer($tabPane) ? 'bv-tab-success' : 'bv-tab-error');
                        }
                        break;

                    case this.STATUS_NOT_VALIDATED:
                    /* falls through */
                    default:
                        isValidField = null;
                        this.disableSubmitButtons(false);
                        $parent.removeClass('has-success').removeClass('has-error');
                        if ($icon) {
                            $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide();
                        }
                        if ($tab) {
                            $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
                        }
                        break;
                }

                switch (true) {
                    // Only show the first error message if it is placed inside a tooltip ...
                    case ($icon && 'tooltip' === container):
                        (isValidField === false)
                                ? $icon.css('cursor', 'pointer').tooltip('destroy').tooltip({
                                    container: 'body',
                                    html: true,
                                    placement: 'auto top',
                                    title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
                                })
                                : $icon.css('cursor', '').tooltip('destroy');
                        break;
                    // ... or popover
                    case ($icon && 'popover' === container):
                        (isValidField === false)
                                ? $icon.css('cursor', 'pointer').popover('destroy').popover({
                                    container: 'body',
                                    content: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html(),
                                    html: true,
                                    placement: 'auto top',
                                    trigger: 'hover click'
                                })
                                : $icon.css('cursor', '').popover('destroy');
                        break;
                    default:
                        (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
                        break;
                }

                // Trigger an event
                $field.trigger($.Event(this.options.events.fieldStatus), {
                    bv: this,
                    field: field,
                    element: $field,
                    status: status
                });
                this._onFieldValidated($field, validatorName);
            }

            return this;
        },

        /**
         * Check the form validity
         *
         * @returns {Boolean}
         */
        isValid: function() {
            for (var field in this.options.fields) {
                if (!this.isValidField(field)) {
                    return false;
                }
            }

            return true;
        },

        /**
         * Check if the field is valid or not
         *
         * @param {String|jQuery} field The field name or field element
         * @returns {Boolean}
         */
        isValidField: function(field) {
            var fields = $([]);
            switch (typeof field) {
                case 'object':
                    fields = field;
                    field  = field.attr('data-bv-field');
                    break;
                case 'string':
                    fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }
            if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
                return true;
            }

            var type  = fields.attr('type'),
                total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
                $field, validatorName, status;
            for (var i = 0; i < total; i++) {
                $field = fields.eq(i);
                if (this._isExcluded($field)) {
                    continue;
                }

                for (validatorName in this.options.fields[field].validators) {
                    if (this.options.fields[field].validators[validatorName].enabled === false) {
                        continue;
                    }

                    status = $field.data('bv.result.' + validatorName);
                    if (status !== this.STATUS_VALID) {
                        return false;
                    }
                }
            }

            return true;
        },

        /**
         * Check if all fields inside a given container are valid.
         * It's useful when working with a wizard-like such as tab, collapse
         *
         * @param {String|jQuery} container The container selector or element
         * @returns {Boolean}
         */
        isValidContainer: function(container) {
            var that       = this,
                map        = {},
                $container = ('string' === typeof container) ? $(container) : container;
            if ($container.length === 0) {
                return true;
            }

            $container.find('[data-bv-field]').each(function() {
                var $field = $(this),
                    field  = $field.attr('data-bv-field');
                if (!that._isExcluded($field) && !map[field]) {
                    map[field] = $field;
                }
            });

            for (var field in map) {
                var $f = map[field];
                if ($f.data('bv.messages')
                      .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
                      .filter('[data-bv-result="' + this.STATUS_INVALID +'"]')
                      .length > 0)
                {
                    return false;
                }
            }

            return true;
        },

        /**
         * Submit the form using default submission.
         * It also does not perform any validations when submitting the form
         */
        defaultSubmit: function() {
            if (this.$submitButton) {
                // Create hidden input to send the submit buttons
                $('<input/>')
                    .attr('type', 'hidden')
                    .attr('data-bv-submit-hidden', '')
                    .attr('name', this.$submitButton.attr('name'))
                    .val(this.$submitButton.val())
                    .appendTo(this.$form);
            }

            // Submit form
            this.$form.off('submit.bv').submit();
        },

        // ---
        // Useful APIs which aren't used internally
        // ---

        /**
         * Get the list of invalid fields
         *
         * @returns {jQuery[]}
         */
        getInvalidFields: function() {
            return this.$invalidFields;
        },

        /**
         * Returns the clicked submit button
         *
         * @returns {jQuery}
         */
        getSubmitButton: function() {
            return this.$submitButton;
        },

        /**
         * Get the error messages
         *
         * @param {String|jQuery} [field] The field name or field element
         * If the field is not defined, the method returns all error messages of all fields
         * @param {String} [validator] The name of validator
         * If the validator is not defined, the method returns error messages of all validators
         * @returns {String[]}
         */
        getMessages: function(field, validator) {
            var that     = this,
                messages = [],
                $fields  = $([]);

            switch (true) {
                case (field && 'object' === typeof field):
                    $fields = field;
                    break;
                case (field && 'string' === typeof field):
                    var f = this.getFieldElements(field);
                    if (f.length > 0) {
                        var type = f.attr('type');
                        $fields = ('radio' === type || 'checkbox' === type) ? f.eq(0) : f;
                    }
                    break;
                default:
                    $fields = this.$invalidFields;
                    break;
            }

            var filter = validator ? '[data-bv-validator="' + validator + '"]' : '';
            $fields.each(function() {
                messages = messages.concat(
                    $(this)
                        .data('bv.messages')
                        .find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]' + filter)
                        .map(function() {
                            var v = $(this).attr('data-bv-validator'),
                                f = $(this).attr('data-bv-for');
                            return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html();
                        })
                        .get()
                );
            });

            return messages;
        },

        /**
         * Update the option of a specific validator
         *
         * @param {String|jQuery} field The field name or field element
         * @param {String} validator The validator name
         * @param {String} option The option name
         * @param {String} value The value to set
         * @returns {BootstrapValidator}
         */
        updateOption: function(field, validator, option, value) {
            if ('object' === typeof field) {
                field = field.attr('data-bv-field');
            }
            if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
                this.options.fields[field].validators[validator][option] = value;
                this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
            }

            return this;
        },

        /**
         * Add a new field
         *
         * @param {String|jQuery} field The field name or field element
         * @param {Object} [options] The validator rules
         * @returns {BootstrapValidator}
         */
        addField: function(field, options) {
            var fields = $([]);
            switch (typeof field) {
                case 'object':
                    fields = field;
                    field  = field.attr('data-bv-field') || field.attr('name');
                    break;
                case 'string':
                    delete this._cacheFields[field];
                    fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }

            fields.attr('data-bv-field', field);

            var type  = fields.attr('type'),
                total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;

            for (var i = 0; i < total; i++) {
                var $field = fields.eq(i);

                // Try to parse the options from HTML attributes
                var opts = this._parseOptions($field);
                opts = (opts === null) ? options : $.extend(true, options, opts);

                this.options.fields[field] = $.extend(true, this.options.fields[field], opts);

                // Update the cache
                this._cacheFields[field] = this._cacheFields[field] ? this._cacheFields[field].add($field) : $field;

                // Init the element
                this._initField(('checkbox' === type || 'radio' === type) ? field : $field);
            }

            this.disableSubmitButtons(false);
            // Trigger an event
            this.$form.trigger($.Event(this.options.events.fieldAdded), {
                field: field,
                element: fields,
                options: this.options.fields[field]
            });

            return this;
        },

        /**
         * Remove a given field
         *
         * @param {String|jQuery} field The field name or field element
         * @returns {BootstrapValidator}
         */
        removeField: function(field) {
            var fields = $([]);
            switch (typeof field) {
                case 'object':
                    fields = field;
                    field  = field.attr('data-bv-field') || field.attr('name');
                    fields.attr('data-bv-field', field);
                    break;
                case 'string':
                    fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }

            if (fields.length === 0) {
                return this;
            }

            var type  = fields.attr('type'),
                total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;

            for (var i = 0; i < total; i++) {
                var $field = fields.eq(i);

                // Remove from the list of invalid fields
                this.$invalidFields = this.$invalidFields.not($field);

                // Update the cache
                this._cacheFields[field] = this._cacheFields[field].not($field);
            }

            if (!this._cacheFields[field] || this._cacheFields[field].length === 0) {
                delete this.options.fields[field];
            }
            if ('checkbox' === type || 'radio' === type) {
                this._initField(field);
            }

            this.disableSubmitButtons(false);
            // Trigger an event
            this.$form.trigger($.Event(this.options.events.fieldRemoved), {
                field: field,
                element: fields
            });

            return this;
        },

        /**
         * Reset given field
         *
         * @param {String|jQuery} field The field name or field element
         * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
         * @returns {BootstrapValidator}
         */
        resetField: function(field, resetValue) {
            var $fields = $([]);
            switch (typeof field) {
                case 'object':
                    $fields = field;
                    field   = field.attr('data-bv-field');
                    break;
                case 'string':
                    $fields = this.getFieldElements(field);
                    break;
                default:
                    break;
            }

            var total = $fields.length;
            if (this.options.fields[field]) {
                for (var i = 0; i < total; i++) {
                    for (var validator in this.options.fields[field].validators) {
                        $fields.eq(i).removeData('bv.dfs.' + validator);
                    }
                }
            }

            // Mark field as not validated yet
            this.updateStatus(field, this.STATUS_NOT_VALIDATED);

            if (resetValue) {
                var type = $fields.attr('type');
                ('radio' === type || 'checkbox' === type) ? $fields.removeAttr('checked').removeAttr('selected') : $fields.val('');
            }

            return this;
        },

        /**
         * Reset the form
         *
         * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
         * @returns {BootstrapValidator}
         */
        resetForm: function(resetValue) {
            for (var field in this.options.fields) {
                this.resetField(field, resetValue);
            }

            this.$invalidFields = $([]);
            this.$submitButton  = null;

            // Enable submit buttons
            this.disableSubmitButtons(false);

            return this;
        },

        /**
         * Revalidate given field
         * It's used when you need to revalidate the field which its value is updated by other plugin
         *
         * @param {String|jQuery} field The field name of field element
         * @returns {BootstrapValidator}
         */
        revalidateField: function(field) {
            this.updateStatus(field, this.STATUS_NOT_VALIDATED)
                .validateField(field);

            return this;
        },

        /**
         * Enable/Disable all validators to given field
         *
         * @param {String} field The field name
         * @param {Boolean} enabled Enable/Disable field validators
         * @param {String} [validatorName] The validator name. If null, all validators will be enabled/disabled
         * @returns {BootstrapValidator}
         */
        enableFieldValidators: function(field, enabled, validatorName) {
            var validators = this.options.fields[field].validators;

            // Enable/disable particular validator
            if (validatorName
                && validators
                && validators[validatorName] && validators[validatorName].enabled !== enabled)
            {
                this.options.fields[field].validators[validatorName].enabled = enabled;
                this.updateStatus(field, this.STATUS_NOT_VALIDATED, validatorName);
            }
            // Enable/disable all validators
            else if (!validatorName && this.options.fields[field].enabled !== enabled) {
                this.options.fields[field].enabled = enabled;
                for (var v in validators) {
                    this.enableFieldValidators(field, enabled, v);
                }
            }

            return this;
        },

        /**
         * Some validators have option which its value is dynamic.
         * For example, the zipCode validator has the country option which might be changed dynamically by a select element.
         *
         * @param {jQuery|String} field The field name or element
         * @param {String|Function} option The option which can be determined by:
         * - a string
         * - name of field which defines the value
         * - name of function which returns the value
         * - a function returns the value
         *
         * The callback function has the format of
         *      callback: function(value, validator, $field) {
         *          // value is the value of field
         *          // validator is the BootstrapValidator instance
         *          // $field is the field element
         *      }
         *
         * @returns {String}
         */
        getDynamicOption: function(field, option) {
            var $field = ('string' === typeof field) ? this.getFieldElements(field) : field,
                value  = $field.val();

            // Option can be determined by
            // ... a function
            if ('function' === typeof option) {
                return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]);
            }
            // ... value of other field
            else if ('string' === typeof option) {
                var $f = this.getFieldElements(option);
                if ($f.length) {
                    return $f.val();
                }
                // ... return value of callback
                else {
                    return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]) || option;
                }
            }

            return null;
        },

        /**
         * Destroy the plugin
         * It will remove all error messages, feedback icons and turn off the events
         */
        destroy: function() {
            var field, fields, $field, validator, $icon, group;
            for (field in this.options.fields) {
                fields    = this.getFieldElements(field);
                group     = this.options.fields[field].group || this.options.group;
                for (var i = 0; i < fields.length; i++) {
                    $field = fields.eq(i);
                    $field
                        // Remove all error messages
                        .data('bv.messages')
                            .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove().end()
                            .end()
                        .removeData('bv.messages')
                        // Remove feedback classes
                        .parents(group)
                            .removeClass('has-feedback has-error has-success')
                            .end()
                        // Turn off events
                        .off('.bv')
                        .removeAttr('data-bv-field');

                    // Remove feedback icons, tooltip/popover container
                    $icon = $field.data('bv.icon');
                    if ($icon) {
                        var container = ('function' === typeof (this.options.fields[field].container || this.options.container)) ? (this.options.fields[field].container || this.options.container).call(this, $field, this) : (this.options.fields[field].container || this.options.container);
                        switch (container) {
                            case 'tooltip':
                                $icon.tooltip('destroy').remove();
                                break;
                            case 'popover':
                                $icon.popover('destroy').remove();
                                break;
                            default:
                                $icon.remove();
                                break;
                        }
                    }
                    $field.removeData('bv.icon');

                    for (validator in this.options.fields[field].validators) {
                        if ($field.data('bv.dfs.' + validator)) {
                            $field.data('bv.dfs.' + validator).reject();
                        }
                        $field.removeData('bv.result.' + validator)
                              .removeData('bv.response.' + validator)
                              .removeData('bv.dfs.' + validator);

                        // Destroy the validator
                        if ('function' === typeof $.fn.bootstrapValidator.validators[validator].destroy) {
                            $.fn.bootstrapValidator.validators[validator].destroy(this, $field, this.options.fields[field].validators[validator]);
                        }
                    }
                }
            }

            this.disableSubmitButtons(false);   // Enable submit buttons
            this.$hiddenButton.remove();        // Remove the hidden button

            this.$form
                .removeClass(this.options.elementClass)
                .off('.bv')
                .removeData('bootstrapValidator')
                // Remove generated hidden elements
                .find('[data-bv-submit-hidden]').remove().end()
                .find('[type="submit"]').off('click.bv');
        }
    };

    // Plugin definition
    $.fn.bootstrapValidator = function(option) {
        var params = arguments;
        return this.each(function() {
            var $this   = $(this),
                data    = $this.data('bootstrapValidator'),
                options = 'object' === typeof option && option;
            if (!data) {
                data = new BootstrapValidator(this, options);
                $this.data('bootstrapValidator', data);
            }

            // Allow to call plugin method
            if ('string' === typeof option) {
                data[option].apply(data, Array.prototype.slice.call(params, 1));
            }
        });
    };

    // The default options
    // Sorted in alphabetical order
    $.fn.bootstrapValidator.DEFAULT_OPTIONS = {
        // The first invalid field will be focused automatically
        autoFocus: true,

        //The error messages container. It can be:
        // - 'tooltip' if you want to use Bootstrap tooltip to show error messages
        // - 'popover' if you want to use Bootstrap popover to show error messages
        // - a CSS selector indicating the container
        // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
        // You also can define the message container for particular field
        container: null,

        // The form CSS class
        elementClass: 'bv-form',

        // Use custom event name to avoid window.onerror being invoked by jQuery
        // See https://github.com/nghuuphuoc/bootstrapvalidator/issues/630
        events: {
            formInit: 'init.form.bv',
            formError: 'validationError.form.bv',
            formSuccess: 'success.form.bv',
            fieldAdded: 'added.field.bv',
            fieldRemoved: 'removed.field.bv',
            fieldInit: 'init.field.bv',
            fieldError: 'validationError.field.bv',
            fieldSuccess: 'success.field.bv',
            fieldStatus: 'status.field.bv',
            validatorError: 'validationError.validator.bv',
            validatorSuccess: 'success.validator.bv'
        },

        // Indicate fields which won't be validated
        // By default, the plugin will not validate the following kind of fields:
        // - disabled
        // - hidden
        // - invisible
        //
        // The setting consists of jQuery filters. Accept 3 formats:
        // - A string. Use a comma to separate filter
        // - An array. Each element is a filter
        // - An array. Each element can be a callback function
        //      function($field, validator) {
        //          $field is jQuery object representing the field element
        //          validator is the BootstrapValidator instance
        //          return true or false;
        //      }
        //
        // The 3 following settings are equivalent:
        //
        // 1) ':disabled, :hidden, :not(:visible)'
        // 2) [':disabled', ':hidden', ':not(:visible)']
        // 3) [':disabled', ':hidden', function($field) {
        //        return !$field.is(':visible');
        //    }]
        excluded: [':disabled', ':hidden', ':not(:visible)'],

        // Shows ok/error/loading icons based on the field validity.
        // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
        // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
        // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
        //
        // Examples:
        // - Use Glyphicons icons:
        //  feedbackIcons: {
        //      valid: 'glyphicon glyphicon-ok',
        //      invalid: 'glyphicon glyphicon-remove',
        //      validating: 'glyphicon glyphicon-refresh'
        //  }
        // - Use FontAwesome icons:
        //  feedbackIcons: {
        //      valid: 'fa fa-check',
        //      invalid: 'fa fa-times',
        //      validating: 'fa fa-refresh'
        //  }
        feedbackIcons: {
            valid:      null,
            invalid:    null,
            validating: null
        },

        // Map the field name with validator rules
        fields: null,

        // The CSS selector for indicating the element consists the field
        // By default, each field is placed inside the <div class="form-group"></div>
        // You should adjust this option if your form group consists of many fields which not all of them need to be validated
        group: '.form-group',

        // Live validating option
        // Can be one of 3 values:
        // - enabled: The plugin validates fields as soon as they are changed
        // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
        // - submitted: The live validating is enabled after the form is submitted
        live: 'enabled',

        // Default invalid message
        message: 'This value is not valid',

        // The submit buttons selector
        // These buttons will be disabled to prevent the valid form from multiple submissions
        submitButtons: '[type="submit"]',

        // The field will not be live validated if its length is less than this number of characters
        threshold: null,

        // Whether to be verbose when validating a field or not.
        // Possible values:
        // - true:  when a field has multiple validators, all of them will be checked, and respectively - if errors occur in
        //          multiple validators, all of them will be displayed to the user
        // - false: when a field has multiple validators, validation for this field will be terminated upon the first encountered error.
        //          Thus, only the very first error message related to this field will be displayed to the user
        verbose: true
    };

    // Available validators
    $.fn.bootstrapValidator.validators  = {};

    // i18n
    $.fn.bootstrapValidator.i18n        = {};

    $.fn.bootstrapValidator.Constructor = BootstrapValidator;

    // Helper methods, which can be used in validator class
    $.fn.bootstrapValidator.helpers = {
        /**
         * Execute a callback function
         *
         * @param {String|Function} functionName Can be
         * - name of global function
         * - name of namespace function (such as A.B.C)
         * - a function
         * @param {Array} args The callback arguments
         */
        call: function(functionName, args) {
            if ('function' === typeof functionName) {
                return functionName.apply(this, args);
            } else if ('string' === typeof functionName) {
                if ('()' === functionName.substring(functionName.length - 2)) {
                    functionName = functionName.substring(0, functionName.length - 2);
                }
                var ns      = functionName.split('.'),
                    func    = ns.pop(),
                    context = window;
                for (var i = 0; i < ns.length; i++) {
                    context = context[ns[i]];
                }

                return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
            }
        },

        /**
         * Format a string
         * It's used to format the error message
         * format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
         *
         * @param {String} message
         * @param {Array} parameters
         * @returns {String}
         */
        format: function(message, parameters) {
            if (!$.isArray(parameters)) {
                parameters = [parameters];
            }

            for (var i in parameters) {
                message = message.replace('%s', parameters[i]);
            }

            return message;
        },

        /**
         * Validate a date
         *
         * @param {Number} year The full year in 4 digits
         * @param {Number} month The month number
         * @param {Number} day The day number
         * @param {Boolean} [notInFuture] If true, the date must not be in the future
         * @returns {Boolean}
         */
        date: function(year, month, day, notInFuture) {
            if (isNaN(year) || isNaN(month) || isNaN(day)) {
                return false;
            }
            if (day.length > 2 || month.length > 2 || year.length > 4) {
                return false;
            }

            day   = parseInt(day, 10);
            month = parseInt(month, 10);
            year  = parseInt(year, 10);

            if (year < 1000 || year > 9999 || month <= 0 || month > 12) {
                return false;
            }
            var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
            // Update the number of days in Feb of leap year
            if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
                numDays[1] = 29;
            }

            // Check the day
            if (day <= 0 || day > numDays[month - 1]) {
                return false;
            }

            if (notInFuture === true) {
                var currentDate  = new Date(),
                    currentYear  = currentDate.getFullYear(),
                    currentMonth = currentDate.getMonth(),
                    currentDay   = currentDate.getDate();
                return (year < currentYear
                        || (year === currentYear && month - 1 < currentMonth)
                        || (year === currentYear && month - 1 === currentMonth && day < currentDay));
            }

            return true;
        },

        /**
         * Implement Luhn validation algorithm
         * Credit to https://gist.github.com/ShirtlessKirk/2134376
         *
         * @see http://en.wikipedia.org/wiki/Luhn
         * @param {String} value
         * @returns {Boolean}
         */
        luhn: function(value) {
            var length  = value.length,
                mul     = 0,
                prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
                sum     = 0;

            while (length--) {
                sum += prodArr[mul][parseInt(value.charAt(length), 10)];
                mul ^= 1;
            }

            return (sum % 10 === 0 && sum > 0);
        },

        /**
         * Implement modulus 11, 10 (ISO 7064) algorithm
         *
         * @param {String} value
         * @returns {Boolean}
         */
        mod11And10: function(value) {
            var check  = 5,
                length = value.length;
            for (var i = 0; i < length; i++) {
                check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
            }
            return (check === 1);
        },

        /**
         * Implements Mod 37, 36 (ISO 7064) algorithm
         * Usages:
         * mod37And36('A12425GABC1234002M')
         * mod37And36('002006673085', '0123456789')
         *
         * @param {String} value
         * @param {String} [alphabet]
         * @returns {Boolean}
         */
        mod37And36: function(value, alphabet) {
            alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            var modulus = alphabet.length,
                length  = value.length,
                check   = Math.floor(modulus / 2);
            for (var i = 0; i < length; i++) {
                check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
            }
            return (check === 1);
        }
    };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
        'default': 'Please enter a valid email address'
    });

    $.fn.bootstrapValidator.validators.emailAddress = {
        html5Attributes: {
            message: 'message',
            multiple: 'multiple',
            separator: 'separator'
        },

        enableByHtml5: function($field) {
            return ('email' === $field.attr('type'));
        },

        /**
         * Return true if and only if the input value is a valid email address
         *
         * @param {BootstrapValidator} validator Validate plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} [options]
         * - multiple: Allow multiple email addresses, separated by a comma or semicolon; default is false.
         * - separator: Regex for character or characters expected as separator between addresses; default is comma /[,;]/, i.e. comma or semicolon.
         * @returns {Boolean}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }

            // Email address regular expression
            // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
            var emailRegExp   = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
                allowMultiple = options.multiple === true || options.multiple === 'true';

            if (allowMultiple) {
                var separator = options.separator || /[,;]/,
                    addresses = this._splitEmailAddresses(value, separator);

                for (var i = 0; i < addresses.length; i++) {
                    if (!emailRegExp.test(addresses[i])) {
                        return false;
                    }
                }

                return true;
            } else {
                return emailRegExp.test(value);
            }
        },

        _splitEmailAddresses: function(emailAddresses, separator) {
            var quotedFragments     = emailAddresses.split(/"/),
                quotedFragmentCount = quotedFragments.length,
                emailAddressArray   = [],
                nextEmailAddress    = '';

            for (var i = 0; i < quotedFragmentCount; i++) {
                if (i % 2 === 0) {
                    var splitEmailAddressFragments     = quotedFragments[i].split(separator),
                        splitEmailAddressFragmentCount = splitEmailAddressFragments.length;

                    if (splitEmailAddressFragmentCount === 1) {
                        nextEmailAddress += splitEmailAddressFragments[0];
                    } else {
                        emailAddressArray.push(nextEmailAddress + splitEmailAddressFragments[0]);

                        for (var j = 1; j < splitEmailAddressFragmentCount - 1; j++) {
                            emailAddressArray.push(splitEmailAddressFragments[j]);
                        }
                        nextEmailAddress = splitEmailAddressFragments[splitEmailAddressFragmentCount - 1];
                    }
                } else {
                    nextEmailAddress += '"' + quotedFragments[i];
                    if (i < quotedFragmentCount - 1) {
                        nextEmailAddress += '"';
                    }
                }
            }

            emailAddressArray.push(nextEmailAddress);
            return emailAddressArray;
        }
    };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
        'default': 'Please enter the same value'
    });

    $.fn.bootstrapValidator.validators.identical = {
        html5Attributes: {
            message: 'message',
            field: 'field'
        },

        /**
         * Check if input value equals to value of particular one
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Consists of the following key:
         * - field: The name of field that will be used to compare with current one
         * @returns {Boolean}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }

            var compareWith = validator.getFieldElements(options.field);
            if (compareWith === null || compareWith.length === 0) {
                return true;
            }

            if (value === compareWith.val()) {
                validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
                return true;
            } else {
                return false;
            }
        }
    };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
        'default': 'Please enter a valid number'
    });

    $.fn.bootstrapValidator.validators.integer = {
        enableByHtml5: function($field) {
            return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
        },

        /**
         * Return true if the input value is an integer
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Can consist of the following key:
         * - message: The invalid message
         * @returns {Boolean}
         */
        validate: function(validator, $field, options) {
            if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
                return false;
            }

            var value = $field.val();
            if (value === '') {
                return true;
            }
            return /^(?:-?(?:0|[0-9][0-9]*))$/.test(value);
        }
    };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
        'default': 'Please enter a value'
    });

    $.fn.bootstrapValidator.validators.notEmpty = {
        enableByHtml5: function($field) {
            var required = $field.attr('required') + '';
            return ('required' === required || 'true' === required);
        },

        /**
         * Check if input value is empty or not
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options
         * @returns {Boolean}
         */
        validate: function(validator, $field, options) {
            var type = $field.attr('type');
            if ('radio' === type || 'checkbox' === type) {
                return validator
                            .getFieldElements($field.attr('data-bv-field'))
                            .filter(':checked')
                            .length > 0;
            }

            if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) {
                return true;
            }

            return $.trim($field.val()) !== '';
        }
    };
}(window.jQuery));
;(function($) {
   $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
      'default': 'Please enter a valid phone number',
      countryNotSupported: 'The country code %s is not supported',
      country: 'Please enter a valid phone number in %s',
      phoneValidationWarning: 'Are you sure this is a valid phone number?',
      countries: {
         BR: 'Brazil',
         CH: 'Switzerland',
         CN: 'China',
         CZ: 'Czech Republic',
         DE: 'Germany',
         DK: 'Denmark',
         ES: 'Spain',
         FR: 'France',
         GB: 'United Kingdom',
         HU: 'Hungary',
         IT: 'Italy',
         LI: 'Liechtenstein',
         MA: 'Morocco',
         PK: 'Pakistan',
         RO: 'Romania',
         RU: 'Russia',
         SK: 'Slovakia',
         TH: 'Thailand',
         US: 'USA',
         VE: 'Venezuela'
      }
   });

   $.fn.bootstrapValidator.validators.phone = {
      html5Attributes: {
         message: 'message',
         country: 'country'
      },

      // The supported countries
      COUNTRY_CODES: ['BR', 'CH', 'CN', 'CZ', 'DE', 'DK', 'ES', 'HR', 'FR', 'GB', 'HU', 'IT', 'LI', 'MA', 'PK', 'RO', 'RU', 'SI', 'SK', 'TH', 'US', 'VE'],

      /**
       * Return true if the input value contains a valid phone number for the country
       * selected in the options
       *
       * @param {BootstrapValidator} validator Validate plugin instance
       * @param {jQuery} $field Field element
       * @param {Object} options Consist of key:
       * - message: The invalid message
       * - country: The ISO-3166 country code. It can be
       *      - A country code
       *      - Name of field which its value defines the country code
       *      - Name of callback function that returns the country code
       *      - A callback function that returns the country code
       *
       * @returns {Boolean|Object}
       */
      validate: function(validator, $field, options) {
         var value = $field.val();
         if (value === '') {
            return true;
         }

         var country = options.country;
         if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
            // Try to determine the country
            country = validator.getDynamicOption($field, country);
         }

         // pokud cislo prošlo striktnější validací, nechceme spoustet mezinarodni validaci, ktera je nize
         // ta mezinarodni validace totiz nechala projit napr. cislo: +42077722793 ktere ma jen 8 cisel misto 9
         var noExtraValidationPrefixes = [];

         var isValid = true;
         switch (country.toUpperCase()) {
            case 'BR':
               // Test: http://regexr.com/399m1
               value   = $.trim(value);
               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);
               break;

            case 'CH':
               // Test: http://regexr.com/3h627
               isValid = /^((((00)|\+)(41)([- ]?))|(0))?( *\d *){9}$/.test(value);
               break;

            case 'CN':
               // http://regexr.com/39dq4
               value   = $.trim(value);
               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);
               break;

            case 'CZ':
               // Test: http://regexr.com/39hhl
               isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
               noExtraValidationPrefixes.push('+420');
               break;

            case 'DE':
               // Test: http://regexr.com/39pkg
               value   = $.trim(value);
               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);
               break;

            case 'DK':
               // Mathing DK phone numbers with country code in 1 of 3 formats and an
               // 8 digit phone number not starting with a 0 or 1. Can have 1 space
               // between each character except inside the country code.
               // Test: http://regex101.com/r/sS8fO4/1
               value   = $.trim(value);
               isValid = (/^(\+45|0045|\(45\))?\s?[2-9](\s?\d){7}$/).test(value);
               break;

            case 'ES':
               // http://regex101.com/r/rB9mA9/1
               value   = $.trim(value);
               isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:9|6)(?:\d\D?){8}$/).test(value);
               break;

            case 'FR':
               // http://regexr.com/39a2p
               value   = $.trim(value);
               isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
               break;

            case 'GB':
               // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
               // Test: http://regexr.com/38uhv
               value   = $.trim(value);
               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);
               break;

            case 'HU':
               // https://en.wikipedia.org/wiki/Telephone_numbers_in_Hungary
               // Test: https://www.regextester.com/98279
               value   = $.trim(value);
               isValid = (/^((?:\+?3|0)6)(?:-|\()?(\d{1,2})(?:-|\))?(\d{3})-?(\d{3,4})$/).test(value);
               break;

            case 'IT':
               // https://en.wikipedia.org/wiki/Telephone_numbers_in_Italy
               // Test: https://regexr.com/3h4up
               // (1) Vyhodi '(' a ')' z hodnoty inputu
               // (2) Vyhodi ' ', '/' a '-' z hodnoty inputu
               value = value.replace(/[\\)\\(]/g, ''); // (1)
               value = value.replace(/[ /-]/g, ''); // (2)
               isValid = (/^((00|\+)39)?(3(\d{8,9})|0(\d{8,10}))$/).test(value);
               break;

            // stejny format jako SI?
            case 'HR':
               // (1) Vyhodi ' ', '/' a '-' z hodnoty inputu
               value = value.replace(/[ /-]/g, ''); // (1)
               // https://en.wikipedia.org/wiki/Telephone_numbers_in_Croatia
               // Test: http://regexr.com/3f9n5
               // V soucasne dobe nefunguje, pro zprovozneni pridat 'HR' do COUNTRY_CODES
               isValid = /^(((00)([- ]?)|\+)(385)([- ]?))?([0]?)(\d{1})?(\d{8})$/.test(value);
               break;

            case 'LI':
               // https://en.wikipedia.org/wiki/Telephone_numbers_in_Liechtenstein
               // kvuli parfimu vyzadujeme vzdy predvolbu
               isValid = /^(((00)([- ]?)|\+)(423)([- ]?))( *\d *){7}$/.test(value);
               break;

            case 'MA':
               // http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
               // Test: http://regexr.com/399n8
               value   = $.trim(value);
               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);
               break;

            case 'PK':
               // http://regex101.com/r/yH8aV9/2
               value   = $.trim(value);
               isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
               break;

            case 'RO':
               // All mobile network and land line
               // http://regexr.com/39fv1
               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);
               break;

            case 'RU':
               // http://regex101.com/r/gW7yT5/5
               isValid = (/^((8|\+7|007)[\-\.\/ ]?)?([\(\/\.]?\d{3}[\)\/\.]?[\-\.\/ ]?)?[\d\-\.\/ ]{7,10}$/g).test(value);
               break;

            case 'SI':
               // Test: https://regexr.com/4hf89
               isValid = /^((((00)([- ]?)|\+)(386)([- ]?))|(0))?([1-9])(([- ]?)(\d)){7}$/.test(value);
               break;

            case 'SK':
               // Test: http://regexr.com/3fsk4
               isValid = /^((((00)([- ]?)|\+)(421|420)([- ]?))|(0 ?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
               noExtraValidationPrefixes.push('+420');
               noExtraValidationPrefixes.push('+421');
               break;

            case 'TH':
               // http://regex101.com/r/vM5mZ4/2
               isValid = (/^0\(?([6|8-9]{2})*-([0-9]{3})*-([0-9]{4})$/).test(value);
               break;

            case 'VE':
               // http://regex101.com/r/eM2yY0/6
               value   = $.trim(value);
               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);
               break;

            case 'US':
               // Make sure US phone numbers have 10 digits
               // May start with 1, +1, or 1-; should discard
               // Area code may be delimited with (), & sections may be delimited with . or -
               // Test: http://regexr.com/38mqi
               value   = value.replace(/\D/g, '');
               isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
               break;

            /* falls through */
            default:
               /* pokud neni v seznamu zemi, kontroluji jen ze je cislo */
               isValid = (/^\d{3,14}$/).test(value);
               break;
         }


         // Pokud číslo neni validni podle vybrane zeme:
         // (1) Vyhodi mezery z hodnoty inputu
         // (2) Pokud to je CZ nebo SK, zkontroluje validitu předčíslí + délku vstupu 6-9 čísel (aby to odpovídalo validaci v engine)
         // (3) Pokud to není CZ ani SK, zkontroluje validitu předčíslí + délku vstupu 1-14 čísel
         // (4) Pokud (2) nebo (3) projde, zobrazi se varovani
         // (5) Pomocí classy .validation-warning určuji jestli zobrazit validační hlášku u validního fieldu
         // (6) Podle způsobu validace vracím buď původní zprávu nebo custom hlášku

         var customMessage = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.phone.country, $.fn.bootstrapValidator.i18n.phone.countries[country]);// (6)

         // Varovani
         if (!isValid && !noExtraValidationPrefixes.some(prefix => value.startsWith(prefix))) {
            value = value.replace(/\s/g, ''); // (1)

            if (country.toUpperCase() === "CZ" || country.toUpperCase() === "SK")  {
               isValid = (/(\+|00)(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{6,10}$/).test(value); // (2)
            } else {
               isValid = (/(\+|00)(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{1,14}$/).test(value); // (3)
            }

            if (isValid) {
               customMessage =  $.fn.bootstrapValidator.i18n.phone.phoneValidationWarning; // (4)
               $field.addClass('validation-warning'); // (5)
            }
         } else {
            $field.removeClass('validation-warning'); // (5)
         }

         return {
            valid: isValid,
            message: customMessage // (6)
         }
      }
   };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
        'default': 'Please enter a value matching the pattern'
    });

    $.fn.bootstrapValidator.validators.regexp = {
        html5Attributes: {
            message: 'message',
            regexp: 'regexp'
        },

        enableByHtml5: function($field) {
            var pattern = $field.attr('pattern');
            if (pattern) {
                return {
                    regexp: pattern
                };
            }

            return false;
        },

        /**
         * Check if the element value matches given regular expression
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Consists of the following key:
         * - regexp: The regular expression you need to check
         * @returns {Boolean}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }

            var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
            return regexp.test(value);
        }
    };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
        'default': 'Please enter a value with valid length',
        less: 'Please enter less than %s characters',
        more: 'Please enter more than %s characters',
        between: 'Please enter value between %s and %s characters long'
    });

    $.fn.bootstrapValidator.validators.stringLength = {
        html5Attributes: {
            message: 'message',
            min: 'min',
            max: 'max',
            trim: 'trim',
            utf8bytes: 'utf8Bytes'
        },

        enableByHtml5: function($field) {
            var options   = {},
                maxLength = $field.attr('maxlength'),
                minLength = $field.attr('minlength');
            if (maxLength) {
                options.max = parseInt(maxLength, 10);
            }
            if (minLength) {
                options.min = parseInt(minLength, 10);
            }

            return $.isEmptyObject(options) ? false : options;
        },

        /**
         * Check if the length of element value is less or more than given number
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Consists of following keys:
         * - min
         * - max
         * At least one of two keys is required
         * The min, max keys define the number which the field value compares to. min, max can be
         *      - A number
         *      - Name of field which its value defines the number
         *      - Name of callback function that returns the number
         *      - A callback function that returns the number
         *
         * - message: The invalid message
         * - trim: Indicate the length will be calculated after trimming the value or not. It is false, by default
         * - utf8bytes: Evaluate string length in UTF-8 bytes, default to false
         * @returns {Object}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (options.trim === true || options.trim === 'true') {
                value = $.trim(value);
            }

            if (value === '') {
                return true;
            }

            var min        = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
                max        = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
                // Credit to http://stackoverflow.com/a/23329386 (@lovasoa) for UTF-8 byte length code
                utf8Length = function(str) {
                                 var s = str.length;
                                 for (var i = str.length - 1; i >= 0; i--) {
                                     var code = str.charCodeAt(i);
                                     if (code > 0x7f && code <= 0x7ff) {
                                         s++;
                                     } else if (code > 0x7ff && code <= 0xffff) {
                                         s += 2;
                                     }
                                     if (code >= 0xDC00 && code <= 0xDFFF) {
                                         i--;
                                     }
                                 }
                                 return s;
                             },
                length     = options.utf8Bytes ? utf8Length(value) : value.length,
                isValid    = true,
                message    = options.message || $.fn.bootstrapValidator.i18n.stringLength['default'];

            if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
                isValid = false;
            }

            switch (true) {
                case (!!min && !!max):
                    message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
                    break;

                case (!!min):
                    if (parseInt(min, 10) > 1 && parseInt(min, 10) < 5 && $.fn.bootstrapValidator.i18n.stringLength.more_than_two) {
                       message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more_than_two, parseInt(min, 10));
                    } else {
                       message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more, parseInt(min, 10));
                    }
                    break;

                case (!!max):
                    message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.less, parseInt(max, 10));
                    break;

                default:
                    break;
            }

            return { valid: isValid, message: message };
        }
    };
}(window.jQuery));
;(function($) {
   $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
      'default': 'Please enter a valid VAT number',
      countryNotSupported: 'The country code %s is not supported',
      country: 'Please enter a valid VAT number in %s',
      countries: {
         AT: 'Austria',
         BE: 'Belgium',
         BG: 'Bulgaria',
         BR: 'Brazil',
         CH: 'Switzerland',
         CY: 'Cyprus',
         CZ: 'Czech Republic',
         DE: 'Germany',
         DK: 'Denmark',
         EE: 'Estonia',
         ES: 'Spain',
         FI: 'Finland',
         FR: 'France',
         GB: 'United Kingdom',
         GR: 'Greek',
         EL: 'Greek',
         HU: 'Hungary',
         HR: 'Croatia',
         IE: 'Ireland',
         IS: 'Iceland',
         IT: 'Italy',
         LT: 'Lithuania',
         LU: 'Luxembourg',
         LV: 'Latvia',
         MT: 'Malta',
         NL: 'Netherlands',
         NO: 'Norway',
         PL: 'Poland',
         PT: 'Portugal',
         RO: 'Romania',
         RU: 'Russia',
         RS: 'Serbia',
         SE: 'Sweden',
         SI: 'Slovenia',
         SK: 'Slovakia',
         VE: 'Venezuela',
         ZA: 'South Africa'
      }
   });

   $.fn.bootstrapValidator.validators.vat = {
      html5Attributes: {
         message: 'message',
         country: 'country'
      },

      // Supported country codes
      COUNTRY_CODES: [
         'AT', 'BE', 'BG', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU',
         'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SE', 'SK', 'SI', 'VE',
         'ZA'
      ],

      /**
       * Validate an European VAT number
       *
       * @param {BootstrapValidator} validator The validator plugin instance
       * @param {jQuery} $field Field element
       * @param {Object} options Consist of key:
       * - message: The invalid message
       * - country: The ISO 3166-1 country code. It can be
       *      - One of country code defined in COUNTRY_CODES
       *      - Name of field which its value defines the country code
       *      - Name of callback function that returns the country code
       *      - A callback function that returns the country code
       * @returns {Boolean|Object}
       */
      validate: function(validator, $field, options) {
         var value = $field.val();
         if (value === '') {
            return true;
         }

         var country = options.country;

         if (!country) {
            country = value.substr(0, 2);
         } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
            // Determine the country code
            country = validator.getDynamicOption($field, country);
         }

         console.log(country);


         // Pokud vybraná země není v COUNTRY_CODES, vrací že je validní
         if ($.inArray(country, this.COUNTRY_CODES) === -1) {
            return true;
         }

         var method  = ['_', country.toLowerCase()].join('');
         return this[method](value)
            ? true
            : {
               valid: false,
               message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vat.country, $.fn.bootstrapValidator.i18n.vat.countries[country.toUpperCase()])
            };
      },

      // VAT validators

      /**
       * Validate Austrian VAT number
       * Example:
       * - Valid: ATU13585627
       * - Invalid: ATU13585626
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _at: function(value) {
         if (/^ATU[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^U[0-9]{8}$/.test(value)) {
            return false;
         }

         value = value.substr(1);
         var sum    = 0,
            weight = [1, 2, 1, 2, 1, 2, 1],
            temp   = 0;
         for (var i = 0; i < 7; i++) {
            temp = parseInt(value.charAt(i), 10) * weight[i];
            if (temp > 9) {
               temp = Math.floor(temp / 10) + temp % 10;
            }
            sum += temp;
         }

         sum = 10 - (sum + 4) % 10;
         if (sum === 10) {
            sum = 0;
         }

         return (sum + '' === value.substr(7, 1));
      },

      /**
       * Validate Belgian VAT number
       * Example:
       * - Valid: BE0428759497
       * - Invalid: BE431150351
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _be: function(value) {
         if (/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0]{0,1}[0-9]{9}$/.test(value)) {
            return false;
         }

         if (value.length === 9) {
            value = '0' + value;
         }
         if (value.substr(1, 1) === '0') {
            return false;
         }

         var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
         return (sum % 97 === 0);
      },

      /**
       * Validate Bulgarian VAT number
       * Example:
       * - Valid: BG175074752,
       * BG7523169263, BG8032056031,
       * BG7542011030,
       * BG7111042925
       * - Invalid: BG175074753, BG7552A10004, BG7111042922
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _bg: function(value) {
         if (/^BG[0-9]{9,10}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9,10}$/.test(value)) {
            return false;
         }

         var sum = 0, i = 0;

         // Legal entities
         if (value.length === 9) {
            for (i = 0; i < 8; i++) {
               sum += parseInt(value.charAt(i), 10) * (i + 1);
            }
            sum = sum % 11;
            if (sum === 10) {
               sum = 0;
               for (i = 0; i < 8; i++) {
                  sum += parseInt(value.charAt(i), 10) * (i + 3);
               }
            }
            sum = sum % 10;
            return (sum + '' === value.substr(8));
         }
         // Physical persons, foreigners and others
         else if (value.length === 10) {
            // Validate Bulgarian national identification numbers
            var egn = function(value) {
                  // Check the birth date
                  var year  = parseInt(value.substr(0, 2), 10) + 1900,
                     month = parseInt(value.substr(2, 2), 10),
                     day   = parseInt(value.substr(4, 2), 10);
                  if (month > 40) {
                     year += 100;
                     month -= 40;
                  } else if (month > 20) {
                     year -= 100;
                     month -= 20;
                  }

                  if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                     return false;
                  }

                  var sum    = 0,
                     weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
                  for (var i = 0; i < 9; i++) {
                     sum += parseInt(value.charAt(i), 10) * weight[i];
                  }
                  sum = (sum % 11) % 10;
                  return (sum + '' === value.substr(9, 1));
               },
               // Validate Bulgarian personal number of a foreigner
               pnf = function(value) {
                  var sum    = 0,
                     weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
                  for (var i = 0; i < 9; i++) {
                     sum += parseInt(value.charAt(i), 10) * weight[i];
                  }
                  sum = sum % 10;
                  return (sum + '' === value.substr(9, 1));
               },
               // Finally, consider it as a VAT number
               vat = function(value) {
                  var sum    = 0,
                     weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
                  for (var i = 0; i < 9; i++) {
                     sum += parseInt(value.charAt(i), 10) * weight[i];
                  }
                  sum = 11 - sum % 11;
                  if (sum === 10) {
                     return false;
                  }
                  if (sum === 11) {
                     sum = 0;
                  }
                  return (sum + '' === value.substr(9, 1));
               };
            return (egn(value) || pnf(value) || vat(value));
         }

         return false;
      },

      /**
       * Validate Brazilian VAT number (CNPJ)
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _br: function(value) {
         if (value === '') {
            return true;
         }
         var cnpj = value.replace(/[^\d]+/g, '');
         if (cnpj === '' || cnpj.length !== 14) {
            return false;
         }

         // Remove invalids CNPJs
         if (cnpj === '00000000000000' || cnpj === '11111111111111' || cnpj === '22222222222222' ||
            cnpj === '33333333333333' || cnpj === '44444444444444' || cnpj === '55555555555555' ||
            cnpj === '66666666666666' || cnpj === '77777777777777' || cnpj === '88888888888888' ||
            cnpj === '99999999999999')
         {
            return false;
         }

         // Validate verification digits
         var length  = cnpj.length - 2,
            numbers = cnpj.substring(0, length),
            digits  = cnpj.substring(length),
            sum     = 0,
            pos     = length - 7;

         for (var i = length; i >= 1; i--) {
            sum += parseInt(numbers.charAt(length - i), 10) * pos--;
            if (pos < 2) {
               pos = 9;
            }
         }

         var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
         if (result !== parseInt(digits.charAt(0), 10)) {
            return false;
         }

         length  = length + 1;
         numbers = cnpj.substring(0, length);
         sum     = 0;
         pos     = length - 7;
         for (i = length; i >= 1; i--) {
            sum += parseInt(numbers.charAt(length - i), 10) * pos--;
            if (pos < 2) {
               pos = 9;
            }
         }

         result = sum % 11 < 2 ? 0 : 11 - sum % 11;
         return (result === parseInt(digits.charAt(1), 10));
      },

      /**
       * Validate Swiss VAT number
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _ch: function(value) {
         if (/^CHE[0-9]{9}(MWST)?$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^E[0-9]{9}(MWST)?$/.test(value)) {
            return false;
         }

         value = value.substr(1);
         var sum    = 0,
            weight = [5, 4, 3, 2, 7, 6, 5, 4];
         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         sum = 11 - sum % 11;
         if (sum === 10) {
            return false;
         }
         if (sum === 11) {
            sum = 0;
         }

         return (sum + '' === value.substr(8, 1));
      },

      /**
       * Validate Cypriot VAT number
       * Examples:
       * - Valid: CY10259033P
       * - Invalid: CY10259033Z
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _cy: function(value) {
         if (/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
            return false;
         }

         // Do not allow to start with "12"
         if (value.substr(0, 2) === '12') {
            return false;
         }

         // Extract the next digit and multiply by the counter.
         var sum         = 0,
            translation = {
               '0': 1,  '1': 0,  '2': 5,  '3': 7,  '4': 9,
               '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
            };
         for (var i = 0; i < 8; i++) {
            var temp = parseInt(value.charAt(i), 10);
            if (i % 2 === 0) {
               temp = translation[temp + ''];
            }
            sum += temp;
         }

         sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
         return (sum + '' === value.substr(8, 1));
      },

      /**
       * Validate Czech Republic VAT number
       * Can be:
       * i) Legal entities (8 digit numbers)
       * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
       * iii) Individuals without a RC (9 digit numbers beginning with 6)
       *
       * Examples:
       * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
       * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _cz: function(value) {
         if (/^CZ[0-9]{8,10}$/.test(value)) {
            value = value.substr(2);
         } else {
            return false;
         }
         if (!/^[0-9]{8,10}$/.test(value)) {
            return false;
         }

         var sum = 0,
            i   = 0;
         if (value.length === 8) {
            // Do not allow to start with '9'
            if (value.charAt(0) + '' === '9') {
               return false;
            }

            sum = 0;
            for (i = 0; i < 7; i++) {
               sum += parseInt(value.charAt(i), 10) * (8 - i);
            }
            sum = 11 - sum % 11;
            if (sum === 10) {
               sum = 0;
            }
            if (sum === 11) {
               sum = 1;
            }

            return (sum + '' === value.substr(7, 1));
         } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
            sum = 0;
            // Skip the first (which is 6)
            for (i = 0; i < 7; i++) {
               sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
            }
            sum = 11 - sum % 11;
            /*if (sum === 10) {
               sum = 0;
            }*/
            if (sum === 11) {
               sum = 1;
            }
            sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
            return (sum + '' === value.substr(8, 1));
         } else if (value.length === 9 || value.length === 10) {
            // Validate Czech birth number (Rodné číslo), which is also national identifier
            var year  = 1900 + parseInt(value.substr(0, 2), 10),
               month = parseInt(value.substr(2, 2), 10) % 50 % 20,
               day   = parseInt(value.substr(4, 2), 10);
            if (value.length === 9) {
               if (year >= 1980) {
                  year -= 100;
               }
               if (year > 1953) {
                  return false;
               }
            } else if (year < 1954) {
               year += 100;
            }

            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
               return false;
            }

            // Check that the birth date is not in the future
            if (value.length === 10) {
               var check = parseInt(value.substr(0, 9), 10) % 11;
               if (year < 1985) {
                  check = check % 10;
               }
               return (check + '' === value.substr(9, 1));
            }

            return true;
         }

         return false;
      },

      /**
       * Validate German VAT number
       * Examples:
       * - Valid: DE136695976
       * - Invalid: DE136695978
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _de: function(value) {
         if (/^DE[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)) {
            return false;
         }

         return $.fn.bootstrapValidator.helpers.mod11And10(value);
      },

      /**
       * Validate Danish VAT number
       * Example:
       * - Valid: DK13585628
       * - Invalid: DK13585627
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _dk: function(value) {
         if (/^DK[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{8}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [2, 7, 6, 5, 4, 3, 2, 1];
         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         return (sum % 11 === 0);
      },

      /**
       * Validate Estonian VAT number
       * Examples:
       * - Valid: EE100931558, EE100594102
       * - Invalid: EE100594103
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _ee: function(value) {
         if (/^EE[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
         for (var i = 0; i < 9; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         return (sum % 10 === 0);
      },

      /**
       * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
       * Can be:
       * i) DNI (Documento nacional de identidad), for Spaniards
       * ii) NIE (Número de Identificación de Extranjeros), for foreigners
       * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
       *
       * Examples:
       * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
       * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _es: function(value) {
         if (/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
            return false;
         }

         var dni = function(value) {
               var check = parseInt(value.substr(0, 8), 10);
               check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
               return (check + '' === value.substr(8, 1));
            },
            nie = function(value) {
               var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
               check = parseInt(check, 10);
               check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
               return (check + '' === value.substr(8, 1));
            },
            cif = function(value) {
               var first = value.charAt(0), check;
               if ('KLM'.indexOf(first) !== -1) {
                  // K: Spanish younger than 14 year old
                  // L: Spanish living outside Spain without DNI
                  // M: Granted the tax to foreigners who have no NIE
                  check = parseInt(value.substr(1, 8), 10);
                  check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
                  return (check + '' === value.substr(8, 1));
               } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
                  var sum    = 0,
                     weight = [2, 1, 2, 1, 2, 1, 2],
                     temp   = 0;

                  for (var i = 0; i < 7; i++) {
                     temp = parseInt(value.charAt(i + 1), 10) * weight[i];
                     if (temp > 9) {
                        temp = Math.floor(temp / 10) + temp % 10;
                     }
                     sum += temp;
                  }
                  sum = 10 - sum % 10;
                  return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
               }

               return false;
            };

         var first = value.charAt(0);
         if (/^[0-9]$/.test(first)) {
            return dni(value);
         } else if (/^[XYZ]$/.test(first)) {
            return nie(value);
         } else {
            return cif(value);
         }
      },

      /**
       * Validate Finnish VAT number
       * Examples:
       * - Valid: FI20774740
       * - Invalid: FI20774741
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _fi: function(value) {
         if (/^FI[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{8}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [7, 9, 10, 5, 8, 4, 2, 1];
         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         return (sum % 11 === 0);
      },

      /**
       * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
       * It's constructed by a SIREN number, prefixed by two characters.
       *
       * Examples:
       * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
       * - Invalid: FR84323140391
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _fr: function(value) {
         if (/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
            return false;
         }

         if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
            return false;
         }

         if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
            // First two characters are digits
            return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
         } else {
            // The first characters cann't be O and I
            var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
               check;
            // First one is digit
            if (/^[0-9]{1}$/.test(value.charAt(0))) {
               check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
            } else {
               check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
            }
            return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
         }
      },

      /**
       * Validate United Kingdom VAT number
       * Example:
       * - Valid: GB980780684
       * - Invalid: GB802311781
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _gb: function(value) {
         if (/^GB[0-9]{9}$/.test(value)             /* Standard */
            || /^GB[0-9]{12}$/.test(value)         /* Branches */
            || /^GBGD[0-9]{3}$/.test(value)        /* Government department */
            || /^GBHA[0-9]{3}$/.test(value)        /* Health authority */
            || /^GB(GD|HA)8888[0-9]{5}$/.test(value))
         {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)
            && !/^[0-9]{12}$/.test(value)
            && !/^GD[0-9]{3}$/.test(value)
            && !/^HA[0-9]{3}$/.test(value)
            && !/^(GD|HA)8888[0-9]{5}$/.test(value))
         {
            return false;
         }

         var length = value.length;
         if (length === 5) {
            var firstTwo  = value.substr(0, 2),
               lastThree = parseInt(value.substr(2), 10);
            return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
         } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
            if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
               || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
            {
               return false;
            }
            return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
         } else if (length === 9 || length === 12) {
            var sum    = 0,
               weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
            for (var i = 0; i < 9; i++) {
               sum += parseInt(value.charAt(i), 10) * weight[i];
            }
            sum = sum % 97;

            if (parseInt(value.substr(0, 3), 10) >= 100) {
               return (sum === 0 || sum === 42 || sum === 55);
            } else {
               return (sum === 0);
            }
         }

         return true;
      },

      /**
       * Validate Greek VAT number
       * Examples:
       * - Valid: GR023456780, EL094259216
       * - Invalid: EL123456781
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _gr: function(value) {
         if (/^(GR|EL)[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)) {
            return false;
         }

         if (value.length === 8) {
            value = '0' + value;
         }

         var sum    = 0,
            weight = [256, 128, 64, 32, 16, 8, 4, 2];
         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }
         sum = (sum % 11) % 10;

         return (sum + '' === value.substr(8, 1));
      },

      // EL is traditionally prefix of Greek VAT numbers
      _el: function(value) {
         return this._gr(value);
      },

      /**
       * Validate Hungarian VAT number
       * Examples:
       * - Valid: HU12892312
       * - Invalid: HU12892313
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _hu: function(value) {
         if (/^HU[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{8}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [9, 7, 3, 1, 9, 7, 3, 1];

         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         return (sum % 10 === 0);
      },

      /**
       * Validate Croatian VAT number
       * Examples:
       * - Valid: HR33392005961
       * - Invalid: HR33392005962
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _hr: function(value) {
         if (/^HR[0-9]{11}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{11}$/.test(value)) {
            return false;
         }

         return $.fn.bootstrapValidator.helpers.mod11And10(value);
      },

      /**
       * Validate Irish VAT number
       * Examples:
       * - Valid: IE6433435F, IE6433435OA, IE8D79739I
       * - Invalid: IE8D79738J
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _ie: function(value) {
         if (/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
            return false;
         }

         var getCheckDigit = function(value) {
            while (value.length < 7) {
               value = '0' + value;
            }
            var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
               sum      = 0;
            for (var i = 0; i < 7; i++) {
               sum += parseInt(value.charAt(i), 10) * (8 - i);
            }
            sum += 9 * alphabet.indexOf(value.substr(7));
            return alphabet[sum % 23];
         };

         // The first 7 characters are digits
         if (/^[0-9]+$/.test(value.substr(0, 7))) {
            // New system
            return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
         } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
            // Old system
            return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
         }

         return true;
      },

      /**
       * Validate Icelandic VAT (VSK) number
       * Examples:
       * - Valid: 12345, 123456
       * - Invalid: 1234567
       *
       * @params {String} value VAT number
       * @returns {Boolean}
       */
      _is: function(value) {
         if (/^IS[0-9]{5,6}$/.test(value)) {
            value = value.substr(2);
         }
         return /^[0-9]{5,6}$/.test(value);
      },

      /**
       * Validate Italian VAT number, which consists of 11 digits.
       * - First 7 digits are a company identifier
       * - Next 3 are the province of residence
       * - The last one is a check digit
       *
       * Examples:
       * - Valid: IT00743110157
       * - Invalid: IT00743110158
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _it: function(value) {
         if (/^IT[0-9]{11}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{11}$/.test(value)) {
            return false;
         }

         if (parseInt(value.substr(0, 7), 10) === 0) {
            return false;
         }

         var lastThree = parseInt(value.substr(7, 3), 10);
         if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
            return false;
         }

         return $.fn.bootstrapValidator.helpers.luhn(value);
      },

      /**
       * Validate Lithuanian VAT number
       * It can be:
       * - 9 digits, for legal entities
       * - 12 digits, for temporarily registered taxpayers
       *
       * Examples:
       * - Valid: LT119511515, LT100001919017, LT100004801610
       * - Invalid: LT100001919018
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _lt: function(value) {
         if (/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
            return false;
         }

         var length = value.length,
            sum    = 0,
            i;
         for (i = 0; i < length - 1; i++) {
            sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
         }
         var check = sum % 11;
         if (check === 10) {
            sum = 0;
            for (i = 0; i < length - 1; i++) {
               sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
            }
         }
         check = check % 11 % 10;
         return (check + '' === value.charAt(length - 1));
      },

      /**
       * Validate Luxembourg VAT number
       * Examples:
       * - Valid: LU15027442
       * - Invalid: LU15027443
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _lu: function(value) {
         if (/^LU[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{8}$/.test(value)) {
            return false;
         }

         return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
      },

      /**
       * Validate Latvian VAT number
       * Examples:
       * - Valid: LV40003521600, LV16117519997
       * - Invalid: LV40003521601, LV16137519997
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _lv: function(value) {
         if (/^LV[0-9]{11}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{11}$/.test(value)) {
            return false;
         }

         var first  = parseInt(value.charAt(0), 10),
            sum    = 0,
            weight = [],
            i,
            length = value.length;
         if (first > 3) {
            // Legal entity
            sum    = 0;
            weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
            for (i = 0; i < length; i++) {
               sum += parseInt(value.charAt(i), 10) * weight[i];
            }
            sum = sum % 11;
            return (sum === 3);
         } else {
            // Check birth date
            var day   = parseInt(value.substr(0, 2), 10),
               month = parseInt(value.substr(2, 2), 10),
               year  = parseInt(value.substr(4, 2), 10);
            year = year + 1800 + parseInt(value.charAt(6), 10) * 100;

            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
               return false;
            }

            // Check personal code
            sum    = 0;
            weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
            for (i = 0; i < length - 1; i++) {
               sum += parseInt(value.charAt(i), 10) * weight[i];
            }
            sum = (sum + 1) % 11 % 10;
            return (sum + '' === value.charAt(length - 1));
         }
      },

      /**
       * Validate Maltese VAT number
       * Examples:
       * - Valid: MT11679112
       * - Invalid: MT11679113
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _mt: function(value) {
         if (/^MT[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{8}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [3, 4, 6, 7, 8, 9, 10, 1];

         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         return (sum % 37 === 0);
      },

      /**
       * Validate Dutch VAT number
       * Examples:
       * - Valid: NL004495445B01
       * - Invalid: NL123456789B90
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _nl: function(value) {
         if (/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}B[0-9]{2}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [9, 8, 7, 6, 5, 4, 3, 2];
         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         sum = sum % 11;
         if (sum > 9) {
            sum = 0;
         }
         return (sum + '' === value.substr(8, 1));
      },

      /**
       * Validate Norwegian VAT number
       *
       * @see http://www.brreg.no/english/coordination/number.html
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _no: function(value) {
         if (/^NO[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [3, 2, 7, 6, 5, 4, 3, 2];
         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         sum = 11 - sum % 11;
         if (sum === 11) {
            sum = 0;
         }
         return (sum + '' === value.substr(8, 1));
      },

      /**
       * Validate Polish VAT number
       * Examples:
       * - Valid: PL8567346215
       * - Invalid: PL8567346216
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _pl: function(value) {
         if (/^PL[0-9]{10}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{10}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];

         for (var i = 0; i < 10; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         return (sum % 11 === 0);
      },

      /**
       * Validate Portuguese VAT number
       * Examples:
       * - Valid: PT501964843
       * - Invalid: PT501964842
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _pt: function(value) {
         if (/^PT[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [9, 8, 7, 6, 5, 4, 3, 2];

         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }
         sum = 11 - sum % 11;
         if (sum > 9) {
            sum = 0;
         }
         return (sum + '' === value.substr(8, 1));
      },

      /**
       * Validate Romanian VAT number
       * Examples:
       * - Valid: RO18547290
       * - Invalid: RO18547291
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _ro: function(value) {
         if (/^RO[1-9][0-9]{1,9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[1-9][0-9]{1,9}$/.test(value)) {
            return false;
         }

         var length = value.length,
            weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
            sum    = 0;
         for (var i = 0; i < length - 1; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }

         sum = (10 * sum) % 11 % 10;
         return (sum + '' === value.substr(length - 1, 1));
      },

      /**
       * Validate Russian VAT number (Taxpayer Identification Number - INN)
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _ru: function(value) {
         if (/^RU([0-9]{10}|[0-9]{12})$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^([0-9]{10}|[0-9]{12})$/.test(value)) {
            return false;
         }

         var i = 0;
         if (value.length === 10) {
            var sum    = 0,
               weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
            for (i = 0; i < 10; i++) {
               sum += parseInt(value.charAt(i), 10) * weight[i];
            }
            sum = sum % 11;
            if (sum > 9) {
               sum = sum % 10;
            }

            return (sum + '' === value.substr(9, 1));
         } else if (value.length === 12) {
            var sum1    = 0,
               weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
               sum2    = 0,
               weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];

            for (i = 0; i < 11; i++) {
               sum1 += parseInt(value.charAt(i), 10) * weight1[i];
               sum2 += parseInt(value.charAt(i), 10) * weight2[i];
            }
            sum1 = sum1 % 11;
            if (sum1 > 9) {
               sum1 = sum1 % 10;
            }
            sum2 = sum2 % 11;
            if (sum2 > 9) {
               sum2 = sum2 % 10;
            }

            return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
         }

         return false;
      },

      /**
       * Validate Serbian VAT number
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _rs: function(value) {
         if (/^RS[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{9}$/.test(value)) {
            return false;
         }

         var sum  = 10,
            temp = 0;
         for (var i = 0; i < 8; i++) {
            temp = (parseInt(value.charAt(i), 10) + sum) % 10;
            if (temp === 0) {
               temp = 10;
            }
            sum = (2 * temp) % 11;
         }

         return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
      },

      /**
       * Validate Swedish VAT number
       * Examples:
       * - Valid: SE123456789701
       * - Invalid: SE123456789101
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _se: function(value) {
         if (/^SE[0-9]{10}01$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{10}01$/.test(value)) {
            return false;
         }

         value = value.substr(0, 10);
         return $.fn.bootstrapValidator.helpers.luhn(value);
      },

      /**
       * Validate Slovenian VAT number
       * Examples:
       * - Valid: SI50223054
       * - Invalid: SI50223055
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _si: function(value) {
         if (/^SI[0-9]{8}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[0-9]{8}$/.test(value)) {
            return false;
         }

         var sum    = 0,
            weight = [8, 7, 6, 5, 4, 3, 2];

         for (var i = 0; i < 7; i++) {
            sum += parseInt(value.charAt(i), 10) * weight[i];
         }
         sum = 11 - sum % 11;
         if (sum === 10) {
            sum = 0;
         }
         return (sum + '' === value.substr(7, 1));
      },

      /**
       * Validate Slovak VAT number
       * Examples:
       * - Valid: SK2022749619
       * - Invalid: SK2022749618
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _sk: function(value) {

         if (!/^SK.*$/.test(value)) {
            return false;
         }

         if (/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
            return false;
         }

         return (parseInt(value, 10) % 11 === 0);
      },

      /**
       * Validate Venezuelan VAT number (RIF)
       * Examples:
       * - Valid: VEJ309272292, VEV242818101, VEJ000126518, VEJ000458324, J309272292, V242818101, J000126518, J000458324
       * - Invalid: VEJ309272293, VEV242818100, J000126519, J000458323
       *
       * @param {String} value VAT number
       * @returns {Boolean}
       */
      _ve: function(value) {
         if (/^VE[VEJPG][0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }
         if (!/^[VEJPG][0-9]{9}$/.test(value)) {
            return false;
         }

         var types  = {
               'V': 4,
               'E': 8,
               'J': 12,
               'P': 16,
               'G': 20
            },
            sum    = types[value.charAt(0)],
            weight = [3, 2, 7, 6, 5, 4, 3, 2];

         for (var i = 0; i < 8; i++) {
            sum += parseInt(value.charAt(i + 1), 10) * weight[i];
         }

         sum = 11 - sum % 11;
         if (sum === 11 || sum === 10) {
            sum = 0;
         }
         return (sum + '' === value.substr(9, 1));
      },

      /**
       * Validate South African VAT number
       * Examples:
       * - Valid: 4012345678
       * - Invalid: 40123456789, 3012345678
       *
       * @params {String} value VAT number
       * @returns {Boolean}
       */
      _za: function(value) {
         if (/^ZA4[0-9]{9}$/.test(value)) {
            value = value.substr(2);
         }

         return /^4[0-9]{9}$/.test(value);
      },
   };
}(window.jQuery));
;(function($) {
   $.fn.bootstrapValidator.i18n.vatSimple = $.extend($.fn.bootstrapValidator.i18n.vatSimple || {}, {
      'default': 'Must begin with the country code (two letters) and contain a minimum of two additional characters.',
   });

   $.fn.bootstrapValidator.validators.vatSimple = {
      html5Attributes: {
         message: 'message'
      },

      /**
       * Validate simple VAT number
       *
       * @param {BootstrapValidator} validator The validator plugin instance
       * @param {jQuery} $field Field element
       * @param {Object} options Consist of key:
       *
       * Examples:
       * - Starts with two letter chars (Country code)
       * - Minimum 7 chars
       *
       * @returns {Boolean}
       */
      validate: function(validator, $field, options) {
         var value = $field.val();
         if (value === '') {
            return true;
         }

         if (/^[A-Za-z]{2}[0-9A-Za-z]{2,}$/.test(value)) {
            return true;
         }

         return {
            valid: false,
            message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vatSimple.default)
         }
      }
   };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.zipCode = $.extend($.fn.bootstrapValidator.i18n.zipCode || {}, {
        'default': 'Please enter a valid postal code',
        countryNotSupported: 'The country code %s is not supported',
        country: 'Please enter a valid postal code in %s',
        countries: {
            AT: 'Austria',
            BR: 'Brazil',
            CA: 'Canada',
            CH: 'Switzerland',
            CZ: 'Czech Republic',
            DE: 'Germany',
            DK: 'Denmark',
            FR: 'France',
            GB: 'United Kingdom',
            HR: 'Croatia',
            IE: 'Ireland',
            IT: 'Italy',
            LI: 'Liechtenstein',
            MA: 'Morocco',
            NL: 'Netherlands',
            PT: 'Portugal',
            RO: 'Romania',
            RU: 'Russia',
            SE: 'Sweden',
            SI: 'Slovenian',
            SG: 'Singapore',
            SK: 'Slovakia',
            US: 'USA'
        }
    });

    $.fn.bootstrapValidator.validators.zipCode = {
        html5Attributes: {
            message: 'message',
            country: 'country'
        },

        COUNTRY_CODES: [ 'AT', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'FR', 'GB', 'HR', 'IE', 'IT', 'LI', 'MA', 'NL', 'PT', 'RO', 'RU', 'SE', 'SI', 'SG', 'SK', 'US', 'PL'],

        /**
         * Return true if and only if the input value is a valid country zip code
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Consist of key:
         * - message: The invalid message
         * - country: The country
         *
         * The country can be defined by:
         * - An ISO 3166 country code
         * - Name of field which its value defines the country code
         * - Name of callback function that returns the country code
         * - A callback function that returns the country code
         *
         * callback: function(value, validator, $field) {
         *      // value is the value of field
         *      // validator is the BootstrapValidator instance
         *      // $field is jQuery element representing the field
         * }
         *
         * @returns {Boolean|Object}
         */
        validate: function(validator, $field, options) {
            var value = $field.val().trim();
            if (value === '' || !options.country) {
                return true;
            }

            var country = options.country;
            if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
                // Try to determine the country
                country = validator.getDynamicOption($field, country);
            }

            if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
                return true;
                return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, country) };
            }

            var isValid = false;
            country = country.toUpperCase();
            switch (country) {
                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria
                case 'AT':
                    isValid = /^([1-9]{1})(\d{3})$/.test(value);
                    break;

                case 'BR':
                    isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
                    break;

                case 'CA':
                    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);
                    break;

                case 'CH':
                    isValid = /^([1-9]{1})(\d{3})$/.test(value);
                    break;

                case 'CZ':
                    // Test: http://regexr.com/39hhr
                    isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
                    break;

                // http://stackoverflow.com/questions/7926687/regular-expression-german-zip-codes
                case 'DE':
                    isValid = /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$/.test(value);
                    break;

                case 'DK':
                    isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
                    break;

                // http://en.wikipedia.org/wiki/Postal_codes_in_France
                case 'FR':
                    isValid = /^[0-9]{5}$/i.test(value);
                    break;

                case 'GB':
                    isValid = this._gb(value);
                    break;

                case 'HR':
                    // Test: http://regexr.com/39hhr
                    isValid = /^(\d{5})$/.test(value);
                    break;

                // http://www.eircode.ie/docs/default-source/Common/prepare-your-business-for-eircode---published-v2.pdf?sfvrsn=2
                // Test: http://refiddle.com/1kpl
                case 'IE':
                    isValid = /^(D6W|[ACDEFHKNPRTVWXY]\d{2})\s[0-9ACDEFHKNPRTVWXY]{4}$/.test(value);
                    break;

                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
                case 'IT':
                    isValid = /^(I-|IT-)?\d{5}$/i.test(value);
                    break;

                // Stejne jako CH
               // https://en.wikipedia.org/wiki/Postal_codes_in_Switzerland_and_Liechtenstein
                case 'LI':
                    isValid = /^([1-9]{1})(\d{3})$/.test(value);
                    break;

                // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
                case 'MA':
                    isValid = /^[1-9][0-9]{4}$/i.test(value);
                    break;

                // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
                case 'NL':
                    isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
                    break;

                // Test: http://refiddle.com/1l2t
                case 'PT':
                    isValid = /^[1-9]\d{3}-\d{3}$/.test(value);
                    break;

                case 'RO':
                    isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})[0-9]{4}$/i.test(value);
                    break;

                case 'RU':
                    isValid = /^[0-9]{6}$/i.test(value);
                    break;

                // https://en.wikipedia.org/wiki/Postal_codes_in_Slovenia
                case 'SI':
                    isValid = /^[0-9]{4}$/i.test(value);
                    break;

                case 'SE':
                    isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
                    break;

                case 'SG':
                    isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
                    break;

                case 'SK':
                    // Test: http://regexr.com/39hhr
                    isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
                    break;

               case 'PL':
                  isValid = /^[0-9]{2}-[0-9]{3}$/.test(value);
                  break;
                case 'US':
                /* falls through */
                default:
                    isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
                    break;
            }

            return {
                valid: isValid,
                message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.zipCode.country, $.fn.bootstrapValidator.i18n.zipCode.countries[country])
            };
        },

        /**
         * Validate United Kingdom postcode
         * Examples:
         * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
         * - Special cases:
         * AI-2640, ASCN 1ZZ, GIR 0AA
         *
         * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
         * @param {String} value The postcode
         * @returns {Boolean}
         */
        _gb: function(value) {
            var firstChar  = '[ABCDEFGHIJKLMNOPRSTUWYZ]',     // Does not accept QVX
                secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]',     // Does not accept IJZ
                thirdChar  = '[ABCDEFGHJKPMNRSTUVWXY]',
                fourthChar = '[ABEHMNPRVWXY]',
                fifthChar  = '[ABDEFGHJLNPQRSTUWXYZ]',
                regexps    = [
                    // AN NAA, ANN NAA, AAN NAA, AANN NAA format
                    new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
                    // ANA NAA
                    new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
                    // AANA NAA
                    new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),

                    new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'),        // BFPO postcodes
                    /^(GIR)(\s*)(0AA)$/i,                       // Special postcode GIR 0AA
                    /^(BFPO)(\s*)([0-9]{1,4})$/i,               // Standard BFPO numbers
                    /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i,        // c/o BFPO numbers
                    /^([A-Z]{4})(\s*)(1ZZ)$/i,                  // Overseas Territories
                    /^(AI-2640)$/i                              // Anguilla
                ];
            for (var i = 0; i < regexps.length; i++) {
                if (regexps[i].test(value)) {
                    return true;
                }
            }

            return false;
        }
    };
}(window.jQuery));
;(function($) {
   $.fn.bootstrapValidator.i18n.charset = $.extend($.fn.bootstrapValidator.i18n.charset || {}, {
      default: 'Prosím používejte pouze latinku'
   });

   $.fn.bootstrapValidator.validators.charset = {
      html5Attributes: {
         encoding: 'encoding'
      },

      CHARSETS: ['windows-1250'],

      /**
       * Return true if the input value matches selected charset.
       *
       * @param {BootstrapValidator} validator The validator plugin instance
       * @param {jQuery} $field Field element
       * @param {Object} options Can consist of the following keys:
       * - encoding: character set to match agains
       * @returns {Boolean}
       */
      validate: function(validator, $field, options) {
         var value = $field.val();
         if (value === '') {
            return true;
         }

         var encoding = options.encoding;
         if (typeof encoding !== 'string' || $.inArray(encoding, this.CHARSETS) === -1) {
            encoding = this.CHARSETS[0];
         }

         var isValid = true;

         switch (encoding) {
            case 'windows-1250':
               isValid = /^[A-Za-z0-9 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~€‚„…†‡‰Š‹ŚŤŽŹ‘’“”•–—™š›śťžźˇ˘Ł¤Ą¦§¨©Ş«¬®Ż°±˛ł´µ¶·¸ąş»Ľ˝ľżŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢßŕáâăäĺćçčéęëěíîďđńňóôőö÷řůúűüýţ˙]*$/.test(
                  value
               );
               break;
         }

         return isValid;
      }
   };
})(window.jQuery);
;(function($) {
    $.fn.bootstrapValidator.i18n.iban = $.extend($.fn.bootstrapValidator.i18n.iban || {}, {
        'default': 'Please enter a valid IBAN number',
        countryNotSupported: 'The country code %s is not supported',
        country: 'Please enter a valid IBAN number in %s',
        countries: {
            AD: 'Andorra',
            AE: 'United Arab Emirates',
            AL: 'Albania',
            AO: 'Angola',
            AT: 'Austria',
            AZ: 'Azerbaijan',
            BA: 'Bosnia and Herzegovina',
            BE: 'Belgium',
            BF: 'Burkina Faso',
            BG: 'Bulgaria',
            BH: 'Bahrain',
            BI: 'Burundi',
            BJ: 'Benin',
            BR: 'Brazil',
            CH: 'Switzerland',
            CI: 'Ivory Coast',
            CM: 'Cameroon',
            CR: 'Costa Rica',
            CV: 'Cape Verde',
            CY: 'Cyprus',
            CZ: 'Czech Republic',
            DE: 'Germany',
            DK: 'Denmark',
            DO: 'Dominican Republic',
            DZ: 'Algeria',
            EE: 'Estonia',
            ES: 'Spain',
            FI: 'Finland',
            FO: 'Faroe Islands',
            FR: 'France',
            GB: 'United Kingdom',
            GE: 'Georgia',
            GI: 'Gibraltar',
            GL: 'Greenland',
            GR: 'Greece',
            GT: 'Guatemala',
            HR: 'Croatia',
            HU: 'Hungary',
            IE: 'Ireland',
            IL: 'Israel',
            IR: 'Iran',
            IS: 'Iceland',
            IT: 'Italy',
            JO: 'Jordan',
            KW: 'Kuwait',
            KZ: 'Kazakhstan',
            LB: 'Lebanon',
            LI: 'Liechtenstein',
            LT: 'Lithuania',
            LU: 'Luxembourg',
            LV: 'Latvia',
            MC: 'Monaco',
            MD: 'Moldova',
            ME: 'Montenegro',
            MG: 'Madagascar',
            MK: 'Macedonia',
            ML: 'Mali',
            MR: 'Mauritania',
            MT: 'Malta',
            MU: 'Mauritius',
            MZ: 'Mozambique',
            NL: 'Netherlands',
            NO: 'Norway',
            PK: 'Pakistan',
            PL: 'Poland',
            PS: 'Palestine',
            PT: 'Portugal',
            QA: 'Qatar',
            RO: 'Romania',
            RS: 'Serbia',
            SA: 'Saudi Arabia',
            SE: 'Sweden',
            SI: 'Slovenia',
            SK: 'Slovakia',
            SM: 'San Marino',
            SN: 'Senegal',
            TN: 'Tunisia',
            TR: 'Turkey',
            VG: 'Virgin Islands, British'
        }
    });

    $.fn.bootstrapValidator.validators.iban = {
        html5Attributes: {
            message: 'message',
            country: 'country'
        },

        // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
        // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
        REGEX: {
            AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}',                       // Andorra
            AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}',                                  // United Arab Emirates
            AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}',                               // Albania
            AO: 'AO[0-9]{2}[0-9]{21}',                                          // Angola
            AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}',                                  // Austria
            AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}',                               // Azerbaijan
            BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}',                   // Bosnia and Herzegovina
            BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}',                           // Belgium
            BF: 'BF[0-9]{2}[0-9]{23}',                                          // Burkina Faso
            BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}',                // Bulgaria
            BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}',                               // Bahrain
            BI: 'BI[0-9]{2}[0-9]{12}',                                          // Burundi
            BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Benin
            BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]',             // Brazil
            CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}',                               // Switzerland
            CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Ivory Coast
            CM: 'CM[0-9]{2}[0-9]{23}',                                          // Cameroon
            CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}',                                  // Costa Rica
            CV: 'CV[0-9]{2}[0-9]{21}',                                          // Cape Verde
            CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}',                       // Cyprus
            CZ: 'CZ[0-9]{2}[0-9]{20}',                                          // Czech Republic
            DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}',                                  // Germany
            DK: 'DK[0-9]{2}[0-9]{14}',                                          // Denmark
            DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}',                               // Dominican Republic
            DZ: 'DZ[0-9]{2}[0-9]{20}',                                          // Algeria
            EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}',                  // Estonia
            ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}',          // Spain
            FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}',                           // Finland
            FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}',                           // Faroe Islands
            FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}',               // France
            GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}',                           // United Kingdom
            GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}',                                  // Georgia
            GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}',                               // Gibraltar
            GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}',                           // Greenland
            GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}',                       // Greece
            GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}',                            // Guatemala
            HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}',                                  // Croatia
            HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}',          // Hungary
            IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}',                           // Ireland
            IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}',                          // Israel
            IR: 'IR[0-9]{2}[0-9]{22}',                                          // Iran
            IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}',                  // Iceland
            IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}',               // Italy
            JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}',                 // Jordan
            KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}',                                  // Kuwait
            KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}',                               // Kazakhstan
            LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}',                               // Lebanon
            LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}',                               // Liechtenstein
            LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}',                                  // Lithuania
            LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}',                               // Luxembourg
            LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}',                               // Latvia
            MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}',               // Monaco
            MD: 'MD[0-9]{2}[A-Z0-9]{20}',                                       // Moldova
            ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}',                          // Montenegro
            MG: 'MG[0-9]{2}[0-9]{23}',                                          // Madagascar
            MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}',                       // Macedonia
            ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Mali
            MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}',                        // Mauritania
            MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}',                       // Malta
            MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}',  // Mauritius
            MZ: 'MZ[0-9]{2}[0-9]{21}',                                          // Mozambique
            NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}',                                  // Netherlands
            NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}',                           // Norway
            PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}',                               // Pakistan
            PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}',                                  // Poland
            PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}',                               // Palestinian
            PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}',                  // Portugal
            QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}',                               // Qatar
            RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}',                               // Romania
            RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}',                          // Serbia
            SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}',                               // Saudi Arabia
            SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}',                          // Sweden
            SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}',                           // Slovenia
            SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}',                          // Slovakia
            SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}',               // San Marino
            SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}',                                  // Senegal
            TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}',                        // Tunisia
            TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}',                    // Turkey
            VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}'                                   // Virgin Islands, British
        },

        /**
         * Validate an International Bank Account Number (IBAN)
         * To test it, take the sample IBAN from
         * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Can consist of the following keys:
         * - message: The invalid message
         * - country: The ISO 3166-1 country code. It can be
         *      - A country code
         *      - Name of field which its value defines the country code
         *      - Name of callback function that returns the country code
         *      - A callback function that returns the country code
         * @returns {Boolean|Object}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }

            value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
            var country = options.country;
            if (!country) {
                country = value.substr(0, 2);
            } else if (typeof country !== 'string' || !this.REGEX[country]) {
                // Determine the country code
                country = validator.getDynamicOption($field, country);
            }

            if (!this.REGEX[country]) {
                return {
                    valid: false,
                    message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.iban.countryNotSupported, country)
                };
            }

            if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
                return {
                    valid: false,
                    message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
                };
            }

            value = value.substr(4) + value.substr(0, 4);
            value = $.map(value.split(''), function(n) {
                var code = n.charCodeAt(0);
                return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
                        // Replace A, B, C, ..., Z with 10, 11, ..., 35
                        ? (code - 'A'.charCodeAt(0) + 10)
                        : n;
            });
            value = value.join('');

            var temp   = parseInt(value.substr(0, 1), 10),
                length = value.length;
            for (var i = 1; i < length; ++i) {
                temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
            }

            return {
                valid: (temp === 1),
                message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
            };
        }
    };
}(window.jQuery));
;(function($) {
    $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
        'default': 'Please enter a value greater than or equal to %s',
        notInclusive: 'Please enter a value greater than %s'
    });

    $.fn.bootstrapValidator.validators.greaterThan = {
        html5Attributes: {
            message: 'message',
            value: 'value',
            inclusive: 'inclusive'
        },

        enableByHtml5: function($field) {
            var type = $field.attr('type'),
                min  = $field.attr('min');
            if (min && type !== 'date') {
                return {
                    value: min
                };
            }

            return false;
        },

        /**
         * Return true if the input value is greater than or equals to given number
         *
         * @param {BootstrapValidator} validator Validate plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Can consist of the following keys:
         * - value: Define the number to compare with. It can be
         *      - A number
         *      - Name of field which its value defines the number
         *      - Name of callback function that returns the number
         *      - A callback function that returns the number
         *
         * - inclusive [optional]: Can be true or false. Default is true
         * - message: The invalid message
         * @returns {Boolean|Object}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }
            
            value = this._format(value);
            if (!$.isNumeric(value)) {
                return false;
            }

            var compareTo      = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
                compareToValue = this._format(compareTo);

            value = parseFloat(value);
			return (options.inclusive === true || options.inclusive === undefined)
                    ? {
                        valid: value >= compareToValue,
                        message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan['default'], compareTo)
                    }
                    : {
                        valid: value > compareToValue,
                        message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
                    };
        },

        _format: function(value) {
            return (value + '').replace(',', '.');
        }
    };
}(window.jQuery));
;(function($) {
   $.fn.bootstrapValidator.i18n.bankAccount = $.extend($.fn.bootstrapValidator.i18n.bankAccount || {}, {
      'default': 'Please enter valid IBAN'
   });

   $.fn.bootstrapValidator.validators.bankAccount = {
      /**
       * Return true if the input value is a czech bank number or IBAN.
       *
       * @param {BootstrapValidator} validator The validator plugin instance
       * @param {jQuery} $field Field element
       * @param {Object} options Can consist of the following keys:
       * - message: The invalid message
       * @returns {Boolean}
       */
      validate: function(validator, $field, options) {
         var value = $field.val();
         var ibanValidator = $.fn.bootstrapValidator.validators.iban;
         if(ibanValidator.validate(validator, $field, options).valid || this.checkBankAccountNumber(value) || value === "") {
            return true;
         }
         return false;
      },
      checkBankAccountNumber: function(account) {
         var matches = /^(([0-9]{0,6})-)?([0-9]{1,10})\/([0-9]{4,6})$/.exec(account);
         if (!matches) {
            return false;
         }
         if (matches[2]) {
            return this.checkDigit11(matches[2]) && this.checkDigit11(matches[3]);
         } else {
            return this.checkDigit11(matches[3]);
         }
      },
      checkDigit11: function(n, x) {
         var l = n.length - 1, i = 0, v = 0;
         var weights = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6];

         for (i = 0; i <= l; i++) {
            v += parseInt(n[l - i], 10) * weights[i];
         }
         return v % 11 == 0;
      }
   };
}(window.jQuery));
