document.write("<style>a.treeview{color:windowtext;text-decoration:none;cursor:hand;}a.treeview:hover{color:windowtext;text-decoration:none;}</style>");
var _JS_TREEVIEW_ID=0;
var _TVW_TEXTONLY=0;
var _TVW_TREELINE=1;
var _TVW_MULTISELECT=2;
var _TVW_ICON=4;
var _TVW_PLUSMINUS=8;
var _TVW_CHILD=0;
var _TVW_PREVIOUS=1;
var _TVW_NEXT=2;
var _TREE_ICON_DIR="images"
var isFather=1;
var _TREE_DBLCLICK_EXPAND=true;

function TreeView(){
	//常数
	this.tvwTextOnly=_TVW_TEXTONLY;
	this.tvwTreeLine=_TVW_TREELINE;
	this.tvwMultiSelect=_TVW_MULTISELECT;
	this.tvwIcon=_TVW_ICON;
	this.tvwPlusMinus=_TVW_PLUSMINUS;
	this.tvwChild=_TVW_CHILD;
	this.tvwPrevious=_TVW_PREVIOUS;
	this.tvwNext=_TVW_NEXT;
        this.dblExpand=_TREE_DBLCLICK_EXPAND;
	//属性
	this.id="_JS_TREEVIEW_"+(_JS_TREEVIEW_ID++);
	this.style=_TVW_TREELINE|_TVW_ICON;
	this.subNodes=new Array();
	this.lastNodeIndex=0;
	//方法
	this.addNode=_addTreeNode;
	this.removeNode=_removeTreeNode;
	this.find=_getJSNodeByKey;
	this.getHtmlText=_getHtmlTextOfTreeView;
        this.setDblExpand=_setDblExpand;
	this.getSelectedNode=_getSelectedTreeNode;
	this.selectNode=_selectTreeNode2;
	this.getCheckedNodes=_getCheckedTreeNodes;
	this.handleEvent=_onTreeViewKeyEvent;
	this.setIconDir=_setTreeIconDir;
	this.enumerateNodes=_enumerateTreeNodes;
}

function _setDblExpand(dblExpand)
{
   _TREE_DBLCLICK_EXPAND=dblExpand;
}
function TreeNode(icon1,icon2,text,script,key,property,chk){
	//属性
	this.id=null;
	this.icon1=icon1;
	this.icon2=(icon2?icon2:icon1);
	this.text=text;
	this.script=(script?script:"");
	this.key=(key!=null?key:"");
	this.property=(property!=null?property:"");
	this.subNodes=new Array();
	this.parNode=null;
	this.parTree=null;
	this.lastNodeIndex=0;
	//方法
	this.addNode=_addTreeNode;
	this.removeNode=_removeTreeNode;
	this.find=_getJSNodeByKey;
	this.getText=_getTreeNodeText;
	this.setText=_setTreeNodeText;
	this.expand=_expandTreeNode;
	this.focus=_setFocusOnTreeNode;
	this.moveUp=_moveTreeNodeUp;
	this.moveDown=_moveTreeNodeDown;
	this.setSubNodes=_setSubTreeNodes;
	this.chk=chk;
}

function _addTreeNode(relative,relationship,oNode){
	isFather=relationship;
	var oRelative=null;
	if(typeof(relative)=="string"){
		oRelative=this.find(relative);
		if(!oRelative){
			return;
		}
	}
	else{
		oRelative=relative;
	}
	if(relationship==null){
		relationship=_TVW_CHILD;
	}
	switch(relationship){
		case _TVW_CHILD:
			return _add_childnode(this,oRelative,oNode);
		case _TVW_PREVIOUS:
			return _insert_node_before(oRelative,oNode,false);
		case _TVW_NEXT:
			return _insert_node_before(oRelative,oNode,true);
	}
}

function _add_childnode(oTopObj,oParNode,oNode){
	if(oParNode==null){
		oParNode=oTopObj;
	}
	if(oParNode.id){
		oNode.id=oParNode.id+"_"+(oParNode.lastNodeIndex++);
		if(!oNode.key){
			oNode.key=oNode.id;
		}
	}
	oParNode.subNodes[oParNode.subNodes.length]=oNode;
	if(oParNode.parTree==null){
		oNode.parNode=null;
		oNode.parTree=oTopObj;
	}
	else{
		oNode.parNode=oParNode;
		oNode.parTree=oParNode.parTree;
	}
	_addSubNodeInDocument(oNode);
	return oNode;
}

