//Holds the "TR" of the first level opened Channel, 
//if first level seleced object is a Posting, 
//it hold the value of: CONST_MENU_WITH_NO_CHILDREN
var oFirstLevelMenuOpen = "";

//If first level seleced object is a Posting, this Holds the Posting's "TR"
var oFirstLevelIndicator = ""; 

//a default value when the first level seleced object is a Posting
var CONST_MENU_WITH_NO_CHILDREN="MenuWithNoChildren";

//Holds the "TR" of the second level opened Channel, 
//if second level seleced object is a Posting, 
//it hold the value of: CONST_MENU_WITH_NO_CHILDREN
var oSecondLevelMenuOpen = "";

//If second level seleced object is a Posting, this Holds the Posting's "TR"
var oSecondLevelIndicator = ""; 

//when we open channel at the second level of the menu if the blnKeepOneSecondLevelOpenForEachParnetOnChange equal to true:
//only one channel can will be open at the menu. if false the menu will keep all the levels open when we navigate at the menu.
//TBD - not supported - Shai G. 02-12-2004
var blnKeepOneSecondLevelOpenForEachParnetOnChange = true;

//blnKeepAllLevelsOpenOnChange define if to display only one channel open (param equal to false) at the menu each click.
//if true we do not close the menu automatic when user click on channel.
var blnKeepAllLevelsOpenOnChange = false;
var globalApplicationPath="";
var iTableUniqueID=0;
var guidLevelUniqueID="";
var iLastDrawnLevel=-1;
var guidHighlightedUniqueID="";
var gChannelGroup = 1;
			
function getMenuRowNumber(rowName)
{
	var r, re;                    //Declare variables.
	re = /mnuTr/g;             //Create regular expression pattern.
	r = rowName.replace(re, "");    //Replace blank with "mnuTr".
	return(r);                   
}
			
