//FILE CREATO DA P.VICGO E A.FERRARA

function controllo_delibera_p(){
  var ok;

                  //--------/ CONTROLLO DATA DELIBERA /-----------//
     ok=controlla_campo_obbligatorio(document.form.data, "Data");

     if(ok==true){ok=controlla_data(document.form.data, "Data")};

                                      //---------/ CONTROLLO TITOLO/OGGETTO DELIBERA /-----------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controllodimcampo(document.form.titolo, "Titolo/oggetto", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controlla_caratteri(document.form.titolo, "Titolo/oggetto", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.titolo, "Titolo/oggetto")};
   
                                    //---------/ CONTROLLO TITOLO/OGGETTO DELIBERA /-----------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.numero, "Numero")};
    ///---if(ok==true){ok=controllodimcampo(document.form.numero, "Numero", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.numero, "Numero")};
    if(ok==true){ok=controlla_caratteri(document.form.numero, "Numero", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.numero, "Numero")};
	
   if(ok==true){

   document.form.submit()};
}

function controllo_albo_p(){
  var ok;

                  //--------/ CONTROLLO DATA DELIBERA /-----------//
     ok=controlla_campo_obbligatorio(document.form.data, "Data");

     if(ok==true){ok=controlla_data(document.form.data, "Data")};

                                      //---------/ CONTROLLO TITOLO/OGGETTO DELIBERA /-----------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controllodimcampo(document.form.titolo, "Titolo/oggetto", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controlla_caratteri(document.form.titolo, "Titolo/oggetto", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.titolo, "Titolo/oggetto")};

                                     //--------------------/ CONTROLLO SINTESI /---------------//

//    if(ok==true){ok=controlla_campo_obbligatorio(document.form.sintesi, "Sintesi")};
//    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.sintesi, "Sintesi")};
//    if(ok==true){ok=controllodimcampo(document.form.sintesi, "Sintesi", 0)};

   if(ok==true){

   document.form.submit()};
}

function controllo_ordinanze_p(){
  var ok;

                  //--------/ CONTROLLO DATA DELIBERA /-----------//
     ok=controlla_campo_obbligatorio(document.form.data, "Data");

     if(ok==true){ok=controlla_data(document.form.data, "Data")};

                                      //---------/ CONTROLLO TITOLO/OGGETTO DELIBERA /-----------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controllodimcampo(document.form.titolo, "Titolo/oggetto", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controlla_caratteri(document.form.titolo, "Titolo/oggetto", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.titolo, "Titolo/oggetto")};
	
	if(ok==true){ok=controlla_campo_obbligatorio(document.form.numero, "Numero")};
    //---if(ok==true){ok=controllodimcampo(document.form.numero, "Numero", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.numero, "Numero")};
    if(ok==true){ok=controlla_caratteri(document.form.numero, "Numero", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.numero, "Numero")};
                         

   if(ok==true){

   document.form.submit()};
}
//-----------------------------------------------/ FUNZIONE CONTROLLO BIlANCIO    /-------------------------------//

function controllo_bilancio_p(){
  var ok;
                                   //--------/ CONTROLLO DATA BILANCIO/-----------//
    ok=controlla_campo_obbligatorio(document.form.data, "Data");

        if(ok==true){ok=controlla_data(document.form.data, "Data")};

                                      //---------/ CONTROLLO TITOLO/OGGETTO BILANCIO /-----------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controllodimcampo(document.form.titolo, "Titolo/oggetto", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.titolo, "Titolo/oggetto")};
    if(ok==true){ok=controlla_caratteri(document.form.titolo, "Titolo/oggetto", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.titolo, "Titolo/oggetto")};

                                     //--------------------/ CONTROLLO SINTESI  BILANCIO/---------------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.editor1, "Sintesi")};
    if(ok==true){ok=controllodimcampo(document.form.editor1, "Sintesi", 0)};

   if(ok==true){document.form.submit()};
  }



//                        -------------/ CONTROLLO GESTIONE BANDI SECONDA FASE /-------------
function controllo_gestionebandi_step_2(){
  var ok;
  ok=selectObbligatoria(document.form.tipo_documento, "Nome");
  if(ok==true){
          document.form.submit()};



}




//                        --------------/ BANDI DI GARA - ESITI /----------------------
function controllo_esiti(pID, pAzione){
    var ok;

        ok=controlla_campo_obbligatorio(document.form.titolo, "Titolo dell'esito");
        if(ok==true) {ok=primo_carattere_nospace_noapice(document.form.titolo, "Titolo dell'esito")};
        if(ok==true) {ok=controllodimcampo(document.form.titolo, "Titolo dell'esito", 0)};
        if(ok==true) {ok=controlla_caratteri(document.form.titolo, "Titolo dell'esito", "4")};
        if(ok==true) {ok=no_spazio_apici_consecutivi(document.form.titolo, "Titolo dell'esito")};


    //        -------------------------

    if (ok==true){ok=controlla_data(document.form.data_documento, "Data esito")};
    if (ok==true){ok=controlla_campo_obbligatorio(document.form.data_documento, "Data esito")};

    //        -----------------------

    if(ok==true){
            document.form.id_elemento.value = pID;
            document.form.azione.value = pAzione;
            document.form.submit();
    }
}


 //---------------------------------------------/COntrollo polizia municipale   /------------------------------------------/
 function controllo_polizia_p()
  {
   var ok;

    ok=controlla_campo_obbligatorio(document.form.nome_servizio, "Nome Servizio");
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.nome_servizio, "Nome Servizio")};
    if(ok==true){ok=controlla_caratteri(document.form.nome_servizio, "Nome Servizio", "4")};
    if(ok==true){ok=controllodimcampo(document.form.nome_servizio, "Nome Servizio", 0)};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.nome_servizio, "Nome Servizio")};

        if(ok==true){document.form.submit()};

 }
 //-----------------------------------------------/ FINE /-------------------------------------------/
function controllo_poliziam_p()
  {
    var ok;

    //------------------------/ Modifica Nome Servizio /-------------------------//

    ok=controlla_campo_obbligatorio(document.form.nome_servizio, "Nome Servizio");
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.nome_servizio, "Nome Servizio")};
    if(ok==true){ok=controllodimcampo(document.form.nome_servizio, "Nome Servizio", 0)};
    if(ok==true){ok=controlla_caratteri(document.form.nome_servizio, "Nome Servizio", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.nome_servizio, "Nome Servizio")};


    //-----------------------------/  SPIEGAZIONE SERVIZIO /-------------------------//

    if(ok==true){ok=controlla_campo_obbligatorio(document.form.spiegazione_servizio , "DESCRIZONE")};



        if(ok==true){document.form.submit()};
  }
//                                =========/ FINE FUNZIONE /=========





//                                =========/ CONTROLLO TRIBUTI /=========

function controllo_tributi_p(){
var ok;
// --------------/ Nome Tributo  /-------------
ok=controlla_campo_obbligatorio(document.form.nome, "Nome Tributo");
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.nome, "Nome Tributo")};
    if(ok==true){ok=controllodimcampo(document.form.nome, "Nome Tributo", 0)};
    if(ok==true){ok=controlla_caratteri(document.form.nome, "Nome Tributo", "4")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.nome, "Nome Tributo")};
//------------/ Descrizione Tributo  /-------------
   if(ok==true){ok=controlla_campo_obbligatorio(document.form.editor1, "Descrizione")};
//------------/ Importi /-------------
   if(ok==true){
      if(document.form.importo.value !=""){
        ok=controlla_caratteri(document.form.importo , "Importo","1")
      }
    }
    if(ok==true){document.form.submit()};
}

//---------------/ COntrollo Autocertificazione/--------------------
function controllo_autocertificazioneM_p(){
  var ok ;
// ----------/ Nome  Modulo /----------
    ok=controlla_campo_obbligatorio(document.form.nome_modulo , "Nome Modulo");
    if(ok==true){ok=controlla_caratteri(document.form.nome_modulo , "Nome Modulo", "4")};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.nome_modulo , "Nome Modulo")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.nome_modulo,  "Nome Modulo")};

   if(ok==true){document.form.submit()};
}



//******************************************************************************/
/******************CONTROLLO PER IL SERVIZIO STATO CIVILE (ADMIN)***********************
//******************************************************************************/
function controlla_stato_civile(pStato){
var ok;
    ok=controlla_campo_obbligatorio(document.form.nome_servizio, "Nome servizio");
    if (ok==true){ok=controlla_caratteri(document.form.nome_servizio, "Nome servizio", "4")};
    if (ok==true){ok=controllodimcampo(document.form.nome_servizio, "Nome servizio", 0)};
    if (ok==true){ok=primo_carattere_nospace_noapice(document.form.nome_servizio, "Nome servizio")};
    if (ok==true){ok=no_spazio_apici_consecutivi(document.form.nome_servizio, "Nome servizio")};

    if (pStato=="update"){
            if (ok==true){ok=controlla_campo_obbligatorio(document.form.spiegazione_servizio, "Cos'è? A cosa Serve?")};
    }

    if (ok==true){document.form.submit();}
}

//******************************************************************************/
/******************CONTROLLO PER I REGOLAMENTI (ADMIN)***********************
//******************************************************************************/
function controlla_regolamenti(){
var ok;
    ok=controlla_campo_obbligatorio(document.form.nome, "Nome regolamento");
    if (ok==true){ok=controlla_caratteri(document.form.nome, "Nome regolamento", "4")};
    if (ok==true){ok=controllodimcampo(document.form.nome, "Nome regolamento", 0)};
    if (ok==true){ok=primo_carattere_nospace_noapice(document.form.nome, "Nome regolamento")};
    if (ok==true){ok=no_spazio_apici_consecutivi(document.form.nome, "Nome regolamento")};

    if (ok==true){document.form.submit();}
}

