if (document.all)    {n=0;ie=1;fShow="visible";fHide="hidden";}
if (document.layers) {n=1;ie=0;fShow="show";   fHide="hide";}
if (!document.all)    {n=0;ie=1;fShow="visible";fHide="hidden";}

window.onerror=new Function("return true")
////////////////////////////////////////////////////////////////////////////
// Function Menu()                                                        //
////////////////////////////////////////////////////////////////////////////
rightX = 0;
var navBarSubBackColor = "#3171AD";
var navBarSelctedBackColor = "#10619C";
var sURL = new String(document.location);

function Menu()
{
	this.bgColor     = "#102C4A";
	this.menuFont = "FONT-WEIGHT: bolder; FONT-SIZE: 12px; FONT-FAMILY:Ariel;";
//	if (ie) this.menuFont = "bold xx-small Verdana";
	this.fontColor   = "#BDD3E7";

	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;
	this.mainPaneBorder = 0;
	this.subMenuPaneBorder = 0;
	this.subMenuBgColor = "#3171AD";
	this.subMenuPaneWidth = 160;
	
	this.lastMenu = null;
	
	rightY = 0;
	leftY = 0;
	leftX = 0;

	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";
	HTMLstr += "<div id='MainTable' style='width:100%;z-index:100;position:absolute'>\n";
	HTMLstr += "<table width='100%' cellspacing=0 cellpadding=0 border='"+this.mainPaneBorder+"'>\n";
	HTMLstr += "<tr>";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	HTMLstr+= "</div>\n";
	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}

