Context Menu - Load according to tree id

My tree code

//tree layout
    dhxLayout.cells("a").setText("Server");
    dhxLayout.cells("a").setWidth(250);
    dhxLayout.cells("a").hideArrow();
    dhxTree = dhxLayout.cells("a").attachTree();
    dhxTree.setImagePath("imgs/icon/tree/");
    dhxTree.setXMLAutoLoading("xml/tree_serverlist.php");
    dhxTree.enableHighlighting(true);
    dhxTree.enableKeyboardNavigation(true);
    dhxTree.enableContextMenu(Contextmenu);
    dhxTree.loadXML("xml/tree_serverlist.php");
    dhxTree.attachEvent("onClick",function(id)
    {
        showDirContent(id);
    });	
    dhxTree.attachEvent("onBeforeContextMenu", function(itemId) 
    {
        //alert(itemId);
                
        if(itemId=="server_top")
        {
            
            Contextmenu.showItem('add_server');
            Contextmenu.hideItem('connect_server');  
            Contextmenu.hideItem('edit_server');
            Contextmenu.hideItem('view_server');
            Contextmenu.hideItem('delete_server');
            Contextmenu.hideItem('file_sep_2');
            Contextmenu.hideItem('file_sep_1');
            Contextmenu.hideItem('disconnect_server');
            
            
                      
        }
        else
        {
            Contextmenu.hideItem('add_server'); 
            Contextmenu.showItem('connect_server'); 
            Contextmenu.showItem('file_sep_1');
            Contextmenu.showItem('edit_server');
            Contextmenu.showItem('view_server');  
            Contextmenu.showItem('delete_server'); 
            Contextmenu.showItem('file_sep_2');
            Contextmenu.hideItem('disconnect_server');
        }
       
        return true;
       }); 
    //end

This is my tree code. I used the hide/show method to load my context menu. But as the system grows, i want the context menu load according to my tree id

My context menu

//tree context menu
    Contextmenu = new dhtmlXMenuObject();
    Contextmenu.setIconsPath("imgs/icon/");
    Contextmenu.renderAsContextMenu();
    Contextmenu.attachEvent("onClick", onContextMenuClick);
    Contextmenu.loadXML("xml/context_menu.php");
    //end

and my xml file

<?php
header('Content-type: application/xml');

include $_SERVER['DOCUMENT_ROOT']."My_Phanto/class/server_class.php";
include $_SERVER['DOCUMENT_ROOT']."My_Phanto/class/web_service.php";
include $_SERVER['DOCUMENT_ROOT']."My_Phanto/class/connect.php";


$id=$_REQUEST[id];

//$id is the tree id.

?>
<menu id="0">


<item text="Add Server" img="add.png" id="add_server"/>



<item text="Connect Server" img="connect.png" id="connect_server"/>



<item text="Disconnect Server" img="disconnect.png" id="disconnect_server"/>

<item id="file_sep_1" type="separator"/>
<item text="Edit Server Information" img="edit.png" id="edit_server"/>
<item text="View Server Information" img="view.png" id="view_server"/>

<item id="file_sep_2" type="separator"/>
<item text="Delete Server" img="delete.png" id="delete_server"/>

</menu>

Is there anyway to load my context menu according to my tree id?

Please help me…Thanks.

Hello
Working code sample:

[code]menu = new dhtmlXMenuObject();
menu.renderAsContextMenu();
menu.setIconsPath("…/dhtmlxMenu/samples/common/imgs/");
menu.loadXML("…/___xml/data_tree_menu_context.xml");

        dhxTree = new dhtmlXTreeObject("mytree", "300px", "300px", 0);
		dhxTree.setImagePath("../dhtmlxTree_prof/codebase/imgs/csh_vista/");
		dhxTree.loadXML("../___xml/data_tree_components.xml");
        dhxTree.enableContextMenu(menu);
		dhxTree.attachEvent("onBeforeContextMenu", function(id) {
			if (dhxTree.hasChildren(id) > 0) {
				menu.showItem('add');
			} else {
				menu.hideItem('add');
			}
			return true;
		});[/code]

Tree xml:

<?xml version='1.0'?> <tree id="0" radio="1"> <item text="Components" id="comp"> <item text="Using Container" id="cont" open="1"> <item text="dhtmlxLayout" id="lay"/> <item text="dhtmlxAccordion" id="acc"/> <item text="dhtlmxTabbar" id="tab"/> <item text="dhtmlxWindows" id="win"/> </item> <item text="Using Data" id="data" open="1"> <item text="dhtmlxGrid" id="grd"/> <item text="dhtmlxTree" id="tre"/> <item text="dhtmlxMenu" id="men"/> <item text="dhtmlxToolbar" id="too"/> </item> </item> </tree>
Menu xml:

[code]<?xml version='1.0' ?>

[/code]

Hi Darya,

Thanks for the reply.

You are welcome!