function getobj(sId){
	return document.getElementById(sId);
}
function tooltip(sText){
	Tip(sText,WIDTH,0);
}
function hide(sId){
	getobj(sId).style.display="none";
}
function show(sId){
	getobj(sId).style.display="inline";
}
function nhide(gObj){
	if (typeof(gObj) == "object"){
		gObj.style.visibility = "hidden";
	}else{
		//se non oggetto è stringa
		getobj(gObj).style.visibility = "hidden";
	}
}
function nshow(gObj){
	if (typeof(gObj) == "object"){
		gObj.style.visibility = "visible";
	}else{
		//se non oggetto è stringa
		getobj(gObj).style.visibility = "visible";
	}
}
function arraysearch(aArray,gValore){
	var i;
	for ( i=0 ; i<aArray.length ; i++ )
		if (aArray[i] == gValore)
			return i;
	return -1;
}
var formmanager = new Object();

//WARNING: IMPOSTAZIONE PARAMETRI
formmanager.aImgExt = Array("jpg","jpeg","gif","png");
formmanager.aAllegatiExt = Array("doc","pdf","xls","txt","pps","rar","zip","ppt","odt","docx","xlsx");
//FINE IMPOSTAZIONE

formmanager.fileformat = function (sFile,sType,bFileObbligatorio){
	if (sFile == "") return !bFileObbligatorio;
	var sExt = sFile.split(".").pop().toLowerCase();
	if (sType == "img"){
		if (arraysearch(this.aImgExt,sExt) != -1)
			return 1;
	}else{
		if (arraysearch(this.aAllegatiExt,sExt) != -1)
			return 1;
	}
	return 0;
}
formmanager.isdate = function (sDate){
	var a = getobj("a_" + sDate).value;
	var m = getobj("m_" + sDate).value;
	var g = getobj("g_" + sDate).value;
	if (isNaN(a) || isNaN(m) || isNaN(g)) return 0;
	if (a < 2000 || a > 2030) return 0;
	if (m < 1 || m > 12) return 0;
	if (g < 1 || g > 31) return 0;
	if ((m == 11 || m == 4 || m == 6 || m == 9) && g > 30) return 0;
	if (m == 2){ 
	 	if (a % 4 == 0 && g > 29) return 0;
		if (a % 4 == 1 && g > 28) return 0;
	}
	return 1;
}
formmanager.isbigdate = function (sDate1,sDate2){
	var a1 = getobj("a_" + sDate1).value;
	var m1 = getobj("m_" + sDate1).value;
	var g1 = getobj("g_" + sDate1).value;
	var a2 = getobj("a_" + sDate2).value;
	var m2 = getobj("m_" + sDate2).value;
	var g2 = getobj("g_" + sDate2).value;
	if (a1 > a2) return 1;
	if (a1 < a2) return 0;
	if (a1 == a2){
		if (m1 > m2) return 1;
		if (m1 < m2) return 0;
		if (m1 == m2){
			if (g1 > g2) return 1;
			if (g1 < g2) return 0;
			if (m1 == m2) return 1;
		}
	}
}
formmanager.isemptydata = function (sDate){
	var a = getobj("a_" + sDate).value;
	var m = getobj("m_" + sDate).value;
	var g = getobj("g_" + sDate).value;
	return (a == "" && m == "" && g == "");
}
formmanager.creadata = function (sVal,sDate){
	 var aVal = sVal.split("-");
	 //assegna valori
   getobj("g_" + sDate).value = aVal[0];
   getobj("m_" + sDate).value = aVal[1];
   getobj("a_" + sDate).value = aVal[2];
   //colora di bianco
   this.disevidcampo("g_" + sDate);
   this.disevidcampo("m_" + sDate);
   this.disevidcampo("a_" + sDate);
}
formmanager.eviddata = function (sDate){
   this.evidcampo("g_" + sDate);
   this.evidcampo("m_" + sDate);
   this.evidcampo("a_" + sDate);
}
formmanager.disevidcampo = function (sField){
	 getobj(sField).style.backgroundColor='#ffffff';
}
formmanager.evidcampo = function (sField){
   getobj(sField).style.backgroundColor='#FFA07A';
}
formmanager.blurme = function (oObj){
	 oObj.style.backgroundColor='#ffffff';
}
formmanager.focusme = function (oObj){
	 oObj.style.backgroundColor='#FFFFA4';
}
formmanager.showtab = function (sTab,sOtherTab){
	 var oOtherTabs = sOtherTab.split(","),i;
	 for (i = 0 ; i < oOtherTabs.length ; i++)
		 hide(oOtherTabs[i]);
	 show(sTab);	
}
formmanager.resetrowcolor = function (sTagContainer){
	var oRows = getobj(sTagContainer).getElementsByTagName('tr'), i;
	for (i = 0 ; i < oRows.length ; i++)
		if (oRows[i].className.indexOf("pari") != -1)	
			if (i % 2){
				oRows[i].className = "private-line private-dispari";
				oRows[i].onmouseout = function(){
					this.className = "private-line private-dispari";
				}			
			}else{
				oRows[i].className = "private-line private-pari";
				oRows[i].onmouseout = function(){
					this.className = "private-line private-pari";
				}			
			}					
}
formmanager.submit = function(sFormId){
	var oForm = getobj(sFormId);
	var oHidden = document.createElement('input');
	oHidden.type = "hidden";
	oHidden.name = "invia";
	oHidden.id = "invia";
	oHidden.value = 1;
	oForm.appendChild(oHidden);
	oForm.submit();
}
var formerror = new Object();
formerror.add = function (sStr,sUl){
	oLi = document.createElement('li');
	oLi.className = "form_error";
	oLi.innerHTML = "&nbsp;" + sStr;
	getobj(sUl).appendChild(oLi);
}
formerror.empty = function (sUl){
	this.hide(sUl);
	getobj(sUl).innerHTML = "";
}
formerror.show = function (sUl){
	show(sUl);
}
formerror.hide = function (sUl){
	hide(sUl);
}
var browser = new Object();
browser.getwindowxy = function (){
	 var myWidth = 0, myHeight = 0;
	 if( typeof( window.innerWidth ) == 'number' ) {
	   //Non-IE
	   myWidth = window.innerWidth;
	   myHeight = window.innerHeight;
	 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	   //IE 6+ in 'standards compliant mode'
	   myWidth = document.documentElement.clientWidth;
	   myHeight = document.documentElement.clientHeight;
	 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	   //IE 4 compatible
	   myWidth = document.body.clientWidth;
	   myHeight = document.body.clientHeight;
	 }
	 return [myWidth,myHeight];
}	
browser.getscrollxy = function (){
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
	  return [scrOfX,scrOfY];
}
browser.getmousexy = function (e) {	
		var posx = 0;	var posy = 0;	
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{		
			posx = e.pageX;		
			posy = e.pageY;	
		}	else if (e.clientX || e.clientY) 	{		
			posx = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;		
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;	
		}	
		return [ posx, posy ];
}	
browser.geteventtype = function (e) {
		if (!e) var e = window.event;
		alert(e.type);
}
browser.isrightclick= function (e) {
		var rightclick;
		if (!e) var e = window.event;
		if (e.which) 
			rightclick = (e.which == 3);
		else if (e.button) 
			rightclick = (e.button == 2);
		return rightclick; // true or false
}
browser.getkeypressed = function (e) {
		var code;
		if (!e) var e = window.event;
		if 
			(e.keyCode) code = e.keyCode;
		else if 
			(e.which) code = e.which;
		var character = String.fromCharCode(code);
		return [character, code];
}


