//ListMenu.js file. used only in frame with files/folders list. Includes
//Java Script functions to show drop down menu.
//Before modify something here see  JS_CSS_VERSION element in HTCOMNET\web.config file!!!

var CurrentMenu = null;
var CloseMenusWhileNavigation = false;
var DelayPopDown = 200;
var scrollmode=false;
var locked=false;
var goritemstyle='z-index:106;float:left;padding:3px;color:Black;font-size:8pt;font-family:Tahoma;height:100%;cursor:pointer;cursor:hand;';
var veritemstyle='padding:2px;color:Black;font-size:8pt;font-family:Tahoma;cursor:pointer;cursor:hand;';
var vertselitemstyle='color:#FFFFFF;backgroundColor:#316AC5;borderColor:#316AC5;';
var gorselitemstyle='color:#FFFFFF;backgroundColor:#316AC5;borderColor:#316AC5;';
var needtoShowScroll=false; 

function DrawListMenuBody(inpscroll)
{
	document.write('<table ID="MainMenu" main="true" cellspacing="0" cellpadding="0" style="background-color:#EEEAD6;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:450;z-index:101;position:static;left:0;top:0;"><tr><td valign="top"><nobr><IMG width="7" height="20" SRC="images/menuvertline.gif" style="float:left;">')
	wig('MenuItemFile', DDM_FILE, 'SubMenuFile');
	wig('MenuItemEdit', DDM_EDIT, 'SubMenuEdit');
	wig('MenuItemView', DDM_VIEW, 'SubMenuView');
	wig('MenuItemDU', DDM_DU, 'SubMenuDU');
	if(window.parent.topFrame.CanWrite && (window.parent.topFrame.CanZip || window.parent.topFrame.CanUnzip))
		wig('MenuItemZU', DDM_ZU, 'SubMenuZU', '#FF6600');
	locked=!inpscroll
	document.write('</td><td width="50" valign="top"><input onclick="lockmenu()" ' + ((locked)?'checked':'')  + ' type=checkbox>&nbsp;' + LOCK + '</td></tr></table>');
	
	document.write('<table ID="SubMenuFile" cellspacing="0" cellpadding="0" onmouseout="LMenu_OnMouseOutSubMenu(event,this);" style="background-color:White;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:150px;padding:2px;visibility:hidden;left:380px;top:0px;position:absolute"><tr><td valign="top">');
	if(window.parent.topFrame.CanWrite || window.parent.topFrame.CanUpload)
	{
		wiv('MenuItemFile_New', DDM_NEW, 'SubMenuFile_New', true);
		line('MenuItemFile_Line1');
	}
	if(window.parent.topFrame.CanWrite)
		wiv('MenuItemFile_OpenInTextEditor', DDM_OPEN_IN_TEXT, false, false,'doaction(\'open_editor\',\'\');');
	if(window.parent.topFrame.CanWrite)
		wiv('MenuItemFile_Delete', MENU_DELETE,false,false,'doaction(\'showdelete\');');
	if(window.parent.topFrame.CanWrite)
		wiv('MenuItemFile_Rename', MENU_RENAME,false,false,'doaction(\'rename\');');
	wiv('MenuItemFile_Properties', MENU_PROPERTIES,false,false, 'doaction(\'viewinfo\');');
	line('MenuItemFile_Line2');
	if(window.parent.topFrame.CanAddProperties)
	{
		wiv('MenuItemFile_AdvProperties', MENU_ADV_PROPERTIES,false,false, 'doaction(\'AdvProperties\',\'\');');
		line('MenuItemFile_Line3');
	}
	wiv('MenuItemFile_Exit', DDM_EXIT ,false, false,'doaction(\'logoff\');');
		
	document.write('</td></tr></table>');

	document.write('<table ID="SubMenuFile_New" cellspacing="0" cellpadding="0" onmouseout="LMenu_OnMouseOutSubMenu(event,this);" style="background-color:White;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:90px;padding:2px;visibility:hidden;left:380px;top:0px;position:absolute"><tr><td valign="top">');
	
	if(window.parent.topFrame.CanWrite || window.parent.topFrame.CanUpload)
		wiv('MenuItemFile_New_Folder', DDM_FOLDER,false,false,'doaction(\'createdir\');');
	if(window.parent.topFrame.CanWrite)
		wiv('MenuItemFile_New_File', DDM_FILE,false,false,'doaction(\'createfile\');');
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
		wiv('MenuItemFile_New_ZIP', DDM_ZIP,false,false,'doaction(\'makezip\');');
	
	document.write('</td></tr></table>');

	document.write('<table ID="SubMenuEdit" cellspacing="0" cellpadding="0" onmouseout="LMenu_OnMouseOutSubMenu(event,this);" style="background-color:White;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:120px;padding:2px;visibility:hidden;left:380px;top:0px;position:absolute"><tr><td valign="top">');
	if(window.parent.topFrame.CanWrite)
		wiv('MenuItemEdit_Cut', MENU_CUT,false,false, 'doaction(\'cut\');');
	if(window.parent.topFrame.CanWrite)
		wiv('MenuItemEdit_Copy', MENU_COPY,false,false, 'doaction(\'showcopy\');');
	if(window.parent.topFrame.CanWrite)
	{
		wiv('MenuItemEdit_Paste', MENU_PASTE,false,false, 'doaction(\'paste\');');
		line('MenuItemEdit_Line1');
	}
	wiv('MenuItemEdit_Search', MENU_SEARCH,false,false, 'doaction(\'findfile\');');
	line('MenuItemEdit_Line2');
	wiv('MenuItemEdit_SelectAll', DDM_SELECT_ALL,false,false,'doaction(\'selectall\');');			
	wiv('MenuItemEdit_InvertSelection', DDM_INVERT,false,false,'doaction(\'InvertSelection\');');
	
	document.write('</td></tr></table>');
	
	document.write('<table ID="SubMenuView" cellspacing="0" cellpadding="0" onmouseout="LMenu_OnMouseOutSubMenu(event,this);" style="background-color:White;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:160px;padding:2px;visibility:hidden;left:380px;top:0px;position:absolute"><tr><td valign="top">');
	
	wiv('MenuItemView_View', DDM_VIEW_IN_NEW, false,false,'doaction(\'open_download\',\',true\');');
	wiv('MenuItemView_Refresh', DDM_REFRESH,false,false,'doaction(\'fresh\');');
	
	document.write('</td></tr></table>');
	
	document.write('<table ID="SubMenuDU" cellspacing="0" cellpadding="0" onmouseout="LMenu_OnMouseOutSubMenu(event,this);" style="background-color:White;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:135px;padding:2px;visibility:hidden;left:380px;top:0px;position:absolute"><tr><td valign="top">');
	
	wiv('MenuItemDU_Download', MENU_DOWNLOAD,false,false, 'doaction(\'open_download\',\'\');');
	if(window.parent.topFrame.CanFTP)
		wiv('MenuItemDU_DownloadFTP',MENU_FTPDOWNLOAD, false,false, 'doaction(\'ftpdownload\');');
	
	if(window.parent.topFrame.CanUpload)
		wiv('MenuItemDU_Upload', DDM_UPLOAD,false,false, 'doaction(\'open_upload\');');
	
	if(window.parent.topFrame.CanUpload && window.parent.topFrame.CanFTP)
		wiv('MenuItemDU_UploadFTP', DDM_FTPUPLOAD,false,false, 'doaction(\'open_uploadFTP\');');
	
	if(window.parent.topFrame.CanUpload && window.parent.topFrame.CanFlash8)
		wiv('MenuItemDU_UploadFlash8', DDM_FLASH8UPLOAD,false,false, 'doaction(\'open_uploadFlash8\');');		
		
	document.write('</td></tr></table>');

	document.write('<table ID="SubMenuZU" cellspacing="0" cellpadding="0" onmouseout="LMenu_OnMouseOutSubMenu(event,this);" style="background-color:White;font-size:8pt;font-family:Tahoma;border-width:1px;border-style:solid;border-color:#ACA899;width:140px;padding:2px;visibility:hidden;left:380px;top:0px;position:absolute"><tr><td valign="top">');
	
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
		wiv('MenuItemZU_CreateNewZIP', DDM_CREATE_NEW_ZIP,false,false,'doaction(\'makezip\');');
	
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
		wiv('MenuItemZU_AddToZIP', MENU_ADD_TO_ZIP,false,false,'doaction(\'addzip\');');
	
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
		wiv('MenuItemZU_AddToNewZIP', MENU_ADD_TO_NEW_ZIP,false,false,'doaction(\'addnewzip\');');
	
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanUnzip)
		wiv('MenuItemZU_ExtractToFolder', MENU_EXTRACT,false,false,'doaction(\'extractzip\');');
	
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanUnzip)
		wiv('MenuItemZU_ViewZIPContent', MENU_VIEW_CONTENT,false,false,'doaction(\'viewcontent\');');
	
	if(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip)
		wiv('MenuItemZU_SelectZIP', MENU_SELECT_ZIP,false,false,'doaction(\'SelectZIP\');');
		
	document.write('</nobr></td></tr></table>');
	

}


