// par défaut, on ne bloque pas les saisies dans la partie logement
var accepteSaisie = true;

function majusculise(champ) {
    var minus = "aàâäbcçdeéèêëfghiîïjklmnoôöpqrstuùûvwxyz"
    var majus = "AAAABCCDEEEEEFGHIIIJKLMNOOOPQRSTUUUVWXYZ"
    var entree = champ.value;
    var sortie = "";
    for (var i = 0 ; i < entree.length ; i++) {
        var car = entree.substr(i, 1);
        sortie += (minus.indexOf(car) != -1) ? majus.substr(minus.indexOf(car), 1) : car;
    }
    champ.value = sortie;
}

function remplacePointEnVirgule(champ) {
   if (champ.value.indexOf(".") != -1)
    champ.value = (champ.value.split(".")[0] + "," + champ.value.split(".")[1]);
}

function testeEntree(champ, valeurInitiale) {
    if (champ.value == valeurInitiale)
        champ.value = '';
}

function testeSortie(champ, valeurInitiale) { 
    if (champ.value == '')
        champ.value = valeurInitiale;
}

function testeEntreeNulle(champ) {
    testeEntree(champ, '0');
}

function testeSortieNulle(champ) {
    testeSortie(champ, '0');
}

function masqueSaisieDate(obj) {
    var ch;
    var ch_gauche, ch_droite;
    ch = obj.value;
    ch.toString();
    
    if ( ( (ch.slice(2,3)) != ("/") ) && (ch.length >= 3) ){
        ch_gauche = ch.slice(0,2);
        ch_droite = ch.slice(2);
        obj.value = ch_gauche + "/" + ch_droite;
    }
    if ( ( (ch.slice(5,6)) != ("/") ) && (ch.length >= 6) ){
        ch_gauche = ch.slice(0,5);
        ch_droite = ch.slice(5);
        obj.value = ch_gauche + "/" + ch_droite;
    }
    return;
}

function ouvreDepliantLocapass() {
    ouvreInfos('./Depliants/ficheAidesLocapass.html','', new Array(850,850,false,true,false,false,false,false,false));
}

function ouvreDepliantPasstravaux() {
    ouvreInfos('./Depliants/fichePasstravaux.html','', new Array(850,850,false,true,false,false,false,false,false));
}

function ouvreDepliantTravauxPasstravaux() {
    ouvreInfos('./Depliants/ficheTravauxFinancables.html','', new Array(850,850,false,true,false,false,false,false,false));
}

function ouvreDepliantMobilipass() {
    ouvreInfos('./Depliants/ficheMobilipass.html','', new Array(850,850,false,true,false,false,false,false,false));
}

function ouvreAideNatureDuParc() {
    ouvreInfos('../../Depliants/aideNatureDuParc.html','', new Array(600,400,false,true,false,false,false,false,false));
}

function ouvreInfos(url, nom, parametres) {
	var wf = "";
	wf = wf + "width=" +parametres[0];
	wf = wf + ",height=" + parametres[1];
	wf = wf + ",screenX=" + (screen.width-parametres[0])/2;
	wf = wf + ",left=" + (screen.width-parametres[0])/2;
	wf = wf + ",screenY=" + (screen.height-parametres[1])/2;
	wf = wf + ",top=" + (screen.height-parametres[1])/2;
	wf = wf + ",resizable=" + (parametres[2] ? "yes" : "no");
	wf = wf + ",scrollbars=" + (parametres[3] ? "yes" : "no");
	wf = wf + ",menubar=" + (parametres[4] ? "yes" : "no");
	wf = wf + ",toolbar=" + (parametres[5] ? "yes" : "no");
	wf = wf + ",directories=" + (parametres[6] ? "yes" : "no");
	wf = wf + ",location=" + (parametres[7] ? "yes" : "no");
	wf = wf + ",status=" + (parametres[8] ? "yes" : "no");

	window.open(url,nom,wf);
}

