//-----------------------------------------------------------------------------
//	Project:	NOSE WEB NAVIGATOR
//	Authors:	Stefan Tan, Walter Stulzer, Alexandra Papadopoulos
//	(c):		1998-1999, Nose GmbH Interactive Media
//	(c):		1999-2000, Perspectix-Nose AG, Digital Business Intelligence
//	(c):		2001, Nose Applied Intelligence
//	History:
//	[04/99]		Rel. 1.0.0 [WS/AP]
//	[04/99]		Rel. 1.0.1 'Debugging Programmlogik, NEW: Powerfunctions' [WS]
//	[04/99]		Rel. 1.0.2 'Kompatibilitaet HTML 3.0' [WS]
//	[04/99]		Rel. 1.0.3 'Reaktion des Menues auf Links im Hauptfenster' [WS]
//	[01/00]		Rel. 1.0.4 'generische Ordnungsnummer, oparent' [WS]
//	[01/00]		Rel. 1.1.0 'generischer expanded-Wert' [WS/MH/NS]
//	[02/00]		Rel. 1.1.1 'Neuer Menueintrag' [WS]
//	[07/00]		Rel. 1.1.2 'Korrektur für Mac-Explorer 5.0' [ST]
//	[08/00]		Rel. 2.0.0 'CSS-capability' [ST]
//	[03/01]		Rel. 2.0.1 'Rewriting refresh(), debugging' [ST/SA]
//	[12/01]		Rel. 2.1.0 'Codewashing' [ST/FS]
//  [01/03]	    Rel. 2.3.0 'Identifizierung des aktuellen Eintrages anhand der Order, 
//							"none" Einträge nicht mehr vorgesehen! [FS/ST]
//-----------------------------------------------------------------------------
//	layout of a menu cell (a cell is build with one table)
//
//	--------------------------------------------------------
//	|  |     |   | |                                       |
//	|1 |  2  | 3 |4|               5                       |  6
//	|  |     |   | |                                       |
//	--------------------------------------------------------
//	|                                                      |  7
//	--------------------------------------------------------
//                             8
//	legend:
//	[1] fix distance --> spaceLeft
//	[2] var distance (level dependend) --> einruecken
//	[3] arrow area --> arrowGifHeight, arrowGifWidth
//	[4] text distance holder --> textSpace
//	[5] text field
//	[6] content cell height --> trHeightBig
//	[7] space cell height --> trHeightSmall
//	[8] total cell width --> widthTotal
//
//	Definition eines Menueintrages:
//	aMain[i].level  Hierarchie (0, 1, 2 usw.)
//					level -1 ersetzen den Inhalt des gesamten Browserfensters
//
//  aMain[i].mother UrMutter des aktiven Eintrages
//
//  MainMenu		zählt den aktuellen Hauptmenübereich, definiert durch level 0 oder 1
//
//	descr			Text
//	menulink		Link zur zugehoerigen Seite im Target Frame
//					"none" zeigt den Text ohne Link
//	tooltip			Tooltip
//
//	expand			dieser Wert muss nicht angegeben werden --> automatisiert
//					0 sichtbar zu mit pfeil 
//					1 sichtbar offen mit pfeil
//					2 sichtbar ohne pfeil
//					3 unsichtbar mit pfeil
//					4 unsichtbar ohne pfeil
//-----------------------------------------------------------------------------
// Navigator LOOK													   [mod 02]
//-----------------------------------------------------------------------------

//	[look] text colors and styles 
var style_txt_noact = "txtnoact";		// nicht aktive Menüschrift Level 0 oder -1
var style_txt_act = "txtact";			// aktive Menüschrift
var style_txt_sel = "txtsel";			// selektierte, aktive Menüschrift

//	[look] background colors of the text areas
var style_hg_act = "hgactiv"  			// Hintergrund aktiver Eintrag
var style_hg_noact = "hgnoact";			// nicht aktiver Hintergrund  
var style_hg_L = "hgL";					// aktiver Hintergrund aufgrund der Hierarchie
var style_hg_Line = "hgLine";			// style für zwischenzeilen bei rollover

