//==========================================================================================================
//=== TRIM
//==========================================================================================================
//---  LeftTrim: elimina tutti gli spazi a sinistra della stringa ------------------------------------------
function LeftTrim(theString)
{
	var RE;
	RE = /^\s+/gi; // tutti gli spazi, a partire dall'inizio della stringa
	return (theString.replace(RE, ""));
}
//---  RightTrim: elimina tutti gli spazi a destra della stringa -------------------------------------------
function RightTrim(theString)
{	var RE;

	RE = /\s+$/gi; // tutti gli spazi, a partire dalla fine della stringa
	return (theString.replace(RE, ""));
}
//---  Trim: elimina tutti gli spazi a sinistra e a destra della stringa -----------------------------------
function Trim(theString)
{
	theString = LeftTrim(theString);
	theString = RightTrim(theString);

	return (theString);
}

//==========================================================================================================
//=== Le funzioni di controllo hanno parametri di ingresso dati di tipo stringa; restituiscono:
//=== 	 true: se il controllo ha avuto esito positivo
//===    false: se il controllo ha avuto esito negativo
//==========================================================================================================
//---  IsStringUndefined: stringa non valorizzata ----------------------------------------------------------
function IsStringUndefined(theString)
{
	//alert("IsStringUndefined")
	return false;
}
//---  IsStringBlank: stringa contenente solo spazi --------------------------------------------------------
function IsStringBlank(theString)
{
	//alert("IsStringBlank")
	//... Blank ............................................
	if ((Trim(theString)) == "") return true;
	// ... Else ............................................
	return false;
}
//---  IsStringEmpty: stringa "vuota" ----------------------------------------------------------------------
function IsStringEmpty(theString)
{
	//alert("IsStringEmpty")
	//... Undefined ........................................
	if (IsStringUndefined(theString)) return true;
	//... Blank ............................................
	if (IsStringBlank(theString)) return true;
	// ... Else ............................................
	return false;
}

//==========================================================================================================
//---  IsNumberInteger: numero intero ----------------------------------------------------------------------
function IsNumberInteger(theNumber)
{
	var RE;
	var matchArray;

	theNumber += ""; // cast a stringa
	RE = /-?\d+/; // sequenza di un numero qualsiasi di cifre, eventualmente precedute da "-"
	matchArray = theNumber.match(RE);
	//--- Se il numero è diverso dalla sequenza estratta
	if ((matchArray == null) || (theNumber != matchArray[0])) return false;
	//--- Else
	return true;
}

//==========================================================================================================
//---  ValidatorNumerico(object): input solo determinati caratteri -----------------------------------------
function ValidatorNumber(object) {
	
 // Se window.event.returnValue è non definito oppure è false non si applica il validator
 // per non sovrascrivere l'azione di un eventuale validator scatenato prima di quello attuale
 if (window.event.returnValue == "undefined" || window.event.returnValue == false) return;
 
 // Il tasto Enter in caso di textbox multiline deve essere sempre consentito
 if (window.event.keyCode == 13) return;
 
 var values = "0123456789";
 if (values.indexOf(String.fromCharCode(window.event.keyCode)) == -1)
  window.event.returnValue = false;
}

//==========================================================================================================
//--- LenMax(Value, Len): Funzione interna per la lunghezza massima [AF, SS, 16 June 2003]
function LenMax(Value, Len)
{
	if ((!(Value == "")) && (!(Value.length <= Len)))
	{
		return (0);
	}
	return (1);
}

//==========================================================================================================
//---  checkMail(TextBox): controlla campo e-mail ----------------------------------------------------------
function checkMail(TextBox)
{
	return(controllaMail(TextBox, true));
}

