var currentHelpPage = "help" ;
var currentHelpThread = "none" ;
var shortcutsMode = "" ;
var popupWin = "" ;
var bookHelpUrl = "" ;

//----------------------------------------------
// Name        : toggleTree(iconObj, rowId)
// Description : Toggles between the states of the help tree - opens a closed thread, closes an openned thread.
// Parameters  : iconObj - The arrow icon besides the current thread.
//	             rowId - The row id of the thread to be toggled.
//----------------------------------------------

function toggleTree(iconObj, rowId)
{   //alert(iconObj + ", " + rowId);
    toggleIcon(iconObj);
    toggleText(document.all(rowId));
}

//----------------------------------------------
// Name        : toggleIcon(iconObj)
// Description : Toggles between the states of the arrow icon in the help tree - opens a closed icon, closes an openned icon.
// Parameters  : iconObj - The arrow icon to be toggled.
//----------------------------------------------
function toggleIcon(iconObj)
{
    var newImagePath = "" ;
    if (iconObj != null)    {
    var fullImgPath = iconObj.src ;
    var pathName = fullImgPath.substring(0, fullImgPath.lastIndexOf("/")+1);
    var imgName = fullImgPath.substring(fullImgPath.lastIndexOf("/")+1, fullImgPath.lastIndexOf(".gif"));
    if (imgName.indexOf("_right") > 0)
       newImagePath =  pathName + "icn_arrow_down.gif" ;
    else if (imgName.indexOf("_down") > 0)
       newImagePath =  pathName + "icn_arrow_right.gif" ;
    else
       newImagePath =  pathName + "no_such_image.gif" ;
    iconObj.src = newImagePath ;
    }
}

//----------------------------------------------
// Name        : toggleText(rowObj)
// Description : Toggles between the states of the text in the help tree - opens a closed text, closes an openned text.
// Parameters  : rowObj - The row object of the text to be toggled.
//----------------------------------------------
function toggleText(rowObj)
{
    if (rowObj.style.display == "none")
        rowObj.style.display = "inline";
    else if (rowObj.style.display == "inline")
        rowObj.style.display = "none";
    else
        rowObj.style.display = "undefined";
}

//----------------------------------------------
// Name        : goToHelp(helpPage, helpThread)
// Description : Decides whether to redirect the help pane to the specified help page and help thread.
// Parameters  : helpPage - The name of the help page to be redirected to.
//             : helpThread - The id of the help thread to be expanded within the help page.
//----------------------------------------------
function goToHelp(helpPage, helpThread)
{    
     //if the current help page is not the relevant to view
     if (getCurrentHelpPage() != helpPage)
     {
        goToHelpPage(helpPage, helpThread);
     }
     //if the current help page is the currect one but not the currect thread is opened
     else if (getCurrentHelpThread() != helpThread)
     {
        setCurrentHelpThread(helpThread);
        goToHelpThread(helpThread);
     }
     //else
        //do nothing
}

//----------------------------------------------
// Name        : goToHelpThread(helpThread)
// Description : Expands the required thread within the help page.
// Parameters  : helpThread - The id of the help thread to be expanded within the help page.
//----------------------------------------------
function goToHelpThread(helpThread)
{
    if ((helpThread != "none") && (top.shortcuts.document.content.document.all(helpThread) != null))
    {
        toggleExpandIcon(top.shortcuts.document.content.document.all(helpThread).previousSibling.all.item('arrow_icon'));
        toggleExpandText(top.shortcuts.document.content.document.all(helpThread));
    }
}

//----------------------------------------------
// Name        : goToHelpPage(helpPage, helpThread)
// Description : Redirects the help pane to the specified help page and sets the current help page and help thread.
// Parameters  : helpPage - The name of the help page to be redirected to.
//             : helpThread - The id of the help thread to be expanded within the help page.
//----------------------------------------------
function goToHelpPage(helpPage, helpThread)
{
    setCurrentHelpPage(helpPage) ;
    setCurrentHelpThread(helpThread) ;
    if (getShortcutsMode() == "help")
    {
        top.shortcuts.document.content.location = "help/" + helpPage + ".jsp" ;
    }
}

//----------------------------------------------
// Name        : goToCurrentHelpThread()
// Description : Redirects the help pane to the current help page.
// Parameters  : none.
//----------------------------------------------
function goToCurrentHelpThread()
{
    if (getCurrentHelpThread() != "none")
    {
        toggleTree(document.all(getCurrentHelpThread()).previousSibling.all.item('arrow_icon'), getCurrentHelpThread());
    }
}

//----------------------------------------------
// Name        : toggleAllHelp(operation)
// Description : Toggles all help threads within the current help page according to the operation - expands or collapses all threads.
// Parameters  : operation - Can be either "Expand" or "Collapse".
//----------------------------------------------
function toggleAllHelp(operation)
{
    var trTags = top.shortcuts.document.content.document.all.tags("tr") ;
    if ((trTags.length) && (trTags.length >0))
    {
        for(i=0; i<trTags.length; i++)
        {
            if (trTags[i].id.indexOf("helpThread_") > -1)
            {
                var helpThread = trTags[i].id ;
                if (operation == "Expand")
                {
                    toggleExpandIcon(top.shortcuts.document.content.document.all(helpThread).previousSibling.all.item('arrow_icon'));
                    toggleExpandText(top.shortcuts.document.content.document.all(helpThread));
                }
                else if (operation == "Collapse")
                {
                    toggleCollapseIcon(top.shortcuts.document.content.document.all(helpThread).previousSibling.all.item('arrow_icon'));
                    toggleCollapseText(top.shortcuts.document.content.document.all(helpThread));
                }
            }

        }
    }
}