function _insert_node_before(nodBefore,nodInst,bInstAfter){
	if(!nodBefore){
		return null;
	}
	var oParObj=nodBefore.parNode?nodBefore.parNode:nodBefore.parTree;
	var index=0;
	for(var index=0;index<oParObj.subNodes.length;index++){
		if(oParObj.subNodes[index]==nodBefore){
			break;
		}
	}
	if(!bInstAfter){
		for(var i=oParObj.subNodes.length;i>index;i--){
			oParObj.subNodes[i]=oParObj.subNodes[i-1];
		}
		oParObj.subNodes[index]=nodInst;
	}
	else{
		for(var i=oParObj.subNodes.length;i>index+1;i--){
			oParObj.subNodes[i]=oParObj.subNodes[i-1];
		}
		oParObj.subNodes[index+1]=nodInst;
	}
	if(oParObj.id){
		nodInst.id=oParObj.id+"_"+(oParObj.lastNodeIndex++);
		if(!nodInst.key){
			nodInst.key=nodInst.id;
		}
	}
	nodInst.parNode=nodBefore.parNode;
	nodInst.parTree=nodBefore.parTree;
	_insertNodeInDocument(nodBefore,nodInst,bInstAfter);
	return nodInst;
}

function _addSubNodeInDocument(oNode){
	if(oNode.id==null){
		return;
	}
	var oTree=document.getElementById(oNode.parTree.id);
	if(!oTree){
		return;
	}
	var oParNode=oNode.parNode;
	var trInst=null;
	if(oParNode==null){
		//是树的第一层子节点
		trInst=oTree.insertRow();
		trInst.id=oNode.id;
		_reset_nodehtml(oNode,true,true,true);
		if(oNode.parTree.subNodes.length>=2){
			_reset_nodehtml(oNode.parTree.subNodes[oNode.parTree.subNodes.length-2],true,false,false,true);
		}
	}
	else{
		var oSubTree=document.getElementById(oNode.parNode.id+"_SubTree");
		if(!oSubTree){
			//假如没有子节点树，插入之
			var oTR=document.getElementById(oParNode.id);
			oTR.cells(0).innerHTML=_getNodeLineImg(oParNode);
			var oTbl=_getTableFromTR(oTR);
			oTR=oTbl.insertRow(oTR.rowIndex+1);
			oTR.id=oParNode.id+"_SubTree";
			oTR.style.display="none";
			var oTD;
			oTD=oTR.insertCell();
			if(!_isLastNode(oParNode)){
				oTD.style.backgroundImage="url('"+_TREE_ICON_DIR+"/line.gif')";
			}
			oTD=oTR.insertCell();
			oTD=oTR.insertCell();
			oTD.innerHTML=_getSubNodesHtml(oParNode);
			return;
		}
		else{
			oSubTree=oSubTree.all.tags("TABLE")[0];
			trInst=oSubTree.insertRow();
			trInst.id=oNode.id;
			_reset_nodehtml(oNode,true,true,true);
			if(oParNode.subNodes.length>=2){
				_reset_nodehtml(oParNode.subNodes[oParNode.subNodes.length-2],true,false,false,true);
			}
		}
	}
}

function _insertNodeInDocument(nodBefore,nodInst,bInstAfter){
	if(nodInst.id==null){
		return;
	}
	var oTree=document.getElementById(nodInst.parTree.id);
	if(!oTree){
		return;
	}
	var trInst;
	var oTbl;
	if(nodInst.parNode==null){
		oTbl=document.getElementById(nodInst.parTree.id);
	}
	else{
		oTbl=_getTableFromTR(document.getElementById(nodBefore.id));
	}
	if(nodBefore){
		var nRowIndex=document.getElementById(nodBefore.id).rowIndex;
		if(bInstAfter){
			if(nodBefore.subNodes.length>0){
				nRowIndex++;
			}
			nRowIndex++;
		}
		_reset_nodehtml(nodBefore,true,false,false,true);
		trInst=oTbl.insertRow(nRowIndex);
	}
	else{
		trInst=oTbl.insertRow();
	}
	trInst.id=nodInst.id;
	_reset_nodehtml(nodInst,true,true,true);
}

function URLID(myURL){
	document.location=myURL
	}

