// Copyright (C) 2002-2004 WEBCOM a.s.
// All rights reserved.

//-------------------------------------------------------------------------------------------
// GLOBAL VARIABLES
//-------------------------------------------------------------------------------------------
var isMenuReady2        = false;
//var navigationBarCount2 = 0;
var activeTab2          = "";
//-------------------------------------------------------------------------------------------
// CSS setings
//-------------------------------------------------------------------------------------------
// top level tabs
//----------------
var topTabBgcolor2           = "#B5B5B5";                          // Top level tab background color
var topTabBgcolorHover2      = "#E60019";                          // Active top level tab background color
var topTabBorderLeft2        = "1px solid #B5B5B5";                // Top level tab left border
var topTabBorderLeftHover2   = "1px solid #E60019";                // Active top level tab left border
var topTabBorderRight2       = "1px solid #B5B5B5";                // Top level tab right border
var topTabBorderRightHover2  = "1px solid #E60019";                // Active top level tab right border
var topTabBorderTop2         = "1px solid #B5B5B5";                // Top level tab top border
var topTabBorderTopHover2    = "1px solid #E60019";                // Active top level tab top border
var topTabBorderBottom2      = "1px solid #B5B5B5";                // Top level tab bottom border
var topTabBorderBottomHover2 = "1px solid #E60019";                // Active top level tab bottom border
var topTabFamily2            = "Tahoma, Arial, Verdana, Helvetica, sans-serif";   // Top level tab font family
var topTabFamilyHover2       = "Tahoma, Arial, Verdana, Helvetica, sans-serif";   // Active top level tab font family
var topTabFontSize2          = 11 +"px";                            // Top level tab font size
var topTabFontSizeHover2     = 11 +"px";                            // Active top level tab font size
var topTabFontWeight2        = 800;                                // Top level tab font weight
var topTabFontWeightHover2   = 800;                                // Active top level tab font weight
var topTabFontColor2         = "#FFFFFF";                          // Top level tab font color
var topTabFontColorHover2    = "#FFFFFF";                          // Active top level tab font color
var topTabHeight2			= 24;								  // Height of Tab Table
var topTabSpaceBetweenTabs2	= 1;								  // Space between Tabs
var topTabSpaceColor2		= "#B5B5B5";						  // Color of Space between Tabs

