/* ======================================================================
DESC: global functions for javascript menu by Manfred Gschweidl

PLATFORMS: Internet Explorer >= 4, Netscape >= 4 and 6, Opera >= 5

USAGE NOTES: this are only basic funtions for all browsers

COPYRIGHT: Manfred Gschweidl / 10.5.2001
====================================================================== */
/* hier werden globale definitionen getroffen , vorallem der browser IE und NE */
var picturePressed = new Array();

function changePicture(src, imgname)
{
	eval("document."+imgname+".src='"+src+"';");
}
function mouseOverOutPicture(src, imgname) {
	if(picturePressed[0] != imgname)
	{
		changePicture(src, imgname);
	}
}
function clickOnPicture(srcPassive, srcPressed, imgname) {
	if(picturePressed[0] != imgname) {
		if(picturePressed.length > 0) {
			changePicture(picturePressed[1], picturePressed[0]);
		}
		if(srcPressed != ""){
			picturePressed[0] = imgname;
			picturePressed[1] = srcPassive;
			changePicture(srcPressed, imgname);
		} else {
			picturePressed = new Array();
		}
	}
}
function toggleSection(grID, grafikName, clIc, opIc) {
	for(var w=0; w < navigation.groups.length; w++)
	{
		if(navigation.groups[w].groupID == grID)
		{
			if(navigation.groups[w].sectionStatus == 'open')
			{
				navigation.groups[w].hideGroup();
				if (clIc != '') changePicture(clIc, grafikName);
				navigation.groups[w].sectionStatus = '';
			} else {
				navigation.groups[w].showGroup();
				if (opIc != '') changePicture(opIc, grafikName);
				navigation.groups[w].sectionStatus = 'open';
			}
			break;
		}
	}
}
function hideGroup()
{
	/*beim zuklappen werden all inneren sections auch zugeklappt, wenn auskommentiert
	bleibt status erhalten*/
/*	for(t=0; t < this.entries.length; t++)
	{
		if(this.entries[t].subGroupID != '')
		{
			for ( var s=0; s<navigation.groups.length; s++ )
			{
   			if(navigation.groups[s].groupID == this.entries[t].subGroupID)
   			{
					this.entryCounter = t;
					navigation.groups[s].hideGroup();
					t = this.entryCounter;				
   			}
			}
		}
	}*/
	
/* Anfang Layersichtbarkeit */
	/* this.entries is only needed for NE 4 function and has no impact on functions for IE or NE 6 */
	this.hideGroupLayer();
/* Ende Positionsverschiebung */
}
function getSectionImageName(name)
{
	return "SI"+entryIdPrefix+name;
}
function getHTMLEntry()
{
	/* onClick event fehlt noch -  onClick="changePicture('+active+')" */
	var code = '';
	var tmpSectionIconWidth = 0;
	var sectionImageName = getSectionImageName(this.name);
	
	if (this.subGroupID != '')
	{
		var onClickCode = "toggleSection('"+this.subGroupID+"', '"+sectionImageName+"', '"+this.closedIcon+"', '"+this.openedIcon+"' )";
	} else {
		var onClickCode = "";
	}
	
	if (this.prevText!='') code = code + new String(this.prevText);
	if(this.entryText != '')
	{
		code = code + new String('<a href="'+this.URL+'"');
		if( openSubGroupOnClick ) code = code + new String(' onClick="'+onClickCode+'"');
		if (this.name!='') code = code + new String(' Name="'+this.name+'"');
		if (this.target!='') code = code + new String(' target="'+this.target+'">');
		code = code + new String(this.entryText+'</a>');
	} else {
		if (this.activePicture=='' && this.passivePicture=='') {
			code = code + new String('<a href="'+this.URL+'"');
			if (this.name!='') code = code + new String(' Name="'+this.name+'"');
			if( openSubGroupOnClick ) code = code + new String(' onClick="'+onClickCode+'"');
			if (this.target!='') code = code + new String(' target="'+this.target+'">');
		} else {
			code = code + new String('<a href="'+this.URL+'"');
			if (this.name!='') code = code + new String(' Name="'+this.name+'"');
			if (this.target!='') code = code + new String(' target="'+this.target+'"');
			if (this.activePicture!='' && this.passivePicture!='') {
				if (this.pressedPicture!='') {
					var pressed = new String("'"+this.passivePicture+"', '"+this.pressedPicture+"', 'img"+this.name+"'");
					if( openSubGroupOnClick ) code = code + new String(' onClick="clickOnPicture('+pressed+');'+onClickCode+'"');
					else code = code + new String(' onClick="clickOnPicture('+pressed+')"');
				} else {
					var pressed = new String("'"+this.passivePicture+"', '', 'img"+this.name+"'");
					if( openSubGroupOnClick ) code = code + new String(' onClick="clickOnPicture('+pressed+');'+onClickCode+'"');
					else code = code + new String(' onClick="clickOnPicture('+pressed+')"');
				}
				var active = new String("'"+this.activePicture+"', 'img"+this.name+"'");
				var passiv = new String("'"+this.passivePicture+"', 'img"+this.name+"'");
				code = code + new String(' onMouseOver="mouseOverOutPicture('+active+')" onMouseOut="mouseOverOutPicture('+passiv+')"');			
			}
			code = code + new String('><img src="'+this.passivePicture+'" name="img'+this.name+'" alt="'+this.name+'" border=0></a>');
		}
	}
	if (this.pastText) code = code + new String(this.pastText);
/* hier dann überprüfung ob, "entry" eine subgroup hat, aber gleichzeitig verhinderung */
/* des nochmaligen aufrufes durch die "getGroupHTML" */
	if (this.subGroupID != '')
	{
		for(e=0; e < navigation.groups.length; e++)
		{
			if(navigation.groups[e].groupID == this.subGroupID)
			{
				/*code fuer pfeile zu beginn*/
				if(this.openedIcon != '' && this.closedIcon != '')
				{
					code = new String('</A>') + code;
//					sectionImageName = getSectionImageName(this.name);
					var tmpCode = "toggleSection('"+this.subGroupID+"', '"+sectionImageName+"', '"+this.closedIcon+"', '"+this.openedIcon+"' )";
					if(navigation.groups[e].sectionStatus=='open')
					{
						code = new String('<img src="'+this.openedIcon+'" name="'+sectionImageName+'" border=0>') + code;
					} else {
						code = new String('<img src="'+this.closedIcon+'" name="'+sectionImageName+'" border=0>') + code;
					}
					code = new String('<A HREF="#" onClick="'+tmpCode+'; return false">') + code;
				}
				/*ende code*/
				code = code + navigation.groups[e].getHTML();
				break;
			}
		}
		if (this.hSpacer!='') code = new String('<img src="'+this.hSpacer+'" width='+this.hSpacerWidth+' height=1 border=0>') + code;
	} else {
		tmpSectionIconWidth = Number(this.hSpacerWidth)+sectionIconWidth;
		if (this.hSpacer!='') code = new String('<img src="'+this.hSpacer+'" width='+tmpSectionIconWidth+' height=1 border=0>') + code;
	}
	/*spacer werden vor code eingefuegt wegen der pfeilberechnung*/
	if (this.vSpacer!='') code = new String('<img src="'+this.vSpacer+'" width=1 height='+this.vSpacerHeight+' border=0>') + code;
	code = '<div id="'+entryIdPrefix+this.name+'" Class="showing">' + code;
	
	code = code + '</div>';
	return code;	
}
function entry (name, link, target, cIcon, oIcon, prevText, hSpacer, hSpacerWidth, vSpacer, vSpacerHeight, aPicture, pPicture, prPicture, entryText, pastText)
{
	this.name = name;
	this.URL = link;
	this.target = target;
	this.prevText = prevText;
	this.pastText = pastText;
	this.entryText = entryText;
	this.activePicture = aPicture;
	this.passivePicture = pPicture;
	this.pressedPicture = prPicture;
	this.subGroupID = '';
	this.closedIcon = cIcon;
	this.openedIcon = oIcon;
	if (hSpacer != '')
	{ this.hSpacer = hSpacer;
	  this.hSpacerWidth = hSpacerWidth;
	} else {
	  this.hSpacer = 0;
	  this.hSpacerWidth = 0;
	}
	if (vSpacer != '')
	{ this.vSpacer = vSpacer;
	  this.vSpacerHeight = vSpacerHeight;
	} else {
	  this.vSpacer = 0;
	  this.vSpacerHeight = 0;
	}
	this.getHTML = getHTMLEntry;
}
function addEntry(name, link, tar, cI, oI, ic, hSp, hSpW, vSp, vSpH, aP, pP, prP, eT, pT)
{
	this.entries[this.entries.length] = new entry(name, link, tar, cI, oI, ic, hSp, hSpW, vSp, vSpH, aP, pP, prP, eT, pT);
}
function group(groupID, referenceGroup, iconB, iconA, status, level)
{
	this.groupTest = '';
	this.sectionStatus = status;
	this.groupID = groupID;
	this.refGroup = referenceGroup;
	this.iconBefore = iconB;
	this.iconAfter = iconA;
	this.entries = new Array();
	this.addEntry = addEntry;
	this.getHTML = getGroupHTML;
	this.calculatedHTML = 0; /*status ob html bereits gerechnet wurde wenn durch getEntryHTML bereits verwendet*/
	this.entryCounter = 0;
	this.hideGroup = hideGroup;
	this.hideGroupLayer = hideGroupLayer;
	this.showGroup = showGroup;
	this.hierarchyLevel = level;
}
function addGroup(groups, id, refGroup, icB, icA, stat)
{
	if (groups.length > 0) {
		groups[refGroup].entries[(groups[refGroup].entries.length-1)].subGroupID = id;
	}
	//code for calculating the level
	
	//end code for calculating the level
	groups[groups.length] = new group(id, refGroup, icB, icA, stat);
}
function getHTMLNavigation()
{
	var code = '';
	for (n=0; n < this.groups.length; n++)
	{
		code = code + this.groups[n].getHTML();
	}
	return code;
}

