function showDivV2(divName) 
{
 	obj = document.all(divName)
  var lefter = 600; 
  var topper = 200;
	obj.style.left = lefter + "px"
	obj.style.top = topper + "px"
 	obj.style.display = 'block';
}
function showDiv(divName) 
{
 	obj = document.all(divName)
  var lefter = 630; 
  var topper = 400;
	obj.style.left = lefter + "px"
	obj.style.top = topper + "px"
 	obj.style.display = 'block';
}
function closeDiv(objChiudi,objTxt) 
{  
   objTxt.value="";
   objChiudi.style.display = "none";
}

function inserisciComune(objChiudi,objTxt,objSel) 
{  
   if (objTxt.value != "")
   {
      var oOption = document.createElement("OPTION");
      objSel.options.add(oOption);
      oOption.innerText = objTxt.value;
      oOption.value = objTxt.value;
      objSel.options.value = objTxt.value;
      objTxt.value = "";
   }
   
   objChiudi.style.display = "none";
}


function menu89Homepage(){
	document.location.href='../892424/home_postlogin.jsp';
}
function menu89Tariffe(){
	document.location.href='../892424/tariffe.jsp';
}
function menu89Cosa(){
	document.location.href='../892424/chisiamo.jsp';
}
function menu89Cosafa(){
	document.location.href='../892424/info.jsp';
}
function menu89HomepageV2(){
	document.location.href='../../892424/home_postlogin.jsp';
}
function menu89TariffeV2(){
	document.location.href='../../892424/tariffe.jsp';
}
function menu89CosaV2(){
	document.location.href='../../892424/chisiamo.jsp';
}
function menu89CosafaV2(){
	document.location.href='../../892424/info.jsp';
}


/* aggiungo le funzioni js nei link di faq e privilegi (il mostra/nascondi risposte) */
function addLinkToFaq(){
	var faqs=document.getElementById("containerDomande").getElementsByTagName("a");
	var totFaqs=faqs.length;
	for (i=0; i<totFaqs; i++){
		if (navigator.appName.indexOf("Explorer")!=-1){
			faqs[i].onclick=function(){return showHideFaq(this)};
		} else{
			faqs[i].onclick=function(){return showHideFaq(this)};
		}	
		faqs[i].id="faq"+i;
		  if(faqs[i].href=="#"){
          	faqs[i].href="#faq"+i;
      	  }
	}
} 

function showHideFaq(q){
	var eventType;
	var faq;
	faq=q;
	var PToShowHide=faq.nextSibling;
	while((PToShowHide != null) && (PToShowHide.className!="risposta")){
		PToShowHide=PToShowHide.nextSibling;
	}
   
	   newAnchor=PToShowHide.appendChild(document.createElement('a'));
	   newAnchor.name=faq.id;
	   if(faq.className=="domandaV1" || faq.className=="domandafaqV1"){
          	PToShowHide.style.display="block";
		  	faq.href="#"+faq.id;
	      	
			if(faq.className=="domandaV1"){
				faq.className="domandaV2";
			}else{
				faq.className="domandafaqV2";
			}
	   
	   } else {
	       	if(faq.className=="domandaV2"){
				faq.className="domandaV1";
			}else{
				faq.className="domandafaqV1";
			}
			faq.href="#"+faq.id;
	        PToShowHide.style.display="none";
	   }
	
}







