

/******************FUNZIONI DI CONTROLLO**********************

//***************************************************/
/******************Confronta due orari**************
//****************************************************/

function confronta_orari(pOra1, pOra2, pMin1, pMin2, pCampo){
var vOra1, vOra2, vMin1, vMin2
        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("Zgjidhni oraret saktė.");
                return false;
        }
        //        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("Orari nuk ėshtė i saktė.");
                        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", "Orari i pėrfundimit.");
                alert(vTxtMsg);
                //alert("Orari nuk ėshtė i saktė.");
                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
        if (Number(pData) < Number(vDataOdierna)){
                vTxtMsg = genera_msg(pCampo, "6", "soēme");
                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
		
        if (Number(pData) > Number(vDataOdierna)){
                vTxtMsg = genera_msg(pCampo, "61", "soēme");
                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;
        }
}

function controlla_numerico_intero(pNr, pCampo){
        var vSpazio;
        var vStringa;
        var vTxtMsg;

        vSpazio = pNr.value.indexOf(" ");
		vPunto= pNr.value.indexOf(".");
		vVirgola= pNr.value.indexOf(",");
        if(isNaN(pNr.value) || (pNr.value=="") || vSpazio>=0 || vPunto>=0 || vVirgola>=0) {
                vTxtMsg = genera_msg(pCampo, "22");
                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 == 9 || 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", "e fushės "+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("Gabim nė fushėn Password:\n duhet tė pėrdorni tė paktėn 5 karaktere");
          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("Pėr tė pėrfituar shėrbimin, ėshtė e nevojshme qe ju tė pranoni ligjin mbi tė dhėnat private");
         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){
   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", "hapėsirė");
                                 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("Tė paktėn njė ["+desc+"] duhet tė jetė zgjedhur");
  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("Tė paktėn njė ["+desc+"] duhet tė jetė zgjedhur");
  return false;
 }else{
  return true;
}
}

/**********************************************************************************************
/*******************function per la webmail***********************************
/***********************************************************************************************/
function controlla_combo_domanda_webmail(){
        if(document.form.id_domanda.value==0){
            alert("Duhet tė plotėsosh fushėn e pyetjes");
             return false;
        }else{
              return true;
        }
}
function controlla_combo_occupazione_webmail(){
        if(document.form.occupazione.value==0){
            alert("Duhet tė plotėsosh fushėn e profesionit");
             return false;
        }else{
              return true;
        }
}
function controlla_combo_settore_webmail(){
        if(document.form.settore.value==0){
            alert("Duhet tė plotėsosh fushėn e sektorit");
             return false;
        }else{
              return true;
        }
}

function confronta_password(){
  if(document.form.pwd.value!=document.form.conf_pwd.value){
     alert("Konfirmimi i kodit ėshtė i gabuar");
     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="pranohen vetėm vlera numerike.";
                        break;
                case "2":
                        vTipoErr="formati jo i rregullt "+pStringa+".";
                        break;
                case "3":
                        vTipoErr="karakteri [" + pStringa + "] nuk lejohet.";
                        break;
                case "4":
                        vTipoErr="dita [" + pStringa + "] nuk ėshtė e vlefshme pėr muajin e futur.";
                        break;
                case "5":
                        vTipoErr="viti [" + pStringa + "] nuk ėshtė i brishtė.";
                        break;
                case "6":
                        vTipoErr="data e dhėnė nuk mund tė jetė mėparė datės "+pStringa;
                        break;
				case "61":
                        vTipoErr="data e dhėnė nuk mund tė jetė mėpas datės "+pStringa;
                        break;		
                case "7":
                        vTipoErr="e dhėnė e detyruar.";
                        break;
                case "8":
                        vTipoErr="numri minimal i karaktereve ėshtė " + pStringa + ".";
                        break;
                case "9":
                        vTipoErr="karakteri i parė nuk mund tė jetė hapsirė apo thonjėz [']";
                        break;
                case "10":
                        vTipoErr="nuk lejohen ["+pStringa+"] tė vazhdueshėm.";
                        break;
                case "11":
                        vTipoErr="vendosni HTTP:// pėrpara emrit tė sitit web";
                        break;
                case "12":
                        vTipoErr="mungon karakteri [" +pStringa+ "].";
                        break;
                case "13":
                        vTipoErr="karakteri i parė nuk mund tė jetė ["+pStringa+"].";
                        break;
                case "14":
                        vTipoErr="lejohet vetėm njė karakter ["+pStringa+"].";
                        break;
                case "15":
                        vTipoErr="Prapashtesa (es: .it,.com) nuk ėshtė e rregullt ose mungon.";
                        break;
                case "16":
                        vTipoErr="verifikoni prapashtesėn, shkaqe tė mundshme \n1. Mungon karakteri[.]\n2. Prapashtesa shume e gjatė";
                        break;
                case "17":
                        vTipoErr="nuk lejohen karakteret [@] dhe/ose [.] te vazhdueshėm.";
                        break;
                case "18":
                        vTipoErr="data nuk ėshtė e vlefshme.";
                        break;
                case "19":
                        vTipoErr="madhėsia e prefiksit e papranueshme";
                        break;
                case "20":
                        vTipoErr=pStringa+" e papranueshme.";
                        break;
                case "21":
                        vTipoErr="Orari i zgjedhur nuk mund te paraprijė ose tė jetė i barabartė me orarin e zgjedhur"+pStringa;
                        break;
			    case "22":
                        vTipoErr="lejohen vetem numra tė plotė.";
                        break;

        }

        return vTxtMsg="Gabim nė fushėn "+pCampo+":\n"+vTipoErr;
}

