/* Generated by    : Indivirtual Function Library                                */
/* Name            : CM in framset with rows                                     */
/* Usage           : Example of the Cascade menu in a rows frameset              */
/* Description     : Example of the Cascade menu in a rows frameset              */
/* Author          : Niels   Koopman                                             */
/* Date            : 7/17/2003                                                   */
/* ReleaseInfo     :                                                             */
/* ReleaseNo       : 2                                                           */
/* Date            : 7/24/2003                                                   */
/* Name            : Niels   Koopman                                             */
/* Description     :                                                             */
/*                 : Copyright (c) 2003 Indivirtual (info@indivirtual.com)       */
//Example of the Cascade menu in a rows frameset
/* Generated by    : Indivirtual Function Library                                */
/* Name            : Cascade menu (IE4+, NS6+)                                   */
/* Usage           :                                                             */
/* Description     : Cascading menu for usage in documents and framesets         */
/* Author          : Niels   Koopman                                             */
/* Date            : 7/17/2003                                                   */
/* ReleaseInfo     :                                                             */
/* ReleaseNo       : 5                                                           */
/* Date            : 7/22/2003                                                   */
/* Name            : Niels   Koopman                                             */
/* Description     :                                                             */
/*                 : Copyright (c) 2003 Indivirtual (info@indivirtual.com)       */
var isDOM = document.getElementById; 
var isIE4 = (document.all && !isDOM);
var isNS = this.ns6=(isDOM && parseInt(navigator.appVersion) >= 5) ;

function getRef(Id,doc) {
	var d=doc;
	var undefined;
	if(d==undefined) d=document;
	if (isDOM) return d.getElementById(Id);
	if (isIE4) return d.all[Id];
}

function oMenu(sName,menuFrame,baseFrame,subFrame,aCorrXYbase,aCorrXYsub,subWidth,frameType){
	//Init properties
	//example normal doc
	//(sName,false,'','','',[-11,0],[2,0],100,'')
	//example frameset
	//(sName,true,'parent.fTop','',parent.content.document,[-11,0],[2,0],100,'col')
	this.menuFrame	= menuFrame; 		//string name of frame where object is defined string i.e. 'parent.frametop' if no frame: ''
	this.baseFrame 	= baseFrame; 		//string for frame where basemenu appears i.e. 'parent.frametop' if no frame: ''
	this.subFrame 	= subFrame; 		//string for frame where submenu's apear i.e. parent.content.document i.e. 'parent.frametop' if no frame: ''
	this.corrXYbase = aCorrXYbase; 	// XY correction to position 1th level submenu's 
	this.corrXYsub 	= aCorrXYsub; 	// XY correction to position rest of the submenu's 
	this.frameType  = frameType=='row'?'row':frameType=='col'?'col':'';//if the menu is in a row frame 'row' and in a cols-frame 'col'
	this.subWidth	= subWidth;		//width of the sub menu's
	
	this.bDebug		= false;			//For DebugInfo
	this.Delay 		= 200;			//Delay for hiding menu
	this.timeOut	= 0;
	this.subIcon	= '';			//img for subicon
	this.subIconWidth = 0;			//width of subicon

	this.nixGif		= 'img/nix.gif';			//nix img

	//privates, no further changes have to be done here.
	this.baseDoc 	= baseFrame==''?document:eval(baseFrame+'.document');//document for basemenu i.e. document
	this.subDoc 	= subFrame==''?document:eval(subFrame+'.document'); //document for submenu's i.e. parent.content.document
	this.sObjName	= sName;
	this.Name 		= menuFrame!=''?menuFrame+'.'+sName:sName;
	this.aHead 		= new Array();
	this.aItem 		= new Array();
	this.aFooter 	= new Array();
	this.aMenu 		= new Array();
	this.Level 		= 0;
	this.Id			= 0;
	this.maxLevel	= 0;
	this.bLeft		= false;
	this.clicked	= false;
	this.DebugDiv = '<div id="'+this.sObjName+'_debug" style="position:absolute;background-color:#ffffff;left:50;top:200;width:100;visibility:visible;z-index:1;">debug</div>';
	if(!isDOM && !isIE4){
		alert('Browser not supported');
		return;
	}
	this.addItem 	= oMenu_addItem;
	this.getMItem 	= oMenu_getMItem;
	this.putMenu 	= oMenu_putMenu;
	this.initSub 	= oMenu_initSub;
	this.hideMenu 	= oMenu_hideMenu;
	this.timeHide 	= oMenu_timeHide;
	this.getLayout 	= oMenu_getLayout;
	this.Debug 		= oMenu_Debug;
	this.goLoc 		= oMenu_goLoc;
	this.timeShow	= oMenu_timeShow;
	//init layout
	var i=0;
	var sL=this.getLayout(i);
	if(sL==''){
		alert('No layout defined, define HTML layout');
		return;
	}
	while(sL!=''){
		this.aHead[i] = sL.substring(sL.search('<!--1-->')+8,sL.search('<!--2-->'));
		this.aItem[i] = sL.substring(sL.search('<!--2-->')+8,sL.search('<!--3-->'));
		this.aFooter[i] = sL.substring(sL.search('<!--3-->')+8);
		i++;
		sL = this.getLayout(i);
	}
}
var MENU_MOUSEOVER;//for debug purposes
var MENU_MOUSEOUT;//for debug purposes
function oMenu_Debug(s){
	if(this.bDebug){
		var d = (this.frameType=='')?getRef(this.sObjName+'_debug',this.baseDoc):getRef(this.sObjName+'debug',this.subDoc);
		if (d!=null) d.innerHTML = s + "<br>";
	}
}
function oMenu_getLayout(Id){
	//gets the HTML layout as defined in the HTML-layout Div
	var oD;
	for(var i=Id;i>=0;i--){
		oD = getRef(this.sObjName+'_layout'+Id);
		if(oD==null) return ''
		else return oD.innerHTML;
	}
}

