
var timer;
var this_dest_div;
var this_return_function;
var this_return_params;

function debutBoucle(dest_div, ajax_function) {
	timer = setInterval("ajaxRequete('" + dest_div + "', '" + ajax_function + "')", 10000);
	ajaxRequete(dest_div, ajax_function);
}

function finBoucle() {
	clearInterval(timer);
}

function reloadChat() {
	var t = setTimeout(reloadChat, 5000);
	ajaxRequete('data_chat', 'chat_reload');
}

//Wait a few seconds before checking if we're ready to go
function battleWait() {
	var t = setTimeout(battleWaitGo, 4000);
}

//Check if we're ready to go
function battleWaitGo() {
	ajaxRequete('rpg_battle', 'battle_wait', 'action_plugin=rpg');
}

function battleSendChips(chips, target) {
	string  = 'action_plugin=rpg';
	string += '&chips=' + chips.join('|');
	string += '&target=' + target;
	/*
	string = 'chips=';
	for (i = 0; i < chips.length; i++) {
		string += chips[i] + '|';
	}*/
	ajaxRequete ('rpg_battle', 'battle_send_chips', string, 'battleUpdate', '');
}

function battleUpdate(success, percent) {
	if (typeof success == 'undefined')	success = false;
	if (typeof percent == 'undefined')	percent = 0;
	if (percent != 0) {
		ajaxRequete ('rpg_battle', 'battle_update', 'action_plugin=rpg&success=true&percent=' + percent);
	} else if (success) {
		ajaxRequete ('rpg_battle', 'battle_update', 'action_plugin=rpg&success=true');
	} else {
		ajaxRequete ('rpg_battle', 'battle_update', 'action_plugin=rpg&success=false');
	}
	//Update the opponents' display
	ajaxRequete ('rpg_battle_left', 'battle_update_player', 'action_plugin=rpg');
	ajaxRequete ('rpg_battle_right', 'battle_update_opponent', 'action_plugin=rpg');
}

function battleUpdateWaitSleep() {
	var t = setTimeout(battleUpdateWait, 3000);
}

function battleUpdateWait() {
	ajaxRequete ('rpg_battle', 'battle_update_wait', 'action_plugin=rpg');

	//Update the opponents' display
	ajaxRequete ('rpg_battle_left', 'battle_update_player', 'action_plugin=rpg&player=true');
	ajaxRequete ('rpg_battle_right', 'battle_update_opponent', 'action_plugin=rpg&player=false');
}
