function ActivateTransMenuItem(itemid)
	{
	//document.getElementById(itemid).className = "CE-VoceMenu3Livello2-hover";
	}

function DeActivateTransMenuItem(itemid)
	{
	//document.getElementById(itemid).className = "CE-VoceMenu3Livello2";
	}

function mostraProvincia(prov)
	{
		if(!document.getElementById) return;

		immagine = document.getElementById("sardegnaProvince");
		//alert(prov);
		switch(prov) 
			{ 
			case "SS":
				immagine.style.marginLeft = '-230px';
				immagine.style.marginTop = '0px';
				break;
			case "OT":
				immagine.style.marginLeft = '-460px';
				immagine.style.marginTop = '0px';
				break;
			case "OR":
				immagine.style.marginLeft = '0px';
				immagine.style.marginTop = '-440px';
				break;
			case "NU":
				immagine.style.marginLeft = '-230px';
				immagine.style.marginTop = '-440px';
				break;
			case "OG":
				immagine.style.marginLeft = '-460px';
				immagine.style.marginTop = '-440px';
				break;
			case "MD":
				immagine.style.marginLeft = '0px';
				immagine.style.marginTop = '-880px';
				break;
			case "CI":
				immagine.style.marginLeft = '-230px';
				immagine.style.marginTop = '-880px';
				break;
			case "CA":
				immagine.style.marginLeft = '-460px';
				immagine.style.marginTop = '-880px';
				break;
			default: 
				immagine.style.marginLeft = '0px';
				immagine.style.marginTop = '0px';
			}
	}

function ValidateContatti(theForm)
{
// Controlla che il messaggio non sia vuoto
/*
if (theForm.Messaggio.value == "") 
	{
	alert("Scrivi il messaggio.");
	theForm.Messaggio.focus();
	return(false)
	}
*/
// Controlla che il nome non sia vuoto
/*
if (theForm.Nome.value == "") 
	{
	alert("Inserisci il Nome.");
	theForm.Nome.focus();
	return(false)
	}
*/
// Controlla che il cognome non sia vuoto
/*
if (theForm.Cognome.value == "") 
	{
	alert("Inserisci il Cognome.");
	theForm.Cognome.focus();
	return(false)
	}
*/
// Controlla se email non sia vuota
if (theForm.EMail.value == "") 
	{
	alert("Inserisci il tuo indirizzo Email.");
	theForm.EMail.focus();
	return(false)
	}

// Controlla che email sia valida: caratteri consentiti
var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
var checkStr = theForm.EMail.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}

	}

// Controlla che email sia valida: presenza della @
if (checkStr.indexOf('@') == -1)
	allValid = false;

// Controlla che email sia valida: presenza di 1 punto
if (checkStr.indexOf('.') == -1)
	allValid = false;

if (!allValid)
	{
	alert("Inserisci un indirizzo email valido");
	theForm.EMail.focus();
	return (false);
	}

// Controlla che il telefono sia in cifre
var checkOK = "0123456789/-\+ ";
var checkStr = theForm.Cellulare.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}
	}
	
if (!allValid)
	{
	alert("Inserisci un numero di Cellulare valido, solo cifre.");
	theForm.Cellulare.focus();
	return (false);
	}

if (theForm.Privacy.checked == false )
	{
	alert('Per inviare un messaggio devi autorizzarci al trattamento dei tuoi dati personali.');
	theForm.Privacy.focus();
	return (false);
	}

return (true)
}

function ValidateRichiedi(theForm)
{
// Controlla che il codice di sicurezza sia presente
  if (theForm.CMImgCheckerText.value == "") {
	alert("Inserisci le lettere che vedi qui sotto.");
	theForm.CMImgCheckerText.focus();
	return(false)
  }
// Controlla che il comune non sia vuoto
if (theForm.Rag_Soc.value == "") 
	{
	alert("Inserisci il tuo Comune.");
	theForm.Rag_Soc.focus();
	return(false)
	}
// Controlla che il nome non sia vuoto
if (theForm.Nome.value == "") 
	{
	alert("Inserisci il Nome.");
	theForm.Nome.focus();
	return(false)
	}
// Controlla che il cognome non sia vuoto
if (theForm.Cognome.value == "") 
	{
	alert("Inserisci il Cognome.");
	theForm.Cognome.focus();
	return(false)
	}
// Controlla se email non sia vuota
if (theForm.EMail.value == "") 
	{
	alert("Inserisci il tuo indirizzo Email.");
	theForm.EMail.focus();
	return(false)
	}

// Controlla che email sia valida: caratteri consentiti
var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
var checkStr = theForm.EMail.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}

	}

// Controlla che email sia valida: presenza della @
if (checkStr.indexOf('@') == -1)
	allValid = false;

