// version 1.2 O'range 2003 Ilya Muzukin ilya@iep.uran.ru
var ns ;
var ie ;
var n6;
var W;
var op;
var aryid = new Array();


function BrowserCheck() {
	if (document.layers) ns=true;
	if (document.all) ie=true;
	op=window.opera;
	if(!ie&&document.getElementById) {
		ns=false;
		n6=true;
	}
	if(ns||n6){
		W=window.innerWidth-16
	} else {
		W=document.body.offsetWidth-20;
	}
}

var level=0;

function TreeView(vname,id,parid,name,link,target,image,image1)
{
	this.vname="Trv"+TreeView.dmcnt;
	TreeView.dmcnt++;
	this.oname=vname+"lay"; // Nome oggetto. E' usato come ID nel LAYER
	this.image=image;
	this.image1=(image1==""||!image1)? image:image1;
	this.name=name;
	this.frname="";
	this.id=id;
	this.imageh=20;this.imagew=12; //***
	this.ih=20;this.iw=10;
	this.x=100;this.y=150;
	this.w=150;this.h=300;
	this.parentItem=null;
	this.parid=parid;
	this.link=link;
	this.target=target;
	this.items=new Array();
	this.itemCount=0;
	this.Opened=true;
	this.bckColor="#ffffff";
	this.fntColor="#000000";
	this.fntSize=2;
	this.icdc=null;
	this.icdo=null;
	this.linkColor="#0000ff";
	this.vlinkColor="#D00001";
	this.alinkColor="#00ffff";
	this.bckIm="/px/images/blank.gif";
	this.opIm="/px/images/blank.gif";
	this.clIm="/px/images/blank.gif";
	this.emp="/px/images/blank.gif";
	this.tre="/px/images/blank.gif";
	this.corn="/px/images/blank.gif";
	this.cont="/px/images/blank.gif";
	this.preCode="";
	this.postCode="";
	this.pc="";
	this.b=false;
	this.i=false;
	this.u=false;
	this.fontFace="Verdana";
	this.Update = TWUpdate;
	this.Switch = TWSwitch;
	this.Add = TWAdd;
	this.Draw = TWDraw;
	this.Get = TWGet;
	this.A = TWA;
	this.Build=TWBuild;
	this.Write=TWWrite;
	this.ind=false;
	this.ilay=null;
	this.nav="";

	eval(this.vname + "=this");
	prl(this.vname+".im1",this.image1);
	prl(this.vname+".im",this.image);
	prl(this.vname+".oop",this.opIm);
	prl(this.vname+".ocl",this.clIm);
	prl(this.vname+".oemp",this.emp);
	prl(this.vname+".otre",this.tre);
	prl(this.vname+".ocorn",this.corn);
	prl(this.vname+".ocont",this.cont);
}

function TWBuild()
{
	this.ind=true;
	var css="";
	var div="";
	var bCol=(ns)?"layer-background-color:" : "background-color:";
	css="<STYLE TYPE='text/css'><!--"+"#"+this.oname+"{position:absolute;top:"+this.y+"px;left:"+this.x+"px;z-index:8}--></STYLE>";
	div="<DIV ID=\""+this.oname+"\">"+this.preCode+this.Draw()+this.postCode+"</DIV>";
	document.write(css);
	document.write(div);
	if(ns) this.ilay=eval("document."+this.oname);
	if(ie) this.ilay=document.all[this.oname];
	if(n6) this.ilay=document.getElementById(this.oname);
}

function TWWrite(txt)
{
	if(ns){
		this.ilay.document.open();
		this.ilay.document.write(txt);
		this.ilay.document.close();
	}
	if(n6||ie) 
		this.ilay.innerHTML=txt;
}

function TWGet(id)
{
	if(id==this.id) 
		return this;
	for(var i=0;i<this.itemCount;i++)
	{
		It=this.items[i].Get(id);
		if(It!=null) return It;
	}
	return null;
}

function TWA(id,parid,name,link,target,image,image1)
{
	if(target=="")
		target="_self";
	It=new TreeView(this.vname,id,parid,name,link,target,image,image1);
	this.Add(It);
}

