var adozione = {idAdozioni:"0", insegnamento:"", osservazioni:"", testiConsigliati:"", testiObbligatori:"", testiAScelta:"", idDocente:"0", dataInserimento:"", user:"", password:""};

function abilitaInvia() {
    var inviaSegnalazioneButton = document.getElementById('inviaSegnalazioneButton');
    inviaSegnalazioneButton.disabled = false;
}

function adozioneClean() {
    adozione.idAdozioni = "0";
    adozione.insegnamento = "";
    adozione.osservazioni = "";
    adozione.testiConsigliati = "";
    adozione.testiObbligatori = "";
    adozione.testiASCelta = "";
    adozione.idDocente = "0";
    adozione.dataInserimento = "";
    adozione.user = "";
    adozione.password = "";
}

function verificaAdozione(b) {
    var tuttoOK = true;
    var problema = "Problemi riscontrati: \n";
    var str = "";

    if (adozione.insegnamento.length==0) {
        tuttoOK = false;
        problema = problema + " - il campo \"Insegnamento\" non puo' essere vuoto\n";
    } 
    if (adozione.testiObbligatori.length==0){
        tuttoOK = false;
        problema = problema + " - il campo \"Testi obbligatori\" non puo' essere vuoto\n";
    }
    

    if ( (adozione.user.length==0 && adozione.password.length==0 && !b) || 
         (adozione.user.length==0 && adozione.password.length>0) || 
          adozione.user.length>0) {
      //  str = check_username(adozione.user);
        if (str.length >0){
            problema = problema + str;
            tuttoOK = false;      
        }
    }

    if ( (adozione.password.length==0 && adozione.user.length==0 && !b) || 
         (adozione.password.length==0 && adozione.user.length>0) ||
          adozione.password.length>0) {
     //   str = check_password(adozione.password);
        if (str.length >0){
            problema = problema + str;
            tuttoOK = false;      
        }
    }

    if (!tuttoOK) 
        alert(problema);
    else
        BI.resetAllBeanList(cleanInsertAdozioni);
}

function insertAdozioni() {
    DWRUtil.getValues(adozione);
    BI.isLogged(verificaAdozione);
}

function cleanInsertAdozioni(f) {
    BI.addAdozione(doInsertAdozioni, adozione);
}

function doInsertAdozioni(f) {
    if (f) {
        retrieveURL("./Controller.do?query=__USERS_ADOZIONI_INSERT");
    } else {
        alert("INTERNAL ERROR: Impossibile eseguire nell'azione di inserimento");
    }
}