//*******************************************************************************************
// Copyright (C) 2004 Intro Design
// All rights reserved.
//*******************************************************************************************

//-------------------------------------------------------------------------------------------
// GLOBAL VARIABLES
//-------------------------------------------------------------------------------------------
var isMenuReady        = false;
var navigationBarCount = 0;
var activeTab          = "";
var closingTimout;
var isMenuReady        = false;
//-------------------------------------------------------------------------------------------
// CSS setings
//-------------------------------------------------------------------------------------------
// top level tabs
//----------------
var topTabBgcolor           = "#E80001";                        // Top level tab background color
var topTabBgcolorHover      = "#BA0003";                        // Active top level tab background color
var topTabBorderLeft        = "0px solid red";              // Top level tab left border
var topTabBorderLeftHover   = "0px solid red";              // Active top level tab left border
var topTabBorderRight       = "0px solid red";              // Top level tab right border
var topTabBorderRightHover  = "0px solid red";              // Active top level tab right border
var topTabBorderTop         = "0px solid red";              // Top level tab top border
var topTabBorderTopHover    = "0px solid red";              // Active top level tab top border
var topTabBorderBottom      = "0px solid red";              // Top level tab bottom border
var topTabBorderBottomHover = "0px solid red";              // Active top level tab bottom border
var topTabFamily            = "Verdana, Helvetica, sans-serif"; // Top level tab font family
var topTabFamilyHover       = "Verdana, Helvetica, sans-serif"; // Active top level tab font family
var topTabFontSize          = 10 +"px";                         // Top level tab font size
var topTabFontSizeHover     = 10 +"px";                         // Active top level tab font size
var topTabFontWeight        = 400;                              // Top level tab font weight
var topTabFontWeightHover   = 800;                              // Active top level tab font weight
var topTabFontColor         = "#FFFFFF";                        // Top level tab font color
var topTabFontColorHover    = "#FFFFFF";                        // Active top level tab font color
var topTabPadding           = new Array(2, 2, 5, 5);            // Top level tab paddings
// menu and menu links
//--------------------
var menuWidth = 250;
var menuContainerStyle        = "filter:progid:DXImageTransform.Microsoft.Alpha (opacity=90)";      // Border style of the menu link container
var menuLinkIconBgColor       = "#233D6F";
var menuLinkFamily            = "Verdana, Helvetica, sans-serif"; // Menu link font family 
var menuLinkFamilyHover       = "Verdana, Helvetica, sans-serif"; // Active menu link font family 
var menuLinkFontWeight        = 400;                              // Menu link font weight
var menuLinkFontWeightHover   = 800;                              // Active menu link font weight
var menuLinkFontSize          = 10 +"px";                         // Menu link font size
var menuLinkFontSizeHover     = 10 +"px";                         // Active menu link font size
var menuLinkFontColor         = "#FFFFFF";                        // Menu link font color
var menuLinkFontColorHover    = "white";                        // Active menu link font color
//var menuLinkBgcolor           = "#233D6F";                        // Menu link background color
//var menuLinkBgcolorHover      = "#233D6F";                        // Active menu link background color
var menuLinkBgcolor           = "transparent";                        // Menu link background color
var menuLinkBgcolorHover      = "#BA0003";                        // Active menu link background color
var menuLinkDecoration        = "none";                           // Menu link text decoration
var menuLinkDecorationHover   = "none";                           // Active menu link text decoration
var menuLinkPadding           = new Array(4, 4, 8, 5);            // Menu link paddings
var menuLinkBorderTop         = "px solid #FFFFFF";              // Menu link border top
var menuLinkBorderTopHover    = "0px solid white";              // Active menu link border top
var menuLinkBorderBottom      = "0px solid #FFFFFF";              // Menu link border bottom
var menuLinkBorderBottomHover = "0px solid #0A246A";              // Active menu link border bottom
var menuLinkBorderLeft        = "0px";                            // Menu link border left
var menuLinkBorderLeftHover   = "0px";                            // Active menu link border left
var menuLinkBorderRight       = "0px";                            // Menu link border right
var menuLinkBorderRightHover  = "0px";                            // Active menu link border right
//------------------------------------
var menuLinkStyle           = "border-top: "+ menuLinkBorderTop +"; border-bottom: "+ menuLinkBorderBottom +"; border-left: "+ menuLinkBorderLeft +"; border-right: "+ menuLinkBorderRight +"; padding-top: "+ menuLinkPadding[0] +"; padding-bottom: "+ menuLinkPadding[1] +"; padding-left: "+ menuLinkPadding[2] +"; padding-right: "+ menuLinkPadding[3] +"; text-decoration: "+ menuLinkDecoration +"; font-weight: "+ menuLinkFontWeight +"; font-size: "+ menuLinkFontSize +"; color: "+ menuLinkFontColor +"; background-color: "+ menuLinkBgcolor +"; cursor: hand; position: relative; font-family: "+ menuLinkFamily +"; font-size: "+ menuLinkFontSize +";";
var strTopTabStyle          = "width: 165px; padding-top: "+ topTabPadding[0] +"; padding-bottom: "+ topTabPadding[1] +"; padding-left: "+ topTabPadding[2] +"; padding-right: "+ topTabPadding[3] +"; cursor: hand; background-color: "+ topTabBgcolor + "; border-left: "+ topTabBorderLeft +"; border-right: "+ topTabBorderRight +"; border-top: "+ topTabBorderTop +"; border-bottom: "+ topTabBorderBottom +"; font-family: "+ topTabFamily +"; font-size: "+ topTabFontSize +"; font-weight: "+ topTabFontWeight +"; color: "+ topTabFontColor;
//-------------------------------------------------------------------------------------------