function TWAdd(item)
{
//	item.Opened=(op)? true:false;
	item.Opened=false;
	It=this.Get(item.parid);
	if(item.parid==this.id)
	{
		aryid[item.id] = item.parid;
		
		this.items[this.itemCount]=item;
		item.opIm=this.opIm;
		item.clIm=this.clIm;
		item.parentItem=this;
		item.vname=this.vname;
		item.tre=this.tre;
		item.cont=this.cont;
		item.corn=this.corn;
		item.emp=this.emp;
		this.itemCount++;
		item.ind=this.ind;
		item.fontFace=this.fontFace;
		item.b=this.b;
		item.i=this.i;
		item.u=this.u;
		item.bckColor=this.bckColor;
		item.fntColor=this.fntColor;
		item.fntSize=this.fntSize;
		item.ih=this.ih;
		item.iw=this.iw;
		
		item.nav = "";
		if ( item.target != "_blank" ) {
			p = item.parentItem;
			l = p.id + ":" +item.id;
			while ( p ) { 
				if ( p.parentItem ) {
					cc=p.Get(p.id);
					if ( cc.parentItem ) {
						l = cc.parentItem.id + ":" + l;
						p = cc.parentItem;
					}
					else {
						l = p.id + ":" + l;
						p=null;
					}
				}
				else 
					p=null;
			}	
			item.nav=l;
		}
		
		return;
	}
	if(It!=null) {
		It.Add(item);
		return;
	}
}

