var consonanti = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
var numeri = "0123456789";
var curricula = document.getElementById('curricula');

window.onload = function() { 
  if (document.getElementById('Tabella1')) { document.getElementById('Tabella1').style.display = "none"; }
  if(!curricula) curricula = document.getElementById('curricula');
}

/************************************ NON TOCCARE *************************************/
function CalcolaCodiceFiscaleRidotto(Cognome, Nome) {
    var PrimaParteCF = "";
    if (Cognome != "" && Nome != "") {
        CognomeCodificato = CalcolaCognome(Cognome);
        NomeCodificato = CalcolaNome(Nome);
        PrimaParteCF = CognomeCodificato + NomeCodificato;
    }
    return PrimaParteCF.toUpperCase();
}

function CalcolaCognome(Cognome) {
    var code = "";
    code = GetConsonanti(Cognome);
    if (code.length >= 3) {
        code = code.substring(0, 3);
    }
    else {
        code += GetVocali(Cognome).substring(0, 3 - code.length)
        if (code.length < 3)
            for (var i = code.length; i < 3; i++)
            code += "X";
    }
    return code.toUpperCase();
}

function CalcolaNome(Nome) {
    var code = "";
    cons = GetConsonanti(Nome);
    if (cons.length > 3)
        code = cons.substring(0, 1) + cons.substring(2, 3) + cons.substring(3, 4);
    else
        if (cons.length == 3)
        code = cons;
    else {
        code = cons + GetVocali(Nome).substring(0, 3 - cons.length);
        if (code.length < 3)
            for (var i = code.length; i < 3; i++)
            code += "X";
    }
    return code.toUpperCase();
}

function GetConsonanti(Stringa) {
    var cns = "";
    for (var i = 0; i < Stringa.length; i++)
        if (consonanti.indexOf(Stringa.substring(i, i + 1)) != -1)
        cns += Stringa.substring(i, i + 1);
    return cns.toUpperCase();
}

function GetVocali(Stringa) {
    var voc = "";
    for (var i = 0; i < Stringa.length; i++)
        if (consonanti.indexOf(Stringa.substring(i, i + 1)) == -1 && Stringa.substring(i, i + 1) != " ")
        voc += Stringa.substring(i, i + 1);
    return voc.toUpperCase();
}

function isNumber(number) {
    var myRE = new RegExp('^[0-9]+$', 'gi');
    var isAllNumber = myRE.test(number);
    return (isAllNumber);
}

function verificaMail(e_mail) {
    return (e_mail.match(/\b(^(\S+@).+((\..{2,4}))$)\b/gi));
}

function getYear(campo) {
    var strYear;
    var indice;
    var indice1;

    indice = campo.indexOf("/");
    if (indice == -1)
        return 0;

    indice1 = campo.indexOf("/", indice + 1);
    if (indice1 == -1)
        return 0;

    strYear = campo.substr(indice1 + 1, campo.length - 1);

    if (!isNumber(strYear))
        return 0;

    return parseInt(strYear, 10);
}

function verificaMail(e_mail) {
    return (e_mail.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,4}))$)\b/gi));
}

function verificaCodFisc(cod_fiscale, Cognome, Nome) {
    cod_fiscale = cod_fiscale.toUpperCase();
    var CFR = CalcolaCodiceFiscaleRidotto(Cognome, Nome).toUpperCase();
    var goodCFR = (CFR == cod_fiscale.substr(0, 6));
    var regExpMatch = cod_fiscale.match(/\b(^([a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1})$)\b/gi);
    return (goodCFR && regExpMatch);
}

function checkData(campo) {
    var strDay;
    var strMonth;
    var strYear;
    var indice;
    var indice1;

    indice = campo.indexOf("/");

    if (indice == -1)
        return false;

    strDay = campo.substr(0, indice);
    if (!isNumber(strDay))
        return false;

    indice1 = campo.indexOf("/", indice + 1);
    if (indice1 == -1)
        return false;

    strMonth = campo.substr(indice + 1, indice1 - (indice + 1));

    if (!isNumber(strMonth))
        return false;

    strYear = campo.substr(indice1 + 1, campo.length - 1);

    if (!isNumber(strYear))
        return false;

    var objData = new Date(parseInt(strYear, 10), parseInt(strMonth, 10) - 1, parseInt(strDay, 10));

    if (isNaN(objData))
        return false;

    if ((parseInt(strYear, 10) != objData.getFullYear()) || ((parseInt(strMonth, 10) - 1) != objData.getMonth()) || (parseInt(strDay, 10) != objData.getDate()))
        return false;

    return true;
}