// Controlla che email sia valida: presenza di 1 punto
if (checkStr.indexOf('.') == -1)
	allValid = false;

if (!allValid)
	{
	alert("Inserisci un indirizzo email valido");
	theForm.EMail.focus();
	return (false);
	}

// Controlla che il telefono sia in cifre
var checkOK = "0123456789/-\+ ";
var checkStr = theForm.Cellulare.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}
	}
	
if (!allValid)
	{
	alert("Inserisci un numero di Cellulare valido, solo cifre.");
	theForm.Cellulare.focus();
	return (false);
	}

if (theForm.Privacy.checked == false )
	{
	alert('Per inviare un messaggio devi autorizzarci al trattamento dei tuoi dati personali.');
	theForm.Privacy.focus();
	return (false);
	}

return (true)
}

function ValidateQuesito(theForm)
{
// Controlla che il messaggio non sia vuoto

if (theForm.Messaggio.value == "") 
	{
	alert("Scrivi il messaggio.");
	theForm.Messaggio.focus();
	return(false)
	}

// Controlla che il comune non sia vuoto

if (theForm.Rag_Soc.value == "") 
	{
	alert("Inserisci il tuo Comune.");
	theForm.Rag_Soc.focus();
	return(false)
	}

// Controlla che il nome non sia vuoto

if (theForm.Nome.value == "") 
	{
	alert("Inserisci il Nome.");
	theForm.Nome.focus();
	return(false)
	}

// Controlla che il cognome non sia vuoto

if (theForm.Cognome.value == "") 
	{
	alert("Inserisci il Cognome.");
	theForm.Cognome.focus();
	return(false)
	}

// Controlla se email non sia vuota
if (theForm.EMail.value == "") 
	{
	alert("Inserisci il tuo indirizzo Email.");
	theForm.EMail.focus();
	return(false)
	}

// Controlla che email sia valida: caratteri consentiti
var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
var checkStr = theForm.EMail.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}

	}

// Controlla che email sia valida: presenza della @
if (checkStr.indexOf('@') == -1)
	allValid = false;

// Controlla che email sia valida: presenza di 1 punto
if (checkStr.indexOf('.') == -1)
	allValid = false;

if (!allValid)
	{
	alert("Inserisci un indirizzo email valido");
	theForm.EMail.focus();
	return (false);
	}

if (theForm.Privacy.checked == false )
	{
	alert('Per inviare un messaggio devi autorizzarci al trattamento dei tuoi dati personali.');
	theForm.Privacy.focus();
	return (false);
	}

return (true)
}

function ValidateNewsletter(theForm)
{
// Controlla che email non sia vuoto
if (theForm.EMail.value == "") 
	{
	alert("Inserire l\'indirizzo Email.");
	theForm.EMail.focus();
	return(false)
	}

// Controlla che email sia valida: caratteri consentiti
var checkOK = "1234567890qwertyuiopsdfghjklafghjklzxcvbnm@_-.QERTYUIOPASDFGHJLZXCVBNM";
var checkStr = theForm.EMail.value;
var allValid = true;
for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		  allValid = false;
		  break;
		}
	}

// Controlla che email sia valida: presenza della @
if (checkStr.indexOf('@') == -1)
	allValid = false;

// Controlla che email sia valida: presenza di 1 punto
if (checkStr.indexOf('.') == -1)
	allValid = false;

if (!allValid)
	{
	alert("Inserire un indirizzo email valido");
	theForm.EMail.focus();
	return (false);
	}

// Controlla che nomeCognome non sia vuoto
/*
if (theForm.NomeCognome.value == "") {
		alert("Inserire il Nome e Cognome.");
		theForm.NomeCognome.focus();
		return(false)
}

*/

if (theForm.Privacy.checked == false )
	{
	alert('Per iscriverti alla newsletter devi autorizzare il trattamento dei dati personali.');
	theForm.Privacy.focus();
	return (false);
	}

return (true)
}

function mostraDivNewsletter()
{
	if(document.getElementById("boxNewsletter"))
		{
		document.getElementById("boxNewsletter").style.display = 'block';
		}
}

function nascondiDivNewsletter()
{
	if(document.getElementById("boxNewsletter"))
		{
		document.getElementById("boxNewsletter").style.display = 'none';
		}
}

function mostraDivSms()
{
	if(document.getElementById("boxSms"))
		{
		document.getElementById("boxSms").style.display = 'block';
		}
}

function nascondiDivSms()
{
	if(document.getElementById("boxSms"))
		{
		document.getElementById("boxSms").style.display = 'none';
		}
}


