/***************************
Author: Sherwin Sena Aborot
Date: 7/22/2008
Purpose:
	Display the subnavigation on L2 pages using javascript.  This can be done using Java but then
we will have to add a "mid" parameter on URL to get the ID of the current page. The subnavigation will
be inserted dynamically and so as the repositioning of the contents on the page for accessibility reasons.
***************************/

function insertSubNavigation() {
	try {
	// GET TARGET LIs TO DISPLAY
		var nav = document.getElementById('nav');
		var pageId = document.getElementsByTagName("BODY")[0].id;
		var tempObj = getElementsByClassName(nav,"li",pageId+'MenuItem');
		var menuItem = tempObj[tempObj.length-1];
		var parentMenuItem = menuItem.parentNode;
		//if ( parentMenuItem.id == 'nav' ) { return; }
	
	// CONSTRUCT 2nd NAVIGATION TO DISPLAY
		var navDiv = document.createElement('DIV');
		navDiv.id = "secondNavigation";
		var navUl = document.createElement('UL');
		navUl.innerHTML = parentMenuItem.innerHTML;
		navDiv.appendChild(navUl);
	
	// DISPLAY 2nd Navigation
		var targetDiv = document.getElementById('objBody').getElementsByTagName('DIV')[1];
		var contentDiv = document.getElementById('contentArea');
		contentDiv.id = "smallContentArea";
		targetDiv.className = "smallTextContent";
		targetDiv.appendChild(navDiv);
	} catch ( Exception ) {}
}

function highLightActiveNavItems() {
	try {
	// HIGHLIGHT CURRENT PAGE VIEWED IN ALL MENU
		var nav = document.getElementById('nav');
		var secondNav = document.getElementById('secondNavigation');
		var pageId = document.getElementsByTagName("BODY")[0].className;
		
		activeMainMenuItem = getElementsByClassName(nav,"li",pageId+'MenuItem');
			for ( i=0;i<activeMainMenuItem.length;i++ ) {
				tempString = activeMainMenuItem[i].getElementsByTagName('DIV')[0].className;
				if ( tempString.indexOf('topMItem') < 0 ) { 
					activeMainMenuItem[i].className += " activeMainNavItem"; 
				} else { 
					if ( activeMainMenuItem[i].id == getQueryParam('mid') ) { activeMainMenuItem[i].className += " activeTopNavItem"; }
				}
			}
		
		activeSecondMenuItem = getElementsByClassName(secondNav,"li",pageId+'MenuItem')[0].className += " activeSecondNavItem";
		
	} catch ( Exception ) {}		
	
	// HIGHLIGHT TOP MENU ITEM EVEN IF A SUBPAGE IS VIEWED
	try {
		activeParentMenuItem = document.getElementById(getQueryParam('mid'));
		if ( activeParentMenuItem.getElementsByTagName('div')[0].className.indexOf("topMItem") < 0 ) {
			activeParentMenuItem.parentNode.parentNode.className += " activeTopNavItem";
		}
	} catch( Exception ) {}
}

/*
	Written by Jonathan Snook, http://www.snook.ca/jonathan
	Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

/*
	Written by pradeep http://www.go4expert.com/forums/showthread.php?t=2163
*/
function getQueryParam(paramName) {
	// get the current URL
	 var url = window.location.toString();
	 //get the parameters
	 url.match(/\?(.+)$/);
	 var params = RegExp.$1;
	 // split up the query string and store in an
	 // associative array
	 var params = params.split("&");
	 var queryStringList = {};
	 
	 for(var i=0;i<params.length;i++)
	 {
	     var tmp = params[i].split("=");
	     queryStringList[tmp[0]] = unescape(tmp[1]);
		 if ( tmp[0] == paramName ) {
			return tmp[1];
		 }
	 }
}