﻿<!--
//DriveHQ web treeview, support XML datasource, delete/cut/copy/paste.
//Powered by DriveHQ
var GlobalXmlDataSource;//cache data source.
var FirstExpandNodeUrl = "";

function DHQTreeView(Tname)
{
  if(typeof(Tname) != "string" || Tname == "")
    throw(new Error(-1, 'class name is required!'));
  
  //【property】


  this.url      = "#";
  this.target   = "_self";
  this.name     = Tname;
  this.wordLine = false;
  this.currentNode = null;
  this.useArrow = false;
  this.nodes = {};
  this.node  = {}; 
  this.UrlClientID = {};
  this.names = "";
  this.remoteUrl = "";
  this.index = 0;
  this.divider   = "_";
  this.navigator = "";
  this.setLevel  = 3;
  this.loadSize  = 300;
  this.displayTip = false;
  this.tempDataSource = {};
  this.navigateurlID  = "";
  this.showMenu = false;
  this.node["0"] =
  {
    "id": "0",
    "path": "0",
    "isLoad": false,
    "childNodes": [],
    "childAppend": "",
    "type" : "",
    "url"  : "",
    "text" : "",
    "icon" : "",
    "navigateurl" : ""
  };

  this.colors   =
  {
    "highLight" : "#0A246A",
    "highLightText" : "#FFFFFF",
    "mouseOverBgColor" : "#D4D0C8"
  };
  
  this.icons    = {
    L0        : 'L0.gif',  //┏

    L1        : 'L1.gif',  //┣

    L2        : 'L2.gif',  //┗

    L3        : 'L3.gif',  //━

    L4        : 'L4.gif',  //┃

    PM0       : 'P0.gif',  //＋┏
    PM1       : 'P1.gif',  //＋┣
    PM2       : 'P2.gif',  //＋┗
    PM3       : 'P3.gif',  //＋━
    empty     : 'L5.gif',     //empty image
    root      : 'root.gif',   //default root icon
    Folder    : 'folder.gif', //default folder icon
    Inbox     : 'Inbox.gif',
    Sent      : 'Sent.gif',
    Draft     : 'Draft.gif',
    Trash     : 'Trash.gif',
    Bulk      : 'Bulk.gif',
    loading   : 'treeview-loading.gif'     
  };
  this.iconsExpand = {  //expand icons
    PM0       : 'M0.gif',     //－┏
    PM1       : 'M1.gif',     //－┣
    PM2       : 'M2.gif',     //－┗
    PM3       : 'M3.gif',     //－━
    Folder    : 'folderopen.gif'
  };

  //serch obj by id
  //id : client id
  this.getElementById = function(id)
  {
    if (typeof(id) != "string" || id == "") return null;
    if (document.getElementById) return document.getElementById(id);
    if (document.all) return document.all(id);
    try {return eval(id);} catch(e){ return null;}
  }

  //DHQTreeView Init function
  this.toString = function()
  {
    this.load("0");
    var rootCN = this.node["0"].childNodes;
    var str=new Array();
    str.push("<A id='"+ this.name +"_RootLink' href='#' style='DISPLAY: none'></A>");
    var len = rootCN!=null ? rootCN.length : 0;
    if(len>0)
    {
      this.node["0"].hasChild = true;
      for(var i=0; i<len; i++)
        str.push(this.nodeToHTML(rootCN[i], i==len-1));
      setTimeout(this.name +".expand('"+ rootCN[0].id +"', true); "+ this.name +".atRootIsEmpty();",10);
       //"+ this.name +".focusClientNode('"+ rootCN[0].id +"'); "
    }
    
    if (this.useArrow)  //
    {
      if (document.attachEvent)
          document.attachEvent("onkeydown", this.onkeydown);
      else if (document.addEventListener)
          document.addEventListener('keydown', this.onkeydown, false);
    }
    var frmMenu = getFrmMenu();
    this.setStyle();
    var frmManage = "";
    return "<DIV class='DHQTreeView' id='"+ this.name +"DHTreeView'"+
      "onclick='"+ this.name +".clickHandle(event)' "+
      "ondblclick='"+ this.name +".dblClickHandle(event)' "+
      ""+
      ">"+ str.join("") +"</DIV>"+frmMenu+frmManage;    
  };

  this.onkeydown= function(e)
  {
    e = window.event || e; var key = e.keyCode || e.which;
    switch(key)
    {
      case 37 : eval(Tname).upperNode(); break;  //Arrow left, shrink child node
      case 38 : eval(Tname).pervNode();  break;  //Arrow up
      case 39 : eval(Tname).lowerNode(); break;  //Arrow right, expand child node
      case 40 : eval(Tname).nextNode();  break;  //Arrow down
    }
  };
}

//Create XML Object。

var createXMLDom=function(){
	if (window.ActiveXObject) 
		var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
	else 
		if (document.implementation&&document.implementation.createDocument)
			var xmldoc=document.implementation.createDocument("","",null);
	xmldoc.async = false;
	xmldoc.preserveWhiteSpace=true;	
	return xmldoc;
}

var createXMLHttp=function(){
	var xmlHttp;
	if (window.ActiveXObject){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		xmlHttp=new XMLHttpRequest();
	}
	return xmlHttp;
}

DHQTreeView.prototype.ShowMenu = function(showMenu)
{
    this.showMenu = showMenu;
};

DHQTreeView.prototype.LoadXML = function(forceLoad)	
{
   this.browserCheck();
   var DOMRoot;
   
   if(GlobalXmlDataSource == null || forceLoad)
   {
      DOMRoot=this.GetRemoteXML(this.remoteUrl);
   }
   else
   {
      DOMRoot=GlobalXmlDataSource;
   }   
   
   if(DOMRoot==null)
        return;//alert(DOMRoot);
   GlobalXmlDataSource = DOMRoot;
   this.index = 0;
   this.node.length = 1;
   this.FillXmltoDataSource(DOMRoot, 0);   
};

DHQTreeView.prototype.GetRemoteXML = function(url)
{
    var xmlDom = createXMLDom();     
    if(xmlDom == null)   
    {
        return null;
    }
    
    try{
	    
	    var xmlHttp=createXMLHttp();
		    xmlHttp.onreadystatechange = function(){
			    if(xmlHttp.readyState == 4 && xmlHttp.status==200){
				    xmlDom = xmlHttp.responseXML; 				    
			    }else{
				    window.state="Getting remote data...";
			    }
		    }		
		    if(this.navigator == "msie")
		        xmlHttp.setRequestHeader("Cache-Control","no-cache");//clear cache in IE browser.
		        
		    xmlHttp.open("GET",url,false);
		    xmlHttp.send(null);		 
    }
    catch(e){
        xmlDom.load(url);    		   
    }
   if(this.navigator == "mozilla" || this.navigator == "firefox" || this.navigator=="netscape")
   {
        var oParser = new DOMParser();
        xmlDom = oParser.parseFromString(xmlHttp.responseText, "text/xml");
   }
   var DOMRoot=xmlDom.documentElement; 
   return DOMRoot;
}

