/*
CKV20021127 Erweiterung Terhuerne; ID und sprache speichern
ckv20021226 CSS - Stil einbauen
spacer unter menues durch black.gif ersetzt länge noch unklar (140px?)

hintergrundbild im Menue geaendert!!
*/

function MM_preloadImages() 
{ //v3.0
	var d=document; 
	if(d.images)
	{ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0)
		{ 
			d.MM_p[j]=new Image; 
			d.MM_p[j++].src=a[i];
		}
	}
}

function MM_swapImgRestore() 
{ //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) 
{ //v4.01
	var p,i,x;	
	if(!d) d=parent.menue.document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); 
	return x;
}

function MM_swapImage() 
{ //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x; 
			if(!x.oSrc) x.oSrc=x.src; 
			x.src=a[i+2];
		}
}

function Menu(parentMenu,name,script,ebene,target,id,firstlevelid)	//CKV20021127 ID ergänzt
{
 this.items=new Array();
 this.menuEbene=ebene;
 this.menuId=id;		//CKV20021127
 this.menuText=name;
 this.menuParent=parentMenu;
 this.menuScript=script;
 this.menuFirstlevelid = firstlevelid;
 if (target) this.menuTarget=target; else this.menuTarget="";
 this.draw=Draw;
 if (parentMenu != null) parentMenu.items[parentMenu.items.length]=this;
 return this;
}

function Ebene(ib,ibt,ab,abt,width,ident,insertMode,bgcolor,bgbild)
{
 this.aButton=ab; // CSS-Style
 this.aLink=abt; // CSS-Style
 this.Button=ib; // CSS-Style
 this.Link=ibt; // CSS-Style
 if (insertMode) this.nextMenuInsertMode=insertMode; else this.nextMenuInsertMode="inline";//inline,behind	Anordung des nächsten Menüs
 if (ident) this.buttonIdent=ident; else this.buttonIdent=0;	 //linker Einzug des Buttons
 this.buttonWidth=width;	// Breite des Buttons ohne Spot
 if (bgcolor) this.bgColor=bgcolor; else this.bgColor="";	//Hintergrundfarbe gesamte Ebene
 if (bgbild) this.bgBild=bgbild; else this.bgBild="";	//Hintergrundbild gesamte Ebene
 this.aSpot=""; // CSS-Style
 this.Spot=""; // CSS-Style
 this.activeContentSpot=""; //text oder HTML
 this.inactiveContentSpot=""; //text oder HTML
 this.spotAlign="left";	//Ausrichtung des Spots
 this.spotWidth=0;	// Breite des Spots
 this.buttonSpacing=0;	// Abstand zwischen den Buttons
 this.topIdent=0;	// Oberer Abstand der Menuebene
 this.bottomIdent=0;	// Unterer Abstand der Menuebene
 this.spacerColor="";	//Farbe für den Zwischenabstand
 this.paddingColor=""; //Farbe für	Menüabstände
 this.visibility=true;	//Sichtbarkeit der Ebene
 this.draw=Draw;	
 this.defineSpot=Spotdefinition;
 this.defineSpaces=Spacedefinitions;
}

function MENUGLOBALS()
 {
	this.width=155;
	this.sprache='DE';		//CKV20021127 ergänzt
	this.bild="clear.gif";
	this.ebenenID=null;//intern
	this.menuFrame=""; //intern
	this.mainFrame="main";
	this.root=null; //intern
	this.ebene=new Array(); // Layoutinformationen zu den einzelnen Menuebenen
	this.displaySpot="allways";	//never, allways, present	Darstellungsmodus des Spots
	this.displayActiveButton="present"; //never, allways, present	Darstellungsmodus des aktuellen Buttons
	this.spacerSpot=true;
	this.update=true; //intern
	this.lastScript=""; //intern
	this.msie4=false; //intern
	this.minEbenen=1;
	this.popupParam="width=640";
	this.sitemapStart="<html><head><title>SITEMAP</title></head><body>";
	this.sitemapFinal="</body></html>";
	this.styleFile = '';	// ckv20021226 CSS - Stil einbauen
	this.header = "";
 }	