var listmanager = new Object();
listmanager.selectall = function (sCheck){
	var i, oCheck;
	for (i=1; oCheck = getobj("check_" + sCheck + "_" + i); i++)
		oCheck.checked = getobj("check_" + sCheck + "_all").checked;
}
listmanager.selectalln = function (sCheck,iNum){
	var i, oCheck;
	for (i=1; i<=iNum; i++)
		if (oCheck = getobj("check_" + sCheck + "_" + i))
			oCheck.checked = getobj("check_" + sCheck + "_all").checked;
}
listmanager.listaselezionati = function (sCheck){
	var aSel = Array(), i, oCheck;
	for (i=1; oCheck = getobj("check_" + sCheck + "_" + i); i++)
		if (oCheck.checked)
			aSel.push(oCheck.value);
	return aSel.join(",");
}
listmanager.listaselezionatin = function (sCheck,iNum){
	var aSel = Array(), i, oCheck;
	for (i=1; i<=iNum ; i++)
		if (oCheck = getobj("check_" + sCheck + "_" + i))
			if (oCheck.checked)
				aSel.push(oCheck.value);
	return aSel.join(",");
}
listmanager.operation = function (sCheck,sHref,sId,sParam,sOtherParam,bMultilang){
	var sLista;
	if (sId == null){
		sLista = this.listaselezionati(sCheck);
		if (sLista == ""){
			alert("Nessun oggetto selezionato!");
			return;
		}
	}else
		sLista = sId;
	if (confirm("Confermi l'operazione?")){
		if (bMultilang && confirm("Applicare l'operazione in tutte le lingue?\nPremere 'annulla' per negare"))
			document.location.href = "?page=" + sHref + "&" + sParam + "=" + sLista + sOtherParam + "&alllang=1";
		else
			document.location.href = "?page=" + sHref + "&" + sParam + "=" + sLista + sOtherParam + "&alllang=0";
	}
}
var ajax = new Object();
//Function to create an XMLHttpRequest.
ajax.getxmlhttp = function (){
	var oXmlHttp = null;
	//If, the activexobject is available, we must be using IE.
	if (window.ActiveXObject){
		oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		//Else, we can use the native Javascript handler.
		oXmlHttp = new XMLHttpRequest();
	}
	return oXmlHttp;
}
//Function to process an XMLHttpRequest.
ajax.process = function (sServerPage, sGetOrPost, sParameter, pfHandleFunc){
	//Get an XMLHttpRequest object for use.
	var oXmlHttp = this.getxmlhttp();
	if (sGetOrPost == "get"){
		oXmlHttp.open("GET", sServerPage);
		oXmlHttp.onreadystatechange = function() {
			if (oXmlHttp.readyState == 4 && oXmlHttp.status == 200) {
				//Handle the response with the function passed
				pfHandleFunc(oXmlHttp.responseText);
			}
		}
		oXmlHttp.send(null);
	} else {
		oXmlHttp.open("POST", sServerPage, true);
		oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		oXmlHttp.onreadystatechange = function() {
			if (oXmlHttp.readyState == 4 && oXmlHttp.status == 200) {
				//Handle the response with the function passed
				pfHandleFunc(oXmlHttp.responseText);
			}
		}
		oXmlHttp.send(sParameter);
	}
}
ajax.parseresponse = function(sText){
	return parseInt(sText.substring(sText.indexOf("<risposta>") + 10, sText.indexOf("</risposta>")));
}
var userchanger = new Object();

