
	/*
	***************************************************************************
	* ( c ) Christian Paul Praher stark ueberarbeitete Version 2000-08-08		*
	* Verwendung nur unter Ruecksprache mit dem Autor							*
	* mailto: cp@hapra.at || praher_c1@hak-hlw-rohrbach.asn-linz.ac.at			*
	* ( c ) Praher KEG http://www.prahersoft.com									*
	*****************************************************************************
	2000-08-09
	2000-09-24 : hide DDMenu bei onmouseout funktionalitaet
	2000-10-21 : BUG-FIX: 2 Child-Menues hintereinander nun auch schliessbar
	2001-02-04 : NEW : NOW LeftOffSet manually setable + according enum-image
	*/
	
	var imgPath = "images/";
	var ie4 = false;
	var ns4 = ( document.layers ) ? true:false; //fuer Netscape Navigator 4xx
	if ( ( navigator.appName == "Microsoft Internet Explorer" ) && 
	( navigator.appVersion.indexOf( "MSIE 4" ) != -1 ) ) ie4 = true; //Internet Explorer 4 ( u 5 ) kompatibel
	var DOMCmp	= ( document.getElementById ) ? true:false; //Means DOM 1 & 2 compatible ( NS6 && IE5 )
	
	function DDMenu(  )
	{
		this.cssOut			= "";
		this.elementsOut	= "";
		this.bgColor		= "";
		this.bgColorOver	= "";
		this.eventListener	= "";
		this.iEnumOffset	= [ ];
		this.strEnumURL		= [ ]; 
		this.iBorderWidth	= 0;
		this.strBorderColor	= "";
		this.meLeft			= 0;
		this.meTop			= 0;
		this.myWidth		= 0;
		this.totalHeight	= 0;
		this.tableHeight	= 0;
		this.isOpen			= false;
		this.displayHR		= false;
		this.TOutActive		= false; //checks, if theres already a timeout started
		this.timeOut		= null;
		this.ancestor		= null;
		this.aClass			= null; //styles fuer die A-Tags
		this.tdClass			= null; //styles fuer die TD-Tags
		this.exTimerID		= null; //external Timer ID
		this.applyStyles	= DDMenu_applyStyles;
		this.setTopLeft		= DDMenu_setTopLeft; //Werte werden mit document.XY gesetzt
		this.adjust			= DDMenu_adjust; //Menues werden mit XuY-Werten von setTopLeft ausgerichtet
		this.addMenuItem	= DDMenu_addMenuItem;
		this.build			= DDMenu_build;		
		this.addChild		= DDMenu_addChild;
		this.getChilds		= DDMenu_getChilds;		
		this.show			= DDMenu_show;
		this.hide			= DDMenu_hide;
		this.hideChildren	= DDMenu_hideChildren; //Netscape proprietaere Funktion, wegen event handler schwaeche
		this.hideParent		= DDMenu_hideParent;
		this.elemChg		= DDMenu_elemChg;
		this.checkTimeOut	= DDMenu_checkTimeOut; // checks to see if there's already a timeout set
		this.clearTimeOut	= DDMenu_clearTimeOut; // clears timeOut of otherwise to much recursion
		this.setTimeOut		= DDMenu_setTimeOut; // sets the timeout
		this.setExTimer		= DDMenu_setExTimer; //clears external Timer
		this.setBorderStyle	= DDMenu_setBorderStyle;
	}
	
	function DDMenu_setBorderStyle( pBorderWidth, pBorderColor )
	{
		this.iBorderWidth	= pBorderWidth;
		this.strBorderColor	= pBorderColor;
	}
	
	
	function DDMenu_setTopLeft( piTop, piLeft )
	{
		this.meLeft  = piLeft;
		this.meTop   = piTop;
	}
	
	function DDMenu_adjust( )
	{
		if ( ie4 ){	
			document.all[ this.menuName ].style.pixelTop	= this.meTop;
			document.all[ this.menuName ].style.pixelLeft	= this.meLeft;
		} if ( ns4 ) {
			document.layers[ this.menuName ].top	= this.meTop;
			document.layers[ this.menuName ].left	= this.meLeft;		
		} if ( DOMCmp ) {
			document.getElementById( this.menuName ).style.top	= this.meTop + "px";
			document.getElementById( this.menuName ).style.left = this.meLeft + "px"; 
		} 			
	}
	
	function DDMenu_addMenuItem( pstrElement, pstrURLs, piEnumOffset, pstrEnumURL, pchildObj, pTarget  )
	{
		key = this.elements.length;
		this.elements[ key ]	= pstrElement;
		this.urls[ key ]		= ( pstrURLs ) ? pstrURLs : null;
		this.iEnumOffset[ key ] = ( piEnumOffset ) ? piEnumOffset : 4; /* Platz zwischen Anfang der Tabelle und Menuetext */
		this.strEnumURL[ key ]	= ( pstrEnumURL ) ? "<img src='" + pstrEnumURL + "' border='0'>" : "&nbsp;";
		this.childObjs[ key ]	= ( pchildObj ) ? pchildObj: null;
		this.targets[ key ]		= ( pTarget ) ? pTarget : "_self";

	}
	
	function DDMenu_applyStyles( piWidth, piTableHeight, pbgColor, pbgColorOver, pAClass, pTDClass )
	{
		this.tableHeight	= ( piTableHeight ) ? piTableHeight:26;
		for ( i=1; i <= this.elements.length; i++ )
		{
			this.totalHeight	= eval( this.tableHeight * i   );
		}
		this.totalHeight	+= this.iBorderWidth; //sets the additional space that is visible at the end of the table content
		this.myWidth		= piWidth;
		this.bgColor		= ( pbgColor ) ? pbgColor : '';
		this.bgColorOver	= ( pbgColorOver ) ? pbgColorOver : '';
		this.aClass		= ( pAClass ) ? 'class="' + pAClass + '"' : "";
		this.tdClass		= ( pTDClass ) ? 'class="' + pTDClass + '"' : "";
				
		this.cssOut += "<style type='text/css'>" + "\n";
		this.cssOut += "#" + this.menuName + "\n";
		this.cssOut += "{" + "\n";
		this.cssOut += "position: absolute;" + "\n";		
		if ( ( ie4 ) || ( ns4 ) ) this.cssOut += "visibility: hidden;" + "\n";
		if ( DOMCmp ) this.cssOut += "display: none;" + "\n";
		this.cssOut += "width: " + piWidth + ";" + "\n";
		this.cssOut += "height: " + this.totalHeight + ";" + "\n";
		this.cssOut += "clip: rect( 0," + piWidth + "," + this.totalHeight + ",0);" + "\n";
		if ( ns4 ) this.cssOut += "layer-background-color: " + this.bgColor + ";" + "\n"; 
		this.cssOut += "background-color: " + this.bgColor + ";" + "\n";
		this.cssOut += "}" + "\n";
		this.cssOut += "</style>";		
	
		document.write( this.cssOut );
	}
	
	function DDMenu_build( )
	{				
		if ( this.menuName == null ) { alert( "ungueltiger MenueName!" ); return; }	
		overEvent	= " onmouseover='" + this.objName + ".show( );' ";
		outEvent	= " onmouseout='" + this.objName + ".hide( );' ";	
		clickEvent	= " onclick='" + this.objName + ".show( );' ";
		if ( ( ie4 ) || ( DOMCmp ) ) 
			this.elementsOut += "<div id='" + this.menuName + "'" + overEvent + ">" + "\n";
		if ( ns4 )
			this.elementsOut += "<div id='" + this.menuName + "'>" + "\n";
			
		var totInnerHeight = 0;	

		for ( key in this.elements )
		{	
			//Breite der Zelle wo Text steht ( Abzueglich aufzaehlungszeichenbreite )
			//Jetzt werden auch noch 2px fuer linken und rechten Rand abgezogen
			//10px werden auch noch Submenus abgezogen
			var mainTDWidth	= eval( this.myWidth - this.iEnumOffset[ key ] - ( this.iBorderWidth * 2 ) - 10 ); 
			
			if ( this.displayHR )
				mult = eval( this.tableHeight + 1 )
			else 
				mult = eval( this.tableHeight );	
			topPos = eval( key * mult );
			totInnerHeight += mult;
			
			/* temp divelem name: */
			divElem = "div" + this.menuName + "Elem" + key;
			/* Events start: */

			if ( this.childObjs[ key ] == null   )
			{
				outEvent	= " onmouseout =" + this.objName + ".elemChg" + "(" + null + ",'" + divElem + "','" + this.bgColor + "','out');";			
				overEvent	= " onmouseover=" + this.objName + ".elemChg" + "(" + null + ",'" + divElem + "','" + this.bgColorOver + "','over');";			
			} else {
				overEvent	= " onmouseover=" + this.objName + ".elemChg" + "(" + this.childObjs[ key ].objName + ",'" + divElem + "','" + this.bgColorOver + "','over');";
				outEvent	= " onmouseout =" + this.objName + ".elemChg" + "(" + null + ",'" + divElem + "','" + this.bgColor + "','out');";			
			} 
			
			if ( this.urls[ key ] == null )
			{
				outEvent	= " onmouseout =" + this.objName + ".elemChg" + "(" + null + ",'" + divElem + "','" + this.bgColor + "','out');";			
				overEvent	= " onmouseover=" + this.objName + ".elemChg" + "(" + null + ",'" + divElem + "','" + this.bgColor + "','over');";			
			}
			/* Events ende */
			/* multiplikator dient der Erhoehung der Tabellenhoehe um eins bei HR == true */
	
			if ( ( ie4 ) || ( DOMCmp ) )
			{
				this.elementsOut += "<div id='" + divElem + "'" + overEvent + outEvent;
				this.elementsOut += " style='position: absolute; left: 0; top: " + topPos + "; width: " + this.myWidth + "; cursor:hand; background-color: " + this.bgColor + ";"; 
				this.elementsOut += " clip: rect(0," + this.myWidth + "," + this.tableHeight + ",0);";
				this.elementsOut += "'>" + "\n";
			} else if ( ns4 ) {
				this.elementsOut += "<layer id=" + divElem + overEvent + outEvent;
				this.elementsOut += " top=" + topPos + " left=0 width=" + this.myWidth; 
				this.elementsOut += " bgColor=" + this.bgColor; 
				this.elementsOut += " clip=0,0," + this.myWidth + "," + this.tableHeight; 
				this.elementsOut += ">" + "\n";				
			}
			tblID = "tbl" + this.menuName + key; //bgColor= 			
			this.elementsOut += "<table border='0' id='" + tblID + "' width='" + this.myWidth + "' cellpadding='0' cellspacing='0' height='" + this.tableHeight + "'>" + "\n";
			this.elementsOut += "<tr>";
			if ( this.iBorderWidth != 0 )
				this.elementsOut += "<td width='" + this.iBorderWidth + "' bgColor='" + this.strBorderColor + "'><img src='" + imgPath + "apixel_transparent.gif' width='" + this.iBorderWidth + "' height='1'></td>";
			this.elementsOut += "<td width='" + this.iEnumOffset[ key ] + "'>" + this.strEnumURL[ key ]  + "</td>" + "\n";
			this.elementsOut += "<td width='" + mainTDWidth + "' valign='middle' onclick='javascript: window.location=" + '\"' + this.urls[ key ] + '\"' + "'" + this.tdClass + ">";
			
			//alert( this.myWidth + " : " + this.iEnumOffset[ key ] + " : " + mainTDWidth );
			
			if ( this.urls[ key ] != null )
			{ 

				if ( ( ie4 ) || ( DOMCmp ) ) 
					this.elementsOut += "<a href='" + this.urls[ key ] + "' target='" + this.targets[ key ] + "' " + this.aClass + ">";
				if ( ns4 )	
					this.elementsOut += "<a href='" + this.urls[ key ] + "' target='" + this.targets[ key ] + "' " + this.aClass + " onclick='hideAllMenus( );'>";

			}		
			this.elementsOut += this.elements[ key ] + "\n";
			if ( this.urls[ key ] != null )
				this.elementsOut += "</a>" + "\n";
			this.elementsOut += "</td>" + "\n";
			this.elementsOut += "<td width='10' valign='middle'>" + "\n";
			if ( this.childObjs[ key ] != null ) 
				this.elementsOut += "<img src='" + imgPath + "arr_ffffff.gif'>"; 
			else 
				this.elementsOut += "&nbsp;";
			this.elementsOut += "</td>";
			if ( this.iBorderWidth != 0 )
				this.elementsOut += "<td width='" + this.iBorderWidth + "' bgColor='" + this.strBorderColor + "'><img src='" + imgPath + "apixel_transparent.gif' width='" + this.iBorderWidth + "' height='1'></td>";
			this.elementsOut += "</tr></table>";
	
			this.elementsOut += ( ns4 ) ? "</layer>" : "</div>" + "\n";
		
		}	// for-end
		
//		alert( totInnerHeight );
		
		/* Unterer Rand - Jaded jeah ! */
		
		/* NEU NEU NEU UNTERER RAND */
		
		this.elementsOut += "<div style='position: absolute; top: " + totInnerHeight + "; width: " + this.myWidth + "' >";
		this.elementsOut += "<table border='0' width='" + this.myWidth + "' cellpadding='0' cellspacing='0' height='" + this.iBorderWidth + "' bgColor='green'>" + "\n";
		this.elementsOut += "<tr>";
		this.elementsOut += "<td width='" + this.myWidth + "' bgColor='" + this.strBorderColor + "'><img src='" + imgPath + "apixel_transparent.gif' width='" + this.myWidth + "' height='" + this.iBorderWidth + "'></td>";
		this.elementsOut += "</tr>";
		this.elementsOut += "</table>";
		this.elementsOut += "</div>";
		
		/* NEU NEU NEU UNTERER RAND */
		
		
		
		this.elementsOut += ( ns4 ) ? "</div>" : "</div>" + "\n";			
		

		document.write( this.elementsOut );
		
		/*  type child left and top pos : */
		/* Hier wird gechecked wo das KindElement auf der Seite plaziert werden soll */
		for ( key in this.childObjs )
		{
			if ( this.childObjs[ key ] != null )
			{	
				divElem		= "div" + this.menuName + "Elem" + key;
				childLeft	= eval( this.meLeft + this.myWidth + 1 );
				//if ( childLeft >= window.innerWidth ) alert( "larger" );
				
				if ( ie4 )childTop	= eval( this.meTop + document.all[ divElem ].style.pixelTop );
				if ( ns4 )	childTop	= eval( this.meTop + document.layers[ this.menuName ].document.layers[ divElem ].top );
				if ( DOMCmp ) childTop	= eval( this.meTop + parseInt( document.getElementById( divElem ).style.top ) );
				
				this.childObjs[ key ].setTopLeft( childTop, childLeft );
			}
		}		
	}
	
	function DDMenu_elemChg( pObj, pDivID, pColor, pEvent )
	{
		if ( this.exTimerID != null ) 
		{ 
			window.clearTimeout( this.exTimerID );
			this.exTimerID = null;
		}	
		
		if ( pEvent == 'over' )
		{
			eval( this.objName + ".hideChildren( );" ); //versteckt alle Untermenues 
			if ( pObj != null ) pObj.show( );
			eval( this.objName + ".checkTimeOut( );" );
		} 
		else if ( pEvent == 'out' ) eval( this.objName + ".setTimeOut( );" );
			
		if ( ns4 ) document.layers[ this.menuName ].document.layers[ pDivID ].bgColor = pColor;		
		if ( DOMCmp ) document.getElementById( pDivID ).style.backgroundColor = pColor;
		//if ( ie4 ) document.all[ pDivID ].style.color = pColor;	//	impossible - IE4 bug
	}
	
	function DDMenu_checkTimeOut(  )
	{
		this.clearTimeOut( ); // timer bei sich selbst loeschen
		
		if ( this.ancestor != null ) this.ancestor.clearTimeOut( ); //timer bei Parent loeschen
			
		if ( this.children.length != 0 ) //timer bei children loeschen
		{
			for ( child in this.children )
			{
				tmpObj = eval( this.children[ child ] );
				tmpObj = tmpObj.objName;
				eval( tmpObj + ".clearTimeOut(  );" );
			}
		}
	}
	
	function DDMenu_clearTimeOut( )
	{
		window.clearTimeout( this.timeOut ); 	
	}
	
	function DDMenu_setTimeOut( )
	{
		this.timeOut = window.setTimeout( this.objName + ".hideParent( )", 100 );	//hideAllMenus( )
	}
	/* neu neu neu */
	//function DDMenu_	
	/* ende neu ende neu */
	
	function DDMenu_addChild( pobjChild )
	{
		//alert( "child added ... " + pobjChild );
		enter = true;
		for ( child in this.children )
		{
			if ( this.children[ child ] == pobjChild ) enter = false;
		}
		if ( enter == true ) this.children[ this.children.length ] = pobjChild;
	}

	function DDMenu_show( )
	{	
		this.isOpen = true;
		if ( ie4 ) document.all[ this.menuName ].style.visibility = "visible";
		if ( ns4 ) document.layers[ this.menuName ].visibility = "show";
		if ( DOMCmp ) document.getElementById( this.menuName ).style.display = "block";				
	
		if ( this.ancestor != null ) 
		{
			this.ancestor.isOpen = true;
			if ( this.ancestor.isOpen == true ) this.ancestor.show( );
		}
	}	
	
	function DDMenu_hide( )
	{
		this.isOpen = false;
		if ( ie4 ) document.all[ this.menuName ].style.visibility = "hidden";
		if ( ns4 ) document.layers[ this.menuName ].visibility = "hide";		
		if ( DOMCmp ) document.getElementById( this.menuName ).style.display = "none";
		
		
		
		// Rekursiver Algorithmus, geht von ganz oben bis ganz unten
		if ( this.children.length != 0 ) //Wenn das Menue Kinder hat, werden diese geschlossen
		{
			//alert( "bin ich bin ich bin ich" );
			this.hideChildren( );			
		}
	}
		
	function DDMenu_hideChildren( )
	{
		// rekursiv 
		for ( child in this.children )
		{	 
			tmpObjName = eval ( this.children[ child ] )
			tmpObjName.isOpen = false;
			tmpObjName.hide( );
		}
	}
	
	function DDMenu_hideParent( )
	{
		this.isOpen = false;
		if ( ie4 ) document.all[ this.menuName ].style.visibility = "hidden";
		if ( ns4 ) document.layers[ this.menuName ].visibility = "hide";				
		if ( DOMCmp ) document.getElementById( this.menuName ).style.display = "none";
		
		if ( this.ancestor != null )
		{
			this.ancestor.isOpen = false;
			this.ancestor.hideParent( ); //recursion
		}
		
		this.hideChildren( ); //muss auch noch sein
	}
	
	function DDMenu_getChilds( )
	{
		for ( child in this.children )
		{
			alert( eval( this.children[ child ] + ".objName" ) + ":" + eval( this.children[ child ] + ".isOpen" ) );
		}
	}
	
	function DDMenu_setExTimer( pTimerID )
	{
		this.exTimerID = pTimerID;
	}		
	