var topTabPadding2           = new Array(0, 0, 5, 5);              // Top level tab paddings (top, bottom, left, right)
// menu and menu links
//--------------------
var menuWidth2				  = 150;
var menuLeftDistance2		  = 0;								  // Distance of submenu left position 
var menuTopDistance2		  = 1;								  // Distance of submenu top position 
var menuBorderLeft2			  = "1px solid #B5B5B5";			  // Submenu left border style
var menuBorderRight2		  = "1px solid #B5B5B5";			  // Submenu right border style
var menuBorderTop2			  = "1px solid #B5B5B5";			  // Submenu top border style
var menuBorderBottom2		  = "1px solid #B5B5B5";			  // Submenu bottom border style
var menuContainerStyle2        = "border: 0px solid #B5B5B5";      // Border style of the menu link container
var menuLinkIconBgColor2       = "#B5B5B5";                        // Background color of the menu icon column
var menuLinkFamily2            = "Tahoma, Arial, Verdana, Helvetica, sans-serif"; // Menu link font family 
var menuLinkFamilyHover2       = "Tahoma, Arial, Verdana, Helvetica, sans-serif"; // Active menu link font family 
var menuLinkFontWeight2        = 800;                              // Menu link font weight
var menuLinkFontWeightHover2   = 800;                              // Active menu link font weight
var menuLinkFontSize2          = 11 +"px";                         // Menu link font size
var menuLinkFontSizeHover2     = 11 +"px";                         // Active menu link font size
var menuLinkFontColor2         = "#FFFFFF";                        // Menu link font color
var menuLinkFontColorHover2    = "#FFFFFF";                        // Active menu link font color
var menuLinkBgcolor2           = "#B5B5B5";						  // Menu link background color
var menuLinkBgcolorHover2      = "#E60019";                        // Active menu link background color
var menuLinkDecoration2        = "none";                           // Menu link text decoration
var menuLinkDecorationHover2   = "none";                           // Active menu link text decoration
var menuLinkPadding2           = new Array(4, 4, 8, 8);            // Menu link paddings (top, bottom, left, right)
var menuLinkBorderTop2         = "0px solid B5B5B5";           // Menu link border top
var menuLinkBorderTopHover2    = "0px solid B5B5B5";               // Active menu link border top
var menuLinkBorderBottom2      = "0px solid B5B5B5";           // Menu link border bottom
var menuLinkBorderBottomHover2 = "0px solid B5B5B5";               // Active menu link border bottom
var menuLinkBorderLeft2        = "0px";                            // Menu link border left
var menuLinkBorderLeftHover2   = "0px";                            // Active menu link border left
var menuLinkBorderRight2       = "0px";                            // Menu link border right
var menuLinkBorderRightHover2  = "0px";                            // Active menu link border right
//-------------------------------------------------------------------------------------------
var menuLinkStyle2             = "border-top: "+ menuLinkBorderTop2 +"; border-bottom: "+ menuLinkBorderBottom2 +"; border-left: "+ menuLinkBorderLeft2 +"; border-right: "+ menuLinkBorderRight2 +"; padding-top: "+ menuLinkPadding2[0] +"; padding-bottom: "+ menuLinkPadding2[1] +"; padding-left: "+ menuLinkPadding2[2] +"; padding-right: "+ menuLinkPadding2[3] +"; text-decoration: "+ menuLinkDecoration2 +"; font-weight: "+ menuLinkFontWeight2 +"; font-size: "+ menuLinkFontSize2 +"; color: "+ menuLinkFontColor2 +"; background-color: "+ menuLinkBgcolor2 +"; cursor: hand; position: relative; font-family: "+ menuLinkFamily2 +"; font-size: "+ menuLinkFontSize2 +";zindex=99";
var strTopTabStyle2            = "padding-top: "+ topTabPadding2[0] +"; padding-bottom: "+ topTabPadding2[1] +"; padding-left: "+ topTabPadding2[2] +"; padding-right: "+ topTabPadding2[3] +"; cursor: hand;background-color: "+ topTabBgcolor2 + "; border-left: "+ topTabBorderLeft2 +"; border-right: "+ topTabBorderRight2 +"; border-top: "+ topTabBorderTop2 +"; border-bottom: "+ topTabBorderBottom2 +"; font-family: "+ topTabFamily2 +"; font-size: "+ topTabFontSize2 +"; font-weight: "+ topTabFontWeight2 +"; zindex=99; color: "+ topTabFontColor2;
//-------------------------------------------------------------------------------------------