function Spotdefinition(width,as,is,ac,ic,align)
 { 
	if (as) this.activeSpot=as;
	if (is) this.inactiveSpot=is;
	if (ac) this.activeContentSpot=ac; 
	if (ic) this.inactiveContentSpot=ic; 
	if (width) this.spotWidth=width; 
	if (align) this.spotAlign=align;
 }
 
function Spacedefinitions(sw,sc,ao,au,ac)
{
 this.buttonSpacing=sw; 
 if (ao) this.topIdent=ao;
 if (au) this.bottomIdent=au;
 if (sc) this.spacerColor=sc;
 if (ac) this.paddingColor=ac; 
} 

var MGlobals=new MENUGLOBALS();
 
function Draw()
{
	var m=this;
	if ((m.menuScript!='') && !MGlobals.update) 
	{
		var ziel=(m.menuTarget=='') ? MGlobals.mainFrame : m.menuTarget;
		if (ziel==MGlobals.mainFrame) 
			eval("parent."+ziel+'.location.href="'+m.menuScript+'"');
		else
		{
			MGpopupfenster=open(m.menuScript,ziel,MGlobals.popupParam);
		}
	}
	MGlobals.update=false;
	MGlobals.ebenenID=new Array();
	while (m.menuParent!=null)
	{
		var a=m;
		m=m.menuParent;
		for (b=0;b<m.items.length;b++) 
			if (m.items[b]==a) 
			{	var h = '<body STYLE="background-image:url(gifs/hg_links.jpg);background-repeat:repeat-n;" width="155"><div style="position:absolute; top: 100px; left: 0px;">';
			 	MGlobals.header = h.replace("hg_links.jpg", b + 'hg_links.jpg');
				MGlobals.ebenenID[MGlobals.ebenenID.length]=b;}
	}
	MGlobals.ebenenID.reverse(); 
	setTimeout("drawMenu()",10);
}