function ouvreAide(url, nom, parametres) {
        parametres[0] = 600;
        parametres[1] = 650;
	var wf = "";
	wf = wf + "width=" +parametres[0];
	wf = wf + ",height=" + parametres[1];
	wf = wf + ",screenX=" + (screen.width-parametres[0])/2;
	wf = wf + ",left=" + (screen.width-parametres[0])/2;
	wf = wf + ",screenY=" + (screen.height-parametres[1])/2;
	wf = wf + ",top=" + (screen.height-parametres[1])/2;
	wf = wf + ",resizable=" + (parametres[2] ? "yes" : "no");
	wf = wf + ",scrollbars=" + (parametres[3] ? "yes" : "no");
	wf = wf + ",menubar=" + (parametres[4] ? "yes" : "no");
	wf = wf + ",toolbar=" + (parametres[5] ? "yes" : "no");
	wf = wf + ",directories=" + (parametres[6] ? "yes" : "no");
	wf = wf + ",location=" + (parametres[7] ? "yes" : "no");
	wf = wf + ",status=" + (parametres[8] ? "yes" : "no");

	window.open(url,nom,wf);
}


function ouvreAPropos(url, nom, parametres) {
        parametres[0] = 600;
        parametres[1] = 600;
	var wf = "";
	wf = wf + "width=" +parametres[0];
	wf = wf + ",height=" + parametres[1];
	wf = wf + ",screenX=" + (screen.width-parametres[0])/2;
	wf = wf + ",left=" + (screen.width-parametres[0])/2;
	wf = wf + ",screenY=" + (screen.height-parametres[1])/2;
	wf = wf + ",top=" + (screen.height-parametres[1])/2;
	wf = wf + ",resizable=" + (parametres[2] ? "yes" : "no");
	wf = wf + ",scrollbars=" + (parametres[3] ? "yes" : "no");
	wf = wf + ",menubar=" + (parametres[4] ? "yes" : "no");
	wf = wf + ",toolbar=" + (parametres[5] ? "yes" : "no");
	wf = wf + ",directories=" + (parametres[6] ? "yes" : "no");
	wf = wf + ",location=" + (parametres[7] ? "yes" : "no");
	wf = wf + ",status=" + (parametres[8] ? "yes" : "no");

	window.open(url,nom,wf);
}

function affichePanneauAttente(elementID) {
    document.getElementById(elementID).style.display='';     
}


function cachePanneauAttente(elementID) {
    document.getElementById(elementID).style.display='none';
}

function propageValeurVers(champ, elementID) {
    // alert("Propage - Champ.value " + champ.value);
    // alert("Propage - ElementID " + document.getElementById(elementID));
    // alert("Propage - Avant ElementID.value " + document.getElementById(elementID).value);
    document.getElementById(elementID).value = champ.value;
    // on prend 1 ou 2 fois la valeur et on borne à 2300
    valeurMaximale(elementID, 2300);
    calculeTexteMontantMensualites();
    // alert("Propage - Apres ElementID.value " + document.getElementById(elementID).value);
}

function valeurMaximale(champ, borne) {
    var meuble = document.getElementById('formeGlobale_id:logementMeuble_id');
    var coef = 1;
    // la valeur 0 pour meublé à "oui"
    if (meuble.value == 0)
        coef = 2;
    champ.value = new String(Math.min(coef * parseFloat(champ.value), borne));
}

function calculeTexteMontantMensualites() {
    // alert("Avant parseInt - nbMois : " + document.getElementById('formeGlobale_id:dureeRemboursement_id').value);
    // alert("Avant parseFloat - montantDepot : " + document.getElementById('formeGlobale_id:montantDepotGarantie_id').value);
    // alert("Avant texteInfos : " + document.getElementById('formeGlobale_id:texteMensualites_id').innerHTML);
    var nbMois = parseInt(document.getElementById('formeGlobale_id:dureeRemboursement_id').value);
    var montantDepot = parseFloat(document.getElementById('formeGlobale_id:montantDepotGarantie_id').value);
    var mensualite = montantDepot / nbMois;
    // alert("nbMois : " + nbMois);
    // alert("montantDepot : " + montantDepot);
    // alert("mensualite : " + mensualite);
    var texteInfos = (mensualite < 15) ? "<br>Attention votre mensualité est inférieur à 15 €" : "";
    var texteMontant = "Montant des mensualités : " + formatMonetaire(mensualite) + " € ";
    document.getElementById('formeGlobale_id:texteMensualites_id').innerHTML = texteMontant + texteInfos;
}