function openCloseFirstLevelSub(oTD)
{
	var oTR, oNextTR;
	var rowNumber;
	oTR = oTD.parentElement;
	var trName = oTR.getAttribute("id");

	//alert(oTD.innerHTML);
	//alert(oTR.childNodes[0].width);
	//window.open('http://www.ynet.co.il');
	//return;
	oNextTR = oTR.nextSibling;
	
	//check if the there is another row.
	//if not then there are no children and nothing should happen
	//taht means that we should not open this level.
	if((typeof(oNextTR)=="undefined")||(oNextTR==null))
	{
		return;
	}
	
	if(oNextTR.style.display!="none")
	{	
		//when the next row has a class of a Top-Leveled element that means that
		//this folder has no children
		if((oNextTR.childNodes[0].className=="TopChannel")||(oNextTR.childNodes[0].className=="HighlightedTopChannel")||(oNextTR.childNodes[0].className=="TopPosting")||(oNextTR.childNodes[0].className=="HighlightedTopPosting"))
		{
			//alert("No Children!!!")
			return;
		}
		
	}
	//if we want to keep all the menus opened:
	if(blnKeepAllLevelsOpenOnChange)
	{
		if (oNextTR.style.display == "")
		{
			//Check if this TR is a Seperator Roe before Closing(hiding) it:
			if(oNextTR.childNodes[0].className!="MenuSeparatorRow")
			{
				oNextTR.style.display = "none";
				//changing the image to show that the menu is open
				oTR.childNodes[1].childNodes[0].src=sTopChannelImgSrc;
				oTR.childNodes[0].className="TopChannel";
				oTR.childNodes[1].className="TopChannel_BulletCell";
				oTR.className="TopChannel";// sharon - add class to tr
			}
		}
		else
		{
			oNextTR.style.display = "";
			//changing the image to show that the menu is open
			oTR.childNodes[1].childNodes[0].src=sTopHighChannelImgSrc;
			oTR.childNodes[0].className="HighlightedTopChannel";
			oTR.childNodes[1].className="HighlightedTopChannel_BulletCell";
			oTR.className="HighlightedTopChannel";// sharon - add class to tr
		}
	}	
	else
	{
		//opening a first level menu
		if (oNextTR.style.display == "none")
		{
			if ((oFirstLevelMenuOpen != "")&&(oFirstLevelMenuOpen!=CONST_MENU_WITH_NO_CHILDREN))
			{
				if (oFirstLevelMenuOpen.style.display == "")
				{
					oFirstLevelMenuOpen.style.display = "none";
					//changing the image to show that the menu is open
					oFirstLevelMenuOpen.previousSibling.childNodes[1].childNodes[0].src=sTopChannelImgSrc;
					oFirstLevelMenuOpen.previousSibling.childNodes[0].className="TopChannel";
					oFirstLevelMenuOpen.previousSibling.childNodes[1].className="TopChannel_BulletCell";
					oFirstLevelMenuOpen.previousSibling.className="TopChannel";// sharon - add class to tr
				}	
			}
			else if(oFirstLevelMenuOpen==CONST_MENU_WITH_NO_CHILDREN)
			{
				//changing the image to show that this Posting is "Disabled"
				oFirstLevelIndicator.childNodes[1].childNodes[0].src=sTopPostingImgSrc;
				oFirstLevelIndicator.childNodes[0].className="TopPosting";
				oFirstLevelIndicator.childNodes[1].className="TopPosting_BulletCell";
				oFirstLevelIndicator.className="TopPosting";// sharon - add class to tr
			}
			else if(oFirstLevelMenuOpen=="")
			{
				//changing the image to show that the menu is open
				oTR.childNodes[1].childNodes[0].src=sTopPostingImgSrc;
				oTR.childNodes[0].className="TopPosting";
				oTR.childNodes[1].className="TopPosting_BulletCell";
				oTR.className="TopPosting";// sharon - add class to tr
			}
						
			oNextTR.style.display = "";
			oFirstLevelMenuOpen = oNextTR;
			//changing the image to show that the menu is open
			oTR.childNodes[1].childNodes[0].src=sTopHighChannelImgSrc;
			oTR.childNodes[0].className="HighlightedTopChannel";
			oTR.childNodes[1].className="HighlightedTopChannel_BulletCell";
			oTR.className="HighlightedTopChannel";// sharon - add class to tr
		}
		else //closing a first level menu
		{
			//Check if this TR is a Seperator Row before Closing(hiding) it:
			if(oNextTR.childNodes[0].className!="MenuSeparatorRow")
			{
				oNextTR.style.display = "none";
				oFirstLevelMenuOpen = "";
				//changing the image to show that the menu is closed
				oTR.childNodes[1].childNodes[0].src=sTopChannelImgSrc;
				oTR.childNodes[0].className="TopChannel";
				oTR.childNodes[1].className="TopChannel_BulletCell";
				oTR.className="TopChannel";// sharon - add class to tr
			}
		}
	}
	
}
			
			
			