function flipTopTab(tabId, hasSubmenu){
	var currnetTab = document.getElementById (tabId);
	//----------------------------------------------

	if(activeTab == "")
	{
		currnetTab.nextSibling.style.backgroundColor = topTabBgcolorHover;
		with(currnetTab.style)
		{
			backgroundColor = topTabBgcolorHover;
			
			
			borderLeft      = topTabBorderLeftHover;
			
			borderRight     = topTabBorderRightHover;
			
			borderTop       = topTabBorderTopHover;
			
			borderBottom    = topTabBorderBottomHover;
			
			fontFamily      = topTabFamilyHover;
			
			fontSize        = topTabFontSizeHover;
			
			color	        = topTabFontColorHover;
			
			fontWeight      = topTabFontWeightHover;
			
			if(!hasSubmenu)
			{
				borderBottom    = topTabBorderBottomHover;
			}
			else
			{
				borderBottom    = topTabBorderBottomHover;
			}
			zIndex = 10;
		}
		activeTab = currnetTab;
	}
	else
	{
		if(activeTab != currnetTab)
		{
			activeTab.nextSibling.style.backgroundColor  = topTabBgcolor;
			with(activeTab.style)
			{
			
				backgroundColor  = topTabBgcolor;
				
				
				borderLeft       = topTabBorderLeft;
				
				borderRight      = topTabBorderRight;
				
				borderTop        = topTabBorderTop;
				
				borderBottom    = topTabBorderBottom;
				
				fontFamily      = topTabFamily;
				
				fontSize        = topTabFontSize;
				
				color	        = topTabFontColor;
				
				fontWeight      = topTabFontWeight;
				
				zIndex = 0;
				
			}	
			
			currnetTab.nextSibling.style.backgroundColor = topTabBgcolorHover;
			with(currnetTab.style)
			{
				backgroundColor = topTabBgcolorHover;
				

				borderLeft      = topTabBorderLeftHover;

				borderRight     = topTabBorderRightHover;

				borderTop       = topTabBorderTopHover;

				borderBottom    = topTabBorderBottomHover;

				fontFamily      = topTabFamilyHover;

				fontSize        = topTabFontSizeHover;

				color	        = topTabFontColorHover;

				fontWeight      = topTabFontWeightHover;
				
				if(!hasSubmenu)
				{
					borderBottom    = topTabBorderBottomHover;
				}
				else
				{
					borderBottom    = topTabBorderBottomHover;
				}
				
				zIndex = 10;
			}	
			activeTab = currnetTab;
		}
	}
}

