﻿/*

AJAX code for getting the online gaming stats.

*/

function initGameStats() {

	if (G_DEBUG_ON) { $('#debugTxt').text('loading tournament info...'); }
	clearTimeout(G_STATS_POLL_TIMER);
	
	$.getJSON("./includes/ajax/tournament_schedule.php", { }, function(json){
		// returns:		{"clickable":false,"title":"","items":[{"players":"2 693","tables":"489"}]}

		var players = json.items[0].players;
		var games = json.items[0].tables;
		
		// pads output to at least [n] characters and ensures that spaced padding are represented by non-breaking-space
		var sPlayers = (players + '');
		var sGames = (games + '');
		if (sPlayers.length < 4) { for (var i=sPlayers.length; i<4; i++) { sPlayers +='&nbsp;&nbsp;'; } }
		if (sGames.length < 4) { for (var i=sGames.length; i<4; i++) { sGames +='&nbsp;&nbsp;'; } }			
		$('#readout_players').html(sPlayers);
		$('#readout_games').html(sGames);
		
		if (G_STATS_POLL_DELAY > 0) { 
			// restarts the timer on a loop if the [G] timer delay is non-zero. 
			G_STATS_POLL_TIMER = setTimeout('initGameStats()', G_STATS_POLL_DELAY);
		}
		

    });	

	if (G_DEBUG_ON) { $('#debugTxt').text('tournament info finished loading.'); }


}

function initGameStats_two() {

	var local_debug = G_DEBUG_ON;
	G_DEBUG_ON = true;
	
	if (G_DEBUG_ON) { $('#debugTxt').text('loading tournament info...'); }
	//clearTimeout(G_STATS_POLL_TIMER);
	
	$.getJSON("./includes/ajax/tournament_schedule2.php", { }, function(json){
		// returns:		{"clickable":false,"title":"","items":[{"players":"2 693","tables":"489"}]}

		if (G_DEBUG_ON) { $('#debugTxt').text('tournament info json received'); }
		var players = json.items[0].players;
		var games = json.items[0].tables;
		
		// pads output to at least [n] characters and ensures that spaced padding are represented by non-breaking-space
		var sPlayers = (players + '');
		var sGames = (games + '');
		if (sPlayers.length < 4) { for (var i=sPlayers.length; i<4; i++) { sPlayers +='&nbsp;&nbsp;'; } }
		if (sGames.length < 4) { for (var i=sGames.length; i<4; i++) { sGames +='&nbsp;&nbsp;'; } }			
		$('#readout_players').html(sPlayers);
		$('#readout_games').html(sGames);
		
		if (G_STATS_POLL_DELAY > 0) { 
			// restarts the timer on a loop if the [G] timer delay is non-zero. 
			G_STATS_POLL_TIMER = setTimeout('initGameStats()', G_STATS_POLL_DELAY);
		}
		

    });	

	if (G_DEBUG_ON) { $('#debugTxt').text('tournament info finished loading.'); }

	G_DEBUG_ON = local_debug;

}
/*END OF FILE*/