function openCloseSecondLevelSub(oTD)
{
	var oTR, oNextTR;
	var oTable;
	oTR = oTD.parentElement;
	oTable = oTR.parentElement;
	oNextTR = oTR.nextSibling;
	
	//if there are any children at all
	if(oNextTR)
	{
		if(oNextTR.style.display!="none")
		{
			if(oTR.childNodes[1].childNodes[0].src.indexOf(sChannelImgSrc)>-1)
			{
				//alert("No Children!!!")
				return;
			}
		}
	}
	else
	{
		return;
	}
	
	//if we want to keep all the menus opened:
	if(blnKeepAllLevelsOpenOnChange)
	{
		if (oNextTR.style.display == "")
		{
			oNextTR.style.display = "none";
			//changing the image to show that the menu is open
			oTR.childNodes[1].childNodes[0].src=sChannelImgSrc;
			oTR.childNodes[0].className="Channel";
			oTR.childNodes[1].className="Channel_BulletCell";
			oTR.className="Channel";// sharon - add class to tr
		}
		else
		{
			oNextTR.style.display = "";
			//changing the image to show that the menu is open
			oTR.childNodes[1].childNodes[0].src=sHighChannelImgSrc;
			oTR.childNodes[0].className="HighlightedChannel";
			oTR.childNodes[1].className="HighlightedChannel_BulletCell";
			oTR.className="HighlightedChannel";// sharon - add class to tr
		}
	}	
	else
	{
		//opening a second level menu
		if (oNextTR.style.display == "none")
		{
			if(blnKeepOneSecondLevelOpenForEachParnetOnChange)
			{
				//run through all TR element of this level (to find other second 
				//leveled menus)
				for(var i=0;i<oTable.childNodes.length;i++)
				{
					//if this TR is a menu and not "this" menu -> close it
					if(oTR!=oTable.childNodes[i] && (oTable.childNodes[i].className=="Channel" || oTable.childNodes[i].className=="HighlightedChannel") && oTable.childNodes[i].isChild=="0")
					{
						//close only the ones that are not "childs" but menus.
						if(oTable.childNodes[i].nextSibling)
						{
							//check if "oTable.childNodes[i].nextSibling" is the 
							//CHILDREN table , of the "oTable.childNodes[i]" row
							//the MenuLevel property could only be reached in a "brother" row,
							//and it is undefined in a "Children" row.
							 if(typeof(oTable.childNodes[i].nextSibling.MenuLevel)=="undefined")
							 {
								if (oTable.childNodes[i].nextSibling.style.display == "")
								{
									oTable.childNodes[i].nextSibling.style.display = "none";
									//changing the image to show that the menu is closed
									oTable.childNodes[i].childNodes[1].childNodes[0].src=sChannelImgSrc;
									oTable.childNodes[i].childNodes[0].className="Channel";
									oTable.childNodes[i].childNodes[1].className="Channel_BulletCell";
									oTable.childNodes[i].className="Channel";// sharon - add class to tr
								}
							}
						}
					}
					//if this TR is a Posting and not "this" menu -> "Disable" it
					else if(oTR!=oTable.childNodes[i] && (oTable.childNodes[i].className=="HighlightedMiddlePosting"))
					{
						oTable.childNodes[i].childNodes[0].className="MiddlePosting";
						oTable.childNodes[i].childNodes[1].className="MiddlePosting_BulletCell";
						oTable.childNodes[i].className="MiddlePosting";//add by sharon - set the class of highlight also to the TR
						oTable.childNodes[i].childNodes[1].childNodes[0].src=sPostingImgSrc;//change by shai g on 25.11.04
					}
				}
			}			
			oNextTR.style.display = "";
			//changing the image to show that the menu is open
			oTR.childNodes[1].childNodes[0].src=sHighChannelImgSrc;
			oTR.childNodes[0].className="HighlightedChannel";
			oTR.childNodes[1].className="HighlightedChannel_BulletCell";
			oTR.className="HighlightedChannel";// sharon - add class to tr
			oSecondLevelMenuOpen = oTR.nextSibling;
		}
		else   //closing a second level menu
		{
			oNextTR.style.display = "none";
			//changing the image to show that the menu is closed
			oTR.childNodes[1].childNodes[0].src=sChannelImgSrc;
			oTR.childNodes[0].className="Channel";
			oTR.childNodes[1].className="Channel_BulletCell";
			oTR.className="Channel";// sharon - add class to tr
		}
	}
}
			
function highlightPosting(oTD)
{
	var oTR;
	oTR = oTD.parentElement;
	var imgSrc;
	
	//change by shai g on 25.11.04: add icon to the postings (close and highlight)
	switch(oTR.getAttribute("MenuLevel"))
	{
		case "0":
		imgSrc=sTopHighPostingImgSrc;
		break;
		case "1":
		imgSrc=sHighPostingImgSrc;
		break;
		case "2":
		imgSrc=sHighChildImgSrc;
		break;
	}
	
	if(oTR.childNodes[0].className=="Posting")
	{
		oTR.childNodes[0].className="HighlightedPosting";
		oTR.childNodes[1].className="HighlightedPosting_BulletCell";
		oTR.className="HighlightedPosting";//add by sharon - set the class of highlight also to the TR
		oTR.childNodes[1].childNodes[0].src=imgSrc;//change by shai g on 25.11.04
	}
	else if(oTR.childNodes[0].className=="TopPosting")
	{
		oTR.childNodes[0].className="HighlightedTopPosting";
		oTR.childNodes[1].className="HighlightedTopPosting_BulletCell";
		oTR.className="HighlightedTopPosting";//add by sharon - set the class of highlight also to the TR
		oTR.childNodes[1].childNodes[0].src=imgSrc;//change by shai g on 25.11.04
	}
	else if(oTR.childNodes[0].className=="MiddlePosting")
	{
		oTR.childNodes[0].className="HighlightedMiddlePosting";
		oTR.childNodes[1].className="HighlightedMiddlePosting_BulletCell";
		oTR.className="HighlightedMiddlePosting";//add by sharon - set the class of highlight also to the TR
		oTR.childNodes[1].childNodes[0].src=imgSrc;//change by shai g on 25.11.04
	}
	
	//changing the image to show that the page is active - remove by shai g on 25.11.04
	//if(sHighChildImgSrc!="")
	//{
		//oTR.childNodes[1].childNodes[0].src=sHighChildImgSrc;
	//}
	
	if(guidHighlightedUniqueID!="")
		disableSubSub(guidHighlightedUniqueID)
	guidHighlightedUniqueID=oTR.getAttribute("LevelUniqueID");//TBD - shai
}
			
