// This main basis of this script is the property of 4thorder(TM) Copyright © 2005.  All rights reserved.
// Author: Michael Falatine 4thorder@4thorder.us
// You may use this script for commercial or personal use, however, the copyright is retained-
// by 4thorder (TM). http://www.4thorder.us/Scripts/
// Original filename was MultiLevelDHTMLMenuExpanderV11.js, renamed by Jeroen van der Sluijs to menu.js
// Script modified by Jeroen van der Sluijs (jeroen@jvds.nl) Oct 2005 for A van den Berg BV, 
// such that buttons without children also show the plus-picture (arrow) in front and expand all deleted
// comments removed for fast loading
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){
HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{switch (where){
case 'beforeBegin':
this.parentNode.insertBefore(parsedNode,this)
break;
case 'afterBegin':
this.insertBefore(parsedNode,this.firstChild);
break;
case 'beforeEnd':
this.appendChild(parsedNode);
break;
case 'afterEnd':
if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
else this.parentNode.appendChild(parsedNode);
break;
}}
HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
{var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var parsedHTML = r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML)
}
HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
{var parsedText = document.createTextNode(txtStr)
this.insertAdjacentElement(where,parsedText)}
}
var firstLoad=0;
var GlobalECState=0;
window.onload=InitializePage;
function InitializePage()
{defineLayout(); prepareListStyles(); setLEVELs(); Icons(); attachEventhandlers();}
function defineLayout()
{document.getElementById("MDME").style.position="absolute";
document.getElementById('MDME').style.left= PagePositionLEFT+"px";
document.getElementById('MDME').style.top= PagePositionTOP+"px";
document.getElementById('MDME').style.zIndex=50;}
function setLEVELs()
{ULCollection=document.getElementById("MDME").getElementsByTagName("UL");
ULCollection.item(0).setAttribute("level", 1);
LICollection=document.getElementById("MDME").getElementsByTagName("LI");
for (a=0; a<LICollection.length;a++)
{LICollection.item(a).setAttribute("level", 1);}
if (ULCollection!=null)
{for (u=0; u<ULCollection.length; u++)
{var ULChildrenCollection=ULCollection.item(u).getElementsByTagName("UL");
for (l=0; l<ULChildrenCollection.length; l++)
{var previousLevel=parseInt(ULCollection.item(u).getAttribute("level"));
ULChildrenCollection.item(l).setAttribute("level", previousLevel+1);
var LIChildrenCollection=ULChildrenCollection.item(l).getElementsByTagName("LI");
for (m=0; m<LIChildrenCollection.length; m++)
{LIChildrenCollection.item(m).setAttribute("level", previousLevel+1);}
}}}}
function prepareListStyles()
{ULCollection=document.getElementById("MDME").getElementsByTagName("UL");
if (ULCollection!=null)
{for (u=0; u<ULCollection.length; u++)
{ULCollection.item(u).style.listStyleType="none";
ULCollection.item(u).setAttribute("id", "ULID"+u);}}}
function attachEventhandlers()
{LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{for (l=0; l<LICollection.length; l++)
{LICollection.item(l).onmouseup=onMouseUpHandler;}}
if(navigator.appName == 'Microsoft Internet Explorer')
{document.getElementById('MDME').style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+TValue+")"}
else
{document.getElementById('MDME').style.MozOpacity=1;
TValue=parseFloat(TValue/100-.001); 
document.getElementById('MDME').style.MozOpacity=TValue;}}
function ECALL(o) 
{LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{for (d=0; d<LICollection; d++)
{LICollection.item(i).style.listStyleImage="none";}}
firstLoad=0; GlobalECState=o; Icons();}
function Icons(tarObj)
{LICollection=document.getElementById("MDME").getElementsByTagName("LI");
if (LICollection!=null)
{for (i=0; i<LICollection.length; i++)
{ULChildrenCol=LICollection.item(i).getElementsByTagName("UL");
if(ULChildrenCol.length>0)
{FirstULWithinLI_ELEMENT=LICollection.item(i).getElementsByTagName("UL");
if(firstLoad==0)
{if(GlobalECState==0)
{LICollection.item(i).setAttribute("ECState",0);
if(imagePLUS!='')
{LICollection.item(i).style.listStyleImage='url(menu/'+imagePLUS+')';
LICollection.item(i).style.listStylePosition='inside';}
LICollection.item(i).style.cursor="pointer";
FirstULWithinLI_ELEMENT.item(0).style.display='none';}
else
{LICollection.item(i).setAttribute("ECState",1);
if(imageMINUS!='')
{LICollection.item(i).style.listStyleImage='url(menu/'+imageMINUS+')';
LICollection.item(i).style.listStylePosition='inside';}
LICollection.item(i).style.cursor="pointer";
FirstULWithinLI_ELEMENT.item(0).style.display='block';}}
else
{State=LICollection.item(i).getAttribute("ECState");
if(State==0)
{if(imagePLUS!='')
{LICollection.item(i).style.listStyleImage='url(menu/'+imagePLUS+')';
LICollection.item(i).style.listStylePosition='inside';}
FirstULWithinLI_ELEMENT.item(0).style.display='none';}
else
{if(oneBranch=='yes' && tarObj!=null)
{targetLevel=tarObj.getAttribute("level");
tarObjParentLICol=tarObj.parentNode.getElementsByTagName("LI");
for (tar=0;tar<tarObjParentLICol.length; tar++)
{ItemLevel=tarObjParentLICol.item(tar).getAttribute("level");
if(targetLevel==ItemLevel)
{tarObjParentLIULCol=tarObjParentLICol.item(tar).getElementsByTagName("UL");
if(tarObjParentLIULCol.length!=0 && tarObj!=tarObjParentLICol.item(tar))
{tarObjParentLIULCol.item(0).style.display='none';
if(imagePLUS!='')
{tarObjParentLICol.item(tar).style.listStyleImage='url(menu/'+imagePLUS+')';
tarObjParentLICol.item(tar).style.listStylePosition='inside';
tarObjParentLICol.item(tar).setAttribute("ECState",0);}}}}}
if(imageMINUS!='')
{LICollection.item(i).style.listStyleImage='url(menu/'+imageMINUS+')';
LICollection.item(i).style.listStylePosition='inside';}
FirstULWithinLI_ELEMENT.item(0).style.display='block';}}}
else   
{if(imagePLUS!='')
{LVL=LICollection.item(i).getAttribute("level");
if(LVL==1)
{LICollection.item(i).style.listStyleImage='url(menu/'+imagePLUS+')';
LICollection.item(i).style.listStylePosition='inside';}
else
{LICollection.item(i).style.listStyleImage="none";}}}}}
if(firstLoad==0){firstLoad=1;}}
function onMouseUpHandler(e)
{var tarObj;
if (!e) var e = window.event;
if (e.target) tarObj= e.target;
else if (e.srcElement) tarObj= e.srcElement;
if (tarObj.nodeType == 3) 
tarObj= tarObj.parentNode;
tarObj=findTH(tarObj);
State=tarObj.getAttribute("ECState");
if(State==0)
{tarObj.setAttribute("ECState",1);}
else{tarObj.setAttribute("ECState",0);}
Icons(tarObj);
e.cancelBubble = true;}
function findTH(t)
{if (t.tagName == "LI")
{return t;}
else if
(t.tagName == "UL")
{return null;}
else
{return findTH(t.parentNode);}}