//----------------------------------------------
// Name        : toggleExpandIcon(iconObj)
// Description : Expands the arrow icon in the help tree, regardless of its previous state.
// Parameters  : iconObj - The arrow icon to be expanded.
//----------------------------------------------
function toggleExpandIcon(iconObj)
{
    var newImagePath = "" ;
    if (iconObj != null)
    {
        var fullImgPath = iconObj.src ;
        var pathName = fullImgPath.substring(0, fullImgPath.lastIndexOf("/")+1);
        var imgName = fullImgPath.substring(fullImgPath.lastIndexOf("/")+1, fullImgPath.lastIndexOf(".gif"));
        if (imgName.indexOf("_right") > 0)
        {
            newImagePath =  pathName + "icn_arrow_down.gif" ;
            iconObj.src = newImagePath ;
        }
    }
}

//----------------------------------------------
// Name        : toggleCollapseIcon(iconObj)
// Description : Collapses the arrow icon in the help tree, regardless of its previous state.
// Parameters  : iconObj - The arrow icon to be collapsed.
//----------------------------------------------
function toggleCollapseIcon(iconObj)
{
    var newImagePath = "" ;
    if (iconObj != null)
    {
        var fullImgPath = iconObj.src ;
        var pathName = fullImgPath.substring(0, fullImgPath.lastIndexOf("/")+1);
        var imgName = fullImgPath.substring(fullImgPath.lastIndexOf("/")+1, fullImgPath.lastIndexOf(".gif"));
        if (imgName.indexOf("_down") > 0)
        {
            newImagePath =  pathName + "icn_arrow_right.gif" ;
            iconObj.src = newImagePath ;
        }
    }
}

//----------------------------------------------
// Name        : toggleExpandText(rowObj)
// Description : Expands the text in the help tree, regardless of its previous state.
// Parameters  : rowObj - The row object of the text to be expanded.
//----------------------------------------------
function toggleExpandText(rowObj)
{
    if (rowObj.style.display == "none")
        rowObj.style.display = "inline";
}

//----------------------------------------------
// Name        : toggleCollapseText(rowObj)
// Description : Collapses the text in the help tree, regardless of its previous state.
// Parameters  : rowObj - The row object of the text to be collapsed.
//----------------------------------------------
function toggleCollapseText(rowObj)
{
    if (rowObj.style.display == "inline")
        rowObj.style.display = "none";
}

//----------------------------------------------
// Name        : goToCurrentHelp(helpTabObj)
// Description : Redirects the help pane to the current help page.
// Parameters  : helpTabObj - The tab object of the help pane.
//----------------------------------------------
function goToCurrentHelp(helpTabObj)
{
    helpTabObj.location.href = "help/" + getCurrentHelpPage() + ".jsp" ;
}

//----------------------------------------------
// Name        : getCurrentHelpPage()
// Description : Returns the current help page.
// Returns     : The current help page.
//----------------------------------------------
function getCurrentHelpPage()
{
    return top.currentHelpPage ;
}

//----------------------------------------------
// Name        : setCurrentHelpPage(helpPage)
// Description : Sets the current help page.
// Parameters  : helpPage - The help page to be set as current.
//----------------------------------------------
function setCurrentHelpPage(helpPage)
{
    top.currentHelpPage = helpPage ;
}

//----------------------------------------------
// Name        : getCurrentHelpThread()
// Description : Returns the current help thread.
// Returns     : The current help thread.
//----------------------------------------------
function getCurrentHelpThread()
{
    return top.currentHelpThread ;
}

//----------------------------------------------
// Name        : setCurrentHelpThread(helpThread)
// Description : Sets the current help thread.
// Parameters  : helpThread - The help thread to be set as current.
//----------------------------------------------
function setCurrentHelpThread(helpThread)
{
    top.currentHelpThread = helpThread ;
}

/*
-- Moved to utils.jsp to eliminate timing problem of loading help.js as part of the main-frameset.jsp
//----------------------------------------------
// Name        : getShortcutsMode()
// Description : Returns the current shortcut mode - bookmarks, TOC or help.
// Returns     : The current shortcut mode.
//----------------------------------------------
function getShortcutsMode()
{
    return top.shortcutsMode ;
}

//----------------------------------------------
// Name        : setShortcutsMode(mode)
// Description : Sets the current shortcut mode - bookmarks, TOC or help.
// Parameters  : mode - The shortcut mode to be set as current - bookmarks, TOC or help.
//----------------------------------------------
function setShortcutsMode(mode)
{
    top.shortcutsMode = mode ;
}

function setBookHelpUrl(helpUrl)
{
   top.bookHelpUrl = helpUrl ;
}

function getBookHelpUrl()
{
   return top.bookHelpUrl ;
}
*/
function openPopup(popupPage)
{
   popupWin = window.open(popupPage, "popup", "menubar=no,resizable=no,scrollbars=yes,toolbar=no,location=no,width=618,height=436,top=200,left=300") ;
   popupWin.focus();
}