function ListMenuGray(id)
{
	var IndArray=SelectedInd.split(";");	
	var IsOne=(IndArray.length==3);
	var IsFew=(IndArray.length>3);
	if(IsOne)
		var filename=eval("window.parent.List.document.form.i"+ IndArray[1] + ".value");
		
	switch(id)
	{
		case 'MenuItemFile':		
			if(IsOne)
			{
				var edit=window.parent.topFrame.EditStr.lastIndexOf(';' + Ext(filename) + ';')
				
				SetMenuItem('MenuItemFile_OpenInTextEditor', (window.parent.topFrame.CanWrite && edit!=-1 && IndArray[1]>folders));
				SetMenuItem('MenuItemFile_Delete', (window.parent.topFrame.CanWrite));				
				SetMenuItem('MenuItemFile_Rename', (window.parent.topFrame.CanWrite));				
				AvailableMenuItem('MenuItemFile_Properties');	
				SetMenuItem('MenuItemFile_AdvProperties',(window.parent.topFrame.CanAddProperties));
			}			
			else if(IsFew)
			{
				GrayMenuItem('MenuItemFile_OpenInTextEditor');
				SetMenuItem('MenuItemFile_Delete',(window.parent.topFrame.CanWrite));
				GrayMenuItem('MenuItemFile_Rename');
				AvailableMenuItem('MenuItemFile_Properties');	
				GrayMenuItem('MenuItemFile_AdvProperties');		
			}
			else
			{
				GrayMenuItem('MenuItemFile_OpenInTextEditor');
				GrayMenuItem('MenuItemFile_Delete');		
				GrayMenuItem('MenuItemFile_Rename');		
				GrayMenuItem('MenuItemFile_Properties');
				GrayMenuItem('MenuItemFile_AdvProperties');			
			}
			break;
		
		case 'MenuItemEdit':
			if(IsOne)
			{
				SetMenuItem('MenuItemEdit_Cut',(window.parent.topFrame.CanWrite));
				SetMenuItem('MenuItemEdit_Copy',(window.parent.topFrame.CanWrite));
			}			
			else if(IsFew)
			{
				SetMenuItem('MenuItemEdit_Cut',(window.parent.topFrame.CanWrite));
				SetMenuItem('MenuItemEdit_Copy',(window.parent.topFrame.CanWrite));
			}
			else
			{
				GrayMenuItem('MenuItemEdit_Cut');
				GrayMenuItem('MenuItemEdit_Copy');
			}
			break;
		case 'MenuItemView':
			if(IsOne)
			{
				var view=window.parent.topFrame.ViewStr.lastIndexOf(';' + Ext(filename) + ';')
				SetMenuItem('MenuItemView_View', (view!=-1 && IndArray[1]>folders));
			}			
			else if(IsFew)
			{
				GrayMenuItem('MenuItemView_View');
			}
			else
			{
				GrayMenuItem('MenuItemView_View');
			}
			break;
		case 'MenuItemDU':
			if(IsOne)
			{
				SetMenuItem('MenuItemDU_Download',(IndArray[1]>folders));					
				AvailableMenuItem('MenuItemDU_DownloadFTP');
			}			
			else if(IsFew)
			{
				GrayMenuItem('MenuItemDU_Download');		
				AvailableMenuItem('MenuItemDU_DownloadFTP');
			}
			else
			{
				GrayMenuItem('MenuItemDU_Download');		
				GrayMenuItem('MenuItemDU_DownloadFTP');
			}
			break;
		case 'MenuItemZU':		
			if(IsOne)
			{
				SetMenuItem('MenuItemZU_AddToZIP', (window.parent.List.zip && window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip))
				SetMenuItem('MenuItemZU_AddToNewZIP',(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip));
				SetMenuItem('MenuItemZU_ExtractToFolder',(Ext(filename)=="ZIP" && IndArray[1]>folders));			
				SetMenuItem('MenuItemZU_ViewZIPContent',(Ext(filename)=="ZIP" && IndArray[1]>folders));			
				SetMenuItem('MenuItemZU_SelectZIP',(Ext(filename)=="ZIP" && IndArray[1]>folders));
				
			}			
			else if(IsFew)
			{
				SetMenuItem('MenuItemZU_AddToZIP', (window.parent.List.zip && window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip))
				SetMenuItem('MenuItemZU_AddToNewZIP',(window.parent.topFrame.CanWrite && window.parent.topFrame.CanZip));
				GrayMenuItem('MenuItemZU_ExtractToFolder');			
				GrayMenuItem('MenuItemZU_ViewZIPContent');			
				GrayMenuItem('MenuItemZU_SelectZIP');
			}
			else
			{
				GrayMenuItem('MenuItemZU_AddToZIP')
				GrayMenuItem('MenuItemZU_AddToNewZIP');
				GrayMenuItem('MenuItemZU_ExtractToFolder');			
				GrayMenuItem('MenuItemZU_ViewZIPContent');			
				GrayMenuItem('MenuItemZU_SelectZIP');
			}
			break;
			
	}
}


