﻿//VER:2.0.0-A
//Copyright (c) 2009 TechPros, LLC (A Michigan Limited Liability Company)
//This website and the code contained within this website belong to its creator, 
//Thomas J. Thelen, owner of TechPros, LLC.
//This code may not be redistributed, copied, altered, or resold 
//without the explicit permission of its creator.
//If this website is not registered to you or your company then it may not be used 
//without obtaining a legal copy from TechPros, LLC.
//You may visit the TechPros, LLC website at "http://www.mitechpros.com" for more information on 
//how to obtain a legal copy of this website and/or the program(s) associated with it.

var i = 0;
var SetSizeTimer;
var strPrevSubMenu = "";
var strPicSrc = "http://" + document.domain + "/Core/Open/Images/Menu/arrow.png";
var strPicSrc2 = "http://" + document.domain + "/Core/Open/Images/Menu/arrow2.png";
var arrMenu = new Array();


function PageLoaded() {
    LoadMenu();
    Initiate_Menu_tabs();
    CheckForPopUps();
    SetSizes(0, 0);
    CheckResolution();
    
    var bolTmpContinue = true;
    
    var intTmpCount = -1

    while (bolTmpContinue == true) {
        intTmpCount += 1;
        if (document.getElementById("SMI" + intTmpCount)) {
            arrMenu[intTmpCount] = document.getElementById("SMI" + intTmpCount);
        }
        else {
            bolTmpContinue = false;
        }
    }
}

function CheckResolution() {
    var strSaveRes;
    
    if (document.getElementById("divBody").offsetWidth >= 1280) {
        if (document.getElementById(strdivMainID).style.width != 1280) {
            strSaveRes = "width=1280";
        }
        else {
            strSaveRes = "width=auto";
        }
    }

    if (document.getElementById("divBody").offsetHeight >= 950) {
        if (strSaveRes != "") {
            strSaveRes = strSaveRes + "&";
        }
        if (document.getElementById(strdivMainID).style.height != 950) {
            strSaveRes = strSaveRes + "height=950";
        }
        else {
            strSaveRes = strSaveRes + "height=auto";
        }
    }

    if (strSaveRes != "") {
        document.getElementById('ifrmSaveVars').src = "/Core/Open/Components/save vars.aspx?" + strSaveRes;
    }
}

function LoadMenu() {
    var strLastOpenMenu = Cookies.getCookie("LastOpenMenu")
    var strPrevMenuID = Cookies.getCookie("PrevMenuID")

    if (strPrevMenuID != "" && strPrevMenuID != null) {
        if (strLastOpenMenu != "" & strLastOpenMenu != null && strMenuID == strPrevMenuID) {
            if (strLastOpenMenu.indexOf("Button") == -1) {
                ShowSubMenus(strLastOpenMenu, "ALL");
                strPrevSubMenu = strLastOpenMenu;
            }
            else {
                document.getElementById(strLastOpenMenu).focus();
            }
        }
    }
}

function MenuMouseOver(strPic, strPicID, intNum, strColor) {
    document.getElementById(strPicID + intNum).src = strPic;
    
    if (bolIsNotIE6 == false) {
        if (strColor == "") {
            strColor = "#000000";
        }
    
        arrMenu[intNum].style.color = strColor;
    }
}

function CheckForPopUps() {
    var strLinks = document.getElementsByTagName("a");

    var intLeftPosition = (screen.width) ? (screen.width - 200) / 2 : 0;
    var intTopPosition = (screen.height) ? (screen.height - 100) / 2 : 0;

    for (i = 0; i < strLinks.length; i++) {
        if (strLinks[i].className == "PopUp" || strLinks[i].className.indexOf("PopUp") != -1) {
            strLinks[i].onclick = function() {
                window.open(this.href);
                return false;
            }
        }
        else if (strLinks[i].href.indexOf("http://sec.sec/") != -1) {
            strLinks[i].onclick = function() {
                window.open(this.href.replace("http://sec.sec/", ""), "_blank", "width=200,height=100,top=" + intTopPosition + ",left=" + intLeftPosition);
                return false;
            }
        }
    }
}

