/*
   xmlmenu.js

   author : delfan@shanghai
   current version : 1.0b fix 01
   =================================================
   version 1.0b fix 01: date : 2006-06-07 06:55 AM
   ------------
   note :
       + 增加支持菜单项内嵌HTML代码,格式为：
        <item subid="aaa">
            <caption>
                <img src="../resources/images/1.gif" onmouseover="this.src='../resources/images/2.gif'"/>
            </caption>
        </item>
       + 增加支持Action节点，用于处理脚本较多的情况，格式如下：
            <item caption="s4gg(action)" >
                <action>
                    <![CDATA[
                    alert('a');
                    alert('b');
                    alert('c');
                    ]]>
                </action>
            </item>

       + 增加支持菜单项的图标
       + 增加了XML文件中定义样式表，格式如下：
       <menus>
         <styles>
            <style id="root-style">border:0; cursor:default;padding:1px 10px 1px 10px;</style>
            <style id="sub-group">border:1px solid #000000; cursor:default; padding:2px; background-color:#ffffff;</style>
            <style id="item-mouseover">border:1px solid blue; background-color:#a0ffff; padding:1px 9px 1px 9px; cursor:default</style>
            <style id="subitem-mouseover">border:5px solid blue; background-color:#a0ffff; cursor:default</style>
          </styles>
         ......(菜单定义)
        </menus>
   =================================================
   version 1.0b : date : 2006-06-07 03:09 AM
   ------------
   note :
     + 两种初始化方式：
       1. Xmlmenu.init(容器，菜单定义的xml串)
       2. Xmlmenu.initFromFile(容器, 菜单定义的xml文件名);
     + 不会被网页上的select等元素遮挡.
     + 支持鼠标离开菜单后2秒自动关闭。
     + 不向页面添加任何事件处理程序，所有事件均在菜单内完成
     + 支持菜单放在任意容器内，可任意位置。
     + 依赖ui库及engine库很少的函数，可抽取出作为独立菜单库执行(依赖：ui.$(), ui.getElementDim(), engine.LoadXML())
   bug :
     。因为不向document.body添加任何事件处理，因此当单击菜单外的元素时，菜单不马上关闭。
     。未支持菜单项的图片
     。未支持菜单分组
     。未支持菜单项内嵌HTML代码
     。未支持独立样式表文件
   ==================================================
*/
var ui = {
    // 确定控值的绝对位置
    getElementDim : function(el) {
        for (var lx = 0,ly = 0; el != null;
             lx += el.offsetLeft,ly += el.offsetTop,el = el.offsetParent) {
            if (el.tagName.toLowerCase() == "div" && el.style.position == "relative") {
                ly = ly - el.offsetTop;
                ly = ly + (el.offsetTop - el.scrollTop);
            }
        }
        return {x:lx,y:ly}
    },

    $ : function(idValue) {
        return document.getElementById(idValue);
    }	
}

var engine = {
    getDOMParse : function(xmlStr) {
        if (window.DOMParser) {
            var p = new DOMParser();
            return p.parseFromString(xmlStr, "text/xml");
        } else if (window.ActiveXObject) {
            var doc = new ActiveXObject("Microsoft.XMLDOM");
            doc.async = "false";
            doc.loadXML(xmlStr);
            return doc;
        } else {
           // alert(tips[0]);
            return null;
        }
    },	
    loadXML : function(filename) {
            var doc = new ActiveXObject("Microsoft.XMLDOM");
            doc.async = "false";
            doc.load(filename);
            return doc;
    }	
}

