var strClassName = "highlighted";
var blnFound = false;
var strCurrentURL = "";
var strCurrentFile = "";
var strClosestURL = "";

function highlightItem(strElement) {

	blnFound = false;
	strCurrentURL = document.location.pathname.toLowerCase();
	strCurrentFile = "";
	strClosestURL = "";

	var objElement = document.getElementById(strElement);

	var blnExists = false;
	
	if (objElement.innerHTML.toLowerCase().indexOf(strCurrentURL) > -1) blnExists = true;

	if (blnExists == false) {

		var strFile = strCurrentURL;

		while (strFile.indexOf("/") > -1) {
			strFile = Right(strFile, strFile.length - strFile.indexOf("/") - 1);
		}
		
		strCurrentFile = strFile;
		strCurrentURL = strCurrentURL.replace(strFile, "");
	}

	if (objElement.childNodes != null) {
		findElement(objElement, blnExists);
	}
	
	if (blnFound == false) {
		strCurrentURL = strClosestURL;
		findElement(objElement, blnExists);
	}
}

function findElement(objParent, blnExists) {

	if (objParent.tagName == "A") {

		if (objParent.href != "") {

			var strLink = "/" + objParent.pathname.toLowerCase();

			if (strLink != "/") {
				
				if (blnExists == false) {

					var strFile = strLink;
					while (strFile.indexOf("/") > -1) {
						strFile = Right(strFile, strFile.length - strFile.indexOf("/") - 1);
					}
					strLink = strLink.replace(strFile, "");
				}

				if (strCurrentURL.indexOf("/tools/") > -1 && objParent.href.indexOf("?") > -1) {

					var strSection = objParent.href.substring(objParent.href.indexOf("?SECT="));
					var strPath = objParent.href.substring(0, objParent.href.lastIndexOf("/") + 1);

					if (strPath == window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1))
					{
						if (window.location.href.indexOf(strPath) > -1 && window.location.href.indexOf(strSection) > -1 && blnFound == false) {
							objParent.className = strClassName;

							blnFound = true;
						}
					}
				} else {

					if (strCurrentURL == "") {
						strCurrentURL = document.location.pathname.toLowerCase();
					}

					if (strLink.indexOf(strCurrentURL) != -1 && blnFound == false) {
					
						objParent.className = strClassName;
						
						backTrack(objParent.parentNode);
						
						blnFound = true;
						
					} else if (blnExists == false && blnFound == false) {

						strClosestURL = document.location.pathname.toLowerCase().substring(0, document.location.pathname.lastIndexOf("/"));
						
						strClosestURL = strClosestURL.substring(0, strClosestURL.lastIndexOf("/")) + "/";
					}
				}
			}
		}
	} else {

		var objChildren = objParent.childNodes;

		for (var i = 0; i < objChildren.length; i++) {
		
			if (objChildren[i].childNodes != null) {
				findElement(objChildren[i], blnExists);
			}
		}
	}
}

function backTrack(objParent) {
	
	while (objParent.parentNode != null) {

		if (objParent.tagName == "LI") {

			var objLink = objParent.getElementsByTagName("A");
			
			if (objLink != null) {
				if (strCurrentURL.indexOf(objLink[0].href.toLowerCase())) {
					objLink[0].className = strClassName;
				}
			}
		}
		objParent = objParent.parentNode;
	}
}

function Right(str, n) {

	if (n <= 0)

		return "";

	else if (n > String(str).length) return str;

	else {

		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);

	}
}