function deactiveTopTab()
{
	if(activeTab != "" && menuGuard.activeSubmenu == "")
	{
		activeTab.nextSibling.style.backgroundColor  = topTabBgcolor;
		with(activeTab.style)
		{
			backgroundColor  = topTabBgcolor;
			
			
			borderLeft       = topTabBorderLeft;
			
			borderRight      = topTabBorderRight;
			
			borderTop        = topTabBorderTop;
			
			borderBottom    = topTabBorderBottom;
			
			fontFamily      = topTabFamily;
			
			fontSize        = topTabFontSize;
			
			color	        = topTabFontColor;
			
			fontWeight      = topTabFontWeight;
			
			zIndex = 0;
		}	
		
		activeTab = "";
	}
}

function flipIconStyle(cellId, action)
{
	with(document.getElementById(cellId).style)
	{
		if(action == "active")
		{
			backGround = "";
			
			fontFamily      = menuLinkFamilyHover;
			
			fontWeight      = menuLinkFontWeightHover;
			
			fontSize        = menuLinkFontSizeHover;
			
			color           = menuLinkFontColorHover;
			
			backgroundColor = menuLinkBgcolorHover;
			
			textDecoration  = menuLinkDecorationHover;
		}
		else if(action == "deactive")
		{
			fontFamily      = menuLinkFamily;
			
			fontWeight      = menuLinkFontWeight;
			
			fontSize        = menuLinkFontSize;
			
			color           = menuLinkFontColor;
			
			backgroundColor = menuLinkBgcolor;
			
			textDecoration  = menuLinkDecoration;
		}
	}
}

