﻿$(document).ready(function () {
    buildHeader();
    buildFooter();
    isMobile || addLikes();
    setFocus();
    imgOndemand();
    addQTip();
    $('.eauLogout').click(function (e) {
        log('clicked');
        e.preventDefault();
        eauLogout();
    });
    $("input.dollarAmount").on("blur", function () {
        var a = "0" + $(this).val(),
        a = stripAlphaChars(a),
        a = parseFloatOrZero(a);
        a < 0 && (a = 0);
        $(this).val(a.toFixed(2))
    });
    $(".dollarAmount").trigger("blur");
    $(".flagAsRequired").append('<span class="rqd"><strong> *</strong></span>');
    $("#progressbar").length > 0 && fillProgressBar();
    $("input[type=text]").live('focus', function () {
        this.select();
    });
    $("div#viewer .close").live("click", function () { //this is used on every Page!!
        $("#viewer").fadeOut("fast", "linear", function () {
            $("#viewer .mainMedia").html("")
        })
    })
    isMobile || ($("body").append('<div id="SnapABug_W"></div><div id="SnapABug_WP"></div><div id="SnapABug_Applet"></div>'), $.getScript((document.location.protocol == "https:" ? "https://snapabug.appspot.com" : "http://www.snapengage.com") + "/snapabug.js", function () {
        SnapABug.initAsync("42381404-0309-4fb0-9556-db617f24b62b");
       // $("#footernav ul").prepend('<li><a onclick="return SnapABug.startLink();">Chat with support</a></li>')
    }));
    $(function () {
        function a() {

            /*
            if ($('.lb-content').length>0) {
            var html = $('#profile .lb-content').html();
            //log(html);
            $('#profile').html('<div class="scrollHelper">'+html+'</div>');
            }
            */
            $(".scrollHelper").height($(window).height() - 110);

            //$(".scrollHelper").lionbars();

            var a = $(window).scrollTop();
            a < 110 ? $("#profile").css({
                top: 110 - a + "px"
            }) : $("#profile").css({
                top: "10px"
            })
            var w = $('.appeal').width() / 3.5;
            $('#profile').css('margin-left', w + 'px');
            a < 110 ? $("#profile").css({
                top: 110 - a + "px"
            }) : $("#profile").css({
                top: "10px"
            })

        }
        $("a.modal").click(function (a) {
            a.preventDefault();
            a = $(this);
            $('<iframe id="externalSite" frameBorder="0" class="externalSite" src="' + this.href + '" />').dialog({
                title: a.attr("title") ? a.attr("title") : a.text(),
                autoOpen: true,
                width: 800,
                height: 500,
                modal: true,
                resizable: true,
                autoResize: true,
                overlay: {
                    opacity: 0.5,
                    background: "black"
                }
            }).width(770).height(470)
        });
        a();
        $(window).scroll(function () {
            a()
        });
        $(window).resize(function () {
            a()
        });
        $(".appeal").bind("resize", function () {
            a()
        })
    });


    //strech banner
    $(function () {
        if ($('img.banner').length > 0) {
            var image = 'img.banner';
            var height = $(image).height();
            var width = $(image).width();
            var aspectRatio = width / height;
            if (aspectRatio > 5) {
                $(image).css("width", '100%');
            }

            log(length);
            log(image);
            log(aspectRatio);

        }
    });




    $(function () {
        $("a.modalWithButtons").live("click", function (a) {
            a.preventDefault();
            a = $(this);
            $('<iframe id="externalSite" class="externalSite" frameBorder="0" src="' + this.href + '" />').dialog({
                title: a.attr("title") ? a.attr("title") : a.text(),
                autoOpen: true,
                width: 600,
                height: 400,
                modal: true,
                resizable: true,
                autoResize: true,
                overlay: {
                    opacity: 0.5,
                    background: "black"
                },
                buttons: {
                    close: function () {
                        $(this).dialog("close")
                    }
                }
            }).width(570).height(370)
        })
    });
    $("#fundraiser-list tr, #modalEventListTable tr").live("mouseenter", function () {
        $(this).addClass("active")
    });
    $("#fundraiser-list tr, #modalEventListTable tr").live("mouseleave", function () {
        $(this).removeClass("active")
    });
    $(".getInnerLink").live("click", function (a) {
        a.preventDefault();
        window.location = $(this).find("a").attr("href")
    })

    $(".popupLink").live("click", function (a) {
        a.preventDefault();
        var popUpUrl = $(this).find("a").attr("href");
        window.open(popUpUrl, "Window2", "width=900,height=800,scrollbars=yes,menubar=yes,");
    })

});