//--- ControllaMail(TextBox,avviso): Funzione e-mail [AF, SS, 16 June 2003]
function controllaMail(TextBox,avviso)
{
	apos=TextBox.indexOf("@");
	dotpos=TextBox.lastIndexOf(".");
	lastpos=TextBox.length-1;

	if (TextBox.value == "")
		return(1);
		if (!(LenMax(TextBox, 50))) {
		if (avviso==true) alert("Inserire al più 50 caratteri nel campo.");
		//TextBox.focus();
		return 0;
	}
	if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) {
		if (avviso==true) alert('Inserire un indirizzo e-mail valido');
		//TextBox.focus();
		return(0);
	}
	return 1;
}

function IsDateEmpty(dd, mm, yyyy)
{	
	//... Data vuota....................................................
	if ((dd == 0) && (mm == 0) && (IsStringEmpty(yyyy)))  return true;
	//... Else .........................................................
	return false;
}
//---  IsYearNotValid: anno non di quattro cifre
function IsYearNotValid(yyyy)
{	
	if (yyyy.search(/\d{4}/) == -1) return true; 
	//... Else ..........................................................
	return false;
}

//==========================================================================================================
//---  IsDateNotValid(dd, mm, yyyy): controlla campo e-mail ------------------------------------------------
function IsDateNotValid(dd, mm, yyyy)
{
 //... Data vuota: data valida ........................................
 if ((dd == 0) && (mm == 0) && (IsStringEmpty(yyyy)))  return false;
 //... Data incompleta: data non valida ...............................
 if ((dd == 0) || (mm == 0) || (IsStringEmpty(yyyy)))  return true;
 //... Anno non corretto: non valida ..................................
 if (IsYearNotValid(yyyy)) return true;
 //... Data non corretta (es. 31 giugno, 29 febbraio di anno non bisestile...): data non valida .............................
 var testDate = new Date(yyyy, mm-1, dd)
 if (!((yyyy==testDate.getFullYear()) && (mm==(testDate.getMonth()+1)) && (dd==testDate.getDate()))) return true;
 //... Else ..........................................................
 return false;
}

//==========================================================================================================
//--- IsDateGreaterThan: prima data più recente della seconda ----------------------------------------------
function IsDateGreaterThan(dd_1, mm_1, yyyy_1, dd_2, mm_2, yyyy_2)
{ 
 var date_1 = new Date(yyyy_1, mm_1-1, dd_1);
 var date_2 = new Date(yyyy_2, mm_2-1, dd_2);
 
 date_1 = date_1.getTime();
 date_2 = date_2.getTime();
 
 if (date_1 > date_2) return true;
 //... Else ..........................................................
 return false;
}

//--- PopUpStatistiche (documento): Apertura Pop Up statistiche [UG, MG, 21 July 2005]
function PopUpStatistiche(documento) {
	var customWindow
	customWindow = window.open(documento, "popUpStatistiche", "toolbar=no, scrollbars= yes, location=no, directories=no, status=no, menubar=no, resizable=no, width=800, height=400");
	customWindow.moveTo(100,150);
	customWindow.focus();
}

//--- checkNumAccessi(theForm): Controllo per form ultimi accessi statistiche [UG, MG, 21 July 2005]
function checkNumAccessi(theForm) {
	if (theForm.numAccessi.value== "") {
		alert("Compilare il campo.");
		theForm.numAccessi.focus();
		return;
	}
	
	if ( !(IsNumberInteger(theForm.numAccessi.value)) ) {
		alert ("E' necessario inserire un valore numerico.");
		theForm.numAccessi.value = '';
		theForm.numAccessi.focus();
		return;
	}
		
	theForm.action = "statistiche.asp?Idstep=1";
	theForm.submit();
}

