var namedDiv = '';

function trim(a){
	var tmp=new Array();
	for(j=0;j<a.length;j++)
		if(a[j]!='')
			tmp[tmp.length]=a[j];
	a.length=tmp.length;
	for(j=0;j<tmp.length;j++)
		a[j]=tmp[j];
	return a;
}

function StyleSheetChanger(cssClassName,toChange,changeTo) {
	for(i = 0; document.styleSheets.length > i; i++) //IE
	{
		var aName = cssClassName.split(',');
		if(document.styleSheets[i].rules != undefined)
		{
			for(j = 0; document.styleSheets[i].rules.length > j; j++)
			{
				for (k =0; aName.length > k; k++) {
					var checkOp = aName[k].replace(/(^ +| +$)/, "");
					if(document.styleSheets[i].rules[j].selectorText.toLowerCase() == checkOp)
					{
						document.styleSheets[i].rules[j].style[toChange] = changeTo;
					}
				}
			}
		} else if(document.styleSheets[i].cssRules != undefined) //Mozilla
		{

			for(j = 0; document.styleSheets[i].cssRules.length > j; j++)
			{
				if(document.styleSheets[i].cssRules[j].selectorText.toLowerCase() == cssClassName)
				{
					document.styleSheets[i].cssRules[j].style[toChange] = changeTo;
				}
			}
		}
	}
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function showMenu(menu,op,pKleur) {
	if (menu!=namedDiv) {
		hideSubMenu();
	}
	clearHideMenu();
	namedDiv = menu;
	StyleSheetChanger('#'+op,'backgroundColor',pKleur);
	oMenu = document.getElementById(menu);
	oSelf = document.getElementById(op);
	xProp = findPosY(oSelf);
	oMenu.style.top = xProp+'px';
	oMenu.style.left = '175px';
	StyleSheetChanger('.submenu a, .submenu a:link, .submenu a:visited, .submenu a:active','color',pKleur);
	StyleSheetChanger('.submenu a:hover','backgroundColor',pKleur);
	oMenu.style.display = 'inline';
	var allselects = document.getElementsByTagName('select');
	for(i = 0; i < allselects.length; i++) {
		allselects[i].style.visibility ="hidden";
	}
}

function hideDelayedMenu() {
	delayhide=setTimeout("hideSubMenu()",300);
}

function clearHideMenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}

function hideSubMenu() {
	oCon = document.getElementById('submenus');
	var inputs = oCon.getElementsByTagName("div");
	for (var i=0; i<inputs.length; i++) {
		inputs[i].style.display = 'none';
	}
	var allselects = document.getElementsByTagName('select');
	for(i = 0; i < allselects.length; i++) {
		allselects[i].style.visibility="visible";
	}
}
