/*global SISAL window*/

/**
 * La variabile rappresenta il namespace utilizzato per tutto il codice
 * javascript del palinsesto.
 */
SISAL.GNTN.REGISTRAZIONE.CHECKCAMPI = (function CHECKCAMPI() {

    /*function trim(str) {
        return str.replace(/^\s+|\s+$/g, "");
    }*/

    function big(campo) {

        campo.style.fontSize = "14px";
        campo.style.fontWeight = "bold";
        campo.style.fontFamily = "Tahoma,Verdana";
    }

    function small(campo) {

        campo.style.fontSize = "12px";
        campo.style.fontWeight = "normal";
        campo.style.fontFamily = "Tahoma,Verdana";

        SISAL.GNTN.REGISTRAZIONE.sbiancaCampo(campo);

    }

    function caricaonfocusonblur()
    {

        var listaCampi = "",
        i = "",
        element = "";

        listaCampi = ['username,pin,confermapin,email,confermaemail,rispostadisicurezza_1,rispostadisicurezza_2',
        'nome', 'cognome,provincianascita,comunenascita,ProvinciaNascitaEstera,comuneNascitaEstero,giornoNascitaParam',
        'meseNascitaParam,annoNascitaParam,codicefiscale,listatipidocumento,enteRilascio,numerodocumento,luogorilascio',
        'giornoRilascioParam,meseRilascioParam,annoRilascioParam,giornoScadenzaParam,meseScadenzaParam,annoScadenzaParam',
        'nazionenull,nazioneresidenza,provinciaresidenza,comuneresidenza,provinciaResidenzaEstero,comuneResidenzaEstero',
        'indirizzo,numcivico,cap,telefono,nazionedomicilio,provinciadomicilio,comunedomicilio,provinciadomicilioestero',
        'comunedomicilioestero,indirizzodomicilio,numcivicodomicilio,capdomicilio,code'];


        for (i = 0; i < listaCampi.length; i = i + 1) 
        {
            element = document.getElementById(listaCampi[i]);
            element.onfocus = big;
            element.onblur = small;
        }  
    }       
    
    function disableCtrlKeyCombination(e) {
        // list all CTRL + key combinations you want to disable
        var forbiddenKeys = ['a', 'n', 'c', 'x', 'v', 'j'],
        key,
        isCtrl,
        i;

        if (window.event) {
            key = window.event.keyCode; // IE
            if (window.event.ctrlKey)
            {    
                isCtrl = true;
            }    
            else
            {    
                isCtrl = false;
            }    
        } else {
            key = e.which; // firefox
            if (e.ctrlKey)
            {    
                isCtrl = true;
            }    
            else
            {    
                isCtrl = false;
            }   
        }

        if (isCtrl) {
            for (i = 0; i < forbiddenKeys.length; i = i + 1) {
                 //alert('Key combination CTRL + ' +
                 //String.fromCharCode(key) + ' has been disabled.');
                if (forbiddenKeys[i].toLowerCase() === String.fromCharCode(key).toLowerCase())
                {    
                    return false;
                }    
            }

            // controllo CTRL INS
            if (key === 45) {
                 //alert('Key combination CTRL INS has been disabled.');
                return false;
            }
        }

        // SHIFT INS
        if (key === 16 || key === 45) {
             //alert('Key combination SHIFT INS has been disabled.');
            return false;
        }
        return true;
    }       

    var EnableRightClick = 0,
        isNS = (navigator.appName === "Netscape") ? 1 : 0;
    
    function mischandler()
    {
        if (EnableRightClick === 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function mousehandler(e)
    {
        var myevent = "",
            eventbutton = ""
            ;
        
        if (EnableRightClick === 1)
        {
            return true;
        }
        myevent = (isNS) ? e : event;
        eventbutton = (isNS) ? myevent.which : myevent.button;
        if ((eventbutton === 2) || (eventbutton === 3))
        {
            return false;
        }  
    }

    function keyhandler(e)
    {
        var myevent = (isNS) ? e : window.event;
        if (myevent.keyCode === 96)
        {
            EnableRightClick = 1;
        }
        return;
    }    
    
    function oggi() {

            var dData = new Date(), today = null,
            giorno = null, mese = null, anno = null;

            giorno = dData.getDate() >= 10 ? dData.getDate() : '0' + dData
                            .getDate();

            mese = (dData.getMonth() + 1) >= 10 ? (dData.getMonth() + 1) : '0' + (dData.getMonth() + 1);

            anno = dData.getFullYear();

            today = giorno + '/' + mese + '/' + anno;

            return today;

    }


	function controlloCampi(form) {

          //alert("controlloCampi ");
          
          var elements = form.elements,
              listaCampi = null,
              obbligatorieta = false,
              nazionenascita = "",
              nazioneresidenza = "",
              nazionedomicilio = ""
              ;
          

          elencoCampi_1 = "username,idpin,confermapin,email,confermaemail,domandadisicurezza_1,rispostadisicurezza_1,domandadisicurezza_2,rispostadisicurezza_2,nome,cognome";
          elencoCampi_2 = "giornoNascitaParam,meseNascitaParam,annoNascitaParam,codicefiscale,listatipidocumento,enterilascio,numerodocumento,luogorilascio,giornoRilascioParam,meseRilascioParam,annoRilascioParam,giornoScadenzaParam,meseScadenzaParam,annoScadenzaParam,cittadinanza";
          elencoCampi_3 = "indirizzo,numcivico,cap,telefono";
          elencoCampi_4 = "code";

          //listaCampi = [elencoCampi];       
          
          listaCampiNascita = "nazionenascita,provincianascita,comunenascita";       
          listaCampiNascitaEE = "nazionenascita,ProvinciaNascitaEstera,comuneNascitaEstero";       
          listaCampiResidenza = "nazioneresidenza,provinciaresidenza,comuneresidenza";       
          listaCampiResidenzaEE = "nazioneresidenza,ProvinciaEsteraResidenza,comuneResidenzaEstero";       
          listaCampiDomicilio = "nazionedomicilio,provinciadomicilio,comunedomicilio,indirizzodomicilio,numcivicodomicilio,capdomicilio";       
          listaCampiDomicilioEE = "nazionedomicilio,provinciadomicilioestero,comunedomicilioestero,indirizzodomicilio,numcivicodomicilio,capdomicilio";                 

          /*listaCampiResidenza = ['username,idpin,confermapin,email,confermaemail,id_domandadisicurezza_1,rispostadisicurezza_1',
          'id_domandadisicurezza_2,rispostadisicurezza_2,nome', 'cognome,nazionenascita,provincianascita,comunenascita,ProvinciaNascitaEstera',
          'comuneNascitaEstero,giornoNascitaParam,meseNascitaParam,annoNascitaParam,codicefiscale,listatipidocumento,enteRilascio',
          'numerodocumento,luogorilascio,giornoRilascioParam,meseRilascioParam,annoRilascioParam,giornoScadenzaParam,meseScadenzaParam',
          'annoScadenzaParam,nazionenull,nazioneresidenza,provinciaresidenza,comuneresidenza,ProvinciaEsteraResidenza,comuneResidenzaEstero',
          'indirizzo,numcivico,cap,telefono,nazionedomicilio,provinciadomicilio,comunedomicilio,provinciadomicilioestero',
          'comunedomicilioestero,indirizzodomicilio,numcivicodomicilio,capdomicilio,code'];*/
          
          

          //alert("listacampi lenght => " + listaCampi.length);
          
          if (!SISAL.isNullOrEmpty(form.nazionenascita.value))
          {
            if (form.nazionenascita.value != "Z000")
            {
              elencoCampi_1 = elencoCampi_1 + "," + listaCampiNascitaEE;
            }
            else
            {
              elencoCampi_1 = elencoCampi_1 + "," + listaCampiNascita;
            }
          }
          if (!SISAL.isNullOrEmpty(form.nazioneresidenza.value))
          {
            if (form.nazioneresidenza.value != "Z000")
            {
               elencoCampi_2 = elencoCampi_2 + "," + listaCampiResidenzaEE;
            }
            else
            {
              elencoCampi_2 = elencoCampi_2 + "," + listaCampiResidenza;
            }
          }
          if (!SISAL.isNullOrEmpty(form.nazionedomicilio.value))
          {
            if (form.nazionedomicilio.value != "Z000")
            {
              if (!form.indirizziCoincidonoSi.checked)
              {
                elencoCampi_3 = elencoCampi_3 + "," + listaCampiDomicilioEE;
              }  
            }
            else
            {
              if (!form.indirizziCoincidonoSi.checked)
              {
                elencoCampi_3 = elencoCampi_3 + "," + listaCampiDomicilio;
              }  
            }
          }
          
          //alert("elencoCampi_1 => " + elencoCampi_1);
          //alert("elencoCampi_2 => " + elencoCampi_2);
          //alert("elencoCampi_3 => " + elencoCampi_3);
          //alert("elencoCampi_4 => " + elencoCampi_4);
          
          listaCampi = elencoCampi_1 + "," + elencoCampi_2 + "," + elencoCampi_3 + "," + elencoCampi_4 ;    
          
          listaCampi = listaCampi.split(",");

          
          //alert("listaCampi => " + listaCampi.length);
          
          
          for (var l=0;l<listaCampi.length;l++)
          {
            //alert("listaCampi => " + listaCampi[l]);
            for (var i=0;i<elements.length;i++)
            {
            
                //alert("elements[i].name => " + elements[i].name + " value => " + elements[i].value);

                if (elements[i].name === listaCampi[l])
                {
                  if (SISAL.isNullOrEmpty(elements[i].value) || elements[i].value=="Scegli")
                  { 
                    document.getElementById(elements[i].name).style.backgroundColor = "#cb0000";
                    //alert(elements[i].name + " OBBLIGATORIO" );
                    obbligatorieta = true;
                  }
                  else
                  {
                    document.getElementById(elements[i].name).style.backgroundColor = "#FFFFFF";
                  }
                  break;
                }
            } 
          }
          
          if (obbligatorieta)
          {
            messaggio = "Attenzione i campi in rosso sono obbligatori";
            SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.alertMessaggio(messaggio);
            return false;
          }
          else
          {
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloUsername("inviarichiesta"))
            {
              return false;
            }
            
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloPin("inviarichiesta"))
            {
              return false;
            }
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloConfermaPin("inviarichiesta"))
            {
              return false;
            }
            
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloEmail("inviarichiesta","Email"))
            {
              return false;
            }
            
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloEmail("inviarichiesta","Conferma Email"))
            {
              return false;
            }

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloDomandeRisposta("inviarichiesta"))
            {
              return false;
            }

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloNome("inviarichiesta","nome"))
            {
              return false;
            }

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloNome("inviarichiesta","cognome"))
            {
              return false;
            }

