//for first level items eg. 1
var iconParent_open = "images/blueminus.gif"; //pathname of icon when link is expanded OPEN
var iconParent_closed = "images/blueplus.gif"; //pathname of icon when link is collapsed CLOSED

//for intermediate level items eg. 1.1, 1.1.1
var iconSubparent_open = "images/greyminus.gif"; //pathname of icon when link is expanded OPEN
var iconSubparent_closed = "images/greyplus.gif"; //pathname of icon when link is collapsed CLOSED

//for bottom level items eg. 1.1.1.1
var iconChild_open = "images/blueminus.gif"; //pathname of icon when link is expanded OPEN
var iconChild_closed = "images/blueplus.gif"; //pathname of icon when link is collapsed CLOSED
var icon_closed, icon_open;

function setLhsMenu(pgNum, leftLink, topLink) { //process (multi-level) submenus and open them individually
	if (pgNum!='') { //if not the section's homepage, cos pgNum will be set to ''
		pgNum=stripLyr(pgNum); //strips prefix 'lyr'
		var pgNumAry=pgNum.split('.');
		var div='';
		for (var i=0; i<pgNumAry.length; i++) {
			div+=pgNumAry[i];
			if (topLink!='site') toggleMenu(div); //don't collapse for sitemap
			div+='.';
		}
	}
	
	if (leftLink!='') highlightCurrentLeftnav(leftLink);
	//if (topLink!='') highlightCurrentTopnav(topLink);
}
function highlightCurrentTopnav(topLink) {
	document.getElementById(topLink).style.color="#ffffff"; //set the current topnav section to white
}
//function highlightCurrentLeftnav(leftLink) {
//	document.getElementById(leftLink).style.color="#072269"; //set the current leftnav section to navy
//	document.getElementById(leftLink).style.color="red"; //set the current leftnav section to navy
//	document.getElementById(leftLink).style.font="bold"; //set the current leftnav section to navy
//}
function highlightCurrentLeftnav(leftLink) {
var LeftOBJ = document.getElementById(leftLink);
	LeftOBJ.style.color="#F82828";
	LeftOBJ.style.fontWeight="normal";
}
function toggleMenu(selcChildDiv) {
	var obj, visible, key, parentTable;
	obj=document.getElementById("lyr" + selcChildDiv);
	visible=(obj.style.display!="none");
	key=document.getElementById("parentIcon" + selcChildDiv); //parent (img tag) of 'selcChildDiv'
	getIcons(selcChildDiv);
	collapseLevel(selcChildDiv); //collapse all parents and subheaders in the same level
	parentTable=document.getElementById("parentTable" + selcChildDiv);

	if (visible) {
		obj.style.display="none";
		key.src=icon_closed;
		if (parentTable) parentTable.className="lhsParentTableNormal";
    } 
	else {
		obj.style.display="block";
		key.src=icon_open;
		if (parentTable) parentTable.className="lhsParentTableSelc"; //changes bgrd col of parent link to dark orange when selected
    }
}

//collapses all parents and subheaders in the same level ONLY eg for 1.1, 1.2, 1.3, 1.4
function collapseLevel(selcChildDiv) {
	var key, divs, parentTable, levelDot=getLevel(selcChildDiv);
	divs=document.getElementsByTagName("div"); //this selects all the child div tags, with ids eg 1, 1.1, 1.2, 2, 3...
	for (i=0;i<divs.length;i++) {
		if (divs[i].id.substr(0,3)=='lyr') {
			numericId=stripLyr(divs[i].id); //remove the 'lyr' prefix
			if ((getLevel(numericId)).toString()==levelDot.toString()) {
				divs[i].style.display="none";
				key=document.getElementById("parentIcon" + numericId);
				key.src=icon_closed;
			}
	
			parentTable=document.getElementById("parentTable" + numericId);
			if (selcChildDiv.indexOf('.')!=-1 && getTopLevel(selcChildDiv)==numericId && parent)  //dot found, clicked on a subparent/child && top parent of selc item is the current item
				parentTable.className="lhsParentTableSelc";
			else if (parentTable) parentTable.className="lhsParentTableNormal";
	
			if (selcChildDiv.indexOf('.')!=-1) { //dot found
				var dotPos=selcChildDiv.indexOf('.');
				var level=selcChildDiv.substring(0, dotPos);
			}
		}
   }
}
function getNumInstances(selcChildDiv) {
	var num=selcChildDiv.split('.');
  	return num.length-1;
}
function getIcons(selcChildDiv) {
	var level;
	if (getNumInstances(selcChildDiv)==0) level='iconParent'; //parent link found, eg 1 (no . found)
	else if (getNumInstances(selcChildDiv)==1) level='iconSubparent'; //intermediate link found, eg 1.1
	else if (getNumInstances(selcChildDiv)==2) level='iconSubparent'; //intermediate link found, eg 1.1.1
	else if (getNumInstances(selcChildDiv)==3) level='iconChild'; //bottom link found, eg 1.1.1.1
	
	icon_closed = eval(level+'_closed'); //eg. iconSubparent_closed
	icon_open = eval(level+'_open'); //eg. iconSubparent_open

//alert('icon_closed is ' + icon_closed);
//alert('icon_open is ' + icon_open);
}
function getLevel(selcChildDiv) {
	var dotPos=selcChildDiv.lastIndexOf('.');
	var level=selcChildDiv.substring(0, dotPos+1);
	if (level=='') level=1; //top level, eg 1	
	return level; //eg returns '1.1.'
}
function getTopLevel(selcChildDiv) {
	var dotPos=selcChildDiv.indexOf('.');
	var level=selcChildDiv.substring(0, dotPos);
	if (level=='') level=1; //top level, eg 1	
	return level; //eg returns '1'
}

function expandAll() {
	divs=document.getElementsByTagName("div");
	for (i=0;i<divs.length;i++) {
		divs[i].style.display="block";
		key=document.getElementById("parentIcon" + divs[i].id);
		key.src=iconParent_open;
   }
}
function stripLyr(str) {
	return str.substring(3,str.length); //strips prefix 'lyr'
}
function collapseAll() { //not in use
	divs=document.getElementsByTagName("div"); //this selects all the child div tags, with ids eg 1, 1.1, 1.2, 2, 3...
	for (i=0;i<divs.length;i++) {
		divs[i].style.display="none";
		key=document.getElementById("parentIcon" + divs[i].id);
		key.src=icon_closed;
	}
}
function openMenu(level) { //not in use
	collapseAll();
}