function wig(id, text, submenuid, color)
{
	var s=''
	var mycolor=(color)?color:"#000000";

	document.write('<TABLE cellspacing="0" cellpadding="0" donthide="true" style="float:left;">'+
		'<tr>' + 
		'<td style="padding:0px 0px 0px 0px;"><TABLE gor="true" cellpadding="0" cellspacing="0" ID="' + id + '" submenu_id="' + submenuid + '" submenu_open="over"' + 
		' style="' + goritemstyle + '"'+
		' onmouseout="if (!ismouseout(event, this)) return false;LMenu_OnMouseOut(event,this);" onmouseover="ListMenuGray(\'' + id + '\');LMenu_OnMouseOver(event,this);"'+
		'>'+
		'<TR>'+
		'<TD align="left" style="width:2px;"><span style="width:2px"></span></TD>'+
		'<TD align="left"><nobr>' + text + '</nobr></TD>'+
		'<TD style="text-decoration:none;">&nbsp;</TD>'+
		'</TR>'+
		'</TABLE>'+
		'</td>'+
		'</tr>'+
		'</TABLE>');
}

function wiv(id, text, submenuid, hassubmenu, click)
{

	var myclick=(click)?click + ";LMenu_OnMouseClick(event,this);":"LMenu_OnMouseClick(event,this);";
	document.write('<TABLE cellspacing="0" cellpadding="0" donthide="true" width="100%">' + 
	'<tr>'+
	'<td style="padding:0px 0px 0px 0px;">'+
	'<TABLE dontclick="" cellpadding="0" cellspacing="0" width="100%" ID="' + id + '" submenu_id="' + submenuid + '" submenu_open="over" style="' + veritemstyle + '"'+
	' onmouseout="if(this.getAttribute(\'dontclick\')==\'yes\') return false;if (!ismouseout(event, this)) return false;LMenu_OnMouseOut(event,this);" onmouseover="if(this.getAttribute(\'dontclick\')==\'yes\') return false;LMenu_OnMouseOver(event,this);"'+
	' onclick="if(this.getAttribute(\'dontclick\')==\'yes\') return false;' + myclick + '">'+
	'<TR>'+
	'<TD align="left" style="width:1em;"><span style="width:1em"></span></TD>'+
	'<TD align="left"><nobr>' + text + '</nobr></TD>' +
	(hassubmenu?'<TD align="right" style="line-height:70%;font-family:webdings;">4</TD>':
			'<TD><span style="width:1em">&nbsp;</span></TD>') + 
	'</TR>'+
	'</TABLE>'+
	'</td>'+
	'</tr>'+
	'</TABLE>');
}	
	

