function validateQuesitoConcorso(theForm)
{
// 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.Messaggio.value == "") 
	{
	alert("Scrivi il tuo quesito.");
	theForm.Messaggio.focus();
	return(false)
	}

if (theForm.Privacy.checked == false )
	{
	alert('Per inviare un quesito devi autorizzarci al trattamento dei tuoi dati personali.');
	theForm.Privacy.focus();
	return (false);
	}

return (true)
}

function ValidateContatti(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 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 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)
}

// Controlla che  anno di nascita sia presente
if (theForm.Data_nascita.value == "-") 
	{
	alert("Inserire l\'anno di nascita.");
	theForm.Data_nascita.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 ValidateSms(theForm)
{
  // Controlla che email non sia vuoto
  if (theForm.Cellulare.value == "") {
    alert("Inserisci un numero di Cellulare valido, solo cifre.");
    theForm.Cellulare.focus();
    return (false);
  }

  // Controlla che il cellulare sia solo 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.PrivacySms.checked == false )
  {
	alert('Per iscriverti al servizio SMS devi autorizzare il trattamento dei dati personali.');
	theForm.PrivacySms.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 galleryClearOnload()
	{
		if(!document.getElementById || !document.getElementsByTagName) return;
		links=document.getElementById("miniatureFoto").getElementsByTagName("A");
		for(i=0;i<links.length;i++){
		
		  if(navigator.userAgent.indexOf("Firefox",0) > 0 ){
				links[i].rel = "clearbox[gal1]";	
				fotoPiccola=links[i].getElementsByTagName("img")[0];
				fotoPiccolaSrc=fotoPiccola.getAttribute("src");
				links[i].href = fotoPiccolaSrc.substr(0,fotoPiccolaSrc.length-12) + "_600_400.jpg";
				
		  }
		  else if(navigator.userAgent.indexOf("Opera",0) > 0 ){
				links[i].rel = "clearbox[gal1]";	
				fotoPiccola=links[i].getElementsByTagName("img")[0];
				fotoPiccolaSrc=fotoPiccola.getAttribute("src");
				links[i].href = fotoPiccolaSrc.substr(0,fotoPiccolaSrc.length-12) + "_600_400.jpg";
	
			}
		  else if(navigator.userAgent.indexOf("MSIE 6",0) > 0 ){
				links[i].rel = "clearbox[gal1]";	
				fotoPiccola=links[i].getElementsByTagName("img")[0];
				fotoPiccolaSrc=fotoPiccola.getAttribute("src");
				links[i].href = fotoPiccolaSrc.substr(0,fotoPiccolaSrc.length-12) + "_600_400.jpg";
	
			}			
		  else if(navigator.userAgent.indexOf("Safari",0) > 0 ){
				links[i].rel = "clearbox[gal1]";	
				fotoPiccola=links[i].getElementsByTagName("img")[0];
				fotoPiccolaSrc=fotoPiccola.getAttribute("src");
				links[i].href = fotoPiccolaSrc.substr(0,fotoPiccolaSrc.length-12) + "_600_400.jpg";
		  }			
		  else {
				links[i].rel = "clearbox[gal1]";	
				fotoPiccola=links[i].getElementsByTagName("img")[0];
				fotoPiccolaSrc=fotoPiccola.getAttribute("src");
				links[i].href = fotoPiccolaSrc.substr(0,fotoPiccolaSrc.length-12) + "_600_400.jpg";
		  }
		}
		return(true);
	}


function galleryOnload()
	{
		if(!document.getElementById || !document.getElementsByTagName) return;
		
		if (document.getElementById("miniatureFoto")) {
			links=document.getElementById("miniatureFoto").getElementsByTagName("A");
			if (links[0]) {
				for(i=0;i<links.length;i++){
					links[i].target='galleryDettaglio';
					}
				
				testoFoto=document.getElementById("miniatureFoto").getElementsByTagName("P");
				nomeFoto=document.getElementById("miniatureFoto").getElementsByTagName("P");
				//descrFoto=document.getElementById("miniatureFoto").getElementsByTagName("SPAN");

				var temp;
				for(i=0;i<testoFoto.length;i++){
					//temp = testoFoto[i].innerHTML.split("- ");
					//alert("temp");
					//nomeFoto[i].innerHTML = temp[0];
					//descrFoto[i].innerHTML = temp[1];
					}
				document.getElementById("galleryDettaglio").src = links[0].getAttribute("HREF");
			}
		}
		if (document.getElementById("miniatureSottoAlbum")) {
			//links2=document.getElementById("miniatureSottoAlbum").getElementsByTagName("A");
			//document.getElementById("galleryDettaglio").src = links2[0].getAttribute("HREF");
		}
	}
function CheckEditor()
	{
    	if(document.getElementById("CElyScript")) {
        	document.getElementById("Riga4Cella3").style.display = "none";
        	document.getElementById("Riga4Cella2").style.width = "700px";
        	document.getElementById("BoxContenuto").style.width = "690px";
        	document.getElementById("Contenuto").style.width = "690px";
        	document.getElementById("ImmagineSezione").style.display = "none";
		}
	}


/** (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/2009-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=contenutoProdotto>")+26,ajax.responseText.indexOf("</DIV id=contenutoProdottoFine>"));
		  }
        else {
          elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
          elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
        }
      } 
    }
    ajax.send(null);
  }
}  

function JJ_alert() {
	alert('Prodotto');
}  

function showFotoRandom()
{
   if(document.getElementById("yogurtFotoPersonaggi")){
	var d, n, numero_foto, url_foto;
    url_foto = "/Temi/2009-Default/immagini/prodotti-yogurt/yogurt_personaggio_";
	d = new Date();
	n = d.getSeconds() % 11 + 1;
	document.getElementById("yogurtFotoPersonaggi").src = url_foto + n + ".jpg";
	}
   return(true);
}
function yogurtIndietro()
{
	var i,fotoPersonaggioSrc,fotoPersonaggioId;
	fotoPersonaggioSrc = document.getElementById("yogurtFotoPersonaggi").src;
	fotoPersonaggioId = fotoPersonaggioSrc.substr(90,fotoPersonaggioSrc.length-4);
  	i = parseInt(fotoPersonaggioId);
	if (i>1){
		k = Math.abs(i-1) % 11;
		document.getElementById("yogurtFotoPersonaggi").src = "http://www.lattearborea.com/Temi/2009-Default/immagini/prodotti-yogurt/yogurt_personaggio_" + Math.abs(k) + ".jpg";
		}
	return(true);
}

function yogurtAvanti()
{
	var fotoPersonaggioSrc,fotoPersonaggioId,url_foto;
	fotoPersonaggioSrc = document.getElementById("yogurtFotoPersonaggi").src;
	fotoPersonaggioId = fotoPersonaggioSrc.substr(90,fotoPersonaggioSrc.length-4);
  	k = Math.abs(parseInt(fotoPersonaggioId)) % 11 + 1;
   	document.getElementById("yogurtFotoPersonaggi").src = "http://www.lattearborea.com/Temi/2009-Default/immagini/prodotti-yogurt/yogurt_personaggio_" + Math.abs(k) + ".jpg";
	return(true);
}