function _moveTreeNodeUp(){
	var oParObj=this.parNode;
	if(!oParObj){
		oParObj=this.parTree;
	}
	if(oParObj.subNodes.length<2){
		return false;
	}
	var index=-1;
	for(var i=0;i<oParObj.subNodes.length;i++){
		if(oParObj.subNodes[i]==this){
			index=i;
			break;
		}
	}
	if(index<=0){
		return false;
	}
	var oTree=document.getElementById(this.parTree.id);
	if(oTree){
		var sSelectedItem=oTree.SelectedItem;
		var tr1=document.getElementById(this.id);
		var tr2=document.getElementById(oParObj.subNodes[index-1].id);
		var oTbl=_getTableFromTR(tr1);
		var bExpand=false;
		if(this.subNodes.length>0){
			bExpand=(oTbl.rows(tr1.rowIndex+1).style.display!="none");
			oTbl.deleteRow(tr1.rowIndex+1);
		}
		oTbl.deleteRow(tr1.rowIndex);
		tr1=oTbl.insertRow(tr2.rowIndex);
		tr1.id=this.id;
		var nodTmp=this;
		oParObj.subNodes[index]=oParObj.subNodes[index-1];
		oParObj.subNodes[index-1]=nodTmp;
		_reset_nodehtml(nodTmp,true,true,true,false);
		if(nodTmp.subNodes.length>0){
			var trSubTree=oTbl.insertRow(document.getElementById(nodTmp.id).rowIndex+1);
			trSubTree.id=nodTmp.id+"_SubTree";
			trSubTree.style.display="none";
			trSubTree.insertCell().style.backgroundImage="url('"+_TREE_ICON_DIR+"/line.gif')";
			trSubTree.insertCell();
			trSubTree.insertCell().innerHTML=_getSubNodesHtml(nodTmp);
		}
		_reset_nodehtml(oParObj.subNodes[index],true,false,false,true);
		if(sSelectedItem==nodTmp.id){
			_select_treenode(sSelectedItem);
		}
		if(bExpand){
			_treenode_onexpand(nodTmp.id);
		}
	}
	else{
		var nodTmp=this;
		oParObj.subNodes[index]=oParObj.subNodes[index-1];
		oParObj.subNodes[index-1]=nodTmp;
	}
	return true;
}

function _moveTreeNodeDown(){
	var oParObj=this.parNode;
	if(!oParObj){
		oParObj=this.parTree;
	}
	if(oParObj.subNodes.length<2){
		return false;
	}
	var index=-1;
	for(var i=0;i<oParObj.subNodes.length;i++){
		if(oParObj.subNodes[i]==this){
			index=i;
			break;
		}
	}
	if(index>=oParObj.subNodes.length-1){
		return false;
	}
	return oParObj.subNodes[index+1].moveUp();
}

function _setSubTreeNodes(nodes,bDontRefresh){
	this.subNodes=null;
	this.subNodes=new Array();
	for(var i=0;i<nodes.length;i++){
		var node=new TreeNode(nodes[i].icon1,nodes[i].icon2,nodes[i].text,nodes[i].script,null,nodes[i].property);
		this.subNodes[this.subNodes.length]=node;
		node.id=this.id+"_"+(this.lastNodeIndex++);
		nodes[i].id=node.id;
		if(!nodes[i].key){
			nodes[i].key=nodes[i].id;
		}
		if(nodes[i].key!=nodes[i].id){
			node.key=nodes[i].key;
		}
		else{
			node.key=node.id;
		}
		node.parNode=this;
		node.parTree=this.parTree;
		if(nodes[i].subNodes.length>0){
			node.setSubNodes(nodes[i].subNodes,true);
		}
	}
	if(!bDontRefresh){
		//刷新子树
		var oTR=document.getElementById(this.id);
		var oTbl=_getTableFromTR(oTR);
		var trSubTree=document.getElementById(this.id+"_SubTree");
		if(!document.getElementById(this.id+"_SubTree")){
			trSubTree=oTbl.insertRow(oTR.rowIndex+1);
			trSubTree.id=this.id+"_SubTree";
			trSubTree.insertCell();
			trSubTree.insertCell();
			trSubTree.insertCell();
			trSubTree.style.display="none";
		}
		trSubTree.cells(2).innerHTML=_getSubNodesHtml(this);
		_reset_nodehtml(this,true,false,false,true);
	}
}

function _removeTreeNode(pIn){
	if(pIn==null){
		return false;
	}
	if(typeof(pIn)=="object"&&pIn.parNode&&pIn.parNode!=this){
		return pIn.parNode.removeNode(pIn);
	}
	var nodes=new Array();
	var nodRemove=null;

	for(var i=0;i<this.subNodes.length;i++){
		var bAdd=true;
		if(typeof(pIn)=="object"){
			if(pIn==this.subNodes[i]){
				bAdd=false;
				nodRemove=pIn;
			}
		}
		else if(pIn==i){
			bAdd=false;
			nodRemove=this.subNodes[pIn];
		}
		if(bAdd){
			nodes[nodes.length]=this.subNodes[i];
		}
	}
	this.subNodes=nodes;
	if(nodRemove){
		_removeNodeInDocument(this,nodRemove);

	}
	return nodRemove;
}