function formatMonetaire(amount) {
    // var i = parseFloat(amount);
    var i = amount;
    if(isNaN(i))
        i = 0.00;
    var minus = '';
    if(i < 0)
        minus = '-';
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0)
        s += '.00';
    if(s.indexOf('.') == (s.length - 2))
        s += '0';
    s = minus + s;
    return s;
}



function changeDestinataireDesFonds(type) {
    var chaineNomDestinaire = document.getElementById('formeGlobale_id:texteNomAdresseDestinataire_id');
    var chaineRIB = document.getElementById('formeGlobale_id:texteJoindreRIB_id');
    // rib = document.getElementById('formeGlobale_id:saisirRIBDestinataire_id');
    var nom = document.getElementById('formeGlobale_id:nomDestinataire_id');
    var adresse = document.getElementById('formeGlobale_id:adresseDestinataire_id');
    var codePostal = document.getElementById('formeGlobale_id:codePostalDestinataire_id');
    var ville = document.getElementById('formeGlobale_id:villeDestinataire_id');
    // type = 0 pour Locataire
    // type = 1 pour propriétaire
    
    if (type.value == 1) {
        chaineNomDestinaire.innerHTML = "Vous devez préciser le nom et l'adresse du destinataire des fonds";
        chaineRIB.innerHTML = "Joindre un RIB du destinataire des fonds, s'il désire un virement";
        // rib.disabled = false;
        nom.disabled = false;
        adresse.disabled = false;
        codePostal.disabled = false;
        ville.disabled = false;
    } else {
        chaineNomDestinaire.innerHTML = "";
        chaineRIB.innerHTML = "";
        // rib.disabled = true;
        nom.disabled = true;
        adresse.disabled = true;
        codePostal.disabled = true;
        ville.disabled = true;
    }
}


function changeSaisirRIBDestinataire(champ) {
    var ongletRIB = document.getElementById('formeGlobale_id:ongletBanqueDestinataire_id');
    var ongletRecapitulatif = document.getElementById('formeGlobale_id:ongletRecapitulatif_id');
    // si on a l'onglet recapitulatif d'actif, cela signifie que l'on est déjà passé sur l'onglet Logement
    if (!ongletRecapitulatif.disabled)
        ongletRIB.disabled = !champ.checked;
}

function changeLogementMeuble(champ) {
    // alert("champ meuble : " + champ.value);
}

function nombreMoisChange() {
    var selectionNbMoisBail = document.getElementById('formeGlobale_id:dureeBail_id').checked;
    // alert("Par ID, valeur : " + selectionNbMoisBail);
    var champNbMoisBail = document.getElementById('formeGlobale_id:nombreMoisBail_id');
    champNbMoisBail.disabled = !selectionNbMoisBail;
}

function valideDureeRemboursement() {
    var checkDuree = document.getElementById('formeGlobale_id:dureeBail_id');
    var texteAlerte = document.getElementById('formeGlobale_id:texteDureeRemboursement_id')
    // on a déselectionné, on efface le texte d'avertissement
    if (!checkDuree.checked) {
        texteAlerte.innerHTML = "";
        return;
    }
    var nbMoisBail = parseInt(document.getElementById('formeGlobale_id:nombreMoisBail_id').value);
    var nbMoisRemboursement = parseInt(document.getElementById('formeGlobale_id:dureeRemboursement_id').value);
    if (nbMoisRemboursement > nbMoisBail)
        texteAlerte.innerHTML = "La durée de remboursement doit être inférieure à la durée du bail";
    else
        texteAlerte.innerHTML = "";
}

function logementCrousSelection() {
    var selectionLogement = document.getElementById('formeGlobale_id:selectionCROUS_id').checked;
    var selectionResidence = document.getElementById('formeGlobale_id:selectionResidence_id');
    selectionResidence.disabled = !selectionLogement;
}