//******************************************************************************/
/******************CONTROLLO PER IL SERVIZIO ANAGRAFICA (ADMIN)***********************
/******************************************************************************/
function controlla_anagrafica(pStato){
var ok;
    ok=controlla_campo_obbligatorio(document.form.nome_servizio, "Nome servizio");
    if (ok==true){ok=controlla_caratteri(document.form.nome_servizio, "Nome servizio", "4")};
    if (ok==true){ok=controllodimcampo(document.form.nome_servizio, "Nome servizio", 0)};
    if (ok==true){ok=primo_carattere_nospace_noapice(document.form.nome_servizio, "Nome servizio")};
    if (ok==true){ok=no_spazio_apici_consecutivi(document.form.nome_servizio, "Nome servizio")};

    if (pStato=="update"){
                if (ok==true){ok=controlla_campo_obbligatorio(document.form.spiegazione_servizio, "Cos'è? A cosa Serve?")};
    }

    if (ok==true){document.form.submit();}
}


//******************************************************************************/
/******************FUNZIONI DI CONTROLLO**********************
//******************************************************************************/

//***************************************************/
/******************Confronta due orari**************
//****************************************************/

function confronta_orari(pOra1, pOra2, pMin1, pMin2, pCampo){
var vOra1, vOra2, vMin1, vMin2
//alert(pOra1.value+"\n"+pOra2.value+"\n"+pMin1.value+"\n"+pMin2.value+"\n"+pCampo);

        vOra1 = pOra1.value;
        vOra2 = pOra2.value;
        vMin1 = pMin1.value;
        vMin2 = pMin2.value;




        //        verifico che le select siano state tutte valorizzate
        if(        vOra1 == ""||
                vOra2 == ""||
                vMin1 == ""||
                vMin2 == ""){
                alert("Selezionare correttamente gli orari.");
                return false;
        }
        //alert("prima: "+vOra2)
      //  if (vOra2==0){vOra2=24;}
        //alert("dopo: "+vOra2)

        //        verifico che l'ora d'inizio sia inferiore a quella di fine
        if (Number(vOra1) > Number(vOra2)){

                        vTxtMsg = genera_msg(pCampo, "21", "orario di fine.");
                        alert(vTxtMsg);
                        //alert("Orario non corretto.");
                        return false;
        }

        //        verifico che l'ora d'inizio e fine
        else if (Number(vOra1) == Number(vOra2) && Number(vMin1) >= Number(vMin2)){

                vTxtMsg = genera_msg(pCampo, "21", "orario di fine.");
                alert(vTxtMsg);
                //alert("Orario non corretto.");
                return false;
                }

        else{
                        return true;
                }
}

/********************************************************************************************
/*********verifica che la data di un campo non sia inf. a quella odierna *********************
/*********************************************************************************************/

function controlla_maggiore_oggi(pData, pCampo){

        var vTxtMsg;
        var vDataOdierna;
        var vMese;
        var vGiorno;
        var vAnnoData;
        var vMeseData;
        var vGiornoData;
        var vAnno;

        vGiorno      = new Date()
        vMese        = new Date()
        vAnno        = new Date()

        vGiorno      = String(vGiorno.getDate())
        vMese        = String(vMese.getMonth()+1)

        vAnno        = String(vAnno.getYear())

        pData                = String(pData.value);
        vAnnoData   = pData.substring(6,10);
        vMeseData   = pData.substring(3,5);
        vGiornoData = pData.substring(0,2);
        pData                = vAnnoData + "" + vMeseData + "" + vGiornoData


        if (vGiorno.length==1){vGiorno="0"+vGiorno}
        if (vMese.length==1){vMese="0"+vMese}

        vDataOdierna =  vAnno+""+vMese+""+vGiorno

      /*  alert(vDataOdierna);
        alert(Number(vDataOdierna));
        alert(Number(pData)); */

        if (Number(pData) < Number(vDataOdierna)){
                vTxtMsg = genera_msg(pCampo, "6", "odierna");
                alert(vTxtMsg);
                return false;
        }
        else{
                return true;
        }

}

/********************************************************************************************
/*********verifica che la data di un campo non sia maggiore a quella odierna *********************
/*********************************************************************************************/

function controlla_minore_oggi(pData, pCampo){

        var vTxtMsg;
        var vDataOdierna;
        var vMese;
        var vGiorno;
        var vAnnoData;
        var vMeseData;
        var vGiornoData;
        var vAnno;

        vGiorno      = new Date()
        vMese        = new Date()
        vAnno        = new Date()

        vGiorno      = String(vGiorno.getDate())
        vMese        = String(vMese.getMonth()+1)

        vAnno        = String(vAnno.getYear())

        pData                = String(pData.value);
        vAnnoData   = pData.substring(6,10);
        vMeseData   = pData.substring(3,5);
        vGiornoData = pData.substring(0,2);
        pData                = vAnnoData + "" + vMeseData + "" + vGiornoData


        if (vGiorno.length==1){vGiorno="0"+vGiorno}
        if (vMese.length==1){vMese="0"+vMese}

        vDataOdierna =  vAnno+""+vMese+""+vGiorno

       /* alert(vDataOdierna);
        alert(Number(vDataOdierna));
        alert(Number(pData)); */

        if (Number(pData) > Number(vDataOdierna)){
                vTxtMsg = genera_msg(pCampo, "61", "odierna");
                alert(vTxtMsg);
                return false;
        }
        else{
                return true;
        }

}


/*********************************************************************************************
/********** controlla che un campo num. non contenga caratteri non validi *********************
/*********************************************************************************************/

function controlla_numerico(pNr, pCampo){
        var vSpazio;
        var vStringa;
        var vTxtMsg;

        vSpazio = pNr.value.indexOf(" ");

        if(isNaN(pNr.value) || (pNr.value=="") || vSpazio>=0){
                vTxtMsg = genera_msg(pCampo, "1");
                alert(vTxtMsg);
                //alert("Errore nel campo "+ pCampo + ":\n sono ammessi solo valori numerici.");
                pNr.select();
                return false;
        } else{
                return true;
        }

}


/*****************************************************************************
/*********controllo la validità delle date e che siano all'interno del range temporale 1900 ~ 2037                                =
******************************************************************************************************/

function controlla_data(pData, pCampo){

    var vForm = pData;
    var vGiorno;
    var vMese;
    var vAnno;
    var vSlash1;
    var vSlash2;
    var vSpazio;
    var k;
    var vTxtMsg;
    var vUltDue;
    var PrimeDue;


    vGiorno      = Number(vForm.value.substring(0,2));
    vSlash1      = vForm.value.substring(2,3);
    vMese        = Number(vForm.value.substring(3,5));
    vSlash2      = vForm.value.substring(5,6);
    vAnno        = Number(vForm.value.substring(6,10));
    vSpazio      = vForm.value.indexOf(" ");
    vUltDue      = Number(vForm.value.substring(2,4));
    PrimeDue     = Number(vForm.value.substring(0,2));


    if(vGiorno>31||vMese>12){
                vTxtMsg = genera_msg(pCampo, "18");
                alert(vTxtMsg);
                vForm.select();
                return false;
    }

        if(vSlash1!="/" || vSlash2!="/" || vSpazio>=0 ||vGiorno=="00"||vMese=="00"||vAnno=="00" || vGiorno.length<=1 || vMese.length<=1 || vAnno.length<=3){
            vTxtMsg = genera_msg(pCampo, "2", " (es.:01/01/2002)");
            alert(vTxtMsg);
            //alert("Errore nel campo " + pCampo +":\n formattazione non valida (es.:01/01/2002)");
            vForm.select();
            return false;
        }


    if (isNaN(vGiorno)||isNaN(vMese)||isNaN(vAnno)){
        vTxtMsg = genera_msg(pCampo, "18");
        alert(vTxtMsg);
        //alert("Caratteri non ammessi nel campo " + pCampo);
        vForm.select();
        return false;
    }


    if(vGiorno == 31 && (vMese == 11 || vMese == 04 || vMese == 06 || vMese == 09 || vMese==02 )) {
        vTxtMsg = genera_msg(pCampo, "4", vGiorno);
        alert(vTxtMsg);
        //alert("Il giorno [ " + vGiorno + " ] non è valido per il mese inserito.");
        vForm.select();
        return false;
    }
    else {
                if(vGiorno == 29 && vMese == 02 && vUltDue == 00 && (PrimeDue % 4 != 0)) {

                    vTxtMsg = genera_msg(pCampo, "5", vAnno);
                    alert(vTxtMsg);
                    vForm.select();
                    //alert("L'anno [ " + vAnno + " ] non è bisestile.");
                    return false;
                }
                else if(vAnno%4 != 0 && vGiorno == 29 && vMese == 02){

                    vTxtMsg = genera_msg(pCampo, "5", vAnno);
                    alert(vTxtMsg);
                    vForm.select();
                    return false;
                }
        }

        if (vAnno < 1900 || vAnno > 2037){
                vTxtMsg = genera_msg(pCampo, "18");
                alert(vTxtMsg);
                vForm.select();
                return false;
        } else {
            return true;
    }

}

/***************************************************************************
/******************** Confronto tra le date *******************************
/**************************************************************************/