function checkPeriodo(campo) {
    var strMonth;
    var strYear;
    var indice;

    indice = campo.indexOf("/");
    if (indice == -1)
        return false;

    strMonth = campo.substr(0, indice);
    if (!isNumber(strMonth))
        return false;

    strYear = campo.substr(indice + 1, campo.length - 1);
    if (!isNumber(strYear))
        return false;

    var objData = new Date(parseInt(strYear, 10), parseInt(strMonth, 10) - 1);

    if (isNaN(objData))
        return false;

    if ((parseInt(strYear, 10) != objData.getFullYear()) || ((parseInt(strMonth, 10) - 1) != objData.getMonth()))
        return false;

    return true;
}


function checkForm(myform) {
    myform = document.getElementsByClassName('IN');
    var i;
    var error_text = "";

    var error_mandatory = "";
    var error_mandatory_count = 0;

    var error_date = "";
    var error_date_count = 0;

    var error_number = "";
    var error_number_count = 0;

    for (var i = 0; i < myform.length; i++) {
        var description = myform[i].description;
        var mandatory = myform[i].mandatory;
        var datatype = myform[i].datatype;
        var type = myform[i].type;
        var value = myform[i].value;

        if (type == 'checkbox') {
            var check = myform[i].checked;

            if (check == true)
                value = "on";
            else
                value = "";
        }

        if (mandatory == 'true' && value == "") {
            error_mandatory_count++;
            error_mandatory += "   " + description + "\n";
        }

        if (datatype == 'date' && value != "") {
            if (!checkData(value)) {
                error_date_count++;
                error_date += "   " + description + "\n";
            }
        }

        if (datatype == 'periodo' && value != "") {
            if (!checkPeriodo(value)) {
                error_date_count++;
                error_date += "   " + description + "\n";
            }
        }

        if (datatype == 'integer' && value != "") {
            if (!isNumber(value)) {
                error_number_count++;
                error_number += "   " + description + "\n";
            }
        }
    }

    if (error_mandatory_count > 0) {
        if (error_mandatory_count == 1)
            error_text = "Il campo\n" + error_mandatory + "&egrave; obbligatorio";
        else
            error_text = "I campi\n" + error_mandatory + "sono obbligatori";
        error_text += "\n\n";
    }

    if (error_date_count > 0) {
        if (error_date_count == 1)
            error_text += "Il campo\n" + error_date + "contiene una data errata";
        else
            error_text += "I campi\n" + error_date + "contengono una data errata";
        error_text += "\n\n";
    }

    if (error_number_count > 0) {
        if (error_number_count == 1)
            error_text += "Il campo\n" + error_number + "contiene un valore non numerico";
        else
            error_text += "I campi\n" + error_number + "contengono un valore non numerico";
        error_text += "\n\n";
    }

    if ((error_mandatory_count + error_date_count + error_number_count) > 0)
        return error_text;

    return null;
}

function anno_conseguimento(anno) {
    if (!isNumber(anno))
        return false;
    var objData = new Date(parseInt(anno, 10));
    if (isNaN(objData))
        return false;
    if (parseInt(anno, 10) == objData.getFullYear())
        return false;
    return true;
}

function mese_conseguimento(mese) {

    try {
        parseInt(mese, 10)
        if (mese <= 12 && mese >= 1) {
            return true;
        }
        return false;
    }
    catch (Exception) {
        return false;
    }

}

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    //else 
    //countfield.value = maxlimit - field.value.length;
}

function annulla() {
    if (confirm("Cancellare tutti i Campi?")){
      //~ curricula.reset();
      var inputs = document.getElementsByClassName('IN');
      for(var x=0; x<inputs.length; x++){inputs[x].value = "";}
    }
}