//Funzione che esegue il refresh della lista dei giorni in funzione del mese e dell'anno selezionati.
//I parametri indicano il nome del form che contiene le selezioni, quello dei tre oggetti select 
//(giorno, mese, anno) e una stringa che indica se lo script  stato lanciato dopo una selezione dalla
//lista dei mesi o degli anni.
//
function refreshGiorni(nomeForm, nomeSelectGiorno, nomeSelectMese, nomeSelectAnno, oggettoModificato)
{
  listaGiorni = document.forms[nomeForm][nomeSelectGiorno];
  listaMesi = document.forms[nomeForm][nomeSelectMese];
  listaAnni = document.forms[nomeForm][nomeSelectAnno];

  indiceGiornoSelezionato = listaGiorni.selectedIndex;
  
  if (listaMesi.selectedIndex == 0)
     meseSelezionato = 0; // Si setta un valore nullo, se non   stato ancora selezionato il mese.
  else
     meseSelezionato = document.forms[nomeForm][nomeSelectMese].options[listaMesi.selectedIndex].value;
  
  if (listaAnni.selectedIndex == 0)
     annoSelezionato = 0; // Si setta un valore nullo, se non  stato ancora selezionato l'anno.
  else
     annoSelezionato = document.forms[nomeForm][nomeSelectAnno].options[listaAnni.selectedIndex].value;
  
  // Se   stato selezionato un nuovo valore per il mese, si aggiorna la lista dei giorni in funzione
  // del mese appena selezionato.
  if (oggettoModificato == "mese")
  { 
    if ((meseSelezionato == 04) || (meseSelezionato == 06) || (meseSelezionato == 09) || (meseSelezionato == 11))
      {
        listaGiorni.options[29] = new Option(29,29);
        listaGiorni.options[30] = new Option(30,30);
        listaGiorni.options[31] = null;
      }
    else
      {
        if (meseSelezionato == 02)
          {
            listaGiorni.options[31] = null;
            listaGiorni.options[30] = null;
            listaGiorni.options[29] = null;
           
            if ((annoSelezionato != 0) && (bisestile(annoSelezionato)))
              listaGiorni.options[29] = new Option(29,29);
          }
        else
          {
            listaGiorni.options[29] = new Option(29,29);
            listaGiorni.options[30] = new Option(30,30);
            listaGiorni.options[31] = new Option(31,31);
          }
      }
  }
  else
  // Se  stato selezionato un nuovo valore per l'anno, si aggiorna la lista dei giorni solo se il
  // mese   febbraio e l'anno selezionato  bisestile.
  { 
    if ((meseSelezionato == 02))
       if ((annoSelezionato != 0) && (bisestile(annoSelezionato)))
          listaGiorni.options[29] = new Option(29,29);
       else
          listaGiorni.options[29] = null;
  }
  
  // Se il giorno selezionato   stato cancellato dalla lista, viene selezionato il valore di dafault
  // della lista (in caso contrario, si mantiene la selezione).
  if (listaGiorni.options[indiceGiornoSelezionato] == null)
     listaGiorni.selectedIndex = 0;
  else
     listaGiorni.selectedIndex = indiceGiornoSelezionato;
}


//
//Funzione che, noti form, oggetti select e relativi valori in essi, seleziona gli elementi.
//
function caricamentoData(nomeForm, nomeSelectGiorno, nomeSelectMese, nomeSelectAnno, giorno, mese, anno){
  // Se non  stata settata una data (valori nulli), si selezionano i campi nulli.
  if (((giorno == 0) && (mese == 0) && (anno == 0)) || 
      ((giorno == null) && (mese == null) && (anno == null)) || 
      ((giorno == "") && (mese == "") && (anno == "")))
  {
     document.forms[nomeForm][nomeSelectAnno].selectedIndex = 0;
     document.forms[nomeForm][nomeSelectMese].selectedIndex = 0;
     document.forms[nomeForm][nomeSelectGiorno].selectedIndex = 0;
  }
  else
  {
     // L'indice dell'anno sar  pari all'anno passato come parametro a cui sia sottratto il valore 
     // del primo anno contenuto nella select (indice 1 perch il primo elemento della select   "") + 1.
     document.forms[nomeForm][nomeSelectAnno].selectedIndex = anno - document.forms[nomeForm][nomeSelectAnno].options[1].value + 1;
     document.forms[nomeForm][nomeSelectMese].selectedIndex = mese;
     document.forms[nomeForm][nomeSelectGiorno].selectedIndex = giorno;
     refreshGiorni(nomeForm, nomeSelectGiorno, nomeSelectMese, nomeSelectAnno, 'mese');
     refreshGiorni(nomeForm, nomeSelectGiorno, nomeSelectMese, nomeSelectAnno, 'anno');
  }
}


//
//Funzione che calcola se l'anno passato come parametro  bisestile.
//
function bisestile(anno)
{
  if ((anno % 4 == 0) && ((anno % 100 != 0) || (anno % 400 == 0)))
     return true;
  else
     return false;
}


// usata per gestire i valori delle option ricopiati in una valore di appoggio
// che sar  quella effettivamente passata nella request
function setSelectHidden(thisForm,campoSel,campoHidd){
	thisForm.elements[campoHidd].value=campoSel.value;
}