function TWDraw(frname,fin)
{
	if(fin==null) fin=false;
	this.frname=frname;
	var trt="";
	var tro="";
	var but=(fin)? this.ocorn.src: this.otre.src;
	var but1=but;
	var balt="'";
	var balt1="'";
	var a1="";
	var a2="";
	if(this.icdc==null){
		var ico= this.im1.src;
		var ic=this.im.src;
		if(this.itemCount>0)
		{
			but1=this.oop.src;
			balt1="-";
			but=this.ocl.src;
			balt="+";
		}
		this.pre="";
		if(this.parentItem!=null){
			this.pre=this.parentItem.pre;
			but="<IMG SRC="+but+" height="+this.ih+"  width="+this.iw+"  BORDER='0' alt='"+balt+"'>";
			but1="<IMG SRC="+but1+" height="+this.ih+"  width="+this.iw+"  BORDER='0' alt='"+balt1+"'>";
			bck="";
			imstr="";
			var pl="";
			imstr1="";
			if(!this.ind) pl="top.";
			if(this.image!=null){
				// *** "<tr><td><table width='100%' border='0' bgcolor='"+this.bckColor+"' cellspacing='0' cellpadding='0' ><tr><td background='/px/images/pointgray.gif'></td></tr></table></td></tr>"
				//imstr1="<td height="+this.ih+"><IMG SRC="+ico+" HEIGHT="+this.ih+"  WIDTH="+this.ih+"  BORDER='0'></td>";
				//imstr="<td height="+this.ih+"><IMG SRC="+ic+" HEIGHT="+this.ih+"  WIDTH="+this.ih+"  BORDER='0'></td>"
				imstr="<td height="+this.imageh+"><IMG SRC="+ic+" HEIGHT="+this.imageh+"  WIDTH="+this.imagew+"  BORDER='0'></td>"
				imstr1="<td height="+this.imageh+"><IMG SRC="+ico+" HEIGHT="+this.imageh+"  WIDTH="+this.imagew+"  BORDER='0'></td>";
			}
			a1="<a href=\"#\" onClick=\"return "+pl+this.vname+".Switch("+this.id+");\" >";
			a2="</a>";
			ref=this.name;
			if(this.b) ref="<b>"+ref+"</b>";
			if(this.i) ref="<i>"+ref+"</i>";
			if(this.u) ref="<u>"+ref+"</u>";
			//***
			if ( this.nav == "" )
				rf=(this.itemCount>0)? "'#' onClick='javascript:return "+pl+this.vname+".Switch("+this.id+")'":this.link+"' target='"+this.target+"' onClick='javascript:return true'";
			else {
				if ( this.link == "#" ) {
					rf=(this.itemCount>0)? "'#' onClick='javascript:return "+pl+this.vname+".Switch("+this.id+")'":this.link+"&asession[nav]="+this.nav+"' target='"+this.target+"' onClick='javascript:return true'";
				}
				else {
					Ittmp=this.Get(this.id);
					if (Ittmp.Opened==false) {
						if (ns)
							rf=(this.itemCount>0)? "'#' onClick='return "+pl+this.vname+".Switch("+this.id+")'":this.link+"&asession[nav]="+this.nav+"' target='"+this.target+"' onClick='javascript:return true'";
						else
							rf=(this.itemCount>0)? "'#' onClick='javascript:window.location.href=\""+this.link+"\";return "+pl+this.vname+".Switch("+this.id+")'":this.link+"&asession[nav]="+this.nav+"' target='"+this.target+"' onClick='javascript:return true'";
					} else {
						rf=(this.itemCount>0)? "'#' onClick='javascript:return "+pl+this.vname+".Switch("+this.id+")'":this.link+"&asession[nav]="+this.nav+"' target='"+this.target+"' onClick='javascript:return true'";
					}
				}
			}
			//***
			//trt+="<tr height="+this.ih+" ><td> <table border='0' cellspacing='0' cellpadding='0' height="+this.ih+"> "+this.pre+" <td width="+this.iw+" ><a name=\"IT"+this.id+"\"></a>"+
			//	a1+but+a2+"</td>"+" <td noWrap>"+imstr+"<td nowrap bgcolor='"+this.bckColor+"'><a href='"+rf+"><font color='"+this.fntColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></td></a></tr></table></td></tr>";
			if ( this.parentItem.parentItem==null) {
				trt+="<tr height="+this.ih+" ><td> <table border='0' cellspacing='0' cellpadding='0' height="+this.ih+" width='100%'> "+this.pre+" <td width="+this.iw+" ><a name=\"IT"+this.id+"\"></a>"+
//				 	a1+but+a2+"</td>"+" <td noWrap  align='right'>"+imstr+"<td nowrap bgcolor='"+this.bckColor+"' align='right'><a href='"+rf+"><font color='"+this.fntColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></a></td></tr></table></td></tr><tr><td><table width='100%' border='0' bgcolor='"+this.bckColor+"' cellspacing='0' cellpadding='0' ><tr><td background='/px/images/pointgray.gif'></td></tr><tr><td><img src='/px/images/blank.gif' height=10 width=16 border=0></td></tr></table></td></tr>";
				 	a1+but+a2+"</td>"+" <td noWrap  align='right'>"+imstr+"<td nowrap bgcolor='"+this.bckColor+"' align='right'><a href='"+rf+"'><font color='"+this.fntColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></a></td></tr></table></td></tr><tr><td><table width='100%' border='0' bgcolor='"+this.bckColor+"' cellspacing='0' cellpadding='0' ><tr><td background='/px/images/pointgray.gif'></td></tr></table></td></tr>";
				tro+="<tr height="+this.ih+" ><td> <table border='0' cellspacing='0' cellpadding='0' height="+this.ih+" width='100%'> "+this.pre+" <td width="+this.iw+" ><a name=\"IT"+this.id+"\"></a>"+
//				 	a1+but1+a2+"</td>"+" <td noWrap align='right'>"+imstr1+"<td nowrap bgcolor='"+this.bckColor+"' align='right'><a href='"+rf+"><font color='"+this.vlinkColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></a></td></tr></table></td></tr><tr><td><table width='100%' border='0' bgcolor='"+this.bckColor+"' cellspacing='0' cellpadding='0' ><tr><td background='/px/images/pointgray.gif'></td></tr><tr><td><img src='/px/images/blank.gif' height=10 width=16 border=0></td></tr></table></td></tr>";
				 	a1+but1+a2+"</td>"+" <td noWrap align='right'>"+imstr1+"<td nowrap bgcolor='"+this.bckColor+"' align='right'><a href='"+rf+"'><font color='"+this.vlinkColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></a></td></tr></table></td></tr><tr><td><table width='100%' border='0' bgcolor='"+this.bckColor+"' cellspacing='0' cellpadding='0' ><tr><td background='/px/images/pointgray.gif'></td></tr></table></td></tr>";
			} else {
				trt+="<tr height="+this.ih+" ><td> <table border='0' cellspacing='0' cellpadding='0' height="+this.ih+" width='100%'> "+this.pre+" <td width="+this.iw+" ><a name=\"IT"+this.id+"\"></a>"+
					a1+but+a2+"</td>"+" <td noWrap align='right'>"+imstr+"<td nowrap bgcolor='"+this.bckColor+"' align='right'><a href='"+rf+"'><font color='"+this.fntColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></a></td></tr></table></td></tr>";
				tro+="<tr height="+this.ih+" ><td> <table border='0' cellspacing='0' cellpadding='0' height="+this.ih+" width='100%'> "+this.pre+" <td width="+this.iw+" ><a name=\"IT"+this.id+"\"></a>"+
					a1+but1+a2+"</td>"+" <td noWrap align='right'>"+imstr1+"<td nowrap bgcolor='"+this.bckColor+"' align='right'><a href='"+rf+"'><font color='"+this.vlinkColor+"' size='"+this.fntSize+"' face='"+this.fontFace+"'>"+ref+"</font></a></td></tr></table></td></tr>";
			}
		}
		if(this.parentItem==null) {
			var np="<table border='0' bgcolor='"+this.bckColor+"' cellspacing='0' cellpadding='0' width='168'>";
			trt+=np;
			tro+=np;
		}
		this.icdc=trt;
		this.icdo=tro;
		var p2=this.pre;
		if(!fin) this.pre=p2+"<td width="+this.iw+" height="+this.ih+"><img src='"+this.ocont.src+"' height="+this.ih+" width="+this.iw+" border=0></td>"; 
		else this.pre=p2+"<td width="+this.iw+" height="+this.ih+"><img src='"+this.oemp.src+"' height="+this.ih+" width="+this.iw+" border=0></td>"; 
		if(this.parentItem==null) this.pre="";
	}
	trt=(this.Opened)?this.icdo:this.icdc;
	if(this.Opened)
		for(var i=0;i<this.itemCount;i++) {
			var fn=(i==this.itemCount-1)? true:false;
			trt+=this.items[i].Draw(frname,fn);
		}
	//*** Fine dell'ultimo elemento
	if(this.parentItem==null) trt+="<tr><td align='right'><br><br><a href='http://www.xantra.it' target='_blank'><img src='/px/images/xantra.gif' border='0'></a><br><br></td></tr></table>";
	return trt;
}