DHQTreeView.prototype.FillXmltoDataSource = function(pNodes, parentId)
{
    if(pNodes==null)
        return;
        
    var subNode = null;
    var i=0;
    while(subNode=pNodes.childNodes[i])  
    {
        if(subNode.nodeType!=1) 
        {
            ++i;
            continue;//empty node
        }    
                       
         /*--------------------------------------------*/         
        this.index++;  
        var text  = subNode.getAttribute("Text");
        var hint  = text;
        var url   = subNode.getAttribute("NavigateUrl"+this.navigateurlID);
        var icon  = subNode.getAttribute("imageurl");
        var msgboxID = subNode.getAttribute("MsgBoxID");
        var objID = subNode.getAttribute("ObjID");
        var type  = subNode.getAttribute("Type");
        var subFoldersCount = subNode.getAttribute("subFoldersCount"); 
        subFoldersCount = parseInt(subFoldersCount);
        this.node[this.index] =
        {
            "id"    : this.index,
            "text"  : text,
            "hint"  : hint ? hint : text,
            "icon"  : icon,
            "msgboxID" : msgboxID,
            "objID": objID,
            "isLoad": false,
            "isExpand": false,
            "parentId": parentId,
            "parentNode" : this.node[parentId],
            "childAppend" : "",
            "url"         : url,
            "type"        : type,
            "subFolderCount" : subFoldersCount
        };

        var hasChild = subNode.hasChildNodes()==false ? (subFoldersCount>0) : true;         
        this.node[this.index].hasChild = hasChild;//hasChild;
        if(this.node[this.index].hasChild)  this.node[this.index].childNodes = [];
        this.UrlClientID[url] = this.index;   
        this.node[parentId].childNodes[this.node[parentId].childNodes.length] = this.node[this.index];           
         /*--------------------------------------------*/   
        this.totalNode = this.index;                
        if(subNode.hasChildNodes())
        {
            this.FillXmltoDataSource(subNode, this.index);
        }
        ++i;
    }
};

//check browser
DHQTreeView.prototype.browserCheck = function()
{
  var ua = window.navigator.userAgent.toLowerCase(), bname;
  if(/msie/i.test(ua))
  {
    this.navigator = /opera/i.test(ua) ? "opera" : "";
    if(!this.navigator) this.navigator = "msie";
  }
  else if(/gecko/i.test(ua))
  {
    var vendor = window.navigator.vendor.toLowerCase();
    if(vendor == "firefox") this.navigator = "firefox";
    else if(vendor == "netscape") this.navigator = "netscape";
    else if(vendor == "") this.navigator = "mozilla";
  }
  else this.navigator = "msie";
  if(window.opera) this.wordLine = false;
};

//tree's style 
DHQTreeView.prototype.setStyle = function()
{
  var style = ""+
  "DIV.DHQTreeView DIV IMG{border: 0px solid #FFFFFF;vertical-align: top;}"+
  "DIV.DHQTreeView DIV SPAN IMG{border: 0px solid #FFFFFF;}"+
  "DIV.DHQTreeView DIV A:LINK, DIV.DHQTreeView A:VISITED, DIV.DHQTreeView A:ACTIVE, DIV.DHQTreeView A:HOVER, black" +
  " {\ " +
  "    TEXT-DECORATION: NONE; color: black; padding-left: 3px;font-size: 11px; font-family: \"Verdana\", \"Arial\", \"Helvetica\", \"sans-serif\";" +
  " }"+
  "ul.DHQTreeMenu{display:inline-block;margin:0;padding:1px;border:1px solid #aca899;background:#F8F9FB;}" +
  "ul.DHQTreeMenu li{display:inline;list-style:none;white-space:nowrap;width:100%;}"+  
  "ul.DHQTreeMenu li a{padding:2px 12px;color:#000;text-decoration:none;line-height:19px;display:block;}" +
  "ul.DHQTreeMenu li a:hover{background:#3E79B0;margin:0;padding:1px 11px;color:white;text-decoration:none;border:1px solid #83aada;}"+  
  ".handlink {cursor:hand; cursor:pointer; }";
  if(this.wordLine)
  {
    style +="\
    DIV.DHQTreeView DIV\
    {\
      height: 25px;"+
      (this.navigator=="firefox" ? "line-height: 20px;" : "" ) +
      (this.navigator=="netscape" ? "" : "overflow: hidden;" ) +"\
    }\
    DIV.DHQTreeView DIV SPAN\
    {\
      vertical-align: middle; font-size: 21px; height: 25px; color: #D4D0C8; cursor: default;\
    }\
    DIV.DHQTreeView DIV SPAN.pm\
    {\
      width: "+ (this.navigator=="msie"||this.navigator=="opera" ? "11" : "9") +"px;\
      height: "+ (this.navigator=="netscape"?"9":(this.navigator=="firefox"?"10":"11")) +"px;\
      font-size: 11pt;\
      overflow: hidden;\
      margin-left: -16px;\
      margin-right: 5px;\
      color: black; \
      vertical-align: middle;\
      border: 1px solid #D4D0C8;\
      cursor: "+ (this.navigator=="msie" ? "hand" : "pointer") +";\
      padding: 0 2px 0 2px;\
      text-align: center;\
      background-color: #F0F0F0;\
    }";
  }
  //style += "<\/style>"; 
 var head = document.getElementsByTagName('HEAD')[0];
 if (head) 
 {
    var cssElement = document.createElement('STYLE');
    cssElement.setAttribute("type", "text/css");
    if(cssElement.styleSheet){// IE
    cssElement.styleSheet.cssText = style;
    } else {// w3c
    var cssText = document.createTextNode(style);
    cssElement.appendChild(cssText);
    }
    head.appendChild(cssElement);
 }
};

//when the root node is empty
DHQTreeView.prototype.atRootIsEmpty = function()
{
  var RCN = this.node["0"].childNodes;
  for(var i=0; i<RCN.length; i++)
  {
    if(!RCN[i].isLoad) this.expand(RCN[i].id);
    if (RCN[i].text=="")
    {
      var node = RCN[i].childNodes[0], HCN  = node.hasChild;
      if(this.wordLine)
      {
        var span = this.getElementById(this.name +"_tree_"+ node.id);
        span = span.childNodes[0].childNodes[0].childNodes[0];
        span.innerHTML = RCN[i].childNodes.length>1 ? "┌" : "─";
      }
      else
      {
        node.iconExpand  =  RCN[i].childNodes.length>1 ? HCN ? "PM0" : "L0" : HCN ? "PM3" : "L3"
        this.getElementById(this.name +"_expand_"+ node.id).src = this.icons[node.iconExpand].src;
      }
    }
  }
};

