//////////////////////////////////////////////////////////////////////
// selectnav.js - code file for selecting navigation items

var g_SelectedTreeAnchor, g_OldBackgroundColor;
var MenuCtrl, HelpTree, strUrl, strRelUrl, idx, strSection, len;

// if there is either a menu or tree control
MenuCtrl = document.getElementById("MenuCtrl");
HelpTree = document.getElementById("HelpTree");

if (MenuCtrl != null || HelpTree != null)
{
	strUrl = document.location.href;
	idx = strUrl.indexOf("?",0);
	if (idx != -1)
		strUrl = strUrl.substr(0,idx);
/*
	idx = strUrl.indexOf("#",0);
	if (idx != -1)
		strUrl = strUrl.substr(0,idx);
*/
	idx = strUrl.indexOf("//",0);
	idx += 2;
	idx = strUrl.indexOf("/",idx);
	strRelUrl = strUrl.substr(idx);	
}

// if there is a menu control highlight the proper section
if (MenuCtrl != null)
{
	len = strRelUrl.indexOf("/",1);
	strSection = strRelUrl.substr(1,len-1);
	HighlightMenuItem(strSection);
}

// if there is a tree control highlight the current document
if (HelpTree != null)
{
	var AnchorList, Anchor, NumAnchors, loop, strHref, strHostname, found;
	AnchorList = HelpTree.getElementsByTagName("a");
	NumAnchors = AnchorList.length;
	found = false;
	for (loop = 0; loop < NumAnchors; loop++)
	{
		Anchor = AnchorList.item(loop);
		strHref = Anchor.protocol + "//" + Anchor.hostname;
		if (Anchor.pathname[0] != '/')
			strHref += '/';
		strHref += Anchor.pathname + Anchor.hash;
		if (strHref == strUrl)
		{
			found = true;
			break;
		}
	}
	if (!found)
	{
		idx = strUrl.indexOf("#",0);
		if (idx != -1)
			strUrl = strUrl.substr(0,idx);
			
		for (loop = 0; loop < NumAnchors; loop++)
		{
			Anchor = AnchorList.item(loop);
			strHref = Anchor.protocol + "//" + Anchor.hostname;
			if (Anchor.pathname[0] != '/')
				strHref += '/';
			strHref += Anchor.pathname;
			if (strHref == strUrl)
			{
				found = true;
				break;
			}
		}
	}
	
	if (found)
	{
		HighlightTreeItem(Anchor);
	}
}

