var stayFolded=true
var exImg=new Image(); exImg.src='img/meno.gif'
var unImg=new Image(); unImg.src='img/piu.gif'

var n = (document.layers) ? 1:0;
var dom1 = (document.getElementById) ? 1:0;
var ie = (document.all) ? 1:0;
var browser=((n || ie || dom1) && parseInt(navigator.appVersion)>=4)

function init()
{
	oTop=new Array()
	oSub=new Array()
	for (i=0; i<15;i++)
	{
	eval ("oTop["+i+"]=new makeMenu('divTop"+(i+1)+"','divCont')");
	eval ("oSub["+i+"]=new makeMenu('divSub"+(i+1)+"','divCont.document.divTop"+(i+1)+"')");
	}
	eval ("oTop["+i+"]=new makeMenu('divTop"+(i+1)+"','divCont')");
	for(i=0;i<oSub.length;i++){ oSub[i].hideIt() }
	var altezzatotale=0
	oTop[0].showIt();
	for(i=1;i<oTop.length;i++)
	{
		oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height);
		altezzatotale+=oTop[i-1].height
		oTop[i].showIt();
	}
	altezzatotale+=oTop[i-1].height
	if (document.layers)
	{
		document.layers["divCont"].clip.height=altezzatotale
		document.height=document.layers["divCont"].pageY +
		document.layers["divCont"].clip.height
	}
}

function makeMenu(obj,nest)
{
	if (document.getElementById && nest && !document.all) nest='document.getElementById("'+nest+'")'; else nest=(!nest) ? '':'document.'+nest+'.';
	
	if (n) this.css=eval(nest+'document.'+obj)
		else if (document.all) this.css=eval('document.all.'+obj+'.style');
	if (dom1)
	{
		
		/*if (nest!='') this.css=eval(nest+'.'+obj+'.style');
		else*/ this.css=eval('document.getElementById("'+obj+'").style');
	}
	/*if (dom1) this.ref= eval(nest+'.style');
	else*/ this.ref=(n) ? eval(nest+'document.'+obj+'.document'):eval('document');
	if (dom1) this.height=eval("parseInt(document.getElementById('"+obj+"').offsetHeight)")
	else this.height=n?this.ref.height:eval(obj+'.height')
	this.x=(n)? this.css.left:this.css.pixelLeft;
	if (dom1) this.x=this.css.left;
	this.y=(n)? this.css.top:this.css.pixelTop;
	if (dom1) this.y=eval("parseInt(document.getElementById('"+obj+"').offsetTop)");
	this.hideIt=b_hideIt;
	this.showIt=b_showIt;
	this.vis=b_vis;
	this.moveIt=b_moveIt											
	return this
}

function b_showIt(){this.css.visibility="visible"}
function b_hideIt(){this.css.visibility="hidden"}
function b_vis(){if(this.css.visibility=="hidden" || this.css.visibility=="hide") return true;}
function b_moveIt(x,y)
{
	this.x=x; 
	this.y=y; 
	this.css.left=this.x;
	this.css.top=this.y;
	if (dom1)
	{
		this.css.left = x + "px";
		this.css.top = y +"px";
	}
}

function menu(num){
	var altezzatotale=0
	if(browser)
	{
		if(!stayFolded){
			for(i=0;i<oSub.length;i++){
				if(i!=num){
					oSub[i].hideIt()
					oTop[i].ref["imgA"+i].src=unImg.src
				}
			}
			for(i=1;i<oTop.length;i++){
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
			}
		}
		if(oSub[num].vis()){
			oSub[num].showIt()
			oTop[num].ref["imgA"+num].src=exImg.src
			
		}else{
			oSub[num].hideIt()
			oTop[num].ref["imgA"+num].src=unImg.src
		}
		for(i=1;i<oTop.length;i++){ 
			if(!oSub[i-1].vis()) 
			{
				oSub[i-1].moveIt(0,oTop[i-1].y + oTop[i-1].height)
				oTop[i].moveIt(0,oTop[i-1].y + oTop[i-1].height + oSub[i-1].height)
				altezzatotale+=oSub[i-1].height
				altezzatotale+=oTop[i-1].height
			}
			else 
			{
				oSub[i-1].moveIt(0, -1000)
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
				altezzatotale+=oTop[i-1].height
			}
		}

		if (document.layers)
		{
		document.layers["divCont"].clip.height=altezzatotale+200
		document.height=document.layers["divCont"].pageY +
		document.layers["divCont"].clip.height
		}
	}
}


