/*************************************************************************************
   DHTML-NAVIGATION KAZENMAIER
   (C)2003 Metrix Internet Design GmbH
   Version....: 1.0
   Autor......: Sebastian Mordziol <s.mordziol@metrix.de>

   Anleitung:

[] Einen Menüpunkt hinzufügen:
   addMenu( ID, Titel, Url, Zielfenster, Inaktiv );
     ID...........: Kennziffer des Menüpunktes, sollte eine eindeutige Ganzzahl sein
     Titel........: die Beschriftung des Menüpunktes
	 Url..........: Die Url, die bei Klick auf den Menüpunkt aufgerufen werden soll.
	                Optional.
	 Zielfenster..: In welchem Browserfenster die Url geöffnet werden soll.
	                Optional.
					Standard: gleiches Fenster
	Inaktiv.......: Ob dieser menüpunkt inaktiv dargestellt werden soll.
	                Werte: true (inaktiv), false (aktiv)
 
[] Einem Menüpunkt einen Unterpunkt hinzufügen:
   addMenuItem( MenüID, ID, Titel, Url, Zielfenster, Inaktiv  );
     MenüID.......: Kennziffer des Menüpunktes, an den der Unterpunkt angehängt
	                werden soll.
     Titel........: die Beschriftung des Unterpunktes
	 Url..........: Die Url, die bei Klick auf den Unterpunkt aufgerufen werden soll.
	                Optional wenn Inaktiv.
	 Zielfenster..: In welchem Browserfenster die Url geöffnet werden soll.
	                Optional.
					Standard: gleiches Fenster
	Inaktiv.......: Ob dieser menüpunkt inaktiv dargestellt werden soll.
	                Werte: true (inaktiv), false (aktiv)
*/

var loginMessage	=	"Bitte loggen Sie sich ein, um in diesen Bereich zu gehen.";
var kmn				=	false;
var kms				=	false;
var menuActive		=	false;
var itemActive		=	false;

var relpfad = "";

function voidNavigation()
{
	if( !kmn )
	{
		kmn	=	new kMNavigation();
	}
}

function addMenu( mid, mtitle, muri, mtarget, minactive )
{
	if( !kmn )
	{
		kmn	=	new kMNavigation();
	}
	
	kmn.addMenu( mid, mtitle, muri, mtarget, minactive );
}

function addMenuItem( mid, iid, mtitle, muri, mtarget, minactive )
{
	if( !kms )
	{
		kms	=	new kMSubnavigation();
	}
	
	kms.addItem( mid, iid, mtitle, muri, mtarget, minactive );
}

/* Wird noch in onload aufgerufen, machte aber Problemen mit dem etracker,
falls der/das Pixel nicht geladen werden kann. */

function init()
{
}

/* Wird neuerdings direkt in NavigationPart.ascx aufgerufen, ganz am Ende */
function initNeu()
{
	if( !kmn )
	{
		kmn	=	new kMNavigation();
	}
	
	if( !kms )
	{
		kms	=	new kMSubnavigation();
	}
	
	kmn.init();
	kms.init();
}


function getUrl( uri, target )
{
	if( uri.length <= 0 )
		return false;

//	if( typeof( target ) == "undefined" )
// nick 29_08_03 
	if( target == "self" )
	{
		document.location	=	uri;
	}
	else
	{
		window.open( uri, target, "location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes" );
	}
}


function kMNavigation()
{
	// properties
	this.menus			=	new Array();
	this.activeMenu		=	false;
	this.initDone		=	false;
	this.tncEl			=	false;

	// methods
	this.addMenu		=	kmn_addMenu;
	this.display		=	kmn_display;
	this.setActive		=	kmn_setActive;
	this.init			=	kmn_init;
	this.show			=	kmn_show;
}

function kmn_init()
{
	if( menuActive )
	{
		this.setActive( menuActive );
	}

	this.display();
}

