$(document).ready(function(){

    AjaxLoadBlock = $('#ajaxLoadingBlock') ;

    AjaxLoadBlock.ajaxStart(function(){
        if(!isIE) $(this).fadeIn(400);
        else $(this).slideDown(400);
        });

    AjaxLoadBlock.ajaxSend(function(){
        AjaxWorking = token;
        });

    AjaxLoadBlock.ajaxStop(function(){
        if(!isIE) $(this).fadeOut(400);
        else $(this).slideUp(400);
        AjaxWorking = 0;
        ReadyScript();
        });

    AjaxLoadBlock.hide();

    $('body').append('<a href="#" style="display:none" id="ajaxReady" >AjaxReady</a>');
    AjaxReady = $('#ajaxReady');
    AjaxReady.click(function(){
        return false
    });

});

/**
 *  * Pour ajouter des scripts qui doivent s'éxécuter à chaque fois qu'une requête ajax est terminé
 *   * if(AjaxReady) AjaxReady.click(function(){ MaFonction(var1,var2); });
 *    */

function ReadyScript(){
    AjaxReady.trigger('click');
}


function loadUrl(url,datas,target,source,mode,callbackFunction){

    if(mode == '' || mode == undefined) mode = 'replace';

    if(url != ''){
        $.ajax({
            url: url,
            type: "get",
            data: datas+'&ajax=1',
            dataType: "html",
            success: function(response){
                if(source != '' && source != undefined ){
                    if(mode == 'append'){
                        $(target).append($(source,response).html());
                    }else{
                        $(target).html($(source,response).html());
                    }
                }else{
                    if(mode == 'append'){
                        $(target).append(response);
                    }else{
                        $(target).html(response);
                    }
                }
                if( $.isFunction(callbackFunction) ) callbackFunction() ;
            }
        });
    }
}