function _removeNodeInDocument(oParObj,nodRemove){
	var oTree=document.getElementById(nodRemove.parTree.id);
	if(!oTree){
		return;
	}

	var trDel=document.getElementById(nodRemove.id);
	if(oTree.SelectedItem==trDel.id){
		oTree.removeAttribute("SelectedItem");
	}
	var oTbl=_getTableFromTR(trDel);
	if(nodRemove.subNodes.length>0){
		oTbl.deleteRow(trDel.rowIndex+1);
	}
	var sScript="";
	//假如是最后一个
	if(trDel.rowIndex==oTbl.rows.length-1&&oParObj.subNodes.length>0){
		_reset_nodehtml(oParObj.subNodes[oParObj.subNodes.length-1],true,false,false,true);
	}
	if(oParObj.subNodes.length==0&&oParObj.parTree!=null){
		_reset_nodehtml(oParObj,true,false,false,false);
		var trSubTree=document.getElementById(oParObj.id+"_SubTree");
		var tblSubTree=_getTableFromTR(trSubTree);
		tblSubTree.deleteRow(trSubTree.rowIndex);
	}
	else{
		oTbl.deleteRow(trDel.rowIndex);
	}

}

function _reset_nodehtml(oNode,bCell1,bCell2,bCell3,bSubTree){
	var oTR=document.getElementById(oNode.id);
	if(!oTR){
		return;
	}
	while(oTR.cells.length<3){
		oTR.insertCell();
	}
	oTR.ParentTree=oNode.parTree.id;
	oTR.key=oNode.key;
	_setObjectProperties(oTR,oNode.property);
	if(bCell1){
		oTR.cells(0).innerHTML=_getNodeLineImg(oNode);
	}
	if(bCell2){
		if(_ifHasProperty(oNode.parTree.style,_TVW_MULTISELECT)){
			oTR.cells(1).innerHTML=_getNodeChkBox(oNode);
			oTR.cells(1).style.width="14px";
		}
		else{
			oTR.cells(1).innerHTML="";
		}
	}
	if(bCell3){
		oTR.cells(2).innerHTML=_getNodeHTML(oNode);
	}
	if(bSubTree&&oNode.subNodes.length>0){
		var oSubTree=document.getElementById(oNode.id+"_SubTree");
		if(oSubTree){
			oSubTree.cells(0).style.backgroundImage=(!_isLastNode(oNode)&&_ifHasProperty(oNode.parTree.style,_TVW_TREELINE)?"url('"+_TREE_ICON_DIR+"/line.gif')":"");
		}
	}
}

function _getJSNodeByKey(sKey){
	if(this.key==sKey){
		return this;
	}
	else{
		for(var i=this.subNodes.length-1;i>=0;i--){
			var obj=this.subNodes[i].find(sKey);
			if(obj){
				return obj;
			}
		}
	}
	return null;
}

function _getHtmlTextOfTreeView(){
	var sCode="<table border=0 id=\""+this.id+"\" cellpadding=0 cellspacing=0 border=0 style=\"cursor:default;font-size:9pt;\" onselectstart=\"return false\">";
	if(this.subNodes.length==1){
		sCode+="<tr id=\""+this.subNodes[0].id+"\" ParentTree=\""+this.subNodes[0].parTree.id+"\" key=\""+this.subNodes[0].key+"\" "+this.subNodes[0].property+"><td>"+(_ifHasProperty(this.style,_TVW_MULTISELECT)?"<td width=14px;>"+_getNodeChkBox(this.subNodes[0]):"<td>")+"<td>"+_getNodeHTML(this.subNodes[0]);
		sCode+="<tr id=\""+this.subNodes[0].id+"_SubTree\"><td><td><td>";
		sCode+=_getSubNodesHtml(this.subNodes[0]);
	}
	else{
		for(var i=0;i<this.subNodes.length;i++){
			sCode+=_getTreeNodeHtml(this.subNodes[i],true);
		}
	}
	sCode+="</table>"
	return sCode;
}

