function form_modifie_type_formation(id){
    var intitule = document.getElementById("nom_type_form_"+id).innerHTML;
    var descr = document.getElementById("description_formation_"+id).innerHTML;

    monForm = document.createElement("form");
    monForm.setAttribute('action', 'index.php?m=formations&a=valide_modif_type');
    monForm.setAttribute('ENCTYPE', 'multipart/form-data');
    monForm.setAttribute("method", "POST");
    monForm.setAttribute("name", "modif_type_formation");
    monForm.setAttribute("id", "modif_type_formation");

    monForm.innerHTML =  "<div id='modalalertdiv_type_formation' class='yui-skin-sam' ><center><br/><table class='text_left' >"+
    "<tr><td>Intitul&eacute; : </td><td><input type='text' size='60' value=\""+intitule+"\" name='intitule_type_formation' id='intitule_type_formation' /></td></tr>"+
    "<tr><td>Description : </td><td><textarea cols='49' rows='5' name='description_type_formation' id='description_type_formation' >"+descr+"</textarea></td></tr>"+
    "</table>"+
    "<input type='hidden' value='"+id+"' name='id_type_formation' />"+
    "<br /><input type='button' name='Annuler' value='Annuler' onclick='modalwindow.hide();' /> " +
    "<input type='submit' id='Valider' name='Valider' value='Valider' /></center></div>";

    document.getElementById("modalalertdiv").appendChild(monForm);

    var larg = (document.body.clientWidth) / 2-325;
    var haut = (window.innerHeight/2)-250;
    var h = 220;

    if(window.innerHeight == null){
        haut = 10;
        h=280;
    }

    modalwindow = dhtmlmodal.open('modal', 'div', 'modalalertdiv',
        "Modification du type de formation", "width=650px,height="+h+"px,left=" + larg
        + ",top=" + haut + ",resize=0,scrolling=1");

    var editorDescr = new YAHOO.widget.Editor('description_type_formation', {
        toolbar: bar
    });
    editorDescr.render();

    YAHOO.util.Event.on('Valider', 'click', function() {
        editorDescr.saveHTML();
        var descr = editorDescr.get('element').value;

        var xhr = getXhr();
        // On défini ce qu'on va faire quand on aura la réponse
        xhr.onreadystatechange = function(){
            // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
            if(xhr.readyState == 4 && xhr.status == 200){

        }
        };
        var titre =  document.getElementById("intitule_type_formation").value;
        var data = 'description_type_formation='+descr+'&intitule_type_formation='+titre;

        xhr.open("POST",'index.php?m=formations&a=valide_modif_type',true);
        xhr.send(data);
    });
}

function form_ajoute_type_formation(){
    monForm = document.createElement("form");
    monForm.setAttribute('action', 'index.php?m=formations&a=valide_ajout_type_form');
    monForm.setAttribute('ENCTYPE', 'multipart/form-data');
    monForm.setAttribute("method", "POST");
    monForm.setAttribute("name", "ajout_type_formation");
    monForm.setAttribute("id", "ajout_type_formation");

    monForm.innerHTML =  "<div id='modalalertdiv_type_formation' class='yui-skin-sam' ><center><br/><table class='text_left' >"+
    "<tr><td>Intitul&eacute; : </td><td><input type='text' size='60' name='intitule_type_formation' id='intitule_type_formation' /></td></tr>"+
    "<tr><td>Description : </td><td><textarea cols='47' rows='5' name='description_type_formation' id='description_type_formation' ></textarea></td></tr>"+
    "</table>"+
    "<br /><input type='button' name='Annuler' value='Annuler' onclick='modalwindow.hide();' /> " +
    "<input type='submit' name='Valider' id='Valider' value='Valider' /></center></div>";

    document.getElementById("modalalertdiv").appendChild(monForm);

    var larg = (document.body.clientWidth) / 2-325;
    var haut = (window.innerHeight/2)-250;
    var h = 220;
    if(window.innerHeight == null){
        haut = 10;
        h = 280;
    }

    modalwindow = dhtmlmodal.open('modal', 'div', 'modalalertdiv',
        "Ajout d'un type de formation", "width=650px,height="+h+"px,left=" + larg
        + ",top=" + haut + ",resize=0,scrolling=1");

    var editorDescr = new YAHOO.widget.Editor('description_type_formation', {
        toolbar: bar
    });
    editorDescr.render();

    YAHOO.util.Event.on('Valider', 'click', function() {
        editorDescr.saveHTML();
        var descr = editorDescr.get('element').value;

        var xhr = getXhr();
        // On défini ce qu'on va faire quand on aura la réponse
        xhr.onreadystatechange = function(){
            // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
            if(xhr.readyState == 4 && xhr.status == 200){

        }
        };
        var titre =  document.getElementById("intitule_type_formation").value;
        var data = 'description_type_formation='+descr+'&intitule_type_formation='+titre;

        xhr.open("POST",'index.php?m=formations&a=valide_ajout_type_form',true);
        xhr.send(data);
    });
}