//	[look] background colors of the arrow areas
var style_arr_node_ = "node";			// kein Menüpunkt
var style_arr_clos_ = "clos";			// geschlossener Menüpfeil
var style_arr_open_ = "open";			// offener Menüpfeil

//	[look] sizes, distances and look options
var trHeightBig = 18;					// Zellenhoehe fuer TextZeilen
var trHeightSmall = 1;					// Zellenhoehe fuer Zwischenzeilen
var widthTotal = 180;					// gesamtbreite des Navigators
var textSpace = 4;						// abstand zwischen arrow und Text
var einruecken = 10;					// Grundwert für die Einrückung 
var spaceLeft = 0;						// genereller Abstand zum linken rand
var arrowGifHeight = 18;				// hoehe der arrow-gifs eingeben
var arrowGifWidth = 10;					// breite des arrow-gifs eingeben

//	[look] gif definitions (path!)
var spaceGif = "src='style/transparent.gif'";
var nodeGif = "src='style/transparent.gif'";
var nodeGif_activ = "src='style/transparent.gif'";
var arrowClose = "src='style/right.gif'";
var arrowOpen = "src='style/down.gif'";
var arrowClose_activ = "src='style/right_activ.gif'";
var arrowOpen_activ = "src='style/down_activ.gif'";
var arrowClose_path = "src='style/path.gif'";
var arrowExit = "src='style/exit.gif'";
var spaceString = "<img " + spaceGif + " width=\"" + textSpace + "\" height=\"" + arrowGifHeight + "\" align=\"center\">";


function writeDoc()
{
	var windoc = top.botl.window.document;
	var rightLine = "hgLine";
	var MainMenu = 0;
	windoc.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"" + widthTotal + "\" align=\"top\">"); 
	for (i=0; i < aMain.length; i++)
	{
		/*if (i > 0) {
			if (aMain[i].mother > aMain[i-1].mother) {
				MainMenu++;
			}
		}*/
		var arrowWidth = spaceLeft + space(aMain[i].level) + arrowGifWidth;
		var textWidth = widthTotal - textSpace - arrowWidth - 10-10;
		if (aMain[i].expand < 3)
		{
			writeBeginTableBig(windoc);
			if (aMain[i].expand <3)
			{
				if (aMain[i].order == actOrder)
				{
					windoc.writeln("<td width=\"10\" height=\"18\"><img src=\"style/active.gif\" height=\"18\"width=\"10\"></td>");
					windoc.writeln("<td width=\"" + arrowWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" valign =\"top\" class=\"" + style_hg_act + "\">" + makeArrow(aMain[i].order,spaceGif,spaceGif,spaceGif) + "</td>");
					windoc.writeln("<td width=\"" + textSpace + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_act + "\"> " + spaceString + "</td>");				
					windoc.writeln("<td width=\"" + textWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_act + "\">" + "<a href=\"javascript:void(0);\" title=\"" + aMain[i].tooltip + "\"><span class=\"" + style_txt_sel + aMain[i].level + "\">" + aMain[i].descr + "</span></a></td>" );
					windoc.writeln("<td width=\"10\" height=\"18\" class=\"hgnoact\"><img src=\"style/transparent.gif\" height=\"18\"width=\"10\"></td>");
				}else
				{
					windoc.writeln("<td width=\"10\" height=\"18\"><img src=\"style/transparent.gif\" height=\"18\"width=\"10\"></td>");
					windoc.writeln("<td width=\"" + arrowWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" valign =\"top\" class=\"" + style_hg_L + aMain[i].level + "_" + MainMenu +  "\">" + makeArrow(aMain[i].order,arrowClose,arrowOpen,nodeGif) + "</td>");
					windoc.writeln("<td width=\"" + textSpace + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_L + aMain[i].level  + "_" + MainMenu + "\"> " + spaceString + "</td>");
					windoc.writeln("<td width=\"" + textWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_L + aMain[i].level  + "_" + MainMenu + "\"> " + "<a href=" + aMain[i].menulink + " title=\"" + aMain[i].tooltip + "\"><span class=\""  + style_txt_act + aMain[i].level + "\">" + aMain[i].descr + "</span></a></td>");
					windoc.writeln("<td width=\"10\" height=\"18\" class=\"hgnoact\"><img src=\"style/transparent.gif\" height=\"18\"width=\"10\"></td>");
				}
			}
			writeEndTableBig(windoc);
			
		}
	}
	windoc.writeln("</table>"); 
}


