// array for thématiques
array_th = new Array(false, false, false, false, false, false);
var generalites         = 0;
var linguistique        = 1;
var linguistiqueApp     = 2;
var ecriture            = 3;
var outilsLinguistiques = 4;
var formations 			= 5;

function formScript_th(categorie) {

    switch (categorie) {
        case "generalites" :
            array_th[generalites]           = isChecked_th(generalites);
            addOption_th();
            break;
        case "linguistique" :
            array_th[linguistique]          = isChecked_th(linguistique);
            addOption_th();
            break;
        case "linguistiqueApp" :
            array_th[linguistiqueApp]       = isChecked_th(linguistiqueApp);
            addOption_th();
            break;
        case "ecriture" :
            array_th[ecriture]              = isChecked_th(ecriture);
            addOption_th();
            break;
        case "outilsLinguistiques" :
            array_th[outilsLinguistiques]   = isChecked_th(outilsLinguistiques);
            addOption_th();
            break;
        case "formations" :
            array_th[formations]   			= isChecked_th(formations);
            addOption_th();
            break;
    }

    // expand thématique
    if (
        array_th[generalites]       	||
        array_th[linguistique]      	||
        array_th[linguistiqueApp]   	||
        array_th[ecriture]          	||
        array_th[outilsLinguistiques]	||
        array_th[formations]
            ) {
        expandForm("thematique");
    }

    repairArray();

    // collapse thématique
    if (
        !array_th[generalites]      	&&
        !array_th[linguistique]    	 	&&
        !array_th[linguistiqueApp]  	&&
        !array_th[ecriture]         	&&
        !array_th[outilsLinguistiques]	&&
        !array_th[formations]
        ) {
        collapseForm("thematique");
    }
}

//-----------------------------------------------------------------------------------------

function repairArray()
{
    for (i = 0; i < array_th.length; i++) {
        array_th[i] = isChecked_th(i);
    }
}


//-----------------------------------------------------------------------------------------

function addOption_th()
{

    //------------------------------//
    // first, we delete all options //
    //------------------------------//
    var thematiqueLength = document.searchForm.thematique.length;

    for (i = thematiqueLength - 1; i >=0; i--) {
        document.searchForm.thematique.options[i] = null;
    }

    // -------------------- all element deleted --------------------//

    //--------------------------------------//
    // we loop our array and we display the //
    // related content when required        //
    //--------------------------------------//
    for(i = 0; i < array_th.length; i++) {

        // if current value is true we call the related function inside the switch block
        if ( isChecked_th(i) ) {
            switch (i) {
                // 0 = generalités
                case 0 :
                    buildGeneralites();
                    break;
                case 1 :
                    buildLinguistique();
                    break;
                case 2 :
                    buildLinguistiqueApp();
                    break;
                case 3 :
                    buildEcriture();
                    break;
                case 4 :
                    buildOutilsLinguistiques();
                    break;
               	case 5 :
                    buildFormations();
                    break;
            }
        }

    }
}

//-----------------------------------------------------------------------------------------

// check if the checkbox was realy checked or not
function isChecked_th(variable)
{
    var myBool = false;

    switch (variable) {
        case 0 :
            if (document.searchForm.generalites.checked) {
                myBool = true; //changeValue(array_th[0]);
            } else {
                myBool = false;
            }
            break;
        case 1 :
            if (document.searchForm.linguistique.checked) {
                 myBool = true; //changeValue(array_th[1]);
            } else {
                myBool = false;
            }
            break;
        case 2 :
            if (document.searchForm.linguistiqueApp.checked) {
                 myBool = true; //changeValue(array_th[2]);
            } else {
                myBool = false;
            }
            break;
        case 3 :
            if (document.searchForm.ecriture.checked) {
                 myBool = true; //changeValue(array_th[3]);
            } else {
                myBool = false;
            }
            break;
        case 4 :
            if (document.searchForm.outilsLinguistiques.checked) {
                 myBool = true; //changeValue(array_th[4]);
            } else {
                myBool = false;
            }
            break;
            
        case 5 :
            if (document.searchForm.formations.checked) {
                 myBool = true; //changeValue(array_th[5]);
            } else {
                myBool = false;
            }
            break;
    }

    return myBool;
}

