// Search functions
function getNavHistory()
{
	var navHistory = new Array();
	if (document.all)
	{
		//fromCharCode(124);
		var nbs=String.fromCharCode(124);
		nbs=/\|/g;
		//alert(nbs);
		var tp = document.getElementById("navigation").innerText.replace(nbs,'');
		navHistory = tp.split(">");
		//alert(tp.charCodeAt(tp.length-1));
		//alert(tp);
//alert(document.getElementById("navigation").innerText.charCodeAt(tp.length));

	}
	else
	{
		var i = new Number();
		var j = new Number();
		j = 0;
		var nbs=/\|/g;
		for (i = 0; i < document.getElementById("navigation").childNodes.length; i++)
		{
			if (document.getElementById("navigation").childNodes[i].tagName == "A")
			{
				navHistory[j] = document.getElementById("navigation").childNodes[i].text;
				navHistory[j] = navHistory[j].replace(nbs,'');
				j++;
			}
		}

	}
	return navHistory;
}

// String functions
function trim(str)
{
	if (str.indexOf("...") >= 0)
	{
		str = str.substring(0, str.indexOf("...") - 1);
	}
	while (str.indexOf("\n") >= 0)
	{
		str = str.replace("\n", "");
	}
	while (str.indexOf("\r") >= 0)
	{
		str = str.replace("\r", "");
	}
	while (str.indexOf("\t") >= 0)
	{
		str = str.replace("\t", "");
	}
	while (str.indexOf(" ") >= 0)
	{
		str = str.replace(" ", "");
	}
	return str;
}

// Indentify menu to hightlight and do it ;)
function makeHightLight(el, pattern)
{
	var i = new Number();

	if (document.all)
	{
		for (i = 0; i < el.children.length; i++)
		{
			if (trim(el.children[i].innerText).indexOf(pattern) >= 0)
			{
				if (el.children[i].children.length == 0)
				{
					el.children[i].style.fontWeight = "bolder";
					el.children[i].backgroundColor='yellow';
					el.children[i].innerHTML = "> " + el.children[i].innerHTML + "";
					return true;
				}
				else
				{
					return makeHightLight(el.children[i], pattern);
				}
			}
		}
		return false;
	}
	else
	{
		for (i = 0; i < el.childNodes.length; i++)
		{
			if (el.childNodes[i].tagName)
			{
				if (el.childNodes[i].tagName == "A")
				{
					if (trim(el.childNodes[i].text).indexOf(pattern) >= 0)
					{
						x = el.childNodes[i];
						y = el.childNodes[i].text;
						x.innerHTML = '';
						x.innerHTML = "<strong>> " + y + "</strong>";

						return true;
					}
				}
				else
				{
					if (el.childNodes[i].hasChildNodes())
					{
						if (makeHightLight(el.childNodes[i], pattern))
						{
							return true;
						}
					}
				}
			}
		}
		return false;
	}
}

// Main function
function hightLight()
{
	var navHistory = new Array();
	var i = new Number();
	navHistory = getNavHistory();
	for (i = 0; i < navHistory.length - 1; i++)
	{
		if (document.getElementById("listFolder"))
		{
			if (makeHightLight(document.getElementById("listFolder"), trim(navHistory[i])))
			{
				if (document.getElementById("listFolder2"))
				{
					makeHightLight(document.getElementById("listFolder2"), trim(navHistory[i + 1]));
				}
				break;
			}
		}
	}
}
