//var Menu = new Array();
var SelectedMenuItem;
var childrenShown;
var bgColor_std = "#dde4ea";
var bgColor_tLvl = "#edf4fa";
var oldBg;

function initMenu(){
	for(i=0; i<Menu.length ; i++){
		tmpMenuItem = Menu[i];
		if (getMenuItemParentId(tmpMenuItem)=="0"){
			visibility(getMenuItemId(tmpMenuItem),"BLOCK");
			className(getMenuItemId(tmpMenuItem),"active");
			backgroundColor(getMenuItemId(tmpMenuItem),bgColor_std);
			SetMenuHeader(tmpMenuItem);
		}
	}
	childrenShown = false;
	SelectedMenuItem = Menu[0];
	fontWeight(getMenuItemId(SelectedMenuItem),"bold");
	className(getMenuItemId(SelectedMenuItem),"parent");
	SetMenuHeader(SelectedMenuItem);
	fNavigate(getMenuItemId(SelectedMenuItem));
	oldBg=null;
}

function doClick(aId){
	CloseAll();
	if (getMenuItemId(SelectedMenuItem)!=aId)
		childrenShown = false;
	SelectedMenuItem = getMenuItem(aId);
	if (!childrenShown){
		SetChildren();
		childrenShown = true;
	}
	else
		childrenShown = false;
	SetSisters(getMenuItemParentId(SelectedMenuItem));
	SetParents(getMenuItemParentId(SelectedMenuItem));
	fontWeight(aId,"bold");
	className(aId,"parent");
	SetMenuHeader(SelectedMenuItem);
	fNavigate(aId);
	oldBg=null;
}

function doSubClick(aId){
	navigate("show.aspx?id=" + aId + "&type=" + "MENUARTICLES");
}

function doOver(aId){
	oldBg=document.getElementById("TD_" + aId).style.backgroundColor
	document.getElementById("TD_" + aId).style.backgroundColor="white";
	document.getElementById("TDa_" + aId).style.backgroundColor="white";
}

function doOut(aId){
	if(oldBg){
		document.getElementById("TD_" + aId).style.backgroundColor=oldBg;
		document.getElementById("TDa_" + aId).style.backgroundColor=oldBg;
}	}

function doNavigate(sType,sId,bShowIn,sName){
	if (bShowIn){
		if (sType=="menu")
			doClick(sId);
		else{
			sNav = "show.aspx?id=" + sId + "&type=" + "ARTICLE";
			showArt_border(sNav,sName);
	}	}
	else {
		if (sType=="menu")
			doClick(sId);
		else{
			sNav = "show.aspx?id=" + sId + "&type=" + "ARTICLE";
			showArt_border(sNav,sName);
}	}	}
	
function fNavigate(){
	if (getMenuItemId(SelectedMenuItem)=='0000000020030311124802232'){
		showArt_border("onlinebestilling/mykennedy.aspx","");
	}
	else{
		if (getMenuItemArticleCount(SelectedMenuItem)>0){
			if(getMenuItemChildCount(SelectedMenuItem)>0){
				sNav = "show.aspx?id=" + getMenuItemId(SelectedMenuItem) + "&type=" + "MENUARTICLES";
				showArt_border(sNav, getMenuItemName(SelectedMenuItem));
			}
			else{
				sNav = "show.aspx?id=" + getMenuItemId(SelectedMenuItem) + "&type=" + "MENUARTICLES";
				showArt_border(sNav, getMenuItemName(SelectedMenuItem));
}	} 	}	}

function fOpenPage(aPage){
	showArt_border(aPage);
}

function setTitle(sTitle){
	document.getElementById("main_frame_borderHeader").innerText=sTitle;
}

function showArt_border(sNav,sMenuName){
	if (sMenuName != "ARTIKELLINK")
		document.getElementById("main_frame_borderHeader").innerHTML=sMenuName;
	document.frames[0].navigate(sNav);
	if (sMenuName == "Kun for b&oslash;rn")
		document.getElementById("menuHeader_image").background = "doc/images/menuHeader/KunForBorn.gif";
	else
		document.getElementById("menuHeader_image").background = "doc/images/menuHeader/Titlebar.gif";
}

function showArt_noborder(sNav){
	document.getElementById("main_frame_borderHeader").innerHTML=sMenuName;
	document.frames[0].navigate(sNav);
	if (sMenuName == "Kun for b&oslash;rn")
		document.getElementById("menuHeader_image").background = "doc/images/menuHeader/KunForBorn.gif";
	else
		document.getElementById("menuHeader_image").background = "doc/images/menuHeader/Titlebar.gif";
}

function SetChildren(){
	if (getMenuItemChildCount(SelectedMenuItem)>0){
		for(i=0; i<Menu.length ; i++){
			tmpMenuItem = Menu[i]
			if (getMenuItemParentId(tmpMenuItem)==getMenuItemId(SelectedMenuItem)){
				visibility(getMenuItemId(tmpMenuItem),"BLOCK");
				className(getMenuItemId(tmpMenuItem),"active")
				backgroundColor(getMenuItemId(tmpMenuItem),bgColor_tLvl)
}	}	}	}