//load the node by clientID
//id: client id
DHQTreeView.prototype.load = function(id)
{
  var node = this.node[id];
  if(!node.isLoad && node.hasChild && !node.childNodes[0] && id!="0")
  {
     	//loading tip
     this.loadingTip(id); 
     var DOMRoot = this.getRemoteData(id, 1); 
     if(DOMRoot != null && DOMRoot.childNodes[0])     
     {
          this.FillXmltoDataSource(DOMRoot, id); 
     }
     else
     {
          this.hideTip(id);
     }
     
  }
  node.isLoad = true;
  this.node[id].isLoad = true;
};

//get data from remote server!
//id: clientId. 
//recursive recursive=0, only fetch one stage, else fetch all sub items recrursily
DHQTreeView.prototype.getRemoteData = function(id, recursive)
{
    var node = this.node[id];
    
    if(recursive == null)
        recursive = 0;
    /*    
	var parentID1, shareID1, share1, parentPath1;
	// Parse: javascript:goto(10091,0,0,&quot;&quot;)
	var nodeUrl = node.url;
	var i = nodeUrl.indexOf(",");
	var pre = "javascript:gotoFrm(";
	var pos = pre.length;
	parentID1 = nodeUrl.substring(pos, i);
	pos = i+1;
	i = nodeUrl.indexOf(",", pos);
	shareID1  = nodeUrl.substring(pos, i);
	pos = i+1;
	i = nodeUrl.indexOf(",", pos);
	share1  = nodeUrl.substring(pos, i);
	pos = i+1;
	i = nodeUrl.indexOf(")", pos);
	parentPath1  = nodeUrl.substring(pos, i);	
	
	if(share1==1 && shareID1==0)//share
	{
	    shareID1  = parentID1;
	    parentID1 = 0;
	}
	*/
	var XmlURL = this.remoteUrl; 
    var DOMRoot = null;
    try
    {
        DOMRoot = this.GetRemoteXML(XmlURL);
    }
    catch(e)
    {
        DOMRoot = null;
    }
    
    if(DOMRoot != null && DOMRoot.childNodes[0])
    {
        //this.FillXmltoDataSource(DOMRoot, id); 
        //return true;
        return DOMRoot;
    }
    else
    {   
        //node.hasChild = false;
        return null;
    }
}

//Create node HTML by node
//node   client node
//AtEnd  boolen  if true means this is the last node of this parent node.
DHQTreeView.prototype.nodeToHTML = function(node, AtEnd)
{
  var target = "";  
  var url  = node.url;//this.getAttribute(source, "url");
  var type = node.type;//this.getAttribute(source, "type"); 
  var id   = node.id;
  var HCN  = node.hasChild, isRoot = node.parentId=="0";
  var iconSrc = "";
  if(isRoot && node.icon=="") node.icon = "root";
  
  if(node.icon=="" )//|| typeof(this.icons[node.icon])=="undefined"
  {
      //node.icon = "Folder";
      iconSrc = this.icons["Folder"].src;
  }
  else if(node.icon!="" && node.icon!=null && node.icon!= "undefined")
  {
      iconSrc = node.icon;
  }
  else if(type!="" && type!="undefined")
  {
      iconSrc = this.icons[type].src;
  }
  else
  {
      node.icon = "folder";
      iconSrc = this.icons[node.icon].src;
  }
  
  node.iconExpand  = AtEnd ? "└" : "├";
  var HTML = "<DIV noWrap='True' id='" +this.name + "_div_"+ id +"'><NOBR>";
  if(!isRoot)
  {
    node.childAppend = node.parentNode.childAppend + (AtEnd ? "　" : "│") + ":" + id + ":";  
    if(this.wordLine)
    {
      HTML += "<SPAN>"+ node.parentNode.childAppend + (AtEnd ? "└" : "├") +"</SPAN>";
      if(HCN) HTML += "<SPAN class='pm' id='"+ this.name +"_expand_"+ id +"'>+</SPAN>";
    }
    else
    {
      node.iconExpand  = HCN ? AtEnd ? "PM2" : "PM1" : AtEnd ? "L2" : "L1";
      HTML += "<SPAN>"+ this.word2image(node.parentNode.childAppend) +"<IMG "+
        "align='absmiddle' id='"+ this.name +"_expand_"+ id +"' "+
        "src='"+ this.icons[node.iconExpand].src +"' style='cursor: "+ (!node.hasChild ? "":
        (this.navigator=="msie"||this.navigator=="opera"? "hand" : "pointer")) +"'></SPAN>";
    }
  }
  HTML += "<IMG "+
    "align='absMiddle' "+
    "id='"+ this.name +"_icon_"+ id +"' "+
    "src='"+ iconSrc +"'><A "+
    "class='DHQTreeView' hideFocus "+
    "id='"+ this.name +"_link_"+ id +"' "+
    "href='"+ url +"' "+
    "target='"+ target +"' "+
    "title='"+ node.hint +"' "+
    "onfocus=\""+ this.name +".focusLink('"+ id +"')\" ";
   if(this.showMenu) 
     HTML += "oncontextmenu = 'return (("+this.navigateurlID+"==0) ? (" + this.name + ".rightClickHandle(event, "+ id +")):true);'";
   HTML += "onclick=\"return "+ this.name +".nodeClick('"+ id +"')\">"+ node.text +
  "</A></NOBR></DIV>";
  if(isRoot && node.text=="") HTML = "";

  HTML = "\r\n<SPAN id='"+ this.name +"_tree_"+ id +"'>"+ HTML 
  HTML +="<SPAN style='DISPLAY: none'></SPAN></SPAN>";
  return HTML;
};

//Convert node.childAppend to img 
DHQTreeView.prototype.word2image = function(word)
{
  var str = new Array(), i=0;
  var len = word.length;
  var j=0;
  while(i<len)
  {
    var img = "";
    switch (word.charAt(i))
    {
      case "│" : img = "L4"; break;
      case "└" : img = "L2"; break;
      case "　" : img = "empty"; break;
      case "├" : img = "L1"; break;
      case "─" : img = "L3"; break;
      case "┌" : img = "L0"; break;
    }
    if(img!="")
    {
      var _pID=word.substring(i+2, word.indexOf(":", i+2));
      str.push("<IMG align='absMiddle' name='" + this.name + "DHQ_Indent_"+ _pID +"' src='"+ this.icons[img].src +"' height='20'>");
    }    
    ++i;
  }
  return str.join("");
}


//Convert node to <HTML>
//id:client id
DHQTreeView.prototype.buildNode = function(id)
{
  if(this.node[id] && this.node[id].hasChild)
  {
    var tcn = this.node[id].childNodes;
    var len = tcn.length;
    var str =new Array();
    var i = 0 ;
    while(i<len)
    {
        str.push(this.nodeToHTML(tcn[i], i==len-1));
        ++i;
    } 
    var temp = this.getElementById(this.name +"_tree_"+ id).childNodes;
    temp[temp.length-1].innerHTML = str.join("");
    str = null;
  }
};