function TWUpdate()
{
	if(this.parentItem!=null) {
		this.parentItem.Update();
		return;
	}
	if(this.ind){
		this.Write(this.preCode+this.Draw()+this.postCode);
		return;
	}
	offT=0;offL=0;
	if (document.all) {
		offL = top.frames[this.frname].document.body.scrollLeft;
	        offT = top.frames[this.frname].document.body.scrollTop;
	} else {
		offT =top.frames[this.frname].window.pageYOffset;
		offL=top.frames[this.frname].window.pageXOffset;
	}
	D=top.frames[this.frname].document;
	if (document.images)
		D.open("text/html", "replace");
	else
		D.open("text/html");
	D.write("<html><meta http-equiv=\"Expires\" content=\"0\"><meta http-equiv=pragma content=no-cache>");
	D.write("<body bgColor="+this.bckColor+" link="+this.linkColor+" text="+this.fntColor+" vLink="+this.vlinkColor+" aLink="+this.alinkColor+" > "+this.preCode);
	D.write(this.Draw(this.frname));
	D.write(this.postCode+"</body></html>");
	D.close();
	top.frames[this.frname].scroll(offL,offT);
}

function TWSwitch(id)
{
//*** chiude i menu già aperti
/*	It=this.Get(id);
	if (It.parentItem.parentItem==null) {
		for(var i=0;i<this.itemCount;i++) {
			if ( this.items[i].id!=id ) {
				It=this.Get(this.items[i].id);
				It.Opened=false;
			}
		}
	}
*/
	It=this.Get(id);
	var len = aryid.length;
	for (i=0; i < len; i++) {
		if ( aryid[i] == It.parid ) {
			Itf=this.Get(i);
			if ( id != i )
				Itf.Opened=false;	
		}
	}
//***	
	It=this.Get(id);
	if(It.Opened==true) It.Opened=false;
	else It.Opened=true;
	var t="";
	if(this.ind) t="top.";
	this.Update();
	return false;
}

function prl(imgObj,imgSrc) {
	eval(imgObj+' = new Image()');
	eval(imgObj+'.src = "'+imgSrc+'"');
}

TreeView.dmcnt=0;