function Count() {
    var contck = 0;
    //~ var countfin = 0;
    //~ if (!(curricula.disable)) { contck = 0; } else if ((!(curricula.disable.length)) && (curricula.disable.checked == true)) { countfin = 1; contck = 1; }
    //~ else if ((!(curricula.disable.length)) && (curricula.disable.checked == false)) { countfin = 0; contck = 1; }
    //~ else { count = curricula.disable.length; contck = count; };
    if(document.getElementsByClassName('disable') != null) contck = document.getElementsByClassName('disable');
    //~ alert(contck);
    return contck.length;
}
/************************************ END OF NON TOCCARE *************************************/


function otherError(myform, error) {
    var curricula = document.getElementById('curricula');
    var other_error = "";
    var media = "";
    var diploma_altro = "";
    var altra_laurea = "";
    var residenza_provincia = document.getElementsByClassName('prov')[0].value;
    var e_mail = document.getElementsByClassName('mail')[0].value;
    //var attivita_periodo		= myform.attivita_periodo.value;
    var data_nascita = document.getElementsByClassName('quando')[0].value;
    var cod_fiscale = document.getElementsByClassName('cFiscD')[0].value;
    
    var media_inf = document.getElementsByClassName('mediaInf')[0].checked;
    var diploma_maturita = document.getElementsByClassName('maturita')[0].value;
    var index_diploma_maturita = document.getElementsByClassName('maturita')[0].selectedIndex;
    var altro_diploma = document.getElementsByClassName('altro0')[0].value;
    var tipo_laurea = document.getElementsByClassName('tipoLaurea')[0].value;
    var index_tipo_laurea = document.getElementsByClassName('tipoLaurea')[0].selectedIndex;
    var laurea = document.getElementsByClassName('laurea')[0].value;
    var index_laurea = document.getElementsByClassName('laurea')[0].selectedIndex;
    var altra_laurea = document.getElementsByClassName('altro1')[0].value;
    var lingua01 = document.getElementsByClassName('lingua1')[0].selectedIndex;
    var livello_lingua01 = document.getElementsByClassName('Livlingua1')[0].selectedIndex;
    var lingua02 = document.getElementsByClassName('lingua2')[0].selectedIndex;
    var livello_lingua02 = document.getElementsByClassName('Livlingua2')[0].selectedIndex;

    var voto_mat01 = document.getElementsByClassName('voto0')[0].value;
    var voto_mat02 = document.getElementsByClassName('maxVoto0')[0].value;
    var voto_laurea01 = document.getElementsByClassName('voto1')[0].value;
    var voto_laurea02 = document.getElementsByClassName('maxVoto1')[0].value;
    var mat_tesi = document.getElementsByClassName('tesi')[0].value;
    var titolo_tesi = document.getElementsByClassName('titoloTesi')[0].value;
    var mese_maturita = document.getElementsByClassName('meseVoto0')[0].value;
    var anno_maturita = document.getElementsByClassName('annoVoto0')[0].value;
    var mese_laurea = document.getElementsByClassName('meseVoto1')[0].value;
    var anno_laurea = document.getElementsByClassName('annoVoto1')[0].value;
    var mese_master = document.getElementsByClassName('meseVoto2')[0].value;
    var anno_master = document.getElementsByClassName('annoVoto2')[0].value;
    var master_titolo = document.getElementsByClassName('master')[0].value;

    var infoscuola_len = document.getElementsByClassName('note')[0].value.length;
    //var attuale_professione_len			= myform.attuale_professione.value.length;
    var esperienze_prof_precedenti_len = document.getElementsByClassName('conoscenze')[0].value.length;
    var ulteriori_informazioni_len = document.getElementsByClassName('cambiamento')[0].value.length;

    var anno_server = document.getElementsByClassName('currentYear')[0].value;
    var mese_server = document.getElementsByClassName('currentMonth')[0].value;
    var year = getYear(data_nascita);

    if (media_inf)
        media = 1;
    else
        media = 0;

    if (altra_laurea != '')
        altra_laurea = 1;
    else
        altra_laurea = 0;

    if (altro_diploma != '')
        diploma_altro = 1;
    else
        diploma_altro = 0;

    if (infoscuola_len > 1000)
        other_error += "il campo NOTE contiene piu' di 1000 caratteri\n";

    //if (attuale_professione_len > 2000)
    //	other_error += "il campo ATTUALE ESPERIENZA PROFESSIONALE contiene piu' di 2000 caratteri\n";

    if (esperienze_prof_precedenti_len > 1000)
        other_error += "il campo PRECEDENTI ESPERIENZE PROFESSIONALI contiene piu' di 1000 caratteri\n";

    if (ulteriori_informazioni_len > 1000)
        other_error += "il campo EVENTUALI ULTERIORI INFORMAZIONI contiene piu' di 1000 caratteri\n";

    if (document.getElementsByClassName('estero')[0].checked)
        if (residenza_provincia == "")
        other_error += "Selezionare almeno una provincia\n";

    if (document.getElementsByClassName('beneficiario')[0].checked) {
        if (document.getElementsByClassName('disable')[0].checked) {
            if (document.getElementsByClassName('minorazionecivcD').value == "")
                other_error += "Inserire la percentuale della minorazione \n";
            if (document.getElementsByClassName('minorazionecivcD').value > 100)
                other_error += "Inserire una minorazione minore al 100%\n";
        }
        else
            if (document.getElementsByClassName('minorazionecivcD')[0].value != "")
            other_error += "Selezionare il tipo di invaliditā  \n";

        if (document.getElementsByClassName('disable')[1].checked) {
            if (document.getElementsByClassName('minorazionelavD')[0].value == "")
                other_error += "Inserire la percentuale della minorazione \n";
            if (document.getElementsByClassName('minorazionelavD')[0].value > 100)
                other_error += "Inserire una minorazione minore al 100%\n";
        }
        else
            if (document.getElementsByClassName('minorazionelavD')[0].value != "")
            other_error += "Selezionare il tipo di invaliditā  \n";

        if (document.getElementsByClassName('disable')[2].checked) {
            if (document.getElementsByClassName('minorazioneservD')[0].value == "")
                other_error += "Inserire la percentuale della minorazione \n";
            if (myform.minorazioneservD.value > 100)
                other_error += "Inserire una minorazione minore al 100%\n";
        }
        else
            if (document.getElementsByClassName('minorazioneservD')[0].value != "")
            other_error += "Selezionare il tipo di invaliditā  \n";
    }

    document.getElementsByClassName('mail')[0].value = (document.getElementsByClassName('mail')[0].value.replace(/^\s+/, '')).replace(/\s+$/, '');
    if (document.getElementsByClassName('mail')[0].value != "")
        if ((!(document.getElementsByClassName('mail')[0].value.indexOf(" ") == -1)) || (!verificaMail(myform.mail.value)))
        other_error += "Il campo 'E-mail' non &egrave; corretto \n";

    if (document.getElementsByClassName('cFiscD')[0].value != "")
        if (!verificaCodFisc(document.getElementsByClassName('cFiscD')[0].value, document.getElementsByClassName('cognome')[0].value, document.getElementsByClassName('nome')[0].value))
        other_error += "Il campo 'Codice Fiscale' non &egrave; corretto \n";

    if ((media + index_diploma_maturita + index_tipo_laurea + diploma_altro + altra_laurea) == 0)
        other_error += "Selezionare almeno un titolo di studio\n";

    if (lingua01 > 0 && livello_lingua01 == 0)
        other_error += "Selezionare il livello della 1^ lingua conosciuta\n";

    if (lingua02 > 0 && livello_lingua02 == 0)
        other_error += "Selezionare il livello della 2^ lingua conosciuta\n";

    if (voto_mat01 != "" || voto_mat02 != "" || anno_maturita != "" || mese_maturita != "")
        if (diploma_altro + index_diploma_maturita == 0)
        other_error += "Selezionare il Diploma di Maturitā riferito ai dati inseriti\n";

    if (index_diploma_maturita > 0) {
        if (voto_mat01 == "" || voto_mat02 == "")
            other_error += "Inserire la votazione del Diploma di Maturitā\n";
        else {
            if ((diploma_maturita != "100") && (diploma_maturita != "299"))
                if ((parseInt(voto_mat02, 10) != 60) && (parseInt(voto_mat02, 10) != 100))
                other_error += "Inserire una Base voto corretta del Diploma di Maturitā\n";

            if (parseInt(voto_mat01, 10) > parseInt(voto_mat02, 10))
                other_error += "Inserire il voto del Diploma di Maturitā valido\n";
        }

        if (anno_maturita == "")
            other_error += "Inserire l'anno del Diploma di Maturitā\n";
        else {
            var controllo = anno_conseguimento(anno_maturita);
            if ((parseInt(anno_maturita, 10) <= year) || (parseInt(anno_maturita, 10) > anno_server) || (!controllo))
                other_error += "Inserire un anno di conseguimento Diploma di Maturitā valido\n";
        }
        if (mese_maturita == "")
            other_error += "Inserire il mese del Diploma di Maturitā\n";
        else {
            var controllo = mese_conseguimento(mese_maturita);
            if ((parseInt(anno_maturita, 10) == anno_server && mese_maturita > mese_server) || (!controllo))
                other_error += "Inserire un mese di conseguimento Diploma di Maturitā valido\n";
        }
    }

    if (voto_laurea01 != "" || voto_laurea02 != "" || mese_laurea != "" || anno_laurea != "" || mat_tesi != "" || titolo_tesi != "")
        if (tipo_laurea == "")
        other_error += "Selezionare il tipo di Laurea riferito ai dati inseriti\n";

    if ((tipo_laurea != "") && (laurea == "") && (altra_laurea == 0))
        other_error += "Indicare sia il tipo di Laurea che la Laurea\n";

    if ((laurea != 0) || (altra_laurea > 0)) {
        if (voto_laurea01 == "" || voto_laurea02 == "")
            other_error += "Inserire la votazione della Laurea\n";
        else {
            if ((laurea != "300") &&
    		(laurea != "499") &&
        (laurea != "399") &&
        (laurea != "498") &&
        (laurea != "620"))
                if ((parseInt(voto_laurea02) != 50) && (parseInt(voto_laurea02) != 60) && (parseInt(voto_laurea02) != 70) && (parseInt(voto_laurea02) != 100) && (parseInt(voto_laurea02) != 110))
                other_error += "Inserire una Base voto corretta della Laurea\n";

            if (parseInt(voto_laurea01, 10) > parseInt(voto_laurea02, 10))
                other_error += "Inserire un voto di Laurea valido\n";
        }

        if (anno_laurea == "")
            other_error += "Inserire anno della Laurea\n";
        else {
            var controllo = anno_conseguimento(anno_laurea);
            if ((parseInt(anno_laurea, 10) <= year) || (parseInt(anno_laurea, 10) > anno_server) || (!controllo))
                other_error += "Inserire un anno di conseguimento Laurea valido \n";
        }
        if (mese_laurea == "")
            other_error += "Inserire mese della Laurea\n";
        else {
            var controllo = mese_conseguimento(mese_laurea);
            if ((parseInt(anno_laurea, 10) == anno_server && mese_laurea > mese_server) || (!controllo))
                other_error += "Inserire un mese di conseguimento Laurea valido \n";
        }


        if (master_titolo != "") {
            if (anno_master == "")
                other_error += "Inserire anno del Master\n";
            else {
                var controllo = anno_conseguimento(anno_master);
                if ((parseInt(anno_master, 10) <= year) || (parseInt(anno_master, 10) > anno_server) || (!controllo))
                    other_error += "Inserire un anno di conseguimento Master valido \n";
            }
            if (mese_master == "")
                other_error += "Inserire mese del Master\n";
            else {
                var controllo = mese_conseguimento(mese_master);
                if ((parseInt(anno_master, 10) == anno_server && mese_master > mese_server) || (!controllo))
                    other_error += "Inserire un mese di conseguimento Master valido \n";
            }
        }
    }

    /*
    var error_banche = false;

  if (myform.banche) {
    var error_banche = true;
    for (var i=0;i<myform.banche.length;i++) {
    if (myform.banche[i].checked)
    error_banche = false;
    }
    }

	if (error_banche && (myform.idProfilo.value==""))
    other_error += "Inserire almeno una banca di validitā\n";
    */
    if ((document.getElementsByClassName('accettazione')[0].checked == false) && (document.getElementsByClassName('accettazione')[1].checked == false) || (document.getElementsByClassName('accettazione')[1].checked))
        other_error += "E' obbligatoria l'accettazione della legge sulla Privacy\n";

    if (other_error != "") {
        if (error == null) {
            error = "";
            error += other_error;
        }
        else
            error += "Inoltre:\n" + other_error;
    }
    return error;
}