//
//Funzione che setta il valore del campo flagName in funzione della checkbox di nome checkName,
//nella form formName. 
//
function caricamentoFlagDaCheckBox(formName,checkName,flagName){
    if (document.forms[formName][checkName].checked == true)
       document.forms[formName][flagName].value = "1";
    else
       document.forms[formName][flagName].value = "0";
}


//
//Funzione che setta il valore flag alla checkbox di nome checkName, nella form formName.
//
function caricamentoCheckboxDaFlag(formName,checkName,flag){
    if (flag == "1")
        document.forms[formName][checkName].checked = true;
    else
        document.forms[formName][checkName].checked = false;
}


//
//Funzione che esegue la submit sul form di nome dato in corrispondenza alla richiesta di 
//esecuzione di una certa azione usando per target il frame dei messaggi.
//
function submitDettaglioClientiMsgForm(formName,azione,path){
    settaAzione(formName,azione);
    thisForm = document.forms[formName];
    thisForm.action = path + "SalvataggioClientiServlet";
    isAjax=null;
    if (thisForm['isAjax'] && thisForm['isAjax'].value !=""){
      isAjax=thisForm['isAjax'].value;
    }
    if (azione == "Salva")
    {
      if (controlliPreSalvataggio()){
         if(isAjax != null){
          submitAjaxForm(formName); 
         }else{
          thisForm.submit();
         } 
      }
    } else {  
       if (azione == "Aggiungi") 
       {
          if (isNaN(Number(thisForm['numTel'].value))){
             alert('Errore: Immettere un valore numerico per il campo Nuovo Telefono');
             thisForm['numTel'].value = "";
             return false;
          }
          else if (thisForm['numTel'].value.length < 7){
               alert('Errore: Il numero di telefono deve essere composto da almeno sette caratteri');
               return false;
          }
          else
          {
            if (thisForm['numeri_telefonici'].length>2){
              alert('Errore: Sono presenti 3 numeri di telefono per il cliente, eliminarne prima di inserirne di nuovi');  
              thisForm['numTel'].value = "";
              return false;
            }else 
              if(isAjax != null){
              submitAjaxForm(formName); 
             }else{
              thisForm.submit();
             } 
          }
       } else if (azione=="Registra"){
          if ((thisForm['email'].value == "") || (!impostaDataNascita()) || (thisForm['flag_DP_email'].value != "1") || (thisForm['flag_DP_posta'].value != "1"))
          {
             alert("Per procedere alla registrazione e' necessario compilare i campi obbligatori contrassegnati da asterisco * e fornire i consensi per comunicazione commerciali su Prontissimo tramite Email e Posta");
             thisForm['dove'].value= 'ics';
             document.getElementById('botRegistra').style.display = 'inline';
             document.getElementById('botAnnulla').style.display = 'inline';
             return false;
          }

          if (controlliPreSalvataggio())
             if(isAjax != null){
              submitAjaxForm(formName); 
             }else{
              thisForm.submit();
             } 
          else {
             thisForm['dove'].value= 'ics';
             document.getElementById('botRegistra').style.display = 'inline';
             document.getElementById('botAnnulla').style.display = 'inline';
             return false;
          }
       } else {
        if (thisForm['numeri_telefonici'].length==1)
              alert('Errore: Impossibile eliminare tutti i numeri di telefono');  
            else
            {
               messaggio = "Eiminare il numero " + thisForm['numeri_telefonici'].value + "?";
               if (confirm(messaggio) == true)
                  if(isAjax != null){
                    submitAjaxForm(formName); 
                   }else{
                    thisForm.submit();
                   } 
            }
       }
    }
    return false;
}

