﻿// Java Script file for inc_top_menu.vb
var ImageArray = new Array(6); // Preload the images into an array for faster response.
var vIE;
var Timeout_ID, GTimeout_ID;
var vPrevID = "";

if(document.all) vIE = true; else vIE = false;

// Preload images for speed reasons.
function Preload_Img(pImage, pNumber){
    ImageArray[pNumber] = new Image();
    ImageArray[pNumber].src = pImage;
}
// Handle the GRAPHICAL menu clicks.
function itm_GMenuClick(){
    var fDiv = document.getElementById("divMnuAdmin");
    var fImg = document.getElementById("imgMenu");
    var IfrRef = document.getElementById("if_Main");
    if( fDiv.style.display == "block" ){ // Close the menu.
        mnu_GHide();
    }else{ // Open the menu.
        // Get coordinates.
        fTop = findTop( fImg ) + findHeight( fImg );
        fLeft = findLeft( fImg );
        // Set the div coordinates.
        fDiv.style.top = fTop + "px";
        fDiv.style.left = fLeft + "px";
        fDiv.style.display = "block";
        // Set the iFrame coordinates.
        IfrRef.style.top = (fTop + 2)+ "px";
        IfrRef.style.left = (fLeft + 2) + "px";
        IfrRef.style.width =  (fDiv.offsetWidth + 2) + "px";
        IfrRef.style.height = (fDiv.offsetHeight + 2) + "px";
        IfrRef.style.display = "block";
        fImg.src = ImageArray[0].src;
    }
}
// Handles a mouse out event to close a graphical menu after a pause of 500 milliseconds.
function itm_GMenuOut(pID, pImg_ID, pNumber1){
    GTimeout_ID = window.setTimeout("mnu_GHide();", 1000);
}
// Handles the mouse over event to cancel a menu close timer for a graphical menu.
function itm_GMenuOver(){
    clearTimeout(GTimeout_ID);
}
// Handles the closing of a graphical menu.
function mnu_GHide(){
    document.getElementById("divMnuAdmin").style.display = "none";
    document.getElementById("if_Main").style.display = "none";
    document.getElementById("imgMenu").src = ImageArray[1].src; // Display the menu closed image.
}

// Handle the TEXT based menu clicks *******************************************************************************
function itm_MenuClick(pID){
    var fTop, fLeft
    var fDiv = document.getElementById("div_" + pID);
    var fAnchor = document.getElementById("a_" + pID);
    var IfrRef = document.getElementById("if_" + pID);
    
    if( fDiv.style.display == "block" ){ // Close the menu.
        mnu_Hide(pID);
    }
    else{ // Close any previously opened menus, and then open the current menu.
        if(vPrevID != ""){
           mnu_Hide(vPrevID);
        }else{ // Close the main graphical menu if it's open.
            if(document.getElementById("divMnuAdmin") != null) if(document.getElementById("divMnuAdmin").style.display == "block") mnu_GHide();
        }
        vPrevID = pID;
        // Get coordinates.
        fTop = (findTop( fAnchor ) + findHeight( fAnchor )) - 1;
        fLeft = findLeft( fAnchor );
        // Set the div coordinates.
        fDiv.style.top = fTop + "px";
        fDiv.style.left = fLeft + "px";
        fDiv.style.display = "block";
        // Set the iFrame coordinates.
        IfrRef.style.top = (fTop + 2)+ "px";
        IfrRef.style.left = (fLeft + 2) + "px";
        IfrRef.style.width =  (fDiv.offsetWidth + 2) + "px";
        IfrRef.style.height = (fDiv.offsetHeight + 2) + "px";
        IfrRef.style.display = "block";
        // Set the anchor color to active.
        fAnchor.style.color = "white";
    }
}
// Handles a mouse out event to close a text menu after a pause of 1 second.
function itm_MenuOut(pID, pTID){
    Timeout_ID = window.setTimeout("mnu_Hide(\'" + pID + "\');", 1000);
}
// Handles the mouse over event to cancel a menu close timer for a text menu.
function itm_MenuOver(pID){
    if(pID == vPrevID) clearTimeout(Timeout_ID);
}
// Handles the closing of a text menu.
function mnu_Hide(pID){
    document.getElementById("a_" + pID).style.color = "#dcdcdc";
    document.getElementById("div_" + pID).style.display = "none";
    document.getElementById("if_" + pID).style.display = "none";
}

//**************************************** Side Menu JS *************************************
function Side_Toggle(pID, pImgDown, pImgUp){
    var fDiv1 = document.getElementById(pID + "_1");
    var fDiv2 = document.getElementById(pID + "_2");
    if( fDiv2.style.display == "none" ){
        fDiv1.style.backgroundImage = "url('" + ImageArray[pImgDown].src + "')";
        fDiv2.style.display = "block";
    }else{
        fDiv1.style.backgroundImage = "url('" + ImageArray[pImgUp].src + "')";
        fDiv2.style.display = "none";
    }
}
function Side_Over(pID, pFontColor, pBGColor, pImg){
    var fDiv =  document.getElementById("mdiv_" + pID);
    if (pFontColor != '') {fDiv.style.color = pFontColor;} else {fDiv.style.color = "black";}
    if (pBGColor != '') {fDiv.style.backgroundColor = pBGColor;} else {fDiv.style.backgroundColor = "white";}
//    fDiv.style.backgroundImage = "url('" + ImageArray[pImg].src + "')";
}
function Side_Out(pID, pFontColor, pBGColor){
    var fDiv =  document.getElementById("mdiv_" + pID);
    if (pFontColor != '') {fDiv.style.color = pFontColor;} else {fDiv.style.color = "blue";}
    if (pBGColor != '') {fDiv.style.backgroundColor = pBGColor;} else {fDiv.style.backgroundColor = "white";}
    fDiv.style.backgroundImage = "none";
}

//**************************************** Universal Functions ******************************
// Returns the horizontal position of a web control.
function findLeft(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1){
          curleft += obj.offsetLeft;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.x) curleft += obj.x;
    return curleft;
}
// Returns the vertical position of a web control.
function findTop(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1){
          curtop += obj.offsetTop;
          if(!obj.offsetParent) break;
          obj = obj.offsetParent;
        }
    else if(obj.y) curtop += obj.y;
    return curtop;
}
function findHeight(obj){
    return obj.offsetHeight;
}