function confronto_date(pData1, pData2, pCampo1, pCampo2){

    var datainizio        = pData1.value;
    arraydatainizio        = datainizio.split("/");

    var datafine        = pData2.value;
    arraydatafine        = datafine.split("/");

    var Anno1        =  arraydatainizio[2];
    var Mese1        =  arraydatainizio[1];
    var Giorno1 =  arraydatainizio[0];

    var Anno2        = arraydatafine[2];
    var Mese2        = arraydatafine[1] ;
    var Giorno2 = arraydatafine[0];

        var valore = "true";

        var vTxtMsg;

    if (Anno2 < Anno1){
        vTxtMsg = genera_msg(pCampo2, "6", "del campo "+pCampo1);
        alert(vTxtMsg);
        //alert("Errore nel campo " + pCampo2 + ": la data indicata non può essere antecedente alla data del campo " + pCampo1 + ".");
        pData1.select();
        valore="false";
    }


    if (Anno2 == Anno1){
        if (Mese2 < Mese1){
            vTxtMsg = genera_msg(pCampo2, "6", pCampo1);
            alert(vTxtMsg);
             //alert("Errore nel campo " + pCampo2 + ": la data indicata non può essere antecedente alla data del campo " + pCampo1 + ".");
             pData1.select();
            valore="false";
        }
    }

    if (Anno2==Anno1) {
        if (Mese2==Mese1)         {
            if (Giorno2 < Giorno1){
                vTxtMsg = genera_msg(pCampo2, "6", pCampo1);
                alert(vTxtMsg);
                //alert("Errore nel campo " + pCampo2 + ": la data indicata non può essere antecedente alla data del campo " + pCampo1 + ".");
                pData1.select();
                valore="false";
            }
        }
    }

     if (valore=="false"){
          return false;
     }else{
          return true;
      }
}

/**************************************************************************
/*************** Controlla che un campo obbligatorio non sia vuoto**********
/***************************************************************************/

function controlla_campo_obbligatorio(pTesto, pCampo){

     if ((pTesto.value=="")||(pTesto.value==" ")){
                vTxtMsg = genera_msg(pCampo, "7");
                alert(vTxtMsg);
                //alert("Errore nel campo " + pCampo + ":\n dato obbligatorio.");
                pTesto.select();
                return false;
     } else{
                return true;
         }

}

/**************************************************************************
/**************************************************************************
/*************** Controlla che un campo obbligatorio select multiple**********
/***************************************************************************/

function controlla_campo_obbligatorio_s(pTesto, pCampo){
     if ((pTesto.value=="")||(pTesto.value==" ")){
                vTxtMsg = genera_msg(pCampo, "7");
                alert(vTxtMsg);
                return false;
     } else{
                return true;
         }

}

/**************************************************************************
/*************** Consente lettere, nr e alcuni caratteri di punteggiatura**********
/***************************************************************************/
function controlla_testo(pTesto, pCampo){
        var i, valore;
        var vTxtMsg;

        valore = "true"

    for (i=0; i<=(pTesto.value.length); i++){

                if(pTesto.value.charCodeAt(i)>32    &&
                        pTesto.value.charCodeAt(i)<=38  ||
                        pTesto.value.charCodeAt(i)>=40  &&
                        pTesto.value.charCodeAt(i)<=43  ||
                        pTesto.value.charCodeAt(i)>=58  &&
                        pTesto.value.charCodeAt(i)<=64  ||
                        pTesto.value.charCodeAt(i)>90   &&
                        pTesto.value.charCodeAt(i)<97   ||
                        pTesto.value.charCodeAt(i)>122  &&
                        pTesto.value.charCodeAt(i)!=224 &&
                        pTesto.value.charCodeAt(i)!=232 &&
                        pTesto.value.charCodeAt(i)!=233 &&
                        pTesto.value.charCodeAt(i)!=236 &&
                        pTesto.value.charCodeAt(i)!=242 &&
                        pTesto.value.charCodeAt(i)!=249){

                                vTxtMsg = genera_msg(pCampo, "3", pTesto.value.substring(i,i+1));
                                alert(vTxtMsg);
                        //alert("Errore nel campo " + pCampo +":\n carattere ["+pTesto.value.substring(i,i+1)+"] non consentito.");
                pTesto.select();
                valore = "false";
                break
            }

    }

    if (valore == "false"){
            return false;
    } else{
             return true;
    }

}

/*********************************************************************************
/********* Verifica che un testo non presenti caratteri non ammessi in base al tipo
/********************di dato che deve contenere ***********************************/
function controlla_caratteri(pTesto, pCampo, pCase){

  return true;

}

/*********************************************************
/*****Controllo che un testo contenga solo lettere*********
/*********************************************************/
function controlla_solo_lettere(pTesto, pCampo){
var i, valore;

        valore = "true"

        for(i=0;i < pTesto.value.length;i++){
        if( pTesto.value.charCodeAt(i)!=32 &&
                        pTesto.value.charCodeAt(i)!=39 &&
                        pTesto.value.charCodeAt(i)!=46 &&
                        pTesto.value.charCodeAt(i)< 65 ||
                        pTesto.value.charCodeAt(i)>90  &&
                        pTesto.value.charCodeAt(i)<97  ||
                        pTesto.value.charCodeAt(i)>122 &&
                        pTesto.value.charCodeAt(i)!=224 &&
                        pTesto.value.charCodeAt(i)!=232 &&
                        pTesto.value.charCodeAt(i)!=233 &&
                        pTesto.value.charCodeAt(i)!=236 &&
                        pTesto.value.charCodeAt(i)!=242 &&
                        pTesto.value.charCodeAt(i)!=249){

                                vTxtMsg = genera_msg(pCampo,"3", pTesto.value.substring(i,i+1));
                                alert(vTxtMsg);
                                //alert("Errore nel campo " + pCampo +":\n carattere["+pTesto.value.substring(i,i+1)+"] non consentito.");
                                pTesto.select();
                                valore = "false";
                                break
                }
    }

    if (valore == "false"){
                return false;
    }
    else{
                return true;
    }
}

/*********************************************************
/*****controlla la formattazione di un nr teleFONO*********
/*********************************************************/
function controlla_tel(pTel, pCampo){
       /* if (pTel.value!=""){

                var tel=pTel.value;
                var lung=tel.length;
                var slash=tel.indexOf("-");
                var prefisso=tel.substring(-1,slash);
                var numero=tel.substring((slash+1),lung);

                if (prefisso.indexOf("+")<0){
                        if (isNaN(prefisso) || slash >7){
                        //alert ("Errore nel campo "+pCampo+": prefisso non valido.");
                        pTel.focus()
                        return false;
                        }
                }  else {
                                        if (slash >7 || prefisso.substring(0,1)!="+"){
                          alert ("Errore nel campo "+pCampo+": prefisso non valido.");
                          pTel.focus()
                          return false;
                  }
                }

                for(i=0;i< numero.length;i++){
                        if(numero.charCodeAt(i)<48||numero.charCodeAt(i)>57){
                                //alert ("Errore nel campo "+pCampo+": contiene caratteri non ammessi.");
                                alert ("Errore nel campo "+pCampo+": carattere ["+numero.substring(i,i+1)+"] non ammesso.");
                                pTel.focus()
                                return false;
                        }
                }
        }*/
        return true;
}

/*****************************************************************************************************/
//************************ Controllo per verificare le dimensioni del campo ***************************
/*****************************************************************************************************/
function controllodimcampo(nomecampo,desc,dimcampo){

 // DISABILITATA

   var vTxtMsg;
     if(dimcampo == 0){
       if(nomecampo.value.length <2){
          vTxtMsg = genera_msg(desc, "8", "2");
          alert(vTxtMsg);
                  //alert("Errore nel campo "+desc+":\n il numero di caratteri minimi è due.");
           return false;
      }   else  {
             return true;
      }
    } else  {
        if(nomecampo.value.length < dimcampo){
           vTxtMsg = genera_msg(desc, "8", dimcampo);
           alert(vTxtMsg);
           //alert("Errore nel campo "+desc+":\n il numero di caratteri minimi è " + dimcampo + ".");
            return false;
         } else {
            return true;
         }
      }
      return true;
 }

/*****************************************************************************************************/
/**********Controllo  verificare che il primo carattere del campo non sia uno spazio o un apice************************/
/*****************************************************************************************************/
 function primo_carattere_nospace_noapice(nomecampo,desc) {
 var vTxtMsg;
    if(nomecampo.value.substring(0).charCodeAt()==32||nomecampo.value.substring(0).charCodeAt()==39) {
                vTxtMsg = genera_msg(desc, "9");
                alert(vTxtMsg);
                //alert("Errore nel campo "+desc+":\n il primo carattere non può essere né uno spazio, né l'apice [']");
                nomecampo.select();
                return false;
                }
        return true;
 }

/*****************************************************************************************************/
/**********Controllo  verificare che la mail per la webmail abbia minimo 5 carrateri************************/
/*****************************************************************************************************/
 function password_min_car(){
    if(document.form.pwd.value.length<5){
          alert("Errore nel campo Password:\n devi inserire al minimo 5 caratteri");
          document.form.pwd.select();
         return false;
    }
  return true;
 }

/*****************************************************************************************************/
/**********Coontrollo PER  verificare che la PRIVACY è stata accettatA************************/
/*****************************************************************************************************/
 function control_privacy(){
    if(document.form.privacy[1].checked){
          alert("Per usufruire del servizio, è necessario che tu accetti la legge sulla privacy ");
         return false;
    }
  return true;
 }

