var div_final;
var popupdyn_final;

function voir_page(ajax,popupdyn,div_tmp,argument1,argument2){
	afficher_loader(true);
	div_final = div_tmp;
	popudyn_final = popupdyn;
	var XHR = new XHRConnection();
	XHR.appendData("ajax", ajax);
	XHR.appendData("arg1", argument1);
	XHR.appendData("arg2", argument2);
	XHR.sendAndLoad("./ajax/voir_page.php", "POST", voir_page_retour);
}

var voir_page_retour = function (obj){
	var tabResult = obj.responseXML.getElementsByTagName('contenu');
	if (tabResult.length > 0){
		for (var i = 0; i < tabResult.length; i++){
			resultat = tabResult.item(i);
			$("#"+div_final).html(resultat.firstChild.nodeValue);
			if(popudyn_final){
				$("#popupdyn").draggable();
				$("#popupdyn").show('clip', '', 400, function() {} );
			}
			else{
				$("#"+div_final).show();
			}
		}
	}
	afficher_loader(false);
}

// Affiche le loader de la page principale
function afficher_loader( show ) {
	if( show ) {
		//$("#background_loader").css('opacity', 0.8).show();
		if( !$('#loader_aom').length ) {
			$("#div_loader").append("<div id='loader_aom'></div>");
			$('#loader_aom').flash( {
				swf: './flash/loading_AOM_combat.swf', height: "90px", width: "90px",
				params: { wmode:'transparent' },
				flashvars: { type: 'general' } 
			} );
		}
	}
	else {
		$("#background_loader").hide();
		$('#loader_aom').remove();
	}
}

// Met à jour la barre d'energie
function update_energie( val, max, pct ) {
	$("#barre_energie_pleine").css('width', pct+"px"); 
	$("#num_energie").attr('title', val+"/"+max);
	$("#num_energie").html( val+"/"+max );
}
// Met à jour la barre de vie
function update_pv( val, max, pct ) {
	$("#barre_pv_pleine").css('width', pct+"px"); 
	$("#num_pv").attr('title', val+"/"+max);
	$("#num_pv").html( val+"/"+max );
}
// Met à jour une div (argent,coins, etc...)
function update_stats( div, val ) {
	$("#"+div).val( val );
}

function AjaxVerificationSession( obj ) {
	var tabResult = obj.responseXML.getElementsByTagName('sessionexpire');
	if( tabResult.length > 0 ) {
		afficher_message( tabResult.item(0).firstChild.nodeValue );
		timer_deco = setTimeout("redirectionSession()", 2500);
    }
}
function redirectionSession() {
	window.location = "http://www.ageofmagic.net/index.php3";
}

// Affiche la div menu passée en paramètre
function afficherMenu( nom ) {
	$(".menu_secondaire").hide();
	$("#"+nom).show();
}


// ------------------------------------------------------------------------------------
var timer_message = 0;

// Ferme le bloc message
function closeMessage() {
	$("#bloc_message").fadeOut(500);
}

// Affiche le cadre message de la page principale
function afficher_message( txt ) {
	
	clearTimeout(timer_message);
	$("#bloc_message").hide();
	$("#message").html(txt);
	$('#message .tip').qtip( { style: { name: 'mystyle' } } );
	$('#message .doubletip').qtip( { style: { name: 'doubleTip' } } );
	$("#bloc_message").fadeIn(500);
	timer_message = setTimeout("closeMessage()", 4000);
}
