var __FXcurrentIdx = 0;
var __FXimgTimer = null;
var __FXimmagini = new Array();
var __FXcolleg = new Array();
var __FXfiltri = new Array();
var __FXtarget = new Array();
var __FXclick = new Array();
var __checkIt = undefined;

function nuovaLingua(nuova, vecchia)
{
var re = /lang=../;
var loc = top.location+"";

	if (loc.indexOf("lang="+vecchia) > -1)
	{
		loc = loc.replace(re, "lang="+nuova);
	}
	else
	{
		if (loc.indexOf("?") > -1)
		{
			loc = loc+"&lang="+nuova;
		}
		else
		{
			loc = loc+"?lang="+nuova;
		}
	}
	if (top.document.forms['__reloadOnLangChange'] == undefined)
	{
		top.location = loc;
	}
	else
	{
		top.document.forms['__reloadOnLangChange'].action = top.location;
		top.document.forms['__reloadOnLangChange'].elements['lang'].value = nuova;
		top.document.forms['__reloadOnLangChange'].submit();	
	}
}

function shrinkToHeight()
{
var eIds = shrinkToHeight.arguments;
var vret;
var elem;
var tmp;
var testo;
var iter = 0;
var maxHeight;
var eId;
var j;
var htmlCont;
var htmlExtra;
var htmlIdx;
	for (var i = 0; i < eIds.length; i++)
	{
		eId = eIds[i];
		j = 0;
		while ((elem = document.getElementById("s"+eId+""+j)) != undefined)
		{
			maxHeight = parseInt(document.getElementById(eId+""+j).style.height, 10);
			htmlCont = elem.innerHTML;
			testo = htmlCont;
			htmlExtra = "";
			htmlIdx = htmlCont.indexOf("<");
			if (htmlIdx > -1)
			{
				testo = htmlCont.substring(0, htmlIdx);
				htmlExtra = htmlCont.substring(htmlIdx);
			}
//	elem.innerHTML = this.titolo;
			vret = testo;
			tmp = testo + "";
			iter = 0;
			while (elem.offsetHeight > maxHeight && iter < 500)
			{
				tmp = tmp.substring(0, tmp.lastIndexOf(' '));
				vret = tmp + " ...";
				elem.innerHTML = vret+htmlExtra;
				iter += 1;
			}
			j += 1;
		}
	}
//	return vret;
}


function calcolaAppPath(loc)
{
var path = loc.pathname;
var i;
var fD = "";
var n = 0;

	if (path.charAt(0) != "/")
	{
		path = "/"+path;
	}
	for (i = 0; i < path.length; i++)
	{
		if (n < 2)
		{
			fD = fD + path.charAt(i);
			if (path.charAt(i) == '/')
			{
				n += 1;
			}
		}
	}
	return fD;
}

function checkdate(objName) 
{
var datefield = objName;
	datefield.value = chkdate(objName);
}

function chkdate(objName) 
{
var strDatestyle = "EU";  //European date style
var strDate = "";
var strDateArray;
var strDay = "";
var strMonth = "";
var strYear = "";
var intday = 0;
var intMonth = 0;
var intYear = 0;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
var oggi = new Date();

strMonthArray[0] = "Gen";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "Mag";
strMonthArray[5] = "Giu";
strMonthArray[6] = "Lug";
strMonthArray[7] = "Ago";
strMonthArray[8] = "Set";
strMonthArray[9] = "Ott";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dic";
strDate = datefield.value;

	if (strDate.length < 1) 
	{
		return "";
	}

	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return "";
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   	}
	}
	
	if (booFound == false) 
	{
		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
	   	}
	}
	
	if (strYear.length == 2) 
	{
		intYear = parseInt(strYear, 10);
		if (isNaN(intYear))
		{
			err = 2;
			return;
		}
		else
		{
			if (intYear+2000 < oggi.getYear())
			{
				strYear = '20' + strYear;
			}
			else
			{
				strYear = '19' + strYear;
			}
		}
	}
	// US style
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
		err = 2;
		return "";
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
	   		}
		}
		
		if (isNaN(intMonth)) 
		{
			err = 3;
			return "";
	   	}
	}

	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return "";
	}

	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return "";
	}

	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return "";
	}

	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return "";
	}

	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return "";
		}
	
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return "";
			}
		}
		else 
		{
			if (intday > 28) 
			{
				err = 10;
				return "";
			}
		}
	}

	if (intday<10){intday = "0"+intday;}
	if (intMonth<10){intMonth = "0"+intMonth;}

	return (intday + "/" + intMonth + "/" + strYear);
}