var Xmlmenu = {
    styles : [
            'root-style=border:0; cursor:hand;padding:1px 20px 1px 20px;font:normal bold 13px arial;',
            'sub-group=border:1px solid #000000; cursor:hand; padding:2px; background-color:red; font:normal bold 14px arial;',
            'item-mouseover=border:1px solid blue; background-color:#a0ffff; color:red; padding:1px 9px 1px 9px; cursor:default',
            'subitem-mouseover=border:1px solid blue; background-color:#a0ffff; cursor:default',
            'new-menu-1=background-color:#EDEDED;color:#000;border-top:#EAD4C8 1px solid;',
            'new-menu-2=background-color:#89CBCA;',
            'new-menu-3=background-color:#EDEDED;color:#000;border-bottom:#EAD4C8 0px solid;',
            'new-menu-4=background-color:#8C92B7;color:#fff;border-bottom:#EAD4C8 0px solid;',
            ],

    getCSS : function(cssName) {
        for (var i = 0; i < this.styles.length; i++) {
            var value = this.styles[i].split("=");
            if (cssName.toUpperCase() == value[0].toUpperCase())
                return value[1];
        }
        return "";
    },
    setCSS : function(cssName, newCSS) {
        for (var i = 0; i < this.styles.length; i++) {
            var value = this.styles[i].split("=");
            if (cssName.toUpperCase() == value[0].toUpperCase()) {
                this.styles[i] = cssName + "=" + newCSS;
                break;
            }
        }
    },
    _initStyle : function(styleList) {
        for (var i = 0; i < styleList.length; i++)
            this.setCSS(styleList[i].getAttribute("id"), styleList[i].text )
    },
    
    _chanUppCase : function(name) {
    	var value=name;
    	if (value != null && typeof(value)=="string") {
           value = value.toUpperCase();
    	}
    	return value;
    },	
    initFromFile : function(container, xmlFile, lang) {
        dom = engine.loadXML(xmlFile);
       // alert(dom.xml);
        Xmlmenu.init(container, dom.xml, lang);
    },
    init : function(container, xmlStr, lang) {     // lang :语言，缺省是EN
        if(lang==null) lang = "EN";
        container.innerHTML = '';
        container.isMenuGroup = true;
        container.rootID = container.id;
        container.onmouseover = container.onmouseout = container.onclick = Xmlmenu._processEvent;
        _buildRoot = function(element) {
            var items = element.getElementsByTagName("item");
            //for (var i = items.length-1; i >= 0;  i--) {
            for (var i = 0; i < items.length ;  i++) {
            	
            	var span = document.createElement("span");
            	container.appendChild(span);

                span.innerHTML = items[i].getAttribute("icon") == null ? "" : "<img src='" + items[i].getAttribute("icon") + "'>";
                
                var topmname = items[i].getAttribute(lang) == null
                        ? items[i].getElementsByTagName(lang).length == 0 ? "undefined" : items[i].getElementsByTagName(lang)[0].xml
                        : items[i].getAttribute(lang);
                topmname = Xmlmenu._chanUppCase(topmname);
                span.innerHTML += "<font style='height:20px;'>" + topmname +"</font>"; 
                //if(i==0)alert(span.innerHTML);
                                            
                //span.style.cssText = Xmlmenu.getCSS('root-style'); 
                span.style.cssText = "width:auto;padding:1px 36px 0px 36px; cursor:hand;font:normal normal 11px Arial;color:#ffffff";
                
                span.isMenuItem = true;
                span.oldcssText = span.style.cssText;
                span.subMenu = items[i].getAttribute("subid") == null ? "" : items[i].getAttribute("subid");
                span.itemLevel = 1;
                span.rootID = container.id;
                span.actionText = items[i].getAttribute("action") == null
                        ? items[i].getElementsByTagName("action").length == 0 ? "" : items[i].getElementsByTagName("action")[0].text
                        : items[i].getAttribute("action");
            	
            	if(i!=items.length-1){
                  var spanwal = document.createElement("span");
            	  container.appendChild(spanwal);
            	  spanwal.innerHTML="<font style='height:25px;'></font>"
            	  spanwal.style.cssText = "border-right:1px solid #84AEBD;"
            	}
            	
            	/*
                var span = document.createElement("SPAN");
                container.appendChild(span);

                span.innerHTML = items[i].getAttribute("icon") == null ? "" : "<img src='" + items[i].getAttribute("icon") + "'>";
                span.innerHTML += items[i].getAttribute(lang) == null
                        ? items[i].getElementsByTagName(lang).length == 0 ? "undefined" : items[i].getElementsByTagName(lang)[0].xml
                        : items[i].getAttribute(lang);
                                            
                span.style.cssText = Xmlmenu.getCSS('root-style'); 
                span.style.cssText = "FILTER:shadow(color=red,direction=225);height:26px;border:1px solid #949694; border-right:5px solid #ffffff; padding:1px 20px 0px 20px; cursor:hand;font:normal bold 18px Times New Roman;color:#ffffff";
                span.isMenuItem = true;
                span.oldcssText = span.style.cssText;
                span.subMenu = items[i].getAttribute("subid") == null ? "" : items[i].getAttribute("subid");
                span.itemLevel = 1;
                span.rootID = container.id;
                span.actionText = items[i].getAttribute("action") == null
                        ? items[i].getElementsByTagName("action").length == 0 ? "" : items[i].getElementsByTagName("action")[0].text
                        : items[i].getAttribute("action");
                 */       
                
            }
        };
        _buildSub = function(element) {
            var tbl = document.createElement("table");
            tbl.onmouseover = tbl.onmouseout = tbl.onclick = Xmlmenu._processEvent;
            tbl.id = element.getAttribute("id");
            with (tbl.style) {
                cssText = Xmlmenu.getCSS('sub-group');
                cssText = 'border:1px solid #000000; cursor:hand; padding:2px; background-color:#94B6BD; font:normal bold 11px arial;color:#fff',
                position = 'absolute';
                display = "none";
                font='normal bold 9pt arial';
            } 
            tbl.isMenuGroup = true;
            tbl.cellSpacing = 0;
            tbl.cellPadding = 0;
            tbl.rootID = container.id;
            var items = element.getElementsByTagName("item");
            for (var i = 0; i < items.length; i++) {
                var tr = tbl.insertRow(tbl.rows.length);
                tr.rootID = container.id;
                tr.insertCell();
                // 存放图像用

                var td = tr.insertCell();
                tr.insertCell();
                // 如果有子菜单
                td.innerHTML = items[i].getAttribute(lang) == null
                        ? items[i].getElementsByTagName(lang).length == 0 ? "undefined" : items[i].getElementsByTagName(lang)[0].xml
                        : items[i].getAttribute(lang);
                td.rootID = container.id;
                td.isMenuItem = true;
                td.style.padding = '1px 15px 1px 5px';
                //tr.style.font='normal bold 18px Times New Roman';
                tr.style.font='normal normal 12px Arial';
                tr.style.cursor="hand";
                tr.oldcssText = tr.style.cssText;
                
                tr.itemLevel = 2;
                tr.cells[0].innerHTML = items[i].getAttribute("icon") == null ? ""
                        : "<img src='" + items[i].getAttribute("icon") + "'>";
                tr.cells[0].isMenuItem = true;
                tr.cells[0].rootID = container.id;
                tr.cells[2].isMenuItem = true;
                tr.cells[2].rootID = container.id;
                tr.subMenu = items[i].getAttribute("subid") == null ? "" : items[i].getAttribute("subid");
                tr.actionText = items[i].getAttribute("action") == null
                        ? items[i].getElementsByTagName("action").length == 0 ? "" : items[i].getElementsByTagName("action")[0].text
                        : items[i].getAttribute("action");
                if (tr.subMenu != "") {
                    tr.cells[2].innerHTML = "<font face=Webdings size=1>4</font>";
                    tr.actionText = "";
                }
            }

            document.body.appendChild(tbl);

            // 为了解决select等遮挡问题
            var over = document.createElement("<iframe src='about:blank' style='position:absolute;left:0;top:0;z-index:998;display:none' scrolling='no' frameborder='3'>fsdfsdfadsfa</iframe>");
            document.body.insertAdjacentElement("beforeEnd", over);
            tbl.over = over;
        };
        var dom = engine.getDOMParse(xmlStr);
        if(dom.getElementsByTagName("styles").length>0) this._initStyle(dom.getElementsByTagName("styles")[0].getElementsByTagName("style"));
        //alert(dom.documentElement);
        var list = dom.documentElement.getElementsByTagName("menu");
        for (var i = 0; i < list.length; i++) {
            if (list[i].getAttribute("id") == "root") _buildRoot(list[i]);
            else _buildSub(list[i]);
        }
        // end of for
    },  // end of init function
    
    _processEventT : function() {
        // 新开发的竖向菜单的鼠标点击事件处理
        var srcElement = Xmlmenu._getRoot(event.srcElement);
        if (!srcElement) return;
        if (srcElement.isMenuItem) {	
        	
            var item = srcElement;
            //if (item.tagName == "TD") item = item.parentNode;
            //item = item.parentNode;
            //item= item.parentNode;
            var parentItem = item.parentNode.tagName == "TBODY" ? item.parentNode.parentNode : item.parentNode;
            switch (event.type) {
                case 'click' :                   
                    if (item.subMenu != '' && item.subMenu) {
                    	if(srcElement.tagName == "IMG"){
                    	   var cn=0;
                           var sub = ui.$(item.subMenu+cn);
                           Xmlmenu._displaySub(item.subMenu);
                        }
                        //Xmlmenu._showSubT(item.subMenu,cn);
                        //if (sub.style.display.toUpperCase() == 'NONE') Xmlmenu._showSubT(sub,cn);
                        //else Xmlmenu._hideSubT(sub);
                    }
                    else {
                    	//alert(item.tagName);
                    	//item = item.parentNode;
                        eval(item.actionText);
                    }  
                    break;
                case 'mouseover' :
                    if(item.itemLevel == 1){
                    	//item.style.cssText= "border-right:2px solid #EAD4C8;padding:1px 10px 2px 9px; cursor:hand;font:normal bold 18px Times New Roman;color:gold";
                    }else if(item.itemLevel == 2){
                        item.style.color= "#8BCCAE";	
                    }else if(item.itemLevel == 3){
                        item.style.color= "#E4B3EB";	 
                    }	
                   
                    break;
                case 'mouseout' :
                    //item.style.cssText = item.oldcssText;
                    if(item.itemLevel == 1){
                    	//item.style.cssText= "border-right:2px solid #EAD4C8;padding:1px 10px 2px 9px; cursor:hand;font:normal bold 18px Times New Roman;color:gold";
                    }else if(item.itemLevel == 2){
                        item.style.color = "#000";	
                    }else if(item.itemLevel == 3){
                        item.style.color= "#000";	
                    }	
                    break;    
                    
            }
        }
    	
    }	,
    
    getMenu:function(container,xmlFile, lang){
    	
    	//container.onmouseover = container.onmouseout = container.onclick = Xmlmenu._processEvent;
    	container.onmouseover = container.onmouseout = container.onclick = Xmlmenu._processEventT;
    	
    	_buildRootForO = function(element,listmenus) {
            var items = element.getElementsByTagName("item");
            for (var i = 0; i < items.length ;  i++) {
            	
            	var subid=items[i].getAttribute("subid") == null ? "" : items[i].getAttribute("subid");
            	
            	var tr = container.insertRow(container.rows.length);
            	
            	var td = tr.insertCell();
            	
                //var img = document.createElement("IMG");
            	//td.appendChild(img);
            	//img.style.cssText="";
            	//img.src='/res/images/menu-folder1-close.gif';	
            	//td.background='/res/images/menu_vertical1.gif';
            	td.style.cssText = Xmlmenu.getCSS('new-menu-1');
            	//td.style.border="1px solid red";
            	td.height='25';
            	var title=items[i].getAttribute(lang) == null
                        ? items[i].getElementsByTagName(lang).length == 0 ? "undefined" : items[i].getElementsByTagName(lang)[0].xml
                        : items[i].getAttribute(lang);
                title = Xmlmenu._chanUppCase(title);        
            	td.innerHTML = "<img id=imgT"+subid+" src='/res/images/menu-folder1-close.gif' style='cursor:hand' align='middle'>"+ title;
            	 
                //td.innerHTML=title;
                //alert(td.innerHTML);
                td.style.cursor='default';
                
                var imgitem=ui.$("imgT"+subid);
                imgitem.isMenuItem=true;
                imgitem.subMenu=items[i].getAttribute("subid") == null ? "" : items[i].getAttribute("subid");
                imgitem.title="menulevel is first";
                
                if(imgitem.subMenu!=""){imgitem.subMenu = "T"+imgitem.subMenu;}

                //tr.isMenuItem = true;      
                //tr.subMenu = items[i].getAttribute("subid") == null ? "" : items[i].getAttribute("subid"); 
                //tr.title="p0pe";
                //alert(tr.menulevel);
                
                //执行子菜单        
                        
                for (var j = 0; j < listmenus.length; j++) {
                   if (listmenu[j].getAttribute("id") == subid) {
                      //var trline = container.insertRow(container.rows.length);
            	      //   var tdline = trline.insertCell();
            	          //tdline.background='/res/images/menu_ver_buttonline2.gif';
            	          //tdline.style.cssText = Xmlmenu.getCSS('new-menu-2');
            	          //tdline.height='1';
            	          
                      var subitems = listmenu[j].getElementsByTagName("item");
                      for (var k = 1; k < subitems.length+1 ;  k++) {
                          _bulidGroundMenu(container,subid,subitems[k-1],k,2);
                          
                          if(subitems[k-1].getAttribute("subid")!=null){
                              	
                              for (var m = 0; m < listmenu.length; m++) {
                              	 if (listmenu[m].getAttribute("id") == subitems[k-1].getAttribute("subid")) {
                              	    
                              	    var groundItems = listmenus[m].getElementsByTagName("item");
                              	    //alert("subin1="+subitems[k].getAttribute("subid"));
                              	    var groundId=subitems[k-1].getAttribute("subid");
                              	    //alert("groundId="+groundId);
                              	    for (var n = 0; n < groundItems.length ;  n++) {
                              	        _bulidGroundMenu(container,groundId,groundItems[n],n,3);	 
                                    }  
                              	    
                              	 }	
                              }	
                            
                          }   
                            
                            
                      }      
                   }
              	
                } 	  
                       
            } 
            
        };
        
        //最底层的menu td
        _bulidGroundMenu = function(container,subid,subitem,n,menulevel){
        	var tdheight='';
        	var tdcss='';        	
        	if(menulevel==2){
        		tdheight='22';
            	        tdcss='new-menu-3';
            	}else if(menulevel==3){
            	        tdheight='22'; 
            	        tdcss='new-menu-4'; 
            	}	   
        	var trsub = container.insertRow(container.rows.length);           	 
            	trsub.subMenu = subitem.getAttribute("subid") == null ? "" : subitem.getAttribute("subid");   
            	if(trsub.subMenu != ""){
            	    trsub.subMenu="T"+trsub.subMenu;	
            	}	
            	//trsub.menulevel= menulevel;     
            	
            	   var tdsub = trsub.insertCell();
            	          trsub.id="T"+subid+n;
            	          //tdsub.id=subid+n;
            	          //alert(subid);
            	          tdsub.height=tdheight;
            	          tdsub.style.cssText = Xmlmenu.getCSS(tdcss);
            	          tdsub.isMenuItem = true;
            	          tdsub.itemLevel=menulevel;
            	          with (trsub.style) {
                            //position = 'absolute';
                            display   = "none";
                            size = "18px"; 
                          }
            	                     	        
                          tdsub.actionText = subitem.getAttribute("action") == null
                              ? subitem.getElementsByTagName("action").length == 0 ? "" : subitem.getElementsByTagName("action")[0].text
                              : subitem.getAttribute("action");  
                          
                          var title= subitem.getAttribute(lang) == null
                            ? subitem.getElementsByTagName(lang).length == 0 ? "undefined" : subitem.getElementsByTagName(lang)[0].xml
                            : subitem.getAttribute(lang);
                          if(title == "Cargo Tracking(Enhanced)"){
                              	//alert(title);
                             title = "Cargo Tracking"+"<Font color='blue'>"+"(Enhanced)"+"</font>";                        	
                          }   
                          if(trsub.subMenu!=""){
                              tdsub.innerHTML = "<img id=imgT"+subid+n+" src='/res/images/menu-folder1-close.gif' style='cursor:hand' align='middle'>"+ title; 
        	              tdsub.style.padding="0px 0px 0px 20px";
        	              tdsub.style.cursor='default';
        	              var imgitem=ui.$("imgT"+subid+n);
        	              //alert(imgitem.id);
                              imgitem.isMenuItem = true;
                              imgitem.subMenu=subitem.getAttribute("subid") == null ? "" : subitem.getAttribute("subid");
                              
                              if(imgitem.subMenu != ""){
            	                 imgitem.subMenu="T"+imgitem.subMenu;	
            	              }
        	              imgitem.title="menulevel is second";
        	          }else{
        	              if(menulevel==2){
        	                 tdsub.style.padding="0px 0px 0px 35px";
        	              }else if(menulevel==3){
        	                 tdsub.style.padding="0px 0px 0px 45px";
        	              }	
        	              tdsub.innerHTML =  title; 
        	              tdsub.style.cursor='hand';
        	          }
        	          
                
        };
        
    	dom = engine.loadXML(xmlFile);
        var listmenu = dom.documentElement.getElementsByTagName("menu");
        for (var i = 0; i < listmenu.length; i++) {
            if (listmenu[i].getAttribute("id") == "root") {
            	_buildRootForO(listmenu[i],listmenu);
            }		
        }
        
    },	
    
    _isInnerElement : function(ele) {
        var result = false;
        //  alert(result)
        while (ele.isMenuItem == null && ele.isMenuGroup == null) {
            if (ele.tagName == "BODY") break;
            ele = ele.parentNode;
            if (ele.isMenuItem || ele.isMenuGroup) {
                result = true;
                break;
            }
        }
        return result;
    },

    _getRoot : function (ele) {
        while (ele.isMenuItem == null && ele.isMenuGroup == null) {
            if (ele.tagName == "BODY") return null;
            ele = ele.parentNode;
        }
        return ele;
    },
    _processEvent : function() {
        // 处理鼠标移出菜单的情况
        if (event.type == "mouseout" && event.toElement && event.toElement.isMenuItem == null
                && event.toElement.isMenuGroup == null) {
            if (! Xmlmenu._isInnerElement(event.toElement)) {
                var ele = Xmlmenu._getRoot(event.srcElement);
                if (!ele) return;
                if (! ui.$(ele.rootID).clearTimer)
                    ui.$(ele.rootID).clearTimer = setTimeout("Xmlmenu._hideAll('" + ele.rootID + "')", 500);
            }
        }

        // 循环找到菜单项目，用于处理用户定义的数据中有图像等HTML代码的情况
        var srcElement = Xmlmenu._getRoot(event.srcElement);
        if (!srcElement) return;
        if (srcElement.isMenuItem) {	
            var item = srcElement;
            if (item.tagName == "TD") item = item.parentNode;
            var parentItem = item.parentNode.tagName == "TBODY" ? item.parentNode.parentNode : item.parentNode;
            switch (event.type) {
                case 'click' :
                    if (item.subMenu != '') {
                        var sub = ui.$(item.subMenu);
                        if (sub.style.display.toUpperCase() == 'NONE') Xmlmenu._showSub(item);
                        else Xmlmenu._hideSub(sub);
                    }
                    else {
                        Xmlmenu._hideAll(item.rootID);
                        eval(item.actionText);
                    }
                    break;
                case 'mouseover' :
                    if (parentItem.activedItem) Xmlmenu._hideSub(parentItem.activedItem);
                    item.style.cssText = item.itemLevel == 1 ? Xmlmenu.getCSS("item-mouseover") :  Xmlmenu.getCSS("subitem-mouseover");
                    if(item.itemLevel == 1){
                    	//item.style.cssText= "border-right:5px solid #ffffff;;padding:1px 20px 1px 20px; cursor:hand;font:normal normal 15pt Impact;color:gold";
                        item.style.cssText= "width:auto;padding:1px 36px 0px 36px; cursor:hand;font:normal normal 11px Arial;color:#ffffff"
                    }else if(item.itemLevel == 2){
                        //item.style.cssText= "border:1px solid blue; background-color:#5AAEAD;cursor:hand;font:normal bold 18px Times New Roman;color:#ffffff";	
                        item.style.cssText= "border:1px solid blue; background-color:#5AAEAD;cursor:hand;font:normal normal 12px Arial;color:#ffffff";	
                    }	
                    var rootEle = ui.$(item.rootID);
                    if (rootEle.clearTimer) {
                        clearTimeout(rootEle.clearTimer);
                        rootEle.clearTimer = null;
                    }
                    Xmlmenu._showSub(item);
                    break;
                case 'mouseout' :
                    item.style.cssText = item.oldcssText;
                    break;
            }
        }
    },

    _hideAll : function (rootID) {
        var root = ui.$(rootID);
        if (root.activedItem) Xmlmenu._hideSub(root.activedItem);
    },

    _hideSub : function (grpEle) {
        with (grpEle.style) {
            display = 'none';
            zIndex = 0;
        }
        grpEle.over.style.display = 'none';
        var sub = grpEle.activedItem;
        if (sub != null) Xmlmenu._hideSub(sub);
        grpEle.activedItem = null;
    },

    _showSub : function(item) {
    	//if(item.title!="")return;
        if (item.subMenu && item.subMenu != '') {
            var sub = ui.$(item.subMenu);
            var dim = ui.getElementDim(item);
            //alert(item.title);
            with (sub.style) {
            	
                left = item.itemLevel == 1 ? dim.x : dim.x + item.offsetWidth - 2;
                top = item.itemLevel == 1 ? dim.y + item.offsetHeight - 1 : dim.y;
                //alert(sub.id);
                display = "";
                //alert(sub.parentNode.tagName);
                zIndex = 9999;
            }
            //alert(item.parentNode.tagName);
            with (sub.over.style) {
                top = sub.style.top;
                left = sub.style.left;
                width = sub.offsetWidth;
                height = sub.offsetHeight;
                display = '';
                zIndex = 9998;
            }
            if (item.parentNode.tagName == "TBODY") item = item.parentNode;
            item.parentNode.activedItem = sub;
        }
    },
    
     _showSubT : function(sub,cn) {
     	var topstatus =''; 
     	//alert(sub);
     	while(ui.$(sub+cn) ) {
     	   //alert(5);	
           var subtd = ui.$(sub+cn);	
           
     	   if(subtd.parentNode.tagName=='TBODY') {
     	       if (subtd.style.display.toUpperCase() == 'NONE')	{
     	           with (subtd.style) {
     	       	     display = '';
     	           }	
     	           topstatus='open';
     	       }else{
     	           with (subtd.style) {
     	       	     display = 'NONE';
     	           }
     	           topstatus='close'; 
     	       }	
     	   }    	
     	   //alert(6);
           if(topstatus=='close'){
           	//alert(7);
     	       Xmlmenu._hideSubT(sub+cn,0);
           }
           
           cn=cn+1;
        }
        //alert(8);
        var img=ui.$("img"+sub);
        if(topstatus=='open'){
           img.src='/res/images/menu-folder1-open.gif';     	
        }else if(topstatus=='close'){
           img.src='/res/images/menu-folder1-close.gif';	
        }	
        //alert(9);		
     },

     _hideSubT : function(sub,cn){
	//alert("19="+sub);
     	while(ui.$(sub+cn) ) {
     	   	
           var subtd = ui.$(sub+cn);
     	   with (subtd.style) {
     	      display = 'NONE';	
     	   }
     	   
     	   Xmlmenu._hideSubT(sub+cn,0);

           cn=cn+1;
        }
        
        var img=ui.$("img"+sub);
        if(ui.$("img"+sub)){
            img.src='/res/images/menu-folder1-close.gif'; 		
     	}
     },	
     
     _displaySub : function(subIn) {
     	
     	var context=Xmlmenu.getContext();
        var item= ui.$("img"+subIn);
        //alert(item.tagName);
        //alert(item.subMenu);
        if(item.title=="menulevel is second"){
           Xmlmenu._showSubT(subIn,0);
           //var img=ui.$('img'+subIn);
           //if(img.src==context+'res/images/menu-folder1-open.gif'){
           //     img.src='/res/images/menu-folder1-close.gif';    	
           //}else if(img.src==context+'res/images/menu-folder1-close.gif'){ 	 
           //     img.src='/res/images/menu-folder1-open.gif';	
           //}
           return;	
        }
     	
     	var listmenu = dom.documentElement.getElementsByTagName("menu");
        for (var i = 0; i < listmenu.length; i++) {
            if (listmenu[i].getAttribute("id") == "root") {
                 var items = listmenu[i].getElementsByTagName("item");
                 for (var j = 0; j < items.length ;  j++) {
                     var subid=items[j].getAttribute("subid"); 
                        
                        if(subIn=="T"+subid){
                             Xmlmenu._showSubT(subIn,1);
                             
                             //var img=ui.$('img'+subid);
                             //if(img.src==context+'res/images/menu-folder1-open.gif'){
                             //    img.src='/res/images/menu-folder1-close.gif';    	
                             //}else if(img.src==context+'res/images/menu-folder1-close.gif'){ 	 
                             //    img.src='/res/images/menu-folder1-open.gif';	
                             //}
                             
                        }else{
                             Xmlmenu._hideSubT("T"+subid,1);   
                             //var img=ui.$('img'+subid);
                             //img.src='/res/images/menu-folder1-close.gif';    	

                        }
                         
                 }
            
            }		
            
        }
        	
        
     	
    } ,
    
    getContext:function(){	
      var loc =document.location+"";
      var urlEnd =loc.indexOf("module"); 	
      var contextUrl = loc.substring(0,urlEnd);	
      return contextUrl;
    } 	
     
}