function runAllForms() {
    $(".delete-after-load").remove(), $.fn.slider && $(".slider").slider(), $.fn.select2 && $(".select2").each(function () {
        var a = $(this), b = a.attr("data-select-width") || "100%", c = !!a.attr("data-select-search");
        a.select2({allowClear: !0, width: b, showSearchInput: c}), a = null
    }), $.fn.mask && $("[data-mask]").each(function () {
        var a = $(this), b = a.attr("data-mask") || "error...", c = a.attr("data-mask-placeholder") || "X";
        a.mask(b, {placeholder: c}), a = null
    }), $.fn.autocomplete && $("[data-autocomplete]").each(function () {
        var a = $(this),
            b = a.data("autocomplete") || ["The", "Quick", "Brown", "Fox", "Jumps", "Over", "Three", "Lazy", "Dogs"];
        a.autocomplete({source: b}), a = null
    }), $.fn.datepicker && $(".datepicker").each(function () {
        var a = $(this), b = a.attr("data-dateformat") || "dd.mm.yy";
        a.datepicker({
            dateFormat: b,
            prevText: '<i class="fa fa-chevron-left"></i>',
            nextText: '<i class="fa fa-chevron-right"></i>',
            firstDay: 1
        }), a = null
    }), $("button[data-loading-text]").on("click", function () {
        var a = $(this);
        a.button("loading"), setTimeout(function () {
            a.button("reset")
        }, 3e3), a = null
    })
}