function drawMenu()
{
	var tableEnd='</table></td></tr>\n';
	var out=parent.frames[MGlobals.menuFrame].document;

	function DrawM(m,mName,richtigerPfad)
	{
		if (navigator.appVersion.indexOf("MSIE 4.")!=-1 && MGlobals.msie4==false)
		{alert("Warnung!\n\nSie benutzen ein sehr alte Version des Internet Explorers.\nEs könnten einige Schwierigkeiten mit dieser Version auftreten.\nWir empfehlen Ihnen auf eine aktuelle Version umzusteigen.");MGlobals.msie4=true;}
		//alert('Neuer Draw in Ebene: '+m.menuEbene+'; '+m.menuText);
		var e=MGlobals.ebene[m.menuEbene+1];
		var restWidth=MGlobals.width-e.buttonIdent-e.spotWidth-e.buttonWidth;
		var tableHead='<tr><td'+(e.bgColor!='' ? ' bgcolor="'+e.bgColor+'"':'')+(e.bgBild!=''? ' background="'+e.bgBild+'"':'')+'>'+'<table width="100%" cellpadding="0" cellspacing="0" border="0" background="gifs/clear.gif">\n';
		//alert('Begin Ebene: '+m.menuEbene);
				
		if (m.items.length !=0) 
		{		
			if (e.visibility) out.write(tableHead);
			var tableOpend=true;
			// Oberer Menu-Abstand
			if (e.topIdent>0)
			{
				s='<tr>';color=(e.paddingColor!='') ? ' bgcolor="'+e.paddingColor+'"' : '';
				spot=(e.spotWidth != 0) ? '<td'+(MGlobals.spacerSpot?color:'')+'><img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="'+e.topIdent+'"></td>' : '';
				s+=(e.buttonIdent != 0) ? '<td><img src="'+MGlobals.bild+'" width="'+e.buttonIdent+'" height="'+e.topIdent+'"></td>' : '';
				if (e.spotAlign=='left') s+=spot;
				s+='<td'+color+'><img src="'+MGlobals.bild+'" width="'+e.buttonWidth+'" height="'+e.topIdent+'"></td>';
				if (e.spotAlign=='right') s+=spot;
				s+=(restWidth != 0) ? '<td><img src="'+MGlobals.bild+'" width="'+restWidth+'" height="'+e.topIdent+'"></td>' : '';
				s+='</tr>\n';
				if (e.visibility) out.write(s);
			}
			for (var a=0;a<m.items.length;a++)
			{
				// Verwendete Klassen berechnen
				var classSpot=(e.Spot!='') ? ' style="'+e.Spot+'"' : '';
				var classButton=(e.Button!='') ? ' style="'+e.Button+'"' : '';
				var classButtonText=(e.Link!='') ? ' style="'+e.Link+'"' : '';
				var spotContent=(e.inactiveContentSpot!='') ? spotContent=e.inactiveContentSpot :'<img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="1" border="0">';
				var knoten=false;
				var href='"javascript:'+mName+a+'].draw()"'
				if ((m.menuEbene<MGlobals.ebenenID.length) && (MGlobals.ebenenID[m.menuEbene]==a) && richtigerPfad) 
				{
					knoten=true;
					if (m.menuEbene+1==MGlobals.ebenenID.length) // present
					{
						classSpot=(e.aSpot!='') ? ' style="'+e.aSpot+'"' : '';
						spotContent=(e.activeContentSpot!='') ? e.activeContentSpot : '<img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="1" border="0">';
						classButton=(e.aButton!='') ? ' style="'+e.aButton+'"' : '';
						classButtonText=(e.aLink!='') ? ' style="'+e.aLink+'"' : '';
					}
					if (MGlobals.displaySpot=="never") 
					{
						classSpot=(e.Spot!='') ? ' style="'+e.Spot+'"' : '';
						spotContent=(e.inactiveContentSpot!='') ? e.inactiveContentSpot : '<img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="1" border="0">';
					}
					if (MGlobals.displaySpot=="allways") 
					{
						classSpot=(e.aSpot!='') ? ' style="'+e.aSpot+'"' : '';
						spotContent=(e.activeContentSpot!='') ? e.activeContentSpot : '<img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="1" border="0">';
					}
					if (MGlobals.displayActiveButton=="never") 
					{
						classButton=(e.Button!='') ? ' style="'+e.Button+'"' : '';
						classButtonText=(e.Link!='') ? ' style="'+e.Link+'"' : '';
					}
					if (MGlobals.displayActiveButton=="allways") 
					{
						classButton=(e.aButton!='') ? ' style="'+e.aButton+'"' : '';
						classButtonText=(e.aLink!='') ? ' style="'+e.aLink+'"' : '';
					}
				}
				
				//	Start zusammensetzung des Buttons
				s='<tr>';
				//CKV20021127
				/*
				wir ersetzen den img_src des aktiven Pointers mit text "pfeil1.gif" durch 
				menuFirstlevelid + pfeil1.gif
				*/
				if (spotContent.search('pfeil1.gif') != -1)
					spotContent = spotContent.replace("pfeil1.gif", m.items[a].menuFirstlevelid + 'pfeil1.gif');
				spot=(e.spotWidth != 0) ? '<td width="'+e.spotWidth+'"'+classSpot+'><a href='+href+classButtonText+'>'+spotContent+'</a></td>' : '';
				s+=(e.buttonIdent != 0) ? '<td width="'+e.buttonIdent+'"><img src="'+ MGlobals.bild+'" width="'+e.buttonIdent+'" height="1"></td>' : '';
				if (e.spotAlign=='left') s+=spot;
		//CKV20021127			 
		s+='<td width="'+e.buttonWidth+'"'+classButton+'><a href='+href+classButtonText+'>'+m.items[a].menuText+'</a></td>';
				//s+='<td width="'+e.buttonWidth+'"'+classButton+'><a onMouseOver="parent.MM_swapImage(\'m'+ m.items[a].menuId+'\',\'\',\'modules/button.php?over=1&sprache='+MGlobals.sprache+'&id='+m.items[a].menuId+'\',0)" onMouseOut="parent.MM_swapImgRestore()" href='+href+classButtonText+'><img border="0" +id="m'+m.items[a].menuId+'" name="m'+m.items[a].menuId+'" src="modules/button.php?over=0&sprache='+MGlobals.sprache+'&id='+m.items[a].menuId+'"></a></td>';//CKV20021127			 
		
				if (e.spotAlign=='right') s+=spot;
					s+=(restWidth != 0) ? '<td width="'+restWidth+'"><img src="'+MGlobals.bild+'" width="'+restWidth+'" height="1"></td>' : '';
					s+='</tr>\n';
				if (e.visibility) out.write(s);
				// Bei inline-Untermenü aufrufen
				var allowSpacer=true;
				if ((knoten && (e.nextMenuInsertMode=="inline")) || ((m.menuEbene+1)<MGlobals.minEbenen))
				{
					if (e.visibility) {out.write(tableEnd);tableOpend=false;} //ckv20021226 vermeintlicher (!) Fehler 
					allowSpacer=!DrawM(m.items[a],mName+a+'].items[',knoten);
					if (a!=m.items.length-1) {if (e.visibility) out.write(tableHead);tableOpend=true;}
				}
				// Zwischenabstand zwischen Buttons zeichnen
				if ((a!=(m.items.length-1)) && (e.buttonSpacing>0) && allowSpacer)
				{
					s='<tr>';color=(e.spacerColor!='') ? ' bgcolor="'+e.spacerColor+'"' : '';
					spot=(e.spotWidth != 0) ? '<td'+(MGlobals.spacerSpot?color:'')+'><img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="'+e.buttonSpacing+'" border="0"></td>' : '';
					s+=(e.buttonIdent != 0) ? '<td><img src="'+MGlobals.bild+'" width="'+e.buttonIdent+'" height="'+e.buttonSpacing+'" border="0"></td>' : '';
					if (e.spotAlign=='left') s+=spot;
					s+='<td'+color+'><img src="'+MGlobals.bild+'" width="'+e.buttonWidth+'" height="'+e.buttonSpacing+'" border="0"></td>';
					if (e.spotAlign=='right') s+=spot;
					s+=(restWidth != 0) ? '<td><img src="'+MGlobals.bild+'" width="'+restWidth+'" height="'+e.buttonSpacing+'" border="0"></td>' : '';
					s+='</tr>\n';
					if (e.visibility) out.write(s);
				} 
			}// ENDE for-schleife
			// Unteren Menü-Abstand 
			if (e.bottomIdent>0)
			{
				if (!tableOpend) {out.write(tableHead);tableOpend=true;}
				s='<tr>';color=(e.paddingColor!='') ? ' bgcolor="'+e.paddingColor+'"' : '';
				spot=(e.spotWidth != 0) ? '<td'+(MGlobals.spacerSpot?color:'')+'><img src="'+MGlobals.bild+'" width="'+e.spotWidth+'" height="'+e.bottomIdent+'" border="0"></td>' : '';
				s+=(e.buttonIdent != 0) ? '<td><img src="'+MGlobals.bild+'" width="'+e.buttonIdent+'" height="'+e.bottomIdent+'" border="0"></td>' : '';
				if (e.spotAlign=='left') s+=spot;
//ckv20021226				s+='<td'+color+'><img src="'+MGlobals.bild+'" width="'+e.buttonWidth+'" height="'+e.bottomIdent+'" border="0"></td>';
				s+='<td><img src="gifs/black.gif" width="1" height="'+e.bottomIdent+'" border="0"></td>';//ckv20021226				
				if (e.spotAlign=='right') s+=spot;
				s+=(restWidth != 0) ? '<td><img src="'+MGlobals.bild+'" width="'+restWidth+'" height="'+e.bottomIdent+'" border="0"></td>' : '';
				s+='</tr>\n';
				if (e.visibility) out.write(s);
			} 
			if (tableOpend && e.visibility) out.write(tableEnd);
			if ((e.nextMenuInsertMode=="behind") && (m.menuEbene<MGlobals.ebenenID.length))
			{ // nun in die nächsten Tiefen abtauchen
				DrawM(m.items[MGlobals.ebenenID[m.menuEbene]],mName+MGlobals.ebenenID[m.menuEbene]+'].items[',true);
			}
			return true;
		}//ENDE if
		return false;
	} // Ende UnterFunktion
	
	out.open();
	out.write('<html><head><title>Strait Menu 2001</title>');
	/* ckv20021226 CSS - Stil einbauen */
	if (MGlobals.styleFile != '') out.write('<link rel="stylesheet" href="'+MGlobals.styleFile+'" type="text/css">'); 
	/* Ende ckv20021226*/
	out.write('</head>\n'+MGlobals.header+'\n<table width="'+MGlobals.width+'" cellpadding="0" cellspacing="0" border="0">\n');
	DrawM(MGlobals.root,"parent.MGlobals.root.items[",true);
	out.write('</table>'+MGlobals.footer+'</html>');
	out.close();
}