/*****************************************************************************************************/
/********Non consente d'inserire apici consecutivi/***********************/
/*****************************************************************************************************/
function no_apici_consecutivi(nomecampo,desc){
   var vTxtMsg;

    if(nomecampo.value.lastIndexOf("''") > 0){
       vTxtMsg = genera_msg(desc, "10", "''");
           alert(vTxtMsg);
           //alert("Errore nel campo "+desc+":\n apici consecutivi non sono ammessi .");
           nomecampo.select();
           return false;
     }else{
           return true;
    }
}

/*****************************************************************************************************/
/********Controllo che nel campo non vengano inseriti caratteri consecutivi ( " " ) o ("''")***********/
/*****************************************************************************************************/
function no_spazio_apici_consecutivi(nomecampo,desc){
   // DISABILITATA
   /*
   var vTxtMsg;
    if(nomecampo.value.lastIndexOf("''") > 0)  {
                vTxtMsg = genera_msg(desc, "10", "''");
                alert(vTxtMsg);
                //alert("Errore nel campo "+desc+":\n apici consecutivi non sono ammessi .");
                nomecampo.select();
                return false;
                }

        if (nomecampo.value.lastIndexOf("  ") > 0) {
                vTxtMsg = genera_msg(desc, "10", "spazi");
                alert(vTxtMsg);
                //alert("Errore nel campo "+desc+":\n spazi consecutivi non sono ammessi .");
                nomecampo.select();
                return false;
                }
                */
        return true;
  }

/***********************************************************************
/***************Controllo Mail **************************
/************************************************************************/
function chkmail(nomecampo, desc){
        var e_mail;
        e_mail=nomecampo.value;
        var vTxtMsg;

        if(e_mail!=""){

         if (nomecampo.value == "es. mario.rossi@tuoprovider.it") {
                nomecampo.value="";
          }
         if(nomecampo.value.lastIndexOf("@")==0) {
                                vTxtMsg = genera_msg(desc, "13", "@");
                                alert(vTxtMsg);
                                //alert("Errore nel campo "+desc+":\n carattere at [@] mancante.");
                                nomecampo.select();
                                return false;
                        }

                        if(nomecampo.value.lastIndexOf("@")==-1) {
                                vTxtMsg = genera_msg(desc, "12", "@");
                                alert(vTxtMsg);
                                nomecampo.select();
                                return false;
                        }


        if(nomecampo.value.substring(0).charCodeAt()==45||nomecampo.value.substring(0).charCodeAt()==46||nomecampo.value.substring(0).charCodeAt()==64||nomecampo.value.substring(0).charCodeAt()==95) {
                                  //alert(nomecampo.value.substring(0,1))
                                vTxtMsg = genera_msg(desc, "13", nomecampo.value.substring(0,1));
                                alert(vTxtMsg);
                                //alert("Errore nel campo "+desc+":\n il primo carattere non può essere\n punto [.], at [@], trattino [-], underscore [_].");
                                nomecampo.select();
                                return false;
                          }

        for(i=0;i < nomecampo.value.length;i++)  //visualizza l' alert se nel campo sono presenti caratteri non consentiti
                           {
                                if(nomecampo.value.charCodeAt(i)!=32&&nomecampo.value.charCodeAt(i)!=45&&nomecampo.value.charCodeAt(i)!=46&&nomecampo.value.charCodeAt(i)<48|| nomecampo.value.charCodeAt(i)>57&&nomecampo.value.charCodeAt(i)< 64|| nomecampo.value.charCodeAt(i)>90 && nomecampo.value.charCodeAt(i)!=95&&nomecampo.value.charCodeAt(i)<97|| nomecampo.value.charCodeAt(i)>122)
                                 {
                                 vTxtMsg = genera_msg(desc, "3", nomecampo.value.substring(i,i+1));
                                 alert(vTxtMsg);
                                 //alert("Errore nel campo "+desc+":\n carattere ["+nomecampo.value.substring(i,i+1)+"] non consentito.");
                                 nomecampo.select();
                                 return false;
                                 }
                           }

         for(i=0;i < nomecampo.value.length;i++)  //visualizza l' alert se nel campo è presente il carattere (spazio)
                           {
                                if(nomecampo.value.charCodeAt(i)==32)
                                 {
                                  vTxtMsg = genera_msg(desc, "3", "spazio");
                                 alert(vTxtMsg);
                                 //alert("Errore nel campo "+desc+":\n spazi non consentiti.");
                                 nomecampo.select();
                                 return false;
                                 }
                           }


                        var chiocciolaCount = 0;
                        var foundatposition = 0;
                        while(foundatposition != -1)
                           {
                                foundatposition = e_mail.indexOf("@", foundatposition);
                                if (foundatposition != -1)
                                {
                                        chiocciolaCount++;
                                        foundatposition++;
                                }
                                }

                if (chiocciolaCount >1)
                     {
                        vTxtMsg = genera_msg(desc, "14", "@");
                        alert(vTxtMsg);
                        //alert("Errore nel campo "+desc+":\n è ammesso un solo carattere at [@].");
                        nomecampo.select();
                        return false;
                        }

                        var lunghezza_mail;
                        lunghezza_mail = e_mail.length;
                        punto_posizionez=(lunghezza_mail-4);
                        punto_posizione=(lunghezza_mail-3);
                        punto_posizionei=(lunghezza_mail-5);
                        punto_posizionem=(lunghezza_mail-7);
                        puntone =e_mail.substring(punto_posizionez,punto_posizionez+1);
                        punto = e_mail.substring(punto_posizione,punto_posizione+1);
                        puntoinfo=e_mail.substring(punto_posizionei,punto_posizionei+1);
                        puntomuseum=e_mail.substring(punto_posizionem,punto_posizionem+1);

         if (e_mail != "es. mario.rossi@tuoprovider.it" && e_mail == "")
            {
                      e_mail = "";
                   }
                   else {

                for(i=punto_posizione+1;i < lunghezza_mail;i++)
                    {

                if (e_mail.charCodeAt(i) < 65 || e_mail.charCodeAt(i) > 90 && e_mail.charCodeAt(i) < 97 || e_mail.charCodeAt(i) > 122)
                   {
                        vTxtMsg = genera_msg(desc, "15");
                        alert(vTxtMsg);
                   //alert("Errore nel campo "+desc+":\n l'estensione (es: .it,.com) non è corretta oppure è mancante.");
                   nomecampo.select();
                   return false;
                   }
                 }
                }

                if (e_mail != "es. mario.rossi@tuoprovider.it" && e_mail == "")
                {
                 e_mail = "";
                }
                else {


                if(punto != "."&&puntone!="."&&puntoinfo!="."&&puntomuseum!=".")
                 {

                 vTxtMsg = genera_msg(desc, "16");
                 alert(vTxtMsg);
                  //alert("Errore nel campo "+desc+":\n le possibili cause sono\n1. Manca il carattere punto.\n2. L'estensione è troppo lunga");
                  nomecampo.select();
                  return false;
                 }
                }

                 if (e_mail.lastIndexOf("@.") > 0 || e_mail.lastIndexOf(".@") > 0) {
                        vTxtMsg = genera_msg(desc, "17");
                        alert(vTxtMsg);
                        //alert("Errore nel campo "+desc+":\n non sono ammessi i caratteri [@] e/o [.] consecutivamente.");
                        nomecampo.select();
                        return false;
                }

                if (e_mail.lastIndexOf("..") > 0)  {
                        vTxtMsg = genera_msg(desc, "10", ".");
                        alert(vTxtMsg);
                        //alert("Errore nel campo "+desc+":\n non sono ammessi punti consecutivi [..].");
                        nomecampo.select();
                        return false;
                        }
                        return true;
        } else{
                return true;
        }
}