function form_supprime_type_formation(id){
    var intitule = document.getElementById("nom_type_form_"+id).innerHTML;

    monForm = document.createElement("form");
    monForm.setAttribute('action', 'index.php?m=formations&a=valide_suppr_type');
    monForm.setAttribute('ENCTYPE', 'multipart/form-data');
    monForm.setAttribute("method", "POST");
    monForm.setAttribute("name", "suppr_type_formation");
    monForm.setAttribute("id", "suppr_type_formation");

    monForm.innerHTML =  "<div id='modalalertdiv_type_formation'><center><br />Etes-vous s&ucirc;r(e) de vouloir supprimer le type de formation \""+intitule+"\" ?<br/>ATTENTION : cette action supprimera toutes les formations contenues dans cette cat&eacute;gorie !<br />"+
    "<input type='hidden' value='"+id+"' name='id_type_formation' />"+
    "<br /><input type='button' name='Annuler' value='Annuler' onclick='modalwindow.hide();' /> " +
    "<input type='button' name='Valider' value='Valider' onclick='supprime_type();' /></center></div>";

    document.getElementById("modalalertdiv").appendChild(monForm);

    var larg = (document.body.clientWidth) / 2-225;
    var haut = (window.innerHeight/2)-250;

    if(window.innerHeight == null){
        haut = 10;
    }

    modalwindow = dhtmlmodal.open('modal', 'div', 'modalalertdiv',
        "Suppression", "width=450px,height=140px,left=" + larg
        + ",top=" + haut + ",resize=0,scrolling=1");
}

function supprime_type(){
    document.suppr_type_formation.submit();
}

