$(function() {
    $.getScript('/static/imio/common.js', function() {
    });
    // Change le titre de l'etape validation en valider. Demande specifique Mt St Guibert.
    $("ol.wcs-steps--list > li").last().find("span.wcs-step--label").html("Valider"); 
    // Si on trouve unhref sur une boite de demarches combo, alors, on desactive les liens.
    $("div.cell.wcsformsofcategorycell.unhref a").each(function(index, obj) {
        $(this).attr("href","#");
	$(this).css("color", "grey");
	$(this).css("cursor","default");
    });
    // temporairement dans la page demarche. msg d'avertissement.
    $("div.fullpage").prependTo("div#main-content");

    // restructurer le resume.
    var $plaine_content = $("div.form-validation div.pp_plaines div.content");
    var $new_presentation = "";
    var $pp_plaine_resume = $("div.form-validation div.pp_plaines label input");
    var $previous_week_number = "";
    $pp_plaine_resume.each(function(i) {
	//f39$element_S29_2020-07-13_53_availablexx
	var $input_parts = $(this).attr("name").split("_");
	var $week_number = $input_parts[1];
	var $current_date = $input_parts[2];
        var $day_date = $current_date.split("-")[2] + "/" + $current_date.split("-")[1] + "/" + $current_date.split("-")[0];
        if($(this).is(":checked") == true){
	    // Je traite une nouvelle semaine => nouvel intitule de semaine
	    if ($previous_week_number != $week_number) {
                if (i > 1) {
	            $new_presentation += "</ul></li></ul>";
	        }
	        $new_presentation += "<ul><li><span style='font-weight:bold;'>"+$week_number+"</span><ul>";
		$new_presentation += "<li>"+$day_date+"</li>";
	    }
	    else {
	    // Je traite un jour de la meme semaine
		$new_presentation += "<li>"+$day_date+"</li>";
	    }
	    $previous_week_number = $week_number;
	}
	if($pp_plaine_resume.length == i + 1) {
            $plaine_content.html("");
            $plaine_content.append($new_presentation);
	}
    });
}); /* end */