function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else 
	{
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

function calcolaDataInizio(partenza, giorni)
{
var ms = giorni*24*3600*1000;
var inizio = new Date();
var gg, mm, aaaa;

	inizio.setTime(partenza.getTime() - ms);
	aaaa = inizio.getFullYear();
	mm = (inizio.getMonth()+1)+"";
	gg = inizio.getDate()+"";
	
	if (mm.length == 1) mm = "0"+mm;
	if (gg.length == 1) gg = "0"+gg;
	
	return gg+"/"+mm+"/"+aaaa;
}

function __FXvai(obj, op)
{
var dE = "";
var dS = "";
	if (op == 'agdata')
	{
		if (document.forms['formP'] != undefined)
		{
			if (document.forms['formP'].elements['dS'] != undefined)
			{
				dS = document.forms['formP'].elements['dS'].value;
			}
			if (document.forms['formP'].elements['dE'] != undefined)
			{
				dE = document.forms['formP'].elements['dE'].value;
			}
		}
		if (dE != "" && (dE == dS))
		{
			obj.href += "&dE="+dE;
		}
	}
}

function ricercaPerData(giorni)
{
var oggi = new Date();
var dataS = calcolaDataInizio(oggi, giorni);
var gg, mm, aaaa;
var dataS;

	aaaa = oggi.getFullYear();
	mm = (oggi.getMonth()+1)+"";
	gg = oggi.getDate()+"";
	
	if (mm.length == 1) mm = "0"+mm;
	if (gg.length == 1) gg = "0"+gg;
	
	dataF = gg+"/"+mm+"/"+aaaa;

	document.forms['__formR1'].elements['dS'].value = dataS;
	document.forms['__formR1'].elements['dE'].value = dataF;
	document.forms['__formR1'].submit();
}

function __FXaggiornaImmagine()
{
var elem = document.images['FXimmaTrans__'];
var elemLnk = document.getElementById('FXimmaTransLnk__');
	if (elem != undefined)
	{
		if (__FXimgTimer == null)
		{
			__FXimgTimer = setInterval("__FXaggiornaImmagine()", 3000);
		}
		elemLnk.href = __FXcolleg[__FXcurrentIdx];
		elemLnk.target = __FXtarget[__FXcurrentIdx];
		elemLnk.onclick = new Function (__FXclick[__FXcurrentIdx]);
		
		elem.style.filter = __FXfiltri[__FXcurrentIdx];
    	elem.filters[0].apply();
	
		elem.src = __FXimmagini[__FXcurrentIdx];
	
    	elem.filters[0].play();
	
	
		__FXcurrentIdx += 1;
		if (__FXcurrentIdx >= __FXimmagini.length)
		{
			__FXcurrentIdx = 0;
		}
	}
}

function DL_GetElementTop(eElement)
{
    var nTopPos = eElement.offsetTop;            // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nTopPos += eParElement.offsetTop;        // appending top offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nTopPos;                              // return the number calculated
}

function DL_GetElementLeft(eElement)
{
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}

function spostaEVisualizzaMenuSX(elemento, pElemento)
{
/*
	document.getElementById(elemento).style.left = (DL_GetElementLeft(pElemento)+pElemento.clientWidth-4)+'px';
	document.getElementById(elemento).style.top = DL_GetElementTop(pElemento)+'px';
*/	
	document.getElementById(elemento).style.visibility = 'visible'; 
	document.getElementById(elemento).style.display = '';
	
}

function checkUserInput(elemento)
{
	if (__checkIt != undefined) clearTimeout(__checkIt);

	__checkIt = setTimeout("closeSubMenuSX('"+elemento+"')",100);
	
}

function checkUserInput(elemento, intv)
{
	if (__checkIt != undefined) clearTimeout(__checkIt);

	__checkIt = setTimeout("closeSubMenuSX('"+elemento+"')",intv);
	
}

function unCheckUserInput()
{
	if (__checkIt != undefined) clearTimeout(__checkIt);
	__checkit = undefined;
//	__checkIt = setTimeout('closeSubMenuSX(1)',5000);
}

function closeSubMenuSX(elemento)
{
	if (document.getElementById(elemento))
	{
		document.getElementById(elemento).style.visibility = 'hidden'; 
		document.getElementById(elemento).style.display = 'none';
	}
}

function cleanupWordStyles(elem)
{
var eCo;
var i;
var e;
var a;
var str;
var re;

//	alert(elem.innerHTML);
	eCo = elem.getElementsByTagName("p");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
		if (e.getAttribute("style"))
		{
			e.removeAttribute("style", 0);
		}
		if (e.getAttribute("class"))
		{
			e.removeAttribute("class", 0);
		}
		if (e.getAttribute("className"))
		{
			e.removeAttribute("className", 0);
		}
	}
	eCo = elem.getElementsByTagName("span");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
		if (e.getAttribute("style"))
		{
			e.removeAttribute("style", 0);
		}
		if (e.getAttribute("class"))
		{
			e.removeAttribute("class", 0);
		}
		if (e.getAttribute("className"))
		{
			e.removeAttribute("className", 0);
		}
	}
	eCo = elem.getElementsByTagName("font");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
		if (e.getAttribute("style"))
		{
			e.removeAttribute("style", 0);
		}
		if (e.getAttribute("class"))
		{
			e.removeAttribute("class", 0);
		}
		if (e.getAttribute("className"))
		{
			e.removeAttribute("className", 0);
		}
	}