/*
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloCodiceFiscale("inviarichiesta"))
            {
              return false;
            }
*/            
            
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloNumeroDocumento("inviarichiesta"))
            {
              return false;
            }

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloLuogoRilascioDocumento("inviarichiesta"))
            {
              return false;
            }
            
            switch (form.listatipidocumento.value)
            {
              case "1":
                // CARTA IDENTITA'
                if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloCartaIdentita("inviarichiesta"))
                {
                  return false;
                }
                break;
              case "2":
                if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloCartaIdentitaEuropea("inviarichiesta"))
                {
                  return false;
                }
                break;
              case "3":
                // PATENTE DI GUIDA ITALIANA
                if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloPatente("inviarichiesta"))
                {
                  return false;
                }
                break;
              case "4":
                // PASSAPORTO ITALIANO
                if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloPassaporto("inviarichiesta"))
                {
                  return false;
                }
                break;
              case "5":
                // PASSAPORTO ESTERO NESSUN CONTROLLO
                if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloPassaportoEstero("inviarichiesta"))
                {
                  return false;
                }
                break;
              default:
                break;
            }              

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloCap("inviarichiesta","residenza"))
            {
              return false;
            }

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloTelefono("inviarichiesta"))
            {
              return false;
            }

            if (!form.indirizziCoincidonoSi.checked)
            {
              if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloCap("inviarichiesta","domicilio"))
              {
                return false;
              }
            }  
            
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloMaggioreEta("inviarichiesta"))
            {
              return false;
            }

            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloTrattamentoDatiPersonali("inviarichiesta"))
            {
              return false;
            }
            
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloConsensoCondizini("inviarichiesta"))
            {
              return false;
            }
            if (!SISAL.GNTN.REGISTRAZIONE.VALIDAZIONE.controlloCaptcha("inviarichiesta"))
            {
              return false;
            }
            return true;
          }
          return true;        
	}
        
	function ControlloDateEstero(data1, data2) {

		var r1 = data1.getTime();
		var r2 = data2.getTime();
		
		//alert("r1 => " + r1);
		//alert("r2 => " + r2);

		if (r1>=r2)
		{
			// alert("Il controllo ha avuto buon esito.");
			return true;
		}
		else
		{
			//alert("La data di partenza è successiva a quella di arrivo!");
			return false;
		}	 

	}
        

	function controlloDataNascita(dataNascita) {
		var one_day = 1000 * 60 * 60 * 24;
		var one_month = 1000 * 60 * 60 * 24 * 30;
		var one_year = 1000 * 60 * 60 * 24 * 30 * 12;

		yr = dataNascita.substr(6, 4);
		mon = dataNascita.substr(3, 2);
		day = dataNascita.substr(0, 2);

		// alert ("anno = " + yr);
		// alert ("mese = " + mon);
		// alert ("giorno = " + day);

		today = new Date();
		var pastdate = new Date(yr, mon - 1, day);
		var countunit = "anni";
		var decimals = 0;
		var rounding = "rounddown";

		finalunit = (countunit == "giorni") ? one_day
				: (countunit == "mesi") ? one_month : one_year;
		decimals = (decimals <= 0) ? 1 : decimals * 10;

		anni = Math.floor((today.getTime() - pastdate.getTime()) / (finalunit)
				* decimals)
				/ decimals + " " + countunit;

		// alert ("nella funzione Anni = " + anni);

		return anni;

	}

	function valorizzaCampo(formInput, campo) {
		// alert ("valorizzaCampo");
		if (campo == "codicepromozionale") {
			if (formInput.value == null || formInput.value == "") {
				formInput.value = "Inseriscilo qui";
			} else if (formInput.value == "Inseriscilo qui") {
				formInput.value = "";
			}

		}
	}

	function ControlloDate(data1, data2) {

		// alert ("anno 1 = " + data1.getFullYear());
		// alert ("anno 2 = " + data2.getFullYear());

		var diff = data1.getFullYear() - data2.getFullYear();

		if (diff == 0) {
			if (((data1.getDate() == data2.getDate()) || (data1.getDate() == data2
					.getDate()))
					&& ((data1.getMonth() == data2.getMonth()) || (data1
							.getMonth() == data2.getMonth()))
					&& ((data1.getFullYear() == data2.getFullYear()) || (data1
							.getFullYear() == data2.getFullYear()))) {
				return true;
			}
		} else if (diff > 0) {
			return false;
		}
		return false;
	}
	

	function checkData(dd, mm, yyyy, tipoData) {
		document.getElementById(dd.id).style.backgroundColor = "";
		document.getElementById(mm.id).style.backgroundColor = "";
		document.getElementById(yyyy.id).style.backgroundColor = "";
		var mex = "";
		if (checkEmpty(dd.value)) {
			// alert('I campi <'+ tipoData +'> devono essere compilati.');
			mex = 'I campi data devono essere compilati.';
			document.getElementById(dd.id).style.backgroundColor = "#cb0000";
			dd.focus();
			// alert ("mex => " + mex);
			return mex;
		}
		if (checkEmpty(mm.value)) {
			// alert('I campi <'+ tipoData +'> devono essere compilati.');
			mex = 'I campi data devono essere compilati.';
			document.getElementById(mm.id).style.backgroundColor = "#cb0000";
			mm.focus();
			return mex;
		}
		if (checkEmpty(yyyy.value)) {
			// alert('I campi <'+ tipoData +'> devono essere compilati.');
			mex = 'I campi data devono essere compilati.';
			document.getElementById(yyyy.id).style.backgroundColor = "#cb0000";
			yyyy.focus();
			return mex;
		}
		if (!checkDate(dd.value, mm.value, yyyy.value)) {
			// alert('I campi <'+ tipoData +'> devono essere corretti.');
			mex = "Data non corretta.";
			document.getElementById(dd.id).style.backgroundColor = "#cb0000";
			document.getElementById(mm.id).style.backgroundColor = "#cb0000";
			document.getElementById(yyyy.id).style.backgroundColor = "#cb0000";
			dd.focus();
			return mex;
		}
		return mex;
	}

	function checkDate(dd, mm, yyyy) {
		var unaData = new Date(yyyy, (mm - 1), dd);

		if (unaData.getDate() == dd && (unaData.getMonth() + 1) == mm
				&& unaData.getFullYear() == yyyy) {
			return true;
		}

		return false;
	}

	function checkEmpty(field) {
		if (field == null || field.search(/\S/) == -1) {
			return true;
		}

		return false;
	}


	function valorizzaData(campo, id) {

		//alert ("valorizzaData");

		var gg = "giorno" + campo;
		var mm = "mese" + campo;
		var aa = "anno" + campo;

		gg = document.getElementById(gg).value;
		mm = document.getElementById(mm).value;
		aa = document.getElementById(aa).value;

		/* alert ("data => " + gg + "/" + mm + "/" + aa) ;
		 alert("campo => " + campo);
		 alert("id => " + id);*/

		if (gg >= 1 && gg <= 9) {
			gg = "0" + gg;
		}

		if (mm >= 1 && mm <= 9) {
			mm = "0" + mm;
		}

		var data = gg + "/" + mm + "/" + aa;

                //alert("data finale => " + data);

		document.getElementById(id).value = data;


		return false;
	}

	function scelta(campo,valore)
	{
	    //alert ("SCELTA IN UTILITY JS campo = " + campo + " valore = " + valore);
	    
	    var num_option=document.getElementById(campo).options.length;   
	    
	    //alert ("num option = " + num_option);
	    
	    for(var a=0;a<num_option;a++)
	    {
	        
	        if(document.getElementById(campo).options[a].value == valore )
	        {
	            document.getElementById(campo).value = valore;
	            return true;
	        }
	    }
	}
	

	function attivaDomicilio(stato) {

		// alert ("attivaDomicilio => " + stato);

		document.getElementById("capdomicilio").disabled = stato;
		document.getElementById("numcivicodomicilio").disabled = stato;
		document.getElementById("indirizzodomicilio").disabled = stato;
		document.getElementById("comunedomicilio").disabled = stato;
		document.getElementById("nazionedomicilio").disabled = stato;
		document.getElementById("provinciadomicilio").disabled = stato;
		document.getElementById("provinciadomicilioestero").disabled = stato;
		document.getElementById("comunedomicilioestero").disabled = stato;

		if (stato == "disabled") {
                
                        document.getElementById("tabelladomicilio_title").style.display = "none";
                        document.getElementById("tabelladomicilio_text").style.display = "none";
                
			document.getElementById("capdomicilio").value = "";
			document.getElementById("numcivicodomicilio").value = "";
			document.getElementById("indirizzodomicilio").value = "";
			document.getElementById("comunedomicilio").value = "";
			document.getElementById("provinciadomicilio").value = "";
			document.getElementById("provinciadomicilioestero").value = "";
			document.getElementById("comunedomicilioestero").value = "";
                        
			if (document.getElementById("nazionedomicilio").value != "Z000") {
				document.getElementById("ProvinciadomicilioTDIT").style.display = "block";
				document.getElementById("ComunedomicilioTDIT").style.display = "block";
				document.getElementById("ProvinciadomicilioTDEE").style.display = "none";
				document.getElementById("ComunedomicilioTDEE").style.display = "none";
				
				//alert("lancio SCELTA");
				
				scelta("nazionedomicilio", "Z000");
				
			}

			document.getElementById("comunedomicilio").style.backgroundColor = "#D4D0C8";
			document.getElementById("provinciadomicilio").style.backgroundColor = "#D4D0C8";
			document.getElementById("provinciadomicilioestero").style.backgroundColor = "#D4D0C8";
			document.getElementById("comunedomicilioestero").style.backgroundColor = "#D4D0C8";
			document.getElementById("capdomicilio").style.backgroundColor = "#D4D0C8";
			document.getElementById("numcivicodomicilio").style.backgroundColor = "#D4D0C8";
			document.getElementById("indirizzodomicilio").style.backgroundColor = "#D4D0C8";
			document.getElementById("nazionedomicilio").style.backgroundColor = "#D4D0C8";

		} else {
                
                        document.getElementById("tabelladomicilio_title").style.display = "";
                        document.getElementById("tabelladomicilio_text").style.display = "";
                
			document.getElementById("comunedomicilio").style.backgroundColor = "#FFFFFF";
			document.getElementById("provinciadomicilio").style.backgroundColor = "#FFFFFF";
			document.getElementById("provinciadomicilioestero").style.backgroundColor = "#FFFFFF";
			document.getElementById("comunedomicilioestero").style.backgroundColor = "#FFFFFF";
			document.getElementById("capdomicilio").style.backgroundColor = "#FFFFFF";
			document.getElementById("numcivicodomicilio").style.backgroundColor = "#FFFFFF";
			document.getElementById("indirizzodomicilio").style.backgroundColor = "#FFFFFF";
			document.getElementById("nazionedomicilio").style.backgroundColor = "#FFFFFF";
		}

	}

	function ControlloMaggiorenne(data) {
		var dataNa = new Date(calcoloData(data, '0'));
		// alert ("dataNa = " + dataNa);
		var today = oggi();
		// alert ("Oggi = " + today);
		var dataAP = new Date(calcoloData(today, '-18'));
		// alert ("dataAP = " + dataAP);

		dataNa = new Date(dataNa.getFullYear(), dataNa.getMonth(), dataNa
				.getDate());

		var dataNascita = new Date();
		var dataAppoggio = new Date();
		var ritorno = false;

		dataNascita.setMonth(dataNa.getMonth());
		dataNascita.setFullYear(dataNa.getFullYear());
		dataNascita.setDate(dataNa.getDate());

		dataAppoggio.setMonth(dataAP.getMonth());
		dataAppoggio.setFullYear(dataAP.getFullYear());
		dataAppoggio.setDate(dataAP.getDate());

		// alert ("dataNascita = " + dataNascita);
		// alert ("dataAppoggio = " + dataAppoggio);

		var mm1 = aggiungizero(dataNascita.getMonth());
		var mm2 = aggiungizero(dataAppoggio.getMonth());
		var aa1 = dataNascita.getFullYear();
		var aa2 = dataAppoggio.getFullYear();
		var gg1 = aggiungizero(dataNascita.getDate());
		var gg2 = aggiungizero(dataAppoggio.getDate());

		var dataNascitastr = aa1 + '/' + mm1 + '/' + gg1;
		var dataAppoggiostr = aa2 + '/' + mm2 + '/' + gg2;

		// alert ("dataNascitastr = " + datanumero(dataNascitastr));
		// alert ("dataAppoggiostr = " + datanumero(dataAppoggiostr));

		if (dataNascitastr == dataAppoggiostr
				|| dataNascitastr < dataAppoggiostr) {
			ritorno = true;
		} else {
			ritorno = false;
		}

		return ritorno;
	}

	// Controllo se la nazione � ITALIA oppure NO
	function checkNazione(tipo, valore) {

		//alert ("TIPO NAZIONE = " + tipo);
		//alert ("VALORE NAZIONE = " + valore);
                //alert ("null => " + !SISAL.isNullOrEmpty(tipo));

		// ARRIVA NULL NEL CASO DI CITTADINANZA
		if (!SISAL.isNullOrEmpty(tipo) && tipo != "null") {
			idProvinciaIT = "Provincia" + tipo + "TDIT";
			idComuneIT = "Comune" + tipo + "TDIT";
			idProvinciaEST = "Provincia" + tipo + "TDEE";
			idComuneEST = "Comune" + tipo + "TDEE";

			// alert ("idProvinciaIT = " + idProvinciaIT)

			if (valore == "Z000" || valore == "Scegli") {
				document.getElementById(idProvinciaIT).style.display = "block";
				document.getElementById(idComuneIT).style.display = "block";
				document.getElementById(idProvinciaEST).style.display = "none";
				document.getElementById(idComuneEST).style.display = "none";
			} else {
				document.getElementById(idProvinciaIT).style.display = "none";
				document.getElementById(idComuneIT).style.display = "none";
				document.getElementById(idProvinciaEST).style.display = "block";
				document.getElementById(idComuneEST).style.display = "block";
			}
		}
	}

	function checkcomune(tipo, select, contesto) {
		var id = "Comune" + tipo + "IT";

		var codProvincia = select.options[select.selectedIndex].value;
		var encodeUrl = "<%= request.getContextPath() %>/pubblico/servlet/comuni"
				+ "?codProvincia=" + codProvincia + "&_tipoComune=" + tipo;
		var encodeUrl = contesto + "/pubblico/servlet/comuni"
				+ "?codProvincia=" + codProvincia + "&_tipoComune=" + tipo;

		/*
		 * alert(encodeUrl); alert(id);
		 */

		var idProv = "provincia" + tipo;

		document.getElementById(idProv).style.backgroundColor = "";

		// actionURLAjaxServlet(encodeUrl, id);
		SISAL.ajax(encodeUrl, {target: id});
		
	}

	function checkenteRilascio(select, contesto) {
		var id = "enteRilascioDiv";
		//var tipoDocumento = select.options[select.selectedIndex].value;
                var tipoDocumento = select;
		var encodeUrl = contesto + "/pubblico/servlet/entiRilascio"
				+ "?tipoDocumento=" + tipoDocumento;

		// alert(encodeUrl);
        SISAL.ajax(encodeUrl, {target: id});
	}
	

	return {
		big : big,
		small : small,
		controlloCampi : controlloCampi,
		valorizzaCampo : valorizzaCampo,
		checkNazione : checkNazione,
		checkcomune : checkcomune,
		checkenteRilascio : checkenteRilascio,
		valorizzaData : valorizzaData,
		attivaDomicilio : attivaDomicilio,
		disableCtrlKeyCombination : disableCtrlKeyCombination,
		caricaonfocusonblur : caricaonfocusonblur,
		mischandler : mischandler,
		keyhandler : keyhandler,
		mousehandler : mousehandler
		/*trim : trim*/

	};
}());

if (SISAL.logger.isInfoEnabled()) {
	SISAL.logger.info("SISAL.GNTN.REGISTRAZIONE.CHECKCAMPI - namespace creato");
}