//focus client node
//id:client id
DHQTreeView.prototype.focusClientNode      = function(id)
{
  if(!this.currentNode) this.currentNode=this.node["0"];

  var a = this.getElementById(this.name +"_link_"+ id); if(a){
  try
  {
    a.focus();
  }catch(e)
  {}
  var link = this.getElementById(this.name +"_link_"+ this.currentNode.id);
  if(link)with(link.style){color="";   backgroundColor="";}
  with(a.style){color = this.colors.highLightText;
  backgroundColor = this.colors.highLight;}
  this.currentNode= this.node[id];}
};

//focus node link
//id : client id
DHQTreeView.prototype.focusLink= function(id)
{
  if(this.currentNode && this.currentNode.id==id) return;
  this.focusClientNode(id);
};

//expand node
//sureExpand if true, always open this node.
DHQTreeView.prototype.expand   = function(id, sureExpand)
{
  var node  = this.node[id];
  if(node==null)
    return;
  if (sureExpand && node.isExpand) return;
  if (!node.hasChild) return;
  var area  = this.getElementById(this.name +"_tree_"+ id);
  if (area)   area = area.childNodes[area.childNodes.length-1];
  if (area)
  {
    var icon  = this.GetIconStr(node.icon, node.type, true);
    var iconE = this.GetIconStr(node.icon, node.type, false);
    
    var Bool  = node.isExpand = sureExpand || area.style.display == "none";
    var img   = this.getElementById(this.name +"_icon_"+ id);
    
    if (img)  img.src = !Bool ? icon.src :typeof(iconE)=="undefined" ? icon.src : iconE.src;
    var exp   = this.icons[node.iconExpand];
    var expE  = this.iconsExpand[node.iconExpand];
    var expand= this.getElementById(this.name +"_expand_"+ id);
    if (expand)
    {
      if(this.wordLine) expand.innerHTML = !Bool ? "+"  : "-";
      else expand.src = !Bool ? exp.src : typeof(expE) =="undefined" ? exp.src  : expE.src;
    }

    area.style.display = !Bool ? "none" : "block";//(this.navigator=="netscape" ? "block" : "");
    if(!node.isLoad)
    {
     //loading tip
      this.load(id);        
      if(this.node[id] !=null && this.node[id].hasChild /*&& this.node[id].childNodes.length > this.loadSize*/ && this.displayTip)
      {                 
         this.loadingTip(id);
         setTimeout(this.name + ".buildNode(" + id + ")", 100);
      } 
      else
      {
         this.buildNode(id);
      }
    }
  }
};

DHQTreeView.prototype.GetIconStr = function(_icon, _type, expand)
{
    var icon  = this.icons[_icon]; 
    if(icon==null || icon=="")
    {
        if(_type=="Folder")
        {   icon = expand ? this.icons["Folder"] : this.iconsExpand["Folder"]; }
        else
        {
            icon=new Image();
            icon.src = (_icon =="" || _icon ==null || _icon =="undefinded") ? this.icons[_type].src : _icon;
        }    
    }
    return icon;
}

//Show Loading Tip 
DHQTreeView.prototype.loadingTip = function(id)
{
    if(id==0 || id=="")
        return;
    var temp = this.getElementById(this.name +"_tree_"+ id).childNodes;
    
    temp[temp.length-1].innerHTML = "<DIV noWrap><NOBR><SPAN>"+ (this.wordLine ?
        this.node[id].childAppend +"└" : this.word2image(this.node[id].childAppend +"└")) +"</SPAN>"+
        "<IMG border='0' height='16' align='absmiddle' src='"+this.icons["loading"].src+"'>"
        "</NOBR></DIV>";    
}

//Hide loading Tip 
DHQTreeView.prototype.hideTip = function(id)
{
    if(id==0 || id=="" || !this.getElementById(this.name +"_tree_"+ id))
        return;
        
    var temp = this.getElementById(this.name +"_tree_"+ id).childNodes;    
    temp[temp.length-1].innerHTML = "";
    temp[temp.length-1].style.display = "none";    
}

//focus in the node 
//sourceId : client id
//defer delay
DHQTreeView.prototype.focus = function(sourceId, defer)
{
    if (!defer)
    {
        setTimeout(this.name +".focus('"+ sourceId +"', true)", 10);
        return;
    }
    this._focus(this.node[sourceId]);
    this.focusClientNode(sourceId);
};

DHQTreeView.prototype._focus = function(pNode)
{    
    if(pNode==null || pNode=="" || pNode=="undefined")
        return;
        
    if(pNode.parentNode)
    {
        this._focus(pNode.parentNode);
    }
    this.expand(pNode.id, true);
    //while(!this.node[pNode.id].isLoad);
    //this.waittoExpand(pNode.id);
}

var intervalID;
DHQTreeView.prototype.waittoExpand = function(id)
{
    if(this.node[id].isLoad)
    {
        clearInterval(intervalID);
        return;
    }
    intervalID = setInterval("waittoExpand("+id+")", 10);
}

//Focus Node by Url
DHQTreeView.prototype.focusByUrl = function(url)
{
    var id = this.UrlClientID[url];
    if(id != "" && id != null && id != "undefined")
    {
        this.displayTip = false;
        this.focus(id, true);
        this.displayTip = true;
        return true;
    }
};


//Delete Node by Url
DHQTreeView.prototype.deleteNodeByUrl = function(url)
{
    var id = this.UrlClientID[url];
    
    if(id != "" && id != null && id != "undefined")
    {
        this.removeNode(id);
    }
    GlobalXmlDataSource = null; //clear global datasource.     
};


//Node click even
//id client node id
DHQTreeView.prototype.nodeClick = function(id)
{

};

//click even
DHQTreeView.prototype.clickHandle = function(e)
{
  e = window.event || e; e = e.srcElement || e.target;
  //alert(e.tagName)  
  switch(e.tagName)
  {
    case "IMG" :
      if(e.id)
      {
        if(e.id.indexOf(this.name +"_icon_")==0)
        {
          this.focusClientNode(e.id.substr(e.id.lastIndexOf("_") + 1));
          if(this.getElementById(this.name +"_link_"+ e.id.substr(e.id.lastIndexOf("_") + 1)))
          {
            this.getElementById(this.name +"_link_"+ e.id.substr(e.id.lastIndexOf("_") + 1)).click(); 
          }  
        }
        else if (e.id.indexOf(this.name +"_expand_")==0)
          this.expand(e.id.substr(e.id.lastIndexOf("_") + 1));          
      }
      break;
    case "A" :
      if(e.id) this.focusClientNode(e.id.substr(e.id.lastIndexOf("_") + 1));
      break;
    case "SPAN" :
      if(e.className=="pm")
        this.expand(e.id.substr(e.id.lastIndexOf("_") + 1));
      break;
    default :
      if(this.navigator=="netscape") e = e.parentNode;
      if(e.tagName=="SPAN" && e.className=="pm")
        this.expand(e.id.substr(e.id.lastIndexOf("_") + 1));
      break;
  }
};