function defineTestAndDescription() {
    document.getElementsByClassName('cognome')[0].description = 'Cognome';
    document.getElementsByClassName('cognome')[0].mandatory = 'true';
    document.getElementsByClassName('cFiscD')[0].mandatory = 'true';
    document.getElementsByClassName('cFiscD')[0].description = 'Codice Fiscale';
    document.getElementsByClassName('nome')[0].description = 'Nome';
    document.getElementsByClassName('nome')[0].mandatory = 'true';
    document.getElementsByClassName('sesso')[0].description = 'Sesso';
    document.getElementsByClassName('sesso')[0].mandatory = 'true';
    document.getElementsByClassName('quando')[0].description = 'Data di nascita';
    document.getElementsByClassName('quando')[0].mandatory = 'true';
    document.getElementsByClassName('quando')[0].datatype = 'date';
    //curricula.attivita_periodo.description='Periodo lavorativo';
    //curricula.attivita_periodo.mandatory='false';
    //curricula.attivita_periodo.datatype='periodo';
    document.getElementsByClassName('nato')[0].description = 'Luogo di nascita';
    document.getElementsByClassName('nato')[0].mandatory = 'true';
    document.getElementsByClassName('cittadinanza')[0].description = 'Cittadinanza';
    document.getElementsByClassName('cittadinanza')[0].mandatory = 'true';
    document.getElementsByClassName('indirizzo')[0].description = 'Indirizzo residenza';
    document.getElementsByClassName('indirizzo')[0].mandatory = 'true';
    document.getElementsByClassName('cap')[0].description = 'C.A.P. Domicilio';
    document.getElementsByClassName('cap')[0].datatype = 'integer';
    document.getElementsByClassName('telefono')[0].description = 'Telefono Residenza';
    document.getElementsByClassName('cellulare')[0].description = 'Telefono cellulare';
    document.getElementsByClassName('telefonoD')[0].description = 'Telefono domicilio';
    document.getElementsByClassName('durata')[0].description = 'durata del master';
    document.getElementsByClassName('durata')[0].datatype = 'integer';
    document.getElementsByClassName('prov')[0].description = 'Comune residenza ';
    document.getElementsByClassName('prov')[0].mandatory = 'true';
    if (document.getElementsByClassName('estero')[0].checked) {
        document.getElementsByClassName('prov')[0].mandatory = 'false';
        document.getElementsByClassName('cap')[0].mandatory = 'false';
        document.getElementsByClassName('cap')[0].datatype = 'integer';
    }
    else {
        document.getElementsByClassName('prov')[0].description = 'Provincia di residenza';
        document.getElementsByClassName('prov')[0].mandatory = 'true';
        document.getElementsByClassName('cap')[0].description = 'C.A.P Residenza';
        document.getElementsByClassName('cap')[0].mandatory = 'true';
        document.getElementsByClassName('cap')[0].datatype = 'integer';
    }
    document.getElementsByClassName('areainteresse')[0].description = 'Area di interesse';
    document.getElementsByClassName('areainteresse')[0].mandatory = 'true';

}