function runAllCharts() {
    if ($.fn.sparkline) {
        var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J,
            K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, aa, ba, ca, da, ea, fa, ga, ha, ia, ja, ka, la, ma, na,
            oa, pa, qa, ra, sa;
        $(".sparkline").each(function () {
            var ta = $(this), ua = ta.data("sparkline-type") || "bar";
            if ("bar" == ua && (a = ta.data("sparkline-bar-color") || ta.css("color") || "#0000f0", b = ta.data("sparkline-height") || "26px", c = ta.data("sparkline-barwidth") || 5, d = ta.data("sparkline-barspacing") || 2, e = ta.data("sparkline-negbar-color") || "#A90329", f = ta.data("sparkline-barstacked-color") || ["#A90329", "#0099c6", "#98AA56", "#da532c", "#4490B1", "#6E9461", "#990099", "#B4CAD3"], ta.sparkline("html", {
                barColor: a,
                type: ua,
                height: b,
                barWidth: c,
                barSpacing: d,
                stackedBarColor: f,
                negBarColor: e,
                zeroAxis: "false"
            }), ta = null), "line" == ua && (b = ta.data("sparkline-height") || "20px", aa = ta.data("sparkline-width") || "90px", g = ta.data("sparkline-line-color") || ta.css("color") || "#0000f0", h = ta.data("sparkline-line-width") || 1, i = ta.data("fill-color") || "#c0d0f0", j = ta.data("sparkline-spot-color") || "#f08000", k = ta.data("sparkline-minspot-color") || "#ed1c24", l = ta.data("sparkline-maxspot-color") || "#f08000", m = ta.data("sparkline-highlightspot-color") || "#50f050", n = ta.data("sparkline-highlightline-color") || "f02020", o = ta.data("sparkline-spotradius") || 1.5, thisChartMinYRange = ta.data("sparkline-min-y") || "undefined", thisChartMaxYRange = ta.data("sparkline-max-y") || "undefined", thisChartMinXRange = ta.data("sparkline-min-x") || "undefined", thisChartMaxXRange = ta.data("sparkline-max-x") || "undefined", thisMinNormValue = ta.data("min-val") || "undefined", thisMaxNormValue = ta.data("max-val") || "undefined", thisNormColor = ta.data("norm-color") || "#c0c0c0", thisDrawNormalOnTop = ta.data("draw-normal") || !1, ta.sparkline("html", {
                type: "line",
                width: aa,
                height: b,
                lineWidth: h,
                lineColor: g,
                fillColor: i,
                spotColor: j,
                minSpotColor: k,
                maxSpotColor: l,
                highlightSpotColor: m,
                highlightLineColor: n,
                spotRadius: o,
                chartRangeMin: thisChartMinYRange,
                chartRangeMax: thisChartMaxYRange,
                chartRangeMinX: thisChartMinXRange,
                chartRangeMaxX: thisChartMaxXRange,
                normalRangeMin: thisMinNormValue,
                normalRangeMax: thisMaxNormValue,
                normalRangeColor: thisNormColor,
                drawNormalOnTop: thisDrawNormalOnTop
            }), ta = null), "pie" == ua && (p = ta.data("sparkline-piecolor") || ["#B4CAD3", "#4490B1", "#98AA56", "#da532c", "#6E9461", "#0099c6", "#990099", "#717D8A"], q = ta.data("sparkline-piesize") || 90, r = ta.data("border-color") || "#45494C", s = ta.data("sparkline-offset") || 0, ta.sparkline("html", {
                type: "pie",
                width: q,
                height: q,
                tooltipFormat: '<span style="color: {{color}}">&#9679;</span> ({{percent.1}}%)',
                sliceColors: p,
                borderWidth: 1,
                offset: s,
                borderColor: r
            }), ta = null), "box" == ua && (t = ta.data("sparkline-width") || "auto", u = ta.data("sparkline-height") || "auto", v = ta.data("sparkline-boxraw") || !1, w = ta.data("sparkline-targetval") || "undefined", x = ta.data("sparkline-min") || "undefined", y = ta.data("sparkline-max") || "undefined", z = ta.data("sparkline-showoutlier") || !0, A = ta.data("sparkline-outlier-iqr") || 1.5, B = ta.data("sparkline-spotradius") || 1.5, C = ta.css("color") || "#000000", D = ta.data("fill-color") || "#c0d0f0", E = ta.data("sparkline-whis-color") || "#000000", F = ta.data("sparkline-outline-color") || "#303030", G = ta.data("sparkline-outlinefill-color") || "#f0f0f0", H = ta.data("sparkline-outlinemedian-color") || "#f00000", I = ta.data("sparkline-outlinetarget-color") || "#40a020", ta.sparkline("html", {
                type: "box",
                width: t,
                height: u,
                raw: v,
                target: w,
                minValue: x,
                maxValue: y,
                showOutliers: z,
                outlierIQR: A,
                spotRadius: B,
                boxLineColor: C,
                boxFillColor: D,
                whiskerColor: E,
                outlierLineColor: F,
                outlierFillColor: G,
                medianColor: H,
                targetColor: I
            }), ta = null), "bullet" == ua) {
                var va = ta.data("sparkline-height") || "auto";
                J = ta.data("sparkline-width") || 2, K = ta.data("sparkline-bullet-color") || "#ed1c24", L = ta.data("sparkline-performance-color") || "#3030f0", M = ta.data("sparkline-bulletrange-color") || ["#d3dafe", "#a8b6ff", "#7f94ff"], ta.sparkline("html", {
                    type: "bullet",
                    height: va,
                    targetWidth: J,
                    targetColor: K,
                    performanceColor: L,
                    rangeColors: M
                }), ta = null
            }
            "discrete" == ua && (N = ta.data("sparkline-height") || 26, O = ta.data("sparkline-width") || 50, P = ta.css("color"), Q = ta.data("sparkline-line-height") || 5, R = ta.data("sparkline-threshold") || "undefined", S = ta.data("sparkline-threshold-color") || "#ed1c24", ta.sparkline("html", {
                type: "discrete",
                width: O,
                height: N,
                lineColor: P,
                lineHeight: Q,
                thresholdValue: R,
                thresholdColor: S
            }), ta = null), "tristate" == ua && (T = ta.data("sparkline-height") || 26, U = ta.data("sparkline-posbar-color") || "#60f060", V = ta.data("sparkline-negbar-color") || "#f04040", W = ta.data("sparkline-zerobar-color") || "#909090", X = ta.data("sparkline-barwidth") || 5, Y = ta.data("sparkline-barspacing") || 2, Z = ta.data("sparkline-zeroaxis") || !1, ta.sparkline("html", {
                type: "tristate",
                height: T,
                posBarColor: _,
                negBarColor: V,
                zeroBarColor: W,
                barWidth: X,
                barSpacing: Y,
                zeroAxis: Z
            }), ta = null), "compositebar" == ua && (b = ta.data("sparkline-height") || "20px", aa = ta.data("sparkline-width") || "100%", c = ta.data("sparkline-barwidth") || 3, h = ta.data("sparkline-line-width") || 1, g = ta.data("sparkline-color-top") || "#ed1c24", _ = ta.data("sparkline-color-bottom") || "#333333", ta.sparkline(ta.data("sparkline-bar-val"), {
                type: "bar",
                width: aa,
                height: b,
                barColor: _,
                barWidth: c
            }), ta.sparkline(ta.data("sparkline-line-val"), {
                width: aa,
                height: b,
                lineColor: g,
                lineWidth: h,
                composite: !0,
                fillColor: !1
            }), ta = null), "compositeline" == ua && (b = ta.data("sparkline-height") || "20px", aa = ta.data("sparkline-width") || "90px", ba = ta.data("sparkline-bar-val"), ca = ta.data("sparkline-bar-val-spots-top") || null, da = ta.data("sparkline-bar-val-spots-bottom") || null, ea = ta.data("sparkline-line-width-top") || 1, fa = ta.data("sparkline-line-width-bottom") || 1, ga = ta.data("sparkline-color-top") || "#333333", ha = ta.data("sparkline-color-bottom") || "#ed1c24", ia = ta.data("sparkline-spotradius-top") || 1.5, ja = ta.data("sparkline-spotradius-bottom") || ia, j = ta.data("sparkline-spot-color") || "#f08000", ka = ta.data("sparkline-minspot-color-top") || "#ed1c24", la = ta.data("sparkline-maxspot-color-top") || "#f08000", ma = ta.data("sparkline-minspot-color-bottom") || ka, na = ta.data("sparkline-maxspot-color-bottom") || la, oa = ta.data("sparkline-highlightspot-color-top") || "#50f050", pa = ta.data("sparkline-highlightline-color-top") || "#f02020", qa = ta.data("sparkline-highlightspot-color-bottom") || oa, thisHighlightLineColor2 = ta.data("sparkline-highlightline-color-bottom") || pa, ra = ta.data("sparkline-fillcolor-top") || "transparent", sa = ta.data("sparkline-fillcolor-bottom") || "transparent", ta.sparkline(ba, {
                type: "line",
                spotRadius: ia,
                spotColor: j,
                minSpotColor: ka,
                maxSpotColor: la,
                highlightSpotColor: oa,
                highlightLineColor: pa,
                valueSpots: ca,
                lineWidth: ea,
                width: aa,
                height: b,
                lineColor: ga,
                fillColor: ra
            }), ta.sparkline(ta.data("sparkline-line-val"), {
                type: "line",
                spotRadius: ja,
                spotColor: j,
                minSpotColor: ma,
                maxSpotColor: na,
                highlightSpotColor: qa,
                highlightLineColor: thisHighlightLineColor2,
                valueSpots: da,
                lineWidth: fa,
                width: aa,
                height: b,
                lineColor: ha,
                composite: !0,
                fillColor: sa
            }), ta = null)
        })
    }
    $.fn.easyPieChart && $(".easy-pie-chart").each(function () {
        var a = $(this), b = a.css("color") || a.data("pie-color"), c = a.data("pie-track-color") || "#eeeeee",
            d = parseInt(a.data("pie-size")) || 25;
        a.easyPieChart({
            barColor: b,
            trackColor: c,
            scaleColor: !1,
            lineCap: "butt",
            lineWidth: parseInt(d / 8.5),
            animate: 1500,
            rotate: -90,
            size: d,
            onStep: function (a) {
                this.$el.find("span").text(~~a)
            }
        }), a = null
    })
}