function Load_Page(strURI) {
    if (strURI != null) {
        window.location = strURI;
    }
}

function CookieHandler() {
    var expires;

	this.setCookie = function (strName, strValue, intSeconds) {

		if (typeof intSeconds != "undefined" && intSeconds != 0) {
			var strDate = new Date();
			strDate.setTime(strDate.getTime() + (intSeconds * 1000));
			strExpires = "; expires=" + strDate.toGMTString();
		}
		else{
			strExpires = "";
		}
		document.cookie = strName + "=" + strValue + strExpires + "; path=/";
	}

	this.getCookie = function (strName) {
		strName = strName + "=";
		var aryCookie = document.cookie.split(";");

		for(i = 0;i < aryCookie.length; i++) {
			var c = aryCookie[i];
			while (c.charAt(0) == " ") c = c.substring(1, c.length);
			if (c.indexOf(strName) == 0) return c.substring(strName.length, c.length);
		}
		return null;
	}
	this.deleteCookie = function (strName) {
		this.setCookie(strName, "", -1);
	}
}

var Cookies = new CookieHandler();

function SetSizes(intPrevHeight, intPrevWidth) {
    var intDivWidth = 0, intDivHeight = 0, bolBodyOverflow = false;
    var intMinHeight = 570, intMinWidth = 980, intMaxHeight = 950, intMaxWidth = 1280;
    var intFixHeight = 0, intFixWidth = 0, bolHeightDif = true, bolWidthDif = true;

    intDivWidth = document.body.offsetWidth;
    intDivHeight = document.body.offsetHeight;

    if (intDivHeight == intPrevHeight) {
        bolHeightDif = false;
    }

    if (intDivWidth == intPrevWidth) {
        bolWidthDif = false;
    }

    if (intDivHeight < intMinHeight && bolHeightDif) {
        intFixHeight = 1;
    }
    else if (intDivHeight > intMaxHeight && bolHeightDif) {
        intFixHeight = 2;
    }

    if (intDivWidth < intMinWidth && bolWidthDif) {
        intFixWidth = 1;
    }
    else if (intDivWidth > intMaxWidth && bolWidthDif) {
        intFixWidth = 2;
    }

    if (bolHeightDif) {
        if (intFixHeight == 1) {
            if (document.getElementById(strdivMainID).style.height != intMinHeight + "px") {
                document.getElementById(strdivMainID).style.height = intMinHeight + "px";
            }
        }
        else if (intFixHeight == 2) {
            if (document.getElementById(strdivMainID).style.height != intMaxHeight + "px") {
                document.getElementById(strdivMainID).style.height = intMaxHeight + "px";
            }
        }
        else {
            if (document.getElementById(strdivMainID).style.height != "100%") {
                document.getElementById(strdivMainID).style.height = "100%";
            }
        }
    }

    if (bolWidthDif) {
        if (intFixWidth == 1) {
            if (document.getElementById(strdivMainID).style.width != intMinWidth + "px") {
                document.getElementById(strdivMainID).style.width = intMinWidth + "px";
            }
        }
        else if (intFixWidth == 2) {
            if (document.getElementById(strdivMainID).style.width != intMaxWidth + "px") {
                document.getElementById(strdivMainID).style.width = intMaxWidth + "px";
            }
        }
        else {
            if (document.getElementById(strdivMainID).style.width != "100%") {
                document.getElementById(strdivMainID).style.width = "100%";
            }
        }
    }

    SetSizeTimer = setTimeout("SetSizes(" + intDivHeight + ", " + intDivWidth + ")", 2000);
}

