function isBrowser () {
  // BROWSER CHECK
  // Note: On IE5, these return 4, so use is.ie5up to detect IE5.
  
	// convert all characters to lowercase to simplify testing 
	var agt=navigator.userAgent.toLowerCase(); 
  
  this.major = parseInt(navigator.appVersion); 
  this.minor = parseFloat(navigator.appVersion); 
  
  this.nav     = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1)); 
  this.nav2    = (this.nav && (this.major == 2)); 
  this.nav3    = (this.nav && (this.major == 3)); 
  this.nav4    = (this.nav && (this.major == 4)); 
  this.nav4up  = (this.nav && (this.major >= 4)); 
  this.navonly = (this.nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) ); 
  this.nav5    = (this.nav && (this.major == 5)); 
  this.nav5up  = (this.nav && (this.major >= 5)); 
  this.nav6    = (this.nav && (this.major == 6)); 
  
  this.ie      = (agt.indexOf("msie") != -1); 
  this.ie3     = (this.ie && (this.major < 4)); 
  this.ie4     = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1) && (agt.indexOf("msie 6")==-1) ); 
  this.ie45    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4.5")==-1) ); 
  this.ie4up   = (this.ie && (this.major >= 4)); 
  this.ie5     = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  this.ie55    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5")!=-1) );  
  this.ie6     = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.0")!=-1) ); 
  this.ie5up   = (this.ie && !this.ie3 && !this.ie4 && !this.ie5); 
}

var browser = new isBrowser();

function DropMenu(oName,topOffset){
	this.oName=oName;
	this.arrMenus=[];	
	this.lastActMenuItem=[];
	this.lastActMenu=[];	
	this.getMenu=getMenu;
	this.showMenu=showMenu;
	this.resetMenu=resetMenu;
	this.hideMenuAll=hideMenuAll;
	this.setupMenus=setupMenus;
	this.sizeSubMenu=sizeSubMenu;
	this.renderType;
	//this.renderHorizontal=renderHorizontal;
	this.renderVertical=renderVertical;
	this.mouseOut=mouseOut;
	this.mouseOver=mouseOver;
	this.topOffset=topOffset;
	
}




function renderVertical(){

	//vanuit asp code = [0][0] leeg, maar dit geeft problemen op oudere IE's, dus onzin waarde erin zetten
	this.arrMenus[0][0]=99999;
	
	//write main menu (always visible)
	document.write(this.getMenu(0,0));
}

function getMenu(parent, level){
	var count=0;
	var menu='';
	var submenus='';

	//write menu
	for(var i=0;i<this.arrMenus.length;i++){
		if(this.arrMenus[i][1]==parent){
			//alert(parent);
			var cl= (level==0) ? 'menuNormal0' : 'menuNormal1';
			//alert(cl);
			var linkId="sc_link_" + this.oName+this.arrMenus[i][0];
			menu += "<img src='images\/templates\/12\/btn.jpg' class='bgImg' style='top:" + (count*21) + "px;width:100%;z-Index:100;overflow:visible;cursor:hand;cursor:pointer;'>";
			
			//tekst in div met attr nowrap (=IE only attr), want IE5 en lager ondersteunen geen white-space, waardoor de menutekst afgebroken werd....
			menu += "<div id='divLabel" + this.oName + this.arrMenus[i][0] + "' class='" + cl + "' style='top:" + (count*21) + "px;cursor:hand;cursor:pointer;' " +
				"onclick='openLink(\"" + this.arrMenus[i][3] + "\")' " + 
				"onmouseover='" + this.oName + ".mouseOver(this.id," + level + ",\"divMenu" + this.oName + parent + "\");return !" + this.oName + ".showMenu(\"divMenu" + this.oName + parent + "\",this,\"divMenu" + this.oName+this.arrMenus[i][0] + "\",event," + (level+1) + "," + this.arrMenus[i][0] + ")'>";
			menu += "<div nowrap id='divSpan" + this.oName + this.arrMenus[i][0] + "' style='display:inline;cursor:hand;cursor:pointer;z-Index:150;overflow:show;white-space:nowrap;width:100%;'>" + this.arrMenus[i][2].replace(' ','&nbsp;') + "</div>";
			menu += "</div>";
			count+=1;
			submenus += this.getMenu(this.arrMenus[i][0], level+1);
		}
	}
	if (menu.length>0){
		var cl= (level==0) ? 'menu0': 'menu1';
		return "<div id='divMenu" + this.oName + parent + "' class='" + cl + "' onmouseover='event.cancelBubble=true;' style='width:125px;height:" + (count*21) + "px;'>" + menu + "</div>" + submenus;
	}else{
		return '';
	}
}


function setupMenus(){

	for(var i=0;i<this.arrMenus.length;i++){
		if(this.arrMenus[i][1]==0){
			this.sizeSubMenu(this.arrMenus[i][0])
			var sp = getObject("divLabel" + this.oName + this.arrMenus[i][0]);
			//alert(sp);
			if (sp) sp.width=125;

		}
	}
}