function flipTopTab2(tabId, hasSubmenu){
	//alert("flipTopTab2\n" + tabId);
	var currnetTab2 = document.getElementById(tabId);
	//----------------------------------------------

	if(activeTab2 == "")
	{
		with(currnetTab2.style)
		{
			backgroundColor = topTabBgcolorHover2;
			
			borderLeft      = topTabBorderLeftHover2;
			
			borderRight     = topTabBorderRightHover2;
			
			borderTop       = topTabBorderTopHover2;
			
			borderBottom    = topTabBorderBottomHover2;
			
			fontFamily      = topTabFamilyHover2;
			
			fontSize        = topTabFontSizeHover2;
			
			color	        = topTabFontColorHover2;
			
			fontWeight      = topTabFontWeightHover2;
			
//			if(!hasSubmenu)
//			{
//				borderBottom    = topTabBorderTopHover2;
//			}
//			else
//			{
//				borderBottom    = topTabBorderBottomHover2;
//			}
			zIndex = 100;
		}
		activeTab2 = currnetTab2;
	}
	else
	{
		if(activeTab2 != currnetTab2)
		{
			with(activeTab2.style)
			{
			
				backgroundColor  = topTabBgcolor2;
				
				borderLeft       = topTabBorderLeft2;
				
				borderRight      = topTabBorderRight2;
				
				borderTop        = topTabBorderTop2;
				
				borderBottom    = topTabBorderBottom2;
				
				fontFamily      = topTabFamily2;
				
				fontSize        = topTabFontSize2;
				
				color	        = topTabFontColor2;
				
				fontWeight      = topTabFontWeight2;
				
				zIndex = 0;
				
			}	
			
			with(currnetTab2.style)
			{
				backgroundColor = topTabBgcolorHover2;

				borderLeft      = topTabBorderLeftHover2;

				borderRight     = topTabBorderRightHover2;

				borderTop       = topTabBorderTopHover2;

				borderBottom    = topTabBorderBottomHover2;

				fontFamily      = topTabFamilyHover2;

				fontSize        = topTabFontSizeHover2;

				color	        = topTabFontColorHover2;

				fontWeight      = topTabFontWeightHover2;
				
//				if(!hasSubmenu)
//				{
//					borderBottom    = topTabBorderTopHover2;
//				}
//				else
//				{
//					borderBottom    = topTabBorderBottomHover2;
//				}
				
				zIndex = 100;
			}	
			activeTab2 = currnetTab2;
		}
	}
}

function deactiveTopTab2()
{
	if(activeTab2 != "" && MenuGuard2.activeSubmenu == "")
	{
		with(activeTab2.style)
		{
			backgroundColor  = topTabBgcolor2;
			
			borderLeft       = topTabBorderLeft2;
			
			borderRight      = topTabBorderRight2;
			
			borderTop        = topTabBorderTop2;
			
			borderBottom    = topTabBorderBottom2;
			
			fontFamily      = topTabFamily2;
			
			fontSize        = topTabFontSize2;
			
			color	        = topTabFontColor2;
			
			fontWeight      = topTabFontWeight2;
			
			zIndex = 0;
		}	
		
		activeTab2 = "";
	}
}

function flipIconStyle2(cellId, action)
{
	with(document.getElementById(cellId).style)
	{
		if(action == "active")
		{
			fontFamily      = menuLinkFamilyHover2;
			
			fontWeight      = menuLinkFontWeightHover2;
			
			fontSize        = menuLinkFontSizeHover2;
			
			color           = menuLinkFontColorHover2;
			
			backgroundColor = menuLinkBgcolorHover2;
			
			textDecoration  = menuLinkDecorationHover2;
			
			borderTop       = menuLinkBorderTopHover2;
			
			borderBottom    = menuLinkBorderBottomHover2;
			
			borderLeft      = menuLinkBorderLeftHover2;
			
			borderRight     = menuLinkBorderRightHover2;
		}
		else if(action == "deactive")
		{
			fontFamily      = menuLinkFamily2;
			
			fontWeight      = menuLinkFontWeight2;
			
			fontSize        = menuLinkFontSize2;
			
			color           = menuLinkFontColor2;
			
			backgroundColor = menuLinkBgcolor2;
			
			textDecoration  = menuLinkDecoration2;
			
			borderTop       = menuLinkBorderTop2;
			
			borderBottom    = menuLinkBorderBottom2;
			
			borderLeft      = menuLinkBorderLeft2;
			
			borderRight     = menuLinkBorderRight2;
		}
	}
}