function form_modifie_formation(id){

    var intitule = document.getElementById("intitule"+id).innerHTML;
    var descr = document.getElementById("description"+id).innerHTML;
    var phrase = "";
    if(document.getElementById("phrase_pdf"+id)){
        phrase = document.getElementById("phrase_pdf"+id).innerHTML;
    }
    var img = document.getElementById("img"+id).value;
    var apercu_img = "";
    if(img != ""){
        apercu_img = "<img src='img/img_formations/"+img+"' alt='image' width='30' title='image' />";
    }else{
        apercu_img = "Aucune";
    }

    var pdf = document.getElementById("pdf"+id).value;
    var apercu_pdf = "";
    if(pdf != ""){
        apercu_pdf = "<a href='docs/formations/"+pdf+"' target='_blank' />Visionner le document actuel</a>";
    }else{
        apercu_pdf = "Ancun";
    }

    var id_type = document.getElementById("type_form").value;

    var types = document.getElementById("types_form").value;
    types = types.split(";");
    var i;
    var select = "<select id='choix_type' name='choix_type' >";
    for(i=0;i<types.length-1 ; i++){
        if(document.getElementById("type_form").value == types[i]){
            select = select+"<option value='"+types[i]+"' selected >"+types[i+1]+"</option>";
        }else{
            select = select+"<option value='"+types[i]+"'>"+types[i+1]+"</option>";
        }
        i++;
    }
    select = select+"</select>";
  
    monForm = document.createElement("form");
    monForm.setAttribute('action', 'index.php?m=formations&a=valide_modif_formation');
    monForm.setAttribute('ENCTYPE', 'multipart/form-data');
    monForm.setAttribute("method", "POST");
    monForm.setAttribute("name", "modif_formation");
    monForm.setAttribute("id", "modif_formation");

    monForm.innerHTML =  "<div id='modalalertdiv_type_formation' class='yui-skin-sam' ><center><br/><table class='text_left' >"+
    "<tr><td>Intitul&eacute; : </td><td><input type='text' size='44' value=\""+intitule+"\" name='intitule_formation' id='intitule_formation' /></td></tr>"+
    "<tr><td>Description : </td><td><textarea cols='50' rows='5' id='description_formation' name='description_formation' >"+descr+"</textarea></td></tr>"+
    "<tr><td>Image actuelle : </td><td>"+apercu_img+"</td></tr>"+
    "<tr><td>Remplacer l'image : </td><td><input type='file' name='img' /></td></tr>"+
    "<tr><td>Document pdf actuel : </td><td>"+apercu_pdf+"</td></tr>"+
    "<tr><td>Changer le document pdf : </td><td><input type='file' name='pdf' /></td></tr>"+
    "<tr><td>Texte d'introduction au PDF : </td><td><textarea cols='50' rows='3' id='phrase_pdf_formation' name='phrase_pdf_formation' >"+phrase+"</textarea></td></tr>"+
    "<tr><td>Type de formation : </td><td>"+select+"</td></tr>"+
    "</table>"+
    "<input type='hidden' value='"+id+"' name='id_formation' />"+
    "<input type='hidden' value='"+id_type+"' name='type_form' />"+
    "<br /><input type='button' name='Annuler' value='Annuler' onclick='modalwindow.hide();' /> " +
    "<input type='submit' name='Valider' id='Valider' value='Valider' /></center></div>";

    document.getElementById("modalalertdiv").appendChild(monForm);

    var larg = (document.body.clientWidth) / 2-325;
    var haut = (window.innerHeight/2)-240;
    var h = 480;
    if(window.innerHeight == null){
        haut = 10;
        h=600;
    }

    modalwindow = dhtmlmodal.open('modal', 'div', 'modalalertdiv',
        "Modification de la formation", "width=650px,height="+h+"px,left=" + larg
        + ",top=" + haut + ",resize=0,scrolling=1");

    var editorDescr = new YAHOO.widget.Editor('description_formation', {
        toolbar: bar
    });
    editorDescr.render();

    var editorPhrase = new YAHOO.widget.Editor('phrase_pdf_formation', {
        toolbar: bar
    });
    editorPhrase.render();

    YAHOO.util.Event.on('Valider', 'click', function() {
        editorDescr.saveHTML();
        editorPhrase.saveHTML();
        var descr = editorDescr.get('element').value;
        var phrase = editorPhrase.get('element').value;

        var xhr = getXhr();
        // On défini ce qu'on va faire quand on aura la réponse
        xhr.onreadystatechange = function(){
            // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
            if(xhr.readyState == 4 && xhr.status == 200){

        }
        };
        var titre =  document.getElementById("intitule_formation").value;
        var type_form = document.getElementById('choix_type').options[document.getElementById('choix_type').selectedIndex].value;
        var data = 'phrase_pdf_formation='+phrase+'&description_formation='+descr+'&intitule_formation='+titre+'&choix_type='+type_form;

        xhr.open("POST",'index.php?m=formations&a=valide_modif_formation',true);
        xhr.send(data);
    });
}