//DHQTreeView Dbclick
DHQTreeView.prototype.dblClickHandle = function(e)
{
  e = window.event || e; e = e.srcElement || e.target;
  if((e.tagName=="A" || e.tagName=="IMG")&& e.id)
  {
    var id = e.id.substr(e.id.lastIndexOf("_") + 1);
    if(this.node[id].hasChild) this.expand(id);
  }
};


var getFrmMenu = function()
{
    var frmMenu = "<ul id=\"DHMenu\" class=\"DHQTreeMenu\" style=\"position:absolute;display:none;\" onmouseover=\"this.style.display='';\" onmouseout=\"this.style.display='none';\">"+
				" <li id=m_new><a href=\"javascript:NewFolder()\">New Folder</a></li>" +  
				" <li id=m_edit><a href=\"javascript:EditFolder()\">Edit Folder</a></li>" +                     
				" <li id=m_delete><a href=\"javascript:DeleteFolder()\">Delete Folder</a></li>" +
				" <li id=m_empty><a href=\"javascript:EmptyFolder()\">Empty Folder</a></li>" +
				" <li id=m_makeread><a href=\"javascript:Markallread(curMailBoxID, 1)\">Mark all read</a></li>" +
				" <li id=m_makeunread><a href=\"javascript:Markallread(curMailBoxID, 0)\">Mark all unread</a></li>" +
				" <li id=m_manage><a href=\"javascript:MsgBoxManage()\">Manage Folders</a></li>" +
				" </ul>" ;  
    return frmMenu;
}

var curMailBoxID    = 0;
var curMailBoxName  = "";
var curClientID     = 0;
var previousID      = 0;  
//
DHQTreeView.prototype.rightClickHandle = function(e, nodeID)
{
    if(e) //e.button right click
    {
        var objMenu = this.getElementById("DHMenu");     
        if(objMenu==null)
        {
            return;
        }
        
    	var l=e.clientX;
	    var t=e.clientY;
	    while(e=e.offsetParent)
	    {
		    t+=e.offsetTop;
		    l+=e.offsetLeft;
	    }   
        objMenu.style.display = "";        
        objMenu.style.left    = l + 10 + "px";
        objMenu.style.top     = t + "px";  
        setMenu(nodeID);
        var url1= this.node[nodeID].url; 
        curMailBoxID    = getMailBoxIDByUrl(url1);
        if(curMailBoxID>0)
        {
             curMailBoxName  =   this.node[nodeID].text;   
             curClientID     =   this.currentNode.id;
             var node11      =   this.getPreviousNode(this.node[nodeID]);
             if(node11!=null)
                previousID   =   getMailBoxIDByUrl(node11.url);
             else//get parent node             
                previousID   =  0;
        }
        else
        {          
            curMailBoxName  =   "";
            curClientID     =   0;
            previousID      =   0;
        }
        return false;
    }
    return false;
}

function setMenu(nodeID)
{
    if(nodeID==1)//root
    {
        document.getElementById("m_new").style.display       = "";
        document.getElementById("m_manage").style.display    = "";
        document.getElementById("m_edit").style.display      = "none";
        document.getElementById("m_delete").style.display    = "none";
        document.getElementById("m_empty").style.display     = "none";   
         document.getElementById("m_makeread").style.display = "none"; 
        document.getElementById("m_makeunread").style.display= "none";      
    }
    else
    {
        document.getElementById("m_new").style.display       = "";
        document.getElementById("m_manage").style.display    = "";
        document.getElementById("m_edit").style.display      = "";
        document.getElementById("m_delete").style.display    = "";
        document.getElementById("m_empty").style.display     = "";        
        document.getElementById("m_makeread").style.display  = ""; 
        document.getElementById("m_makeunread").style.display= ""; 
    }
}

function getMailBoxIDByUrl(url)
{
    if(url=="")
        return 0;
        
     var tag = "MailList,";
     var tag2= "\")";
     var i   = 0, j=0;
     var mailBoxID  =   0;
            
     i=url.indexOf(tag);
     if(i>0)
     {
          j=url.indexOf(tag2, i+tag.length+1);               
          if(j>0)
          {
             mailBoxID    =   url.substring(i+tag.length, j);  
          }
          else
          {
             mailBoxID = 0;
          }
      }
      else
      {
          mailBoxID = 0;
      }  
      return   mailBoxID;     
}

//Up to the parent node of current node
DHQTreeView.prototype.upperNode = function()
{
  if(!this.currentNode) return;
  if(this.currentNode.id=="0" || this.currentNode.parentId=="0") return;
  if (this.currentNode.hasChild && this.currentNode.isExpand)
    this.expand(this.currentNode.id, false);
  else this.focusClientNode(this.currentNode.parentId);
};

//expand current node
DHQTreeView.prototype.lowerNode = function()
{
  if (!this.currentNode) this.currentNode = this.node["0"];
  if (this.currentNode.hasChild)
  {
    if (this.currentNode.isExpand)
      this.focusClientNode(this.currentNode.childNodes[0].id);
    else this.expand(this.currentNode.id, true);
  }
}

//focus pervious node.
DHQTreeView.prototype.pervNode = function()
{
  if(!this.currentNode) return; var e = this.currentNode;
  if(e.id=="0") return; var a = this.node[e.parentId].childNodes;
  for(var i=0; i<a.length; i++){if(a[i].id==e.id){if(i>0){e=a[i-1];
  while(e.hasChild){this.expand(e.id, true);
  e = e.childNodes[e.childNodes.length - 1];}
  this.focusClientNode(e.id); return;} else {
  this.focusClientNode(e.parentId); return;}}}
};

//focus next node.
DHQTreeView.prototype.nextNode = function()
{
  var e = this.currentNode; if(!e) e = this.node["0"];
  if (e.hasChild){this.expand(e.id, true);
  this.focusClientNode(e.childNodes[0].id); return;}
  while(typeof(e.parentId)!="undefined"){
  var a = this.node[e.parentId].childNodes;
  for(var i=0; i<a.length; i++){ if(a[i].id==e.id){
  if(i<a.length-1){this.focusClientNode(a[i+1].id); return;}
  else e = this.node[e.parentId];}}}
};

//get previous sibling node
DHQTreeView.prototype.getPreviousSibling = function(currNode)
{
  if(!currNode) return; 
  var e = currNode;
  if(e.id=="0") return; 
  var a = this.node[e.parentId].childNodes;
  var len = a.length;
  for(var i=0; i<len; i++)
  {
    if(a[i].id==e.id)
    {
        return i>0 ? a[i-1] : a[0];      
    }
  }
  return null;
};