//*******************
// OBJECT Navigation2
//*******************
function Navigation2(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 == "ST")
		{
			this.topLevelTab[this.topLevelTabCounter] = new TabObject2(id , parentId , caption, linkType, linkValue, isLocked, hasSubmenu, icon);
			
			this.topLevelTabCounter ++;
		}
		//tab isn't top level tab
		else
		{
			this.tab[this.tabCounter] = new TabObject2(id , parentId , caption, linkType, linkValue, isLocked, hasSubmenu, icon);

			this.tabCounter ++;
		}
	}

	// Method creates top level tabs
	this.createTopLevelTabs = function()
	{
		var strOutpu = "";
		var isLocked = "";
		//----------------

		strOutpu += "<table cellpadding=0 cellspacing=0 border=0 height="+ topTabHeight2 +" style='zindex:100'><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 +"\"'";
			}
			// Tab is locked
			else
			{
				isLocked = "";	
			}
			
			// space between menu items
			if(topTabSpaceBetweenTabs2 > 0 & i > 0)
				strOutpu += "<td width='"+ topTabSpaceBetweenTabs2 +"' bgcolor='"+ topTabSpaceColor2 +"'><img border='0' width='"+ topTabSpaceBetweenTabs2 +"' src='"+ appImagesRoot +"iReadyCommon_1x1_Transparent.gif'></td>";
			

			// current tab has some submenu
			if(this.topLevelTab[i].hasSubmenu)
			{
				//strOutpu += "<td nowrap style='position: relative; "+ strTopTabStyle +"' onMouseOut='deactiveTopTab2()' onMouseOver='flipTopTab2(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu2(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;<img src='"+appImagesRoot+"iReadyCommon_Tab_Arrow.gif' width=8 height=4 border=0></td>";
				//oldrem strOutpu += "<td nowrap style='"+ strTopTabStyle +"' onMouseOut='deactiveTopTab2()' onMouseOver='flipTopTab2(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu2(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"&nbsp;<img src='"+appImagesRoot+"iReadyCommon_Tab_Arrow.gif' width=8 height=4 border=0></td>";
				strOutpu += "<td nowrap style='position: relative; "+ strTopTabStyle2 +"' onMouseOut='deactiveTopTab2()' onMouseOver='flipTopTab2(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu2(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
			}
			// current tab hasn't submenu
			else
			{
				strOutpu += "<td nowrap style='position: relative; "+ strTopTabStyle2 +"' onMouseOut='deactiveTopTab2()' onMouseOver='flipTopTab2(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu2(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
				//strOutpu += "<td nowrap style='"+ strTopTabStyle +"' onMouseOut='deactiveTopTab2()' onMouseOver='flipTopTab2(\"topTab_"+ this.topLevelTab[i].id +"\", "+ this.topLevelTab[i].hasSubmenu +"); openMenu2(\"menu_"+ this.topLevelTab[i].id +"\")' id='topTab_"+ this.topLevelTab[i].id +"' "+ isLocked +">"+ this.topLevelTab[i].caption +"</td>";
			}
		}
		
		strOutpu += "</tr></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++)
			{
				// (ST) if(parseInt(currentParent) == parseInt(oldParent[u]))
				if(currentParent == oldParent[u])
				{
					isNextParent = false;
				}
				else
				{
					isNextParent = true;
				}
			}
			
			// for the tabs with the same parentId renders html output (creates menu)
			if(isNextParent)
			{
				//strOutpu += "<table cellpadding=0 cellspacing=0 border=0 id='menu_"+ parseInt(currentParent) +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden; border-left:"+menuBorderLeft+"; border-right:"+menuBorderRight+"; border-top:"+menuBorderTop+"; border-bottom:"+menuBorderBottom+"' width='160'><tr><td>";
				// (ST) strOutpu += "<table cellpadding=0 cellspacing=0 border=0 id='menu_"+ parseInt(currentParent) +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden; border-left:"+ menuBorderLeft2 +"; border-right:"+ menuBorderRight2 +"; border-top:"+ menuBorderTop2 +"; border-bottom:"+ menuBorderBottom2 +"'><tr><td>";
				strOutpu += "<table cellpadding=0 cellspacing=0 border=0 id='menu_"+ currentParent +"' style='position: absolute; left: 300px; top: 0px; visibility: hidden; border-left:"+ menuBorderLeft2 +"; border-right:"+ menuBorderRight2 +"; border-top:"+ menuBorderTop2 +"; border-bottom:"+ menuBorderBottom2 +"'><tr><td>";

				//strOutpu += "<div class='menuLinksContainer' style='"+ menuContainerStyle +";width:160px'>";
				strOutpu += "<div class='menuLinksContainer' style='"+ menuContainerStyle2 +"'>";
				
				// (ST) strOutpu += "<table cellpadding=0 cellspacing=0 border=0 width='100%'><tr>";
				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 +"\"'"
						}
						// 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 = "<div style='padding: 2px'><img src='images/m_dot.gif' width=14 height=14 border=0></div>";
							icon = "";
						}
						
						// Current tab has some submenu
						//alert(this.tab[k].hasSubmenu);
						if(this.tab[k].hasSubmenu)
						{
							//strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'>"+ icon +"</td><td width='100%'><div onMouseOver='flipIconStyle2(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu2(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle2(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle2 +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"'><img src='images/m_dot.gif' width=5 height=8 border=0><img src='images/arrow01.gif' width=4 height=8 border=0><img src='images/m_dot.gif' width=5 height=8 border=0></td></tr>";
							// (ST) strOutpu += "<td nowrap width='100%'><div onMouseOver='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu2(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle2 +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td>";
							strOutpu += "<tr><td nowrap width='100%'><div onMouseOver='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu2(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle2 +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td></tr>";
							//alert("tab_"+ this.tab[k].id);
						}
						// current tab hasn't submenu
						else
						{
							//strOutpu += "<tr><td bgcolor='"+ menuLinkIconBgColor +"'>"+ icon +"</td><td width='100%'><div onMouseOver='flipIconStyle2(\"linkIcon_"+ this.tab[k].id +"\", \"active\"); flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu2(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle2(\"linkIcon_"+ this.tab[k].id +"\", \"deactive\"); flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle2 +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td><td id='linkIcon_"+ this.tab[k].id +"' bgColor='"+ menuLinkBgcolor +"'><img src='images/m_dot.gif' width=14 height=8 border=0></td></tr>";
							// (ST) strOutpu += "<td nowrap width='100%'><div onMouseOver='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu2(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle2 +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td>";
							strOutpu += "<tr><td nowrap width='100%'><div onMouseOver='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"active\"); openMenu2(\"menu_"+ this.tab[k].id +"\", \"menu_"+ currentParent +"\")' onMouseOut='flipIconStyle2(\"tab_"+ this.tab[k].id +"\", \"deactive\");' id='tab_"+ this.tab[k].id +"' style='"+ menuLinkStyle2 +"' "+ isLocked +">"+ this.tab[k].caption +"</div></td></tr>";
						}
						
					}	
				}
				// (ST) strOutpu += "</tr></table>";
				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 Menu2("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 or onLoad of the BODY element is catched
	this.recalculatePositions = function()
	{
		// for each menu objects calculate absolute position in the document
		for(r = 0; r < this.menu.length; r++)
		{
			positionMenus2(this.menu[r]);
		}
	}
}