function valideSituationFamilialeAvecCoDemandeur() {
    var coDemandeur = document.getElementById('formeGlobale_id:coDemandeurSelection_id').checked;
    var indexSituation = document.getElementById('formeGlobale_id:situationFamiliale_id').value;
    var texteAvertissement = document.getElementById('formeGlobale_id:texteSituationFamiliale_id');
    var listeSituations = new Array("Célibataire", "Marié(e)", "Pacsé(e)", "Veuf(ve)", "Séparé(e)", "Divorcé(e)", "Vie maritale");
    var situationFamiliale = listeSituations[indexSituation].toUpperCase();
    if (((situationFamiliale.indexOf("MARI", 0) == -1) && 
         (situationFamiliale.indexOf("PAC", 0) == -1)) || coDemandeur) {
        texteAvertissement.innerHTML = "";
        clearInterval(processusClignotement);
    } else {
        texteAvertissement.innerHTML = "Attention, votre situation familiale nécessite un co-demandeur";
        processusClignotement = setInterval("clignotement(texteAvertissement)", 500); 
    }
}

function clignotement(element){ 
    if (element.style.visibility=='hidden') 
        element.style.visibility=''; 
    else 
        element.style.visibility='hidden'; 
}

function accepteLaSaisie() {
    var residence = document.getElementById('formeGlobale_id:texteCrousResidence_id');
    // on accepte la saisie si l'on n'est pas CROUS
    if (residence == null)
        return true;
    var index = document.getElementById('formeGlobale_id:typeLogement_id').value;
    valeurResidence = residence.innerHTML.toUpperCase();
    // on accepte la saisie pour la résidence cézeaux et le logement en indice 0 (autres)
    // return ((valeurResidence.indexOf("ZEAUX", 0) != -1) && (index == 0));
    // maintenant, tous (et plus uniquement CEZEAUX) peuvent avoir une saisie libre
    return (index == 0);
}

function bloqueSaisie(evt) {
    var keyCode = evt.which ? evt.which : window.event.keyCode;
    if (keyCode==9)
        return evt.which ? true : window.event.returnValue = true;
    return evt.which ? accepteLaSaisie() : window.event.returnValue = accepteLaSaisie();
}

function initialiseLogement() {
    var index = document.getElementById('formeGlobale_id:typeLogement_id').value;
    var residence = document.getElementById('formeGlobale_id:texteCrousResidence_id');
    if (residence == null)
        return;
    
        
    var texteAlerte = document.getElementById('formeGlobale_id:texteSaisieInactive_id');
    texteAlerte.innerHTML = "Les informations affichées ne sont pas modifiables";

    accepteSaisie = false;
    document.getElementById('formeGlobale_id:debutLocationLogement_id').value = "01/09/2009"; 
    document.getElementById('formeGlobale_id:signatureBail_id').value = "01/09/2009";

    valeurResidence = residence.innerHTML.toUpperCase();
    if (valeurResidence.indexOf("DOLET", 0) != -1)
        initialiseLogementDolet(index);
    if (valeurResidence.indexOf("AMBOISE", 0) != -1)
        initialiseLogementAmboise(index);
    if (valeurResidence.indexOf("ZEAUX", 0) != -1)
        initialiseLogementCezeaux(index);
}

function initialiseLogementDolet(index) {
    if (index == 0)
        initialiseLogementDolet0();
    if (index == 1)
        initialiseLogementDoletChambre();
    if (index == 2)
        initialiseLogementDoletChambreConfortAmeliore();
    if (index == 3)
        initialiseLogementDoletStudette();
}

function initialiseLogementDolet0() {
    
    var texteAlerte = document.getElementById('formeGlobale_id:texteSaisieInactive_id')
    texteAlerte.innerHTML = "Vous devez saisir les informations de votre logement";

    accepteSaisie = true;
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "0";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "0";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "0";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}


function initialiseLogementDoletChambre() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "25 RUE ETIENNE DOLET\nRES DU CLOS ST JACQUES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63037";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT FD CEDEX";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "136,40";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "156";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

function initialiseLogementDoletChambreConfortAmeliore() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "25 RUE ETIENNE DOLET\nRES DU CLOS ST JACQUES Bat. B";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63037";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT FD CEDEX";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "146,50";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "166";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