$(window).scroll(function() {
    imgOndemand()
    });
function buildHeader() {
    $("#searchby").selectmenu({
        width: "95px"
    });
    $("#aboutfglink").mouseenter(function() {
        $(".aboutnav").fadeIn("slow", "linear");
        $("#siteNav").addClass("hoverAbout");
        _gaq.push(["_trackEvent", "Header", "Play", "Explore"])
        });
    $("#mainNav").mouseleave(function() {
        $(".aboutnav").fadeOut("slow", "linear");
        $("#siteNav").removeClass("hoverAbout")
        })
    }
function buildFooter() {
    jQuery.qtip && $("#footerContainer .social a[title]").qtip({
        show: "mouseover",
        hide: "mouseout",
        style: {
            width: 150,
            padding: 5,
            background: "#1CA4DD",
            color: "#fff",
            fontSize: "12px",
            textAlign: "center",
            border: {
                width: 7,
                radius: 5,
                color: "#1CA4DD"
            },
            tip: "bottomLeft",
            name: "dark"
        },
        position: {
            corner: {
                target: "topMiddle",
                tooltip: "bottomLeft"
            }
        }
    })
    }
function mediaViewer(a) {
    window.scroll(0, 225);
    $(".mainMedia").html(a);
    $("#viewer").fadeIn("slow", "linear")
    }
function addVideo() {
    var a = $("#videoID").val(),
    c;
    $("#videoContainer").html("<div class='play'></div><img src='//img.youtube.com/vi/" + a + "/0.jpg' id=" + a + " />");
    $(" #videoContainer").click(function() {
        mediaViewer('<iframe class="youtube-player" type="text/html" width="620" height="380" src="http://www.youtube.com/embed/' + a + '?autoplay=1" frameborder="0"></iframe>')
        });

    
    }
function addShareElements() {
    isMobile || ($("#shareUrl").length && $("#shareUrl").val(), typeof addthis !== "undefined" && (addthis.addEventListener("addthis.menu.share", shareEventHandler), addthis.init()))
    }
function shareEventHandler(a) {
    a.type == "addthis.menu.share" && _gaq.push(["_trackPageview", shareUrl + "/share/" + a.data.service])
    }
function addLikes() {
    $("#fbVerb");
    $("#shareUrl").length > 0 && $(".fb").prepend('<fb:like href="' + $("#shareUrl").val() + '" layout="button_count" show_faces="false" width="90" font="arial" ref="mainpage" send="true"></fb:like>')
    }
function fillProgressBar() {
    var a = $("#percent").val();
    $("#progressbar").progressbar({
        value: parseInt(a)
        })
    }
if (typeof $.fn.qtip !== "undefined") {
    $.fn.qtip.styles.FGStyle = {
        width: 400,
        background: "#FFFFF2",
        color: "#454545",
        textAlign: "left",
        padding: 10,
        border: {
            width: 5,
            radius: 5,
            color: "#1ca4dd"
        },
        tip: "bottomLeft",
        title: {
            background: "#FFFFF2",
            "font-weight": "Bold"
        }
    }
}
function qtipWrapper(a, c, b, d, e, g, h) {
    a != null && a.qtip({
        content: {
            text: b,
            title: {
                text: c,
                button: '<img onclick="return false;" style="border:0;" src="/App_Themes/Default/Images/Buttons/close_btn_grey.png" alt="Close" />'
            }
        },
        position: {
            corner: {
                target: d,
                tooltip: e
            }
        },
        show: {
            solo: true,
            when: g
        },
        hide: h,
        style: {
            tip: true,
            name: "FGStyle"
        }
    })
    }
function addQTip() {
    return false
}
function setFocus() {
    $(".focus").focus()
    }
function createPaging() {
    bindPrevNext();
    formatPager(totalPages, currentPage);
    $(".pagenav").show();
    $(".pager").live("click", function(a) {
        var c = $(this),
        b = parseInt($(this).html());
        retreivePage(b, pageSize, $("#{0}".formatWith(activeSortField)).data("sortfield"), $("#{0}".formatWith(activeSortField)).data("sortorder"), function() {
            currentPage = b;
            a.preventDefault();
            $(".current").removeClass("current");
            $(c).addClass("current");
            formatPager(totalPages, currentPage, $(".current").prev().attr("href"), $(".current").next().attr("href"));
            imgOndemand()
            })
        })
    }