//*******************
// OBJECT Navigation
//*******************
function Navigation (renderDirection)
{
	this.renderDirection    = renderDirection;		//horizontal or vertical
	this.topLevelTab        = new Array();
	this.tab                = new Array();
	this.tabCounter         = 0;
	this.topLevelTabCounter = 0;
	this.menu               = new Array;
	this.menCounter         = 0;
	//--------------------------------------
	
	// Method divides tabs to top level tabs and the other tabs and save them in to the array
	this.addTab = function(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon)
	{
		//tab is top level tab
		if(parentId == "")
		{
			this.topLevelTab[this.topLevelTabCounter] = new TabObject(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon);
			
			this.topLevelTabCounter ++;
		}
		//tab isn't top level tab
		else
		{
			this.tab[this.tabCounter] = new TabObject(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon);

			this.tabCounter ++;
		}
	}

	// Method creates top level tabs
	this.createTopLevelTabs = function()
	{
		var strOutpu = "";
		var isLocked = "";
		//----------------

		if (this.renderDirection == "horizontal")
		{
			if (navigator.appName == "Microsoft Internet Explorer")
			{
				strOutpu += "<table onMouseOut='closeMenu ()' onMouseOver='cancelTimeout ()' cellpadding=0 cellspacing=0 border=0><tr>";
			}
			else
			{
				strOutpu += "<table onMouseOut='window.event.cancelBubble = true; closeMenu ()' onMouseOver='window.event.cancelBubble = true; cancelTimeout ()' cellpadding=0 cellspacing=0 border=0><tr>";
			}
			
			for(i = 0; i < this.topLevelTabCounter; i ++)
			{
				// Tab isn't locked
				if(this.topLevelTab[i].isLocked == false)
				{
					//isLocked = "onClick='document.location = \""+ this.topLevelTab[i].linkValue +"\"'";
					isLocked = "onClick='"+ this.topLevelTab[i].linkValue +"'";
				}
				// Tab is locked
				else
				{
					isLocked = "";	
				}

				// current tab has some submenu
				if(this.topLevelTab[i].hasSubmenu)
				{
					strOutpu += "<td style='position: relative;"+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;<img src='images/arrow02.gif' width=8 height=4 border=0></td>";
				}
				// current tab hasn't submenu
				else
				{
					strOutpu += "<td style='position: relative; "+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
				}
			}
			
			strOutpu += "</tr></table>";
		}
		else
		{
			if (navigator.appName == "Microsoft Internet Explorer")
			{
				//strOutpu += "<div style='border-right: 1px solid #476E4F; padding-right: 1px; padding-left: 1px; background-color: red'><table onMouseOut='closeMenu ()' onMouseOver='cancelTimeout ()' cellpadding=0 cellspacing=0 border=0>";
				strOutpu += "<table onMouseOut='closeMenu ()' onMouseOver='cancelTimeout ()' cellpadding=0 cellspacing=0 border=0>";
			}
			else
			{
				//strOutpu += "<div style='border-right: 1px solid #476E4F; padding-right: 1px; padding-left: 1px; background-color: red'><table onMouseOut='window.event.cancelBubble = true; closeMenu ()' onMouseOver='window.event.cancelBubble = true; cancelTimeout ()' cellpadding=0 cellspacing=0 border=0>";
				strOutpu += "<table onMouseOut='window.event.cancelBubble = true; closeMenu ()' onMouseOver='window.event.cancelBubble = true; cancelTimeout ()' cellpadding=0 cellspacing=0 border=0>";
			}
			
			for (i = 0; i < this.topLevelTabCounter; i ++)
			{
				// Tab isn't locked
				if (this.topLevelTab [i].isLocked == false)
				{
					//isLocked = "onClick='document.location = \""+ this.topLevelTab[i].linkValue +"\"'";
					isLocked = "onClick='"+ this.topLevelTab[i].linkValue +"'";
				}
				// Tab is locked
				else
				{
					isLocked = "";	
				}

				// current tab has some submenu
				if (this.topLevelTab [i].hasSubmenu)
				{
					strOutpu += "<tr><td><img src='Images/1x1.gif' width=3 height=1 border=0></td><td style='position: relative;"+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;</td><td align=right><img src='Images/menu2.gif' width=13 height=20 border=0></td><td><img src='Images/1x1.gif' width=3 height=1 border=0></td></tr>";
				}
				// current tab hasn't submenu
				else
				{
					strOutpu += "<tr><td><img src='Images/1x1.gif' width=3 height=1 border=0></td><td style='position: relative; "+ strTopTabStyle +"' onMouseOut='deactiveTopTab()' onMouseOver='flipTopTab(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;</td><td align=right bgcolor='"+topTabBgcolor+"'><img src='Images/1x1.gif' width=13 height=20 border=0></td><td><img src='Images/1x1.gif' width=3 height=1 border=0></td></tr>";
				}
			}
			
			//strOutpu += "</table></div>";
			strOutpu += "</table>";
		}
		
		// open document, writes result and closes the document
		with(document)
		{
			open();
			
			write(strOutpu);
			
			close();
		}	
	}
	
	// Method creates menus
	this.createMenus = function()
	{
		var parentElement;
		var currentParent;
		var parentsCount   = 0
		var strOutpu       = "";
		var isLocked       = "";
		var isNextParent   = true;
		var oldParent      = new Array();
		//-------------------------------
		
		// for all non top level tabs
		for(i = 0; i < this.tabCounter; i ++)
		{
			currentParent = this.tab[i].parentId;
			
			// search for the tabs with the same parentId
			for(u = 0; u < parentsCount; u++)
			{
				if(parseInt(currentParent) == parseInt(oldParent[u]))
				{
					isNextParent = false;
				}
				else
				{
					isNextParent = true;
				}
			}
			
			// for the tabs with the same parentId renders html output (creates menu)
			if(isNextParent)
			{
				//strOutpu += "<table onMouseOut='window.event.cancelBubble = true; closeMenu ()' onMouseOver='window.event.cancelBubble = true; cancelTimeout ()' border=0 id='menu_"+ parseInt(currentParent) +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden'><tr><td>";
				strOutpu += "<table width='250' onMouseOut='window.event.cancelBubble = true; closeMenu ()' onMouseOver='window.event.cancelBubble = true; cancelTimeout ()' border=0 cellpadding=0 cellspacing=0 id='menu_"+ parseInt(currentParent) +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden'>";
				strOutpu += "<tr><td><img src='Images/submenu_01.gif' width=4 height=4 border=0></td>";
				strOutpu += "<td background='Images/submenu_tex_top.gif' width='100%'><img src='Images/1x1.gif' width=4 height=4 border=0></td>";
				strOutpu += "<td><img src='Images/submenu_02.gif' width=4 height=4 border=0></td></tr>";
				strOutpu += "<tr>";
				strOutpu += "<td background='Images/submenu_tex_left.gif'><img src='Images/1x1.gif' width=4 height=4 border=0></td>";
				strOutpu += "<td>";
				
				
				//strOutpu += "<div class='menuLinksContainer' style='"+ menuContainerStyle +"; padding-left: 4px; padding-right: 4px; background-color: #233D6F; width: 250px'>";
				strOutpu += "<div class='menuLinksContainer' style='"+ menuContainerStyle +"; width: 250px'>";
				
				strOutpu += "<table cellpadding=0 cellspacing=0 border=0 width='100%'>";
				
				for(k = 0; k < this.tabCounter; k ++)
				{
					if(currentParent == this.tab[k].parentId)
					{
						// Tab isn't locked
						if(this.tab[k].isLocked == false)
						{
							//isLocked = "onClick='document.location=\""+ this.tab[k].linkValue +"\"'";
							isLocked = "onClick='"+ this.tab[k].linkValue +"'";
						}
						// Tab is locked
						else
						{
							isLocked = "";	
						}
						
						// Tab has icon
						if(this.tab[k].icon != "")
						{
							icon = "<div style='padding: 2px'><img src='"+ this.tab[k].icon +"' width=14 height=14 border=0></div>"
						}
						// Tab hasn't icon
						else
						{
							icon = "";
						}
						
						// Current tab has some submenu
						if(this.tab[k].hasSubmenu)
						{
							//strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'  style='border-bottom: 1px solid red'>"+ icon +"</td><td width='100%' bgcolor='"+ menuLinkIconBgColor +"' style='border-bottom: 1px solid red'><div onMouseOver='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"' style='border-bottom: 1px solid red'><img src='images/1x1.gif' width=13 height=20 border=0><img src='images/menu4.gif' width=13 height=20 border=0><img src='images/1x1.gif' width=5 height=8 border=0></td></tr>";
							strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'>"+ icon +"</td><td width='100%' bgcolor='"+ menuLinkIconBgColor +"'><div onMouseOver='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"'><img src='images/1x1.gif' width=13 height=20 border=0><img src='images/menu4.gif' width=13 height=20 border=0><img src='images/1x1.gif' width=5 height=8 border=0></td></tr>";
						}
						// current tab hasn't submenu
						else
						{
							//strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"' style='border-bottom: 1px solid red'>"+ icon +"</td><td width='100%' bgcolor='"+ menuLinkIconBgColor +"' style='border-bottom: 1px solid red'><div onMouseOver='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td style='border-bottom: 1px solid red' id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"'><img src='images/1x1.gif' width=13 height=20 border=0></td></tr>";
							strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'>"+ icon +"</td><td width='100%' bgcolor='"+ menuLinkIconBgColor +"'><div onMouseOver='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"'  style='"+ menuLinkStyle +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"'  bgColor='"+ menuLinkBgcolor +"'></td></tr>";
						}
					}	
				}
				strOutpu += "</table>";
				strOutpu += "</div>";
				
				strOutpu += "</td>";
				strOutpu += "<td background='Images/submenu_tex_right.gif'><img src='Images/1x1.gif' width=4 height=4 border=0></td>";
				strOutpu += "</tr><tr>";
				strOutpu += "<td><img src='Images/submenu_03.gif' width=4 height=4 border=0></td>";
				strOutpu += "<td background='Images/submenu_tex_down.gif'><img src='Images/1x1.gif' width=4 height=4 border=0></td>";
				strOutpu += "<td><img src='Images/submenu_04.gif' width=4 height=4 border=0></td>";
				strOutpu += "</tr>";
				
				strOutpu += "</table>";
								
				//strOutpu += "</div>";

				//strOutpu += "</td></tr></table>";
				
				oldParent[parentsCount] = currentParent;

				parentsCount ++;
				
				for(a = 0; a < this.topLevelTab.length; a ++)
				{
					if(this.topLevelTab[a].id == currentParent)
					{
						parentElement = "topTab_"+ currentParent;
						
						break;
					}
					else
					{
						parentElement = "tab_"+ currentParent;
					}
				}

				this.menu[this.menCounter] = new Menu("menu_"+ currentParent, parentElement);

				this.menCounter ++;
			}	
		}
		
		// open document, writes result and closes the document
		with(document)
		{
			open();

			write(strOutpu);

			close();
		}	
	}
	
	// Method recalculate positions of all menu objects when event onResize of the BODY element is catched
	this.recalculatePositions = function()
	{
		// for each menu objects calculate absolute position
		for(r = 0; r < this.menu.length; r++)
		{
			positionMenus(this.menu[r]);
		}
	}
}

