<!--

/** FUNZIONI */

	// 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");
					//alert('IE vecchio');
				}
				else
				{
					XHR = new ActiveXObject("Microsoft.XMLHTTP");
					//alert('IE nuovo');
				}
			}
			return XHR;
		};

/** 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";
		
function getFormValue()
{
    car = document.carrello.carrello.value;
    cod_art = document.carrello.cod_art.value; 
    qta = document.carrello.qta.value; 
    id = document.carrello.id.value; 
    id_cat = document.carrello.id_cat.value; 
    prez = document.carrello.prezzo.value;
    
    postVars = "carrello="+car+"&cod_art="+cod_art+"&qta="+qta+"&id="+id+"&id_cat="+id_cat+"&prezzo="+prez;
    
    if(document.carrello.taglia)
    {
        taglia = document.carrello.taglia.value;
        postVars += "&taglia="+taglia;
    } 
    if(document.carrello.id_colore)
    {
        id_colore = document.carrello.id_colore.value;
        postVars += "&id_colore="+id_colore;
    }
    
    return postVars; 
}


function loadComuni() 
{
  // variabili di funzione
  var
    // assegnazione oggetto XMLHttpRequest
    ajax = assegnaXMLHttpRequest(),
    // assegnazione elementi del documento
    //comuni = document.nsl_form.comune;
    comuni = prendiElementoDaId('mario'); 
    prov = document.nsl_form.provincia.value;
    
   
  
  // se l'oggetto XMLHttpRequest non è nullo
  if(ajax) 
  {
      postVars = "prov="+prov;
      //alert(postVars);
      // inizializzo la richiesta in post
      ajax.open("post", "loadComuni.php", true);

      // imposto il giusto header
      ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");

      // rimozione dell'header "connection" come "keep alive"
      ajax.setRequestHeader("connection", "close");

      // impostazione controllo e stato della richiesta
      ajax.onreadystatechange = function() 
      {
          // verifica dello stato
          if(ajax.readyState === readyState.COMPLETATO) 
          {
              // verifica della risposta da parte del server
              if(statusText[ajax.status] === "OK")
              {
                  //alert(ajax.responseText); 
                  comuni.innerHTML = "<select name=\"comune\">"+ajax.responseText+"</select>";                           
                  //document.write(ajax.responseText);*/
                  //comuni.outerHTML = comuni.outerHTML;
              }
              else if(ajax.status == "12030")
              {
                  //alert("ERROR_INTERNET_CONNECTION_ABORTED");
                  loadComuni();
              }
              else  
              {
                  // errore di caricamento
                  /*elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
                  elemento.innerHTML += "Errore riscontrato: " + ajax.status;
                  elemento.style.visibility='visible';*/
                  alert("Errore connessione asincrona");
              }
          } 
      }
      // effettuo la richiesta inviando le variabili 
      ajax.send(postVars); 
  }
}

function decrypt(foo)
{
  var len = foo.length;
  var mufli ="";
  for(var i=0;i<len;i++)
  {
     var n = foo.charCodeAt(i);
     if(n<=97 && n>=72)
       mufli+=String.fromCharCode(n-7);
      else if(n<=100 && n>=95) 
       mufli+=String.fromCharCode(n-4);
      else if(n<=128 && n>=103) 
       mufli+=String.fromCharCode(n-6);
      else mufli+=String.fromCharCode(n-5);   
  }  
  foo="";
  for(i=0;i<=len;i++)
  {
    foo+=mufli.charAt(len-i);
  }
  document.location.href="mailto:"+foo;
}

<!--
function ControllaMail(mail)
{
   EmailAddr = mail;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
   {
      alert("Formato Indirizzo Mail Errato");
      document.nsl_form.mail.focus();
      return false;
   }
}
//-->

function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return false;
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return false;
	for(var i = 0; i < radioLength; i++) 
  {
	   if(radioObj[i].checked) 
     {
		    return radioObj[i].value;
		 }
	}
	return false;
}

function filtraComune() 
{
    comune = document.comuni.comune.value;
    document.location.href="da_vedere.php?filtra=1&comune="+comune;
}

function mailControl()
{
    send = 0;
    cons = document.nsl_form.consenso;   
    EmailAddr = document.nsl_form.mail.value;
    EmailAddrConf = document.nsl_form.mail_conf.value;
    if(ControllaMail(EmailAddr))
        send ++;
    if(getCheckedValue(cons) == 'T')
        send ++;
    else
        alert("Accettare il consenso alla privacy");
    if(EmailAddr == EmailAddrConf)
        send ++;
    else
        alert("Gli indirizzai mail inseriti non corrispondono");
    if(send == 3)
        document.nsl_form.submit();  
}

function mailGuestControl()
{
    send = 0;
    EmailAddr = document.guestForm.mail.value;   
    if(ControllaMail(EmailAddr))
        send ++;
    if(send == 1)
        document.guestForm.submit();  
}

function mailAdvControl()
{
    send = 0; 
    EmailAddr = document.pubblicita.mail.value;
    tel = document.pubblicita.tel.value;
    cell = document.pubblicita.cell.value;
    
    if(EmailAddr.length > 5)
    {
        if(ControllaMail(EmailAddr))
          send ++;
    }
    if(tel.length > 5)
          send ++;
    if(cell.length > 5)
          send ++;

    if(send > 0)
        document.pubblicita.submit(); 
    else
        alert("Compilare almeno un campo dei seguenti: Mail - Telefono - Cellulare");
}


function setIframeNL(target)
{
    iframe = prendiElementoDaId('iframe_nl');
    iframe.src = target;
}

function get_NL_H()
{
    //setTimeout("",2000);
    iframe = prendiElementoDaId('iframe_nl');
    //alert(iframe.contentDocument.getElementsByTagName('table'));
    tabelle = iframe.contentDocument.getElementsByTagName('table');
    tab_h = tabelle[0].offsetHeight;
    //alert("Altezza Tabella: " + tab_h);
    iframe.height = tab_h + 260;
}
function nascondiDiv(id_elemento)
{
    div = prendiElementoDaId(id_elemento);
    /*alert("DIV:"+div.id);*/
    div.style.display = "none";/*
    if(div.style.display == "none")
        alert("NASCOSTO");
    else
        alert("VISIBILE");*/
} 


//-->