function setFolderNavigationClass(idFolder)
{
	if (document.getElementById("hdnIdTab"))
	{
		document.getElementById("hdnIdTab").value = idFolder;
	}
	switch (parseInt(idFolder)) 
	{
		case 1:
			document.getElementById("label_1").className = "label_tabellaSchede_on";
			document.getElementById("label_2").className = "label_tabellaSchede_off";
			if (document.getElementById("label_3"))
			{
				document.getElementById("label_3").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_4"))
			{
				document.getElementById("label_4").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_5"))
			{
				document.getElementById("label_5").className = "label_tabellaSchede_off";
			}

			document.getElementById("div_1").className = "div_tabellaSchede_on";
			document.getElementById("div_2").className = "div_tabellaSchede_off";
			if (document.getElementById("div_3"))
			{
				document.getElementById("div_3").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_4"))
			{
				document.getElementById("div_4").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_5"))
			{
				document.getElementById("div_5").className = "div_tabellaSchede_off";
			}		
		break;
		
		case 2:
			document.getElementById("label_1").className = "label_tabellaSchede_off";
			document.getElementById("label_2").className = "label_tabellaSchede_on";
			if (document.getElementById("label_3"))
			{
				document.getElementById("label_3").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_4"))
			{
				document.getElementById("label_4").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_5"))
			{
				document.getElementById("label_5").className = "label_tabellaSchede_off";
			}

			document.getElementById("div_1").className = "div_tabellaSchede_off";
			document.getElementById("div_2").className = "div_tabellaSchede_on";
			if (document.getElementById("div_3"))
			{
				document.getElementById("div_3").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_4"))
			{
				document.getElementById("div_4").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_5"))
			{
				document.getElementById("div_5").className = "div_tabellaSchede_off";
			}
		break;

		case 3:
			document.getElementById("label_1").className = "label_tabellaSchede_off";
			document.getElementById("label_2").className = "label_tabellaSchede_off";
			if (document.getElementById("label_3"))
			{
				document.getElementById("label_3").className = "label_tabellaSchede_on";
			}
			if (document.getElementById("label_4"))
			{
				document.getElementById("label_4").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_5"))
			{
				document.getElementById("label_5").className = "label_tabellaSchede_off";
			}

			document.getElementById("div_1").className = "div_tabellaSchede_off";
			document.getElementById("div_2").className = "div_tabellaSchede_off";
			if (document.getElementById("div_3"))
			{
				document.getElementById("div_3").className = "div_tabellaSchede_on";
			}
			if (document.getElementById("div_4"))
			{
				document.getElementById("div_4").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_5"))
			{
				document.getElementById("div_5").className = "div_tabellaSchede_off";
			}		
		break;
		
		case 4:
			document.getElementById("label_1").className = "label_tabellaSchede_off";
			document.getElementById("label_2").className = "label_tabellaSchede_off";
			if (document.getElementById("label_3"))
			{
				document.getElementById("label_3").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_4"))
			{
				document.getElementById("label_4").className = "label_tabellaSchede_on";
			}
			if (document.getElementById("label_5"))
			{
				document.getElementById("label_5").className = "label_tabellaSchede_off";
			}

			document.getElementById("div_1").className = "div_tabellaSchede_off";
			document.getElementById("div_2").className = "div_tabellaSchede_off";
			if (document.getElementById("div_3"))
			{
				document.getElementById("div_3").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_4"))
			{
				document.getElementById("div_4").className = "div_tabellaSchede_on";
			}
			if (document.getElementById("div_5"))
			{
				document.getElementById("div_5").className = "div_tabellaSchede_off";
			}			
		break;
		
		case 5:
			document.getElementById("label_1").className = "label_tabellaSchede_off";
			document.getElementById("label_2").className = "label_tabellaSchede_off";
			if (document.getElementById("label_3"))
			{
				document.getElementById("label_3").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_4"))
			{
				document.getElementById("label_4").className = "label_tabellaSchede_off";
			}
			if (document.getElementById("label_5"))
			{
				document.getElementById("label_5").className = "label_tabellaSchede_on";
			}

			document.getElementById("div_1").className = "div_tabellaSchede_off";
			document.getElementById("div_2").className = "div_tabellaSchede_off";
			if (document.getElementById("div_3"))
			{
				document.getElementById("div_3").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_4"))
			{
				document.getElementById("div_4").className = "div_tabellaSchede_off";
			}
			if (document.getElementById("div_5"))
			{
				document.getElementById("div_5").className = "div_tabellaSchede_on";
			}			
		break;
	}	
}

//----------------------------------------------------
//--- mostraNascondiDiv(elem)
function mostraNascondiDiv(elem)
{	
	if(document.getElementById(elem).style.display=='block')
	{
		document.getElementById(elem).style.display='none';
	}
	else
	{
		document.getElementById(elem).style.display='block';
	}
}

//----------------------------------------------------
//--- printPage()
function printPage()
{
	document.getElementById(1).style.display='none';
	document.getElementById(2).style.display='none';
	window.print();
	//document.getElementById(1).style.display='block';
	//document.getElementById(2).style.display='block';
}

//----------------------------------------------------
//--- checkForumReg(TheForm)
function checkForumReg(TheForm)
{
	if(TheForm.txtNome.value.length<2)
	{
		alert("Inserire un nome valido");
		TheForm.txtNome.focus();
		return true;
	}
	if(TheForm.txtCognome.value.length<2)
	{
		alert("Inserire un cognome valido");
		TheForm.txtCognome.focus();
		return true;
	}
	if ((TheForm.txtEmail.value==null)||(TheForm.txtEmail.value==""))
	{
		alert("Inserire un email corretta")
		TheForm.txtEmail.focus()
		return true;
	}
	if (controllaMail(TheForm.txtEmail.value, true)==false)
	{
		TheForm.txtEmail.value=""
		TheForm.txtEmail.focus()
		return true;
	}
	if(TheForm.txtUsername.value.length<4)
	{
		alert("Inserire un username valido");
		TheForm.txtUsername.focus();
		return true;
	}
	if(TheForm.txtPassword.value.length<4)
	{
		alert("Inserire una password valida");
		TheForm.txtPassword.focus();
		return true;
	}
	if(TheForm.txtRepeatPassword.value.length<4)
	{
		alert("Inserire una password valida");
		TheForm.txtRepeatPassword.focus();
		return true;
	}
	if(TheForm.txtPassword.value!=TheForm.txtRepeatPassword.value)
	{
		alert("Le due password sono diverse fra loro");
		TheForm.txtPassword.focus();
		return true;
	}
	if(!TheForm.rdbPrivacy[0].checked)
	{
		alert("Devi accettare le informative sulla privacy");
		TheForm.rdbPrivacy[0].focus();
		return true;
	}
	if (confirm("Attenzione: \n\nSei sicuro di voler procedere?"))
	{
		TheForm.submit();
	}
}

//----------------------------------------------------
//--- checkNewsletter(TheForm) @fg(11221)
function checkNewsletter(TheForm)
{
	if(TheForm.txtNome.value.length<2)
	{
		alert("Inserire un nome valido");
		TheForm.txtNome.focus();
		return true;
	}
	if(TheForm.txtCognome.value.length<2)
	{
		alert("Inserire un cognome valido");
		TheForm.txtCognome.focus();
		return true;
	}
	if ((TheForm.txtEmail.value==null)||(TheForm.txtEmail.value==""))
	{
		alert("Inserire un email corretta");
		TheForm.txtEmail.focus();
		return true;
	}
	if (controllaMail(TheForm.txtEmail.value, true)==false)
	{
		TheForm.txtEmail.value="";
		TheForm.txtEmail.focus();
		return true;
	}
	if(!TheForm.rdbPrivacy[0].checked)
	{
		alert("Devi accettare le informative sulla privacy");
		TheForm.rdbPrivacy[0].focus();
		return true;
	}
	if (confirm("Attenzione: \n\nSei sicuro di voler procedere?"))
	{
		TheForm.submit();
	}
}

//----------------------------------------------------
//--- checkInvioArticolo(TheForm) @fg(11221)
function checkInvioArticolo(TheForm)
{
	if(TheForm.txtNome.value.length<2)
	{
		alert("Inserire un nome valido");
		TheForm.txtNome.focus();
		return true;
	}
	if ((TheForm.txtEmail.value == null) || (TheForm.txtEmail.value == ""))
	{
		alert("Inserire un email corretta");
		TheForm.txtEmail.focus();
		return true;
	}
	if (controllaMail(TheForm.txtEmail.value, true)==false)
	{
		TheForm.txtEmail.value="";
		TheForm.txtEmail.focus();
		return true;
	}
	if (confirm("Attenzione: \n\nSei sicuro di voler procedere?"))
	{
		TheForm.submit();
	}
}

function changeLang(idLang,lPage)
{		
	if (lPage == 2) 
	{
		window.location.href='../includes/incChangeLang.asp?idLang='+ idLang;
	}
	else
	{
		window.location.href='includes/incChangeLang.asp?idLang='+ idLang;
	}
}

function setCookie(NameOfCookie, value, expiredays)
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function getCookie(NameOfCookie)
{
	if (!navigator.cookieEnabled)
	{
    	alert('Per poter visualizzare correttamente questo sito devi abilitare i cookies');
	}
	else
	{
		if (document.cookie.length > 0)
		{
			begin = document.cookie.indexOf(NameOfCookie+"=");
			if (begin != -1)
			{
				begin += NameOfCookie.length+1;
				end = document.cookie.indexOf(";", begin);
				if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end));
			}
			return null;
		}
	}
}

function NewWindow(mypage,myname,w,h)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+', toolbar=no, location=no, status=no, scrollbars=yes, resizable=no';
	win = window.open(mypage,myname,settings);
	if(win.window.focus)
	{
		win.window.focus();
	}
}

// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers più recenti e diffusi
function assegnaXMLHttpRequest()
{
	var XHR = null, browserUtente = navigator.userAgent.toUpperCase();
	
	// browser standard con supporto nativo non importa il tipo di browser
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
	{
		XHR = new XMLHttpRequest();
	}

	// browser Internet Explorer - è necessario filtrare la versione 4
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0)
	{
 
		// la versione 6 di IE ha un nome differente per il tipo di oggetto ActiveX
		if(browserUtente.indexOf("MSIE 5") < 0)
		{
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		}
		// le versioni 5 e 5.5 invece sfruttano lo stesso nome
		else
		{
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return XHR;
}
 
var http = assegnaXMLHttpRequest();
 
function changeStateSondaggio(id)
{
	var postData = "idStep=4&id="+id;
	http.open("POST", "cmsSondaggi.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Sondaggio",5,6); };
	http.send(postData);
}

function changeStateTemaFAQ(id)
{
	var postData = "idStep=8&id="+id;
	http.open("POST", "cmsFAQ.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"FAQTema",1,8); };
	http.send(postData);
}

function changeStateTipologiaFAQ(id)
{
	var postData = "idStep=8&id="+id;
	http.open("POST", "cmsFAQ.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"FAQTipologia",1,8); };
	http.send(postData);
}

function changeStateFAQ(id)
{
	var postData = "idStep=9&id="+id;
	http.open("POST", "cmsFAQ.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"FAQ",1,8); };
	http.send(postData);
}

function changeStateTipologieDocumentazione(id)
{
	var postData = "idStep=9&id="+id;
	http.open("POST", "cmsDocumentazione.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"TipoDoc",1,8); };
	http.send(postData);
}

function changeStateDocumentazione(id)
{
	var postData = "idStep=10&id="+id;
	http.open("POST", "cmsDocumentazione.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Doc",1,8); };
	http.send(postData);
}

function changeStateEures(id)
{
	var postData = "idStep=6&id="+id;
	http.open("POST", "cmsEures.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Offerta",1,8); };
	http.send(postData);
}

function changeStateGalleria(id)
{
	var postData = "idStep=5&id="+id;
	http.open("POST", "cmsGallerieFotografiche.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Galleria",1,8); };
	http.send(postData);
}

function changeStateEventi(id)
{
	var postData = "idStep=4&id="+id;
	http.open("POST", "cmsEventi.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Eventi",1,8); };
	http.send(postData);
}

function changeStateGlossario(id)
{
	var postData = "idStep=5&id="+id;
	http.open("POST", "cmsGlossario.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Glossario",1,8); };
	http.send(postData);
}

function changeStateScadenziario(id)
{
	var postData = "idStep=4&id="+id;
	http.open("POST", "cmsScadenziario.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Scadenziario",1,8); };
	http.send(postData);
}

function changeStateTipologieSiti(id)
{
	var postData = "idStep=10&id="+id;
	http.open("POST", "cmsSitiWeb.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"TipoLink",1,8); };
	http.send(postData);
}

function changeStateSiti(id)
{
	var postData = "idStep=11&id="+id;
	http.open("POST", "cmsSitiWeb.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"Sito",1,8); };
	http.send(postData);
}

function changeStateAggregatoreSubCanali(id)
{
	var postData = "idStep=5&id="+id;
	http.open("POST", "cmsAggregatore.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"AggregatoreSubCanali",1,8); };
	http.send(postData);
}

function changeStateAggregatoreCanali(id)
{
	var postData = "idStep=9&id="+id;
	http.open("POST", "cmsAggregatore.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { getStateResponse(id,"AggregatoreCanali",1,8); };
	http.send(postData);
}

function spostaFileRepository(element, idTipologia)
{
	var idFile, strElementId;
	strElementId = String(element.id);
	var iLen = String(strElementId).length;
	idFile = eval(String(strElementId).substring(11, iLen));
	var postData = "idStep=12&idFile="+idFile+"&idTipologia="+idTipologia;
	http.open("POST", "cmsRepository.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { hideTR(idFile); };
	http.send(postData);
}

function hideTR(idTR)
{
	var trName = 'trFile' + String(idTR);
	var row = document.getElementById(trName);
	row.style.display = 'none';
}

function getStateResponse(id, idName, stateAbil, stateDisab)
{
	if(http.readyState == 4)
	{  
		var response = http.responseText;
		if (response != "")
		{
			imgIDName = 'img' + idName + id;
			lnkIDName = 'lnk' + idName + id;
			//@fg(11560) aggiunto il cambio etichetta
			if(response == stateDisab)
			{
				document.getElementById(imgIDName).setAttribute("src","../Images/ico_abilita.gif");
				document.getElementById(imgIDName).setAttribute("alt","Il contenuto è attualmente disattivato. Fare click per attivare.");
				document.getElementById(lnkIDName).setAttribute("title","Il contenuto è attualmente disattivato. Fare click per attivare.");
			}
			else if(response == stateAbil)
			{
				document.getElementById(imgIDName).setAttribute("src","../Images/ico_disabilita.gif");
				document.getElementById(imgIDName).setAttribute("alt","Il contenuto è attualmente attivo. Fare click per disattivare.");
				document.getElementById(lnkIDName).setAttribute("title","Il contenuto è attualmente attivo. Fare click per disattivare.");
			}
			else
			{
				return;
			}
		}
		else
		{
			return;
		}
	}
}

function addFileToGallery(element, idGalleria)
{
	var idFile, strElementId;
	strElementId = String(element.id);
	var iLen = String(strElementId).length;
	idFile = eval(String(strElementId).substring(11, iLen));
	var postData = "idStep=6&idFile="+idFile+"&idGalleria="+idGalleria;
	http.open("POST", "cmsGallerieFotografiche.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { insertTRGallery(); };
	http.send(postData);
}

function insertTRGallery()
{
	if(http.readyState == 4)
	{  
		var response = http.responseText;
		if (response != "")
		{
			var returnValue = response.split("|");
			var newId = returnValue[0];
			var newTitle = returnValue[1];
			var newName = returnValue[2];
			var newIcon = returnValue[3];
			var trName = 'trFile' + newId;
			var tableObj = document.getElementById('elencoGalleria');
			var bgBody = ((tableObj.rows.length - 1) % 2) + 1;
			var tbodyObj = document.getElementById('elencoGalleriaTbody');
			var tr1Obj = document.createElement("tr");
			var varSfondo = 'sfondo' + bgBody;
			tr1Obj.setAttribute((document.all ? 'className' : 'class'), varSfondo);
			tr1Obj.setAttribute('id', 'trFileGallery'+newId);
			var tr1td1Obj = document.createElement("td");
			tr1td1Obj.setAttribute('width','95%');
			var imgTag = document.createElement("img");
			imgTag.setAttribute('src','../images/'+newIcon+'', 'alt', newTitle, 'align', 'top');
			tr1td1Obj.appendChild(imgTag);
			tr1td1Obj.appendChild(document.createTextNode(" "));
			var spanTag = document.createElement("span");
			spanTag.setAttribute((document.all ? 'className' : 'class'), 'repository_fileLink');
			spanTag.ondblclick = function() { window.open('../upload/'+newName+''); void(0); };
			var aTag = document.createElement("a");
			aTag.appendChild(document.createTextNode(newTitle));
			spanTag.appendChild(aTag);
			tr1td1Obj.appendChild(spanTag);
			var tr1td1Obj2 = document.createElement("td");
			tr1td1Obj2.setAttribute('width','5%');
			var aTag2 = document.createElement("a");
			aTag2.setAttribute('href','Javascript: removePhoto('+newId+');')
			aTag2.setAttribute('title','Elimina')
			var imgTag2 = document.createElement("img");
			imgTag2.setAttribute('src','../images/ico_Delete.gif', 'alt', 'Elimina', 'align', 'top');
			aTag2.appendChild(imgTag2);
			tr1td1Obj2.appendChild(aTag2);
			tr1Obj.appendChild(tr1td1Obj);
			tr1Obj.appendChild(tr1td1Obj2);
			tbodyObj.appendChild(tr1Obj);
		}
		else
		{
			return;
		}
	}
}

function hideTRGallery(idFotografia)
{
	var trName = 'trFileGallery' + idFotografia;
	var row = document.getElementById(trName);
	row.style.display = 'none';
}

function removePhoto(idFotografia)
{
	var postData = "idStep=7&id="+idFotografia;
	http.open("POST", "cmsGallerieFotografiche.asp", true);
	http = setXHRProperties(http,postData);
	http.onreadystatechange = function() { hideTRGallery(idFotografia); };
	http.send(postData);

}

function setXHRProperties(xhr,postData)
{
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.setRequestHeader("Content-length", postData.length);
	xhr.setRequestHeader("Connection", "close");
	return xhr;
}

function votaSondaggioAJAX(rdbRisposta)
{
	http.open('get', 'prt_sondaggi.asp?idStep=0&rdbRisposta='+rdbRisposta);
	http.send(null);
}

function CreateControl(id, fileName) //fg(10672)
{
	if (id == 1)
	{
		document.write('<object type="video/x-ms-wmv" data="upload/<%= video %>" width="320" height="240">');
		document.write('<param name="src" value="upload/'+fileName+'" />');
		document.write('<param name="autostart" value="true" />');
		document.write('<param name="controller" value="true" />');
		document.write('<param name="loop" value="true">');
		document.write('</object>');
	}
	else if (id == 2)
	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" id="filmatoFlash">')
		document.write('<param name="movie" value="upload/'+fileName+'">')
		document.write('<param name="quality" value="high">')
		document.write('<param name="allowScriptAccess" value="sameDomain">')
		document.write('<param name="menu" value="false">')
		document.write('<param name="scale" value="noscale">')
		document.write('<embed src="upload/'+fileName+'" width="320" height="240" quality="high" bgColor="#FFFFFF" scale="noscale" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" name="'+fileName+'" menu="false"></embed>')
		document.write('</object>')
	}
	else if (id == 3)
	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" id="filmatoFlash">')
		document.write('<param name="movie" value="FLVPlayer_Progressive.swf" />')
		document.write('<param name="salign" value="lt" />')
		document.write('<param name="quality" value="high" />')
		document.write('<param name="scale" value="noscale" />')
		document.write('<param name="FlashVars" value="&skinName=clearSkin_3&streamName=upload/'+fileName+'&autoPlay=false&autoRewind=false" />')
		document.write('<embed src="FLVPlayer_Progressive.swf" flashvars="&skinName=clearSkin_3&streamName=upload/'+fileName+'&autoPlay=false&autoRewind=false" quality="high" scale="noscale" width="320" height="240" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />')
		document.write('</object>')
	}
}

function CreateControlForCMS(id, fileName) //fg(10672)
{
	if (id == 1)
	{
		document.write('<object type="video/x-ms-wmv" data="../upload/<%= video %>" width="320" height="240">');
		document.write('<param name="src" value="../upload/'+fileName+'" />');
		document.write('<param name="autostart" value="true" />');
		document.write('<param name="controller" value="true" />');
		document.write('<param name="loop" value="true">');
		document.write('</object>');
	}
	else if (id == 2)
	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" id="filmatoFlash">')
		document.write('<param name="movie" value="../upload/'+fileName+'">')
		document.write('<param name="quality" value="high">')
		document.write('<param name="allowScriptAccess" value="sameDomain">')
		document.write('<param name="menu" value="false">')
		document.write('<param name="scale" value="noscale">')
		document.write('<embed src="../upload/'+fileName+'" width="320" height="240" quality="high" bgColor="#FFFFFF" scale="noscale" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowScriptAccess="sameDomain" name="'+fileName+'" menu="false"></embed>')
		document.write('</object>')
	}
	else if (id == 3)
	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" id="filmatoFlash">')
		document.write('<param name="movie" value="FLVPlayer_Progressive.swf" />')
		document.write('<param name="salign" value="lt" />')
		document.write('<param name="quality" value="high" />')
		document.write('<param name="scale" value="noscale" />')
		document.write('<param name="FlashVars" value="&skinName=clearSkin_3&streamName=../upload/'+fileName+'&autoPlay=false&autoRewind=false" />')
		document.write('<embed src="FLVPlayer_Progressive.swf" flashvars="&skinName=clearSkin_3&streamName=../upload/'+fileName+'&autoPlay=false&autoRewind=false" quality="high" scale="noscale" width="320" height="240" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />')
		document.write('</object>')
	}
}


//==========================================================================================================
//---  FUNZIONI JS PER EFFETTO ROLLOVER  ----------------------------------------------------------
//==========================================================================================================
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//--- secondExample()
function MM_reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function isnum(obj) {
    if (isNaN(obj.value) || parseInt(obj.value) < 0 || parseInt(obj.value) > 9999) {
        alert('Nel campo è possibile immettere solo numeri!');
        obj.value = "";
        obj.focus();
    }
}

function isnum1(obj) {
    if (isNaN(obj.value) || parseInt(obj.value) < 15 || parseInt(obj.value) > 65) {
        alert('Nel campo è possibile immettere solo numeri compresi tra 15 e 65!');
        obj.value = "";
        obj.focus();
    }
}
function trim(stringa) {
    while (stringa.substring(0, 1) == ' ') {
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length - 1, stringa.length) == ' ') {
        stringa = stringa.substring(0, stringa.length - 1);
    }
    return stringa;
}

function ReplaceEcomm(stringa) {
    return stringa.replace(/&/g, "%26");
}