function disableSubSub(guidLevelUniqueID)
{
	//go through all "TR" element recoursively(on all levels)
	//in order to find the requested UniqueID
	var oTRCol = document.all.FirstLevelMainMenu.all.tags("TR");
	var oParentMenu;
	for(var i=0;i<oTRCol.length;i++)
	{
		//if the requested "TR" was found
		if(oTRCol[i].LevelUniqueID==guidLevelUniqueID)
		{
			if(oTRCol[i].childNodes[0].className=="HighlightedPosting")
			{
				oTRCol[i].childNodes[0].className="Posting";
				oTRCol[i].childNodes[1].className="Posting_BulletCell";
				oTRCol[i].className="Posting";// sharon - add class to tr
				oTRCol[i].childNodes[1].childNodes[0].src = sPostingImgSrc;
			}
			else if(oTRCol[i].childNodes[0].className=="HighlightedTopPosting")
			{
				oTRCol[i].childNodes[0].className="TopPosting";
				oTRCol[i].childNodes[1].className="TopPosting_BulletCell";
				oTRCol[i].className="TopPosting";// sharon - add class to tr
				oTRCol[i].childNodes[1].childNodes[0].src = sTopPostingImgSrc;
			}
			else if(oTRCol[i].childNodes[0].className=="HighlightedMiddlePosting")
			{
				oTRCol[i].childNodes[0].className="MiddlePosting";
				oTRCol[i].childNodes[1].className="MiddlePosting_BulletCell";
				oTRCol[i].className="MiddlePosting";// sharon - add class to tr
				oTRCol[i].childNodes[1].childNodes[0].src = sChildImgSrc;
			}
		}
	}
}

