//***************************************************************************
// *                                                                        *
// *      JAVASCRIPT  HIGHLIGHTER FOR NAVIGATION                            *
// *                                                                        * 
//***************************************************************************
//
// Change history
// JZ [1]
//		- class changed from "selected" to "highlight selected"
//		- navigation id changed from "navigation" to "nav"
//
//***************************************************************************
 
function extractPageName(hrefString)
{
 var myString = _removehttp(hrefString); 
 return myString.toLowerCase();
}


function _removehttp (str) 
{
	re1 = /http:\/\/.*?\//g;
	re2 = /.*(STAGING|(WORKAREA|EDITION)\/[^\/]+)\//;
	var a1= str.replace(re1, "");
	return a1.replace(re2,"");
}

function _displayEntity(str) {
	var xlate = str.replace(/&amp;/,'&');
	return xlate;
}

function setActiveMenu(arr, crtPage) {
	/*
		There are 2 different methods:
		- css : highlighting using CSS
			This is for StudyLink, SuperGold etc.
		- non-css : this is for Doogle, Heartlands etc	
	*/
	
	for(var i=0; i < arr.length; i++) {
		var menuItem = extractPageName(arr[i].href); 
		if(menuItem == crtPage) { 		
		    var myEm = document.createElement('em');
		    var text = document.createTextNode(arr[i].firstChild.data);
		    //var text = document.createTextNode(_displayEntity(arr[i].firstChild.innerHTML));
		    myEm.appendChild(text);
		    arr[i].replaceChild(myEm, arr[i].firstChild);
			arr[i].className = "highlight selected";
		}
	}
}

function setPage()
{
	if(document.location.href) 
		hrefString = document.location.href;
	else
		hrefString = document.location;

	if (document.getElementById("nav")!=null) 
		setActiveMenu(document.getElementById("nav").getElementsByTagName("a"), extractPageName(hrefString));

}