function initialiseLogementDoletStudette() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "25 RUE ETIENNE DOLET\nRES DU CLOS ST JACQUES BAT A";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63037";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT FD CEDEX";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "268,71";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "286";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "12";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "14";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "12";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

function initialiseLogementAmboise(index) {
    eval("initialiseLogementAmboise" + index + "()");
/*
    if (index == 0)
        initialiseLogementAmboise0();
    if (index == 1)
        initialiseLogementAmboise1();
    if (index == 2)
        initialiseLogementAmboise2();
*/
}

function initialiseLogementAmboise0() {
    
    var texteAlerte = document.getElementById('formeGlobale_id:texteSaisieInactive_id')
    texteAlerte.innerHTML = "Vous devez saisir les informations de votre logement";

    accepteSaisie = true;
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "0";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "0";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "0";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}


// Chambre confort amélioré Amboise
function initialiseLogementAmboise1() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "11 RUE D AMBOISE\nRU LEBON AMBOISE";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63037";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT FD CEDEX";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "146,50";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "150,00";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Chambre rénovée  Philippe Lebon
function initialiseLogementAmboise2() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "28 BD COTE BLATIN\nRU LEBON AMBOISE";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63037";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT FD CEDEX";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "216,05";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "220,00";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Chambre traditionnelle Philippe Lebon
function initialiseLogementAmboise3() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "28 BD COTE BLATIN\nRU LEBON AMBOISE";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63037";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT FD CEDEX";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "136,40";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "140,00";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

function initialiseLogementCezeaux(index) {
    eval("initialiseLogementCezeaux" + index + "()");
    /*
    if (index == 0)
        initialiseLogementCezeaux0();
    if (index == 1)
        initialiseLogementCezeaux1();
    if (index == 2)
        initialiseLogementCezeaux2();
    if (index == 3)
        initialiseLogementCezeaux3();
    if (index == 4)
        initialiseLogementCezeaux4();
        */
}

