//HALL OF FAME - Weekly Table
$(document).ready(function(){ 
	$.get("/data/leader-board/halloffame.xml",{},function(xml){
	HTMLOutput = '';	
	$('hof-all',xml).each(function(i) {			
		HTMLOutput += '<table class="tbl_weekly" width="80%"><tr><th>Sijoitus</th><th>Pelaaja</th><th>Maa</th><th>Pisteet</th><th>Pvm.</th></tr>';
		$('hof-weekly ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			name = $(this).find("userID").text();
			country = $(this).find("country").text();
			var iniPoints = $(this).find("points").text();
			var makingLocal_Points = iniPoints.replace(/\,/g, " ");
			var points = makingLocal_Points.replace(/\.\b/, ",");
			var theLocalMonth = $(this).find("month").text();
			var theLocalDay = $(this).find("day").text();
			var year = $(this).find("year").text();
			
			var date = theLocalDay + '.' + theLocalMonth + '.' + year;
			
			mydata = buildWeeklyTable(place,name,country,points,date);
			HTMLOutput = HTMLOutput + mydata;
		});
		HTMLOutput += '</table>';
		$("#writeWeeklyTable").append(HTMLOutput);
	});
});
	
});
 //The HOF Weekly table
function buildWeeklyTable(place,name,country,points,date){
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '.</td>';
	output += '<td>'+ name +'</td>';
	output += '<td style="text-align:center;">'+ country +'</td>';
	output += '<td>'+ points +'</td>';
	output += '<td>'+ date +'</td>';
	output += '</tr>';
	return output;
}
//HALL OF FAME - Monthly Table
$(document).ready(function(){ 
	$.get("/data/leader-board/halloffame.xml",{},function(xml){
	HTMLOutput = '';	
	$('hof-all',xml).each(function(i) {			
		HTMLOutput += '<table class="tbl_monthly" width="80%"><tr><th>Sijoitus</th><th>K&auml;ytt&auml;j&auml;nimi</th><th>Maa</th><th>Pisteet</th><th>Kuukausi</th></tr>';
		$('hof-monthly ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			name = $(this).find("userID").text();
			country = $(this).find("country").text();
			var iniPoints = $(this).find("points").text();
			var makingLocal_Points = iniPoints.replace(/\,/g, " ");
			var points = makingLocal_Points.replace(/\.\b/, ",");
			var month = $(this).find("month").text();			
			var monthNames = { '1':'Tam', '2':'Hel', '3':'Maa', '4':'Huh', '5':'Tou', '6':'Kes', '7':'Hei', '8':'Elo', '9':'Syy', '10':'Lok', '11':'Mar', '12':'Jou'}; 
			year = $(this).find("year").text();			
			date = monthNames[month] + '-' + year;
			
			mydata = buildMonthlyTable(place,name,country,points,date);
			HTMLOutput = HTMLOutput + mydata;
		});
		HTMLOutput += '</table>';
		$("#writeMonthlyTable").append(HTMLOutput);
	});
});
	
});
 //The HOF Monthly table
function buildMonthlyTable(place,name,country,points,date){
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '.</td>';
	output += '<td>'+ name +'</td>';
	output += '<td style="text-align:center;">'+ country +'</td>';
	output += '<td>'+ points +'</td>';
	output += '<td>'+ date +'</td>';
	output += '</tr>';
	return output;
}
//HALL OF FAME - Yearly Table
$(document).ready(function(){ 
	$.get("/data/leader-board/halloffame.xml",{},function(xml){
	HTMLOutput = '';	
	$('hof-all',xml).each(function(i) {			
		HTMLOutput += '<table class="tbl_yearly" width="80%"><tr><th>Sijoitus</th><th>K&auml;ytt&auml;j&auml;nimi</th><th>Maa</th><th>Pisteet</th><th>Vuosi</th></tr>';
		$('hof-yearly ranking',xml).each(function(i) {
			place = $(this).find("place").text();
			name = $(this).find("userID").text();
			country = $(this).find("country").text();
			var iniPoints = $(this).find("points").text();
			var makingLocal_Points = iniPoints.replace(/\,/g, " ");
			var points = makingLocal_Points.replace(/\.\b/, ",");
			year = $(this).find("year").text();			
						
			mydata = buildYearlyTable(place,name,country,points,year);
			HTMLOutput = HTMLOutput + mydata;
		});
		HTMLOutput += '</table>';
		$("#writeYearlyTable").append(HTMLOutput);
	});
});
	
});
 //The HOF Yearly table
function buildYearlyTable(place,name,country,points,year){
	output = '';
	output += '<tr>';
	output += '<td>'+ place + '.</td>';
	output += '<td>'+ name +'</td>';
	output += '<td style="text-align:center;">'+ country +'</td>';
	output += '<td>'+ points +'</td>';
	output += '<td>'+ year +'</td>';
	output += '</tr>';
	return output;
}
