//-----------------------------------------------------------------------------
//	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]
//	[11/02]		Rel. 2.1.1 'Removed div-Tag to keep hover functionality' [CM]
//-----------------------------------------------------------------------------
//	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 Menueschrift
var style_txt_sel = "txtsel";			// selektierte, aktive Menueschrift

//	[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 fuer zwischenzeilen bei rollover

//	[look] background colors of the arrow areas
var style_arr_node_ = "node";			// kein Menuepunkt
var style_arr_clos_ = "clos";			// geschlossener Menuepfeil
var style_arr_open_ = "open";			// offener Menuepfeil

//	[look] sizes, distances and look options
var trHeightBig = 19;					// 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 = 0;						// Grundwert fuer die Einrueckung 
var spaceLeft = 15;						// genereller Abstand zum linken rand
var arrowGifHeight = 18;				// hoehe der arrow-gifs eingeben
var arrowGifWidth = 15;					// breite des arrow-gifs eingeben

//	[look] gif definitions (path!)
var spaceGif = "src='style/transparent.gif'";
var nodeGif = "src='style/node.gif'";
var nodeGif_activ = "src='style/node_activ.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\">"); 
	writeTableSmall(windoc,rightLine);
	for (i=0; i < aMain.length; i++)
	{
		if (i > 0) {
			if (aMain[i].mother > aMain[i-1].mother) {
				MainMenu++;
				//writeTableSmall(windoc, style_hg_Line);
			}
		}
		var arrowWidth = spaceLeft + space(aMain[i].level) + arrowGifWidth;
		var textWidth = widthTotal - textSpace - arrowWidth - 0;

		if (aMain[i].expand < 3)
		{
			writeBeginTableBig(windoc);
			switch(aMain[i].menulink)
			{
				case "":
					windoc.writeln("<td width=\"" + arrowWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" valign =\"top\">" + makeArrow(aMain[i].order,arrowClose_activ,arrowOpen_activ,nodeGif_activ) + "</td>");
					windoc.writeln("<td width=\"" + textSpace + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_act + "_" +aMain[i].level  + "\">" + spaceString + "</td>");				
					windoc.writeln("<td width=\"" + textWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_act + "_" +aMain[i].level  + "\">" + "<a href=\"javascript:void(0);\" title=\"" + aMain[i].tooltip + "\" class=\"" + style_txt_sel + aMain[i].level + "\">" + aMain[i].descr + "</a></td>" );
					//windoc.writeln("<td width=\"" + textWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_act  + "_" +aMain[i].level  + "\">" + "<a href=\"javascript:void(0);\" title=\"" + aMain[i].tooltip + "\" class=\"" + style_txt_sel + aMain[i].level + "\"><div class=\"" + style_txt_sel + aMain[i].level + "\">" + aMain[i].descr + "</div></a></td>" );
					//windoc.writeln("<td width=\"1\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + rightLine + "\"><img " + spaceGif + " width=\"1\" height=\"" + trHeightBig + "\"></td>" );
				break;
				case "none":
					windoc.writeln("<td width=\"" + arrowWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" valign =\"top\">" + 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=\"javascript:void(0);\" title=\"" + aMain[i].tooltip + "\"><div class=\"none\">"  + aMain[i].descr + "</div></a></td>");
					//windoc.writeln("<td width=\"" + textWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + style_hg_L + aMain[i].level + "_" + MainMenu + "\"><a href=\"javascript:void(0);\" title=\"" + aMain[i].tooltip + "\"><div class=\"none\">"  + aMain[i].descr + "</div></a></td>");
					//windoc.writeln("<td width=\"1\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + rightLine + "\"><img " + spaceGif + " width=\"1\" height=\"" + trHeightBig + "\"></td>" );
				break;
				default:
					windoc.writeln("<td width=\"" + arrowWidth + "\" height=\"" + trHeightBig + "\" align=\"left\" valign =\"top\">" + 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 + "\" class=\""  + style_txt_act + aMain[i].level + "\">" + aMain[i].descr + "</a></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 + "\" class=\""  + style_txt_act + aMain[i].level + "\"><div class=\"" + style_txt_act + aMain[i].level + "\">" + aMain[i].descr + "</div></a></td>");
					//windoc.writeln("<td width=\"1\" height=\"" + trHeightBig + "\" align=\"left\" class=\"" + rightLine + "\"><img " + spaceGif + " width=\"1\" height=\"" + trHeightBig + "\"></td>" );
				break;
			}
			writeEndTableBig(windoc);
			writeTableSmall(windoc, style_hg_Line);
			
			/*if (i < aMain.length-1) {
				if (aMain[i+1].level < aMain[i].level) {
					writeTableSmall(windoc, style_hg_Line);
				}
			}*/
			/*if (aMain[i].menulink == "" && i < aMain.length-1) {
				writeTableSmall(windoc, style_hg_Line);
			}*/
		}
	}
	//writeTableSmall(windoc,rightLine);
	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>");
}