function oItem(Id,sLink,sLabel,iLevel){
	//menu item object
	this.aMenu=new Array();//of items
	this.Id = Id;
	this.sLink = sLink;
	this.sLabel = sLabel;
	this.Level= iLevel;
	//Debug(Id + " - " + sLink + " - " + sLabel + " - " + iLevel);
}

function oMenu_addItem(Id,ParentId,sLink,sLabel){
	var aM;
	var Level;
	if(ParentId==0){
		aM = this.aMenu;
		Level = this.Level;
	}else{
		var oI = this.getMItem(ParentId,this.aMenu);
		aM = oI.aMenu
		Level = oI.Level;
	}
	var i = aM.length;
	aM[i] = new oItem(Id,sLink,sLabel,Level+1);
	if(Level+1>this.maxLevel)this.maxLevel=Level+1;
	this.Level=0;
}

function oMenu_getMItem(Id,aM){
	for(var i=0;i<aM.length;i++){
		if(aM[i].Id==Id){
			return aM[i]; //array which contains the sumbenu items
		}else{
			var aNew = this.getMItem(Id, aM[i].aMenu);
			if(aNew!='') return aNew;
		}
	}
	return '';
}

function oMenu_initSub(Id,aM,bSub){
	//if submenudiv not initialized then do it here
	this.subDoc	= (this.subFrame=='')?document:eval(this.subFrame+'.document');
	var d = getRef(this.sObjName+'_submenu',this.subDoc);
	if(d==null){
		if (isDOM){
			var sD = this.subDoc.getElementsByTagName('body');
			var newDiv = this.subDoc.createElement('div');
			newDiv.id = this.sObjName+'_submenu';
			sD.item(0).appendChild(newDiv);
			newDiv.style.position = 'absolute';
			newDiv.style.visibility = 'visible';
			newDiv.style.left = 0;
			newDiv.style.top = 0;
		}
		// Insert a div tag to the end of the BODY with menu HTML in place for IE4.
		if (isIE4) document.body.insertAdjacentHTML('beforeEnd', '<div id="'+this.sObjName+'_submenu" style="position: absolute; visibility: hidden;"></div>');
		d = getRef(this.sObjName+'_submenu',this.subDoc);
		if(d!=null){
			var subM=this.bDebug?this.DebugDiv:'';
			for(var i=0;i<=this.maxLevel;i++){
				subM+= '<div id="'+this.sObjName+'_sub'+i+'" '
				//subM+= !isNS?'onmouseover="'+this.Name+'.timeShow();" onmouseout="'+this.Name+'.timeHide();" ':'';
				subM+= 'onmouseover="'+this.Name+'.timeShow();" '
				subM+= 'onmouseout="'+this.Name+'.timeHide();" ';
				subM+= 'style="position:absolute;left:0;top:0;width='+this.subWidth+';visibility:visible;z-index:'+(i+2)+';"></div>';
			}
			d.innerHTML = subM;
			return true;
		}else return false;
	}
	return true;
}

