
bw=new Browser();
function TREEView(name,def){
	this.def=def;this.format=def.format;this.name=name;this.num=0;this.anim_ref=0;this.id='ADULTED'+name;
	this.nodes=[];this.root={id:name+"_i"};this.root.level_format=this.format;
	this.root.format=this.format;
	this.root.sub=def.sub;eval("window."+this.id+"=this");
	if (!bw) bw=new Browser();
	this.init=function(){
		this.code='';
		this.back=new DHTMLObject(this.name+'_back');
		this._init(null,this.root,-1,0);
		if (!this.format.no_images) {var f=this.format;

		pldImg([f.e_image,f.c_image])};

		document.write(this.back.draw(this.format.left,this.format.top,this.format.width,this.format.height,this.getp(this.root,"back_bgcolor",0),0,50,this.getp(this.root,"back_class",0),this.code,0)+this.wm_code());
		
		this.back.init();if (this.format.dont_resize_back)this.back.show();
	};
	
	this._init=function(parent,node,lvl,num){
		if(!node) return; node.parent=parent; node.id=node.id||node.parent.id+"_"+num;node.lvl=lvl;node.ind=(this.num++)-1;
		if(node!=this.root){
			this.nodes[node.id]=node;var s=this.init_item(node);
			node.obj=new DHTMLObject(node.id);
			this.code+=(node.obj.draw(0,0,this.getp(node,"width","100%"),0,this.getp(node,"bgcolor",0),0,(1000-this.num),this.getp(node,"div_class",0),s));
		}
		if(node.sub) for(var i=0;i<node.sub.length;i++) this._init(node,node.sub[i], lvl+1,i);
	};
	
	this.wm_code=function()
	{
	
	this.wm=new DHTMLObject(this.name+'_wm');
		return this.wm.draw(this.format.left,this.format.top-25,this.format.width,12,0,1,2,0,(bw.ns4?'<font face="Verdana, sans-serif" color=silver point-size=6>':'<div style="font-size:8px;color:silver;">')+unescape('')+(bw.ns4?'</font>':'</div>'));
	};
	
	this.getp=function(n,name,def,nf){return this.format[name]||def};
	
	this.indent_code=function(n){
		var indent=this.getp(n,"indent",parseInt(this.format.level_indent||16)*n.lvl-this.getp(n,"padding",0))||0;
		return n.lvl&&indent?'<td><img src="'+this.format.b_image+'" width="'+indent+'" height="1"></td>':'';
	};
	
	this.init_item=function(n){
	
		var tc=this.getp(n,"table_class",0);
		
		var s='<table width="'+this.getp(n,"width","100%")+'" cellpadding="'+this.getp(n,"padding",0)+'" cellspacing="'+this.getp(n,"spacing",0)+'" border="0"'+(tc?' class="'+tc+'"':'')+'><tr>';
		s+=this.indent_code(n);
		var img=this.getp(n,(n.sub?n.exp?"e":"c":"i")+"_image",this.format.b_image);
		var sz=this.getp(n,"img_size",[32,16]);
		s+=!this.getp(n,"no_images",0)?'<td>'+(n.sub?'<a onclick="if(this.blur)this.blur()" href="javascript:Toggle(\''+this.name+'\',\''+n.id.substr(this.name.length+3)+'\',0)">':'')+'<img '+(bw.ns4?'name="'+n.id+'_img" ':'')+'id="'+n.id+'_img" src="'+img+'" width="'+sz[0]+'" height="'+sz[1]+'" border="0"/>'+(n.sub?'</a>':'')+'</td>':'';
		var bgc=this.getp(n,"item_bgcolor",0);bgc=bgc?' bgcolor="'+bgc+'"':' ';
		var targ=n.target||this.format.target||0;
		tc=this.getp(n,"item_class",0);var lc=this.getp(n,"link_class",0);
		var hr='Toggle(\''+this.name+'\',\''+n.id.substr(this.name.length+3)+'\',1)';
		var chkimgsrc
		if(n.chk==1){chkimgsrc=this.format['unchk_image']}else{chkimgsrc=this.format['chk_image']}
		s+='<td><a href="javascript:void(0)" onClick="MyToggle(\''+this.name+'\',\''+n.id.substr(this.name.length+3)+'\',0,'+n.myKey+')" ><img '+(bw.ns4?'name="'+n.id+'_chkimg" ':'')+'id="'+n.id+'_chkimg" src="'+chkimgsrc+'" width="11" border="0"/></a></td>'
		
		//s+='<td width="100%"'+bgc+(tc?'class="'+tc+'"':'')+'><a '+(lc?'class="'+lc+'"':'')+'href="'+(n.url||'javascript:'+(n.sub?hr:'void(0)'))+'" onclick="if(this.blur)this.blur();'+(n.sub&&n.url?'Toggle(\''+this.name+'\',\''+n.id.substr(this.name.length+3)+'\',1)':'')+'"'+(targ?' target="'+targ+'"':'')+'>'+n.html+'</a> '+ n.myKey+'</td>';
		
		if(n.url)
			s+='<td width="100%"'+bgc+(tc?'class="'+tc+'"':'')+'><a '+(lc?'class="'+lc+'"':'')+'href="'+(n.url||'javascript:'+('void(0)'))+'" '+(targ?' target="'+targ+'"':'')+'>'+n.html+'</a> '+ n.myKey+'</td>';
		else
		
			s+='<td width="100%"'+bgc+(tc?'class="'+tc+'"':'')+'>'+n.html+'</td>';
		s+="</tr></table>";
		
		return s;
	};
	
	this.get_image=function(par,name){

		return bw.dom?document.getElementById(name):bw.ie4?document.all[name]:bw.ns4?par.el.document.images[name]:[]
	
	};
	
	this.update=function(n){
		if(this.format.no_images) return;
		var src=this.getp(n,(n.sub?n.exp?"e":"c":"i")+"_image",this.format.b_image);
		var img=this.get_image(n.obj,n.id+'_img')||[];
		img.src=src;
		
	};
	
	this.close_level=function(p,n){
		for(var i=0;i<p.sub.length;i++)
			if(p.sub[i]!=n&&p.sub[i].sub&&p.sub[i].exp){
				p.sub[i].exp=0; this.update(p.sub[i]);
				this.collapse_children(p.sub[i],p.sub[i].obj.x,p.sub[i].obj.y,this.format.animation,1,1);
			}
	};
	
	this.click=function(id){
		this.togg(id);
	};
	
	this.MyClick=function(id){
		var n=this.nodes[id];
		
		if(n.chk==1)//if unchecked,check it
		{
			
			if(n.sub)
			{this.checkFolder(n,0)}
			else
			{this.check(n,0)}
		}
		else
		{
			
			if(n.sub)
			{this.checkFolder(n,1)}
			else
			{this.check(n,1)}
			
			if(n.parent)
			{
				this.uncheckParent(n.parent,1)
			}
		}
		pausecomp(100);
		this.draw(1)

	};
	this.checkFolder=function(n,c)
	{
		this.check(n,c)
		if(n.sub)
		{
			for(var i=0;i<n.sub.length;i++)
			{
				if(n.sub[i])
				{
					
					this.checkFolder(n.sub[i],c)
				}
				else{this.check(n.sub[i],c)}
			}
		}
	}
	
	this.uncheckParent=function(n,c)
	{
		this.check(n,c)
		if(n.parent)
		{
			this.uncheckParent(n.parent,c)
		}
	}
	
	this.check=function(n,c)
	{
	var img=this.get_image(n.obj,n.id+'_chkimg')||[];
	
		if(c==1)//Uncheck it
		{
			n.chk=c
			img.src=this.format['unchk_image']
			removeKey(n.myKey)
		}
		else//check it
		{
			n.chk=c
			img.src=this.format['chk_image']
			if(bw.ie)
			pausecomp(10)
			addKey(n.myKey)
			
		}
		
	}
	
	this.togg=function(id){
		if(this.anim_ref>0){return};
		var n=this.nodes[id];
		n.exp=!n.exp;
		if(n.exp&&this.format.one_branch) this.close_level(n.parent,n);
		this.update(n);
		if(this.format.animation&&n.sub&&n.exp) this.collapse_children(n,n.obj.x,n.obj.y,0,0,0);
		if(n.sub&&!n.exp) this.collapse_children(n,n.obj.x,n.obj.y,this.format.animation,1,1,1);
		this.draw(0);
		
	};
	this.collapse_children=function(n,x,y,anim,f,hide,no_move){
		if(!n.obj.el) n.obj.init(this.back);
		if(f)if(!anim){if(!no_move)n.obj.move(x,y);if(hide)n.obj.hide()} else this.slide(n,x,y,this.format.anim_step||20,this.format.anim_timer||20,hide?n.obj.name+".hide()":'');
		if(n.sub) for(var i=0;i<n.sub.length;i++) this.collapse_children(n.sub[i],x,y,anim,1,hide)
	};
	this.draw=function(no_anim){
		if(this.onbeforedraw) this.onbeforedraw(this);
		this.top=0;this.dnum=0;
		this._draw(this.root,no_anim);
		if(!(this.format.animation&&!no_anim)) this.resize_back(0,0);
	};
	this.resize_back=function(x,y){
		if(this.format.dont_resize_back) return;
		var n=this.last_drawed;
		n.bott=n.obj.y+n.obj.h;
		this.back.resize(x||this.format.width, y||n.bott,1);
		this.back.show();
		if(!this.wm.el) this.wm.init();
		this.wm.move(this.back.x,this.back.y+this.back.h+2);
	};
	
	this.expand=function(n,e){if(!n.obj.el) n.obj.init(this.back);if(n.sub){n.exp=e;this.update(n);}};
	
	this.expandAll=function(){for(var i in this.nodes)this.expand(this.nodes[i],1)};
	
	this.expandChecked=function()
	{
	    
	    for(var i in this.nodes)
	    {
	        if(this.nodes[i].chk==0 && this.nodes[i].id!='ADED_i')
	        {
                this.expand(this.nodes[i],1)
                if(this.nodes[i].parent)
                {
                    var x= this.nodes[i].parent
			        if(x.id!='ADED_i')
			        {
                        this.expandParent(x,1)
                     }
                }
	        }
        }
	 };

	this.expandParent=function(n,e)
	{
		this.expand(n,e)
		if(n.parent)
		{ 
		    var x= n.parent   
			if(x.id!='ADED_i')
			{
			    this.expandParent(x,e)
			}
		}
	}
	
	this.checkAll=function(){for(var i in this.nodes)this.check(this.nodes[i],0)};
	
	this.uncheckAll=function(){for(var i in this.nodes)this.check(this.nodes[i],1)};
	
	this.collapseAll=function(){for(var i in this.nodes){this.expand(this.nodes[i],0);this.nodes[i].obj.hide()}};
	
	this.slide=function(n,x,y,speed,step,done,estep){this.anim_ref++;n.obj.slide(x,y,speed,step,this.id+".anim_ref--;"+done, estep||this.id+".resize_back(0,0)")};
	
	this._draw=function(n,no_anim){
		this.last_drawed=n;
		this.dnum++;
		if(this.root!=n){
			if(!n.obj.el) n.obj.init(this.back);
			var indent=this.getp(n,"real_indent",0);
			if(indent!=n.obj.x||this.top.y!=n.obj.y) {
				if(a=this.format.animation&&!no_anim) {
					n.obj.show();
					this.slide(n,indent,this.top,this.format.anim_step||20,this.format.anim_timer||20,'');
				}else{
					n.obj.move(indent,this.top);
					n.obj.show();
				}
			}
			this.top+=n.obj.h+this.getp(n,"offset_y",0);;
		}
		if(n.sub&&(n.exp||this.root==n))
			for(var i=0;i<n.sub.length;i++)
				this._draw(n.sub[i], no_anim);
	};
	this.init();this.draw(1);
	return this;
}
function Browser(){

this.ver=navigator.appVersion;
this.agent=navigator.userAgent.toLowerCase();

this.dom=document.getElementById?1:0;
this.opera5=this.agent.indexOf("opera 5")>-1;
this.opera6=this.agent.indexOf("opera 5")>-1;
this.opera7=(this.agent.indexOf("opera/7")>-1)||(this.agent.indexOf("opera 7")>-1);
this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
this.ie=this.ie4||this.ie5||this.ie6;
this.mac=this.agent.indexOf("mac")>-1;
this.mozilla=this.agent.indexOf("firefox")>-1;
this.ns6=(this.dom && parseInt(this.ver)>=5)?1:0;
this.ns7=(this.agent.indexOf("netscape/7")!=-1)||(this.agent.indexOf("netscape7")!=-1);
this.ns4=(document.layers && !this.dom)?1:0;
this.operaOld=window.opera&&!this.opera7;
this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5||this.opera6||this.opera7);