function SetSisters(ParentId){
	for(i=0; i<Menu.length ; i++){
		tmpMenuItem = Menu[i];
		if (getMenuItemParentId(tmpMenuItem)==ParentId){
			visibility(getMenuItemId(tmpMenuItem),"BLOCK");
			if (getMenuItemLevel(tmpMenuItem)==1){
				// level 1 er altid mørk
				backgroundColor(getMenuItemId(tmpMenuItem),bgColor_std)
			}
			else if ((getMenuItemLevel(tmpMenuItem)==getMenuItemLevel(SelectedMenuItem))&&(getMenuItemChildCount(SelectedMenuItem)<1)){
				// hvis samme level som selected og selected ikke har børn : lys
				backgroundColor(getMenuItemId(tmpMenuItem),bgColor_tLvl)
				className(getMenuItemId(tmpMenuItem),"active")
			}
			else if ((getMenuItemLevel(tmpMenuItem)==getMenuItemLevel(SelectedMenuItem))&&(getMenuItemChildCount(SelectedMenuItem)>0)){
				// hvis samme level som selected og selected har børn : mørk
				backgroundColor(getMenuItemId(tmpMenuItem),bgColor_std)
			}
			else if (getMenuItemLevel(tmpMenuItem)<getMenuItemLevel(SelectedMenuItem)){
				// lavere level end selected : mørk
				backgroundColor(getMenuItemId(tmpMenuItem),bgColor_std)
			}
			else{
				backgroundColor(getMenuItemId(tmpMenuItem),bgColor_tLvl)
				className(getMenuItemId(tmpMenuItem),"active")
}	}	}	}

function SetParents(ParentId){
	if (ParentId != "0"){
		SetSisters(getMenuItemParentId(getMenuItem(ParentId)))
		SetParents(getMenuItemParentId(getMenuItem(ParentId)))
		className(ParentId,"parent")
}	}

function CloseAll(){
	for(i=0; i<Menu.length ; i++){
		visibility(Menu[i][0],"NONE");
		className(Menu[i][0],"deactive")
		fontWeight(Menu[i][0],"normal")
		backgroundColor(Menu[i][0],bgColor_std)
}	}

function SetMenuHeader(aMenuItem){
	if ((document.getElementById("menuHeader_image").background != getMenuHeader_image(aMenuItem))||(document.getElementById("menuHeader_text").innerText != getMenuHeader_text(aMenuItem))) {
		document.getElementById("menuHeader_image").background = getMenuHeader_image(aMenuItem); 
		document.getElementById("menuHeader_text").innerText = getMenuHeader_text(aMenuItem);
	}
}

function backgroundColor(aId,backgroundColor){
	document.getElementById("TD_" + aId).style.backgroundColor=backgroundColor;
	document.getElementById("TDa_" + aId).style.backgroundColor=backgroundColor;
}

function fontWeight(aId,fontWeight){
	document.getElementById("TD_" + aId).style.fontWeight=fontWeight;
	document.getElementById("TDa_" + aId).style.fontWeight=fontWeight;
}

function className(aId,className){
	document.getElementById("TD_" + aId).className=className;
	document.getElementById("TDa_" + aId).className=className;
}

function visibility(aId,display){
	document.getElementById(aId).style.display=display;
}

function getMenuItemId(MenuItem){
	return MenuItem[0]
}

function getMenuItemName(MenuItem){
	return MenuItem[1]
}

function getMenuItemParentId(MenuItem){
	return MenuItem[2]
}

function getMenuItemLevel(MenuItem){
	return MenuItem[3]
}

function getMenuItemChildCount(MenuItem){
	return MenuItem[4]
}

function getMenuHeader_text(MenuItem){
	return MenuItem[5]
}
function getMenuHeader_image(MenuItem){
	return ("doc/images/menuHeader/" + MenuItem[6])
}

function getMenuItemArticleCount(MenuItem){
	return MenuItem[7]
}

function getMenuItem(aId){
	var i = 0; 
	var found = false;
	while((i<Menu.length)&&(!found)){ 
		if (aId == Menu[i][0]){
			found=true;
		}
		else{
			i+=1;
	}	}
	return Menu[i]
}

function getMenuItemByIndex(aIndex){
	return Menu[aIndex]
}

function doPrint(){
	var oRoot = window.document.frames[0].document;
	var oNode = oRoot.createElement("<h2>")
	oNode.innerText =  document.getElementById("main_frame_borderHeader").innerText;
	oRoot.insertBefore(oNode,oRoot.firstChild) 
	window.document.frames[0].focus();
	window.document.frames[0].print();
	oRoot.removeChild(oNode)
}