function setup_widgets_desktop() {
    $.fn.jarvisWidgets && enableJarvisWidgets && $("#widget-grid").jarvisWidgets({
        grid: "article",
        widgets: ".jarviswidget",
        localStorage: !0,
        deleteSettingsKey: "#deletesettingskey-options",
        settingsKeyLabel: "Reset settings?",
        deletePositionKey: "#deletepositionkey-options",
        positionKeyLabel: "Reset position?",
        sortable: !0,
        buttonsHidden: !1,
        toggleButton: !0,
        toggleClass: "fa fa-minus | fa fa-plus",
        toggleSpeed: 200,
        onToggle: function () {
        },
        deleteButton: !0,
        deleteClass: "fa fa-times",
        deleteSpeed: 200,
        onDelete: function () {
        },
        editButton: !0,
        editPlaceholder: ".jarviswidget-editbox",
        editClass: "fa fa-cog | fa fa-save",
        editSpeed: 200,
        onEdit: function () {
        },
        colorButton: !0,
        fullscreenButton: !0,
        fullscreenClass: "fa fa-expand | fa fa-compress",
        fullscreenDiff: 3,
        onFullscreen: function () {
        },
        customButton: !1,
        customClass: "folder-10 | next-10",
        customStart: function () {
            alert("Hello you, this is a custom button...")
        },
        customEnd: function () {
            alert("bye, till next time...")
        },
        buttonOrder: "%refresh% %custom% %edit% %toggle% %fullscreen% %delete%",
        opacity: 1,
        dragHandle: "> header",
        placeholderClass: "jarviswidget-placeholder",
        indicator: !0,
        indicatorTime: 600,
        ajax: !0,
        timestampPlaceholder: ".jarviswidget-timestamp",
        timestampFormat: "Last update: %m%/%d%/%y% %h%:%i%:%s%",
        refreshButton: !0,
        refreshButtonClass: "fa fa-refresh",
        labelError: "Sorry but there was a error:",
        labelUpdated: "Last Update:",
        labelRefresh: "Refresh",
        labelDelete: "Delete widget:",
        afterLoad: function () {
        },
        rtl: !1,
        onChange: function () {
        },
        onSave: function () {
        },
        ajaxnav: $.navAsAjax
    })
}

function setup_widgets_mobile() {
    enableMobileWidgets && enableJarvisWidgets && setup_widgets_desktop()
}

function loadScript(a, b) {
    if (jsArray[a]) b && b(); else {
        jsArray[a] = !0;
        var c = document.getElementsByTagName("body")[0], d = document.createElement("script");
        d.type = "text/javascript", d.src = a, d.onload = b, c.appendChild(d)
    }
}

function checkURL() {
    var a = location.href.split("#").splice(1).join("#");
    if (!a) try {
        var b = window.document.URL;
        b && b.indexOf("#", 0) > 0 && b.indexOf("#", 0) < b.length + 1 && (a = b.substring(b.indexOf("#", 0) + 1))
    } catch (a) {
    }
    if (container = $("#content"), a) {
        $("nav li.active").removeClass("active"), $('nav li:has(a[href="' + a + '"])').addClass("active");
        var c = $('nav a[href="' + a + '"]').attr("title");
        document.title = c || document.title, loadURL(a + location.search, container)
    } else {
        var d = $('nav > ul > li:first-child > a[href!="#"]');
        window.location.hash = d.attr("href"), d = null
    }
}

function loadURL(a, b) {
    $.ajax({
        type: "GET", url: a, dataType: "html", cache: !0, beforeSend: function () {
            if ($.navAsAjax && $(".google_maps")[0] && b[0] == $("#content")[0]) {
                var a = $(".google_maps"), c = 0;
                a.each(function () {
                    c++;
                    var b = document.getElementById(this.id);
                    c == a.length + 1 || b && b.parentNode.removeChild(b)
                })
            }
            if ($.navAsAjax && $(".dataTables_wrapper")[0] && b[0] == $("#content")[0]) {
                var d = $.fn.dataTable.fnTables(!0);
                $(d).each(function () {
                    $(this).dataTable().fnDestroy()
                })
            }
            if ($.navAsAjax && $.intervalArr.length > 0 && b[0] == $("#content")[0] && enableJarvisWidgets) for (; $.intervalArr.length > 0;) clearInterval($.intervalArr.pop());
            pagefunction = null, b.removeData().html(""), b.html('<h1 class="ajax-loading-animation"><i class="fa fa-cog fa-spin"></i> Loading...</h1>'), b[0] == $("#content")[0] && ($("body").find("> *").filter(":not(" + ignore_key_elms + ")").empty().remove(), drawBreadCrumb(), $("html").animate({scrollTop: 0}, "fast"))
        }, success: function (a) {
            b.css({opacity: "0.0"}).html(a).delay(50).animate({opacity: "1.0"}, 300), a = null, b = null
        }, error: function () {
            b.html('<h4 class="ajax-loading-error"><i class="fa fa-warning txt-color-orangeDark"></i> Error 404! Page not found.</h4>')
        }, async: !0
    })
}

function drawBreadCrumb() {
    var a = $("nav li.active > a"), b = a.length;
    bread_crumb.empty(), bread_crumb.append($("<li>Home</li>")), a.each(function () {
        bread_crumb.append($("<li></li>").html($.trim($(this).clone().children(".badge").remove().end().text()))), --b || (document.title = bread_crumb.find("li:last-child").text())
    }), a = null
}