function CompilaTextAreaDescrizione()
{
	if(!document.getElementById || !document.getElementsByTagName) return;
	if(!document.getElementById("datiUtenteCellaTextArea")) return;
	if(!document.getElementById("GestUtenti-InputDESCRIZIONE")) return;
	
	tempDescrizione = document.getElementById("GestUtenti-InputDESCRIZIONE").value;
	document.getElementById("datiUtenteTextAreaDescrizione").innerHTML = tempDescrizione.replace(/"<BR>"/g,"\n");
	return(true);
}

function SalvaTextAreaDescrizione(elem)
{
	tempSalva = elem.value;
	//alert(tempSalva);
	document.getElementById("GestUtenti-InputDESCRIZIONE").value = tempSalva.replace(/"\n"/g,"<BR>");
	//	alert(document.getElementById("GestUtenti-InputDESCRIZIONE").value);
	return(true);
}



/** (C) HTML.IT - insieme di funzioni ed oggetti utili per interagire con ajax */
/** FUNZIONI */
/** OGGETTI / ARRAY */

	// oggetto di verifica stato
		var readyState = {
			INATTIVO:	0,
			INIZIALIZZATO:	1,
			RICHIESTA:	2,
			RISPOSTA:	3,
			COMPLETATO:	4
		};

	// array descrittivo dei codici restituiti dal server
	// [la scelta dell' array è per evitare problemi con vecchi browsers]
		var statusText = new Array();
		statusText[100] = "Continue";
		statusText[101] = "Switching Protocols";
		statusText[200] = "OK";
		statusText[201] = "Created";
		statusText[202] = "Accepted";
		statusText[203] = "Non-Authoritative Information";
		statusText[204] = "No Content";
		statusText[205] = "Reset Content";
		statusText[206] = "Partial Content";
		statusText[300] = "Multiple Choices";
		statusText[301] = "Moved Permanently";
		statusText[302] = "Found";
		statusText[303] = "See Other";
		statusText[304] = "Not Modified";
		statusText[305] = "Use Proxy";
		statusText[306] = "(unused, but reserved)";
		statusText[307] = "Temporary Redirect";
		statusText[400] = "Bad Request";
		statusText[401] = "Unauthorized";
		statusText[402] = "Payment Required";
		statusText[403] = "Forbidden";
		statusText[404] = "Not Found";
		statusText[405] = "Method Not Allowed";
		statusText[406] = "Not Acceptable";
		statusText[407] = "Proxy Authentication Required";
		statusText[408] = "Request Timeout";
		statusText[409] = "Conflict";
		statusText[410] = "Gone";
		statusText[411] = "Length Required";
		statusText[412] = "Precondition Failed";
		statusText[413] = "Request Entity Too Large";
		statusText[414] = "Request-URI Too Long";
		statusText[415] = "Unsupported Media Type";
		statusText[416] = "Requested Range Not Satisfiable";
		statusText[417] = "Expectation Failed";
		statusText[500] = "Internal Server Error";
		statusText[501] = "Not Implemented";
		statusText[502] = "Bad Gateway";
		statusText[503] = "Service Unavailable";
		statusText[504] = "Gateway Timeout";
		statusText[505] = "HTTP Version Not Supported";
		statusText[509] = "Bandwidth Limit Exceeded";
		
// funzione per prendere un elemento con id univoco
function prendiElementoDaId(id_elemento) {
		var elemento;
		if(document.getElementById)
			elemento = document.getElementById(id_elemento);
		else
			elemento = document.all[id_elemento];
		return elemento;
	};

// funzione per assegnare un oggetto XMLHttpRequest
function assegnaXMLHttpRequest() {
		var
			XHR = null,
			browserUtente = navigator.userAgent.toUpperCase();
		if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
			XHR = new XMLHttpRequest();
		else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
			if(browserUtente.indexOf("MSIE 5") < 0)
				XHR = new ActiveXObject("Msxml2.XMLHTTP");
			else
				XHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
		return XHR;
	};

function JJ_openURL(elementID, nomeFile) {
	//alert(elementID);
	//alert(nomeFile);
	var 
	ajax = assegnaXMLHttpRequest(),
    elemento = prendiElementoDaId(elementID),
    usaLink = true;
	elemento.innerHTML = "<br><br><br><br><br>";
	elemento.style.background = "url(/Temi/Default/immagini/preload-flash.gif) no-repeat center center";
  
  if(ajax) {
    usaLink = false;
    ajax.open("get", nomeFile, true);
    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
      if(ajax.readyState === readyState.COMPLETATO) {
        if(statusText[ajax.status] === "OK"){
		  elemento.style.background = "";
          elemento.innerHTML = ajax.responseText.substring(ajax.responseText.indexOf("<DIV id="+elementID+">")+26,ajax.responseText.indexOf("</DIV id="+elementID+"Fine>"));
		  }
        else {
          elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
          elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
        }
      } 
    }
    ajax.send(null);
  }
}  