function formatPager(a, c, b, d) {
    if (c <= 5) {
        for (i = 1; i <= a; i++) {
            $("." + i).removeClass("visuallyhidden")
            }
        for (i = 6; i <= a; i++) {
            $("." + i).addClass("visuallyhidden")
            }
        a > 1 && $("#next").removeClass("visuallyhidden")
        } else {
        if (c >= a - 4) {
            for (i = 1; i <= a - 5; i++) {
                $("." + i).addClass("visuallyhidden")
                }
            for (i = a - 4; i <= a; i++) {
                $("." + i).removeClass("visuallyhidden")
                }
        } else {
            for (i = c - 3; i <= c + 3; i++) {
                $("." + i).removeClass("visuallyhidden")
                }
            for (i = 1; i <= c - 3; i++) {
                $("." + i).addClass("visuallyhidden")
                }
            for (i = c + 3; i <= a; i++) {
                $("." + i).addClass("visuallyhidden")
                }
        }
    }
    c == 1 && $("#prev").addClass("visuallyhidden");
    c == a && $("#next").addClass("visuallyhidden");
    b !== null && $("#next").attr("href", d);
    d !== null && $("#prev").attr("href", b)
    }
function bindPrevNext() {
    $("#prev, #next").unbind("click").removeClass("visuallyhidden");
    $("#prev").click(function(a) {
        retreivePage(currentPage - 1, pageSize, $("#{0}".formatWith(activeSortField)).data("sortfield"), $("#{0}".formatWith(activeSortField)).data("sortorder"), function() {--currentPage;
            a.preventDefault();
            $(".current").removeClass("current");
            $("." + currentPage).addClass("current");
            formatPager(totalPages, currentPage, $(".current").prev().attr("href"), $(".current").next().attr("href"))
            })
        });
    $("#next").click(function(a) {
        $(this).data("active", true);
        retreivePage(currentPage + 1, pageSize, $("#{0}".formatWith(activeSortField)).data("sortfield"), $("#{0}".formatWith(activeSortField)).data("sortorder"), function() {++currentPage;
            a.preventDefault();
            $(".current").removeClass("current");
            $("." + currentPage).addClass("current");
            formatPager(totalPages, currentPage, $(".current").prev().attr("href"), $(".current").next().attr("href"))
            })
        })
    }
function fundraiserSearch(a, c) {
    retreivePage(1, c, $("#{0}".formatWith(activeSortField)).data("sortfield"), $("#{0}".formatWith(activeSortField)).data("sortorder"), function(b) {
        currentPage = 1;
        $(".current").removeClass("current");
        $("." + currentPage).addClass("current");
        $(".pagenav").children().each(function() {
            $(this).addClass("visuallyhidden")
            });
        $("#searchMessage").html(b.SearchResultMessage);
        totalPages = Math.ceil($(".total").html() / c);
        formatPager(totalPages, 1, $(".current").prev().attr("href"), $(".current").next().attr("href"));
        imgOndemand();
        a.preventDefault()
        })
    }
function sortFundraisersOrTeamsList(a, c, b, d, e) {
    b == "asc" ? b = "desc": b = "asc";
    retreivePage(1, pageSize, c, b, function() {
        currentPage = 1;
        $(".current").removeClass("current");
        $("." + currentPage).addClass("current");
        $(".pagenav").children().each(function() {
            $(this).addClass("visuallyhidden")
            });
        totalPages = Math.ceil($(".total").html() / pageSize);
        formatPager(totalPages, 1, $(".current").prev().attr("href"), $(".current").next().attr("href"));
        $("#sortContainer").children("span").each(function() {
            $(this).removeClass("desc").removeClass("asc").data("sortorder", null)
            });
        b == "asc" ? $(a).data("sortorder", "asc").addClass("asc") : $(a).data("sortorder", "desc").addClass("desc");
        activeSortField = $(a).attr("id");
        imgOndemand();
        e.preventDefault()
        }, d)
    }
function fgDialog(a, c, b) {
    $('<div id="dialog-message" title="{0}"><p>{1}</p></div>'.formatWith(a, c)).dialog({
        modal: true,
        draggable: false,
        resizable: false,
        buttons: {
            Ok: function() {
                $.isFunction(b) && b.apply();
                $(this).dialog("close")
                }
        }
    })
    }
function fgConfirm(a, c, b, d) {
    $('<div id="dialog-message" title="{0}"><p>{1}</p></div>'.formatWith(a, c)).dialog({
        modal: true,
        buttons: {
            Ok: function() {
                $.isFunction(b) && b.apply();
                $(this).dialog("close")
                },
            Cancel: function() {
                $.isFunction(d) && d.apply();
                $(this).dialog("close")
                }
        }
    })
}