function pageSetUp() {
    "desktop" === thisDevice ? ($("[rel=tooltip]").tooltip(), $("[rel~=popover]").popover(), $("[rel~=popover-hover]").popover({trigger: "hover"}), setup_widgets_desktop(), runAllCharts(), runAllForms()) : ($("[rel~=popover]").popover(), $("[rel~=popover-hover]").popover({trigger: "hover"}), runAllCharts(), setup_widgets_mobile(), runAllForms())
}

function pageSetUpMin() {
}

$.root_ = $("body"), $.intervalArr = [];
var calc_navbar_height = function () {
        var a = null;
        return $("#header").length && (a = $("#header").height()), null === a && (a = $('<div id="header"></div>').height()), null === a ? 49 : a
    }, navbar_height = calc_navbar_height, shortcut_dropdown = $("#shortcut"), bread_crumb = $("#ribbon ol.breadcrumb"),
    topmenu = !1, thisDevice = null,
    ismobile = /iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()),
    jsArray = {}, initApp = function (a) {
        return a.addDeviceType = function () {
            return ismobile ? ($.root_.addClass("mobile-detected"), thisDevice = "mobile", fastClick ? ($.root_.addClass("needsclick"), FastClick.attach(document.body), !1) : void 0) : ($.root_.addClass("desktop-detected"), thisDevice = "desktop", !1)
        }, a.menuPos = function () {
            ($.root_.hasClass("menu-on-top") || "top" == localStorage.getItem("sm-setmenu")) && (topmenu = !0, $.root_.addClass("menu-on-top"))
        }, a.SmartActions = function () {
            var a = {
                userLogout: function (a) {
                    function b() {
                        window.location = a.attr("href")
                    }

                    $.SmartMessageBox({
                        title: a.data("logout-title"),
                        content: a.data("logout-msg"),
                        buttons: "[Нет][Да]"
                    }, function (a) {
                        "Да" == a && ($.root_.addClass("animated fadeOutUp"), setTimeout(b, 1e3))
                    })
                }, resetWidgets: function (a) {
                    $.widresetMSG = a.data("reset-msg"), $.SmartMessageBox({
                        title: "<i class='fa fa-refresh' style='color:green'></i> Clear Local Storage",
                        content: $.widresetMSG || "Would you like to RESET all your saved widgets and clear LocalStorage?",
                        buttons: "[Да][Нет]"
                    }, function (a) {
                        "Да" == a && localStorage && (localStorage.clear(), location.reload())
                    })
                }, launchFullscreen: function (a) {
                    $.root_.hasClass("full-screen") ? ($.root_.removeClass("full-screen"), document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen && document.webkitExitFullscreen()) : ($.root_.addClass("full-screen"), a.requestFullscreen ? a.requestFullscreen() : a.mozRequestFullScreen ? a.mozRequestFullScreen() : a.webkitRequestFullscreen ? a.webkitRequestFullscreen() : a.msRequestFullscreen && a.msRequestFullscreen())
                }, minifyMenu: function (a) {
                    $.root_.hasClass("minified") ?  $.removeCookie("minified", {path: "/"}) : $.cookie("minified", "y", {expires: 30, path: "/"}),
                    $.root_.toggleClass("minified global-menu-minified"),
                    $.root_.removeClass("hidden-menu"),
                    $("html").removeClass("hidden-menu-mobile-lock")

                }, toggleMenu: function () {
                    $.root_.toggleClass("hidden-menu");
                    if (window.innerWidth >= 1500) {
                        if ($.root_.hasClass("hidden-menu")) {
                            $.root_.addClass("global-menu-hidden");
                            $.cookie("hidden-menu", "y", {expires: 30, path: "/"})
                        } else {
                            $.root_.removeClass("global-menu-hidden");
                            $.removeCookie("hidden-menu", {path: "/"});
                        }
                    }

                    $.root_.removeClass("minified");

                }, toggleShortcut: function () {

                    function a() {

                        shortcut_dropdown.animate({height: "hide"}, 300, "easeOutCirc"), $.root_.removeClass("shortcut-on")
                    }

                    function b() {
                        shortcut_dropdown.animate({height: "show"}, 200, "easeOutCirc"), $.root_.addClass("shortcut-on")
                    }

                    shortcut_dropdown.is(":visible") ? a() : b(), shortcut_dropdown.find("a").click(function (b) {
                        b.preventDefault(), window.location = $(this).attr("href"), setTimeout(a, 300)
                    }), $(document).mouseup(function (b) {
                        shortcut_dropdown.is(b.target) || 0 !== shortcut_dropdown.has(b.target).length || a()
                    })
                }
            };
            $.root_.on("click", '[data-action="userLogout"]', function (b) {
                var c = $(this);
                a.userLogout(c), b.preventDefault(), c = null
            }), $.root_.on("click", '[data-action="resetWidgets"]', function (b) {
                var c = $(this);
                a.resetWidgets(c), b.preventDefault(), c = null
            }), $.root_.on("click", '[data-action="launchFullscreen"]', function (b) {
                a.launchFullscreen(document.documentElement), b.preventDefault()
            }), $.root_.on("click", '[data-action="minifyMenu"]', function (b) {
                var c = $(this);
                a.minifyMenu(c), b.preventDefault(), c = null
            });
            $('a[data-action="toggleMenu"]').off("click");
            $('a[data-action="toggleMenu"]').on("click", function (b) {
                a.toggleMenu();
            });
            $.root_.on("click", '[data-action="toggleShortcut"]', function (b) {
                a.toggleShortcut(), b.preventDefault()
            })
        }, a.leftNav = function () {
            var a = !!a && a;
            topmenu || $("nav ul").jarvismenu({
                accordion: !0,
                speed: a,
                closedSign: '<em class="fa fa-plus-square-o"></em>',
                openedSign: '<em class="fa fa-minus-square-o"></em>'
            })
        }, a.domReadyMisc = function () {
            $("[rel=tooltip]").length && $("[rel=tooltip]").tooltip(), $("#search-mobile").click(function () {
                $.root_.addClass("search-mobile")
            }), $("#cancel-search-js").click(function () {
                $.root_.removeClass("search-mobile")
            }), $("#activity").click(function (a) {
                var b = $(this);
                b.find(".badge").hasClass("bg-color-red") && (b.find(".badge").removeClassPrefix("bg-color-"), b.find(".badge").text("0")), b.next(".ajax-dropdown").is(":visible") ? (b.next(".ajax-dropdown").fadeOut(150), b.removeClass("active")) : (b.next(".ajax-dropdown").fadeIn(150), b.addClass("active"));
                var c = b.next(".ajax-dropdown").find(".btn-group > .active > input").attr("id");
                b = null, c = null, a.preventDefault()
            }), $('input[name="activity"]').change(function () {
                var a = $(this);
                url = a.attr("id"), container = $(".ajax-notifications"), loadURL(url, container), a = null
            }), $(document).mouseup(function (a) {
                $(".ajax-dropdown").is(a.target) || 0 !== $(".ajax-dropdown").has(a.target).length || ($(".ajax-dropdown").fadeOut(150), $(".ajax-dropdown").prev().removeClass("active"))
            }), $("button[data-btn-loading]").on("click", function () {
                var a = $(this);
                a.button("loading"), setTimeout(function () {
                    a.button("reset")
                }, 3e3), $this = null
            }), $this = $("#activity > .badge"), parseInt($this.text()) > 0 && ($this.addClass("bg-color-red bounceIn animated"), $this = null)
        }, a
    }({});
