// JavaScript Document

function hasClass(el, name) {
   return new RegExp('(\\s|^)'+name+'(\\s|$)').test(el.className);
}

function addClass(el, name)
{
   if (!hasClass(el, name)) { el.className += (el.className ? ' ' : '') +name; }
}

function extractPageName(hrefString)
{
	var arr = hrefString.split('/');
	return  (arr.length < 2) ? hrefString : arr[arr.length-1].toLowerCase();
}
 
function setTopMenu(arr, crtPage)
{
	for (var i=0; i < arr.length; i++)
	{
		if (crtPage == "")
		{
			if (extractPageName(arr[i].href) == "index.html")
			{
				addClass(arr[i],"currpage");
			}
		}
		if (crtPage == "contact-retry.html")
		{
			if (extractPageName(arr[i].href) == "contact.html")
			{
				addClass(arr[i],"currpage");
			}
		}
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				
				addClass(arr[i],"currpage");
			}
		}
	}
}

function setSubMenu(arr, crtPage)
{
	for (var i=0; i < arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "DIV")
			{
				addClass(arr[i],"currsubpage");
			}
		}
	}
}

function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;
 
	if (document.getElementById("menu") !=null )
	setTopMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));
	if (document.getElementById("submenu") !=null )
	{
		setTopMenu(document.getElementById("menu").getElementsByTagName("a"), "products.html");
		setSubMenu(document.getElementById("submenu").getElementsByTagName("a"), extractPageName(hrefString));
	}
}