function line(id)
{
	document.write('<HR size="1" ID="' + id + '" style="position:static;padding:0px;color:Black;border-style:solid;border-color:#B2B4BF;height:1px;">');
}	

function GrayMenuItem(id)
{
	var item=document.getElementById(id)
	if(item)
	{
		if(item.onclick!=null)
		{		
			item.style.color='#ACA899';
			item.setAttribute("dontclick", "yes")
		}	
	}
}

function AvailableMenuItem(id)
{
	var item=document.getElementById(id);
	if(item)
	{
		if(item.getAttribute("dontclick")=="yes")
		{
	
			item.style.color='Black';
			item.setAttribute("dontclick", "")
		}
	}
}


function doaction(funcname, atr)
{
	var filename=null
	var index=null;
	var IndArray=SelectedInd.split(";")
	if(IndArray.length==3)
	{
		filename=eval("window.parent.List.document.form.i"+ IndArray[1] + ".value")
		index=IndArray[1]
	}
	if(!atr)
		atr='';
	if(funcname=='open_editor' || funcname=='open_download' || funcname=='AdvProperties')
		eval("window.parent.topFrame." + funcname + "('" + index + "'" + atr + ");")
	else
		eval("window.parent.topFrame." + funcname + "(" + atr + ");");

}

function ShowScroll()
{
	if(scrollmode && needtoShowScroll)
	{
		if (document.body)
			x = document.body.scrollLeft;

		if (document.body)
			y = document.body.scrollTop;
		var menuobj=document.getElementById('MainMenu');
		var headerobj=document.getElementById('ListHeader');
		
		menuobj.style.left=x+8;
		menuobj.style.top= y;
		headerobj.style.left=8;
		headerobj.style.top= y + menuobj.offsetHeight;
		menuobj.style.visibility='visible';
		headerobj.style.visibility='visible';
		needtoShowScroll=false;
	}
}
 