function kmn_setActive( mid, activate, execute )
{
	kms.setMenu( mid );

	for( var t=0; t < this.menus.length; t++ )
	{
		if( this.menus[t].id == mid )
		{
			if( typeof( execute ) != "undefined" && execute == true )
			{
				getUrl( this.menus[t].uri, this.menus[t].target );
			}
			
			if( typeof( activate ) != "undefined" && activate == true )
			{
				menuActive	=	this.menus[t].id;
				itemActive	=	false;
				this.display();
				kms.activeItem	=	false;
				kms.display();
				return true;
			}
		
			this.activeMenu	=	this.menus[t];
			return true;
		}
	}
	
	return false;
}

function kmn_show( mid )
{
	if( this.activeMenu.id == mid )
		return true;

	this.setActive( mid );
	this.display();
	kms.display();
}

function kmn_display()
{
	if( !document.getElementById )
		return false;
		
	if( !this.tncEl )
		this.tncEl	=	document.getElementById( "tncontent" );
	
	var html =	'<table cellpadding="0" cellspacing="0" border="0"><tr>';
	
	if( this.menus.length >= 1 )
	{
		for( var l=0; l < this.menus.length; l++ )
		{
			// inaktiver menüpunkt
			if( this.menus[l].inactive )
			{
				html +=	'<td id="mt'+this.menus[l].id+'" class="navI" onmouseover="showTooltip( \'mt'+this.menus[l].id+'\', \''+loginMessage+'\' );" onmouseout="hideTooltip( \'mt'+this.menus[l].id+'\' );">'+this.menus[l].title+'</td>';
			}
			// aktiver menüpunkt
			else if( menuActive == this.menus[l].id )
			{
				html +=	'<td class="navA" onmouseover="kmn.show('+this.menus[l].id+');" onclick="kmn.setActive( '+this.menus[l].id+', true, true );">'+this.menus[l].title+'</td>';
			}
			// over
			else if( this.activeMenu && ( this.menus[l].id == this.activeMenu.id ) )
			{
				html +=	'<td class="navO" onclick="kmn.setActive( '+this.menus[l].id+', true, true );">'+this.menus[l].title+'</td>';
			}
			// normaler menüpunkt
			else
			{
				html +=	'<td class="nav" onmouseover="kmn.show('+this.menus[l].id+');">'+this.menus[l].title+'</td>';
			}
		}
	}
	else
	{
		html +=	'<td class="navV">&nbsp;</td>';
	}

	html += '	</tr>'+
			'</table>';
	
	this.tncEl.innerHTML	=	html;
}

function kmn_addMenu( mid, mtitle, muri, mtarget, minactive )
{
	this.menus[this.menus.length]	=	new kMMenu( mid, mtitle, muri, mtarget, minactive );
}

function kMMenu( mid, mtitle, muri, mtarget, minactive, iid )
{
	this.id			=	mid;
	this.iid		=	iid,
	this.title		=	mtitle;
	this.uri		=	muri;
	this.target		=	mtarget;
	this.inactive	=	minactive;
}





function kMSubnavigation()
{
	this.items		=	new Array();
	this.container	=	false;
	this.activeItem	=	false;
	this.mid		=	false;
	
	this.addItem		=	kms_addItem;
	this.display		=	kms_display;
	this.displayEmpty	=	kms_displayEmpty;
	this.setActive		=	kms_setActive;
	this.init			=	kms_init;
	this.setMenu		=	kms_setMenu;
	this.countItems		=	kms_countItems;
}

function kms_setMenu( mid )
{
	this.mid	=	mid;
	
	this.display();
}

function kms_init()
{
	if( itemActive )
	{
		this.setActive( itemActive );
	}

	if( menuActive )
	{
		this.display();
	}
	else
	{
		this.displayEmpty();
	}
}

function kms_setActive( iid, execute )
{
	for( var t=0; t < this.items.length; t++ )
	{
		if( this.items[t].id == this.mid && this.items[t].iid == iid )
		{
			if( typeof( execute ) != "undefined" && execute == true )
			{
				getUrl( this.items[t].uri, this.items[t].target );
			}
			
			this.activeItem	=	this.items[t];
			menuActive		=	kmn.activeMenu.id;
			kmn.display();
			return true;
		}
	}
	
	return false;
}

function kms_addItem( mid, iid, mtitle, muri, mtarget, minactive )
{
	this.items[this.items.length]	=	new kMMenu( mid, mtitle, muri, mtarget, minactive, iid );
}