function postForm(action) {
    //alert("ciao");
    defineTestAndDescription();
    //convertAllSingleQuote(curricula);
    var error = checkForm(curricula);
    error = otherError(curricula, error);

    if (error != null) {
        alert(error);
        return false;
    }
    //curricula.azione.value=action;
    //curricula.submit();
    return true;
}

function open_beneficiario(io) {

    var offy = 0;
    var posx = 0;
    var posy = 0;
    if (io.checked == true) {
        document.getElementById('Tabella1').style.display = "block";
    }
    else {
        var offy = -280;
        document.getElementById('Tabella1').style.display = "none";
        
        var contck = Count(); if (contck == 1) { document.getElementsByClassName('disable')[0].checked = true; } else if (contck == 0) { } else for (var d = 0; d < contck; d++) { document.getElementsByClassName('disable')[d].checked = false; }

        document.getElementsByClassName('minorazionecivcD')[0].value = "";
        document.getElementsByClassName('minorazionelavD')[0].value = "";
        document.getElementsByClassName('minorazioneservD')[0].value = "";
        document.getElementsByClassName('autorizzoD')[0].checked = false;
        document.getElementsByClassName('autorizzoD')[1].checked = false;
    }

}

function controllaConsenso() {
    if ((document.getElementsByClassName('autorizzoD')[0].checked == false) && (document.getElementsByClassName('autorizzoD')[1].checked == false)) {
        alert("E' obbligatoria l'accettazione della legge sulla Privacy per poter avvalorare la scelta relativa ai benefici di legge");
        document.getElementsByClassName('autorizzoD')[0].focus();
    }
}