//
//Funzione che esegue la submit sul form di nome dato in corrispondenza alla richiesta di 
//esecuzione di una certa azione usando per target il frame dei messaggi.
//
function submitDettaglioClienti800MsgForm(formName,azione,path){
    settaAzione(formName,azione);
    thisForm = document.forms[formName];
    thisForm.action = path + "SalvataggioClienti800Servlet";
    isAjax=null;
    if (thisForm['isAjax'] && thisForm['isAjax'].value !=""){
      isAjax=thisForm['isAjax'].value;
    }
    if (azione == "Salva")
    {
      if (controlliPreSalvataggio()){
         if(isAjax != null){
          submitAjaxForm(formName); 
         }else{
          thisForm.submit();
         } 
      }
    } else {  
       if (azione == "Aggiungi") 
       {
          if (isNaN(Number(thisForm['numTel'].value))){
             alert('Errore: Immettere un valore numerico per il campo Nuovo Telefono');
             thisForm['numTel'].value = "";
             return false;
          }
          else if (thisForm['numTel'].value.length < 7){
               alert('Errore: Il numero di telefono deve essere composto da almeno sette caratteri');
               return false;
          }
          else
          {
            if (thisForm['numeri_telefonici'].length>2){
              alert('Errore: Sono presenti 3 numeri di telefono per il cliente, eliminarne prima di inserirne di nuovi');  
              thisForm['numTel'].value = "";
              return false;
            }else 
              if(isAjax != null){
              submitAjaxForm(formName); 
             }else{
              thisForm.submit();
             } 
          }
       } else if (azione=="Registra"){
          if ((thisForm['email'].value == "") || (!impostaDataNascita()) || (thisForm['flag_DP_email'].value != "1") || (thisForm['flag_DP_posta'].value != "1"))
          {
             alert("Per procedere alla registrazione e' necessario compilare i campi obbligatori contrassegnati da asterisco * e fornire i consensi per comunicazione commerciali su Prontissimo tramite Email e Posta");
             thisForm['dove'].value= 'ics';
             document.getElementById('botRegistra').style.display = 'inline';
             document.getElementById('botAnnulla').style.display = 'inline';
             return false;
          }

          if (controlliPreSalvataggio())
             if(isAjax != null){
              submitAjaxForm(formName); 
             }else{
              thisForm.submit();
             } 
          else {
             thisForm['dove'].value= 'ics';
             document.getElementById('botRegistra').style.display = 'inline';
             document.getElementById('botAnnulla').style.display = 'inline';
             return false;
          }
       } else {
        if (thisForm['numeri_telefonici'].length==1)
              alert('Errore: Impossibile eliminare tutti i numeri di telefono');  
            else
            {
               messaggio = "Eiminare il numero " + thisForm['numeri_telefonici'].value + "?";
               if (confirm(messaggio) == true)
                  if(isAjax != null){
                    submitAjaxForm(formName); 
                   }else{
                    thisForm.submit();
                   } 
            }
       }
    }
    return false;
}


function submitAjaxForm(formName){
  thisForm = document.forms[formName];
  var AnagraficaReq = new Ajax(thisForm.action);
  AnagraficaReq.onLoading = function()
	{
    div_bottoneSalva=document.getElementById("_bottoneSalva");	
    if (div_bottoneSalva!=null){
      div_bottoneSalva.style.visibility='hidden';
    } 
	}
  AnagraficaReq.onCompletion = function()
	{
    alert('Modifiche salvate correttamente');
    div_bottoneSalva.style.visibility='visible';
	}
  AnagraficaReq.doPost(thisForm,false,null,'UTF-8');
  //divElenco.innerHTML=RicTicketReq.request.responseText;
  
}

function impostaDataNascita(){
    //Si testa che la data di nasciata immessa sia un valore corretto.
    if ( ((thisForm['giornoNascita'].value == null) || (thisForm['giornoNascita'].value == "")) ||
         ((thisForm['meseNascita'].value == null) || (thisForm['meseNascita'].value == "")) ||
         ((thisForm['annoNascita'].value == null) || (thisForm['annoNascita'].value == "")) )
    {
       if ((thisForm['giornoNascita'].value == "") &&
           (thisForm['meseNascita'].value == "") &&
           (thisForm['annoNascita'].value == ""))
          thisForm['dataNascita'].value = "";
       else
       {
          thisForm['giornoNascita'].value = "";
          thisForm['meseNascita'].value = "";
          thisForm['annoNascita'].value = "";
          alert('Errore: Data di nascita immessa non valida');
          return false;
       }
    }
    else
    {
       thisForm['dataNascita'].value = thisForm['giornoNascita'].value + "-" + thisForm['meseNascita'].value + "-" + thisForm['annoNascita'].value;
       return true;
    }
}
//
//Funzione che setta il valore del parametro azione.
//
function settaAzione(formName,azione){
    document.forms[formName].azione.value = azione;
}


