/* Cached on Thu, 30 Jan 2025 20:50:53 */
(function($) {
    window.FormValidator = function(params) {
        var params = params;

        this.validate = function(event, submit) {
            if (submit == undefined) submit = false;
            var
                _this = $(this),
                _thisName = _this.attr('name').replace(/\[\d+]/, '[]'),
                validation;
            if (params[_thisName] == undefined)
                validation = {isValid: _this.val().length > 0};
            else {
                validation = params[_thisName](_this, event, submit)
            }
            if (validation.isValid) {
                var ff = _this.parents('.form-field:first');
                var fef = ff.find('.form-field-errors').parent();
                if (fef.is(ff))
                    _this.parents('.form-field:first').find('.form-field-errors').slideUp(200, function() {
                        $(this).remove();
                    });
                _this.parents('.form-field:first')
                    .removeClass('Validation-error')
                    .addClass('Validation-success')
            } else {
                _this.parents('.form-field:first')
                    .removeClass('Validation-success Validation-error')
                if (validation.errors != undefined && validation.errors.length > 0) {
                    var errorsUl = _this.parents('.form-field:first').find('.form-field-errors'), mustSlide = true, toSave = $();
                    if (!errorsUl.length) {
                        errorsUl = $('<ul class="form-field-errors">');
                        mustSlide = false;
                    }
                    if (mustSlide) {
                        for (var i in validation.errors)
                            toSave = toSave.add(errorsUl.find('li:contains('+validation.errors[i]+')'))
                        errorsUl.find('li').not(toSave).slideUp(200, function() {
                            $(this).remove();
                        })
                    }
                    errorsUl.addClass(validation.errorClass).append(function() {
                        var errorsList = $();
                        for (var i in validation.errors) if (errorsUl.find('li:contains('+validation.errors[i]+')').length == 0)
                            errorsList = errorsList.add($('<li>').text(validation.errors[i]).toggle(!mustSlide));
                        return errorsList;
                    })
                    _this.parents('.form-field:first')
                        .addClass('Validation-error')
                        .append(errorsUl)
                    if (!mustSlide)
                        errorsUl.slideDown(250)
                    else
                        errorsUl.find(':hidden').slideDown(250)
                } else {
                    var ff = _this.parents('.form-field:first');
                    var fef = ff.find('.form-field-errors').parent();
                    if (fef.is(ff))
                        _this.parents('.form-field:first').find('.form-field-errors').slideUp(200, function() {
                            $(this).remove();
                        });
                }
            }
        }
    }
    $(function() {
        $('body').delegate('.form-field-errors', 'click', function() {
            var ff = $(this).parents('.form-field:first');
            if (!!ff.find('.select2').length) {
                ff.find('select').select2('open');
                return;
            }
            var toFocus = $(this).parents('.form-field:first').find('input, textarea')
            if (toFocus.hasClass('text') || toFocus.hasClass('ui-combobox-input'))
                toFocus.focus().mousedown()
            else {
                if (toFocus.hasClass('ui-combobox-input'))
                    toFocus.find('input').focus()
            }
        })

        $('#email').focus(function() {
            if ($('#addWOEmail .form-alert').is(':visible')) {
                $('#addWOEmail .form-alert').slideUp(200, function() {
                    $('#submit').slideDown(200).next().removeClass('form-alert warning')
                })
            }
        })
    })
})(jQuery)