function apri_thread(num){
	var altezzatotale=0
	if(browser)
	{
		if(!stayFolded){
			for(i=0;i<oSub.length;i++){
				if(i!=num){
					oSub[i].hideIt()
					oTop[i].ref["imgA"+i].src=unImg.src
				}
			}
			for(i=1;i<oTop.length;i++){
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
			}
		}
		if(oSub[num].vis()){
			oSub[num].showIt()
			oTop[num].ref["imgA"+num].src=exImg.src
			
		}
		for(i=1;i<oTop.length;i++){ 
			if(!oSub[i-1].vis()) 
			{
				oSub[i-1].moveIt(0,oTop[i-1].y + oTop[i-1].height)
				oTop[i].moveIt(0,oTop[i-1].y + oTop[i-1].height + oSub[i-1].height)
				altezzatotale+=oSub[i-1].height
				altezzatotale+=oTop[i-1].height
			}
			else 
			{
				oSub[i-1].moveIt(0, -1000)
				oTop[i].moveIt(0,oTop[i-1].y+oTop[i-1].height)
				altezzatotale+=oTop[i-1].height
			}
		}
	}
}



if(browser) onload=init;
if (self.name==top.name) 
{ 
var ausilio=String(this.location);
location.href="frameset.php?su=newsgroup.php&ng="+ausilio.substring(ausilio.lastIndexOf("ng=")+3,ausilio.length);
}

function apri_busta(img){
	img.src='img/msgletti.gif';
	//document.images[img].width=13;
	//document.images[img].height=12;
}
function centra(){
	document.getElementById('divCont').style.width= 0.85 * parseInt(document.body.clientWidth) + "px";
	document.getElementById('divCont').style.left = 0.05 * parseInt(document.body.clientWidth)+"px";
	/*alert ("Pagina:"+document.body.clientWidth + "\nLivello:" + document.getElementById('divCont').style.left + "\nLivello:" + document.getElementById('divCont').style.width)*/
	if (document.layers)
	{
		document.layers['divCont'].clip.pageX=top.alto.width*0.1;
	}
}

function leggi(num,ng)
{
	top.destra.basso.location='messaggio.php?num='+num+'&ng_id='+ng;
	eval("document.img"+num+".src='img/msgletti.gif'");
	eval("document.img"+num+".height=12");
	eval("document.img"+num+".width=13");
	top.destra.basso.focus();

}
function attesa()
{
	document.getElementById("loading").style.visibility="hidden";
}

function reg()
{
	alert ("Questa funzione è riservata agli utenti registrati");
}

function msg(risposte, allegato, thread, num, ng_id, letto, titolo, nome, data)
{
	// scrive un messaggio di inizio thread
	document.write('<div style="position:relative; width:100%; height:19px"><div style="width:16px" class="cella">')
	if (risposte!=0) document.write('<a href="javascript:menu('+ thread +')"><IMG name="imgA'+ thread +'" SRC="img/piu.gif" WIDTH=13 HEIGHT=13 border=0 alt=apri></a>')
	else document.write ("&nbsp;")
	document.write('</div><div style="left:16px;width:16px" class=cella>')
	if (letto==1) document.write ('<IMG name="img' + num + '" SRC="img/msgletti.gif" WIDTH=13 HEIGHT=12 alt="">')
	else document.write ('<IMG name="img' + num + '" SRC="img/msgdaleggere.gif" WIDTH=14 HEIGHT=11 alt="">')
	document.write ('</div><div class=cella style="left:32px; width=50%">')
	if (allegato!=0) document.write ('<IMG SRC="img/allegato.gif" WIDTH=6 HEIGHT=13 BORDER=0 ALT="">')
	document.write ('<a href="javascript:');
	if (risposte!=0) document.write('apri_thread('+ thread +');')
	//document.write ('leggi(' + num + ', ' + ng_id + ');" CLASS=msg>'+ titolo + '</a></div><div style="left:60%; width=40%; min-width=40%" class="cella">' + nome + '</div><div style="left:90%; width:10%" class="cella">' + data + '</div></div>')
	document.write ('leggi(' + num + ', ' + ng_id + ');" CLASS=msg')
	if (letto==1) document.write (' STYLE="font-weight : lighter;"')
	document.write ('>'+ titolo + '</a></div><div style="left:60%; width=40%; min-width=40%" class="cella">' + nome + '</div><div style="left:90%; width:10%" class="cella">' + data + '</div></div>')
}

function re (livello, allegato, num, ng_id, letto, nome, data)
{
	document.write ('<div style="position:relative; width:100%; height:19px"><div style="left:' + (16*livello) + 'px" class="cella">')
	if (letto==1) document.write ('<IMG name="img' + num + '" SRC="img/msgletti.gif" WIDTH=13 HEIGHT=12 alt="">')
	else document.write ('<IMG name="img' + num + '" SRC="img/msgdaleggere.gif" WIDTH=14 HEIGHT=11 alt="">')
	document.write ('</div><div class=cella style="left:' + (16*(livello+1)) + 'px; width=90%">')
	if (allegato!=0) document.write ('<IMG SRC="img/allegato.gif" WIDTH=6 HEIGHT=13 BORDER=0 ALT="">')
	document.write ('<a href="javascript:leggi(' + num + ', ' + ng_id + ')" CLASS=msg')
	if (letto==1) document.write (' STYLE="font-weight : lighter;"')
	document.write ('>'+ nome + '</a></div><div style="left:90%; width:10%" class="cella">' + data + '</div></div>')
}
