/*
 * Script functions for the Documentation
 *
 * Company : Hyfinity Ltd.
 * Copyright (c) 2008
 *
 * @author Hyfinity Limited
 */

var previousElem = null;
var previousColor = "";
var previousBgColor = "";

function highlight_selected(evt, selectedElem)
{
    previousColor = selectedElem.style.color;
    previousBgColor = selectedElem.style.backgroundColor;
    selectedElem.style.color="white";
    selectedElem.style.backgroundColor="maroon";
    if (previousElem != null)
    {
        previousElem.style.color = previousColor;
        previousElem.style.backgroundColor = previousBgColor;
    }
    previousElem = selectedElem;
    //Update section title
    if (parent.frames['header'] != null && parent.frames['doc'] != null)
    {
        parent.frames['header'].document.getElementById("section-title").innerHTML = selectedElem.innerHTML;
    }
    //IE Version to prevent the tree element folding after navigation.
    if (evt != null)
    {
        if (evt.stopPropagation)
        {
            evt.stopPropagation();
        }
        else
        {
            evt.cancelBubble = true;
        }
    }

    //ensure the selected tree item is expanded
    expandTree(selectedElem.parentNode);
    //ensure the selected tree item is expanded
    expandTreeEntry(selectedElem.parentNode);

    //ensure the selected item is visble
    scrollViewToShow(parent.frames['contents'].document.body, selectedElem);
}

function sync_treeview(sectionId)
{
    var selectedElem = document.getElementById(sectionId);
    highlight_selected(null, selectedElem);
}

window.onload = function()
{
    setTimeout('showPage()', 500);
}

function showPage()
{
    var pageParam = gup("page");
    if (pageParam != '')
    {
        pageParam = unescape(pageParam);
        var treeEntry = document.getElementById(pageParam);

        if (treeEntry != null)
        {
            //treeEntry.click();
            parent.frames['doc'].location = treeEntry.href;
        }
    }
}

function gup(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( parent.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}