function bodyscroll(Ev)
{
	if(locked) return;
	if (document.body)
		x = document.body.scrollLeft;

	if (document.body)
		y = document.body.scrollTop;

	var menuobj=document.getElementById('MainMenu');
	var headerobj=document.getElementById('ListHeader');
	if(y<22)
	{
		if(scrollmode)
		{
			menuobj.style.position='static';
			//menuobj.style.borderColor="#F5F5F5";		
			headerobj.style.position='static';
			menuobj.style.visibility='visible';
			headerobj.style.visibility='visible';
			needtoShowScroll=false;
			//refresh table. bug in IE
			document.getElementById('listTable').outerHTML=document.getElementById('listTable').outerHTML;
			scrollmode=false;
		}
	}
	else
	{
		if(!scrollmode)
		{
			menuobj.style.position='absolute';
			//menuobj.style.borderColor="#ACA899";			
			headerobj.style.position='absolute';
			scrollmode=true;
		}
		menuobj.style.visibility='hidden';
		headerobj.style.visibility='hidden';
		window.setTimeout('ShowScroll()', 800);
		needtoShowScroll=true;
	}

}

function lockmenu()
{
	if(ie50 || Netscape7 || Netscape8 || Opera6 || Opera7 || Opera8) return;
	if(!locked)
	{
		var menuobj=document.getElementById('MainMenu');
		menuobj.style.position='static';
		menuobj.style.borderColor="#F5F5F5";
		
		var headerobj=document.getElementById('ListHeader');
		headerobj.style.position='static';
		
		//refresh table. bug in IE
		document.getElementById('listTable').outerHTML=document.getElementById('listTable').outerHTML;
		scrollmode=false;
		locked=true;	
	}
	else
	{
		locked=false	
	}
	window.parent.leftFrame.location.href="ExecActions.aspx?action=scrollmenu&value=" + ((locked==true)?"no":"yes");
}


