$(document).ready(function() {
    $("#js").css("display", "none");
    $("#aide").css("display", "none");
    $("div.subleftmenu").corner("sc:#AAAAAA top").corner("sc:#CCCCCC bottom");

    LoadingEnd();
});

function LoadContent(loadurl, params, confirmation) {
    if (confirmation != undefined) {
        if (confirmation == false) {
            $("#confirm").fadeOut(500);
        } else {
            ConfirmAction(loadurl, params, confirmation);
//        if (!confirm(confirmation)) {return false;}
            return false;
        }
    }
    
    if (ReloadAccueil2Timer != undefined) {clearTimeout(ReloadAccueil2Timer);}
    if (UpdateDateTimer != undefined) {clearInterval(UpdateDateTimer);}
    var params2 = {header: 0};
    if (params) {jQuery.extend(params2, params);}

    LoadingStart();
    $("#content").load(loadurl, params2, LoadingEnd);
    return false;
}

function LoadSubContent(loadurl, destination, params, confirmation) {
    if (confirmation != undefined) {
        if (!confirm(confirmation)) {return false;}
    }
    
    var params2 = {header: 0};
    if (params) {jQuery.extend(params2, params);}

    $("#"+destination).slideUp(200);
    $("#"+destination).load(loadurl, params2, function() {$("#"+destination).slideDown(200);});
    return false;
}

function debug(aMsg) {
	setTimeout(function() { throw new Error("[debug] " + aMsg); }, 0);
}


loading = false;

function LoadingStart() {
    loading = true;
    $("#content").fadeTo(0.1, 300, function() {
        if (loading == true) {
            //$("#loading").show("fast");
            $("#loading").css("display", "block");
            //$("#loading").fadeIn(100);
        }
    });
}

function LoadingEnd() {
    loading = false;
    //$("h3").corner();
//    $("#content").prepend('<div id="fond"><img src="./img/fond.png" alt="fond" width="100%" height="100%"/></div>');
    
    $("#content a").Tooltip({showURL: false});
    $("#content input").Tooltip({showURL: false});
    $("#content").fadeTo(1, 300);
    //$("#loading").fadeOut(100);
    $("#loading").css("display", "none");
}

function HoverTable(target) {
    $(target+" .row1").hover(function(){
            $(this).removeClass("row1");
            $(this).addClass("row_hover");
        },function(){
            $(this).addClass("row1");
            $(this).removeClass("row_hover");
    });
    $(target+" .row2").hover(function(){
            $(this).removeClass("row2");
            $(this).addClass("row_hover");
        },function(){
            $(this).addClass("row2");
            $(this).removeClass("row_hover");
    });
}

function HoverCell(target, row) {
    $(target).hover(function(){
            $(this).removeClass("row"+row);
            $(this).addClass("row_hover");
        },function(){
            $(this).addClass("row"+row);
            $(this).removeClass("row_hover");
    });
}

function ConfirmAction(loadurl, params, confirmation) {
    $("#confirm").html('<p><strong>'+confirmation+'</strong></p><p><a href="#" onclick="LoadContent(\''+loadurl+'\', '+params+', false)">Confirmer</a></p><p><a href="#" onclick="DismissConfirm();">Annuler</a></p>');
    $("#confirm").fadeIn(500);
}

function ConfirmAction2(loadurl, confirmation) {
    $("#confirm").html('<p><strong>'+confirmation+'</strong></p><p><a href="'+loadurl+'">Confirmer</a></p><p><a href="#" onclick="DismissConfirm();">Annuler</a></p>');
    $("#confirm").fadeIn(500);
}

function DismissConfirm() {
    $("#confirm").fadeOut(500, function () {
        $("#confirm").html('&nbsp;');
    });
}

function DisplayHelp(id, cat, subcat) {
    $("#aide").load("aide.php5", {faq_id: id, section: cat, subsection: subcat}, function() {
        if ($("#aide").css("display") == "none") {
            $("#content").css("bottom", "110px");
            $("#aide").slideDown(200);
        }
    });
}

function HideHelp() {
    $("#aide").slideUp(200);
    $("#content").css("bottom", "10px");
}

function ResizeHelp() {
    if ($("#aide").css("height") == "100px") {
        $("#resizehelp").html("R&eacute;duire l'aide");
        $("#aide").css("height", "400px");
    } else {
        $("#resizehelp").html("Agrandir l'aide");
        $("#aide").css("height", "100px");
    }
}

function PopupUser(id) {
    $("#confirm").load("etc/dindons2.php5", {user_id: id}, function() {
        $("#confirm").fadeIn(400);
    });
}