function ShowOrHide(strItems, strState, strType) {
    var intCount = 0;
    var strItems2 = new Array();

    if (typeof strItems == "object") {
        intCount = strItems.length - 1;
        strItems2 = strItems;
    }
    else {
        strItems2[0] = strItems;
    }

    for (i = 0; i <= intCount; i++) {
        if (document.getElementById(strItems2[i]) == "null") {
            return false;
        }
        
        if (document.getElementById(strItems2[i])) {
            if (strType == "DIS") {
                if (strState == "CHANGE") {
                    if (typeof document.getElementById(strItems2[i]).style.display == "undefined") {
                        document.getElementById(strItems2[i]).style.display = "inline";
                    }
                    else {
                        if (document.getElementById(strItems2[i]).style.display == "inline") {
                            document.getElementById(strItems2[i]).style.display = "none";
                        }
                        else {
                            document.getElementById(strItems2[i]).style.display = "inline";
                        }
                    }
                }
                else if (strState == "SHOW") {
                    document.getElementById(strItems2[i]).style.display = "inline";
                }
                else if (strState == "HIDE") {
                    document.getElementById(strItems2[i]).style.display = "none";
                }
            }
            else if (strType == "VIS") {
                if (strState == "CHANGE") {
                    if (typeof document.getElementById(strItems2[i]).style.visibility == "undefined") {
                        document.getElementById(strItems2[i]).style.visibility = "visible";
                    }
                    else {
                        if (document.getElementById(strItems2[i]).style.visibility == "visible") {
                            document.getElementById(strItems2[i]).style.visibility = "hidden";
                        }
                        else {
                            document.getElementById(strItems2[i]).style.visibility = "visible";
                        }
                    }
                }
                else if (strState == "SHOW") {
                    document.getElementById(strItems2[i]).style.visibility = "visible";
                }
                else if (strState == "HIDE") {
                    document.getElementById(strItems2[i]).style.visibility = "hidden";
                }
            }
        }
    }
}

function ChangMenuPic(strID, strWhat) {
    if (strID != "") {
        if (strWhat == "CHANGE") {
            if (document.getElementById(strID).src == strPicSrc) {
                document.getElementById(strID).src = strPicSrc2;
            }
            else if (document.getElementById(strID).src == strPicSrc2) {
                document.getElementById(strID).src = strPicSrc;
            }
        }
        else if (strWhat == "OPEN") {
            document.getElementById(strID).src = strPicSrc2;
        }
        else if (strWhat == "CLOSED") {
            document.getElementById(strID).src = strPicSrc;
        }
    }
}

function ShowSubMenus(strItem, strWhat) {
    var strItem2 = strItem.split("_");
    var intCount, bolContinue, strTemp = new Array(1);

    if (strWhat == "ALL") {
        ChangMenuPic("iButton" + strItem2[0].replace("Sub", ""), "OPEN");
    }

    if (strItem2[0] != strPrevSubMenu.split("_")[0] && strPrevSubMenu != "") {
        HideSubMenus(strPrevSubMenu.split("_")[0] + "_0", "ALL");
    }
    else {
        if (strPrevSubMenu.split("_").length >= strItem2.length && strPrevSubMenu != strItem) {
            strTemp[0] = "";
            strTemp[1] = "";
            for (i = 0; i <= strItem2.length - 1; i++) {
                if (strTemp[0] == "") {
                    strTemp[0] = strPrevSubMenu.split("_")[i];
                    strTemp[1] = "iSub" + strTemp[0].replace("Sub", "");
                }
                else {
                    strTemp[0] = strTemp[0] + "_" + strPrevSubMenu.split("_")[i];
                    if ((strItem2.length - 1) - i != 0) {
                        strTemp[1] = strTemp[1] + "_" + strPrevSubMenu.split("_")[i];
                    }
                }
            }
            HideSubMenus(strTemp[0], "");
            ChangMenuPic(strTemp[1], "CLOSED");
        }
    }

    for (i = 0; i <= strItem2.length - 1; i++) {
        bolContinue = false;
        intCount = -1;

        strTemp[0] = "";
        for (i2 = 0; i2 <= i; i2++) {
            if (strTemp[0] == "") {
                strTemp[0] = strItem2[i2];
            }
            else {
                strTemp[0] = strTemp[0] + "_" + strItem2[i2];
            }
        }

        if (strTemp[0] != strTemp[1] && strTemp[0].split("_").length <= strItem.split("_").length - 1) {
            if (document.getElementById("i" + strTemp[0]) != null) {
                ChangMenuPic("i" + strTemp[0], "OPEN");
            }
            
            do {
                intCount += 1;
                if (document.getElementById(strTemp[0] + "_" + intCount) != null) {
                    if (document.getElementById(strTemp[0] + "_" + intCount).style.display == "none") {
                        document.getElementById(strTemp[0] + "_" + intCount).style.display = "block";
                        document.getElementById(strTemp[0] + "_" + intCount).focus();
                    }
                }
                else {
                    bolContinue = true;
                }
            }
            while (bolContinue == false)
            
            strTemp[1] = strTemp[0];
        }
        else {
            i = strItem2.length;
        }
    }
}