function _getTreeNodeHtml(oJSNode,bIncludeSubNodes){
	var sCode="";
	sCode="<tr id=\""+oJSNode.id+"\" ParentTree=\""+oJSNode.parTree.id+"\" key=\""+oJSNode.key+"\" "+oJSNode.property+"><td>"+_getNodeLineImg(oJSNode);
	if(_ifHasProperty(oJSNode.parTree.style,_TVW_MULTISELECT)){
		sCode+="<td width=14px;>"+_getNodeChkBox(oJSNode);
	}
	else{
		sCode+="<td>";
	}
	sCode+="<td>"+_getNodeHTML(oJSNode);
	if(bIncludeSubNodes&&oJSNode.subNodes.length>0){
		sCode+="<tr id=\""+oJSNode.id+"_SubTree\" style=\"display:none;\"><td style=\""+((!_isLastNode(oJSNode)&&_ifHasProperty(oJSNode.parTree.style,_TVW_TREELINE)&&!_ifHasProperty(oJSNode.parTree.style,_TVW_PLUSMINUS))?"background:url('"+_TREE_ICON_DIR+"/line.gif')":"")+"\">&nbsp;<td><td>";
		sCode+=_getSubNodesHtml(oJSNode);
	}
	return sCode;
}

function _getSubNodesHtml(oJSNode){
	var sCode="<table border=0 cellpadding=0 cellspacing=0 border=0 style=\"cursor:default;font-size:9pt;\" >";
	for(var i=0;i<oJSNode.subNodes.length;i++){
		sCode+=_getTreeNodeHtml(oJSNode.subNodes[i],true);
	}
	sCode+="</table>";
	return sCode;
}

//判断是否为最后的一个节点
function _isLastNode(node){
	var bLastNode=false;
	if(node.parNode==null){
		bLastNode=(node==node.parTree.subNodes[node.parTree.subNodes.length-1]);
	}
	else{
		bLastNode=(node==node.parNode.subNodes[node.parNode.subNodes.length-1]);
	}
	return bLastNode;
}

function _getNodeLineImg(node){
	var oTree=node.parTree;

	if(_ifHasProperty(node.parTree.style,_TVW_PLUSMINUS)){
		if(node.subNodes.length==0){
			return "<span style=width:20px;></span>";
		}
		else{
			return "<span style=width:20px;><img id=\""+node.id+"_lineicon1\" src="+_TREE_ICON_DIR+"/plus.gif align=absmiddle width=9 height=9 style=\"display:"+(oTree.expanOnInit?"none":"")+"\" onclick=\"_treenode_onexpand('"+node.id+"')\"><img id=\""+node.id+"_lineicon2\" src="+_TREE_ICON_DIR+"/minus.gif align=absmiddle width=9 height=9 style=\"display:"+(oTree.expanOnInit?"":"none")+";\" onclick=\"_treenode_onexpand('"+node.id+"')\"></span>";
		}
	}
	if(!_ifHasProperty(node.parTree.style,_TVW_TREELINE)){
		return (node.parNode==null?"&nbsp;":"<span style=width:20px;></span>");
	}
	else{
		var sNode="";
		var bLastNode=_isLastNode(node);
		if(node.subNodes.length==0){
			//没有子节点
			if(bLastNode){
				sNode+="<img src="+_TREE_ICON_DIR+"/cornerline.gif align=absmiddle width=20 height=18>"
			}
			else{
				sNode+="<img src="+_TREE_ICON_DIR+"/crossline.gif align=absmiddle width=20 height=18>"
			}
		}
		else{
			if(bLastNode){
				sNode+="<img id=\""+node.id+"_lineicon1\" src="+_TREE_ICON_DIR+"/cornerplusnode.gif align=absmiddle width=20 height=18 style=\"display:"+(oTree.expanOnInit?"none":"")+"\" onclick=\"_treenode_onexpand('"+node.id+"')\"><img id=\""+node.id+"_lineicon2\" src="+_TREE_ICON_DIR+"/cornerminusnode.gif align=absmiddle width=20 height=18 style=\"display:"+(oTree.expanOnInit?"":"none")+";\" onclick=\"_treenode_onexpand('"+node.id+"')\">";
			}
			else{
				sNode+="<img id=\""+node.id+"_lineicon1\" src="+_TREE_ICON_DIR+"/plusnode.gif align=absmiddle width=20 height=18 style=\"display:"+(oTree.expanOnInit?"none":"")+"\" onclick=\"_treenode_onexpand('"+node.id+"')\"><img id=\""+node.id+"_lineicon2\" src="+_TREE_ICON_DIR+"/minusnode.gif align=absmiddle width=20 height=18 style=\"display:"+(oTree.expanOnInit?"":"none")+";\" onclick=\"_treenode_onexpand('"+node.id+"')\">";
			}
		}
		return sNode;
	}
}

function _getNodeChkBox(oJSNode){
	return "<div style=\"font-size:9pt;border:solid black 1px;width:12px;height:12px;cursor:hand;\" id=\"chk"+oJSNode.id+"\" onclick=_node_onSelectCheckbox(\""+oJSNode.id+"\")>&nbsp;</div>";
}

