

$(document).ready(function(){

	$('body').append('<a href="#" style="display:none" id="ajaxReady" >AjaxReady</a>');

	AjaxReady = $('#ajaxReady');
	AjaxReady.click(function(){
		return false
	});

	AjaxLoadBlock = $('#ajaxLoadingBlock') ;

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

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

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

	AjaxLoadBlock.hide();

});

/**
 * 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() ;
			}
		});
	}
}