// autre
function initialiseLogementCezeaux0() {
    
    var texteAlerte = document.getElementById('formeGlobale_id:texteSaisieInactive_id')
    texteAlerte.innerHTML = "Vous devez saisir les informations de votre logement";

    accepteSaisie = true;
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "0";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "0";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "0";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Cezeaux / Chambre rénovée
function initialiseLogementCezeaux1() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "17 RUE ROCHE GENES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63170";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "AUBIERE";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "216,05";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "220";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Cezeaux / Chambre traditionnelle
function initialiseLogementCezeaux2() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "17 RUE ROCHE GENES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63170";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "AUBIERE";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "136,40";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "0";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "140";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "9";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Cezeaux / Studio T1
function initialiseLogementCezeaux3() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "17 RUE ROCHE GENES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63170";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "AUBIERE";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "189,70";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "105,30";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "340";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Cezeaux / T1 avec Cuisine Commune
function initialiseLogementCezeaux4() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "17 RUE ROCHE GENES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63170";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "AUBIERE";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "189,70";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "97,30";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "340";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Cezeaux / T1 bis
function initialiseLogementCezeaux5() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "17 RUE ROCHE GENES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63170";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "AUBIERE";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "268,14";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "135,86";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "400";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// La gare / T1
function initialiseLogementCezeaux6() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "58 AV DE L URSS";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63000";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT-FERRAND";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "220,71";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "90,29";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "340";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// La gare / T1 bis
function initialiseLogementCezeaux7() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "58 AV DE L URSS";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63000";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT-FERRAND";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "293,00";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "120,00";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "400";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Les jardins / T1
function initialiseLogementCezeaux8() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "10 RUE SAINT RAMES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63000";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT-FERRAND";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "189,58";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "95,42";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "340";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

// Les jardins / T1 bis
function initialiseLogementCezeaux9() {
    document.getElementById('formeGlobale_id:adresseLogement_id').value = "10 RUE SAINT RAMES";
    document.getElementById('formeGlobale_id:codePostalLogement_id').value = "63000";
    document.getElementById('formeGlobale_id:villeLogement_id').value = "CLERMONT-FERRAND";
    document.getElementById('formeGlobale_id:montantLoyer_id').value = "255,35";
    document.getElementById('formeGlobale_id:montantCharges_id').value = "117,65";
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').value = "400";
    document.getElementById('formeGlobale_id:nombreMoisBail_id').value = "10";
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').value = "20";

    document.getElementById('formeGlobale_id:dureeRemboursement_id').value = "10";
    document.getElementById('formeGlobale_id:dureeBail_id').checked = true;
    
    // desactiveSaisiesLogement();
}

function desactiveSaisiesLogement() {
    document.getElementById('formeGlobale_id:adresseLogement_id').disabled = true;
    document.getElementById('formeGlobale_id:codePostalLogement_id').disabled = true;
    document.getElementById('formeGlobale_id:villeLogement_id').disabled = true;
    document.getElementById('formeGlobale_id:montantLoyer_id').disabled = true;
    document.getElementById('formeGlobale_id:montantDepotGarantie_id').disabled = true;
    document.getElementById('formeGlobale_id:debutLocationLogement_id').disabled = true;
    document.getElementById('formeGlobale_id:nombreMoisBail_id').disabled = true;
    document.getElementById('formeGlobale_id:surfaceHabitableLogement_id').disabled = true;

    document.getElementById('formeGlobale_id:dureeBail_id').disabled = true;
}

// pour le passtravaux et le mobilipass
function locataireProprietaireSelection(selection_id, montantLoyer_id, montantMensualites_id) {
    // on prend le premier radio bouton (locataire) pour vérifier s'il est sélectionné
    var selection = document.getElementsByName(selection_id)[0];
    var montantLoyer = document.getElementById(montantLoyer_id);
    var montantMensualites = document.getElementById(montantMensualites_id);
    var listeSituations = new Array("Locataire", "Propriétaire");
    // si le premier élément du radio bouton est sélectionné
    var indexSituation = selection.checked ? 0 : 1;
    var situation = listeSituations[indexSituation].toLowerCase();
    // est-ce un locataire ou un propriétaire
    var locataire = situation.indexOf("locataire", 0) != -1;
    montantLoyer.disabled = !locataire;
    montantMensualites.disabled = locataire;
}

function afficheEfface(element, etat) {
    element.style.visibility = etat ? '' : 'hidden';
}


// Mobili-pass
// pour recopier l'ancienne situation pro dans la nouvelle
function recopieSituationsPro() {
    document.getElementById('formeGlobale_id:situationProApres_id').value = document.getElementById('formeGlobale_id:situationProAvant_id').value;
    document.getElementById('formeGlobale_id:nomEmployeurApres_id').value = document.getElementById('formeGlobale_id:nomEmployeurAvant_id').value;
    document.getElementById('formeGlobale_id:adresseEmployeurApres_id').value = document.getElementById('formeGlobale_id:adresseEmployeurAvant_id').value;
    document.getElementById('formeGlobale_id:codePostalEmployeurApres_id').value = document.getElementById('formeGlobale_id:codePostalEmployeurAvant_id').value;
    document.getElementById('formeGlobale_id:villeEmployeurApres_id').value = document.getElementById('formeGlobale_id:villeEmployeurAvant_id').value;
    document.getElementById('formeGlobale_id:telephoneEmployeurApres_id').value = document.getElementById('formeGlobale_id:telephoneAvant_id').value;
    document.getElementById('formeGlobale_id:adresseTravailApres_id').value = document.getElementById('formeGlobale_id:adresseTravailAvant_id').value;
    document.getElementById('formeGlobale_id:codePostalTravailApres_id').value = document.getElementById('formeGlobale_id:codePostalTravailAvant_id').value;
    document.getElementById('formeGlobale_id:villeTravailApres_id').value = document.getElementById('formeGlobale_id:villeTravailAvant_id').value;
    document.getElementById('formeGlobale_id:dateArrivee_id').value = document.getElementById('formeGlobale_id:dateDepart_id').value;
}

// pour annuler le contenu de la nouvelle situation pro
function effaceSituationProApres() {
    document.getElementById('formeGlobale_id:situationProApres_id').value = '';
    document.getElementById('formeGlobale_id:nomEmployeurApres_id').value = '';
    document.getElementById('formeGlobale_id:adresseEmployeurApres_id').value = '';
    document.getElementById('formeGlobale_id:codePostalEmployeurApres_id').value = '';
    document.getElementById('formeGlobale_id:villeEmployeurApres_id').value = '';
    document.getElementById('formeGlobale_id:telephoneEmployeurApres_id').value = '';
    document.getElementById('formeGlobale_id:adresseTravailApres_id').value = '';
    document.getElementById('formeGlobale_id:codePostalTravailApres_id').value = '';
    document.getElementById('formeGlobale_id:villeTravailApres_id').value = '';
    document.getElementById('formeGlobale_id:dateArrivee_id').value = '';
}

// pour changer le texte suivant l'accord ou pas de l'employeur
function accordEmployeurChange(champ) {
    var indexAccord = champ.value;
    var texte = document.getElementById('formeGlobale_id:texteAccordEmployeur_id');
    
    var listeAccords = new Array("oui", "non");
    var accord = listeAccords[indexAccord].toLowerCase();
    if (accord.indexOf("non", 0) != -1)
        texte.innerHTML = "Sans accord de votre employeur, le montant maximum de votre MOBILI-PASS® est de <b>1600 €</b>";
    else
        texte.innerHTML = "Avec l'accord de votre employeur, le <b>montant maximum de votre MOBILI-PASS® est de 3200 €</b>";
}

function testOnglet() {
    var ongletDemandeur = document.getElementById('formeGlobale_id:ongletDemandeur_id');
    alert("onglet : " + ongletDemandeur + " onglet disabled : " + ongletDemandeur.disabled);
    ongletDemandeur.disabled = !ongletDemandeur.disabled;
}

// Pas utilisé, car on prégère l'accès direct par 'forme_id:elment_id'
// plutot que getFormeElement('forme_id', 'element_id')

function getFormeElement(formeID, elementID) {
    return document.forms[formeID].elements[elementID];
}


function getFormeElementValeur(formeID, elementID) {
    return getFormeElement(formeID, elementID).value;
}


function setFormeElementValeur(formeID, elementID, valeur) {
    getFormeElement(formeID, elementID).value = valeur;
}

function testeMineur(dateNaissance) {
    var crous = document.getElementById('formeGlobale_id:texteCrousSelectionnePourEtudiant_id');

    var texte = document.getElementById('formeGlobale_id:texteMineurEtudiant_id');
    var dateCouranteC = new Date();
    var tab = dateNaissance.value.split('-'); 
    var dateNaissanceC = new Date(tab[2], tab[1] - 1, tab[0]);
    // alert("Naissance : " + dateNaissance.value + " Tab : " + tab[2] + ":" + tab[1] + ":" + tab[0]);

    var anneeNaissance = dateNaissanceC.getFullYear();
    var anneeCourante = dateCouranteC.getFullYear();
    
    if (anneeCourante - anneeNaissance > 18) {
        texte.innerHTML = "";
        return;
    }
    
    if (anneeCourante - anneeNaissance < 18) {
        if (crous == null)
            texte.innerHTML = "Attention, l'offre de prêt et/ou la garantie de loyers ne peut être accordée aux mineurs";
        else
            texte.innerHTML = "Attention, vous êtes mineur, l'offre de prêt et/ou la garantie de loyers devra(ont) être signé(e)(s) par votre représentant légal";
        return;
    }

    var moisNaissance = dateNaissanceC.getMonth() + 1;
    var moisCourant = dateCouranteC.getMonth() + 1;

    if (moisCourant > moisNaissance) {
        texte.innerHTML = "";
        return;
    }
    
    if (moisCourant < moisNaissance) {
        if (crous == null)
            texte.innerHTML = "Attention, l'offre de prêt et/ou la garantie de loyers ne peut être accordée aux mineurs";
        else
            texte.innerHTML = "Attention, vous êtes mineur, l'offre de prêt et/ou la garantie de loyers devra(ont) être signé(e)(s) par votre représentant légal";
        return;
    }
    
    var jourNaissance = dateNaissanceC.getDate();
    var jourCourant = dateCouranteC.getDate();

    // alert("Date courante : " + jourCourant + "/" + moisCourant + "/" + anneeCourante + " Date naissance : " + jourNaissance + "/" + moisNaissance + "/" + anneeNaissance);
    if (jourCourant >= jourNaissance) {
        texte.innerHTML = "";
        return;
    }
    
    if (crous == null)
        texte.innerHTML = "Attention, l'offre de prêt et/ou la garantie de loyers ne peut être accordée aux mineurs";
    else
        texte.innerHTML = "Attention, vous êtes mineur, l'offre de prêt et/ou la garantie de loyers devra(ont) être signé(e)(s) par votre représentant légal";
}

function activeMasque(id, masque) {
    jQuery(function($){ $("#formeGlobale_id\\:" + id).unmask().mask(masque);});
}


/*
    Tableau des onglets LOCA-PASS
*/

tabOngletsLocapass = new Array (
    "ongletPresentation_id",
    "ongletDossier_id",
    "ongletDemandeur_id",
    "ongletRessourcesDemandeur_id",
    "ongletCoDemandeur_id",
    "ongletRessourcesCoDemandeur_id",
    "ongletBanqueDemandeur_id",
    "ongletBailleur_id",
    "ongletLogement_id",
    "ongletRecapitulatif_id");

/*
    Tableau des onglets MOBILI-PASS
*/

tabOngletsMobilipass = new Array (
    "ongletPresentation_id",
    "ongletDossier_id",
    "ongletDemandeur_id",
    "ongletCoDemandeur_id",
    "ongletLogement_id",
    "ongletDepenses_id",
    "ongletRecapitulatif_id");

/*
    Tableau des onglets PASS-TRAVAUX
*/

tabOngletsPasstravaux = new Array (
    "ongletPresentation_id",
    "ongletDemandeur_id",
    "ongletRessourcesDemandeur_id",
    "ongletCoDemandeur_id",
    "ongletBanqueDemandeur_id",
    "ongletProjet_id",
    "ongletFinancement_id",
    "ongletCredits_id",
    "ongletRecapitulatif_id");

function activeOnglet(tabOnglets, indiceCourant, sens) {
    var indiceSuivant = indiceCourant + sens;
    var tailleTab = tabOnglets.length;
    while (indiceSuivant >= 0 && indiceSuivant < tailleTab) {
        var onglet_id = 'formeGlobale_id:' + tabOnglets[indiceSuivant];
        var onglet = document.getElementById(onglet_id);
        // alert("propriete onclick : " + onglet.onclick);
        // s'il n'y a pas de fonction associé
        if (onglet.onclick != null) {
            _submitPartialChange('formeGlobale_id',1,{partialTargets:'formeGlobale_id:tabPanneaux_id',event:'show',source:onglet_id});
            return true;
        }
        indiceSuivant = indiceSuivant + sens;
    }
    return false;
}

function activeOngletLocapass(indiceCourant, sens) {
    return activeOnglet(tabOngletsLocapass, indiceCourant, sens);
}

function activeSuivantLocapass(indiceCourant) {
    return activeOngletLocapass(indiceCourant, 1);
}

function activePrecedentLocapass(indiceCourant) {
    return activeOngletLocapass(indiceCourant, -1);
}

function activeOngletMobilipass(indiceCourant, sens) {
    return activeOnglet(tabOngletsMobilipass, indiceCourant, sens);
}

function activeSuivantMobilipass(indiceCourant) {
    return activeOngletMobilipass(indiceCourant, 1);
}

function activePrecedentMobilipass(indiceCourant) {
    return activeOngletMobilipass(indiceCourant, -1);
}

function activeOngletPasstravaux(indiceCourant, sens) {
    return activeOnglet(tabOngletsPasstravaux, indiceCourant, sens);
}

function activeSuivantPasstravaux(indiceCourant) {
    return activeOngletPasstravaux(indiceCourant, 1);
}

function activePrecedentPasstravaux(indiceCourant) {
    return activeOngletPasstravaux(indiceCourant, -1);
}