function _getNodeHTML(oJSNode){
	var sCode="<nobr>";
	if(_ifHasProperty(oJSNode.parTree.style,_TVW_ICON)){
		
		var tempKeyS=oJSNode.key;
		if (tempKeyS=="root")
		{//根目录
			sCode+="<span oncontextmenu=showNewSiteMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle  id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\">&nbsp;</font>";
		}else if (tempKeyS.indexOf("site")!=-1)
		{//站点目录
			tempKeyS=tempKeyS.substring(0,tempKeyS.indexOf("site"));
			if (oJSNode.chk!=null)
			{
				if (oJSNode.chk==1)
				{
					sCode+="<span oncontextmenu=showSiteRightMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\"><input type=\"checkbox\" name=\"siteIDs\" checked value=\""+tempKeyS+"\">&nbsp;</font>";
				}
				else
				sCode+="<span oncontextmenu=showSiteRightMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\"><input type=\"checkbox\" name=\"siteIDs\" value=\""+tempKeyS+"\">&nbsp;</font>";
			}
			else
			sCode+="<span oncontextmenu=showSiteRightMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\">&nbsp;</font>";
		}else{//频道目录
		if (oJSNode.chk!=null)
			{
				if (oJSNode.chk==1)
				{
					sCode+="<span oncontextmenu=showChannelRightMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle  id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\"><input type=\"checkbox\" name=\"channelIDs\" checked value=\""+tempKeyS+"\">&nbsp;</font>";
				}
				else
				sCode+="<span oncontextmenu=showChannelRightMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle  id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\"><input type=\"checkbox\" name=\"channelIDs\" value=\""+tempKeyS+"\">&nbsp;</font>";
			}
			else
			sCode+="<span oncontextmenu=showChannelRightMenu('"+tempKeyS+"')><img src=\""+oJSNode.icon1+"\" align=absmiddle id=\""+oJSNode.id+"_icon1\"><img src=\""+oJSNode.icon2+"\" style=\"display:none;\" align=absmiddle  id=\""+oJSNode.id+"_icon2\"><font style=\"font-size:3px;\">&nbsp;</font>";
		}
	}
        if(_TREE_DBLCLICK_EXPAND)
           sCode+="<a href=#TREEVIEW_ANCHOR id=\""+oJSNode.id
              +"_text\" onmousedown=_select_treenode('"+oJSNode.id
              +"') style=\"height:18px;padding-top:2px;padding-left:3px;padding-right:3px;\" ondblclick=_treenode_onexpand('"
                +oJSNode.id+"') onclick=\""+(oJSNode.script?oJSNode.script:"")
              +"\" class=treeview>"+oJSNode.text+"</a></nobr>";
        else
           sCode+="<a href=#TREEVIEW_ANCHOR id=\""+oJSNode.id
              +"_text\" onmousedown=_select_treenode('"+oJSNode.id
              +"') style=\"height:18px;padding-top:2px;padding-left:3px;padding-right:3px;\""
              +" ondblclick=\""+(oJSNode.script?oJSNode.script:"")
                +";_treenode_onexpand('" +oJSNode.id+"');"
              +"\"  onclick='' class=treeview>"+oJSNode.text+"</a></span></nobr>";

	return sCode;
}

function _ifHasProperty(nSetting,nProperty){
	var i=0;
    var j=0;

    while(Math.pow(2,i++)<=nSetting);
	i=i-2;
	if(Math.pow(2,i)==nProperty){
		return true;
    }
	else{
		if(nSetting<Math.pow(2,i)){
			return false;
		}
		return _ifHasProperty(nSetting-Math.pow(2,i),nProperty);
	}

	return false;
}

function _select_treenode(nodeid){
	var oNode=document.getElementById(nodeid);
	var oTree=document.getElementById(oNode.getAttribute("ParentTree"));
	_disselectTreeNode(oTree.id);
	oTree.SelectedItem=oNode.id;
	var oTxt=document.getElementById(oNode.id+"_text");
	oTxt.style.backgroundColor="activecaption";
	oTxt.style.color="window";
	oTxt.focus();
	var oIcon1=document.getElementById(nodeid+"_icon1");
	var oIcon2=document.getElementById(nodeid+"_icon2");
	if(oIcon1&&oIcon2){
		oIcon1.style.display="none";
		oIcon2.style.display="";
	}
}