DHQTreeView.prototype.getPreviousNode = function(currNode)
{
  if(!currNode) return; 
  var e = currNode;
  if(e.id=="0") return; 
  var a = this.node[e.parentId].childNodes;
  var len = a.length;
  for(var i=0; i<len; i++)
  {
    if(a[i].id==e.id)
    {
        return i>0 ? a[i-1] : this.node[e.parentId];      
    }
  }
  return null;
};



DHQTreeView.prototype.getNextSibling = function()
{
  if(!this.currentNode) return; 
  var e = this.currentNode;
  if(e.id=="0") return; 
  var a = this.node[e.parentId].childNodes;
  var len = a.length;
  for(var i=0; i<len; i++)
  {
    if(a[i].id==e.id)
    {
        return i>0 ? a[i-1] : a[0];      
    }
  }
};

DHQTreeView.prototype.removeNode =function(id)
{   this.expand(id, true);
    var e = null;//this.currentNode; 
    if(id!=0 && this.node[id])
    {
        e=this.node[id];
    }
    else
    {
        return ;
    }
    var len=0;
    if(this.tempDataSource!=null)
    {       
        for(var _node in this.tempDataSource)
        {
            if(e.url.toLowerCase() == this.tempDataSource[_node].url.toLowerCase() &&
               e.text.toLowerCase() == this.tempDataSource[_node].text.toLowerCase() )
            {
                if(e.hasChild)
                {
                    //may be some nodes been deleted in this folder. so we need reload this node.
                    if(e.isExpand == true)
                    {
                        this.expand(id, false);
                    }
                    if(e.isLoad == true)
                    {
                        this.node[id].isLoad = false;
                        this.node[id].childNodes = [];
                    }
                }
                return ;
            }
        }
    }
    var box = this.getElementById(this.name +"_tree_"+ e.id);//this.name+"_div_"+ e.id  
	if(box)
	{
		for(var i=0;  box.childNodes && i<box.childNodes.length; i++)
		{
			box.removeChild(box.childNodes[i]);	
		}	
		
		box.parentNode.removeChild(box);
	}

    var i=0, isLastNode = false;
    var parentNode = e.parentNode;
    var parentNodeLen = parentNode.childNodes.length;
    
    isLastNode =  parentNode.childNodes[parentNodeLen-1]==e ? true : false;
    
	var pSibling = this.getPreviousSibling(e);	
	if(isLastNode && pSibling!=null && pSibling.id!=0)
	{
        var pIndentObj	= document.getElementsByName(this.name + "DHQ_Indent_" + pSibling.id);
        var len = pIndentObj==null ? 0 : pIndentObj.length;
	    for(var i=0;i<len;i++)
	    {
	        pIndentObj[i].src = this.icons["empty"].src;	    
	    }
	    //change child nodes indent.    
        this._changeNodesInfo(pSibling, pSibling.id);
    }
    
    //change previous sibling expand icon.    
    if(parentNodeLen > 1)
    {   
        if(isLastNode && this.getElementById(this.name + "_expand_" + pSibling.id))//last children node
        {            
            if(pSibling.hasChild)// Sibling has child node
            { 
               this.node[pSibling.id].iconExpand  = "PM2";   
               if(this.node[pSibling.id].isExpand == false)
	           {
	                this.getElementById(this.name + "_expand_" + pSibling.id).src= this.icons["PM2"].src;
	           }
	           else
	           {
	                this.getElementById(this.name + "_expand_" + pSibling.id).src= this.iconsExpand["PM2"].src;
	           }
	        }
	        else// Sibling no child node
	        {
	           this.getElementById(this.name + "_expand_" + pSibling.id).src= this.icons["L2"].src;
	        }
	    }
	    else
	    {
	        //not last children	node       
	    }
	}
	else//this parent node has only one children
	{
	    var pLastNode = parentNode.parentNode.childNodes[parentNode.parentNode.childNodes.length-1]==parentNode? true :false;	   
	    
	    this.expand(parentNode.id, false);//collspand the node
	    var imgsrc="";
	    if(pLastNode) //last node
	    {
	        //this.node[parentNode.id].iconExpand = "PM2";
	        imgsrc = this.icons["L2"].src;
	    }
	    else //
	    {
	        imgsrc = this.icons["L1"].src;
	    }	  
	    
	    if(imgsrc!="" && this.getElementById(this.name + "_expand_" + parentNode.id))  
	    {
	        this.getElementById(this.name + "_expand_" + parentNode.id).src = imgsrc;
	        this.getElementById(this.name + "_expand_" + parentNode.id).style.cursor="default";
	    }
//	    this.node[parentNode.id].iconExpand = "";
	    
	    this.node[parentNode.id].hasChild   = false;
	    this.node[parentNode.id].childNodes = []; 	    
	}	
	
	//delete from datasource.	
    this.DeleteNodes(e);  
    
    //delete url maps
    delete this.UrlClientID[e.url];
    this.UrlClientID.length -=1;
};

DHQTreeView.prototype._changeIndent = function(Str, oldStr, newStr, ID)
{
    return Str.replace(oldStr+":"+ ID + ":", newStr + ":"+ ID + ":");    
};

DHQTreeView.prototype._changeNodesInfo = function(pNode, ID)
{
    for(var i=0; pNode.hasChild && i<pNode.childNodes.length; i++)     
    {
        if(pNode.childNodes[i].hasChild)
            this._changeNodesInfo(pNode.childNodes[i], ID); 
        this.node[pNode.childNodes[i].id].childAppend =  this._changeIndent(this.node[pNode.childNodes[i].id].childAppend, "│", "　", ID);       
    }   
   this.node[pNode.id].childAppend = this._changeIndent(this.node[pNode.id].childAppend, "│", "　", ID);
};