/*==============================================================================================================================*/	

	function DDMenuParent( pstrName, pstrObjName ) /* Class 2: Parent Menu */
	{
		this.menuName	= pstrName;
		this.objName	= pstrObjName;		
		this.elements	= [ ]; //creates new Array( );
		this.targets	= [ ];
		this.urls		= [ ];
		this.childObjs	= [ ];
		this.children	= [ ];
	}
	DDMenuParent.prototype = new DDMenu;	// same as extends in Java

/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/		
		
	function DDMenuChild( pstrName, pstrObjName ) /* Class 3: Child Menu */
	{
		this.menuName	= pstrName;
		this.objName	= pstrObjName;
		this.elements	= [ ]; //creates new Array( );
		this.targets	= [ ];
		this.urls		= [ ];
		this.childObjs	= [ ];
		this.children	= [ ];		
		this.setAncestor = DDMenuChild_setAncestor;
	}
	DDMenuChild.prototype = new DDMenu;
	
	/* proprietaere Methoden die nur zum Child Menu gehoeren */	
		function DDMenuChild_setAncestor( pobjAncestor )
		{	
			//alert( this.objName  );
			this.ancestor	= pobjAncestor;
			pobjAncestor.addChild( this.objName );
		}
		
/*=========================================================================================================================*/	