function positionMenus(objMenu)
{
	var objParentEl	    = document.getElementById(objMenu.parentId);    // parent object of the menu ... object(link) which opens and closes this menu
	var objCurrentMenu  = document.getElementById(objMenu.id);          // object which represents menu
	var objParentMenu;                                                  // object which represents parent menu. parent menu contains parent object(link) which opens the submenu
	var numParentTop    = parseInt(objParentEl.offsetTop);
	var numParentLeft   = parseInt(objParentEl.offsetLeft);
	var numParentWidth  = parseInt(objParentEl.offsetWidth);
	var numParentHeight = parseInt(objParentEl.offsetHeight);
	var strParentId     = objMenu.parentId;                             // parent object(link) id ... object which opens the submenu
	var isTopLevelTab   = false;
	var clientWidth     = document.body.clientWidth;
	var clientHeight    = document.body.clientHeight;
	//-------------------------------------------------------------


	// true = top bar tab, false = every other tabs
	isTopLevelTab = (strParentId.indexOf("topTab") != -1) ? true : false;
	
	with(objCurrentMenu.style)
	{
		// sets position of each menu
		
		if (this.renderDirection == "horizontal")
		{
			// top bar tab
			if(isTopLevelTab)
			{
				top  = numParentTop + numParentHeight - 4 +"px";
				left = numParentLeft - 3 +"px";
			}
			// other tabs
			else
			{
				objParentMenu = objParentEl.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode

				if(objParentMenu.offsetTop + numParentTop > clientHeight)
				{
					top  = objParentMenu.offsetTop - objParentEl.parentNode.offsetTop + "px";
				}
				else
				{
					top  = objParentMenu.offsetTop + objParentEl.parentNode.offsetTop + "px";
				}
				
				if (objParentMenu.offsetLeft + objParentMenu.offsetWidth + objParentMenu.offsetWidth> clientWidth)
				{
					left = objParentMenu.offsetLeft - objParentMenu.offsetWidth - 20 +"px";
				}
				else
				{
					left = objParentMenu.offsetLeft + objParentMenu.offsetWidth - 10 +"px";
				}	
			}
		}
		else
		{
			// top bar tab
			if (isTopLevelTab)
			{
				top  = numParentTop - 3 +"px";
				//left = numParentLeft + 143 +"px";
				left = numParentLeft + 189 +"px";
			}
			// other tabs
			else
			{
				objParentMenu = objParentEl.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode

				left = objParentMenu.offsetLeft + objParentMenu.offsetWidth - 7 +"px";
				
				top  = objParentMenu.offsetTop + numParentTop - 5 +"px";
			}
		}
	}
	isMenuReady = true;
}