function oMenu_timeShow(){
	clearTimeout(this.timeOut);
}
function oMenu_timeHide(){
	clearTimeout(this.timeOut);
	this.timeOut = setTimeout(this.Name+'.hideMenu();',this.Delay);
}
function oMenu_hideMenu(){
	for(var i=0;i<=this.maxLevel;i++){
		var d = getRef(this.sObjName+'_sub'+i,this.subDoc)
		if(d!=null) d.innerHTML ='';
	}
}
function oMenu_goLoc(ref){
	//prevent 2 clicks
	clearTimeout(this.timeOut);
	if((this.clicked!=ref && isNS) || !isNS){
		this.clicked = ref;
		if(ref!='' && ref!='#') parent.content.document.location = ref;// this.subDoc.location = ref;
		setTimeout(this.Name+'.clicked="";',1000);
		this.Debug(ref);
	}
}

function oMenu_putMenu(Id){
	clearTimeout(this.timeOut);
	var aM = this.aMenu;
	var s='';
	var d;
	var Level=this.Level;
	if(Id!=0){
		var oI=this.getMItem(Id,aM);
		aM = oI.aMenu;
		Level=oI.Level;
		if(Level==1){
			if(!this.initSub(0,aM,false)){
				setTimeout(this.Name + '.putMenu('+Id+')',200);
				return;
			}
		}
	}
	var iM = (Level>=this.aHead.length)?this.aHead.length-1:Level;
	if(aM.length>0){
		s+=this.aHead[iM];
		for(var i=0;i<aM.length;i++){
			var subPos ='<div id="'+this.sObjName+'_subPos'+aM[i].Id+'" ';
			subPos +='style="position:relative;left:0;top:0;width:0;height:0;';
			subPos +='visibility:visible;z-index:'+(Level+2)+';"></div>';

			var l= this.aItem[iM].replace(/MENU_LINK/g,this.Name+'.goLoc(\''+aM[i].sLink+'\');');
			l = l.replace(/MENU_MOUSEOVER/g, this.Name+'.putMenu('+aM[i].Id+');');
			
			l = l.replace(/MENU_SUBICON/g, (this.subIcon!=''?'<img src="'+(aM[i].aMenu.length>0?this.subIcon:this.nixGif)+'" width="'+this.subIconWidth+'">':''));
			if(Level==0) l = l.replace(/MENU_MOUSEOUT/g,this.Name+'.timeHide();');
			else l = l.replace(/MENU_MOUSEOUT/g,'');
			l = l.replace(/MENU_ID/g,aM[i].Id);
			s+= l.replace(/MENU_DIV/g,subPos).replace(/MENU_LABEL/g,aM[i].sLabel);
		}
		s+=this.aFooter[iM];
		//if(Level==1) alert(s);
		if(Level==0){
			getRef(this.sObjName+'_menu',this.baseDoc).innerHTML = s;
		}else {
			//get the x and y position of the positiondiv (posDiv)
			d=getRef(this.sObjName+'_subPos'+Id,(Level==1)?this.baseDoc:this.subDoc);
			var	iX = d.offsetLeft;
			var	iY = d.offsetTop;
			//var	iY = (Level==1 || isNS)?d.offsetTop:d.offsetTop/2;//bug in IE(returns 2*top)!!!??
			d=d.offsetParent;
			iX += d.offsetLeft;
			iY += d.offsetTop;
			d=getRef(this.sObjName+'_sub'+Level,this.subDoc);
			if(Level==1){ //check scrolled content in frame
				this.bLeft=false;
				if (this.frameType=='col') iX = this.subDoc.body.scrollLeft
				else if(this.frameType=='row') iY = this.subDoc.body.scrollTop;
			}
			d.style.left = iX+(Level==1?this.corrXYbase[0]:this.corrXYsub[0]);
			d.style.top = iY+(Level==1?this.corrXYbase[1]:this.corrXYsub[1]);
			d.innerHTML = s;
			//check if menu fits in the page else move opposite way (only X direction)
			if(iX+this.subWidth>this.subDoc.body.clientWidth-(Level==1?this.corrXYbase[0]:this.corrXYsub[0]) || this.bLeft){
				this.bLeft=true;
				d.style.left=iX-2*this.subWidth-this.corrXYsub[0];
			 }
			for(var i=Level+1;i<this.maxLevel;i++) getRef(this.sObjName+'_sub'+i,this.subDoc).innerHTML='';

			this.Debug('div='+this.subWidth+' div+left='+(iX+this.subWidth)+' body='+this.subDoc.body.clientWidth)
		}
	}else{
		for(var i=Level;i<this.maxLevel;i++) getRef(this.sObjName+'_sub'+i,this.subDoc).innerHTML='';
		this.Debug('loc='+oI.sLink+', no submenu')
	}
}