function disabile() {
    // Se microsoft
    if ((document.getElementsByClassName('autorizzoD')[0].checked == false) && (document.getElementsByClassName('autorizzoD')[1].checked == false) || (document.getElementsByClassName('autorizzoD')[1].checked == true)) {
        alert("E' obbligatoria l'accettazione della legge sulla Privacy per poter avvalorare la scelta relativa ai benefici di legge");
        document.getElementsByClassName('autorizzoD')[0].focus();
        var contck = Count(); if (contck == 1) { document.getElementsByClassName('disable')[0].checked = true; } else if (contck == 0) { } else for (var d = 0; d < contck; d++) { document.getElementsByClassName('disable')[d].checked = false; }
    }
    else {
        if (document.getElementsByClassName('disable')[0].checked) {
            document.getElementsByClassName('minorazionecivcD')[0].focus();
            document.getElementsByClassName('minorazionelavD')[0].value = "";
            document.getElementsByClassName('minorazioneservD')[0].value = "";
        }
        if (document.getElementsByClassName('disable')[1].checked) {
            document.getElementsByClassName('minorazionecivcD')[0].focus();
            document.getElementsByClassName('minorazionelavD')[0].value = "";
            document.getElementsByClassName('minorazioneservD')[0].value = "";
        }
        if (document.getElementsByClassName('disable')[2].checked) {
            document.getElementsByClassName('minorazionecivcD')[0].focus();
            document.getElementsByClassName('minorazionelavD')[0].value = "";
            document.getElementsByClassName('minorazioneservD')[0].value = "";
        }
        if ((document.getElementsByClassName('disable')[0].checked == false) && (document.getElementsByClassName('disable')[1].checked == false) && (document.getElementsByClassName('disable')[2].checked == false)) {
            document.getElementsByClassName('minorazionecivcD')[0].focus();
            document.getElementsByClassName('minorazionelavD')[0].value = "";
            document.getElementsByClassName('minorazioneservD')[0].value = "";
        }
    }
    for (var i = 0; i < 7; i++) {
        var disable;
        if (document.getElementsByClassName('disable')[i] != null && document.getElementsByClassName('disable')[i].checked)
            disable = document.getElementsByClassName('disable')[i].value;
    }
}