function initMenu(root,frame)
{
	MGlobals.menuFrame=frame;
	MGlobals.root=root;
	var a=MGlobals.ebene[MGlobals.ebene.length]=new Ebene("","","","",0,0,"","");
}

// Update-Funktion

function updateMenu()
{ 
 var l=parent.frames[MGlobals.mainFrame].location.pathname+parent.frames[MGlobals.mainFrame].location.search;
 var rootpath=parent.location.pathname;

/*ckv20031105*/
while (true)	//wir verkürzen auf ein Verzeichnis
{ 
var character = rootpath.substr(rootpath.length-1,1)
var code = character.charCodeAt(0);
if (code!= 47) 
	rootpath = rootpath.substring(0,rootpath.length - 1);
	else break;
}
/*ckv20031105*/

 if (l.indexOf(rootpath)==0) l=l.substring(rootpath.length,l.length);

 var m=null;

 function durchsuchen(mo)
  {
   if (mo.menuScript==l) {m=mo;return true;}  //wir haben einen Treffer
   else 
	 	if (mo.items.length > 0) 
			for (var a=0;a<mo.items.length;a++) if (durchsuchen(mo.items[a])) return true;
	return false;
  }
 if (l!=MGlobals.lastScript) if (durchsuchen(MGlobals.root)) {MGlobals.update=true;m.draw();}
}

function makeSitemap()
{
	/*
	function drawSitemap(m,einrueckung,win)
		{
			var s='';var a=einrueckung;
			var ziel=(m.menuTarget=='') ? MGlobals.mainFrame : m.menuTarget;
			while (a-->0) s+="&nbsp;";
			win.document.writeln(s+"<a href='"+m.menuScript+"' target='"+ziel+"' onclick='window.close()'>"+m.menuText+"</a><br>");
			a=0;
			while (a++<m.items.length) drawSitemap(m.items[a-1],einrueckung+3,win);
		}
	var a=0;
	sm=open("","SiteMap","width=240");
	sm.document.open();sm.document.writeln(MGlobals.sitemapStart);
	while (a<MGlobals.root.items.length) {drawSitemap(MGlobals.root.items[a],0,sm);a++;}
	sm.document.writeln(MGlobals.sitemapFinal);sm.document.close(); */
}
