function getObj(name){
  if (document.getElementById){
  	this.obj = document.getElementById(name);
	this.style = this.obj.style;
  }
  else if (document.all){
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers){
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getfObj(frame,name){
  if (document.getElementById){
	this.obj = frame.getElementById(name);
	this.style = frame.getElementById(name).style;
  }
  else if (document.all){
	this.obj = frame.all[name];
	this.style = frame.all[name].style;
  }
  else if (document.layers){
	this.obj = getObjNN4(frame,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name){
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++){
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		//curleft = obj.offsetLeft;
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curtop += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		curtop = obj.offsetTop;
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function interno(id,obj){
	if (obj.id==id)
		return true;
	while (obj.offsetParent){
		obj = obj.offsetParent;
		if (obj.id==id)
			return true;
	}
	return false;
}

function docFrame(IFrameObj){
  var IFrameDoc=null;
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument;
  }
  else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  }
  else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  }
  return IFrameDoc
}

function altRett(misura){
	if (screen.availHeight>768)
		return misura*1.6;
	else if (screen.availHeight>600)
		return misura;
	else
		return misura*0.8;
}

function largRett(misura){
	if (screen.availWidth>1024)
		return misura*1.6;
	else if (screen.availWidth>800)
		return misura;
	else
		return misura*0.7;
}

function stileRett(stile){
	if (screen.availWidth>1024)
		stile=stile + "1800";
	else if (screen.availWidth>800)
		stile=stile + "1024";
	else
		stile=stile + "800";
	var a;
	for(var i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		a.disabled = true;
	if(a.getAttribute("title")==stile)
		 a.disabled = false;
    }
  }
}

var pagAperta=false,__x=0,__y=0;
var menu=null,chiudiAttuale=true;
var MessaggioAttuale=null,Cosa=null;
var fuori=true;


function __apriDialogo(src, target, width, height){
	var top=Math.round((screen.availHeight-height)/2);
	var left=Math.round((screen.availWidth-width)/2);
	document.getElementById("datiAggiornati").innerHTML="null";
	pagAperta=window.open(src,target,"width=" + width + "px,height=" + height +"px,status=no,toolbar=no,left=" + left + "px,top=" + top +"px,screenX=" + left + "px,screenY=" + top +"px");
	//pagAperta=window.open(src);
}

function __controllo(){
	if(pagAperta) pagAperta.focus();
}

function __chiudiDialogo(){
	if(chiudiAttuale){
		if(pagAperta) pagAperta.__chiudiDialogo();
		if (window.opener){
			window.opener.pagAperta=false;
			try{document.location="/form/chiudiDialogo.asp?form=" + __formAttuale}catch(e){};
		}
	}
	else
		chiudiAttuale=true;
}

function entra(e){
	var targ;
	if(!e) {
		e=window.event;
		targ = e.srcElement;
	}
	else
		targ = e.target;
	if (targ.id=="tabLibri" && dialogoAperta){
		fuori=false;
		return true;
	}
	return false;
}

function esci(e){
	if(!e) {
		e=window.event;
		targ = e.srcElement;
	}
	else
		targ = e.target;
	if (targ.id=="tabLibri" && dialogoAperta){
		fuori=true;
		return true;
	}
	return false;
}

function right(e) {
/*
	if (fuori) {
		alert("Spiacenti, il tasto del mouse e' disabilitato");
		return false;
	}
	return true;
*/
	var bottone;
	if (!e){
		e=window.event;
		bottone=e.button;
	}
	else
		bottone=e.which;
	if (bottone==1)
		return true;
		alert("Spiacenti, il tasto del mouse e' disabilitato");
	return false;
}

menuVert=function (e){
	var bottone;
	if (!e){
		e=window.event;
		bottone=e.button;
	}
	else
		bottone=e.which;
	if (bottone==1)
		return true;
	try{
		var cont=(new getObj("__contMenu")).obj;
		cont.style.left= e.screenX-10 + "px";
		cont.style.top= e.screenY-130 + "px";
		cont.style.width= "300px";
		cont.style.height= "60px";
	}
	catch(x){
		alert(x.description);
	}
	event.cancelBubble=true;
	return false;
}

function InizializzaMessaggio(CampoMessaggio,CampoTesto){
	var Testo=(new getObj(CampoTesto)).obj;
	var Messaggio=(new getObj(CampoMessaggio)).obj;
	if (Cosa!=null && Testo!=null) {
		 Cosa.className="nascondiTesto";
	}
	if (Testo!=null){
		Cosa=Testo;
		Cosa.className="mostraTesto";
	}
	MessaggioAttuale=Messaggio;
	if (MessaggioAttuale.className=="level3")
		MessaggioAttuale.className="level3a";
}

function Seleziona(evento,Testo){
	if (MessaggioAttuale.className=="level3a")
		MessaggioAttuale.className="level3";
	InizializzaMessaggio (evento.id, Testo);
	window.event.cancelBubble = true;
}

function formatoData(data,formato){
	if (formato=="tes")
		return giornoLett(data.getDay()) + data.getDate() + "/" + meseLett(data.getMonth()+1) + "/" + data.getFullYear();
	var testo=new Array(),valore=0;
	testo[0]=data.getFullYear();
	valore=data.getMonth()+1;
	if (valore<10)
		testo[1]= "0" + valore;
	else
		testo[1]=valore;
	valore=data.getDate();
	if (valore<10)
		testo[2]= "0" + valore;
	else
		testo[2]=valore;
	valore=data.getHours();
	if (valore<10)
		testo[3]= "0" + valore;
	else
		testo[3]=valore;
	valore=data.getMinutes();
	if (valore<10)
		testo[4]= "0" + valore;
	else
		testo[4]=valore;
	if (formato=="d")
		return testo[2]+"/"+testo[1]+"/"+testo[0];
	else if (formato=="dgo")
		return testo[0]+testo[1]+testo[2]+testo[3]+testo[4];
	else if (formato=="do")
		return testo[2]+"/"+testo[1]+"/"+testo[0]+" "+testo[3]+":"+testo[4];
	else if (formato=="g")
		return testo[0]+testo[1]+testo[2];
	else if (formato=="a")
		return testo[1]+"/"+testo[2]+"/"+testo[0];
}

function giornoLett(ordGiorno){
	switch (ordGiorno){
		case 1:return "Lunedì ";
		case 2:return "Martedì ";
		case 3:return "Mercoledì ";
		case 4:return "Giovedì ";
		case 5:return "Venerdì ";
		case 6:return "Sabato ";
		case 7:return "Domenica ";
	}
	return "";
}

function meseLett(ordMese){
	switch (ordMese){
		case 1:return "Gennaio";
		case 2:return "Febbraio";
		case 3:return "Marzo";
		case 4:return "Aprile";
		case 5:return "Maggio";
		case 6:return "Giugno";
		case 7:return "Luglio";
		case 8:return "Agosto";
		case 9:return "Settembre";
		case 10:return "Ottobre";
		case 11:return "Novembre";
		case 12:return "Dicembre";
	}
	return "";
}

function mostraSubMenu(nome,padre,pos){
	var obj=new getObj(nome);
	if (padre.calcolaPos())
		obj.style.left= findPosX(new getObj(padre.nome+pos).obj) + "px";
	else
		obj.style.left= (new getObj(padre.nome+pos)).style.left;
	obj.style.display="";
	padre.mostra=obj.obj;
}