var imgLoadedH = false,
imgLoadedW = false,
offset = 90;
function CheckLoad(a) {
    var c = $(window).height() + $(window).scrollTop(),
    b = $(window).width() + $(window).scrollLeft(),
    a = $(a),
    c = a.offset().top < c + offset && a.offset().left < b + offset,
    b = a.is(":visible");
    c && b && a.attr("src", a.attr("longdesc")).removeClass("img-ondemand")
    }
function imgOndemand() {
    var a = $(document).height(),
    c = $(document).width();
    $("img.img-ondemand").each(function() {
        CheckLoad(this)
        });
    imgLoadedH = $(window).height() + $(window).scrollTop() >= a;
    imgLoadedW = $(window).width() + $(window).scrollLeft() >= c
}
function buildProgressButton() {
    var a = $(".progressButton").length,
    c = 0;
    $("a.progressButton").each(function() {
        c++;
        var b,
        d = '<div class="outerProgress">';
        for (b = 0; b < c; b++) {
            d += '<span class="done" style="width:' + 1 / a * 100 + '%"></span>'
        }
        for (b = c; b < a; b++) {
            d += '<span class="todo" style="width:' + 1 / a * 100 + '%"></span>'
        }
        d += "</div>";
        $(this).append(d)
        })
    } (function(a) {
    a.widget("ui.combobox", {
        _create: function() {
            var c = this,
            b = this.element.hide(),
            d = b.children(":selected"),
            d = d.val() ? d.text() : "",
            e = a("<input>").insertAfter(b).val(d).autocomplete({
                delay: 0,
                minLength: 0,
                source: function(c, d) {
                    var e = RegExp(a.ui.autocomplete.escapeRegex(c.term), "i");
                    d(b.children("option").map(function() {
                        var b = a(this).text();
                        if (this.value && (!c.term || e.test(b))) {
                            return {
                                label: b.replace(RegExp("(?![^&;]+;)(?!<[^<>]*)(" + a.ui.autocomplete.escapeRegex(c.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
                                value: b,
                                option: this
                            }
                        }
                    }))
                    },
                select: function(a, b) {
                    b.item.option.selected = true;
                    c._trigger("selected", a, {
                        item: b.item.option
                    })
                    },
                change: function(c, d) {
                    if (!d.item) {
                        var e = RegExp("^" + a.ui.autocomplete.escapeRegex(a(this).text()) + "$", "i"),
                        f = false;
                        b.children("option").each(function() {
                            if (this.value.match(e)) {
                                return this.selected = f = true,
                                false
                            }
                        });
                        if (!f) {
                            return b.val(""),
                            false
                        }
                    }
                }
            }).addClass("ui-widget ui-widget-content ui-corner-left");
            e.data("autocomplete")._renderItem = function(b, c) {
                return a("<li></li>").data("item.autocomplete", c).append("<a>" + c.label + "</a>").appendTo(b)
                };
            a("<button type=button></button>").attr("tabIndex", -1).attr("title", "Show All Items").insertAfter(e).button({
                icons: {
                    primary: "ui-icon-triangle-1-s"
                },
                text: false
            }).removeClass("ui-corner-all").addClass("ui-corner-right ui-button-icon").click(function() {
                if (e.autocomplete("widget").is(":visible")) {
                    return e.autocomplete("close"),
                    false
                }
                e.autocomplete("search", "");
                e.focus()
                })
            }
    })
    })(jQuery); (function(a) {
    a.widget("ui.comboboxValidate", {
        _create: function() {
            var c = this,
            b = this.element.hide(),
            d = b.children(":selected"),
            d = d.val() ? d.text() : "",
            e = a("<input>").insertAfter(b).val(d).autocomplete({
                delay: 0,
                minLength: 0,
                source: function(c, d) {
                    var e = RegExp(a.ui.autocomplete.escapeRegex(c.term), "i");
                    d(b.children("option").map(function() {
                        var b = a(this).text();
                        if (this.value && (!c.term || e.test(b))) {
                            return {
                                label: b.replace(RegExp("(?![^&;]+;)(?!<[^<>]*)(" + a.ui.autocomplete.escapeRegex(c.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
                                value: b,
                                option: this
                            }
                        }
                    }))
                    },
                select: function(a, b) {
                    b.item.option.selected = true;
                    c._trigger("selected", a, {
                        item: b.item.option
                    })
                    },
                change: function(c, d) {
                    if (!d.item) {
                        var e = RegExp("^" + a.ui.autocomplete.escapeRegex(a(this).text()) + "$", "i"),
                        f = false;
                        b.children("option").each(function() {
                            if (this.value.match(e)) {
                                return this.selected = f = true,
                                false
                            }
                        });
                        if (!f) {
                            return a(this).val(""),
                            b.val(""),
                            false
                        }
                    }
                }
            }).addClass("ui-widget ui-widget-content ui-corner-left");
            e.data("autocomplete")._renderItem = function(b, c) {
                return a("<li></li>").data("item.autocomplete", c).append("<a>" + c.label + "</a>").appendTo(b)
                };
            a("<button type=button></button>").attr("tabIndex", -1).attr("title", "Show All Items").insertAfter(e).button({
                icons: {
                    primary: "ui-icon-triangle-1-s"
                },
                text: false
            }).removeClass("ui-corner-all").addClass("ui-corner-right ui-button-icon").click(function() {
                if (e.autocomplete("widget").is(":visible")) {
                    return e.autocomplete("close"),
                    false
                }
                e.autocomplete("search", "");
                e.focus()
                })
            }
    })
    })(jQuery);
function parseIntOrZero(a) {
    return isNaN(a) ? 0: parseInt(a)
    }
function parseFloatOrZero(a) {
    return isNaN(a) ? 0: parseFloat(a)
    }
function stripAlphaChars(a) {
    return a = a.replace(/[^0-9\.]+/g, "")
    }
    $(".slideShowThumb").live("click", function (a) {
        a.preventDefault();
        var c = $(this).attr("href");
        var a = "";
        if ($(this).attr("title")) {
            $(this).attr("title").replace(/[^a-zA-Z 0-9]+/g, "") 
        }

        var c = '<div style="min-height:450px"><img src="' + c + '" alt="' + a + '"/>';
        c += '<p class="caption">' + a + "</p></div>";
        $("#thumbStrip").length > 0 && (c += $("#thumbStrip").html());
        mediaViewer(c)
    });

jQuery.fn.ForceNumericOnly =
function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        });
    });
};


var isMobile = /iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase());


