﻿// JScript File

SetCss = function () {
    if (screen.width >= 1024 && screen.width < 1280)
        document.getElementById('BaseStyle').href = '/shared/style/BaseStyle1024.css';
    if (screen.width >= 1280)
        document.getElementById('BaseStyle').href = '/shared/style/BaseStyle1280.css';
}

var navShowTimeout;

TopNavHover = function (nav) {
    var ni = $("#" + nav + " li");
    for (i = 0; i < ni.length; i++) {
        var obj = ni.eq(i);
        obj.attr("id", "topNav_" + i);
        if (obj.hasClass("parent")) {
            obj.hover(
                function () {
                    var timeoutLength = 0;
                    if ($(this).parent().parent().attr("id") == "links")
                        timeoutLength = 300;
                    navShowTimeout = setTimeout("showNav('" + this.id + "');", timeoutLength);
                },
                function () {
                    clearTimeout(navShowTimeout);
                    $(this).removeClass("over");
                    $("#" + this.id + " ul").eq(0).fadeOut("fast");
                }
            );
        }
    }
}

showNav = function (id) {
    $("#" + id).addClass("over");
    $("#" + id + " ul").eq(0).fadeIn("fast");
}

PageNavHover = function (nav) {
    if (document.getElementById(nav)) {
        var navItems = document.getElementById(nav).getElementsByTagName("li");
        for (var i = 0; i < navItems.length; i++) {
            if (navItems[i].className == "parent") {
                var navSideItems = navItems[i].getElementsByTagName("li");
                for (var j = 0; j < navSideItems.length; j++) {
                    if (navSideItems[j].className == "parent") {
                        navSideItems[j].onmouseover = function () { this.className += " over"; }
                        navSideItems[j].onmouseout = function () { this.className = "parent"; }
                    }
                }
            }
        }
    }
}

ResizeForIframe = function () {
    TopNavHover('links');
    //  TopNavHover('pageLinks');
    //  SetCss();

    var f = document.getElementById('AppIframe');

    function resize() {
        var h = "";
        var w = "";
        if (f.Document && f.Document.body.scrollHeight) //ie5+ syntax
            h = f.Document.body.scrollHeight;
        else if (f.contentDocument) {
            h = f.contentDocument.documentElement.offsetHeight + 25 + "px";
            // can't find anything for Opera and Firefox that works for the width. OffetWidth doesn't work right either.
            // w = f.contentDocument.defaultView.getComputedStyle(f.contentDocument.documentElement,"").getPropertyValue("width");
        }
        else if (f.contentWindow) {
            try {
                h = f.contentWindow.document.getElementById("IframeContainer").scrollHeight + 65 + "px";
            }
            catch (err) {
                h = f.contentWindow.document.body.scrollHeight + 25 + "px";
            }
            // w = f.contentWindow.document.body.scrollWidth + 5 + "px";
        }
        else if (f.contentDocument && f.contentDocument.body.scrollHeight) //ns6+ / opera syntax
            h = f.contentDocument.body.scrollHeight + 25 + "px";
        else if (f.contentDocument && f.contentDocument.body.offsetHeight) //standards compliant syntax - probably nothing will drop through to this
            h = f.contentDocument.body.offsetHeight + 25 + "px";
        else {
            return;
        }

        // f.setAttribute("width", w);
        $(f).css("height", h);
        //f.setAttribute("height", h);
        // f.parentNode.setAttribute("width",w);
        f.parentNode.setAttribute("height", h);
    }

    if (f != null) {
        if (window.addEventListener) {
            f.onload = resize;
        }
        else if (f.attachEvent) {
            f.attachEvent("onload", resize);
        }
        else {
            return;
        }
        resize();
    }
}

window.onload = ResizeForIframe;

function TrapEnterKeyPress(btn, event) {
    if (document.all) {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.getElementById) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
    else if (document.layers) {
        if (event.which == 13) {
            event.returnValue = false;
            event.cancel = true;
            btn.click();
        }
    }
}