function openMenu(menuId, parentMenuId){
	var objMmenuToOpen  = eval("document.getElementById('"+ menuId +"')");        // object menu to open
	var objMpenFromMenu = eval("document.getElementById('"+ parentMenuId +"')");  // object menu from which will be opened submenu
	var activeMenu;
	var openFromMenu    = "";                                                     // id of object menu to open
	var menuToOpen      = "";                                                     // id of object menu from which will be opened submenu
	//---------------------------------------------------------------------------
	
	if (!isMenuReady)
	{
		return;
	}
	
	openFromMenu = (objMpenFromMenu) ? objMpenFromMenu.id : "";
	
	menuToOpen   = (objMmenuToOpen) ? objMmenuToOpen.id : "";
	
	// open demand menu which is not submenu
	if(openFromMenu == "")
	{
		// if function receive some menu object to open
		if(menuToOpen != "")
		{
			// if there is not other menu opened
			if(menuGuard.getSelectedMenu() == "")
			{
				objMmenuToOpen.style.visibility = "visible";
				
				menuGuard.addSelectedMenu(objMmenuToOpen);
				
				menuGuard.addActiveSubMenu(menuToOpen, "xxx");
			}
			// if some other menu is opened
			else
			{
				// if some submenu is opened
				if(menuGuard.activeSubmenu != "")
				{
					document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
					
					menuGuard.closeSubMenuChain((openFromMenu));
				}
				menuGuard.activeSubmenu = "";
				
				activeMenu = menuGuard.getSelectedMenu();
				
				activeMenu.style.visibility = "hidden";
				
				objMmenuToOpen.style.visibility = "visible";
				
				menuGuard.addSelectedMenu(objMmenuToOpen);
				
				menuGuard.addActiveSubMenu(menuToOpen, "xxx");
			}
		}
		// if function doesn't receive some menu object to open
		else
		{
			// if some other menu is opened
			if(menuGuard.getSelectedMenu() != "")
			{
				activeMenu = menuGuard.getSelectedMenu();
				
				activeMenu.style.visibility = "hidden";
				
				menuGuard.closeSubMenuChain((openFromMenu));
				
				menuGuard.activeSubmenu = "";
			}
		}
	}
	// open demand submenu
	else
	{
		// if function receive some menu object to open
		if(menuToOpen != "")
		{
			// if there is not other submenu opened
			if(menuGuard.activeSubmenu == "")
			{
				objMmenuToOpen.style.visibility = "visible";
				
				menuGuard.addActiveSubMenu(menuToOpen, openFromMenu);
			}
			else
			{
				if(openFromMenu == menuGuard.activeSubmenu.parentId)
				{
					if(menuGuard.activeSubmenu.parentId != "xxx")
					{
						document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
					}	
					objMmenuToOpen.style.visibility = "visible";
					
					menuGuard.replaceLastSubMenu(menuToOpen, openFromMenu);
				}
				else if(openFromMenu == menuGuard.activeSubmenu.id)
				{
					objMmenuToOpen.style.visibility = "visible";
					
					menuGuard.addActiveSubMenu(menuToOpen, openFromMenu);
				}
				else
				{
					menuGuard.closeSubMenuChain(openFromMenu);
					
					document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
					
					objMmenuToOpen.style.visibility = "visible";
					
					menuGuard.replaceLastSubMenu(menuToOpen, openFromMenu);
				}
			}
		}
		// if some other menu is opened
		else
		{
			if(openFromMenu == menuGuard.activeSubmenu.parentId)
			{
				document.getElementById(menuGuard.activeSubmenu.id).style.visibility = "hidden";
				
				menuGuard.closeLastSubMenu();
			}	
		}	
	}
}