function LMenu_OnMouseClick(ev, item)
{
    LMenu_OnMouseOver(ev, item);
    PopDownAndUnselect(CurrentMenu);
}


function LMenu_OnMouseOver(ev, item)
{
    var src = null;
    if (ev.srcElement)
        src = ev.srcElement;
    else if (ev.target)
        src = ev.target;
    if (src != item && !IsobjContains(item, src))
        return;
    SelectItem(item);
}


function LMenu_OnMouseOut(ev, item)
{
    var tgt;
    if (ev.relatedTarget)
        tgt = ev.relatedTarget;
    else if (ev.toElement)
        tgt = ev.toElement;
    if (!tgt || (tgt != item.submenu && !IsobjContains(item.submenu, tgt)))
    {
        UnSelectItem(item);
    }
}

function PopDownOut()
{
    if (!CloseMenusWhileNavigation && CurrentMenu)
    {
        PopDownAndUnselect(CurrentMenu);
        CurrentMenu = null;
    }
}


function LMenu_OnMouseOutSubMenu(ev, submenu)
{
    var tgt;
    if (ev.relatedTarget)
        tgt = ev.relatedTarget;
    else if (ev.toElement)
        tgt = ev.toElement;
    while (tgt && getSubMenu(tgt))
    {
        if (IsobjContains(submenu, tgt) || tgt == CurrentMenu || getAttribute(tgt, 'parent_item'))
            return;
        tgt = getParent(tgt);
    }
    CloseMenusWhileNavigation = false;
    if (window.setTimeout)
        window.setTimeout('PopDownOut()', DelayPopDown);
    else
        PopDownOut();
}

function SelectItem(item)
{
    CloseMenusWhileNavigation = true;
    var menu = getSubMenu(item);

    if (menu.sel_item == item)
        return;
    if (menu.sel_item)
    {
        UnSelectItem(menu.sel_item);
        CloseMenusWhileNavigation = true;
    }
    if (menu.menu_item && menu.menu_item != item)
        PopDownItem(menu.menu_item)
    if (!menu.parent_item)
    {
        if (CurrentMenu && CurrentMenu != menu)
        {
            PopDownAndUnselect(CurrentMenu);
            CurrentMenu = null;
        }
    }
    else
    {
        if (getSubMenu(menu.parent_item).sel_item != menu.parent_item)
            SelectItem(menu.parent_item);
    }
    
    if (CurrentMenu == null)
        CurrentMenu = menu;
            
    PopUpItem(item);
    HiliteItem(item, true);
    menu.sel_item = item;
    
    CloseMenusWhileNavigation = true;
}

function UnSelectItem(item)
{
    if (getAttribute(item, 'submenu_id'))
    {
        if (window.setTimeout)
            window.setTimeout('PopDownItemDelayed("' + item.id + '")', DelayPopDown);
        else
            PopDownItem(item);
    }
    HiliteItem(item, false);
    if (getSubMenu(item).sel_item == item)
        getSubMenu(item).sel_item = null;
    if (CurrentMenu == getSubMenu(item) && !CurrentMenu.menu_item)
        CurrentMenu = null;
}

