var strSelectedMapRowName = "";
var boolDisclaimerVisible = false;

// Show the hierarchy.
function getHierarchy(pNumMapID, pObjDiv)
{
    if ((pObjDiv == null) || (pObjDiv == undefined))
        return;

    var strUrl = "./jsp/showSliderMapHierarchy.jsp";
    var strUrlParams = "mapID=" + pNumMapID + "&lang=" + strLang;

    // Create a new XML HTTP object for AJAX operation.
    var oTempXmlHttp = getNewXmlHTTPObject();

    // Process the AJAX request.
    if (!isXmlHTTPNull(oTempXmlHttp))
    {
        logMsg("Retrieving view hierarchy. url: " + encodeURIComponent(strUrl + "?" + strUrlParams), "info", "sliderMapHierarchy.js (getHierarchy)");
        doXMLRequest(oTempXmlHttp, strUrl, strUrlParams, "post", false, "application/x-www-form-urlencoded");
    }

    // Show the hierarchy in the div.
    pObjDiv.innerHTML = oTempXmlHttp.responseText;

    oTempXmlHttp = null;
}

function showHideRow(pStrRowName, pStrImgName)
{
    if ((boolLoadMapAuthor != undefined) && (boolLoadMapAuthor != null) && (boolLoadMapAuthor != false))
        return;

    var objImgOpenClose = document.getElementById(pStrImgName);

    showHideSliderElement(pStrRowName, objImgOpenClose, false)
}

function doHierarchyClick(pNumMapID, pStrRowName)
{
    strSelectedMapRowName = pStrRowName;

    if (boolDisclaimerVisible)
        return;

    changeMap(pNumMapID);

    if (document.getElementById("divDisclaimerPopUp"))
        boolDisclaimerVisible = true;
    else
    {
        // Refresh download slider to reflect the newly selected map.
        if ((document.getElementById("divDownload") != null) && (document.getElementById("divDownload") != undefined))
            showDownloadableLayers(document.getElementById("divDownload"),numMapID, objMap.getScale());
    }
}

function doHighlight(pObj, pStrType, pStrAction, pParentID, pMapID)
{
    if (pStrAction.toUpperCase() == "MOUSEOVER")
    {
        colorFade(pObj.id, "background", "ffffff", "aeaeae", 10, 0);

        // Firefox recognizes whitespaces in the HTML. We need to clean it up before further processing.
        removeWhiteSpace(pObj);

        // Change the font color of the hyperlink to simulate a "mouseover" effect.
        pObj.childNodes[0].childNodes[0].style.color = "white";
    }
    else if (pStrAction.toUpperCase() == "MOUSEOUT")
    {
        colorFade(pObj.id, "background", "aeaeae", "ffffff", 10, 0);

        // Firefox recognizes whitespaces in the HTML. We need to clean it up before further processing.
        removeWhiteSpace(pObj);

        // Change the font color of the hyperlink to simulate a "mouseout" effect.
        pObj.childNodes[0].childNodes[0].style.color = "";
    }
    else if (pStrAction.toUpperCase() == "CLICK")
    {
        // Clear the class names of the temporarily selected items.
        // To do this, get all the rows with a class name of "tempSelected". Then set
        // the class name to "".
        var arryObjTemp = getElementsByClassName("tempSelected");

        for (objTemp in arryObjTemp)
            arryObjTemp[objTemp].className = "hiearchyRow";

        if (pStrType.toUpperCase() == "VIEW")
        {
            // See if the disclaimer has already been displayed.
            if (!boolDisclaimerVisible)
            {
                // Need to verify of the map has a disclaimer.
                getMap(pMapID);

                // If the disclaimer is visible, exit the procedure. Otherwise, continue.
                if (boolDisclaimerVisible)
                    return;
            }
            else
                return;

            // Reset the class names of the previous selected map.
            // To do this, get all the rows with a class name of "selected". Then set
            // the class name to "hiearchyRow".
            var arryObjTemp = getElementsByClassName("selected");
            for (objTemp in arryObjTemp)
                arryObjTemp[objTemp].className = "hiearchyRow";

            // Highlight the selected row (if not already selected).
            pObj.className = "selected";

            // Highlight the parent row.
            document.getElementById(pParentID).onclick();

            // Assign a permanant class name for the "newly" selected map.
            // To do this, get all the rows with a class name of "tempSelected". Then set
            // the class name to "selected".
            arryObjTemp = getElementsByClassName("tempSelected");
            for (objTemp in arryObjTemp)
                arryObjTemp[objTemp].className = "selected";
        }
        else if (pStrType.toUpperCase() == "TOPIC")
        {
            // Highlight the selected row (if not already selected).
            if (pObj.className != "selected")
                pObj.className = "tempSelected";

            // Highlight the parent row.
            document.getElementById(pParentID).onclick();
        }
        else if (pStrType.toUpperCase() == "SUBJECT")
        {
            // Highlight the selected row (if not already selected).
            if (pObj.className != "selected")
                pObj.className = "tempSelected";
        }

        // Assign a temporary class to the selected row (if not already selected).
        if (pObj.className != "selected")
            pObj.className = "tempSelected";
    }
}