function kms_displayEmpty()
{
	if( !this.container )
		this.container	=	document.getElementById( "sncontent" );

	var html	=	''+
				'<table width="100%" cellpadding="0" cellspacing="0" border="0">'+
				'	<tr valign="top">'+
				'		<td class="snav" nowrap="nowrap" style="cursor:auto;">&nbsp;</td>'+
				'	</tr>'+
				'	<tr>'+
				'		<td class="snavb"><img src="'+relpfad+'img/misc/px.gif" width="1" height="4" alt="" border="0" /></td>'+
				'	</tr>'+
				'</table>';

	this.container.innerHTML	=	html;
}

function kms_countItems()
{
	if( !this.mid )
		return -1;

	var count	=	0;
	
	for( var g=0; g < this.items.length; g++ )
	{
		if( this.items[g].id != this.mid )
		{
			continue;
		}
		
		count++;
	}
	
	return count;
}

function kms_display( iid )
{
	if( !this.container )
		this.container	=	document.getElementById( "sncontent" );

	if( this.countItems() < 1 )
	{
		this.displayEmpty();
		return true;
	}
	
	var html	=	''+
				'<table width="100%" cellpadding="0" cellspacing="0" border="0">'+
				'	<tr valign="top">';

	for( var g=0; g < this.items.length; g++ )
	{
		if( this.items[g].id != this.mid )
			continue;
	
		if( this.items[g].inactive )
		{
			html += '<td class="snavI" nowrap="nowrap" onmouseover="showTooltip( \'st'+this.items[g].iid+'\', \''+loginMessage+'\' );" onmouseout="hideTooltip( \'st'+this.items[g].iid+'\' );"><div id="st'+this.items[g].iid+'"></div>'+this.items[g].title+'</td>';
		}
		// aktiver punkt
		else if( kmn.activeMenu && kmn.activeMenu.id == menuActive && this.activeItem && ( this.items[g].iid == this.activeItem.iid ) )
		{
			html += '<td class="snavA" nowrap="nowrap">'+this.items[g].title+'</td>';
		}
		else if( typeof( iid ) != "undefined" && this.items[g].iid == iid )
		{
			html += '<td class="snavO" nowrap="nowrap" onmouseout="kms.display();" onclick="kms.setActive( '+this.items[g].iid+', true );">'+this.items[g].title+'</td>';
		}
		else
		{
			html += '<td class="snav" nowrap="nowrap" onmouseover="kms.display( '+this.items[g].iid+' );" onclick="kms.setActive( '+this.items[g].iid+', true );">'+this.items[g].title+'</td>';
		}
	}
	
	html +=	''+
				'		<td width="100%"><img src="'+relpfad+'img/misc/px.gif" width="1" height="1" border="0" /></td>'+
				'	</tr>'+
				'	<tr class="snavb">';
				
	for( var h=0; h < this.items.length; h++ )
	{
		if( this.items[h].id != this.mid )
			continue;

		if( ( kmn.activeMenu && kmn.activeMenu.id == menuActive && this.activeItem && ( this.items[h].iid == this.activeItem.iid ) ) || ( typeof( iid ) != "undefined" && this.items[h].iid == iid ) )
		{
			html +=	'<td class="snavbA">'+
					'	<table width="100%" cellpadding="0" cellspacing="0" border="0">'+
					'		<tr valign="top">'+
					'			<td><img src="'+relpfad+'img/misc/px-000000.gif" width="10" height="1" alt="" border="0" style="margin-top:2px;" /></td>'+
					'			<td align="right"><img src="'+relpfad+'img/misc/px-000000.gif" width="10" height="1" alt="" border="0" style="margin-top:2px;" /></td>'+
					'		</tr>'+
					'	</table>'+
					'</td>';
		}
		else
		{
			html +=	'<td><img src="'+relpfad+'img/misc/px.gif" width="1" height="4" alt="" border="0" /></td>';
		}
	}

	html +=	''+
				'		<td><img src="'+relpfad+'img/misc/px.gif" width="1" height="4" border="0" /></td>'+
				'	</tr>'+
				'</table>';

	this.container.innerHTML	=	html;
}