function clear_non_autorizzo() {
    var contck = Count(); if (contck == 1) { document.getElementsByClassName('disable')[0].checked = true; } else if (contck == 0) { } else for (d = 0; d < contck; d++) { document.getElementsByClassName('disable')[d].checked = false; }

    document.getElementsByClassName('minorazionecivcD')[0].value = "";
    document.getElementsByClassName('minorazionelavD')[0].value = "";
    document.getElementsByClassName('minorazioneservD')[0].value = "";
}



//****************************** FUNZIONI NON UTILIZZATE *****************************/
//~ function campo_nascosto() {
    //~ if (curricula.estero.checked == true) {
        //~ document.getElementById("Tabella").style.display = "";
        //~ curricula.residenza_provincia.value = "EST";
        //~ curricula.residenza_provincia.disabled = true;
        //~ curricula.residenza_cap.value = "99999";
        //~ curricula.residenza_cap.disabled = true;
        //~ curricula.stato_estero.focus();
    //~ }
    //~ else {
        //~ document.getElementById("Tabella").style.display = "none";
        //~ curricula.residenza_provincia.value = "";
        //~ curricula.residenza_provincia.disabled = false;
        //~ curricula.residenza_cap.value = "";
        //~ curricula.residenza_cap.disabled = false;
        //~ curricula.stato_estero.value = "";
    //~ }
