function CalendrierDetail(d, m, y, section_id) {
    $("#calendrier_details").prepend("Chargement en cours<br/>");
    $.post("/calendrier", { d: d, m: m, y: y, section: section_id},
  function(data){
    $("#calendrier_details").hide("slide", {direction: 'down'}, 200, function() {
    $("#calendrier_details").html(data);
    $("#calendrier_details").show("slide", {direction: 'up'}, 200);
    });
  });

}

function Calendrier(m, y, dir, section_id) {
    $("#calendrier_entete").html("Chargement...");
    $("#calendrier_entete_g").html("&lt;&lt;");
    $("#calendrier_entete_d").html("&gt;&gt;");
    $.post("/calendrier", { m: m, y: y, section: section_id},
  function(data){
    $("#calendrier").hide("slide", {direction: (dir == 'l') ? 'left' : 'right'}, 200, function() {
    $("#calendrier").html(data);
    $("#calendrier").show("slide", {direction: (dir == 'l') ? 'right' : 'left'}, 200);
  });
});
}

function DeleteMessageFromOneliner(message_id) {
    $("#oneliner_message_"+message_id).html("Suppression en cours...");
    $.post("/oneliner/Xvz/supprimer", { id: message_id },
  function(data){
    if (data == "1") {$("#oneliner_message_"+message_id).html("Suppression effectu&eacute;e").hide("slide", {direction: 'up'}, 200);}
    else {$("#oneliner_message_"+message_id).html("Erreur lors de la suppression");}
  });
}

var c = 0;
$(document).ready(function() {
    $('#form_oneliner').submit(function() {
        if ($("#form_message").val().length == 0) {return false;}
        val = $("#form_oneliner_submit").attr("value");
        $("#form_oneliner_submit").attr("disabled", "disabled");
        $("#form_oneliner_submit").attr("value", "en cours");
        $(this).ajaxSubmit({dataType: 'json', success:    function(data) {
            if (data.result == '1') {
                $("#oneliner").prepend(data.content);
//                $("#oneliner_message_"+data.id).hide();
                $("#oneliner_message_"+data.id).show("slide", {direction :'up'}, 200);
                $("#form_message").val("");
                $("#form_oneliner_submit").removeAttr("disabled");
                $("#form_oneliner_submit").attr("value", val);
            } else {
                c++;
                $("#oneliner").prepend('<li id="oneliner_erreur_'+c+'">Une erreur est survenue</li>');
                $("#oneliner_erreur_"+c).show("slide", {direction :'up'}, 200, function() {
                    $(this).fadeOut(10000, function() {
                        $(this).remove();
                    });
                });
                $("#form_oneliner_submit").removeAttr("disabled");
                $("#form_oneliner_submit").attr("value", val);
            }
        }
        });
        return false;
    });
    
    calendrier_help = setTimeout('$("#calendrier_help").hide()', 1);

    $("#calendrier").mouseover(function() {
        $("#calendrier_help").fadeIn(300);
        clearTimeout(calendrier_help);
    });
    
    $("#calendrier").mouseout(function() {
        calendrier_help = setTimeout('$("#calendrier_help").fadeOut(500)', 1000);
    });

    $("#form_entry").keyup(function() {
        if ($("#form_entry").val() == "" || $("#form_entry").val().length > 2) {
            Search();
        }
    });
    
    $("#form_search").submit(function() {
        Search();
        return false;
    });
    
    $('#form_search_button').hide();
    
    
    
/*    $("#menuleft, #menuright").sortable({
			connectWith: '.menu',
			handle: 'h2',
			placeholder: 'ui-state-highlight',
			scroll: true,
			items: 'div',
			update: function(event, ui) {alert($("#menuleft").sortable('serialize')); alert($("#menuright").sortable('serialize'));},
		}).disableSelection();*/

    $('#form_sondage').submit(function() {
        val = $("#form_sondage :submit").attr("value");
        $("#form_sondage :submit").attr("disabled", "disabled");
        $("#form_sondage :submit").attr("value", "en cours");
        $(this).ajaxSubmit({dataType: 'json', success:    function(data) {
            if (data.result == '1') {
                $("#sondage").fadeOut(300, function() {
                    $("#sondage").html("Merci d'avoir voté!");
                    $("#sondage").fadeIn(300);
                });
            } else {
                c++;
                if (data.result == 0) {
                    explain = "Vous n'avez choisi aucune réponse";
                } else if (data.result == -1) {
                    explain = "Vous avez déjà voté pour ce sondage";
                } else {
                    explain = "Une erreur inconnue est arrivée";
                }
                
                $("#form_sondage").append('<p id="sondage_erreur_'+c+'">Une erreur est survenue : '+explain+'</p>');
                $("#sondage_erreur_"+c).show("slide", {direction :'up'}, 200, function() {
                    $(this).fadeOut(30000, function() {
                        $(this).remove();
                    });
                });
                $("#form_sondage :submit").removeAttr("disabled");
                $("#form_sondage :submit").attr("value", val);
            }
        }
        });
        return false;
    });
});


function Search() {
    if ($("#form_entry").val() == "") {
        $("#recherche_content").fadeOut(100);
        $("#content").show();
    } else {
        $.post("/recherche", { search: $("#form_entry").val()},
          function(data){
            $("#recherche_content").html(data);
            
    
/*            $("#recherche_content li a").mouseover(function() {
                $(this).parent().children("blockquote").slideDown(100);
            });
            
            $("#recherche_content li").mouseout(function() {
                $(this).children("blockquote").slideUp(100);
            });*/
            
          });
  
        if ($("#recherche_content").css("display") == "none") {
            $("#recherche_content").html("Recherche en cours...");
            $("#recherche_content").fadeIn(300, function() {
                $("#content").hide();
            });
        }
    }
}