userchanger.change = function(gModulo,sTable,sKey,iId,iIdUtente){
	ajax.process("ajax.php?page=private_common_userchanger&modulo="+gModulo+"&table="+sTable+"&key="+sKey+"&id="+iId+"&id_utente="+iIdUtente,"get",null,userchanger.afterchange);
}

userchanger.afterchange = function (sText){
	if (!ajax.parseresponse(sText)){
		document.location.href='?page=common_errore';
	}
}
	var Menu = function(sCont,iOpenDelay,iCloseDelay){
		
		//proprietà oggetto	
		this.sCont = sCont;
		this.iOpenDelay = iOpenDelay;
		this.iCloseDelay = iCloseDelay;
		this.oSelVoice = null;
		this.aDispVoice = new Array();
		this.aEvidVoice = new Array();
		this.iDispTimer = -1;
		this.iHideTimer = -1;
		
		//metodi
		this.onmouseover_voice = function (oVoice){
			//elimino il timer che potrebbe farmi nascondere tutto
			clearTimeout(this.iHideTimer);
			//se ho selezionato il blocco già selezionato esco diretto
			if (this.oSelVoice == oVoice)
				return;
			//elimino l'eventuale timer di visualizzazione che è stato fatto partire prima
			clearTimeout(this.iDispTimer);		
			//imposto sel_voice
			this.oSelVoice = oVoice;
			//lancio il timer per la visualizzazione
			var this_obj = this;
			this.iDispTimer = setTimeout(
													function(){
														this_obj.show_menu();
													},
													this.iOpenDelay
												);
		}	
		this.show_menu = function (){
			//nascondo ciò che visualizzato in precedenza
			this.hide_menu();
			//mostro mio figlio se presente (è un UL)
			var oChild = getobj(this.oSelVoice.id + "_0");
			if (oChild)
				nshow(oChild);
			//mostro i miei antenati (UL)
			for (sUl = this.oSelVoice.id.substr(0,this.oSelVoice.id.lastIndexOf("-")); sUl.indexOf("-") != -1 ; sUl = sUl.substr(0,sUl.lastIndexOf("-")) )
				nshow(sUl);
			//evidenzio i miei me e i miei antenati (LI)
			for (sLi = this.oSelVoice.id ; sLi.indexOf("_") != -1 ; sLi = sLi.substr(0,sLi.lastIndexOf("_")) )
				getobj(sLi).className = getobj(sLi).className.replace(/_out/g,"_in");			
		}	
		this.hide_menu = function (){
			var oCont = getobj(sCont);
			if (oCont){
				//nascondo tutti gli ul contenuti nel container (partendo dal secondo!)
				var aUl = oCont.getElementsByTagName('ul');
				for (var i = 1; i < aUl.length; i++)
					nhide(aUl[i]);
				//dis-evidenzio tutti i li contenuti nel container
				var aLi = oCont.getElementsByTagName('li');
				for (var i = 0; i < aLi.length; i++)
					aLi[i].className = aLi[i].className.replace(/_in/g,"_out");
			}
		}	
		this.onmouseout_voice = function (){
			//lancio il timer per la cancellazione del menu
			var this_obj = this;
			this.iHideTimer = setTimeout(
													 function(){
													 		this_obj.oSelVoice = null;
													 		this_obj.hide_menu();
													 },
													 this.iCloseDelay
												);
		}
	}