// Function closes all open menus and its submenus
function colapseAll ()
{
	if(menuGuard.activeSubmenu != "")
	{
		document.getElementById (menuGuard.activeSubmenu.id).style.visibility = "hidden";
		
		menuGuard.closeSubMenuChain ((menuGuard.activeSubmenu.id));
		
		menuGuard.activeSubmenu = "";
	}
	if(activeTab != "")
	{
		activeTab.nextSibling.style.backgroundColor  = topTabBgcolor;
		with(activeTab.style)
		{
			backgroundColor  = topTabBgcolor;
			
			borderLeft       = topTabBorderLeft;
			
			borderRight      = topTabBorderRight;
			
			borderTop        = topTabBorderTop;
			
			borderBottom    = topTabBorderBottom;
			
			fontFamily      = topTabFamily;
			
			fontSize        = topTabFontSize;
			
			color	        = topTabFontColor;
			
			fontWeight      = topTabFontWeight;
			
			zIndex           = 0;
		}	
		
		activeTab = "";
	}
}

//*******************
// OBJECT MenuGuard
//*******************
function MenuGuard(){
	this.openMenu       = "";
	this.selectedItem   = "";
	this.openFromMenu   = "";
	this.activeSubMenu  = new Array();
	this.submenuCounter = 0;
	this.activeSubmenu  = "";
	//--------------------------------
	
	this.closeSubMenuChain = function(openFromMenu)
	{
		for (i = this.submenuCounter -1; i >= 0; i--)
		{
			if(this.activeSubMenu[i].parentId != openFromMenu)
			{
				document.getElementById(this.activeSubMenu[i].id).style.visibility = "hidden";
			}
			else
			{
				break;
			}
		}
		this.submenuCounter = i + 1;
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.closeLastSubMenu = function()
	{
		this.submenuCounter--;
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.replaceLastSubMenu = function(menuId, openFromMenu)
	{
		this.activeSubMenu[this.submenuCounter - 1] = new Menu(menuId, openFromMenu);
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.addActiveSubMenu = function(menuId, openFromMenu)
	{
		this.activeSubMenu[this.submenuCounter] = new Menu(menuId, openFromMenu);
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter];
		
		this.submenuCounter++;
	}
	
	this.addSelectedMenu = function(menuName)
	{
		this.openMenu = menuName;
	}
	
	this.removeSelectedMenu = function()
	{
		this.openMenu = "";
	}
	
	this.getSelectedMenu = function()
	{
		return this.openMenu;
	}
	
	this.addOpenFromMenu = function(menuName)
	{
		this.openFromMenu = menuName;
	}
	
	this.removeOpenFromMenu = function()
	{
		this.openFromMenu = "";
	}
	
	this.getOpenFromMenu = function()
	{
		return this.openFromMenu;
	}
}

var menuGuard = new MenuGuard();


//*******************
// OBJECT Menu
//*******************
function Menu(id, parentId){
	this.id       = id;
	this.parentId = parentId;
}


//*******************
// OBJECT TabObject
//*******************
function TabObject(id, parentId, caption, linkType, linkValue, isLocked, hasSubmenu, icon){
	this.id         = id;
	this.parentId   = parentId;
	this.caption    = caption;
	this.linkType   = linkType;
	this.linkValue  = linkValue;
	this.isLocked   = isLocked;
	this.hasSubmenu = hasSubmenu;
	this.icon       = icon;
}

function closeMenu ()
{
	closingTimout = window.setTimeout("colapseAll()", 200);
}

function cancelTimeout ()
{
	window.clearTimeout (closingTimout);
}

function LoadFrame (sourceFile)
{
	document.getElementById ("ifrLeftColumn").src = sourceFile;
}