//Delete datasource
DHQTreeView.prototype.DeleteNodes = function(pNode)
{
    for(var i=0; pNode.hasChild && i<pNode.childNodes.length; i++)     
    {
        if(pNode.childNodes[i].hasChild)
            this.DeleteNodes(pNode.childNodes[i]); 
        if(pNode.childNodes[i]!=null && pNode.childNodes[i]!="undefined")    
        {
            this.node[pNode.childNodes[i].id] = null;
            if(pNode.childNodes[i] != null && pNode.childNodes[i].url != null &&
                pNode.childNodes[i].url !="")
            {
                delete this.UrlClientID[pNode.childNodes[i].url];
                this.UrlClientID.length -=1;
            }
            delete this.node[pNode.childNodes[i].id];  
            this.node.length-=1;       
        }
    }
   
   this.node[pNode.id] = null; 
   if(pNode != null && pNode.url != null &&
        pNode.url !="")
    {
        delete this.UrlClientID[pNode.url];
        this.UrlClientID.length -=1;
    }  
   delete this.node[pNode.id];
   this.node.length-=1;
   
   var parentNode = pNode.parentNode;
   for(var i=0;parentNode && i<parentNode.childNodes.length;i++)  
   {
        if(parentNode.childNodes[i]==pNode)
        {
             for(var j=i;j<parentNode.childNodes.length;j++)
             {
                this.node[pNode.parentId].childNodes[j]=this.node[pNode.parentId].childNodes[j+1];
             }
             
             if(this.node[pNode.parentId].childNodes[j] != null && this.node[pNode.parentId].childNodes[j].url != null &&
                this.node[pNode.parentId].childNodes[j].url !="")
             {
                delete this.UrlClientID[this.node[pNode.parentId].childNodes[j].url];
                this.UrlClientID.length -=1;
             } 
             delete this.node[pNode.parentId].childNodes[j];
             this.node[pNode.parentId].childNodes.length-=1;
             break;
        }
   }
};

//Expand all nodes
DHQTreeView.prototype.expandAll = function()
{
  if(this.node["0"].childNodes.length==0) return;
  var e = this.node["0"].childNodes[0];
  var isdo = t = false;
  while(e.id != "0")
  {
    var p = this.node[e.parentId].childNodes, pn = p.length;
    if(p[pn-1].id==e.id && (isdo || !e.hasChild)){e=this.node[e.parentId]; isdo = true;}
    else
    {
      if(e.hasChild && !isdo)
      {
        this.expand(e.id, true), t = false;
        for(var i=0; i<e.childNodes.length; i++)
        {
          if(e.childNodes[i].hasChild){e = e.childNodes[i]; t = true; break;}
        }
        if(!t) isdo = true;
      }
      else
      {
        isdo = false;
        for(var i=0; i<pn; i++)
        {
          if(p[i].id==e.id) {e = p[i+1]; break;}
        }
      }
    }
  }
};

//Expand nodes by set expand level
DHQTreeView.prototype.expandSetNodes = function(setLevel)
{
    var arr=new Array();
    if(this.node["0"].childNodes.length>0)
    {
        arr[0]=this.node["0"].childNodes[0];    
        this.expandSetLevel(arr, 0, setLevel);
    }
    else
    {   
        return;
    }
};

//Expand nodes
DHQTreeView.prototype.expandSetLevel = function(parentNodes, pLevel, setLevel)
{
  if(parentNodes.length==0) return;
  
  var childNodes=Array();
  var j=0;
  for(var i=0; i<parentNodes.length; i++)
  {
    this.expand(parentNodes[i].id, true);
    for(var k=0; parentNodes[i] && parentNodes[i].hasChild && k<parentNodes[i].childNodes.length; k++)
    {
        childNodes[j++]=parentNodes[i].childNodes[k];
    }
  }
  
  pLevel++;
  if(pLevel>=setLevel)
    return;
  
  this.expandSetLevel(childNodes, pLevel, setLevel);
};

//Pre-load image
//path :set image path
DHQTreeView.prototype.setIconPath  = function(path)
{
  var k = 0, d = new Date().getTime();
  for(var i in this.icons)
  {
    var tmp = this.icons[i];
    this.icons[i] = new Image();
    this.icons[i].src = path + tmp;
    //if(k==9 && (new Date().getTime()-d)>30)
    //   this.wordLine = true; 
     k++;
  }
  for(var i in this.iconsExpand)
  {
    var tmp = this.iconsExpand[i];
    this.iconsExpand[i]=new Image();
    this.iconsExpand[i].src = path + tmp;
  }
};

//Add node
DHQTreeView.prototype.AddNode = function(pId, url, text, icon, type)
{
    var e = null;    
    if(pId==null || pId=="" || pId==0)           
    {
        e = this.currentNode;
    }
    else
    {
        e = this.node[pId];
    }
    
    parentId = e.id;
    if(type=="")
        type = "Folder";
    var _node={};
    
    _node =
          {
            "id"    : ++this.index,
            "text"  : text,
            "hint"  : text,
            "icon"  : icon,
            "isLoad": false,
            "isExpand": false,
            "parentId": parentId,
            "parentNode" : e,
            "childAppend" : e.childAppend + "　" + ":" + this.index + ":",
            "url"         : url,
            "type"        : type,
            "iconExpand"  : "PM2",
            "hasChild"    : false         
          };
    this.UrlClientID[url] = this.index; 
    this.node[this.index]=_node;  
    if(this.node[parentId].hasChild)
    {
        //this.node[parentId].childNodes.length += 1;
        var len1 = this.node[parentId].childNodes.length;
        this.node[parentId].childNodes[this.node[parentId].childNodes.length] =_node;
        var len2 = this.node[parentId].childNodes.length;
        if(len1==len2)
            this.node[parentId].childNodes.length += 1;
        for(var i=0;i<len1;i++)    
        {
            this.node[parentId].childNodes[i].isLoad = false;
        }
    }
    else
    {
        this.node[parentId].hasChild = true;
        this.node[parentId].childNodes        = {};
        this.node[parentId].iconExpand        = "PM2";  
        this.node[parentId].childNodes[0]     = _node;
        this.node[parentId].childNodes.length = 1; 
    }    
    
    
    var expandObj = this.getElementById(this.name + "_expand_" + parentId);
    if(expandObj)
    {
        var expandsrc = expandObj.src;
        if(expandsrc==this.icons["L1"].src)  
        {
            this.node[parentId].iconExpand = "PM1"; 
        }
        else if(expandsrc==this.icons["L2"].src)  
        {
            this.node[parentId].iconExpand = "PM2";  
        }
        expandObj.className ="handlink";
    }
    
    this.node[parentId].isLoad   = false;
    this.node[parentId].isExpand = false;
    this.expand(parentId, true);
    FirstExpandNodeUrl  = null;//clear temp datasource.
    GlobalXmlDataSource = null; 
};

DHQTreeView.prototype.RenameNodeByUrl = function(Url, newText)
{
    var Id = this.UrlClientID[Url];   
    if(Id != null && Id!=0)
    {
        this.RenameNode(Id, newText);
    }
}

//rename
//Id: clientId, newText: newName	     
DHQTreeView.prototype.RenameNode = function(Id, newText)
{
    var i=0;
    var node = this.node[Id];
    var parentNode = this.node[Id].parentNode;
    var len = parentNode.childNodes.length;
    
    while(i<len)
    {
        if(parentNode.childNodes[i]==node)
            break;       
        ++i;         
    }
    
    if(i==len)
    {
        return;
    }
    else        
    {
        this.node[Id].text = newText;
        this.node[Id].hint = newText;  
        this.node[Id].parentNode.childNodes[i] = this.node[Id];
        GlobalXmlDataSource = null; //clear temp datasource.       
        if(this.getElementById(this.name +"_link_"+ Id))
        {
            this.getElementById(this.name +"_link_"+ Id).innerHTML   = newText; 
            this.getElementById(this.name +"_link_"+ Id).title       = newText;      
        }    
    }
}