(function ($) {
    $.fn.hasScrollBar = function () {
        return this.get(0).scrollHeight > this.height();
    };
    $.fn.lionbars = function (options) {
        options = options || {};
        autohide = options.autohide;

        // Flags
        var timeout,
			HDragging = false,
			VDragging = false,
			activeScroll = 0,
			activeWrap = 0,
			eventX,
			eventY,
			mouseX,
			mouseY,
			currentRatio,
			initPos,
			scrollValue,
			hideTimeoutSet = false,
			vEventFired = false,
			hEventFired = false;

        // Initialization
        var elements = $(this),
			id = 0,
			vScrollWidth = 0, hScrollWidth = 0,
			addHScroll = false, addVScroll = false,
			paddingTop = 0, paddingLeft = 0, paddingBottom = 0, paddingRight = 0,
			borderTop = 0, borderRight = 0, borderBottom = 0, borderLeft = 0,
			scrollHeight = 0, scrollWidth = 0, offsetWidth = 0, offsetHeight = 0, clientWidth = 0, clientHeight = 0,
			vRatio = 0, hRatio = 0,
			vSliderHeight = 0, hSliderHeight = 0,
			vLbHeight = 0, hLbHeight = 0;

        // Main Loop
        mainLoop();

        function mainLoop() {
            for (var i = 0; elements[i] !== undefined; i++) {
                if (needScrollbars(elements[i]) && !$(elements[i]).hasClass('nolionbars')) {
                    // add the element to the main array
                    target = elements[i];

                    // get some values before the element is wrapped
                    getDimentions(target);

                    // wrap the element
                    wrap(target, addVScroll, addHScroll);

                    // hide the default scrollbar
                    hideScrollbars(target, addVScroll, addHScroll);

                    // Calculate the size of the scrollbars
                    reduceScrollbarsWidthHeight(target);
                    setSlidersHeight(target);

                    // Set variables needed to calculate scroll speed, etc.
                    setScrollRatios(target);

                    // Set events
                    setEvents(target);

                    // prepare for next element
                    resetVars();
                }
            }
        }

        // Set document events
        $(document).mousemove(function (e) {
            if (VDragging) {
                mouseY = e.pageY;
                activeWrap.scrollTop((initPos + mouseY - eventY) * Math.abs(currentRatio));
            }
            if (HDragging) {
                mouseX = e.pageX;
                activeWrap.scrollLeft((initPos + mouseX - eventX) * Math.abs(currentRatio));
            }
        });
        $(document).mouseup(function (e) {
            if (VDragging) {
                VDragging = false;
            }
            if (HDragging) {
                HDragging = false;
            }
        });

        // Core functions
        function setEvents(elem) {
            var el = $(elem);

            if (addVScroll || addHScroll) {
                el.find('.lb-wrap').scroll(function (e) {
                    el.find('.lb-v-scrollbar-slider').css({ "top": -$(this).scrollTop() / el.attr('vratio') });
                    el.find('.lb-h-scrollbar-slider').css({ "left": -$(this).scrollLeft() / el.attr('hratio') });

                    if (el.find('.lb-v-scrollbar').height() == (parseInt(el.find('.lb-v-scrollbar-slider').css('top')) + el.find('.lb-v-scrollbar-slider').height())
						&& typeof (options.reachedBottom) == 'function'
						&& !vEventFired
					) {
                        vEventFired = true;
                        var self = $(this);

                        // TODO: make this work for ie8 and opera
                        $(this).children('.lb-content').bind('DOMSubtreeModified', function () {
                            getDimentions($(self).parent(), {
                                height: $(self).children('.lb-content').get(0).scrollHeight,
                                width: $(self).children('.lb-content').get(0).scrollWidth
                            });

                            // Calculate the size of the scrollbars
                            reduceScrollbarsWidthHeight($(self).parent());
                            setSlidersHeight($(self).parent());

                            // Set variables needed to calculate scroll speed, etc.
                            setScrollRatios($(self).parent());

                            // prepare for next element
                            resetVars();

                            vEventFired = false;
                            $(self).children('.lb-content').unbind('DOMSubtreeModified');
                        });

                        options.reachedBottom.apply($(this).children('.lb-content'));
                    }

                    if (el.find('.lb-h-scrollbar').width() == (parseInt(el.find('.lb-h-scrollbar-slider').css('left')) + el.find('.lb-h-scrollbar-slider').width())
						&& typeof (options.reachedRight) == 'function'
						&& !hEventFired
					) {
                        hEventFired = true;
                        var self = $(this);

                        // TODO: make this work for ie8 and opera
                        $(this).children('.lb-content').bind('DOMSubtreeModified', function () {
                            getDimentions($(self).parent(), {
                                height: $(self).children('.lb-content').get(0).scrollHeight,
                                width: $(self).children('.lb-content').get(0).scrollWidth
                            });

                            // Calculate the size of the scrollbars
                            reduceScrollbarsWidthHeight($(self).parent());
                            setSlidersHeight($(self).parent());

                            // Set variables needed to calculate scroll speed, etc.
                            setScrollRatios($(self).parent());

                            // prepare for next element
                            resetVars();

                            vEventFired = false;
                            $(self).children('.lb-content').unbind('DOMSubtreeModified');
                        });

                        options.reachedRight.apply($(this).children('.lb-content'));
                    }

                    if (autohide) {
                        el.find('.lb-v-scrollbar, .lb-h-scrollbar').fadeIn(150);
                        clearTimeout(timeout);
                        timeout = setTimeout(function () {
                            el.find('.lb-v-scrollbar, .lb-h-scrollbar').fadeOut(150);
                        }, 2000);
                    }
                });
            }

            if (addVScroll) {
                el.find('.lb-v-scrollbar-slider').mousedown(function (e) {
                    eventY = e.pageY;

                    VDragging = true;
                    activeScroll = $(this);
                    activeWrap = el.find('.lb-wrap');
                    currentRatio = activeWrap.parent().attr('vratio');
                    initPos = activeScroll.position().top;
                    return false;
                });
                el.find('.lb-v-scrollbar').mousedown(function (e) {
                    if (!$(e.target).hasClass('lb-v-scrollbar-slider')) {
                        el.find('.lb-wrap').scrollTop((e.pageY - $(this).offset().top) * Math.abs(el.attr('vratio')) - $(this).find('.lb-v-scrollbar-slider').height() / 2);
                    }
                    return false;
                });
            }

            if (addHScroll) {
                el.find('.lb-h-scrollbar-slider').mousedown(function (e) {
                    eventX = e.pageX;

                    HDragging = true;
                    activeScroll = $(this);
                    activeWrap = el.find('.lb-wrap');
                    currentRatio = activeWrap.parent().attr('hratio');
                    initPos = activeScroll.position().left;
                    return false;
                });
                el.find('.lb-h-scrollbar').mousedown(function (e) {
                    if (!$(e.target).hasClass('lb-h-scrollbar-slider')) {
                        el.find('.lb-wrap').scrollLeft((e.pageX - $(this).offset().left) * Math.abs(el.attr('hratio')) - $(this).find('.lb-h-scrollbar-slider').width() / 2);
                    }
                    return false;
                });
            }

            if ((addVScroll || addHScroll) && autohide) {
                el.find('.lb-v-scrollbar, .lb-h-scrollbar').hide();

                el.find('.lb-v, .lb-h').hover(function () {
                    clearTimeout(timeout);
                    el.find('.lb-v-scrollbar, .lb-h-scrollbar').fadeIn(150);
                }, function () {
                    clearTimeout(timeout);
                    timeout = setTimeout(function () {
                        el.find('.lb-v-scrollbar, .lb-h-scrollbar').fadeOut(150);
                    }, 2000);
                });
            }
        }
        function setScrollRatios(elem) {
            vRatio = (offsetHeight - $(elem).find('.lb-wrap').get(0).scrollHeight - borderTop - borderBottom) / (vLbHeight - vSliderHeight);
            hRatio = (offsetWidth - $(elem).find('.lb-wrap').get(0).scrollWidth - borderLeft - borderRight) / (hLbHeight - hSliderHeight);

            var el = $(elem);
            el.attr('vratio', vRatio);
            el.attr('hratio', hRatio);
        }
        function setSlidersHeight(elem) {
            var el = $(elem);
            var hmin, hmax, gap;

            if (el.find('.lb-v-scrollbar').length != 0) {
                hmin = 20;
                gap = offsetHeight - el.find('.lb-v-scrollbar').height();
                hmax = offsetHeight - gap - hmin;
                vSliderHeight = Math.round((offsetHeight * hmax) / scrollHeight);
                vSliderHeight = (vSliderHeight < hmin) ? hmin : vSliderHeight;
            }

            if (el.find('.lb-h-scrollbar').length != 0) {
                hmin = 20;
                gap = offsetWidth - el.find('.lb-h-scrollbar').width();
                hmax = offsetWidth - gap - hmin;
                hSliderHeight = Math.round((offsetWidth * hmax) / scrollWidth);
                hSliderHeight = (hSliderHeight < hmin) ? hmin : hSliderHeight;
            }
            el.find('.lb-v-scrollbar-slider').css({ "height": vSliderHeight });
            el.find('.lb-h-scrollbar-slider').css({ "width": hSliderHeight });
        }
        function resetVars() {
            vScrollWidth = 0;
            hScrollWidth = 0;
            addHScroll = false;
            addVScroll = false;
            paddingTop = 0;
            paddingLeft = 0;
            paddingBottom = 0;
            paddingRight = 0;
            borderTop = 0;
            borderLeft = 0;
            borderBottom = 0;
            borderRight = 0;
            scrollHeight = 0;
            scrollWidth = 0;
            offsetWidth = 0;
            offsetHeight = 0;
            clientWidth = 0;
            clientHeight = 0;
            // vRatio = 0;
            // hRatio = 0;
            vSliderHeight = 0;
            hSliderHeight = 0;
            vLbHeight = 0;
            hLbHeight = 0;
        }
        function reduceScrollbarsWidthHeight(elem) {
            var el = $(elem);

            if (addVScroll && addHScroll) {
                vLbHeight = el.height() - 12;
                hLbHeight = el.width() - 12;
                el.find('.lb-v').css({ "height": vLbHeight });
                el.find('.lb-h').css({ "width": hLbHeight });
            } else {
                vLbHeight = el.height() - 4;
                hLbHeight = el.width() - 4;
                el.find('.lb-v').css({ "height": vLbHeight });
                el.find('.lb-h').css({ "width": hLbHeight });
            }
        }
        function hideScrollbars(elem, vscroll, hscroll) {
            var el = $(elem);

            if (vscroll || hscroll) {
                el.css({ "overflow": 'hidden' });
                movePadding(el, el.find('.lb-wrap'));
                resizeMainBox(el);
                resizeInnerWrap(el, el.find('.lb-wrap'));
            }
        }
        function resizeMainBox(elem) {
            var el = $(elem);
            el.css({ "width": el.width() + paddingLeft + paddingRight, "height": el.height() + paddingTop + paddingBottom });
        }
        function movePadding(from, to) {
            var fromEl = $(from);
            var toEl = $(to);

            fromEl.css({ "padding": 0 });
            toEl.css({
                "padding-top": paddingTop + 'px',
                "padding-left": paddingLeft + 'px',
                "padding-bottom": paddingBottom + 'px',
                "padding-right": paddingRight + 'px'
            });
        }
        function resizeInnerWrap(main, child) {
            var mainEl = $(main);
            var childEl = $(child);
            mainEl.css({ "position": 'relative' });
            childEl.css({
                "width": mainEl.width() + vScrollWidth - paddingLeft - paddingRight,
                "height": mainEl.height() + hScrollWidth - paddingTop - paddingBottom
            });
        }
        function setVScrollbarWidth(elem) {
            var el = $(elem);
            el.css({ "overflow": 'auto' });
            vScrollWidth = offsetWidth - clientWidth - borderLeft - borderRight;
            el.css({ "overflow": 'hidden' });
        }
        function setHScrollbarWidth(elem) {
            var el = $(elem);
            el.css({ "overflow": 'auto' });
            hScrollWidth = offsetHeight - clientHeight - borderTop - borderBottom;
            el.css({ "overflow": 'hidden' });
        }
        function wrap(elem, vscroll, hscroll) {
            var el = $(elem);
            var elemId = el.attr('id');
            var wrap = 0;

            if (elemId !== undefined) {
                el.wrapInner('<div class="lb-wrap" id="lb-wrap-' + id + '-' + elemId + '"></div>');
                wrap = $('#lb-wrap-' + id + '-' + elemId);
            } else {
                el.wrapInner('<div class="lb-wrap" id="lb-wrap-' + id + '"></div>');
                wrap = $('#lb-wrap-' + id);
            }
            wrap.wrapInner('<div class="lb-content"></div>');
            if (vscroll) {
                el.prepend('<div class="lb-v"><div class="lb-v-scrollbar"></div></div>');
                el.find('.lb-v-scrollbar').append('<div class="lb-v-scrollbar-slider"></div>');
            }
            if (hscroll) {
                el.prepend('<div class="lb-h"><div class="lb-h-scrollbar"></div></div>');
                el.find('.lb-h-scrollbar').append('<div class="lb-h-scrollbar-slider"></div>');
            }

            // preparation for the next element
            id = id + 1;
        }
        function needScrollbars(elem) {
            var el = $(elem);
            addVScroll = false;
            addHScroll = false;

            getPadding(el);
            getBorders(el);

            el.css({ "overflow": 'hidden' });

            // check for vertical scrollbars
            if (el.get(0).scrollHeight > el.get(0).clientHeight) {
                addVScroll = true;
                // setVScrollbarWidth(el);
            }

            // check for horizontal scrollbars
            if (el.get(0).scrollWidth > el.get(0).clientWidth) {
                addHScroll = true;
                // setHScrollbarWidth(el);
            }

            el.css({ "overflow": 'auto' });

            if (addVScroll || addHScroll) {
                return true;
            }
        }
        function getPadding(elem) {
            var el = $(elem);

            paddingTop = parseInt(el.css('padding-top').replace('px', ''));
            paddingLeft = parseInt(el.css('padding-left').replace('px', ''));
            paddingBottom = parseInt(el.css('padding-bottom').replace('px', ''));
            paddingRight = parseInt(el.css('padding-right').replace('px', ''));
        }
        function getBorders(elem) {
            var el = $(elem);

            borderTop = parseInt(el.css('border-top-width').replace('px', ''));
            borderRight = parseInt(el.css('border-right-width').replace('px', ''));
            borderBottom = parseInt(el.css('border-bottom-width').replace('px', ''));
            borderLeft = parseInt(el.css('border-left-width').replace('px', ''));
        }
        function getDimentions(elem, scroll) {
            var el = $(elem).get(0);

            scrollHeight = (typeof (scroll) != 'undefined') ? scroll.height : el.scrollHeight;
            scrollWidth = (typeof (scroll) != 'undefined') ? scroll.width : el.scrollWidth;
            clientHeight = el.clientHeight;
            clientWidth = el.clientWidth;
            offsetHeight = el.offsetHeight;
            offsetWidth = el.offsetWidth;

            setVScrollbarWidth($(elem));
            setHScrollbarWidth($(elem));
        }

        return this.each(function () {
            //var $this = $(this);
        });
    };
})(jQuery);


function eauLogout() {

    $.post("/Utils/logout.asp?did=1");
    var a = false;
    $.ajax({
        type: "Post",
        url: "/app/LoginWebApi/Logout",
        data: null,
        dataType: "json",
        contentType: "application/json;",
        cache: false,
        async: false,
        success: function () {
            a = true;
           
            location.reload(true)

        },
        error: function (a, c, d) {
            alert("An unexpected error has occurred. Please try again. If errors continue contact customer support. " + a.status + " " + d)

        }

    });
}
function addLoader(element) {
    $(element).append('<div class="ajaxLoader"></div>');
}
function removeLoader(element) {
    $(".ajaxLoader").remove();
}