return this
};
function DHTMLObject(id){

	this.id=id;if(!bw.bw) return;
	this.name='DHTMLObject_'+this.id;
	
	this.init=function(ns4p){
		this.el=bw.dom?document.getElementById(this.id):bw.ie4?document.all[this.id]:bw.ns4?ns4p?ns4p.doc.layers[this.id]:document.layers[this.id]:0;
		if(!this.el) return;this.css=bw.dom||bw.ie4?this.el.style:this.el;
		this.doc=bw.dom||bw.ie4?document:this.css.document;
		this.x=parseInt(this.css.left)||this.css.pixelLeft||this.el.offsetLeft||0;
		this.y=parseInt(this.css.top)||this.css.pixelTop||this.el.offsetTop||0;
		this.w=this.el.offsetWidth||this.css.clip.width||this.doc.width||this.css.pixelWidth||0;
		this.h=this.el.offsetHeight||this.css.clip.height||this.doc.height||this.css.pixelHeight||0;
		this.h=bw.opera7?this.el.firstChild.offsetHeight:this.h;
		this.w=bw.opera7?this.el.firstChild.offsetWidth:this.w;
		if(this.initClip)this.initClip()
		};
	
	this.draw=function(x,y,w,h,bg,v,z,css,code,rel,mover,mout){
	
	if(this.id=='ADED_back')
	{
	    if(bw.ns6 && bw.ns7==false && bw.mozilla==false)
	    {
	    
	    
	        return (bw.ns4?'<'+(rel?'i':'')+'layer id="'+this.id+'" z-index='+z+' left='+x+' top='+y+' '+(w&&w!='auto'?'width='+w:'')+' height='+h+(!v?' visibility=visible':'')+(bg!=""?' bgcolor="'+bg+'"':'')+(css!=''?' class="'+css+'"':'')+(mover?' onmouseover="'+mover+'"':'')+(mout?' onmouseout="'+mout+'"':'')+'>'+code+'</'+(rel?'i':'')+'layer>':'<div id="'+this.id+'" style="position:'+(rel?'relative':'absolute')+';z-index:'+z+';left:'+x+'px;top:'+y+'px;'+(w?'width:'+w+(w=='auto'?'':'px;'):'')+(h?'height:'+h+'px;':'')+(!v?'visibility:hidden;':'')+(bg!=""?''+(bw.ns4?'layer-':'')+'background-color:'+bg+';':'')+'"'+(css!=''?' class="'+css+'"':'')+'>'+code+'</div>')
	    }
	    else
	    {
	    
	        return (bw.ns4?'<'+(rel?'i':'')+'layer id="'+this.id+'" z-index='+z+' left='+x+' top='+y+' '+(w&&w!='auto'?'width='+w:'')+' height='+h+(!v?' visibility=visible':'')+(bg!=""?' bgcolor="'+bg+'"':'')+(css!=''?' class="'+css+'"':'')+(mover?' onmouseover="'+mover+'"':'')+(mout?' onmouseout="'+mout+'"':'')+'>'+code+'</'+(rel?'i':'')+'layer>':'<div id="'+this.id+'" style="overflow:auto;border: solid 1px #670000; position:'+(rel?'relative':'absolute')+';z-index:'+z+';left:'+x+'px;top:'+y+'px;width:450px;height:345px;'+(!v?'visibility:hidden;':'')+(bg!=""?''+(bw.ns4?'layer-':'')+'background-color:'+bg+';':'')+'"'+(css!=''?' class="'+css+'"':'')+'>'+code+'</div>')
	    }
	}else
	{
	    return (bw.ns4?'<'+(rel?'i':'')+'layer id="'+this.id+'" z-index='+z+' left='+x+' top='+y+' '+(w&&w!='auto'?'width='+w:'')+' height='+h+(!v?' visibility=visible':'')+(bg!=""?' bgcolor="'+bg+'"':'')+(css!=''?' class="'+css+'"':'')+(mover?' onmouseover="'+mover+'"':'')+(mout?' onmouseout="'+mout+'"':'')+'>'+code+'</'+(rel?'i':'')+'layer>':'<div id="'+this.id+'" style="position:'+(rel?'relative':'absolute')+';z-index:'+z+';left:'+x+'px;top:'+y+'px;'+(w?'width:'+w+(w=='auto'?'':'px;'):'')+(h?'height:'+h+'px;':'')+(!v?'visibility:hidden;':'')+(bg!=""?''+(bw.ns4?'layer-':'')+'background-color:'+bg+';':'')+'"'+(css!=''?' class="'+css+'"':'')+'>'+code+'</div>')
	}
	
	
	};
	this.move=function(x,y){this.css.left=this.x=x;this.css.top=this.y=y};
	this.moveBy=function(x,y){this.css.left=this.x+=x; this.css.top=this.y+=y};
	this.resize=function(w,h,clip){this.css.pixelWidth=this.css.width=this.w=w;this.css.pixelHeight=this.css.height=this.h=h;if(clip&&this.clip)this.clip(0,w,h,0)};
	this.show=function(){this.css.visibility="visible"};
	this.hide=function(){this.css.visibility="hidden"};
	this.bgColor=function(color){if(bw.opera) this.css.background=color; else if(bw.dom || bw.ie4) this.css.backgroundColor=color; else if(bw.ns4) this.css.bgColor=color};
	this.slide=function(toX,toY,step,speed,execDone,execStep){if(!this.inWay){var newX=toX-this.x;var newY=toY-this.y;var num=Math.sqrt(Math.pow(newX,2)+Math.pow(newY,2))/step;var stepX=newX/num; var stepY=newY/num;this.inWay=1;this.slideInt(stepX,stepY,toX,toY,speed,execDone,execStep)}};
	this.slideInt=function(stepX,stepY,toX,toY,speed,execDone,execStep){function fabs(v){return Math.floor(Math.abs(v))};if(this.inWay&&(fabs(stepX)<fabs(toX-this.x)||fabs(stepY)<fabs(toY-this.y))){this.moveBy(stepX,stepY);if(execStep)eval(execStep);setTimeout(this.name+".slideInt("+stepX+","+stepY+","+toX+","+toY+","+speed+",'"+execDone+"', '"+execStep+"')",speed)}else{this.inWay=0;this.move(toX,toY);if(execStep)eval(execStep);if(execDone)eval(execDone)}};
	this.initClip=function(){this.clp=[];if((bw.dom||bw.ie4)&&this.css.clip){this.clp=this.css.clip.slice(5,this.clp.length-1).split(' ');for(var i=0;i<4;i++)this.clp[i]=parseInt(this.clp[i])};this.ct=this.css.clip.top||this.clp[0]||0; this.cr=this.css.clip.right||this.clp[1]||this.w||0;this.cb=this.css.clip.bottom||this.clp[2]||this.h||0;this.cl=this.css.clip.left||this.clp[3]||0};
	this.clip=function(t,r,b,l,resize){if(bw.ns4){this.css.clip.top=this.ct=t;this.css.clip.right=this.cr=r;this.css.clip.bottom=this.cb=b;this.css.clip.left=this.cl=l}else{this.ct=t>0?t:0;this.cr=r>0?r:0;this.cb=b>0?b:0;this.cl=l>0?l:0;this.css.clip="rect("+this.ct+","+this.cr+","+this.cb+","+this.cl+")"}if(resize)this.resize(this.cr,this.cb,0)};
	eval(this.name+'=this');
	
	return this;
}
function pldImg(arg){for(var i in arg)if(arg[i]&&arg[i]!=''){var im=new Image();im.src=arg[i];}}
function und(val){return typeof(val)=='undefined'}
function Toggle(name,id,br){

void(eval('ADULTED'+name+'.click(\''+name+'_i_'+id+'\','+br+')'));
}


function MyToggle(name,id,br,myKey){
	
	void(eval('ADULTED'+name+'.MyClick(\''+name+'_i_'+id+'\','+br+','+myKey+')'));
}



function pausecomp(Amount)
{
	d = new Date() //today's date
	while (1)
	{
		mill=new Date() // Date Now
		diff = mill-d //difference in milliseconds
		if( diff > Amount ) {break;}
	}
}


function addKey(iKey)
{

	//arrKeys.push(parseInt(iKey)*1)   DOES NOT WORK WITH MAC 
	arrKeys[arrKeys.length] = parseInt(iKey)*1
	

}



function removeKey(iKey)
{
	for(var i=0;i<arrKeys.length;i++)
	{
		if(arrKeys[i] == parseInt(iKey))
		{
			if(!bw.ie5)
			{
			arrKeys.splice(i,1)
			}
		}
	}	
}


function unique(a) {
	tmp = new Array(0);
	for(i=0;i<a.length;i++){
		if(!contains(tmp, a[i])){
			tmp.length+=1;
			tmp[tmp.length-1]=a[i];
		}
	}
	
	return tmp;
}

function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}

function sortit(a,b){
return(a-b)
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function launch(newURL, newName, newFeatures, orgName) {
  var remote = open(newURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
}

