/* 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";
				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));
	}
}