function positionMenus2(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
		// top bar tab
		if(isTopLevelTab)
		{
			top  = numParentTop + numParentHeight + menuTopDistance +"px";
			left = numParentLeft + menuLeftDistance +"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 + 10 +"px";
			}
			else
			{
				left = objParentMenu.offsetLeft + objParentMenu.offsetWidth - 10 +"px";
			}	
		}	
	}
}

function MainMenuOverlaps2(o1,o2)
{
	/*var o1x1=o1.offsetLeft;
	var o1y1=o1.offsetTop;
	var o1x2=o1.offsetLeft+o1.offsetWidth;
	var o1y2=o1.offsetTop+o1.offsetHeight;
	var o2x1=o2.offsetLeft;
	var o2y1=o2.offsetTop;
	var o2x2=o2.offsetLeft+o2.offsetWidth;
	var o2y2=o2.offsetTop+o2.offsetHeight;*/


	var o1x1=GetOffsetLeft2(o1);
	var o1y1=GetOffsetTop2(o1);
	var o1x2=o1x1+GetOffsetWidth2(o1);
	var o1y2=o1y1+GetOffsetHeight2(o1);

	var o2x1=GetOffsetLeft2(o2);
	var o2y1=GetOffsetTop2(o2);
	var o2x2=o2x1+GetOffsetWidth2(o2);
	var o2y2=o2y1+GetOffsetHeight2(o2);


	//alert(o1x1+"-"+o1y1+":"+o1x2+"-"+o1y1+":"+o1x1+"-"+o1y2+":"+o1x2+"-"+o1y2);

	if ((o1x1 <= o2x1) && (o1x2 >= o2x1) && (o1y1<=o2y1) && (o1y2>=o2y1)||
	(o1x1 <= o2x2) && (o1x2 >= o2x2) && (o1y1<=o2y1) && (o1y2>=o2y1)||
	(o1x1 <= o2x1) && (o1x2 >= o2x1) && (o1y1<=o2y2) && (o1y2>=o2y2)||
	(o1x1 <= o2x2) && (o1x2 >= o2x2) && (o1y1<=o2y2) && (o1y2>=o2y2)||
	(o1x1 <= o2x1) && (o1x2 >= o2x2) && (o1y1>=o2y1) && (o1y2>=o1y2)
)
		return true;
	else
		return false;
}