function OpenMenu(LevelUniqueID)
{
	//go through all "TR" element recoursively(on all levels)
	//in order to find the requested UniqueID
	var oTRCol = document.all.FirstLevelMainMenu.all.tags("TR");
	var oParentMenu;

	//go through all "TR" element recoursively(on all levels)
	//in order to find the requested UniqueID
	for(var i=0;i<oTRCol.length;i++)
	{
		//if the requested "TR" was found
		if(oTRCol[i].getAttribute("LevelUniqueID")==LevelUniqueID)
		{
		//alert(oTRCol[i].outerHTML)
			//the row has been found by it's Unique level ID
			bIsRowFound=true;
			//case this is a child(any Level Posting or any object on third level):
			if(oTRCol[i].getAttribute("isChild")=="1")
			{
				//Highlight this object
				highlightPosting(oTRCol[i].childNodes[1]);
				
				var iParentUniqueID,oParent;
				
				//for the recourtion, get the ParentMenu of this "TR"
				oParentMenu=getParentMenu(oTRCol[i]);
				
				//in case that this child has a parent and is not 
				//a top leveled child
				if(oParentMenu!=null)
				{
					//call the "OpenMenu" recoursively, to "open" it's parent
					OpenMenu(oParentMenu.previousSibling.getAttribute("LevelUniqueID"))
				}
				else
				{//Case this is a Top level Posting:
					//this is a posting therefore:
					oFirstLevelMenuOpen=CONST_MENU_WITH_NO_CHILDREN;
					//Keep a reference to the highlighted Posting
					oFirstLevelIndicator=oTRCol[i];
				}
			}
			else //case this is a Channel == "folder" (and not a third leveled one)
			{
				//Get the Parent menu of this Channel
				oParentMenu=getParentMenu(oTRCol[i]);
				
				//if this is the top level, and there is no parent
				if(oParentMenu==null)
				{
					//changing the image to show that the menu is open
					oTRCol[i].childNodes[1].childNodes[0].src=sTopHighChannelImgSrc;
					oTRCol[i].childNodes[0].className="HighlightedTopChannel";
					oTRCol[i].childNodes[1].className="HighlightedTopChannel_BulletCell";
					oTRCol[i].className="HighlightedTopChannel";
					
					//if there are any children for this folder -> open it, otherwise
					//only highlight it.
					if(oTRCol[i].nextSibling!=null)
					{
						//if the Children are Hidden
						if(oTRCol[i].nextSibling.style.display=="none")
						{
							//Display the Children
							oTRCol[i].nextSibling.style.display="";
							//Keep a reference to the highlighted Channel
							oFirstLevelMenuOpen=oTRCol[i].nextSibling;
						}
						else
						{
							//there are no Children to this channel, meaning, it is 
							//almost like a Posting
							oFirstLevelMenuOpen=CONST_MENU_WITH_NO_CHILDREN;
							oFirstLevelIndicator=oTRCol[i];
							
							//In case that there are no children we will change back
							//the Icon to "Collapsd Iamge" inorder not to show 
							//and "Open" icon with no children or sub menues.
							oTRCol[i].childNodes[1].childNodes[0].src=sTopHighPostingImgSrc;
						}
					}
					else
					{
						//there are no Children to this channel, meaning, it is 
						//almost like a Posting
						oFirstLevelMenuOpen=CONST_MENU_WITH_NO_CHILDREN;
						oFirstLevelIndicator=oTRCol[i];
					}
					
					return;
				}
				else
				{//if this is not the top level
					//changing the image to show that the menu is open
					oTRCol[i].childNodes[1].childNodes[0].src=sHighChannelImgSrc;
					oTRCol[i].childNodes[0].className="HighlightedChannel";
					oTRCol[i].childNodes[1].className="HighlightedChannel_BulletCell";
					oTRCol[i].className="HighlightedChannel";
					
					//if there is any "TR", show it = open the Children "TR" 
					//(if the next "TR" is just another Brother, it is
					//displayed anyway)
					if(oTRCol[i].nextSibling)
						oTRCol[i].nextSibling.style.display="";
					
					//make sure the Parent is displayed inorder for 
					//this to be displayed
					oParentMenu.style.display=""
					
					//Because this is only 3 levels menu, the Parent must be
					// a Top leveled menu(and the selected one)
					oFirstLevelMenuOpen=oParentMenu;
					
					//Keep a refernce to the second level opened menu
					oSecondLevelMenuOpen=oTRCol[i].nextSibling;
					
					//changing the images of the Parent to show that the 
					//menu is open
					oParentMenu.previousSibling.childNodes[1].childNodes[0].src=sTopHighChannelImgSrc;
					oParentMenu.previousSibling.childNodes[0].className="HighlightedTopChannel";
					oParentMenu.previousSibling.childNodes[1].className="HighlightedTopChannel_BulletCell";
					oParentMenu.previousSibling.className="HighlightedTopChannel";
				}
			}
		}
	}
}
			
function getParentMenu(currMenuTR)
{
	var oParentMenu;
	var bGoUp=true;
	var bTopLevelMenu=false;
	oParentMenu=currMenuTR.parentElement;
	while(bGoUp)
	{
		if(oParentMenu.tagName=="TR")
			bGoUp=false;
		else if(oParentMenu.id=="FirstLevelMainMenu")
		{ //this is atop keveled menu, there is no parent menu
			bGoUp=false;
			return null;
		}
		else
			oParentMenu=oParentMenu.parentElement;
	}
	return oParentMenu;
}
			