//
//Funzione che effettua controlli su tutti i campi della pagina modificabili dall'utente,
//prima che sia eseguito il salvataggio dei dati.
//
function controlliPreSalvataggio(){
    if ((thisForm['nomeUtente'].value == "") || (thisForm['cognomeUtente'].value == "") || (thisForm['provinciaUtente'].value == "") || (thisForm['cittaUtente'].value == "") || (thisForm['indirizzoUtente'].value == "") || (thisForm['CAP'].value == "") || (thisForm['sesso'].value == ""))
    {
       alert("Per procedere alla registrazione e' necessario compilare i campi obbligatori contrassegnati da asterisco * e fornire i consensi per comunicazione commerciali su Prontissimo tramite Email e Posta");
       return false;
    }
    
    if ((thisForm['email'].value != "") && (thisForm['flag_DP_email'].value != "1"))
    {
       alert("Occorre dare il consenso ai dati personali tramite eMail");
       return false;
    }
    
    if ((thisForm['partnerPin']) && (thisForm['partnerPin'].value != "") && (thisForm['numtelinseritoalmenounavolta'].value == ""))
    {
       alert("Occorre inserire almeno un numero di telefono");
       return false;
    }

    thisForm['nomeUtente'].value = trim(thisForm['nomeUtente'].value);
    thisForm['cognomeUtente'].value = trim(thisForm['cognomeUtente'].value);
    thisForm['cittaUtente'].value = trim(thisForm['cittaUtente'].value);
    thisForm['provinciaUtente'].value = trim(thisForm['provinciaUtente'].value);
    thisForm['CAP'].value = trim(thisForm['CAP'].value);
    thisForm['indirizzoUtente'].value = trim(thisForm['indirizzoUtente'].value);

    if (!((thisForm['CAP'].value == null) || (thisForm['CAP'].value == "")))
    {
       //Si testa che il campo CAP sia un valore numerico.
       if (isNaN(Number(thisForm['CAP'].value)))
       {
          alert('Errore: Immettere un valore numerico per il campo CAP');
          return false;
       }
    }
    
    thisForm['email'].value = trim(thisForm['email'].value);
    if (!((thisForm['email'].value == null) || (thisForm['email'].value == "")))
    {
       //Si testa che il campo E-Mail contenga il carattere "@".
       if (thisForm['email'].value.indexOf("@") < 0)
       {
          alert('Errore: Immettere un valore valido per il campo E-mail');
          return false;
       }
    }
    
    //Si testa che la data di nasciata immessa sia un valore corretto.
    if ( ((thisForm['giornoNascita'].value == null) || (thisForm['giornoNascita'].value == "")) ||
         ((thisForm['meseNascita'].value == null) || (thisForm['meseNascita'].value == "")) ||
         ((thisForm['annoNascita'].value == null) || (thisForm['annoNascita'].value == "")) )
    {
       if ((thisForm['giornoNascita'].value == "") &&
           (thisForm['meseNascita'].value == "") &&
           (thisForm['annoNascita'].value == ""))
          thisForm['dataNascita'].value = "";
       else
       {
          thisForm['giornoNascita'].value = "";
          thisForm['meseNascita'].value = "";
          thisForm['annoNascita'].value = "";
          alert('Errore: Data di nascita immessa non valida');
          return false;
       }
    }
    else
       thisForm['dataNascita'].value = thisForm['giornoNascita'].value + "-" + thisForm['meseNascita'].value + "-" + thisForm['annoNascita'].value;

    return true;
}


//
// Funzione che elimina gli spazi all'inzio ed alla fine di una stringa.
//
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}





function submitNewsletter(formName,path){
    thisForm = document.forms[formName];
    thisForm.action = path + "SalvataggioNewsletterServlet";
    email = thisForm['email'].value;
    
    //Controllo che il campo email sia valorizzato.
    if (email == "")
    {
       alert('Inserire un indirizzo eMail');
       return false;
    }
    
    //Controllo che il campo email contenga il carattere "@".
    if (email.indexOf("@") < 0)
    {
       alert('Errore: Immettere un valore valido per il campo E-mail');
       return false;
    }
    
    if (thisForm.privacy[0].checked)
       thisForm.submit();
    else
       alert("E' necessaria l'accettazione dell'infomativa sulla privacy, grazie");
    return false;
}