//	alert(elem.innerHTML);
	eCo = elem.getElementsByTagName("table");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
//		alert(e.outerHTML);
		if (e.getAttribute("style"))
		{
			e.removeAttribute("style", 0);
		}
		if (e.getAttribute("class"))
		{
			e.removeAttribute("class", 0);
		}
		if (e.getAttribute("className"))
		{
			e.removeAttribute("className", 0);
		}
		if (e.getAttribute("width"))
		{
			e.removeAttribute("width", 0);
		}
		
//		alert(e.outerHTML);
	}
	eCo = elem.getElementsByTagName("tr");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
		if (e.getAttribute("style"))
		{
			e.removeAttribute("style", 0);
		}
		if (e.getAttribute("class"))
		{
			e.removeAttribute("class", 0);
		}
		if (e.getAttribute("className"))
		{
			e.removeAttribute("className", 0);
		}
		if (e.getAttribute("width"))
		{
			e.removeAttribute("width", 0);
		}
	}
	eCo = elem.getElementsByTagName("td");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
		if (e.getAttribute("style"))
		{
			e.removeAttribute("style", 0);
		}
		if (e.getAttribute("class"))
		{
			e.removeAttribute("class", 0);
		}
		if (e.getAttribute("className"))
		{
			e.removeAttribute("className", 0);
		}
		if (e.getAttribute("width"))
		{
			e.removeAttribute("width", 0);
		}
	}
	eCo = elem.getElementsByTagName("td");
//	alert(eCo.length);
	for (i = 0; i < eCo.length; i++)
	{
		e = eCo.item(i);
//		alert(e.outerHTML);
		str = e.innerHTML;
		str = str.replace(/nbsp/g,"-");
		str = str.replace(/&-;/g,"");
		e.innerHTML = str;
//		alert("pippo");
//		alert(e.outerHTML);
	}

}