/**************************************************************************
/*******************fUNZIONE PER IL CONTROLLO NUMERO DI TELEFONO*********************
/**************************************************************************/
function controllo_telefono(nomecampo, desc){
/*
var vTxtMsg;
var tel;
var telCount = 0;
var foundatposition = 0;
var vPosMeno;
var vPref;


tel                 = nomecampo.value;
vPosMeno = tel.lastIndexOf("-");
vPref         = tel.substring(0, vPosMeno);

if (nomecampo.value.length <5)
        {
        vTxtMsg = genera_msg(desc, "8", "5");
        alert(vTxtMsg);
        //alert("Inserisci correttamente il tuo numero telefonico (min. 5 cifre)");
        nomecampo.select();
        return false;
        }

if (vPref.length>=7){
         vTxtMsg = genera_msg(desc, "19");
        alert(vTxtMsg);
        nomecampo.select();
        return false;

}

  for(i=0;i< nomecampo.value.length;i++)  {
      if(nomecampo.value.charCodeAt(i)!=32&&nomecampo.value.charCodeAt(i)!=45&&nomecampo.value.charCodeAt(i)<48||nomecampo.value.charCodeAt(i)>57)
            {
                vTxtMsg = genera_msg(desc, "3", nomecampo.value.substring(i,i+1));
                alert(vTxtMsg);
        //alert("Nel campo TELEFONO il carattere [ "+nomecampo.value.substring(i,i+1)+" ] non è consentito.\nSono consentiti solo i caratteri numerici e il carattere trattino [-].");
        nomecampo.select();
            return false;
          }
        }

     for(i=0;i< nomecampo.value.length;i++)  //visualizza l' alert se nel campo è presente il carattere (spazio)
         {
        if(nomecampo.value.charCodeAt(i)==32)
        {
                vTxtMsg = genera_msg(desc, "3", "spazio");
                alert(vTxtMsg);
        //alert("Il carattere [spazio] nel campo TELEFONO non è consentito");
         nomecampo.select();
         return false;
         }
         }
      if(vPosMeno < 0)
                {
                vTxtMsg = genera_msg(desc, "12", "-");
                alert(vTxtMsg);
                //alert("il carattere trattino [ - ] deve essere presente nel campo TELEFONO (es:02-34252299).");
                nomecampo.select();
                return false;
                }


    while(foundatposition != -1)  {
        foundatposition = tel.indexOf("-", foundatposition);
        if (foundatposition != -1) {
                telCount++;
                foundatposition++;
        }
        }

        if (telCount>1) {
                vTxtMsg = genera_msg(desc, "14", "-");
                alert(vTxtMsg);
                //alert("Attenzione! Hai inserito " + telCount + " volte il simbolo [-]. Nel campo TELEFONO ne puoi inserire soltanto uno!");
                nomecampo.select();
                return false;
        }

    if (nomecampo.value.substring(0).charCodeAt()==45||nomecampo.value.substring(1).charCodeAt()==45)
     {
                vTxtMsg = genera_msg(desc, "2", " (es: 02-0821441)");
                alert(vTxtMsg);
                //alert("Inserisci correttamente il carattere trattino [ - ] nel campo TELEFONO (es:02-34252299).");
                nomecampo.select();
                return false;
         }

   for(i=4;i < tel.length;i++);
    {
     if(tel.charCodeAt(i) < 48||tel.charCodeAt(i) > 57)
      {
                vTxtMsg = genera_msg(desc, "2", " (es: 02-0821441)");
                alert(vTxtMsg);
       //alert("Inserisci correttamente il carattere trattino [ - ] nel campo TELEFONO (es:02-34252299).");
           nomecampo.select();
           return false;
          }
          return true;
           }*/
return true;
}

/**************************************************************************
/*******************ffunction per il controllo di una select obbligatoria*********************
/**************************************************************************/
function selectObbligatoria(nomecampo,desc){
  var vTxtMsg;
  if(nomecampo.value=="0" || nomecampo.value=="") {
         vTxtMsg=genera_msg(desc, "7")
         alert(vTxtMsg);
         //alert("Il Campo ["+desc+"] non puo essere non selezionato!");
         return false;
        }
         return true;
        }


/**********************************************************************************************
/*******************verifica che l'indirizzo del sito sia preceduto da http:// *********************
/***********************************************************************************************/
function controllo_SitoWeb(nomecampo, desc){
 var vTxtMsg;
    if(nomecampo.value.substring(0,7)!="http://" ) {
       vTxtMsg = genera_msg(desc, "11");
       alert(vTxtMsg);
       nomecampo.select();
       return false;
    } else{
           return true;
    }
}

/**********************************************************************************************
/*******************function per verificare che almeno un campo sia selezionato********************
/***********************************************************************************************/
function controllo_che_almeno_unatextsiapiena(nomecampo1,nomecampo2,nomecampo3,nomecampo4,nomecampo5,nomecampo6, desc){
 if(nomecampo1.value=="" &&nomecampo2.value=="" &&nomecampo3.value=="" &&nomecampo4.value=="" &&nomecampo5.value=="" &&nomecampo6.value=="") {
  alert("Almeno un["+desc+"] deve essere selezionato");
  return false;
 }else{
  return true;
}
}

/**********************************************************************************************
/*******************function per verificare che almeno una checkbox sia selezionata********************
/***********************************************************************************************/
function controllo_che_almeno_unaCheckBox(nomecampo1,nomecampo2,nomecampo3,nomecampo4, desc){
 if(nomecampo1.checked==false &&nomecampo2.checked==false &&nomecampo3.checked==false &&nomecampo4.checked==false){
  alert("Almeno un["+desc+"] deve essere selezionato");
  return false;
 }else{
  return true;
}
}

/**********************************************************************************************
/*******************function per la webmail***********************************
/***********************************************************************************************/
function controlla_combo_domanda_webmail(){
        if(document.form.id_domanda.value==0){
            alert("Devi compilare il campo della domanda");
             return false;
        }else{
              return true;
        }
}
function controlla_combo_occupazione_webmail(){
        if(document.form.occupazione.value==0){
            alert("Devi compilare il campo dell'occupazione");
             return false;
        }else{
              return true;
        }
}
function controlla_combo_settore_webmail(){
        if(document.form.settore.value==0){
            alert("Devi compilare il campo del settore");
             return false;
        }else{
              return true;
        }
}

function confronta_password(){
  if(document.form.pwd.value!=document.form.conf_pwd.value){
     alert("La conferma della password è sbagliata");
     return false;
   }else{
      return true;
   }

}


/**********************************************************************************************
/*******************function per verificare vhe genera il messaggio di alert********************
/***********************************************************************************************/
function genera_msg(pCampo, pIndice, pStringa){
        var vTipoErr;
        var vTxtMsg;

        //pIndice = "'"+String(pIndice)+"'"
        switch (pIndice){
                case "1":
                        vTipoErr="sono ammessi solo valori numerici.";
                        break;
                case "2":
                        vTipoErr="formattazione non valida "+pStringa+".";
                        break;
                case "3":
                        vTipoErr="carattere [" + pStringa + "] non consentito.";
                        break;
                case "4":
                        vTipoErr="il giorno [" + pStringa + "] non è valido per il mese inserito.";
                        break;
                case "5":
                        vTipoErr="l'anno [" + pStringa + "] non è bisestile.";
                        break;
                case "6":
                        vTipoErr="la data indicata non può essere antecedente alla data "+pStringa;
                        break;
                case "61":
                        vTipoErr="la Data di nascita non può essere successiva alla data "+pStringa;
                        break;
                case "7":
                        vTipoErr="dato obbligatorio.";
                        break;
                case "8":
                        vTipoErr="il numero di caratteri minimi è " + pStringa + ".";
                        break;
                case "9":
                        vTipoErr="il primo carattere non può essere né uno spazio, né un apice [']";
                        break;
                case "10":
                        vTipoErr="non sono ammessi ["+pStringa+"] consecutivi.";
                        break;
                case "11":
                        vTipoErr="Indicare HTTP:// davanti al nome del sito web";
                        break;
                case "12":
                        vTipoErr="carattere [" +pStringa+ "] mancante.";
                        break;
                case "13":
                        vTipoErr="il primo carattere non può essere ["+pStringa+"].";
                        break;
                case "14":
                        vTipoErr="è ammesso un solo carattere ["+pStringa+"].";
                        break;
                case "15":
                        vTipoErr="l'estensione (es: .it,.com) non è corretta oppure è mancante.";
                        break;
                case "16":
                        vTipoErr="verificare l'estensione, possibili cause \n1. Manca il carattere [.]\n2. L'estensione è troppo lunga";
                        break;
                case "17":
                        vTipoErr="non sono ammessi i caratteri [@] e/o [.] consecutivamente.";
                        break;
                case "18":
                        vTipoErr="data non valida.";
                        break;
                case "19":
                        vTipoErr="dimensione prefisso non accettabile.";
                        break;
                case "20":
                        vTipoErr=pStringa+" non accettabile.";
                        break;
                case "21":
                        vTipoErr="l'orario selezionato non può essere antecedente o uguale all' orario "+pStringa;
                        break;

        }

        return vTxtMsg="Errore nel campo "+pCampo+":\n"+vTipoErr;
}