function _disselectTreeNode(treeid){
	var oTree=document.getElementById(treeid);
	if(oTree.SelectedItem){
		var oldNode=document.getElementById(oTree.SelectedItem);
		var oTxt=document.getElementById(oldNode.id+"_text");
		oTxt.style.backgroundColor="";
		oTxt.style.color="menutext";
		if(document.getElementById(oldNode.id+"_SubTree")==null){
			var oIcon1=document.getElementById(oldNode.id+"_icon1");
			var oIcon2=document.getElementById(oldNode.id+"_icon2");
			if(oIcon1&&oIcon2){
				oIcon1.style.display="";
				oIcon2.style.display="none";
			}
		}
	}
	oTree.removeAttribute("SelectedItem");
}

function _expandTreeNode(){
	_treenode_onexpand(this.id,true);
}

function _treenode_onexpand(nodeid,bExpand){
	var oNode=document.getElementById(nodeid);
	var oSubTree=document.getElementById(nodeid+"_SubTree");
	if(oSubTree==null){
		return;
	}
	if(bExpand==null){
		var bExpand=(oSubTree.style.display=="none");
	}
	oSubTree.style.display=(bExpand?"":"none");
	var oIcon1=document.getElementById(nodeid+"_icon1");
	var oIcon2=document.getElementById(nodeid+"_icon2");
	if(oIcon1&&oIcon2){
		oIcon1.style.display=(bExpand?"none":"");
		oIcon2.style.display=(bExpand?"":"none");
	}
	var oLineIcon1=document.getElementById(nodeid+"_lineicon1");
	var oLineIcon2=document.getElementById(nodeid+"_lineicon2");
	if(oLineIcon1&&oLineIcon2){
		oLineIcon1.style.display=(bExpand?"none":"");
		oLineIcon2.style.display=(bExpand?"":"none");
	}
}

function _setFocusOnTreeNode(){
	for(var nodTmp=this;nodTmp!=null;nodTmp=nodTmp.parNode){
		nodTmp.expand();
	}
	_select_treenode(this.id);
}

function _getSelectedTreeNode(){
	var oTree=document.getElementById(this.id);
	var sID=oTree.SelectedItem;
	if(sID){
		return document.getElementById(sID);
	}
}

function _selectTreeNode2(node){
	_select_treenode(node.id);
	node.expand();
}

function _getTreeNodeText(){
    return document.getElementById(this.id+"_text").innerText;
    //return this.text;
}

function _setTreeNodeText(text){
	this.text=text;
	if(document.all(this.id)){
		document.getElementById(this.id+"_text").innerText=text;
	}
}

function _node_onSelectCheckbox(nodeid,treeid){
	_setSingleNodeChecked(nodeid);
	var bChecked=(document.all(nodeid).isChecked=="1");
	_setSubNodesChecked(nodeid,bChecked);
	_setParNodeChecked(nodeid);
}

function _setSingleNodeChecked(nodeid,bChecked){
	var oChk=document.all("chk"+nodeid);
	var oNode=document.all(nodeid);
	if(!oNode||!oChk){
		return;
	}
	if(bChecked==null){
		bChecked=oNode.isChecked!="1";
	}
	if(bChecked!="0"){
		oChk.innerHTML="<div style=\"margin-top:-1px;margin-left:-1px;\"><b>√</b></div>";
		if(bChecked=="2"){
			oChk.style.backgroundColor="";
		}
		else{
			oChk.style.backgroundColor="";
		}
	}
	else{
		oChk.style.backgroundColor="";
		oChk.innerHTML="&nbsp;"
	}
	oNode.isChecked=bChecked;;

}

function _setSubNodesChecked(nodeid,bChecked){
	var index=0;
	while(true){
		var sid=nodeid+"_"+index;
		var oChk=document.all("chk"+sid);
		if(oChk){
			_setSingleNodeChecked(sid,bChecked);
			_setSubNodesChecked(sid,bChecked);
		}
		else{
			break;
		}
		index++;
	}

}

function _setParNodeChecked(nodeid){
	var sid="";
	for(var i=nodeid.length;i>0;i--){
		if(nodeid.substring(i-1,i)=="_"){
			sid=nodeid.substring(0,i-1);
			break;
		}
	}
	var oParNode=document.all(sid);
	if(sid==""||!oParNode){
		return;
	}
	var index=0;
	var checked=null;
	while(true){
		var oSubNode=document.all(sid+"_"+index);
		if(!oSubNode){
			break;
		}
		if(checked==null){
			if(oSubNode.isChecked==null){
				oSubNode.isChecked="0";
			}
			checked=oSubNode.isChecked;
		}
		else if(checked!=oSubNode.isChecked){
			checked="2";
		}
		index++;
	}
	_setSingleNodeChecked(sid,checked);
	_setParNodeChecked(sid);
}