//-----------------------------------------------------------------------------
// makeArrow: define arrows by level (myOrder) and type (myClose,myOpen,myNode)
//-----------------------------------------------------------------------------
function makeArrow(myOrder,myClose,myOpen,myNode) {
	if (aMain[myOrder].activ && aMain[myOrder].expand == 0)
	{
		//alert("actParent: " + actParent + "\n" + "actMother: " + actMother);
		myClose = arrowClose_path;
	}
	var indentFix = "";
	var indentVar = "";
	var indentVarPix = space(aMain[myOrder].level);
	if (indentVarPix > 0) {
		indentVar = "<img " + spaceGif + " width=\"" + indentVarPix + "\" height=\"" + arrowGifHeight + "\" border=\"0\" align=\"center\">";
	}
	if (spaceLeft > 0) {
		indentFix = "<img " + spaceGif + " width=\"" + spaceLeft + "\" height=\"" + arrowGifHeight + "\" align=\"center\">";
	}

	if (aMain[myOrder].level < 0) {
		myArrow = indentFix + "<img " + arrowExit + " width=\"" + arrowGifWidth + "\" height=\"" + arrowGifHeight + "\" align=\"center\">";
	} else { 
		switch(aMain[myOrder].expand) {
 			case 0:
				myArrow = indentFix + indentVar + "<a href=javascript:top.expandLevel(" + aMain[myOrder].level + "," + myOrder + ")><img " + myClose + "\" width=\"" + arrowGifWidth + "\" height=\"" + arrowGifHeight + "\" border=\"0\" align=\"center\"></a>";
 			break;
			case 1:
				myArrow = indentFix + indentVar + "<a href=javascript:top.contractLevel(" + aMain[myOrder].level + "," + myOrder + ")><img " + myOpen + "\" width=\"" + arrowGifWidth + "\" height=\"" + arrowGifHeight + "\" border=\"0\" align=\"center\"></a>";
			break;
			default:
				myArrow = indentFix + indentVar + "<img " + myNode + " width=\"" + arrowGifWidth + "\" height=\"" + arrowGifHeight + "\" align=\"center\">";
			break;
		}
	}
	return myArrow;
}

//-----------------------------------------------------------------------------
// space: calculate the insertion value (pixel)
//-----------------------------------------------------------------------------
function space(mylevel)
{
	indent_pixel = 0;
	if (mylevel > 0)
	{
		indent_pixel = mylevel * einruecken;
	}
	return indent_pixel;
}

//-----------------------------------------------------------------------------
//  Table write functions
//-----------------------------------------------------------------------------
function writeBeginTableBig(windoc)
{
	windoc.writeln("<tr width=\"" + widthTotal + "\" height=\"" + trHeightBig + "\">");
	windoc.writeln("<td width=\"" + widthTotal + "\">");
	windoc.writeln("<table height=\"" + trHeightBig + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"top\" width=\"" + widthTotal + "\">");
	windoc.writeln("<tr align=\"top\" height=\"" + trHeightBig + "\">");
}
function writeEndTableBig(windoc)
{
	windoc.writeln("</tr>");
	windoc.writeln("</table>");
	windoc.writeln("</td>");
	windoc.writeln("</tr>");
}
function writeTableSmall(windoc,type)
{
	windoc.writeln("<tr width=\"" + widthTotal + "\" height=\"" + trHeightSmall + "\">");
	windoc.writeln("<td width=\"" + widthTotal + "\">");
	windoc.writeln("<table height=\"" + trHeightSmall + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"top\" width=\"" + widthTotal + "\">");
	windoc.writeln("<tr align=\"top\" height=\"" + trHeightSmall + "\">");
	windoc.writeln("<td class=\"" + type + "\" width=\"" + widthTotal + "\" height=\"" + trHeightSmall + "\"><img " + spaceGif + " width=\"" + widthTotal + "\" height=\"1\"></td>");
	windoc.writeln("</tr>");
	windoc.writeln("</table>");
	windoc.writeln("</td>");
	windoc.writeln("</tr>");
}