function writeMenuStart()
{
	var str;
	str="<TABLE border='0' id='FirstLevelMainMenu' cellSpacing='0' cellPadding='0' width='" + iMenuTableWidth + "'>\n";
	return str;
}
function writeMenuEnd()
{
	var str;
	str="</TABLE>\n";
	return str;
}
function DrawNewLevelTableEnd()
{
	var str="";
	str+="</table>";
	str+="</TD>"
	str+="</TR>"
	return str;
}
			
function DrawNewLevelTableStart()
{
	var str="";
	str+="<TR style='DISPLAY: none'>";
	str+="<TD colSpan='2'>";
	str+="<TABLE id='Table" + iTableUniqueID + "' border='0' cellSpacing='0' cellPadding='0' width='" + iMenuTableWidth + "'>\n";
	iTableUniqueID++;
	return str;
}

//separator row between channel groups
function addSeparatorRow()
{
	var sSeparatorRow = "";
	//sSeparatorRow = "<TR><TD class='MenuSeparatorRow' colspan='2'></td></tr>\n";
	//sSeparatorRow = sSeparatorRow + addSeparatorExtension();
	return sSeparatorRow;
}	

function addSeparatorExtension()
{
	var sSeparatorRow = "";
	//sSeparatorRow =  "<TR><TD class='MenuSeparatorRow1' colspan='2'></td></tr>\n";
	return sSeparatorRow;
}			


function writeMenuRow(iRowIndex)
{
	var str,sClassName,sRightTDOnClick,sLeftTDOnClick;
	var iLevel,sCaption,sLink,bIsDirectory,sImgSrc;
	var iChannelGroup;
	str="";
	sRightTDOnClick="";
	sLeftTDOnClick="";
	iIsChild="-1";
	sCaption=mnuArr[iRowIndex][0];
	iLevel=parseInt(mnuArr[iRowIndex][1]);
	sLink=mnuArr[iRowIndex][2];
	//set the Guid for this menu entry
	guidLevelUniqueID=mnuArr[iRowIndex][4];
	//get the channel group
	iChannelGroup = mnuArr[iRowIndex][5];
	
	
	//"c" stands for channel which is a directory
	//"p" stands for posting which is a page
	if(mnuArr[iRowIndex][3]=="c")
		bIsDirectory=true;
	else
		bIsDirectory=false;
				
	switch(iLevel)
	{
		case 0:
			if(bIsDirectory)
			{
				//alert("if" + sCaption);
				sRightTDOnClick="openCloseFirstLevelSub(this);";
				sLeftTDOnClick="openCloseFirstLevelSub(this.nextSibling);";
				iIsChild="0";
				sClassName="TopChannel";
				sImgSrc=sTopChannelImgSrc;
			}
			else
			{
				sClassName="TopPosting";
				sRightTDOnClick="highlightPosting(this);";
				sLeftTDOnClick="highlightPosting(this.nextSibling);";
				iIsChild="1";
				sImgSrc=sTopPostingImgSrc;
			}
			
		break;
		case 1:
			if(bIsDirectory)
			{
				sClassName="Channel";
				sRightTDOnClick="openCloseSecondLevelSub(this);";
				sLeftTDOnClick="openCloseSecondLevelSub(this.nextSibling);";
				iIsChild="0";
				sImgSrc=sChannelImgSrc;
			}
			else
			{
				sClassName="MiddlePosting";
				sRightTDOnClick="highlightPosting(this);";
				sLeftTDOnClick="highlightPosting(this.nextSibling);";
				iIsChild="1";
				sImgSrc=sPostingImgSrc;//change by shai g on 25.11.04
			}
			
		break;
		case 2:
			sClassName="Posting";
			sRightTDOnClick="highlightPosting(this);";
			sLeftTDOnClick="highlightPosting(this.nextSibling);";
			iIsChild="1";
			sImgSrc=sChildImgSrc;
		break;
		default:
			sClassName="Posting";
			sRightTDOnClick="highlightPosting(this);";
			sLeftTDOnClick="highlightPosting(this.nextSibling);";
			iIsChild="1";
			sImgSrc=sChildImgSrc;
		break;
	}
	
	if(sLink!="")
	{
		//if target value is 1(blank) - open in new window
		if(mnuArr[iRowIndex][6]==1)
			sLeftTDOnClick+="window.open(\"" + sLink + "\");"
		else
			sLeftTDOnClick+="document.location=\"" + sLink + "\";"
			
		if((iLevel==2)||(!bIsDirectory))
		{
			//if target value is 1(blank) - open in new window
			if(mnuArr[iRowIndex][6]==1)
				sRightTDOnClick+="window.open(\"" + sLink + "\");"
			else
				sRightTDOnClick+="document.location=\"" + sLink + "\";"
		}
	}
				
	if(iLastDrawnLevel>=0)
	{
		//if this is a new level of menus, a table should be added
		if(iLastDrawnLevel>iLevel)
		{
			var iNumOfTablesToClose;
			iNumOfTablesToClose=iLastDrawnLevel-iLevel;
			for(var j=0;j<iNumOfTablesToClose;j++)
			{
				str+=DrawNewLevelTableEnd();
			}
		}
	}
				
	if(iLastDrawnLevel>=0)
	{
		//if this is a new level of menus, a table should be added
		if(iLastDrawnLevel<iLevel)
		{
			str+=DrawNewLevelTableStart();
		}
	}
	
	//add an separate row before the menu row every time the gChannelGroup value is change 
	//(it Happened every time that the last parameter at mnuArr is change - represent the group of channel)	
	//if (gChannelGroup != iChannelGroup)//gChannelGroup & iChannelGroup start from 1
	//{
//		str+=addSeparatorRow();
	//	gChannelGroup = iChannelGroup;//update the global param with the new channel group id
	//}
	
	str+="<TR id='mnuTr" + iRowIndex + "' class='" + sClassName + "' isChild='" + iIsChild + "' LevelUniqueID=" + guidLevelUniqueID + " MenuLevel=" + iLevel + ">";
	str+="<TD class='" + sClassName + "' onclick='" + sLeftTDOnClick + "' "
	str+=" align=left width='" + iMenuLeftCellWidth + "'>" + sCaption + "</TD>";
	//set the class of the bullet cell according to the text cell: concatenation the name of the cell with "BulletCell" string - change by sharon on 20.7.04
	var bulletCellClass = sClassName + "_BulletCell";
	str+="<TD class='" + bulletCellClass + "' align=center ";
				
	//determine if this row represents a directory or a page
	if(sImgSrc!="")
	{
		str+="onclick='" + sRightTDOnClick + "' width='" + iMenuBulletCellwidth + "' valign='center'><IMG SRC='" + sImgSrc + "' BORDER=0 vspace='2'></TD>";
	}
	else
	{
		str+="onclick='" + sRightTDOnClick + "' width='" + iMenuBulletCellwidth + "'>&nbsp;</TD>";
	}

	str+="</TR>";
	
	iLastDrawnLevel=iLevel;
	//alert(str)
	return str;
}