//~ }

//~ function residenza() {

//~ }

//~ function convertSingleQuote(orgString) {
    //~ var re = new RegExp("'+", "gi");
    //~ var tempstr = new String(orgString);
    //~ return tempstr.replace(re, '\'\'');
//~ }

//~ function convertAllSingleQuote(myform) {
    //~ myform.cognome.value = convertSingleQuote(myform.cognome.value);
    //~ myform.nome.value = convertSingleQuote(myform.nome.value);
    //~ myform.nato.value = convertSingleQuote(myform.nato.value);
    //~ myform.cittadinanza.value = convertSingleQuote(myform.cittadinanza.value);
    //~ myform.stato_civile.value = convertSingleQuote(myform.stato_civile.value);
    //~ myform.residenza_indirizzo.value = convertSingleQuote(myform.residenza_indirizzo.value);
    //~ myform.residenza_comune.value = convertSingleQuote(myform.residenza_comune.value);
    //~ myform.residenza_cap.value = convertSingleQuote(myform.residenza_cap.value);
    //~ myform.indirizzo.value = convertSingleQuote(myform.indirizzo.value);
    //~ myform.comune.value = convertSingleQuote(myform.comune.value);
    //~ myform.telefono.value = convertSingleQuote(myform.telefono.value);
    //~ myform.telefono_cellulare.value = convertSingleQuote(myform.telefono_cellulare.value);
    //~ myform.telefono_domicilio.value = convertSingleQuote(myform.telefono_domicilio.value);
    //~ myform.altro_diploma.value = convertSingleQuote(myform.altro_diploma.value);
    //~ myform.altra_laurea.value = convertSingleQuote(myform.altra_laurea.value);
    //~ myform.mat_tesi.value = convertSingleQuote(myform.mat_tesi.value);
    //~ myform.titolo_tesi.value = convertSingleQuote(myform.titolo_tesi.value);
    //~ myform.universita_sede.value = convertSingleQuote(myform.universita_sede.value);
    //~ myform.master_titolo.value = convertSingleQuote(myform.master_titolo.value);
    //~ myform.ente_erogatore.value = convertSingleQuote(myform.ente_erogatore.value);
    //~ myform.office_automation.value = convertSingleQuote(myform.office_automation.value);
    //~ myform.operativ_sistem.value = convertSingleQuote(myform.operativ_sistem.value);
    //~ myform.data_base.value = convertSingleQuote(myform.data_base.value);
    //~ myform.program.value = convertSingleQuote(myform.program.value);
    //~ myform.web_application.value = convertSingleQuote(myform.web_application.value);
    //~ myform.altro_it.value = convertSingleQuote(myform.altro_it.value);
    //~ myform.sede_azienda.value = convertSingleQuote(myform.sede_azienda.value);
    //~ myform.attuale_professione.value = convertSingleQuote(myform.attuale_professione.value);
    //~ myform.esperienze_prof_precedenti.value = convertSingleQuote(myform.esperienze_prof_precedenti.value);
    //~ myform.ulteriori_informazioni.value = convertSingleQuote(myform.ulteriori_informazioni.value);
    //~ myform.e_mail.value = convertSingleQuote(myform.e_mail.value);
    //~ myform.infoscuola.value = convertSingleQuote(myform.infoscuola.value);
//~ }

//~ function reload() {
    //~ curricula.azione.value = "reload";
    //~ curricula.submit();
//~ }