// === Ajax global
function ajax_updater(destination,fichier,param,ajax_eval,async)
{
	if(typeof(Bulle) != 'undefined')
		Bulle.Hide();
	derniereajax = fichier;
	derniereparam = param+' (async:'+async+')';
	if(typeof(async) == 'undefined')
		async = true;
	if(destination && typeof(destination.indexOf) == 'function' && destination.indexOf('_message') > 0 && $(destination.substr(0,destination.indexOf('_message'))) && typeof($(destination.substr(0,destination.indexOf('_message')))) == 'object' && $(destination.substr(0,destination.indexOf('_message'))).style && !ajax_eval)
	{
		if(typeof(Game) == 'undefined')
			ajax_eval = '$(\''+destination.substr(0,destination.indexOf('_message'))+'\').show();';
		else
			ajax_eval = 'Game.div_setup(\''+destination.substr(0,destination.indexOf('_message'))+'\');';
	}
	if(typeof(fichier) != 'undefined' && fichier)
	{
		if(fichier.substring(fichier.length-4,fichier.length) == '.php')
			fichier = fichier.substring(0,fichier.length-4);
		if(typeof(destination) != 'undefined' && destination && $(destination))
		{
			new Ajax.Updater(destination,'ajax/'+fichier+'.php', 
			{
				onLoading:function(request)
				{
					if($('attente'))
						$('attente').show();
					//if($('contenu'))
					//	$('contenu').innerHTML = '<img src="images/attente.gif" class="attente" alt="Patientez..." />';
				},
				onComplete:function(request)
				{
					if($('attente'))
						$('attente').hide();
					if(typeof(IEPatchs) != 'undefined' && typeof(IEPatchs.applyall) != 'undefined')
						IEPatchs.applyall();
					if($('attente'))
						setTimeout("$('attente').hide()",100);
					if(ajax_eval)
					{
						eval(ajax_eval);
					}
					if(typeof(Bulle) != 'undefined')
						Bulle.Hide();
					if(typeof(Tri) != 'undefined')
						Tri.sortables_init();
					if($('date'))
			            $('date').innerHTML = ( (new Date().toLocaleDateString().ucfirst())+' - '+(new Date().toLocaleTimeString())+'.'+(new Date().getMilliseconds().toPaddedString(3)) );
				},
				parameters:'ajax=1'+(param?'&'+param:''),
				evalScripts:true, 
				asynchronous:async
			}
			);
		}
		else
		{
			new Ajax.Request('ajax/'+fichier+'.php', 
			{
				onLoading:function(request)
				{
				},
				onComplete:function(request)
				{
					if(typeof(IEPatchs) != 'undefined' && typeof(IEPatchs.applyall) != 'undefined')
						IEPatchs.applyall();
					if($('attente'))
						$('attente').hide();
					if(ajax_eval)
					{
						eval(ajax_eval);
					}
					if(typeof(Bulle) != 'undefined')
						Bulle.Hide();
				},
				parameters:'ajax=1'+(param?'&'+param:''),
				evalScripts:false, 
				asynchronous:async
			}
			);
		}
	}
}