function createPage()
{
	init();
//	this.navigation = new navigation();
//this.navigation = navigation;
	return navigation.getHTML();
}
/*HTML-Code generieren*/
var navigation = new navigation();
var menu = createPage();

function closeOtherGroups(grpId)
{
	//get next higher group in hierarchy level => "activeGroupRef"
	for(var grpCounter=0; grpCounter < navigation.groups.length; grpCounter++)
	{
		if(grpId == navigation.groups[grpCounter].groupID)
		{
			var activeGroupRef = navigation.groups[grpCounter].refGroup;
			break;
		}
	}

	for(var grpCounter=0; grpCounter < navigation.groups.length; grpCounter++)
	{
		if(navigation.groups[grpCounter].refGroup == activeGroupRef  && grpId != navigation.groups[grpCounter].groupID && navigation.groups[grpCounter].sectionStatus == 'open')
		{
			for(var entryCounter=0; entryCounter < navigation.groups[activeGroupRef].entries.length; entryCounter++)
			{
				if(navigation.groups[grpCounter].groupID == navigation.groups[activeGroupRef].entries[entryCounter].subGroupID)
				{
					tEntry = navigation.groups[activeGroupRef].entries[entryCounter];
					toggleSection(tEntry.subGroupID, getSectionImageName(tEntry.name), tEntry.closedIcon, tEntry.openIcon);
				}
			}
			break;
		}
	}
}