function sizeSubMenu(parentid){
	//size menu
	var maxwidth=0;
	var thiswidth=0;
	
	//determine maxwidth
	for(var i=0;i<this.arrMenus.length;i++){
		if(this.arrMenus[i][1]==parentid){
			//window.status=getObjectWidth("divSpan" + this.oName + this.arrMenus[i][0]);
			thiswidth = getObjectWidth("divSpan" + this.oName + this.arrMenus[i][0]);
			//alert(thiswidth);
			if (thiswidth>maxwidth) maxwidth=thiswidth;
			this.sizeSubMenu(this.arrMenus[i][0]);
		}
	}
	if (maxwidth<125) maxwidht=125;
	
	//set all items to maxwidth	
	for(var i=0;i<this.arrMenus.length;i++){
		if(this.arrMenus[i][1]==parentid){
			var sp = getObject("divLabel" + this.oName + this.arrMenus[i][0]);
			//alert(sp);
			if (sp) sp.width=maxwidth;
		}
	}
	maxwidth=maxwidth+10;
	
	//set container to maxwidth
	var oMenuStyle=getObject("divMenu" + this.oName + parentid);
	//alert(oMenuStyle);
	if (oMenuStyle)	oMenuStyle.width = maxwidth;
}



function showMenu(parentMenu,parentMenuItem,idMenu,evt,level, parentid){


	document.onmouseover=new Function(this.oName+".resetMenu()");
	
	this.lastActMenu[level]=null;
	
	
	var oMenuStyle=getObject(idMenu);
	if (oMenuStyle){
		var top = getObjectTop(parentMenu) + getObjectTop(parentMenuItem); // getTop(oEl.id)+4;//+4 => adjustment
		var maxBottom = getInsideWindowHeight();		
		if (level ==2){
			var topParent = getObjectTop(parentMenuItem) + parseInt(parentMenuItem.style.top) + this.topOffset;
		}else{
			var topParent =   this.topOffset;
		}
			var bottom = top + topParent + getObjectHeight(idMenu);		
		if (bottom>maxBottom){
			top = top -  (bottom-maxBottom);
			if ((topParent+top)<0) top=-1*topParent;
		}
		oMenuStyle.top = top;
		oMenuStyle.left = getObjectWidth(parentMenu) + getObjectLeft(parentMenu) ;

		//this.hideMenuAll();
		evt.cancelBubble=true;
		show(oMenuStyle);
		setZIndex(oMenuStyle,1000);
		this.lastActMenu[level]=idMenu;
		
		if (browser.ie && !browser.ie5up){
			// als er een dataframe is op ie5 of lager dan frame tijdelijk hiden, want het menu 
			// valt eronder.....
			hide("dataFrame");	
		}
		return true;
	}else{
		return false
	}
}
		
function resetMenu()
{
	//alert("reset");

	if (this.lastActMenuItem[0]) this.mouseOut(this.lastActMenuItem[0],0);
	this.lastActMenuItem[0]=null;
	this.hideMenuAll();
	if (browser.ie && ! browser.ie5up){
		// als er een dataframe is op ie5 of lager dan frame tijdelijk hiden, want het menu 
		// valt eronder.....
		//var frame = getObject("dataFrame");
		//if (frame) 
		show("dataFrame");
	}


}

function hideMenuAll(){
	for(var i=0;i<this.arrMenus.length;i++)	{
		var id=this.arrMenus[i][0]
		hide("divMenu"+this.oName+id);
	}
}


function mouseOver(idEl,level,menu)	{
	
	if (this.lastActMenu[level+1]) {
		if (this.lastActMenu[level+1]!=null) {
			hide(this.lastActMenu[level+1]);
		}
	}

	
	if (level==0) this.resetMenu();
	
	var el = getObject(idEl);
	setClass(idEl,'menuHoover');
	if (el)	el.width = getObjectWidth(menu);
	
	if (this.lastActMenuItem[level]){
		if (this.lastActMenuItem[level]!=idEl){
			this.mouseOut(this.lastActMenuItem[level],level);
		}
	}
	this.lastActMenuItem[level]=idEl;
}
	
function mouseOut(idEl,level){
	//alert("mouseout " + idEl + " level:" + level);
	var cl= (level==0) ? 'menuNormal0' : 'menuNormal1';
	setClass(idEl,cl);
}
	
function openLink(url){
		window.location.href=url;
}
	

var isCSS, isW3C, isIE4, isNN4;
// initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}

// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof(obj) == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
	if (theObj){
	    if (isCSS && theObj.style) {
    	    theObj = theObj.style;
	    }
    	return theObj;
	}
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
		theObj.visibility 
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Set the z-order of an object
function setZIndex(obj, zOrder) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Retrieve the x coordinate of a positionable object
function getObjectLeft(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    } else if (isNN4) {
        result = elem.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
function getObjectTop(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    } else if (isNN4) {
        result = elem.top;
    }
//	return(result);
  	return parseInt(result);
}

// Retrieve the rendered width of an element
function getObjectWidth(obj)  {
    var elem = getRawObject(obj);
    var result = 0;

    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
function getObjectHeight(obj)  {
    var elem = getRawObject(obj);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}


// Return the available content width space in browser window
function getInsideWindowWidth() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}
// Return the available content height space in browser window
function getInsideWindowHeight() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}

function setClass(obj,cls){
	theObj=getRawObject(obj);
	if (theObj)
		theObj.className=cls;
		
}