function HideControlsMenu2(tagName,menuId)
{
	if (menuId!=null)
	{
		var menu=document.getElementById(menuId);
		var objekty=document.getElementsByTagName(tagName);


		
		//alert(left);
	
		if(menu!=null)
			for(i=0;i<objekty.length;i++)
			{
				
				//alert(GetOffsetLeft2(objekty[i])+"-"+GetOffsetTop2(objekty[i])+"-"+GetOffsetWidth2(objekty[i])+"-"+GetOffsetHeight2(objekty[i]));

				if (MainMenuOverlaps2(objekty[i],menu) || MainMenuOverlaps2(menu,objekty[i]))  
					objekty[i].style.visibility="hidden";
			}
	}
}



function GetOffsetLeft2(obj)
{

	var left=0;
	while (obj.offsetParent!=null)
	{
		left=left+obj.offsetLeft;
		obj=obj.offsetParent;
	
	}

return left;
}


function GetOffsetTop2(obj)
{

	var top=0;
	while (obj.offsetParent!=null)
	{
		top=top+obj.offsetTop;
		obj=obj.offsetParent;
	
	}

return top;
}


function GetOffsetWidth2(obj)
{

	return obj.offsetWidth;
}

function GetOffsetHeight2(obj)
{

	return obj.offsetHeight;
}