//Refresh Node. Get data from server.     
DHQTreeView.prototype.RefreshNode = function(Id)
{
    var node=this.node[Id]; 
    var hasChildNodes = node.childNodes!=null;  
    var len = hasChildNodes ? node.childNodes.length : 0;
    var i=0;
    var oldIconExpand = (hasChildNodes && len != 0) ? this.node[Id].iconExpand : node.iconExpand=="L2" ? "PM2" : "PM1";
    while(i<len)
    {
       //this.removeNode(node.childNodes[0].id);
       this.DeleteNodes(node.childNodes[0]);
       ++i;
    }
    this.node[Id].hasChild   = true; 
    this.node[Id].isLoad     = false;
    this.node[Id].isExpand   = false;
    this.node[Id].iconExpand = oldIconExpand;
    if(!hasChildNodes)
    {
        this.node[Id].childNodes = [];
    }
    
    //setTimeout(this.name + ".loadingTip(" + Id + ")", 10);  
    //var ret = this.getRemoteData(Id, 0); 
    
    this.loadingTip(Id); 
    var DOMRoot = this.getRemoteData(Id, 0); 
    var ret ;
    if(DOMRoot != null && DOMRoot.childNodes[0])     
    {
         this.FillXmltoDataSource(DOMRoot, Id); 
         ret = true;
    }
    else
    {
         this.hideTip(Id);
         ret = false;
    }
     
    if(!this.node[Id].hasChild && this.getElementById(this.name+"_expand_" + Id))
    {
        node = this.node[Id];
        var pLastNode = node.parentNode.childNodes[node.parentNode.childNodes.length-1]==node? true :false;	   
	    
	    this.expand(Id, false);//collspand the node	    
	    if(pLastNode) //last node
	    {
	        //this.node[parentNode.id].iconExpand = "PM2";
	        this.getElementById(this.name+"_expand_" + Id).src = this.icons["L2"].src;
	    }
	    else //
	    {
	        this.getElementById(this.name+"_expand_" + Id).src = this.icons["L1"].src;
	    }	    
	    
	    this.getElementById(this.name+"_expand_" + Id).style.cursor="default";
	    this.getElementById(this.name+"_icon_" + Id).src           = this.GetIconStr(node.icon, node.type, true).src;
	    this.node[Id].iconExpand = "";
	    this.node[Id].hasChild   = false;
	    this.node[Id].childNodes = [];
	    return; 	   
    }
    if(ret)
    {
        if(this.node[Id].childNodes.length > this.loadSize)
            setTimeout(this.name + ".expand(" + Id + ", true)", 100);
        else
            this.expand(Id, true);
    }
}

DHQTreeView.prototype.syncServerData = function(id)
{
    var DOMRoot = this.getRemoteData(id, 0); 
    if(DOMRoot != null && DOMRoot.childNodes[0])     
    {
        var domNodes = DOMRoot.childNodes;
        var len = domNodes.length;
        var i=0;
        var subNode;
        this.clearTempData();
        while(i<len)
        {
            subNode = domNodes[i];
            var text  = subNode.getAttribute("Text");
            var url   = subNode.getAttribute("NavigateUrl");
            var icon  = subNode.getAttribute("imageurl");
            var type  = subNode.getAttribute("Type");
            var subFoldersCount = subNode.getAttribute("subFoldersCount"); 
            subFoldersCount = parseInt(subFoldersCount);
            this.tempDataSource[i] =
            {
                "id"    : i,
                "text"  : text,
                "icon"  : icon,              
                "url"         : url,
                "type"        : type,
                "subFolderCount" : subFoldersCount
            };
            ++i;
        }
    }
}

DHQTreeView.prototype.clearTempData = function()
{
    this.tempDataSource = {};
}
//set remote server url
//url: remote server url
DHQTreeView.prototype.setRemoteURL     = function(url){this.remoteUrl = url;};

//display loading tip..
DHQTreeView.prototype.setdisplayTip    = function(value){this.displayTip = value;};

document.oncontextmenu = function(e)
{   
    if(e==null || (e && e.button == "2" && ((e.target && e.target.className=="DHQTreeView") ||
    (e.srcElement && e.srcElement.className=="DHQTreeView"))))
    {
       
    }
    else
    {
        document.getElementById("DHMenu").style.display="none"; 
    }
}

/*
document.onclick  =  function(e) 
{
    if(document.getElementById("divSenderEmail"))
        document.getElementById("divSenderEmail").style.dispaly="none";
        
    if(e && e.button == "2" && e.target && e.target.className=="DHQTreeView")        
    {
        return true;
    }   
    return true;
};
*/

function NewFolder()
{
    //if(curMailBoxID!=0)
    //{
        NewMailBox(curMailBoxID);//this method in email.js.
    //}
}

function EditFolder()
{
    if(!checkSystemFolder() )
    {
        alert("You can't edit system mail box!");
        return;
    }
    
    if(curMailBoxID!=0)
    {
        EditMailBox(curMailBoxID);//this method in email.js.
    }
}

function DeleteFolder()
{
    if(!checkSystemFolder() )
    {
        alert("You can't delete system mail box!");
        return;
    }
    
	if(confirm("Are you sure to delete this mail box?"))
	    DeleteMailBox(curMailBoxID, previousID);//this method in email.js.
}

function EmptyFolder()
{
    if(confirm("Are you sure to empty this mail box?"))
	    EmptyMsgBoxByMsgBoxID(curMailBoxID);//this method in email.js.
}



function checkSystemFolder()
{
    if(tree==null)
        return false;
      
    if((curMailBoxName=="Inbox"||curMailBoxName=="Sent"||curMailBoxName=="Draft"||curMailBoxName=="Trash"||curMailBoxName=="Bulk")
        && tree.node[curClientID].type!=null &&
       (tree.node[curClientID].type =="Inbox" ||
        tree.node[curClientID].type =="Sent"  ||
        tree.node[curClientID].type =="Draft" ||
        tree.node[curClientID].type =="Trash" ||
        tree.node[curClientID].type =="Bulk" ))
	{		
		return false;
	}
	else
	{
	    return true;
	}
}

function FocusTreeNodeByMsgBoxID(msgBoxID)
{    
    var url = "javascript:__doPostBack(\"commander\",\"MailList,"+msgBoxID+"\")";
    if(tree==null)
    {
        FirstExpandNodeUrl = url;
        return;
    }
    else{tree.focusByUrl(url);}
}    

/*          
document.write(frmMenu); 
document.write(DHQTreeView.prototype.setStyle());*/
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
// -->