function addItem(idItem, text, hint, location, altLocation)
{
	var tblStart, tblEnd, siman;
	var SELECTED_BGCOLOR;
	
	if (idItem=='indextaskifim' && view_type=='search' && srh_event=='300-310') 
		SELECTED_BGCOLOR = navBarSelctedBackColor;
	else if(idItem=='indexBaalInyan' && view_type=='search' && srh_event=='900') 
		SELECTED_BGCOLOR = navBarSelctedBackColor;
	else
		SELECTED_BGCOLOR = (idItem == 'index'+view_type) ? navBarSelctedBackColor : this.bgColor; 
	
	tblStart = '<table border=0 height="20" width="100%" cellspacing=0 cellpadding=0>'
			+ '<tr><td id="td'+idItem+'" align=center style="cursor: pointer;" bgcolor='+SELECTED_BGCOLOR+' valign=center onmouseover=ChangeBack("'+idItem+'",1); onmouseout=ChangeBack("'+idItem+'",0);>'; 
			    
    if (idItem.indexOf("Today") != -1) 
		tblEnd = '</td><td id="tds'+idItem+'" align=left width=2 bgcolor='+SELECTED_BGCOLOR+'><img src=\"imgr/home/micro_blue_arrow.gif\" height=\"7\" width=\"5\">&nbsp;</td><td width=2 height="10" bgcolor="#6386AD"></td>'
				+ '</tr></table>';
    else
		tblEnd = '</td><td width=2 height="10" bgcolor="#6386AD"></td>'
				+ '</tr></table>';
        
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1)
	{
		alert(idParent + " already exist");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	//MENUitem += "<td valign=center bgcolor='"+this.bgColor+"' height=20 onmouseover=\"this.bgColor='#08498C';\" onmouseout=\"this.bgColor='#10304A';\">\n";
	
	if (location == null)
		{
		MENUitem += "<td valign=center height=20\n";
		//MENUitem += "onclick=\"window.location.href='"+idItem+".htm'\"\n";
		MENUitem += "onclick=\"window.location.href='"+altLocation+"'\"\n";
		MENUitem += " onmouseover=\"displaySubMenu('"+idItem+"')\">\n";
		}
	else
		{
		MENUitem += "<td valign=center height=20\n";
		MENUitem += "onclick=\"window.location.href='"+altLocation+"'\"\n";
		//MENUitem += "onclick=\"window.location.href='"+idItem+".htm'\">\n";
		//MENUitem += " onmouseover=\"displaySubMenu('"+idItem+"')\">\n";
		}
	MENUitem += "<div id='"+idItem+"' style='z-index:100;position:relative; "+this.menuFont+";'>\n";
	MENUitem += tblStart+"\n";
	MENUitem += "<a ";
	MENUitem += "class=clsMenuItemIE ";
	if (idItem.indexOf("today") != -1) 
		MENUitem += "style='text-decoration: none; "+this.menuFont+"; color: #FFFFFF; cursor: pointer;' ";
	else
		MENUitem += "style='text-decoration: none; "+this.menuFont+"; color: "+this.fontColor+"; cursor: pointer;' ";
	if (hint != null)
		MENUitem += "title='"+hint+"' ";
	if (location != null)
	{
		MENUitem += "href='"+location+"' ";
		MENUitem += "onmouseover=\"hideAll()\" ";
	}
	else
	{
		if (altLocation != null)
			MENUitem += "href='"+altLocation+"' ";
		else
			MENUitem += "href='.' ";
		//MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
		//MENUitem += "onclick=\"return false;\" "
	}
	MENUitem += ">";
	//MENUitem += "|&nbsp;\n";
	
	MENUitem += text;
	MENUitem += "</a>\n";
	MENUitem += tblEnd+"\n";
	MENUitem += "</div>\n";
	MENUitem += "</td>\n";

	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

function addSubItem(idParent, text, hint, location)
{
	var MENUitem = "";
		
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		
		MENUitem += "\n";
		MENUitem += "<div id='"+idParent+"submenu' style='z-index:100;position:absolute; cursor: pointer; visibility: hidden; width: "+this.subMenuPaneWidth+"; color:' + this.subMenuBgColor + '; "+this.menuFont+"; top: -300;'>\n";
		MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.subMenuBgColor+"' cellpadding=0 cellspacing=0 width="+this.subMenuPaneWidth+">\n";
		MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
		MENUitem += "</table>\n";
		MENUitem += "</div>\n";
		MENUitem += "\n";

		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	MENUitem = "<tr onmouseover=\"this.bgColor='#57a3d1';\" onmouseout=\"this.bgColor='#3171AD';\"><td align=right height=17 align=center style=\"BORDER-TOP:#94AACE 1px solid; BORDER-BOTTOM:#10304A 1px solid;\" \n>";
	MENUitem += "<a class=clsMenuItemIE\n";
	MENUitem += "title='"+hint+"' href='"+location+"'\n";
	if (idParent.indexOf("Today") != -1) 
		MENUitem += " style='text-decoration: none; "+this.menuFont+"; color: #FFFFFF; cursor: pointer;'>\n";
	else
		MENUitem += " style='text-decoration: none; "+this.menuFont+"; color: "+this.fontColor+"; cursor: pointer;'>\n";
	MENUitem += text;
	MENUitem += "</a><br></td><td align=center width=\"30px\" style=\"BORDER-TOP:#94AACE 1px solid; BORDER-BOTTOM:#10304A 1px solid;\"><img src=imgr/home/sub_arrow.gif width=9 height=9></td></tr>\n";
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function showMenu()
{
	document.writeln(HTMLstr);
}

////////////////////////////////////////////////////////////////////////////
// Private declaration
function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
		
		menu = eval(document.getElementById(idMainMenu));
		submenu = eval(document.getElementById(idMainMenu+"submenu"));
		
		submenu.style.left = calculateSumOffset(menu, 'offsetLeft')-(submenu.offsetWidth-menu.offsetWidth)+"px";
		submenu.top  = calculateSumOffset(menu, 'offsetTop') ;
		
		submenu.style.top  = 20;
		submenu.style.visibility = fShow;
		
		if (idMainMenu=="indextashlumim" || idMainMenu=="indexkranot"){
			if ((sURL.indexOf("index.asp")!=-1 || sURL.indexOf("indextoday.htm")!=-1 || sURL.indexOf("indeximptoday.htm")!=-1) && document.getElementById("CompanyGroup"))
			{
				if (idMainMenu!="indexkranot")
				{
					if (submenu.offsetLeft < document.getElementById("CompanyGroup").offsetWidth + document.getElementById("CompanyGroup").offsetLeft)
						document.getElementById("CompanyGroup").style.width = (submenu.style.left.substring(0,submenu.style.left.indexOf("px")) - cGroup.offsetLeft)+"px";
				}
				else
					document.getElementById("CompanyGroup").style.width = 0;
			}
			
			if ((sURL.indexOf("indexkrnmsg.asp")!=-1 || sURL.indexOf("indexkranot.htm")!=-1)  && document.getElementById("kranotGroup"))
			{
				if (idMainMenu=="indextashlumim")
				{
					if (submenu.offsetLeft < document.getElementById("kranotGroup").offsetWidth + document.getElementById("kranotGroup").offsetLeft)
						document.getElementById("kranotGroup").style.width = (submenu.style.left.substring(0,submenu.style.left.indexOf("px")) - document.getElementById("kranotGroup").offsetLeft);
				}
				else
					document.getElementById("kranotGroup").style.width = 0;
			}
		}
		
		if (this.lastMenu != null && this.lastMenu != submenu.style) hideAll();
		
		leftX  = submenu.offsetLeft;
		rightX = leftX + submenu.offsetWidth;

		leftY  = submenu.offsetTop+
			submenu.offsetHeight+89;
		rightY = leftY;
	
	this.lastMenu = submenu.style;
}

function hideAll()
{
	
	if ((sURL.indexOf("index.asp")!=-1 || sURL.indexOf("indextoday.htm")!=-1 || sURL.indexOf("indeximptoday.htm")!=-1) && document.getElementById("CompanyGroup"))
		document.getElementById("CompanyGroup").style.width = "163px";
	
	if ((sURL.indexOf("indexkrnmsg.asp")!=-1  || sURL.indexOf("indexkranot.htm")!=-1) && document.getElementById("kranotGroup"))
		document.getElementById("kranotGroup").style.width = "163";
	
	if (this.lastMenu != null) {
		this.lastMenu.visibility = fHide;
		this.lastMenu.left = 0;
	    //eval('td'+this.lastMenuName+'.bgColor="#10304A";')
	}
	
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function ChangeSubBack(idItem,flag)
{
	if (flag==0)
		eval(idItem+".bgColor='#10304A'");
	else
		eval(idItem+".bgColor='#10619C'");

	return false;
}

function ChangeBack(idItem,flag)
{
	if (idItem=='index'+view_type) return false;
	if (flag==0)
		{
		eval("td"+idItem+".bgColor='#10304A'");
		if (idItem.indexOf("Today") != -1) eval("tds"+idItem+".bgColor='#10304A'");
		}
	else
		{
		eval("td"+idItem+".bgColor='#10619C'");
		if (idItem.indexOf("Today") != -1) eval("tds"+idItem+".bgColor='#10619C'");
		}
}
function updateIt(e)
{
	var x,y;
	if (window.event)
	{
		x = window.event.clientX;
		y = window.event.clientY;
	}
	else
	{
		x = e.clientX;
		y = e.clientY;
	}

	if (x > rightX || x < leftX) hideAll();
	else if (y > rightY)
	 hideAll();
	}


	document.body.onclick=hideAll;
	//document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;