//*************************************************************************************************
//***************FUNZIONE PER L'APERTURA DELLA POPUP PER AIUTO PER IL FORMATO DEI TESTI****************
//*************************************************************************************************/
function open_aiuto(){
window.open('aiuto.php', 'Aiuto', 'width=400,height=400,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}

function open_aiuto_editor(){
window.open('popup/aiuto_editor.php', 'Aiuto', 'width=450,height=200,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}


function open_aiuto2(id_div){
window.open('popup/aiuto_online.php#'+id_div, 'Aiuto', 'width=450,height=400,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}
function open_aiuto_s(){
window.open('aiuto_s.php', 'Aiuto', 'width=400,height=400,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}
function open_aiuto_turismo(){
window.open('../aiuto.php', 'Aiuto', 'width=400,height=400,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}

/****************************************************************************************
/***********************FUNZIONE PER L'APERTURA DELLA POPUP DEGLI ORARI (BACK END)*************************
/****************************************************************************************/
function PopUpOrari(id,Sessione,type){

    var Url;
        var StrWin;
        Url = "includes/orari_form.php?item="+id+"&id="+Sessione+"&type="+type;
    StrWin = window.open (Url,"PopUp",["width=400,height=500,left=250,top=150,resizable=no,menubar=no,toolbars=no,directories=no"]);
        StrWin.focus();
}

function PopUpOrari2(id,Sessione,type){
        var Url;
        var StrWin;
        Url = "includes/orari_numerici_form.php?item="+id+"&id="+Sessione+"&type="+type;
        StrWin = window.open (Url,"PopUp",["width=400,height=500,left=250,top=150,resizable=no,menubar=no,toolbars=no,directories=no"]);
        StrWin.focus();
  }


/****************************************************************************************
/***********************FUNZIONE PER L'APERTURA DELLA POPUP dei PARTITI (BACK END)*************************
/****************************************************************************************/
function PopUpMaggioranza(Sessione,type){
  var Url;
  var StrWin;
  Url = "includes/partiti_form.php?id="+Sessione;
  StrWin = window.open (Url,"PopUpMaggioranza",["width=450,height=300,left=250,top=200,resizable=no,menubar=no,toolbars=no,directories=no"]);
  StrWin.focus();
}


/**************************************************************************************
***********funzione per l'apertura della popup dell'angrafica******************
*****************************************************************************************/
function anagraficabreve(idanagrafica,id){
  window.open("popup/anagraficabreve.php?id="+id+"&idanagrafica="+idanagrafica+"","anagraficabreve","width=400, height=280");
}



//**************************************************************************************************************************
//****************************funzione per il page editor (pagine aggiuntive)***********************************************
//**************************************************************************************************************************

function validate_page_editor(){
 if(document.pagina.intestazione.value==''){
  alert("Non hai inserito il titolo della paginas");
  return false;
 }
}



//*********************************************************************************************
//***********************FUNZIONI PER LA GESTIONE DELLa POLIZIA (MODULISTICA)*******************************
//*********************************************************************************************
function controllo_poliziamodulistica_p(pAzione){
 var ok;

// -------------/ Titolo categoria /----------------------
        ok=controlla_campo_obbligatorio(document.form.titolo_bando, "Categoria");
        if(ok==true){ok=controllodimcampo(document.form.titolo_bando, "Categoria", 0)};
        if(ok==true){ok=primo_carattere_nospace_noapice(document.form.titolo_bando, "Categoria")};
        if(ok==true){ok=controlla_caratteri(document.form.titolo_bando, "Categoria", "4")};
        if(ok==true){ok=no_spazio_apici_consecutivi(document.form.titolo_bando, "Categoria")};

        if(ok==true) {
                if (pAzione=='New') {
                        document.form.submit('true');
                } else {
                        return true;
                        document.form.submit();
                }
        }
}



//*********************************************************************************************
//***********************FUNZIONI PER LA GESTIONE DELL'ANAGRAFICA*******************************
//*********************************************************************************************
function controllo_anagrafica_p(pAzione){
	var ok;

      //                  --------------/ Nome /----------------------
/*	
        ok=controlla_campo_obbligatorio(document.form.nome, "Nome servizio");
        if(ok==true){ok=controllodimcampo(document.form.nome, "Nome servizio", 0)};
        if(ok==true){ok=primo_carattere_nospace_noapice(document.form.nome, "Nome servizio")};
        if(ok==true){ok=controlla_caratteri(document.form.nome, "Nome servizio", "4")};
        if(ok==true){ok=no_spazio_apici_consecutivi(document.form.nome, "Nome servizio")};
*/
     //                       --------------/ cosa  /----------------------
        ok=controlla_campo_obbligatorio(document.form.editor1, "Cos'è? A cosa Serve? ");
        if(ok==true){ok=controllodimcampo(document.form.editor1, "Cos'è? A cosa Serve? ", 0)};
        if(ok==true){ok=primo_carattere_nospace_noapice(document.form.editor1, "Cos'è? A cosa Serve? ")};
        if(ok==true){ok=controlla_caratteri(document.form.editor1, "Cos'è? A cosa Serve? ", "4")};
        if(ok==true){ok=no_spazio_apici_consecutivi(document.form.editor1, "Cos'è? A cosa Serve? ")};


        if(ok==true){
       		if (pAzione=='New'){
            	document.form.submit('true');
          	}  
          	else  {
            	return true;
                document.form.submit();
          	}
       	}
}

//********************CONSIGLIO COMUNALE**************
//FUNZIONE PER L'APERTURA DELLA POPUP QUANDO SI CLICCA SUL NOME DI UN CONSIGLIERE - FRONT END

function info_img_citta(){
window.open('popup/info_img_citta.php', 'Aiuto', 'width=420,height=220,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}

function info_img_comune(){
window.open('popup/info_img_comune.php', 'Aiuto', 'width=420,height=220,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}

function info_img_turismo(){
window.open('../popup/info_img_turismo.php', 'Aiuto', 'width=420,height=220,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}


//*************************************************
//*****************SERVIZIO CIMITERIALE**************
//*****************************************************

function controllo_doc_cimitero(){
    var ok;

        ok=controlla_campo_obbligatorio(document.form.descrizione, "Nome del documento");
        if(ok==true) {ok=primo_carattere_nospace_noapice(document.form.descrizione, "Nome del documento")};
        if(ok==true) {ok=controllodimcampo(document.form.descrizione, "Nome del documento", 0)};
        if(ok==true) {ok=controlla_caratteri(document.form.descrizione, "Nome del documento", "4")};
        if(ok==true) {ok=no_spazio_apici_consecutivi(document.form.descrizione, "Nome del documento")};

    if(ok==true){
            document.form.submit();
    }
}

  //------------------------  fUNZIONE PER CONTROLLARE L'ESATTEZZA DELLA DATA--------------------------------------
  function checkdate(data) {
                giorno         = data.substring(0,2);
                mese        = data.substring(3,5);
                anno        = data.substring(6,10);

                if(giorno == 30 && mese==02) {
                        alert("Non puoi inserire il giorno [ " + giorno + " ] per il mese inserito.");
                        return 1;
                }
                if(giorno == 31 && (mese == 11 || mese == 04 || mese == 06 || mese == 09 || mese==02 )) {
                        alert("Non puoi inserire il giorno [ " + giorno + " ] per il mese inserito.");
                        return 1;
                } else {
                        if(giorno == 29 && mese == 02 && anno.substring(2,4) == 00 && (anno.substring(0,2)%4 != 0)) {
                                alert("L'anno [ " + anno + " ] non è bisestile.");
                                return 1;
                        } else {
                                if(anno%4 != 0 && giorno == 29 && mese == 02) {
                                        alert("L'anno [ " + anno + " ] non è bisestile.");
                                        return 1;
                                } else {
                                        return 0;
                                }
                        }
                }
        }


function ultimora(){
        larghFinestra=470; /*creo una variabile contenente la larghezza della finestra*/
    altezFinestra=320; /* creo una variabile contenente l'altezza della finestra*/
        sinistra=screen.width-larghFinestra*2+100; /*creo una variabile e mi ricavo il valore della posizione della finestra a sinistra dello schermo*/
        alto=screen.height-altezFinestra*3/2; /*creo una variabile e mi ricavo il valore della posizione della finestra dall'alto dello schermo */
     window.open("ultimora/popup/news.php","last_news","left="+sinistra+",top="+alto+",width="+larghFinestra+", height="+altezFinestra+", scrollbars");
}



function  aprinews(idnews){
  larghFinestra=470; /*creo una variabile contenente la larghezza della finestra*/
  altezFinestra=320; /* creo una variabile contenente l'altezza della finestra*/
  sinistra=screen.width-larghFinestra*2+100; /*creo una variabile e mi ricavo il valore della posizione della finestra a sinistra dello schermo*/
  alto=screen.height-altezFinestra*3/2; /*creo una variabile e mi ricavo il valore della posizione della finestra dall'alto dello schermo */
  window.open("ultimora/popup/news.php?idnews="+idnews+"","news","left="+sinistra+",top="+alto+",width="+larghFinestra+", height="+altezFinestra+", scrollbars");
}

//***********messaggi_cs_form.inc.php
function RadioButtonSystem(stato,numero)
{
  if(stato == "on")
  {
  document.form.tutti.value=0;
        for(x=0;x<numero;x++)
        {
           oggetto_check = eval("document.form.contatto_" + x);
           if(oggetto_check != null)
           {
           oggetto_check.disabled = false;
           }
        }
  }
  else
  {
  document.form.tutti.value=1;

            for(x=0;x<numero;x++)
            {

                 oggetto_check = eval("document.form.contatto_" + x);
                 if(oggetto_check != null)
                 {
                 oggetto_check.disabled = true;
                 }
            }
  }
}

function confermaDeleteMessaggio(url) {
   conferma = confirm("Sei sicuro di voler eliminare il messaggio selezionato?\nQuesta operazione non può essere annullata.");
   if(conferma == true) {
       document.location.href = url;
    }
}

function ConfermaElimina(url,var_testo) {

 conferma = confirm("Sei sicuro di voler eliminare "+var_testo+" selezionato?");
 if(conferma == true) {
   document.location.href = url;
 } else {
   return false;
 }
}

//**************************************************************************
//************FUNZIONI PER LE POPUP DELLA CREAZIONE HOME PAGE SEZIONI + PAGINE AGIUNTIVE
//**************************************************************************

function close_popup(){
window.opener.location.reload();
window.close();
}


function presenza_link(){
var tot_elem=document.contenuto_paragrafo.elements.length;
  for(i=0;i<=(tot_elem-2);i++){
    if(document.contenuto_paragrafo.elements[i].name=='tipo_link'){
         return true;
        }
  }
}

function validate_link(){
    if(document.contenuto_paragrafo.link_interno.value==0 & document.contenuto_paragrafo.link_esterno.value=='http://'){
          alert("Devi scegliere un link");
          return false;
        } else if(document.contenuto_paragrafo.link_esterno.value.substring(0,7)!="http://" & document.contenuto_paragrafo.link_interno.value==0){
          alert("Un link esterno deve cominciare con 'http://'");
          return false;
        } else {
         return true;
        }
}

function validate_compila_parag(img_esiste){
var tot_elem=document.contenuto_paragrafo.elements.length;
  if(presenza_link()==true){
   for(i=0;i<=(tot_elem-6);i++){   //se ci sono i link, faccio un controllo a parte e quindi ciclo su 6 elemnti in meno
      if(document.contenuto_paragrafo.elements[i].value.substring(0).charCodeAt()==32){
                 if(document.contenuto_paragrafo.elements[i].name=="userfile"){
                   if(img_esiste==0){
                        alert("Devi inserire un'immagine");
                        return false;
                   }
                 } 
                 else {
                 	if(document.contenuto_paragrafo.elements[i].value=='' && (document.contenuto_paragrafo.elements[i].name=='titolo' || document.contenuto_paragrafo.elements[i].name=='editor1' || document.contenuto_paragrafo.elements[i].name=='editor2')){
		 				
		 			     alert("Devi compilare il campo "+document.contenuto_paragrafo.elements[i].name);
        			     return false;
					}                 
                 /*
                     if(document.contenuto_paragrafo.elements[i].value==''){
                     
                         alert("Devi compilare il campo "+document.contenuto_paragrafo.elements[i].name);
                        return false;
                      } else { //caso dello spazio  come primo carattere
                        alert("Non puoi inserire uno spazio come primo carattere nel campo "+document.contenuto_paragrafo.elements[i].name);
                           return false;
                     }
                   */
                    }
       }
   } //fine del ciclo
    if(validate_link()==false){
            return false;
    }
  }  else { //non ci sono i link, faccio un controllo su tutti gli elementi meno 2 (i due bottoni)
    for(i=0;i<=(tot_elem-2);i++){
         if(document.contenuto_paragrafo.elements[i].value=='' || document.contenuto_paragrafo.elements[i].value.substring(0).charCodeAt()==32){
                   if(document.contenuto_paragrafo.elements[i].name=='userfile'){
                     if(img_esiste==0){
                           alert ("Devi inserire un'immagine");
                           return false;
                         }
                    } else {
                 	if(document.contenuto_paragrafo.elements[i].value=='' && (document.contenuto_paragrafo.elements[i].name=='titolo' || document.contenuto_paragrafo.elements[i].name=='editor1' || document.contenuto_paragrafo.elements[i].name=='editor2')){
		 				
		 			     alert("Devi compilare il campo "+document.contenuto_paragrafo.elements[i].name);
        			     return false;
					}                      
                    /*
                       if(document.contenuto_paragrafo.elements[i].value=='' && (document.contenuto_paragrafo.elements[i].name=='titolo' || document.contenuto_paragrafo.elements[i].name=='editor1' || document.contenuto_paragrafo.elements[i].name=='editor2')){
                       alert("Currentelem:" + document.contenuto_paragrafo.elements[i].value);
                          alert("Devi compilare il campo "+document.contenuto_paragrafo.elements[i].name);
                         return false;
                        } else { //caso dello spazio  come primo carattere
                         alert("Non puoi inserire uno spazio come primo carattere nel campo "+document.contenuto_paragrafo.elements[i].name);
                            return false;
                      }
                   */
                   }
          }
    } //fine ciclo
 }
}


function change_radio(){
  if(document.contenuto_paragrafo.tipo_link[0].checked==true){
    document.contenuto_paragrafo.link_interno.disabled=false;
        document.contenuto_paragrafo.link_esterno.disabled=true;
        document.contenuto_paragrafo.link_esterno.value="http://";
  }
  if(document.contenuto_paragrafo.tipo_link[1].checked==true){
   document.contenuto_paragrafo.link_interno.disabled=true;
   document.contenuto_paragrafo.link_esterno.disabled=false;
   document.contenuto_paragrafo.link_interno.value="";
  }
}

function stato_radio_onload(){
 if(presenza_link()==true){
        if(document.contenuto_paragrafo.link_interno.value!=""){
           document.contenuto_paragrafo.tipo_link[0].checked=true;
       document.contenuto_paragrafo.link_esterno.disabled=true;
         } else {
           document.contenuto_paragrafo.tipo_link[1].checked=true;
          document.contenuto_paragrafo.link_interno.disabled=true;
         }
  }
}

function open_aiuto_img(){

Url = "aiuto_img.php";
window.open(Url, 'Aiuto', 'width=500,height=200,resizable=no,status=no,location=no,toolbar=no');
}

//FINE FUNZIONI PERMLE POPUP DI CREAZIONE DI PAGINE (PARAGRAFi)


//**********************************************************************************
//***************************funzioni per l'upload dei files************************
//**********************************************************************************

//per la pagina anagrafica_foem.inc.php
function check_file(id, field_name) {
  oggetto_file = eval("document.form." + field_name + "_" + id);
  if(oggetto_file.disabled == true) {   /* SE L'OGGETTO è DISABILITATO ALLORA LO ABILITO */
        oggetto_file.disabled = false;
  } else { /* E VICEVERSA */
     oggetto_file.disabled = true;
  }
}

function check_upload_form_anagrafica(n_ext, field_name){
   for(x = 1;x < n_ext;x++){ /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
     /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
         oggetto_file = eval("document.form." + field_name + "_" + x);
     oggetto_flag = eval("document.form.ck_" + x);
     oggetto_tipo = eval("document.form.ext_" + x);
         /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
         if(oggetto_file != null){
           if(oggetto_file.value.length>0){
             /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                  if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                    return false;
                  }
           }
         }
  }
  return controllo_gestionebandi_step_2();
}

function check_upload_form_autocertificazione(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){  /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
    oggetto_file = eval("document.form." + field_name + "_" + x);
        oggetto_flag = eval("document.form.ck_" + x);
        oggetto_tipo = eval("document.form.ext_" + x);
        /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
        if(oggetto_file != null){
          if(oggetto_file.value.length>0){
            /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                  if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                     return false;
              }
          }
    }
  }
 return controllo_autocertificazioneM_p();
}

function check_upload_form_bandi(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){
     /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
         oggetto_file = eval("document.form." + field_name + "_" + x);
         oggetto_flag = eval("document.form.ck_" + x);
         oggetto_tipo = eval("document.form.ext_" + x);
         /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
         if(oggetto_file != null){
            if(oggetto_file.value.length>0){
                  /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                    if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                          return false;
                        }
            }
     }
  }
 return controllo_gestionebandi_step_2();
}

function check_upload_form_bilancio(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){ /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
    oggetto_file = eval("document.form." + field_name + "_" + x);
        oggetto_flag = eval("document.form.ck_" + x);
        oggetto_tipo = eval("document.form.ext_" + x);
        /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
        if(oggetto_file != null){	
          if(oggetto_file.value.length>0){
           /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE  DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
             if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                   return false;
                 }
          }
        }
  }
  
  return controllo_bilancio_p();
}

function check_upload_form_delibere(n_ext, field_name, flag)
{
if(flag=="true")
{
    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
    for(x = 1;x < n_ext;x++)
    {
        /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
        oggetto_file = eval("document.form." + field_name + "_" + x);
        oggetto_flag = eval("document.form.ck_" + x);
        oggetto_tipo = eval("document.form.ext_" + x);
        /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
        if(oggetto_file != null)
        {
            if(oggetto_file.value.length>0)
            {
               /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE  FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                if(checkFileExt(oggetto_file,oggetto_tipo.value) == false)
                {
                  return false;
                }
            }
        }
    }
}
    return controllo_delibera_p();
}

function check_upload_form_albo(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */	
  for(x = 1;x < n_ext;x++){ /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
    oggetto_file = eval("document.form." + field_name + "_" + x);
        oggetto_flag = eval("document.form.ck_" + x);
        oggetto_tipo = eval("document.form.ext_" + x);
        /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
         if(oggetto_file != null){
           if(oggetto_file.value.length>0){
           /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE  FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
            if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                  return false;
                }
      }
        }		
 }
  
 return controllo_albo_p();
}

function check_upload_form_ordinanze(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){ /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
    oggetto_file = eval("document.form." + field_name + "_" + x);
        oggetto_flag = eval("document.form.ck_" + x);
        oggetto_tipo = eval("document.form.ext_" + x);
        /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
         if(oggetto_file != null){
           if(oggetto_file.value.length>0){
           /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE  FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
            if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                  return false;
                }
      }
        }
 }
 
 return controllo_ordinanze_p();
}

function check_upload_form_esiti(n_ext, field_name,id_anagrafica,azione){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){
    /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
        oggetto_file = eval("document.form." + field_name + "_" + x);
        oggetto_flag = eval("document.form.ck_" + x);
        oggetto_tipo = eval("document.form.ext_" + x);
        /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
        if(oggetto_file != null){
           if(oggetto_file.value.length>0){
             /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                  if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                    return false;
                  }
                }
         }
        }
  return controllo_esiti(id_anagrafica,azione);
}

function check_upload_form_gestione_bandi(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
   for(x = 1;x < n_ext;x++){
     /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
         oggetto_file = eval("document.form." + field_name + "_" + x);
         oggetto_flag = eval("document.form.ck_" + x);
         oggetto_tipo = eval("document.form.ext_" + x);
         /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
         if(oggetto_file != null){
           if(oggetto_file.value.length>0){
             /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                   if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                     return false;
                   }
                }
         }
   }
   return controllo_gestionebandi_step_2();
}

function check_upload_form_cimitero(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){
   /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
   oggetto_file = eval("document.form." + field_name + "_" + x);
   oggetto_flag = eval("document.form.ck_" + x);
   oggetto_tipo = eval("document.form.ext_" + x);
   /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
     if(oggetto_file != null){
           if(oggetto_file.value.length>0){
             /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONE DEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
                   if(checkFileExt(oggetto_file,oggetto_tipo.value) == false){
                    return false;
                   }
            }
      }
  }
  return controllo_doc_cimitero();
}

function check_upload_form_tributi(n_ext, field_name){    /* ORA EFFETTUO UN BEL CICLO TRA I VARI ELEMENTI DI UPLOAD */
  for(x = 1;x < n_ext;x++){
   /* VERIFICO CHE ESISTA UN ELEMENTO FILE CON L'ID ESTENSIONE corrente */
   oggetto_file = eval("document.form." + field_name + "_" + x);
   oggetto_flag = eval("document.form.ck_" + x);
   oggetto_tipo = eval("document.form.ext_" + x);
   /* VERIFICO CHE ESISTA EFFETTIVAMENTE IL CAMPO X IL FILE */
   if(oggetto_file != null)  {
     if(oggetto_file.value.length>0){
         /* RICHIAMO UNA FUNZIONE CHE CONTROLLA L'ESTENSIONEDEL FILE CHE SI STA CERCANDO DI CARICARE CON PHP */
          if(checkFileExt(oggetto_file,oggetto_tipo.value) == false) {
            return false;
          }
    }
  }
}
return controllo_tributi_p();
}




function checkFileExt(objFile, objExt){
  /* CALCOLO LA POSIZIONE DELL'ULTIMO PUNTO NELLA STRINGA E LUNGHEZZA DELLA STRINGA X EFFETTUARE LE OPERAZIONI DI
     ANALISI DELLA ESTENSIONE DEL FILE */
         strLength = objFile.value.length;
         lastPoint = objFile.value.lastIndexOf('.') + 1;
         /* ESTRAGGO L'ESTENSIONE CORRENTE DEL FILE */
         currentExt = objFile.value.substring(lastPoint,strLength);
         /* ORA TRASFORMO QUESTA STRINGA IN CARATTERI MINUSCOLI X LA COMPARAZIONE */
         currentExt = currentExt.toLowerCase();

         /* ORA ANALIZZO LA STRINGA */
         if (objExt=="htm")
         {
            if(currentExt=="html")
            {
            return true;
            }

         }
         else
         {

                 if(currentExt == objExt) {
                   return true;
                 } else {
                   alert("Il file che stai cercando di caricare non è conforme al tipo di documento previsto per questa casella.\nPuoi caricare nella casella corrente documenti con estensione [ " + objExt + "]");
                   objFile.focus();
                   return false;
                 }
          }
}

function bandireloadpage() {
  document.form.submit();
}

function modify(bando,azione) {
  oggetto_form = eval("document.form" + bando);
  oggetto_form.azione.value = azione;
  oggetto_form.submit();
}


function CofermaEliminaBando(bando,azione) {
  oggetto_form = eval("document.form" + bando);
  oggetto_form.azione.value = azione;
  conferma = confirm("Sei sicuro di voler eliminare questo dato?");
  if(conferma == true) {
    oggetto_form.submit();
  } else {
    return false;
  }
}

function setAzione(azione) {
  valore = controllo_anagrafica_p();
  if(valore == true) {
     document.form.azione.value = azione;
     document.form.submit();
  }
}

function setAzione2(pID,pAzione){
  // document.location.href="template.php?pag=36&azione="+action+"&id_nota="+id_nota+"&id="+id;
   document.form.azione.value = pAzione;
   document.form.id_nota.value = pID;
   document.form.submit();
}

function setAzione_basic(id, azione) {
  document.form.id_elemento.value = id;
  document.form.azione.value = azione;
  document.form.submit();
}

function setAzioneNoCheck(azione) {
  document.form.azione.value = azione;
  document.form.submit();
}

function setAzioneParam(id, azione) {
  document.form.id_elemento.value = id;
  document.form.azione.value = azione;
  if (azione=="del_lista")  {
    var ok;
        ok=confirm("Vuoi davvero eliminare il documento?");
          if (ok==true){
            document.form.submit();
          }
   }else{
     document.form.submit();
   }
}

function tornaHP() {
  document.form.azione.value = "";
  document.form.submit();
}

function Check() {
  for(x=1;x<9;x++) {
    oggetto_file = eval("document.form." + document.form.field_name.value + "_" + x);
        oggetto_check = eval("document.form.del_" + x);
        if(oggetto_file != null) {
          if(oggetto_file.value.length > 0) {
             if(oggetto_check != null) {
                   oggetto_check.checked = false;
                  }
           }
        }
  }
}

//**********FUNZIONE PER LA RICERCA SUL SITO***************//

/*********************************************************
/*****Controllo che il campo contenga solo lettere, numeri, apice singole, spazzi*********
/*********************************************************/
function controlla_solo_lettnum(pTesto, pCampo){
     var i, valore;
     valore = "true"
     for(i=0;i < pTesto.value.length;i++){
        if( pTesto.value.charCodeAt(i)!=32 &&
            pTesto.value.charCodeAt(i)!=39 &&
            pTesto.value.charCodeAt(i)< 48 ||
            pTesto.value.charCodeAt(i)> 57 &&
            pTesto.value.charCodeAt(i)< 65 ||
            pTesto.value.charCodeAt(i)> 90 &&
            pTesto.value.charCodeAt(i)< 97 ||
            pTesto.value.charCodeAt(i)>122 &&
            pTesto.value.charCodeAt(i)<128 ||
            pTesto.value.charCodeAt(i)>155 &&
            pTesto.value.charCodeAt(i)<160 ||
            pTesto.value.charCodeAt(i)>165 &&
                        pTesto.value.charCodeAt(i)<224 ||
            pTesto.value.charCodeAt(i)>240 &&
                        pTesto.value.charCodeAt(i)!=249 &&
                        pTesto.value.charCodeAt(i)!=242){

              vTxtMsg = genera_msg(pCampo,"3", pTesto.value.substring(i,i+1));
             alert(vTxtMsg);
             pTesto.select();
                         valore = "false";
                   break
         }
      }
    if (valore == "false"){
     return false;
    }else{
         return true;
    }
}




//----------------------------------------------------------------------------------------

function unsubscribe()

{
    var ok          //--email obbligatoria---//
    ok=controlla_campo_obbligatorio(document.form.email,"E-Mail");
   if(ok==true){ok=chkmail(document.form.email, "E-Mail")};
   if(ok==true){document.form.submit()};

  }

//per il motore di ricerca
//------IL NOME DEL FORM E' STATO VOLONTARIAMENTE INDICATO DIVERSAMENTE
//------X NON CREARE CONFLITTO NEL FRONT-END QUANDO VIENE UTILIZZATO
//------IL MODUL0 DELLA MAILING-LIST
function controllo_ricerca(){
    var ok;
    ok=controlla_campo_obbligatorio(document.form1.ricerca, "ricerca");
    if(ok==true){ok=controllodimcampo(document.form1.ricerca, "ricerca", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form1.ricerca, "ricerca")};
    if(ok==true){ok=controlla_solo_lettnum(document.form1.ricerca, "ricerca")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form1.ricerca, "ricerca")};
    if(ok==true){
         document.form1.submit();
        } else {
         return false;
        }
}

//per il menu di sinistra dinamico
         var curPop = null;

         function clearCurrent() {
            // Hide the pop-up menu that is currently displayed.
            if (null != curPop)
               curPop.style.display = "";
            curPop = null;
         }

         function popup() {
            var el = event.srcElement;
            clearCurrent();
            // Display a new menu option.
            if (("P" == el.tagName) && ("menu" == el.parentElement.id)){
               // Position and display the pop-up menu.
               var elpop = document.all[el.sourceIndex + 1];
               elpop.style.pixelLeft = document.all.menu.offsetLeft + document.all.menu.offsetWidth - 7;
               elpop.style.pixelTop  = el.offsetTop + document.all.menu.offsetTop;
               elpop.style.display = "block";
               curPop = elpop;
            }
            event.cancelBubble = true;
         }

         function highlight() {
            // Highlight the menu options.
            if (null != event.fromElement)
               if ((event.fromElement.tagName == "P") && (event.fromElement.parentElement.id == "menu")) event.fromElement.className = "";
            if (null != event.toElement)
                if ((event.toElement.tagName == "P") && (event.toElement.parentElement.id == "menu")) event.toElement.className = "over";
         }

         
         function  checkFormCommissioni(){
		    ok=controlla_campo_obbligatorio(document.form.txtNomeCommissione, "Nome della commissione");
		    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.txtNomeCommissione, "Nome della commissione")};
		    if(ok==true){ok=controlla_caratteri(document.form.txtNomeCommissione, "Nome della commissione", "4")};
		    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.txtNomeCommissione, "Nome della commissione")};         	

		    if(ok==true){ok=controlla_campo_obbligatorio(document.form.txtPresidente, "Presidente")};
		    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.txtPresidente, "Presidente")};
		    if(ok==true){ok=controlla_caratteri(document.form.txtPresidente, "Presidente", "4")};
		    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.txtPresidente, "Presidente")};         			    
			
		    if(ok==true){document.form.submit();}
		 }

         function popup2(sezione){
           var i;
           var tot_elem=document.all.menu.childNodes.length;
           if(sezione!=0){
                   for(i=0;i<=tot_elem;i++){
                      if((document.all.menu.childNodes.item(i).tagName=="P") && (document.all.menu.childNodes.item(i).id==sezione)){
                      //alert(document.all.menu.childNodes.item(i).id);
                       document.all.menu.childNodes.item(i).click();
                       return false;
                    }
                 }
          }
         }




