/*
Author:fason
Date:2003-8-16
Email:fason_p@163.com
*/
function add_tree(id1,tb1){
window.navigate("tree_add.asp?urlTb="+tb1+"&urlId="+(id1+1));
}
function edit_tree(id,tb2){
window.navigate("tree_edit.asp?urlTb="+tb2+"&urlId="+(id+1));
}
function del_tree(id2,tb3){
window.navigate("tree_del.asp?urlTb="+tb3+"&urlId="+(id2+1));
}

var icon=['img/collapse.gif','img/expand.gif','img/page.gif']
var img=[]
for(i=0;i<icon.length;i++){
img[i]=new Image()
img[i].src=icon[i]
}

function tree(obj,target,selectOne){
	this.obj=obj
	this.target=target
	this.node=[];
	this.single=selectOne?true:false
	this.LightObj=null
	this.html="<style>.deeptree{padding:3px}\n.node{background-color:transparent;font-size:12px;font-family:Arial, Helvetica, sans-serif;color:#000000;padding:4 2 4 0}\n"
	this.html+=".node img{border:0;}\n"
	this.html+=".node a{text-decoration:none;color:#000000;cursor:hand}\n.node a:hover{text-decoration:underline}\n.node a.light{background-color:highlight;color:highlighttext}</style>"
}

tree.prototype.add=function(id,pid,txt,link,tb){
	this.node[this.node.length]=[id,pid,txt,link,tb]
}

tree.prototype.draw=function(n){
	var i;
	for(i=0;i<this.node.length;i++){
	if(this.node[i][1]==n){
	if(this.isFolder(i)){
	this.html+="<div class='node'><nobr><img src='"+img[0].src+"' align='absmiddle' onclick='"+this.obj+".expand(this,"+i+")'><a href='#' id='img"+i+"' onclick='"+this.obj+".expand(this,"+i+")'  title='"+this.node[i][2]+"'><strong>"+this.node[i][2]+"</strong></a></nobr></div><div style='padding-left:10;display:none' id='child"+i+"'>"
	this.draw(this.node[i][0])
	this.html+="</div>"
	}
	else this.html+="<div class='node' style='padding-left:2'><nobr><img src='"+img[2].src+"'  align='absmiddle'><a href='"+(this.node[i][3]?this.node[i][3]:'javascript:void(0)')+"' target='content'  title='"+this.node[i][2]+"'>"+this.node[i][2]+"</a></nobr></div>"
	}
	}
}

tree.prototype.expand=function(o,n){
	if(this.single){
	for(var i=0;i<this.node.length;i++)
	if((this.node[i][1]==this.node[n][1])&&this.isFolder(i)){
	var m=document.getElementById('img'+i)
	var c=document.getElementById('child'+i).style
	m.src=m==o?(c.display==''?img[0].src:img[1].src):img[0].src
	c.display=m==o?(c.display==''?'none':''):'none'
	}
	}
	else{
	var c=document.getElementById('child'+n).style
	o.src=c.display==''?img[0].src:img[1].src
	c.display=c.display==''?'none':''
	}
}

tree.prototype.isFolder=function(n){
var num=0;
for(var i=0;i<this.node.length;i++)
if(this.node[i][1]==this.node[n][0])num++
if(num>0)return true;
return false
}

tree.prototype.expandAll=function(flag){
	for(var i=0;i<this.node.length;i++)
	if(this.isFolder(i)){
	var m=document.getElementById('img'+i)
	var c=document.getElementById('child'+i).style
	m.src=flag?img[1].src:img[0].src
	c.display=flag?'':'none'
	}
}


tree.prototype.Light=function(o){
	if(this.LightObj==null)this.LightObj=o
	this.LightObj.className=''
	o.className='light'
	this.LightObj=o
	o.blur()
}

tree.prototype.toString=function(){
	this.draw(-1);
	return this.html
}
