/* JS functions by Olga Turkevich*/

/* to handle query result pages with ? after the url */
function extractPageName(hrefString){
	var arr = hrefString.split('.');	
	var hasquestion=hrefString.indexOf('?'); // Check to see if the url has a query string by searching for the question mark
	if (hasquestion == '-1')
	{
		arr = arr[arr.length-2].split('/');
		//alert(arr);
		if (arr[1] != null){
			return arr[1].toLowerCase();					//returns the file folder in the position of 2
		}
		else{
			return "default";
		}	
	}
	else{
		var hrefString = arr[arr.length-2].split('?');	
		arr = arr[arr.length-2].split('/');
		return arr[1].toLowerCase();					//returns the file folder in the position of 2
	}
}

function setActiveMenu(arr, crtPage)
{
	for (var i=0; i<arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			
			if (arr[i].parentNode.tagName != "DIV")
			{
				arr[i].className = "current";
				
				var CurID = arr[i].id;
				var CurID_Element = document.getElementById(CurID);
				var CurSubMenu = CurID_Element.parentNode;
				
				if (CurSubMenu.childNodes[2] != null ){
					
					CurSubMenu = CurSubMenu.childNodes[2];
					CurSubMenu.className = "currentSubMenu";
					
					var liArray = new Array(); 
					liArray = CurSubMenu.getElementsByTagName("a");
					
					for (var j=0; j<liArray.length; j++){
						/*alert("arr:" + arr[i] + " liArray:" + liArray[j].href + " href:" + hrefString );*/
						if 	(hrefString == liArray[j].href ){
							liArray[j].className="currentSubItem";
						}
					}
				}

				return;	// We changed the nav graphic. Need to make sure it doesn't go into subitems in the menu.
			}
		}
	}
}

function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;
	//alert("hrefString: " + hrefString);	//get current URL

	if (document.getElementById("nav")!=null){
		setActiveMenu(document.getElementById("nav").getElementsByTagName("a"), extractPageName(hrefString));
	}
}