initApp.addDeviceType(), initApp.menuPos(), jQuery(document).ready(function () {
    initApp.SmartActions(), initApp.leftNav(), initApp.domReadyMisc()
}), function (a, b, c) {
    function d() {
        e = b[h](function () {
            f.each(function () {
                var b, c, d = a(this), e = a.data(this, j);
                try {
                    b = d.width()
                } catch (a) {
                    b = d.width
                }
                try {
                    c = d.height()
                } catch (a) {
                    c = d.height
                }
                (b !== e.w || c !== e.h) && d.trigger(i, [e.w = b, e.h = c])
            }), d()
        }, g[k])
    }

    var e, f = a([]), g = a.resize = a.extend(a.resize, {}), h = "setTimeout", i = "resize", j = i + "-special-event",
        k = "delay", l = "throttleWindow", m = !!m && m;
    g[k] = m, g[l] = !0, a.event.special[i] = {
        setup: function () {
            if (!g[l] && this[h]) return !1;
            var b = a(this);
            f = f.add(b);
            try {
                a.data(this, j, {w: b.width(), h: b.height()})
            } catch (c) {
                a.data(this, j, {w: b.width, h: b.height})
            }
            1 === f.length && d()
        }, teardown: function () {
            if (!g[l] && this[h]) return !1;
            var b = a(this);
            f = f.not(b), b.removeData(j), f.length || clearTimeout(e)
        }, add: function (b) {
            function d(b, d, f) {
                var g = a(this), h = a.data(this, j);
                if (h == undefined) return;
                h.w = d !== c ? d : g.width(), h.h = f !== c ? f : g.height(), e.apply(this, arguments)
            }

            if (!g[l] && this[h]) return !1;
            var e;
            return a.isFunction(b) ? (e = b, d) : (e = b.handler, void (b.handler = d))
        }
    }
}(jQuery, this);
var ie = function () {
    for (var a, b = 3, c = document.createElement("div"), d = c.getElementsByTagName("i"); c.innerHTML = "<!--[if gt IE " + ++b + "]><i></i><![endif]-->", d[0];) ;
    return b > 4 ? b : a
}();
if ($.fn.extend({
    jarvismenu: function (a) {
        var b = {accordion: "true", speed: 200, closedSign: "[+]", openedSign: "[-]"}, c = $.extend(b, a), d = $(this);
        d.find("li").each(function () {
            0 !== $(this).find("ul").length && ($(this).find("a:first").append("<b class='collapse-sign'>" + c.closedSign + "</b>"), "#" == $(this).find("a:first").attr("href") && $(this).find("a:first").click(function () {
                return !1
            }))
        }), d.find("li.active").each(function () {
            $(this).parents("ul").slideDown(c.speed), $(this).parents("ul").parent("li").find("b:first").html(c.openedSign), $(this).parents("ul").parent("li").addClass("open")
        }), d.find("li a.root-item-open").click(function (event) {

            if($.root_.hasClass("minified") && $(this).hasClass('root-head')){
                /**
                 *   Предотвращение попытки свернуть меню в режиме "Иконки".
                 */
                event.preventDefault();
                return 0;
            }

            return 0 !== $(this).parent().find("ul").length && (c.accordion && ($(this).parent().find("ul").is(":visible") || (parents = $(this).parent().parents("ul"), visible = d.find("ul:visible"), visible.each(function (a) {
                var b = !0;
                parents.each(function (c) {
                    return parents[c] == visible[a] ? (b = !1, !1) : void 0
                }), b && $(this).parent().find("ul") != visible[a] && $(visible[a]).slideUp(c.speed, function () {
                    $(this).parent("li").find("b:first").html(c.closedSign), $(this).parent("li").removeClass("open")
                })
            }))), $(this).parent().find("ul:first").is(":visible") && !$(this).parent().find("ul:first").hasClass("active") ? $(this).parent().find("ul:first").slideUp(c.speed, function () {
                $(this).parent("li").removeClass("open"), $(this).parent("li").find("b:first").delay(c.speed).html(c.closedSign)
            }) : $(this).parent().find("ul:first").slideDown(c.speed, function () {
                $(this).parent("li").addClass("open"), $(this).parent("li").find("b:first").delay(c.speed).html(c.openedSign)
            })), !1
        }), d.find("li.active").each(function () {
            $(this).children("ul").slideDown(c.speed), $(this).children("ul").parent("li").find("b:first").html(c.openedSign), $(this).children("ul").parent("li").addClass("open")
        })
    }
}), jQuery.fn.doesExist = function () {
    return jQuery(this).length > 0
}, $.navAsAjax || $(".google_maps")) {
    var gMapsLoaded = !1;
    window.gMapsCallback = function () {
        gMapsLoaded = !0, $(window).trigger("gMapsLoaded")
    }, window.loadGoogleMaps = function () {
        if (gMapsLoaded) return window.gMapsCallback();
        var a = document.createElement("script");
        a.setAttribute("type", "text/javascript"), a.setAttribute("src", "http://maps.google.com/maps/api/js?sensor=false&callback=gMapsCallback"), (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(a)
    }
}
$.navAsAjax && ($("nav").length && checkURL(), $(document).on("click", 'nav a[href!="#"]', function (a) {
    a.preventDefault();
    var b = $(a.currentTarget);
    b.parent().hasClass("active") || b.attr("target") || ($.root_.hasClass("mobile-view-activated") ? (window.setTimeout(function () {
        window.location.search ? window.location.href = window.location.href.replace(window.location.search, "").replace(window.location.hash, "") + "#" + b.attr("href") : window.location.hash = b.attr("href")
    }, 150)) : window.location.search ? window.location.href = window.location.href.replace(window.location.search, "").replace(window.location.hash, "") + "#" + b.attr("href") : window.location.hash = b.attr("href"))
}), $(document).on("click", 'nav a[target="_blank"]', function (a) {
    a.preventDefault();
    var b = $(a.currentTarget);
    window.open(b.attr("href"))
}), $(document).on("click", 'nav a[target="_top"]', function (a) {
    a.preventDefault();
    var b = $(a.currentTarget);
    window.location = b.attr("href")
}), $(document).on("click", 'nav a[href="#"]', function (a) {
    a.preventDefault()
}), $(window).on("hashchange", function () {
    checkURL()
})), $("body").on("click", function (a) {
    $('[rel~="popover"]').each(function () {
        $(this).is(a.target) || 0 !== $(this).has(a.target).length || 0 !== $(".popover").has(a.target).length || $(this).popover("hide")
    })
}), $(document).ready(function () {
    $("#doublescroll").length > 0 && $("#doublescroll").before($("<div></div>").append($("<div></div>").css({
        "padding-top": "1px",
        width: $("#doublescroll")[0].scrollWidth + "px"
    }).text(" ")).css({overflow: "auto", overflowY: "hidden"}).bind("scroll", function () {
        $("#doublescroll")[0].scrollLeft = $(this)[0].scrollLeft
    })).bind("scroll", function () {
        $(this).prev()[0].scrollLeft = $(this)[0].scrollLeft
    })
}), $(document).ready(function () {
    $(".SetHiddenAlert").click(function () {
        $.cookie($(this).attr("data-code"), "Y", {expires: 30, path: "/"})
    });
    var a = window.location.hash.replace("#", "");
    "" != a && $("[name=" + a + "]").length > 0 && $("html,body").animate({scrollTop: $("[name=" + a + "]").offset().top - 60}, 300), $("a[data-scroll=true]").click(function () {
        if ($(this).attr("href")) {
            var a = $(this).attr("href").split("#");
            a[1] && $("[name=" + a[1] + "]").length > 0 && $("html,body").animate({scrollTop: $("[name=" + a[1] + "]").offset().top - 60}, 300)
        }
    }), $(".fancy").fancybox({padding: 0})


    var Option = $("#header-search select").find("option[value='"+$("#header-search select").val()+"']");
    if (Option.attr("data-action")){
        $("#header-search form").attr("action",Option.attr("data-action"));
    }else{
        $("#header-search form").attr("action",$("#header-search input[type=text]").attr("data-action-"+$("#header-search select").val()));
    }
    if (Option.attr("data-name")){
        $("#header-search input[type=text]").attr("name",Option.attr("data-name"));
    }else{
        $("#header-search input[type=text]").attr("name",$("#header-search input[type=text]").attr("data-name-"+$("#header-search select").val()));
    }
    $("#header-search select").change(function () {
        var Option = $(this).find("option[value='"+$(this).val()+"']");
        if (Option.attr("data-action")){
            $("#header-search form").attr("action",Option.attr("data-action"));
        }else{
            $("#header-search form").attr("action",$("#header-search input[type=text]").attr("data-action-"+$(this).val()));
        }
        if (Option.attr("data-name")){
            $("#header-search input[type=text]").attr("name",Option.attr("data-name"));
        }else{
            $("#header-search input[type=text]").attr("name",$("#header-search input[type=text]").attr("data-name-"+$(this).val()));
        }


    });
});

function SetBubble($x, $y, $x2, $y2, $message, $bid) {
    var matches = document.cookie.match(new RegExp("(?:^|; )" + 'hide_' + $bid.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
    if (matches) return false;
    var Bubble = $("<div class='inf-bubble-overlay'><div class='inf-bubble-item'><div>" + $message + "</div></div></div>");
    Bubble.children().css({"left": $x, "top": $y, "right": $x2, "bottom": $y2});
    $(Bubble).click(function () {
        var d = new Date();
        d.setTime(d.getTime() + (366 * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toUTCString();
        document.cookie = 'hide_' + $bid + "=" + 1 + ";path=/;domain=infostart.ru;" + expires;
        $(Bubble).remove();
    });
    $("body").append(Bubble);
}

$(document).on("click", "[data-action=get-user-info]", function () {
    $(".get-user-info").remove();
    var UID = $(this).attr("data-uid");
    var BTN = $(this);
    if (UID > 0) {
        $.get('/bitrix/ajax/get_info_user.php?UID=' + UID, function (data) {
            BTN.after(data);
            $(".get-user-info .close").click(function () {
                $(this).parents(".get-user-info").remove();
            });
        });

        return false;
    }
});

$(document).on("click", "a[href]", function () {
    if ($(this).attr("href").indexOf("action=buy") !== -1) {
        var price = parseInt($(this).attr("data-price"), 10).toFixed(2);
        var name = $(this).attr("data-name");
        var id = $(this).attr("data-id");
        if (price && name) {
          try {
            window.dataLayer?dataLayer.push({
              "event": "addToCart",
              "ecommerce": {
                "currencyCode": "RUB",
                "add": {
                  "products": [{
                    "id": id,
                    "name": name,
                    "price": '"' + price + '"',
                    "quantity": 1
                  }]
                }
              }
            }):'';
            window.dataLayer?dataLayer.push({
              "event": "productaddtocart"
            }):'';

            //dataLayer.push({ ecommerce: null });
            window.dataLayer?dataLayer.push({
              "event": "add_to_cart",
              "ecommerce": {
                "items": [{
                  "item_name": name,
                  "item_id": id,
                  "price": '"' + price + '"',
                  "index": 1,
                  "quantity": 1
                }]
              }
            }):'';
          } catch (error) {
            console.error(error);
          }
        }
    }
});

$(document).ready(function () {
    $('#main-left-menu > li').on({
        mouseenter: function () {
            if (!document.body.classList.contains("minified")) {
                return false;
            }
            let $ul = $(this).children('ul');
            let top_window;
            if ($ul.offset() != undefined) {
                top_window = $ul.offset().top - $(document).scrollTop();
            }
            let margin = 70;
            let height = $(window).height() - top_window - 5;
            if (height != undefined && !isNaN(height)) {
                if (height < margin) {
                    let $aF = $(this).find('> a > span');
                    $aF.css({'top': '-'+($aF.parent().outerHeight() + margin)+'px'});
                    $ul.css({'max-height': (height + margin) + 'px', 'top': '-'+margin+'px'});
                } else {
                    $ul.css({'max-height': (height) + 'px'});
                }
            }
        },
        mouseleave: function () {
            let $ul = $(this).children('ul');
            $ul.css({'max-height': ''});
        }
    });


    var ImpressionProducts = new Array();
    $("a[data-price]").each(function () {
        if ($(this).attr("href").indexOf("action=buy") !== -1) {
            var price = parseInt($(this).attr("data-price"), 10).toFixed(2);
            var name = $(this).attr("data-name");
            var id = $(this).attr("data-id");
            if (price && name) {
                ImpressionProducts.push({
                    "id": id,
                    "name": name,
                    "price": price,
                    "list": "infostart"
                });

                try {
                  window.dataLayer?dataLayer.push({
                    'event': 'remarketingTriggered',
                    'google_tag_params': {
                      'ecomm_pagetype': 'product',
                      'ecomm_prodid': id,
                    }
                  }):'';
                } catch (error) {
                  console.error(error);
                }
            }

        }
    });
    if (ImpressionProducts.length > 0) {
      try {
        window.dataLayer?dataLayer.push({
          "event": "impressions",
          "ecommerce": {
            "currencyCode": "RUB",
            "impressions": ImpressionProducts
          }
        }):'';
      } catch (error) {
        console.error(error);
      }
    }

});

function GetArCharVersion() {
    var arChars = [];
    var arCharsEncode = [];
    var arCharsDecode = [];
    var START_CHAR_ID = 58;
    arChars_loop:
        for (var i = 10; i <= 600000000; i *= 10) {
            for (var a = i; a < i * 10; a += i) {
                if (arCharsEncode[a.toString().length - 1] === undefined) {
                    arCharsEncode[a.toString().length - 1] = [];
                }
                if (arCharsDecode[a.toString().length - 1] === undefined) {
                    arCharsDecode[a.toString().length - 1] = [];
                }

                arCharsEncode[a.toString().length - 1][a.toString().substr(0, 1)] = String.fromCharCode(START_CHAR_ID);
                arCharsDecode[a.toString().length - 1][String.fromCharCode(START_CHAR_ID)] = a.toString().substr(0, 1);

                if (START_CHAR_ID === 126) {
                    break arChars_loop;
                }
                START_CHAR_ID++;
            }
        }
    arChars["ENCODE"] = arCharsEncode;
    arChars["DECODE"] = arCharsDecode;
    return arChars;
}

function DecodeCharVersion(number) {
    var arChars = GetArCharVersion()["DECODE"];
    var arNumber = number.split("").reverse();
    var resNumber = [];
    for (var i = 0; i < arNumber.length; i++) {
        if (i === 0 || arNumber[i] === "0") {
            resNumber.push(arNumber[i]);
            continue;
        }
        resNumber.push(arChars[i][arNumber[i]]);
    }
    return parseInt(resNumber.reverse().join(''));
}

function EncodeCharVersion(number) {
    var arChars = GetArCharVersion()["ENCODE"];
    var arNumber = number.toString().split("").reverse();
    var resNumber = [];
    for (var i = 0; i < arNumber.length; i++) {
        if (i === 0 || arNumber[i] === "0") {
            resNumber.push(arNumber[i]);
            continue;
        }
        resNumber.push(arChars[i][arNumber[i]]);
    }
    return resNumber.reverse().join('');
}

function copyToClipboard(element) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(element).text()).select();
    document.execCommand("copy");
    $temp.remove();
}

$(document).ready(function () {
    $(document).on("click", ".copy-to-clipboard", function () {
        copyToClipboard($(this));
        $.smallBox({
            title: 'Успешно!',
            content: "Cкопировано в буфер обмена",
            color: "#666",
            icon: "fa fa-check fadeInRight animated",
            timeout: 2000
        });
    });

    checkSectionSearch();
    $('#select-section').change(function() {
        checkSectionSearch();
    });
});

function checkSectionSearch(){
    let st = $('form[name="search_h"]').find('input[name="st"]');
    let sort = $('form[name="search_h"]').find('input[name="sort"]');
    let section = $('#select-section').val();
    if(section === 'c'){
        st.attr('disabled', true);
        sort.attr('disabled', true);
    }
    else{
        st.attr('disabled', false);
        sort.attr('disabled', false);
    }
}

let disableSubmit = false
$(document).on("click", ".btn-feedback", function () {
	let paramsBody = {
		'ACTION': 'GET_FORM',
		'ACTION_TYPE': 'FEEDBACK_GLOBAL',
        'HIDE_FIELDS': this.getAttribute('data-hide-fields')
	};

	function showFeedbackModal(self, m) {
        let hideFields = self.data("hide-fields");

        disableSubmit = self.data("disable_submit");
        if(disableSubmit == 1){
            $('#global-feedback-form .modal-footer button[type="submit"]').attr("disabled", 1);
        }

        if (hideFields !== undefined && hideFields.length > 0) {
            hideFields = hideFields.split(',');
            for (let f in hideFields) {
                let code = hideFields[f].toUpperCase();
                if (["NAME", "PHONE", "POST"].indexOf(code) == -1) {
                    let section = m.find("section:has([name='" + code + "'])");
                    section.remove();
                }
            }
        }

        let displayHideFields = self.data("display-hide-fields");
        if (displayHideFields !== undefined && displayHideFields.length > 0) {
			displayHideFields = displayHideFields.split(',');
            for (let f in displayHideFields) {
                let code = displayHideFields[f].toUpperCase();
                if (["NAME", "MESSAGE", "POST"].indexOf(code) == -1) {
                    let section = m.find("section:has([name='" + code + "'])");
                    section.hide();
                }
            }
        }

		const new_sub_ticket = self.data("create_new_sub_ticket") ? self.data("create_new_sub_ticket").toUpperCase() : "N";

        let delReqFields = self.data("del_req");
        if ((new_sub_ticket == 'Y') && (delReqFields !== undefined) && delReqFields.length > 0) {
			delReqFields = delReqFields.split(',');
            for (let f in delReqFields) {
                let code = delReqFields[f].toUpperCase();
                if (["NAME", "MESSAGE", "POST"].indexOf(code) == -1) {
					const el = m.find("[name='" + code + "']");
					el.removeAttr("required");
                }
            }
        }

        let dopReqFields = self.data("dop_req");
        if (dopReqFields !== undefined && dopReqFields.length > 0) {
            dopReqFields = dopReqFields.split(',');
            for (let d in dopReqFields) {
                let code = dopReqFields[d].toUpperCase();
                if (["NAME", "PHONE", "POST"].indexOf(code) == -1) {
                    let fieldModif = m.find('[name="' + code + '"]');
                    fieldModif.prop('required', true);
                    fieldModif.parent().prev().append('<span class="text-danger">*</span>');

                }
            }
        }
        m.find('input[name="UID"]').val(self.data("uid"));
        m.find('input[name="DIRECTION"]').val(self.data("direction"));
        m.find('input[name="BUSINESS"]').val(self.data("business"));
        m.find('input[name="INFO"]').val(self.data("info"));

        m.find('input[name="PUB_ID"]').val(self.data("pub_id"));
        m.find('input[name="SPECIAL_CASE"]').val(self.data("special_case"));
        m.find('input[name="TICKET_TITLE"]').val(self.data("ticket_title"));
        m.find('input[name="TAGS"]').val(self.data("tags"));
        m.find('input[name="DOPUID"]').val(self.data("dopuid"));
        m.find('input[name="PARENT_TICKET_ID"]').val(self.data("parent_ticket_id"));
        m.find('input[name="CREATE_NEW_SUB_TICKET"]').val(new_sub_ticket);
        m.find('input[name="DISABLE_SUBMIT"]').val(self.data("disable_submit"));
        m.find('input[name="ORDER_NUMBER"]').val(self.data("order_number"));
        m.find('input[name="SYSTEM_TICKET"]').val(self.data("system_ticket"));

        let title = self.data("title");
        m.find('input[name="TITLE"]').val(title);
        if (title !== undefined) {
            m.find(".modal-title").html(title);
        }
        m.find('textarea[name="MESSAGE"]').html(self.data("message"));

        let modal_chat = self.data("modal_chat") == "Y" ? "Y" : "N";
        m.find('input[name="MODAL_CHAT"]').val(modal_chat);

        m.modal("show");
    }

    let self = $(this);
    $("#global-feedback-modal").remove();
	const SPECIAL_CASE = self.data("special_case") ? self.data("special_case").toUpperCase().trim() : null;
	if (
		SPECIAL_CASE &&
		(
			(SPECIAL_CASE === "BTN_CALL") || (SPECIAL_CASE.indexOf('PUB_BTN_CALL') === 0)
		)
	) {
		$.extend(paramsBody, { 'CALL-TIME': 'SHOW' })
	}

    if (paramsBody.HIDE_FIELDS) {
        paramsBody.HIDE_FIELDS.split(',').map(code => {
            if (['NAME', 'PHONE', 'POST'].indexOf(code) !== -1) {
                paramsBody.HIDE_FIELDS = paramsBody.HIDE_FIELDS.replace(
                    new RegExp(`,?${code},?`, 'i'),
                    ','
                );
            }
        });
    }

    let freeFileId = $(this).data('freeFileId') || 0;

    $.extend(paramsBody, { freeFileId })

    $.get("/bitrix/ajax/feedback_form.php", paramsBody, function (data) {
        $("body").append(data);
        m = $("#global-feedback-modal");
        showFeedbackModal(self, m);
    });
    return false;
});

function showFeedbackForm(params) {
    let a = document.createElement("a");
    a.classList.add("btn-feedback");
    for (let code in params) {
        a.setAttribute(code, params[code]);
    }
    document.body.appendChild(a);
    a.click();
    a.remove();
}