function openMenu2(menuId, parentMenuId){
	//alert("openMenu2\n" + menuId)
	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
	//---------------------------------------------------------------------------
	
	colapseAll();

	if(!isMenuReady2)
	{
		return;
	}
	
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		if (parentMenuId==null)
			ShowControlsMenu2("select");

		if (parentMenuId==null)
			HideControlsMenu2("select",menuId);
	}
	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(MenuGuard2.getSelectedMenu() == "")
			{
				objMmenuToOpen.style.visibility = "visible";
				
				MenuGuard2.addSelectedMenu(objMmenuToOpen);
				
				MenuGuard2.addActiveSubMenu(menuToOpen, "xxx");
			}
			// if some other menu is opened
			else
			{
				// if some submenu is opened
				if(MenuGuard2.activeSubmenu != "")
				{
					document.getElementById(MenuGuard2.activeSubmenu.id).style.visibility = "hidden";
					
					MenuGuard2.closeSubMenuChain((openFromMenu));
				}
				MenuGuard2.activeSubmenu = "";
				
				activeMenu = MenuGuard2.getSelectedMenu();
				
				activeMenu.style.visibility = "hidden";
				
				objMmenuToOpen.style.visibility = "visible";
				
				MenuGuard2.addSelectedMenu(objMmenuToOpen);
				
				MenuGuard2.addActiveSubMenu(menuToOpen, "xxx");
			}
		}
		// if function doesn't receive some menu object to open
		else
		{
			// if some other menu is opened
			if(MenuGuard2.getSelectedMenu() != "")
			{
				activeMenu = MenuGuard2.getSelectedMenu();
				
				activeMenu.style.visibility = "hidden";
				
				MenuGuard2.closeSubMenuChain((openFromMenu));
				
				MenuGuard2.activeSubmenu = "";
			}
		}
	}
	// open demand submenu
	else
	{
		// if function receive some menu object to open
		if(menuToOpen != "")
		{
			// if there is not other submenu opened
			if(MenuGuard2.activeSubmenu == "")
			{
				objMmenuToOpen.style.visibility = "visible";
				
				MenuGuard2.addActiveSubMenu(menuToOpen, openFromMenu);
			}
			else
			{
				if(openFromMenu == MenuGuard2.activeSubmenu.parentId)
				{
					if(MenuGuard2.activeSubmenu.parentId != "xxx")
					{
						document.getElementById(MenuGuard2.activeSubmenu.id).style.visibility = "hidden";
					}	
					objMmenuToOpen.style.visibility = "visible";
					
					MenuGuard2.replaceLastSubMenu(menuToOpen, openFromMenu);
				}
				else if(openFromMenu == MenuGuard2.activeSubmenu.id)
				{
					objMmenuToOpen.style.visibility = "visible";
					
					MenuGuard2.addActiveSubMenu(menuToOpen, openFromMenu);
				}
				else
				{
					MenuGuard2.closeSubMenuChain(openFromMenu);
					
					document.getElementById(MenuGuard2.activeSubmenu.id).style.visibility = "hidden";
					
					objMmenuToOpen.style.visibility = "visible";
					
					MenuGuard2.replaceLastSubMenu(menuToOpen, openFromMenu);
				}
			}
		}
		// if some other menu is opened
		else
		{
			if(openFromMenu == MenuGuard2.activeSubmenu.parentId)
			{
				document.getElementById(MenuGuard2.activeSubmenu.id).style.visibility = "hidden";
				
				MenuGuard2.closeLastSubMenu();
			}	
		}	
	}
}


function ShowControlsMenu2(tagName)
{
	var objekty=document.getElementsByTagName(tagName);
	for(i=0;i<objekty.length;i++)
	{
		objekty[i].style.visibility="visible";
	}
}


// Function closes all open menus and its submenus
// VLAZAL: pouziva se  nekde tato funkce?
function colapseAll2()
{
if (navigator.appName=="Microsoft Internet Explorer")
{
	ShowControlsMenu2("select");
}
	if(MenuGuard2.activeSubmenu != "")
	{
		document.getElementById(MenuGuard2.activeSubmenu.id).style.visibility = "hidden";
		
		MenuGuard2.closeSubMenuChain((MenuGuard2.activeSubmenu.id));
		
		MenuGuard2.activeSubmenu = "";
	}
	if(activeTab2 != "")
	{
		with(activeTab2.style)
		{
			backgroundColor  = topTabBgcolor2;
			
			borderLeft       = topTabBorderLeft2;
			
			borderRight      = topTabBorderRight2;
			
			borderTop        = topTabBorderTop2;
			
			borderBottom    = topTabBorderBottom2;
			
			fontFamily      = topTabFamily2;
			
			fontSize        = topTabFontSize2;
			
			color	        = topTabFontColor2;
			
			fontWeight      = topTabFontWeight2;
			
			zIndex          = 0;
		}	
		
		activeTab2 = "";
	}
}

//*******************
// OBJECT MenuGuard2
//*******************
function MenuGuard2(){
	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 Menu2(menuId, openFromMenu);
		
		this.activeSubmenu = this.activeSubMenu[this.submenuCounter - 1];
	}
	
	this.addActiveSubMenu = function(menuId, openFromMenu)
	{
		this.activeSubMenu[this.submenuCounter] = new Menu2(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 MenuGuard2 = new MenuGuard2();


//*******************
// OBJECT Menu2
//*******************
function Menu2(id, parentId){
	this.id       = id;
	this.parentId = parentId;
}


//*******************
// OBJECT TabObject2
//*******************
function TabObject2(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;
}