function HideSubMenus(strItem, strWhat) {
    var strItem2 = strItem.split("_");
    var intCount, intCount2, intNum, bolContinue, strTemp = new Array(1);

    if (strWhat == "ALL") {
        ChangMenuPic("iButton" + strItem2[0].replace("Sub", ""), "CLOSED");
    }

    intCount2 = strItem2.length - 1;
    if (strItem.length < strPrevSubMenu.split("_").length) {
        intNum = strPrevSubMenu.split("_").length - 1;
    }
    else {
        intNum = strItem.length - 1;
    }

    for (i = intNum; i >= 0 - 1; i--) {
        bolContinue = false
        intCount = -1;

        strTemp[0] = "";
        if (intCount2 >= 0) {
            for (i2 = 0; i2 <= intCount2; i2++) {
                strTemp[0] = strTemp[0] + "_" + strItem2[i2];
            }
            intCount2 -= 1;
        }
        else {
            strTemp[0] = strItem2[0]
        }

        strTemp[0] = strTemp[0].replace("_Sub", "Sub");

        if (strTemp[0] != strTemp[1] && strTemp[0].split("_").length >= strItem.split("_").length - 1) {
            do {
                intCount += 1;                  

                if (document.getElementById(strTemp[0] + "_" + intCount) != null) {
                    if (document.getElementById(strTemp[0] + "_" + intCount).style.display == "block") {
                        document.getElementById(strTemp[0] + "_" + intCount).style.display = "none";

                        if (document.getElementById("i" + strTemp[0] + "_" + intCount) != null) {
                            ChangMenuPic("i" + strTemp[0] + "_" + intCount, "CLOSED");
                        }

                        if (document.getElementById(strTemp[0]) != null && strTemp[0].split("_").length != 2) {
                            if (document.getElementById(strTemp[0]).style.display == "block") {
                                document.getElementById(strTemp[0]).style.display = "none";

                                if (document.getElementById("i" + strTemp[0]) != null) {
                                    ChangMenuPic("i" + strTemp[0], "CLOSED");
                                }
                            }
                        }

                        if (document.getElementById(strTemp[0] + "_" + intCount + "_0") != null) {
                            if (document.getElementById(strTemp[0] + "_" + intCount + "_0").style.display == "block") {
                                HideSubMenus(strTemp[0] + "_" + intCount + "_0", "");
                            }
                        }
                    }
                }
                else {
                    bolContinue = true;
                }
            }
            while (bolContinue == false)

            strTemp[1] = strTemp[0];
        }
        else {
            i = -1;
        }
    }
}

function ShowOrHideSubMenus(strItem, strID) {
    var bolContinue = true;
    
    ChangMenuPic(strID, "CHANGE");
    if (document.getElementById(strItem).style.display == "block") {
        HideSubMenus(strItem, "");

        if (strItem.split("_").length == 2) {
            strPrevSubMenu = "";
        }
        else {
            strPrevSubMenu = strItem;
        }
    }
    else {
        ShowSubMenus(strItem, "");
        strPrevSubMenu = strItem;
    }

    Cookies.setCookie("PrevMenuID", strMenuID, 0);
    if (strItem.split("_").length == 2 && document.getElementById(strItem).style.display == "none") {
        Cookies.setCookie("LastOpenMenu", "", 0);
    }
    else {
        Cookies.setCookie("LastOpenMenu", strItem, 0); 
    }
}

function SubMenuHover(strID, strWhat) {
    if (strWhat == "HIGHLIGHT") {
        document.getElementById(strID).style.backgroundColor = strSubMenuBackColor;
    }
    else if (strWhat == "CLEAR") {
        document.getElementById(strID).style.backgroundColor = "Transparent";
    }
}