function form_ajoute_formation(){
    var id_type = document.getElementById("type_form").value;

    monForm = document.createElement("form");
    monForm.setAttribute('action', 'index.php?m=formations&a=valide_ajout_formation');
    monForm.setAttribute('ENCTYPE', 'multipart/form-data');
    monForm.setAttribute("method", "POST");
    monForm.setAttribute("name", "ajout_formation");
    monForm.setAttribute("id", "ajout_formation");

    monForm.innerHTML =  "<div id='modalalertdiv_formation' class='yui-skin-sam' ><center><br/><table class='text_left' >"+
    "<tr><td>Intitul&eacute; : </td><td><input type='text' size='44' name='intitule_formation' id='intitule_formation' /></td></tr>"+
    "<tr><td>Description : </td><td><textarea cols='50' rows='5' name='description_formation' id='description_formation' ></textarea></td></tr>"+
    "<tr><td>Image : </td><td><input type='file' name='img' id='img' /></td></tr>"+
    "<tr><td>Document pdf : </td><td><input type='file' name='pdf' id='pdf' /></td></tr>"+
    "<tr><td>Texte d'introduction au PDF : </td><td><textarea cols='50' rows='5' id='phrase_pdf_formation' name='phrase_pdf_formation' ></textarea></td></tr>"+
    "</table>"+
    "<input type='hidden' value='"+id_type+"' name='type_form' />"+
    "<br /><input type='button' name='Annuler' value='Annuler' onclick='modalwindow.hide();' /> " +
    "<input type='submit' id='Valider' name='Valider' value='Valider' /></center></div>";

    document.getElementById("modalalertdiv").appendChild(monForm);

    var larg = (document.body.clientWidth) / 2-325;
    var haut = (window.innerHeight/2)-250;
    var h = 390;
    if(window.innerHeight == null){
        haut = 10;
        h= 530;
    }

    modalwindow = dhtmlmodal.open('modal', 'div', 'modalalertdiv',
        "Ajout d'une formation", "width=650px,height="+h+"px,left=" + larg
        + ",top=" + haut + ",resize=0,scrolling=1");

    var editorDescr = new YAHOO.widget.Editor('description_formation', {
        toolbar: bar
    });
    editorDescr.render();
    var editorPhrase = new YAHOO.widget.Editor('phrase_pdf_formation', {
        toolbar: bar
    });
    editorPhrase.render();

    YAHOO.util.Event.on('Valider', 'click', function() {
        editorDescr.saveHTML();
        editorPhrase.saveHTML();
        var descr = editorDescr.get('element').value;
        var phrase = editorPhrase.get('element').value;

        var xhr = getXhr();
        // On défini ce qu'on va faire quand on aura la réponse
        xhr.onreadystatechange = function(){
            // On ne fait quelque chose que si on a tout reçu et que le serveur est ok
            if(xhr.readyState == 4 && xhr.status == 200){

        }
        };
        var titre =  document.getElementById("intitule_formation").value;
        var type_form = document.getElementById('choix_type').options[document.getElementById('choix_type').selectedIndex].value;
        var data = 'phrase_pdf_formation='+phrase+'&description_formation='+descr+'&intitule_formation='+titre+'&choix_type='+type_form;

        xhr.open("POST",'index.php?m=formations&a=valide_ajout_formation',true);
        xhr.send(data);
    });
}

function form_supprime_formation(id){
    var intitule = document.getElementById("intitule"+id).innerHTML;
    var id_type = document.getElementById("type_form").value;

    monForm = document.createElement("form");
    monForm.setAttribute('action', 'index.php?m=formations&a=valide_suppr_form');
    monForm.setAttribute("method", "POST");
    monForm.setAttribute("name", "suppr_formation");
    monForm.setAttribute("id", "suppr_formation");

    monForm.innerHTML =  "<div id='modalalertdiv_formation'><center><br />Etes-vous s&ucirc;r(e) de vouloir supprimer la formation \""+intitule+"\" ?<br/>"+
    "<input type='hidden' value='"+id+"' name='id_formation' />"+
    "<input type='hidden' value='"+id_type+"' name='type_form' />"+
    "<br /><input type='button' name='Annuler' value='Annuler' onclick='modalwindow.hide();' /> " +
    "<input type='button' name='Valider' value='Valider' onclick='supprime_form();' /></center></div>";

    document.getElementById("modalalertdiv").appendChild(monForm);

    var larg = (document.body.clientWidth) / 2-225;
    var haut = (window.innerHeight/2)-250;

    if(window.innerHeight == null){
        haut = 10;
    }

    modalwindow = dhtmlmodal.open('modal', 'div', 'modalalertdiv',
        "Suppression", "width=450px,height=120px,left=" + larg
        + ",top=" + haut + ",resize=0,scrolling=1");
}

function supprime_form(){
    document.suppr_formation.submit();
}