//*************************************************************************************************
//***************FUNZIONE PER L'APERTURA DELLA POPUP PER AIUTO PER IL FORMATO DEI TESTI****************
//*************************************************************************************************/
function open_aiuto(){
window.open('aiuto.php', 'Ndihma', 'width=400,height=400,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, 'Ndihma', 'width=450,height=400,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}
function open_aiuto_s(){
window.open('popup/aiuto_s.php', 'Ndihma', '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', 'Ndihma', 'width=400,height=400,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}
function open_aiuto_editor(){
window.open('aiuto_editor.php', 'Ndihma Botuesi tekstit', 'width=400,height=200,top=250,left=250,resizable=no,status=no,location=no,toolbar=no,scrollbars');
}
function open_aiuto_editor2(){
window.open('popup/aiuto_editor.php', 'Ndihma Botuesi tekstit', 'width=400,height=200,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 = "popup/popup_orario_servizio.inc.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 dell'angrafica******************
*****************************************************************************************/
function anagraficabreve(idanagrafica,id){
  window.open("popup/padre_anagraficabreve.php?id="+id+"&idanagrafica="+idanagrafica+"","anagraficabreve","width=520, height=380");
}
function anagraficabreve_digital(idanagrafica,id){
  window.open("popup/anagraficabrevedigital.php?id="+id+"&idanagrafica="+idanagrafica+"","anagraficabreve","width=400, height=400");
}
//**************************************************************************************************************************
//****************************funzione per il page editor (pagine aggiuntive)***********************************************
//**************************************************************************************************************************
function validate_page_editor(){
 if(document.pagina.intestazione.value==''){
  alert("Nuk ke futur titullin e faqes");
  return false;
 }
}

 //------------------------  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("Nuk mund te futesh diten [ " + giorno + " ] per muajin e futur.");
                        return 1;
                }
                if(giorno == 31 && (mese == 11 || mese == 04 || mese == 06 || mese == 9 || mese==02 )) {
                        alert("Nuk mund te futesh diten [ " + giorno + " ] per muajin e futur.");
                        return 1;
                } else {
                        if(giorno == 29 && mese == 02 && anno.substring(2,4) == 00 && (anno.substring(0,2)%4 != 0)) {
                                alert("Viti [ " + anno + " ] nuk eshte i brishte.");
                                return 1;
                        } else {
                                if(anno%4 != 0 && giorno == 29 && mese == 02) {
                                        alert("Viti [ " + anno + " ] nuk eshte i brishte.");
                                        return 1;
                                } else {
                                        return 0;
                                }
                        }
                }
        }


function RadioButtonSystem(stato,numero) {
//***********messaggi_cs_form.inc.php
  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("Je i sigurte qe deshiron ta eleminosh mesazhin e zgjedhur?\nKy veprim nuk mund te anullohet.");
   if(conferma == true) {
       document.location.href = url;
    }
}

function ConfermaElimina(url,var_testo) {

 conferma = confirm("Je i sigurt qe deshiron ta eleminosh "+var_testo+" e zgjedhur?");
 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("Duhet te zgjedhesh nje link");
          return false;
        } else if(document.contenuto_paragrafo.link_esterno.value.substring(0,7)!="http://" & document.contenuto_paragrafo.link_interno.value==0){
          alert("Nje link i jashtem duhet te filloje me '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=='' || document.contenuto_paragrafo.elements[i].value.substring(0).charCodeAt()==32){
                 if(document.contenuto_paragrafo.elements[i].name=="userfile"){
                   if(img_esiste==0){
                        alert("Duhet te futesh nje imazh");
            		    return false;
                   }
                 } else {
					 if(document.contenuto_paragrafo.elements[i].value==''){
		 			    alert("Duhet te plotesosh fushen "+document.contenuto_paragrafo.elements[i].name);
        			    return false;
		 			 } else { //caso dello spazio  come primo carattere
						alert("Nuk mund te futesh nje hapesire si karakterin e pare te fushes "+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 ("Duhet te futesh nje imazh");
                           return false;
                         }
                    } else {
            		   if(document.contenuto_paragrafo.elements[i].value==''){
		 			     alert("Duhet te plotesosh fushen "+document.contenuto_paragrafo.elements[i].name);
        			     return false;
		  			  } else { //caso dello spazio  come primo carattere
						 alert("Nuk mund te futesh nje hapesire si karakterin e pare te fushes "+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');
}

//**********************************************************************************
//***************************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){    /* 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_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("Skedari qe po kerkon te ngarkosh nuk pershtatet me tipin e dokumentave te percaktuara per kete kategori.\nNe kategorine aktuale mund te ngarkosh dokumenta me prapashtesen [ " + 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("Je i sigurte qe deshiron ta eleminosh kete te dhene?");
  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("Je i sigurte qe deshiron ta eleminosh dokumentin?");
          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
function controllo_ricerca(){
    var ok;
    ok=controlla_campo_obbligatorio(document.form.ricerca, "ricerca");
    if(ok==true){ok=controllodimcampo(document.form.ricerca, "ricerca", 0)};
    if(ok==true){ok=primo_carattere_nospace_noapice(document.form.ricerca, "ricerca")};
    if(ok==true){ok=controlla_solo_lettnum(document.form.ricerca, "ricerca")};
    if(ok==true){ok=no_spazio_apici_consecutivi(document.form.ricerca, "ricerca")};
    if(ok==true){
	
         document.form.submit();
        } else {
         return false;
        }
}

		 
//*********************************************************
//*FUNZIONI PER I PRODOTTI BACK END***************************
//*********************************************************
//PER IL MOTORE DI RICERCA
function carica_pagina(){
  //se c'č il param scat o cat nell'url, vuol dire che si ricarica la pagina per ua ricerca per criteri
  var url=String(document.location);
  if(url.indexOf('cat')==-1 & url.indexOf('scat')==-1){
    document.cerca_prod.tipo_ricerca[0].checked=true;
	set_visibilita('libera');
	set_radio('libera');
  } else {
    document.cerca_prod.tipo_ricerca[1].checked=true;
	set_visibilita('criteri');
	set_radio('criteri');
  }  
}

function set_visibilita(tipo_ricerca){  
 for(i=0;i<document.cerca_prod.elements.length-1;i++){
  if(document.cerca_prod.elements[i].name!="tipo_ricerca"){
 	 if(tipo_ricerca=="libera"){
		 if(document.cerca_prod.elements[i].name!="ricerca_prod"){
		   document.cerca_prod.elements[i].disabled=true;
		 } else {
		   document.cerca_prod.elements[i].disabled=false;
		 } 
 	 } else {   
		 if(document.cerca_prod.elements[i].name!="testo_libero"){
	 		document.cerca_prod.elements[i].disabled=false;
	 	} else {
	 		document.cerca_prod.elements[i].disabled=true;
	 	}     
  	 }
  }
 }
}

function set_radio(tipo_ricerca){
 if(tipo_ricerca=="libera"){
  if(document.cerca_prod.tipo_ricerca[0].checked==false){
   document.cerca_prod.tipo_ricerca[0].checked=true;
  }
 } else {
   if(document.cerca_prod.tipo_ricerca[1].checked==false){
   document.cerca_prod.tipo_ricerca[1].checked=true;
   }
 }
}

function change_cat(id_session,prd,filtro){
 var id_cat=document.scheda_prodotto.categoria.value;
 if(prd == "")	 document.location="template.php?pag=25&id="+id_session+"&cat="+id_cat+"&filtro="+filtro; 
 else	document.location="template.php?pag=25&id="+id_session+"&cat="+id_cat+"&prd="+prd+"&filtro="+filtro; 
}
function change_scat(id_session,prd,filtro){
 var id_cat=document.scheda_prodotto.categoria.value;
 var id_scat=document.scheda_prodotto.sotto_categoria.value;
 if(prd == "") document.location="template.php?pag=25&id="+id_session+"&cat="+id_cat+"&scat="+id_scat+"&filtro="+filtro;
 else	document.location="template.php?pag=25&id="+id_session+"&cat="+id_cat+"&scat="+id_scat+"&prd="+prd+"&filtro="+filtro;
}

function change_cat_fatt(id_session,prd,filtro){
 var id_cat=document.scheda_prodotto.categoria.value;
 if(prd == "")	 document.location="template.php?pag=100114&id="+id_session+"&cat="+id_cat+"&filtro="+filtro; 
 else	document.location="template.php?pag=100114&id="+id_session+"&cat="+id_cat+"&prd="+prd+"&filtro="+filtro; 
}
function change_scat_fatt(id_session,prd,filtro){
 var id_cat=document.scheda_prodotto.categoria.value;
 var id_scat=document.scheda_prodotto.sotto_categoria.value;
 if(prd == "") document.location="template.php?pag=100114&id="+id_session+"&cat="+id_cat+"&scat="+id_scat+"&filtro="+filtro;
 else	document.location="template.php?pag=100114&id="+id_session+"&cat="+id_cat+"&scat="+id_scat+"&prd="+prd+"&filtro="+filtro;
}

//-----MODIFICA EFFETTUATA DA A.FERRARA 17-07-03
//-----FUNZIONE RICHIAMATA DALLA SELECT DI FRONT END
function change_cat_fe(par_id_pag){
	var id_cat=document.cerca_prod.categoria.value;
	document.location="/template.php?pag="+par_id_pag+"&tipo_ricerca=criteri&cat="+id_cat;
}


//-----MODIFICA EFFETTUATA DA A.FERRARA 17-07-03
//-----FUNZIONE RICHIAMATA DALLA SELECT DI FRONT END
function change_scat_fe(par_id_pag)
{
	var id_cat=document.cerca_prod.categoria.value;
 	var id_scat=document.cerca_prod.sottocategoria.value;
 	document.location="/template.php?pag="+par_id_pag+"&tipo_ricerca=criteri&cat="+id_cat+"&scat="+id_scat;
}

//-----MODIFICA EFFETTUATA DA M.PANZERI 06-08-03
//-----FUNZIONE RICHIAMATA DALLA SELECT DI BACK END
function change_cat_be(id_pag,id){
	var id_cat=document.cerca_prod.categoria.value;
	document.location="template.php?pag="+id_pag+"&tipo_ricerca=criteri&cat="+id_cat+"&id="+id;
}


//-----MODIFICA EFFETTUATA DA M.PANZERI 06-08-03
//-----FUNZIONE RICHIAMATA DALLA SELECT DI BACK END
function change_scat_be(id_pag,id)
{
	var id_cat=document.cerca_prod.categoria.value;
 	var id_scat=document.cerca_prod.sottocategoria.value;
 	document.location="template.php?pag="+id_pag+"&tipo_ricerca=criteri&cat="+id_cat+"&scat="+id_scat+"&id="+id;
}




//-----MODIFICA EFFETTUATA DA A.FERRARA 17-07-03
//-----FUNZIONE RICHIAMATA DAL BUTTON DI FRONT END & BACK END

function validate()
{
	var ok="";
	
	if((document.cerca_prod.tipo_ricerca[0].checked==false)&&(document.cerca_prod.tipo_ricerca[1].checked==false))
	{
		alert("Zgjidh nje nga dy menyrat e kerkimit.");
		return false;
	}

	if(document.cerca_prod.tipo_ricerca[0].checked == true)
	{
		ok=primo_carattere_nospace_noapice(document.cerca_prod.testo_libero,"Testo libero");
	}
	else
	{
		ok=primo_carattere_nospace_noapice(document.cerca_prod.codice,"Codice");
		if(ok){ok=primo_carattere_nospace_noapice(document.cerca_prod.nome,"Nome prodotto");}		
	}

	if (ok)
	{
		if(document.cerca_prod.tipo_ricerca[0].checked==true)
		{
			if(document.cerca_prod.testo_libero.value=="")
			{
				alert("Ke zgjedhur te besh nje kerkim te lire,\rduhet te plotesosh fushen Tekst.");
				document.cerca_prod.testo_libero.focus();
				return false;
			}
		} 
		else 
		{
			var scelta=0;
			for(i=3;i<document.cerca_prod.length-1;i++)
			{ 
				//ciclo sui campi della parte della ricerca per criteri per sapere se č stao compilato al meno un campo
				if(document.cerca_prod.elements[i].value!="" & document.cerca_prod.elements[i].value!=0)
				{
					scelta=1;
				}
			}
		}
		
		if(scelta==0)
		{
			alert("Ke zgjedhur te besh nje kerkim ne baze te kritereve,\rduhet te plotesosh te pakten nje prej fushave.");
			document.cerca_prod.codice.focus();
			return false;
		}  
	}
	else
	{ 
		return false;
	}
}


function control_numeri(a){
var num_virgola=0;
 for(i=0;i<document.cerca_prod.elements[a].value.length;i++){ 
   n=document.cerca_prod.elements[a].value.charCodeAt(i);       
   if(n>57 || (n<48 & n!=44)){ //se non č un numero o una virgola    
    alert("Fut vetem numra per "+document.cerca_prod.elements[a].name+".\r Ndaresi i dhjetoreve duhet te jete presje.\rNuk duhet te futesh hapesira ose pika.");	
	return false;
	exit();
   }   
   if(n==44){ //devo controllare che ce ne sia solo una
   num_virgola=num_virgola+1;     
   var pos_virgola=i;    
	if(num_virgola>1){	  
	   alert("Ke futur "+num_virgola+" presje ne fushen "+document.cerca_prod.elements[a].name+"...");
   	   document.cerca_prod.elements[a].focus();
	   return false;	   
	} 
  } 

 }
  if(num_virgola==1){   
   var num_decimali=document.scheda_prodotto.elements[a].value.length-pos_virgola-1;   
    if(num_decimali>2 || num_decimali==0){
	  alert("Fut 2 shifra pas presjes ne fushen "+document.scheda_prodotto.elements[a].name);
	  document.scheda_prodotto.elements[a].focus();	
	  return false;	 
	}    
  }
  
}		 

//PER la PAGINA DELLA GESTIONE DEI PRODOTTI

function order_list(id_session,tipo_pag,order,limit,filtro){ 
  if(limit=="no"){
 document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&ord="+order+"&filtro"+filtro;
 } else {
 document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&ord="+order+"&limit="+limit+"&filtro"+filtro;
 }
}

	 
function limit_list_inf(id_session,tipo_pag,limit,order,filtro){  
 if(order==0 & limit=="no"){   
   document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&filtro"+filtro;
 } else if(order==0 & limit!="no"){
 document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&limit="+limit+"&filtro"+filtro;
 } else if(order!=0 & limit=="no"){
  document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&ord="+order+"&filtro"+filtro;
 } else if(order!=0 & limit!="no"){
   document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&ord="+order+"&limit="+limit+"&filtro"+filtro;

 }
}	

function limit_list(id_session,tipo_pag,limit,order,filtro){  
 if(order==0){   
   document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&limit="+limit+"&filtro"+filtro;
 } else{
   document.location="template.php?pag=14&id="+id_session+"&tipo_pag="+tipo_pag+"&ord="+order+"&limit="+limit+"&filtro"+filtro;

 }
}	

function validate_scheda_prodotto(img_esiste){

	save_in_textarea_all();
  var decimali=0; //var che mi serve per sapere se č un numero con decimali o no, e pi controllare che ci siano solo 2 decimali
  var tot_elem=document.scheda_prodotto.elements.length; 
  for(i=0;i<=(tot_elem-6);i++){       
    if(document.scheda_prodotto.elements[i].name!="img_cancel"){  //nessun controllo su questo campo,
      if(document.scheda_prodotto.elements[i].name=="userfile"){
      //
	    } else{ //controllo che i campi siano compilati
        if(document.scheda_prodotto.elements[i].name!='userfile2'){ //tranne per il campo userfile2
          if(document.scheda_prodotto.elements[i].value=='' && (document.scheda_prodotto.elements[i].name=='categoria'  || document.scheda_prodotto.elements[i].name=='codice' || document.scheda_prodotto.elements[i].name=='nome')){
            alert("duhet te plotesosh fushen "+document.scheda_prodotto.elements[i].name);
            //document.scheda_prodotto.elements[i].focus();
            return false;	
          }
        } 	
      }
    }
  }  
  if(document.scheda_prodotto.prezzo.value=='' || document.scheda_prodotto.prezzo_imprenditori.value=='' || document.scheda_prodotto.prezzo_ristoranti.value=='' ){
    //alert("devi compilare il prezzo");
    //return false;
  }
  
  if(isNaN(MoneyValue(document.scheda_prodotto.prezzo.value))  ||  isNaN(MoneyValue(document.scheda_prodotto.prezzo_imprenditori.value)) || isNaN(MoneyValue(document.scheda_prodotto.prezzo_ristoranti.value)) ){
    alert("ēmimi duhet te jete vlere numerike");
    return false;
  }
  //document.scheda_prodotto.submit();
  return true;
}	

////////////////////////////
	// MoneyValue
	//
	// SCOPO: Ottenere il valore numerico reale del valore monetario inserito
	// INPUT:
	//		- strValue: valore da calcolare
	// OUTPUT:
	//		- [double]: valore reale ottenuto
	//		- 0: ci sono stati dei problemi o č effettivamente 0
	// FUNZIONAMENTO: 
	//		- questa funzione č in grado di formattare in moneta valori monetari gią formattati
	//		  valori numerici interi e valori numerici reali (con il puntino!)
	//		- se il valore da formattare non č valido ritorna una stringa vuota
	//		- ritorna un valore formattato solo se ha un senso
	function MoneyValue (strValue)
	{
	
		// controllo... se non č una stringa allora la faccio diventare una stringa...
		if(typeof(strValue) == "number")
			strValue = strValue.toString();
		else if(typeof(strValue) != "string")		
			return "";

		// controllo... puņ avere lunghezza zero...
		if(strValue.length == "") 
			return 0;

		// controllo...se si tratta effettivamente di un valore monetario...
		if(strValue.indexOf(",") >= 0) {			
			strValue = ReplaceString(strValue, ".", "");
			strValue = ReplaceString(strValue, ",", ".");
		}
		
		// vedo se si tratta di un numero valido...
		return strValue;
	}
	
	////////////////////////
	// ReplaceString
	//
	// data ultima modifica : 30/04/2003
	//
	// SCOPO : effettuare la replace di tutte le stringhe che trova
	// OUTPUT : stringa modificata
	// OCCHIO... equivalente lato Server 'ReplaceString()'
	function ReplaceString (strOriginal, strFind, strPlace) 
	{
		// VARIABILI	
		var strResult = "";
		//var n = strOriginal.search(strFind);
		var n = strOriginal.indexOf(strFind);
			
		// controllo...
		if(n < 0)
			return strOriginal;
			
		while(n >= 0) {
			
			strResult += strOriginal.substring(0, n);
			strResult += strPlace;
			
			strOriginal = strOriginal.substr(n + strFind.length);

			//n = strOriginal.search(strFind);
			n = strOriginal.indexOf(strFind);
				
			// controllo...
			if(n < 0)
				strResult += strOriginal;
				
		}
			
		return strResult;
		
	}	 
    
   