function drawMenu(strAppPath)
{
	sTopChannelImgSrc = strAppPath + sTopChannelImgSrc;
	sTopHighChannelImgSrc = strAppPath + sTopHighChannelImgSrc;
	sChannelImgSrc = strAppPath + sChannelImgSrc;
	sHighChannelImgSrc = strAppPath + sHighChannelImgSrc;
	
	sTopPostingImgSrc = strAppPath + sTopPostingImgSrc;
	sTopHighPostingImgSrc = strAppPath + sTopHighPostingImgSrc;
	sPostingImgSrc = strAppPath + sPostingImgSrc;
	sHighPostingImgSrc = strAppPath + sHighPostingImgSrc;
	
	if(sChildImgSrc!="")
	{
		sChildImgSrc = strAppPath + sChildImgSrc;
	}
	if(sHighChildImgSrc!="")
	{
		sHighChildImgSrc = strAppPath + sHighChildImgSrc;
	}

	//Preloading all menu Images
	if(!preloadMenuFlag)
		preloadMenuImages();

	var str;
	str="";
	str+=writeMenuStart();
				
	//str+=addSeparatorRow()
	for(var i=0;i<mnuArr.length;i++)
	{
		str+=writeMenuRow(i);
	}
	str+=addSeparatorRow()
	str+=writeMenuEnd();
	//alert(str)
	document.all.MenuDiv.innerHTML = str;
}