function _getCheckedTreeNodes(node){
	if(node==null){
		node=this;
	}
	var oNode=document.all(node.id);
	var sID="";

	if(!oNode){
		return "";
	}
	if(oNode.isChecked=="1"){
		return oNode.id;
	}
	else{
		for(var i=0;i<node.subNodes.length;i++){
			var s=_getCheckedTreeNodes(node.subNodes[i]);
			if(s.length>0){
				if(sID.length>0){
					sID+="\n";
				}
			}
			sID+=s;
		}
	}
	return sID;
}

function _onTreeViewKeyEvent(evt){
	var node=this.getSelectedNode();

	switch(evt.keyCode){
	case 13:
		try{
			if(node!=null){
				_treenode_onexpand(node.id);
				node.all.tags("SPAN")[0].onclick();
			}
		}
		catch(e){}
		break;
	case 38:  //up key
		if(node==null){
			node=document.all(this.subNodes[0].id);
		}
		else{
			node=_getNextTreeNode(node,-1,document.all(this.id));
		}
		_select_treenode(node.id);
		break;
	case 40:  //down key
		if(node==null){
			node=document.all(this.subNodes[0].id);
		}
		else{
			node=_getNextTreeNode(node,1,document.all(this.id));
		}
		_select_treenode(node.id);
		break;
	case 27:
		_disselectTreeNode(this.id);
	}
}

function _getNextTreeNode(oNode,dindex,oTree){
	var index=oNode.sourceIndex;
	var oObj=null;
	while(true){
		index+=dindex;

		if(index<=oTree.sourceIndex){
			index=oTree.sourceIndex+oTree.all.length;
		}
		else if(index>=oTree.sourceIndex+oTree.all.length){
			index=oTree.sourceIndex;
		}
		if(index==oNode.sourceIndex){
			return oNode;
		}
		oObj=document.all(index);
		if(oObj.tagName!="TR"){
			continue;
		}
		//查看oObj是否可见
		var oTemp=oObj;
		while(oTemp!=oTree){
			if(oTemp.style.display=="none"){
				break;
			}
			oTemp=oTemp.parentElement;
		}
		if(oTemp!=oTree){
			continue;
		}
		if(!oObj.ParentTree){
			continue;
		}
		else if(oObj.style.display==""){
			return	oObj;
		}

	}
}

function _setTreeIconDir(path){
	if(path.substring(path.length-1)=="/"){
		path=path.substring(0,path.length-1);
	}
	_TREE_ICON_DIR=path;
}

function _setObjectProperties(obj,str){
	if(str.length==0){
		return;
	}
	var i=0;
	var aProp=new Array();
	var s="";
	while(i<str.length){
		var c=str.charAt(i);
		if(c=="="||c==" "){
			if(s!=""){
				aProp[aProp.length]=s;
			}
			if(c=="="){
				aProp[aProp.length]="=";
			}
			s="";
		}
		else if((c=="\""||c=="'")&&s==""){
			var j=i+1;
			while(j<str.length){
				var c2=str.charAt(j);
				if(c2!=c){
					s+=c2;
				}
				else{
					i=j;
					aProp[aProp.length]=s;
					s="";
					break;
				}
				j++;
			}
		}
		else{
			s+=c;
		}
		i++;
	}
	if(s!=""){
		aProp[aProp.length]=s;
	}
	i=0;
	while(i<aProp.length){
		while(aProp[i+1]!="="&&i<aProp.length-2){
			i++;
		}
		if(i>aProp.length-3){
			break;
		}
		obj.setAttribute(aProp[i],aProp[i+2]);
		i+=3;
	}
}

function _getTableFromTR(oTR){
	var oTbl=oTR;
	while(oTbl&&oTbl.tagName!="TABLE"){
		oTbl=oTbl.parentElement;
	}
	return oTbl;
}

function _enumerateTreeNodes(){
	var sIDs=_enumerateSubNodes(this);
	var aIDs=sIDs.split("\n");
	var aNodes=new Array();
	for(var i=0;i<aIDs.length;i++){
		aNodes[aNodes.length]=document.getElementById(aIDs[i]);
	}
	return aNodes;
}

function _enumerateSubNodes(obj){
	var sIDs="";
	for(var i=0;i<obj.subNodes.length;i++){
		if(obj.subNodes[i].subNodes.length>0){
			sIDs+=(sIDs.length>0?"\n":"")+_enumerateSubNodes(obj.subNodes[i]);
		}
		sIDs+=(sIDs.length>0?"\n":"")+obj.subNodes[i].id;
	}

	return sIDs;
}
function rightC(i){
	alert(i);
	return false;
}