function PopUpItem(item)
{
    var submenu_id = getAttribute(item, 'submenu_id');
    if (submenu_id)
    {
        var submenu = document.getElementById(submenu_id);
        if (submenu)
        {
            ShowSubMenu(item, submenu);
            item.submenu = submenu;
            submenu.parent_item = item;
            getSubMenu(item).menu_item = item;
        }
    }
}

function PopDownItemDelayed(id)
{
    var item = document.getElementById(id);
    if (item && getSubMenu(item).sel_item != item)
        PopDownItem(item);
}


function PopDownItem(item)
{
    var submenu = item.submenu;
    if (submenu)
    {
        if (submenu.menu_item)
            PopDownItem(submenu.menu_item);
        if (submenu.sel_item)
            UnSelectItem(submenu.sel_item);
        submenu.style.left=380;
        submenu.style.top=0;
        submenu.style.visibility='hidden';
        submenu.parent_item = null;
        item.submenu = null;
        getSubMenu(item).menu_item = null;
        if (CurrentMenu == getSubMenu(item) && !CurrentMenu.sel_item)
            CurrentMenu = null;
    }
}

function PopDownAndUnselect(menu)
{
    if (menu)
    {
        if (menu.menu_item)
            PopDownItem(menu.menu_item);
        if (menu.sel_item)
            UnSelectItem(menu.sel_item);
    }
}


function HiliteItem(item, on)
{
    if (on)
    {
        if(getAttribute(item, 'gor')=='true')
			SetStyles(item,  gorselitemstyle)
		else
			SetStyles(item,  vertselitemstyle);
    }
    else
    {
		if(getAttribute(item, 'gor')=='true')
			RemoveStyles(item, gorselitemstyle)
		else
			RemoveStyles(item, vertselitemstyle);
    }
}

function ShowSubMenu(item, submenu)
{
	submenu.style.zIndex = 110;
	
	var tx, ty;
	var leftToRight = true;
	var topToBottom = true;

    var itm = getParent(item);
    while (itm != null && !itm.tagName == 'TABLE' && menu.tagName != 'SPAN')
    {
		itm = getParent(item);	
    }
    if (getAttribute(item, 'donthide') != 'true')
        itm = item;

	if (getAttribute(getSubMenu(item), 'main')) 
	{
	        if (leftToRight)
        		tx = Xoffset(itm) - Xoffset(submenu.offsetParent);
	        else
        		tx = Xoffset(itm) - submenu.offsetWidth + itm.offsetWidth;

	        if (topToBottom)
        		ty = Yoffset(itm) - Yoffset(submenu.offsetParent) + itm.offsetHeight;
	        else    
        		ty = Yoffset(itm) - submenu.offsetHeight;

			if (tx + submenu.offsetWidth > document.body.clientWidth + document.body.scrollLeft)
			{
				tx = document.body.clientWidth  + document.body.scrollLeft - submenu.offsetWidth - 5; 
			}
			if (tx <  document.body.scrollLeft)
				tx =  document.body.scrollLeft;
	}
	else 
	{
        if (leftToRight)
			tx = Xoffset(itm) - Xoffset(submenu.offsetParent) + itm.offsetWidth;
		else
			tx = Xoffset(itm) - submenu.offsetWidth + 8;
		ty = Yoffset(itm) - Yoffset(submenu.offsetParent);
		if (!topToBottom)
			ty = ty - (submenu.offsetHeight - itm.offsetHeight);

		if (tx + submenu.offsetWidth > document.body.clientWidth +  document.body.scrollLeft)
		{
			tx = tx - submenu.offsetWidth - itm.offsetWidth + 8; 
		}
		if (tx <  document.body.scrollLeft)
			tx =  document.body.scrollLeft;
	    	
	}
	submenu.style.left = tx;
	submenu.style.top = ty;	
	submenu.style.visibility='visible';
}

function getSubMenu(item)
{
    var menu = getParent(item);
    while (menu != null && ((menu.tagName != 'SPAN' && menu.tagName != 'TABLE') || getAttribute(menu, 'donthide') == 'true'))
    {
        menu = getParent(menu);
    }
    return menu;	
}

