function add_result()
{
	 postData = 'cc_playername=' + document.getElementById('cc_playername').value;
	 postData = postData + '&cc_score=' + document.getElementById('cc_score').value;
	 postData = postData + '&cc_device_id=' + document.getElementById('cc_device_id').value;
	 postData = postData + '&cc_gamename=' + document.getElementById('cc_gamename').value;
	 postData = postData + '&cc_hash=' + document.getElementById('cc_hash').value;
	 postData = postData + '&cc_prot_ver=' + document.getElementById('cc_prot_ver').value;

 // Передача данных
	 var req = getXmlHttpRequest();
	 req.onreadystatechange = function()
	 {
		 if (req.readyState != 4) return;
		 document.getElementById('results').innerHTML = req.responseText;
		 alert('Данные добавлены!');
	 }
 //асинхронный POST-метод
	 req.open("POST", "table_model.php", true);
	 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 req.setRequestHeader("Content-Length", postData.length);
 	req.send(postData);
}

function get_result(ver)
{
	 var req = getXmlHttpRequest();
	 req.onreadystatechange = function()
	{
		 if (req.readyState != 4) return;
		data = JSON.parse(req.responseText);
		jsonData = data.scores;
		text = "<table width=400 cellpadding=0 cellspacing=0 style=\"border:2px solid grey;\">";
		text += "<tr><td align=center width=60>Место</td><td align=left width=290>Имя</td><td align=center width=50>Очки</td></tr>";
		for (i=0;i<jsonData.length;i++)
		{
			j = i+1;
			text += "<tr><td align=center width=60>" + j + "</td><td align=left width=290>" + jsonData[i].playername + "</td><td align=center width=50>" +jsonData[i].score + "</td></tr>";
		}
		text += "</table>";
		text += "Уникальных айфонаф: "+data.devices;
		 document.getElementById('results').innerHTML = text;
		 
	 }
	 req.open("GET", "table_model.php?gamename=Strongholds"+ver+"&offset=0&limit=10&from=admin", true);
	 req.send(null);
}

function get_main()
{
	document.getElementById('scores').innerHTML = '';
	document.getElementById('content_main').style.display = 'block';
	document.getElementById('scores').style.display = 'none';
}

function get_results(ver)
{
	 var req = getXmlHttpRequest();
	 req.onreadystatechange = function()
	{
		 if (req.readyState != 4) return;
		data = JSON.parse(req.responseText);
		jsonData = data.scores;
		
		
		text ="<img src=\"img/files_ru/to_main_button_ru.png\" onclick=\"get_main()\" style=\"cursor: pointer; position:relative;\"/>";
		text +="<div id=\"old_ver_link\" style=\"cursor: pointer; position: relative;color:#646464; font-wieght:bold; font-size:small; text-decoration:underline; font-family:arial;\" onclick=\"get_results('')\">Рекорды версии 1.5</div>";
		text +="<div id=\"hiscore\" style=\"display:block; background-image: url(img/files_ru/top_back_ru.png); background-position: top; background-repeat: no-repeat;\">";
		text += "<div style=\"position: absolute; margin-top: 54px; margin-left:293px; font-weight:bold; font-size: 18pt; font-family:arial; color:#646464;\">"+data.count+"</div>";
		text += "<br /><br /><br /><br /><br /><br /><br /><br /><br /></div>";
		text += "<div id=\"best\" style=\"margin-top:0px;\"><table border=0 cellpadding=0 cellspacing=0>";
		text += "<tr><td style=\"height:72px; width: 91px; background: URL(img/files_ru/top_L.png) top no-repeat;\"></td>";
		text += "<td style=\"background: URL(img/files_ru/top_flexible.png) top repeat-x; text-align: center; vertical-align: top;\">";
		text += "<span style=\"color:#d3d3d3; font-wieght:bold; font-size:x-large; font-family:arial;\">"+jsonData[0].playername+"</span><br>";
		text += "<span style=\"color:#646464; font-wieght:bold; font-size:22pt; font-family:arial;\">"+jsonData[0].score+"</span></td>";
		text += "<td style=\"height:72px; width: 92px; background: URL(img/files_ru/top_R.png) top no-repeat;\"></td></tr></table></div>";
		text += "<div id=\"scoretable\" style=\"background: URL(img/files_ru/table_header_ru.png) top no-repeat; margin-right:35px;font-weight:bold; font-size: large; color:#3d3d3d; margin-top:10px;\">&nbsp;";
		
		for (i=0;i<jsonData.length;i++)
		{
			j = i+1;
			if (j%2 == 0)
			{
				text += "<div style=\"background: URL(img/files_ru/line_divider.png) top no-repeat; font:16pt Tahoma bold; color:#646464;\"><table border=0 cellpadding=0 cellspacing=0 width=340><tr><td align=center width=\"100\">";
				text += j+"</td><td align=left>"+jsonData[i].playername+"</td><td align=right>"+jsonData[i].score+"</td></tr></table></div>";				
				
			}
			else
			{
				text += "<div style=\" font:16pt Tahoma bold; color:#646464;\"><table border=0 cellpadding=0 cellspacing=0 width=340><tr><td align=center width=\"100\">";
				text += j+"</td><td align=left>"+jsonData[i].playername+"</td><td align=right>"+jsonData[i].score+"</td></tr></table></div>";				
			}
		}
		
		 document.getElementById('scores').innerHTML = text;
		 document.getElementById('content_main').style.display = 'none';
		 document.getElementById('scores').style.display = 'block';
		 
	 }
	 req.open("GET", "table_model.php?gamename=Strongholds"+ver+"&offset=0&limit=15&from=site", true);
	 req.send(null);
}

function get_results_eng(ver)
{
	 var req = getXmlHttpRequest();
	 req.onreadystatechange = function()
	{
		 if (req.readyState != 4) return;
		data = JSON.parse(req.responseText);
		jsonData = data.scores;
		
		
		text ="<img src=\"img/files_us/to_main_button_us.png\" onclick=\"get_main()\" style=\"cursor: pointer; position:relative;\"/>";
		text +="<div id=\"old_ver_link\" style=\"cursor: pointer; position: relative;color:#646464; font-wieght:bold; font-size:small; text-decoration:underline; font-family:arial;\" onclick=\"get_results_eng('')\">Ver. 1.5 records</div>";
		text +="<div id=\"hiscore\" style=\"display:block; background-image: url(img/files_us/top_back_us.png); background-position: top; background-repeat: no-repeat;\">";
		text += "<div style=\"position: absolute; margin-top: 54px; margin-left:293px; font-weight:bold; font-size: 18pt; font-family:arial; color:#646464;\">"+data.count+"</div>";
		text += "<br /><br /><br /><br /><br /><br /><br /><br /><br /></div>";
		text += "<div id=\"best\" style=\"margin-top:0px;\"><table border=0 cellpadding=0 cellspacing=0>";
		text += "<tr><td style=\"height:72px; width: 91px; background: URL(img/files_us/top_L.png) top no-repeat;\"></td>";
		text += "<td style=\"background: URL(img/files_us/top_flexible.png) top repeat-x; text-align: center; vertical-align: top;\">";
		text += "<span style=\"color:#d3d3d3; font-wieght:bold; font-size:x-large; font-family:arial;\">"+jsonData[0].playername+"</span><br>";
		text += "<span style=\"color:#646464; font-wieght:bold; font-size:22pt; font-family:arial;\">"+jsonData[0].score+"</span></td>";
		text += "<td style=\"height:72px; width: 92px; background: URL(img/files_us/top_R.png) top no-repeat;\"></td></tr></table></div>";
		text += "<div id=\"scoretable\" style=\"background: URL(img/files_us/table_header_us.png) top no-repeat; margin-right:35px;font-weight:bold; font-size: large; color:#3d3d3d; margin-top:10px;\">&nbsp;";
		
		for (i=0;i<jsonData.length;i++)
		{
			j = i+1;
			if (j%2 == 0)
			{
				text += "<div style=\"background: URL(img/files_us/line_divider.png) top no-repeat;font:16pt Tahoma bold; color:#646464;\"><table border=0 cellpadding=0 cellspacing=0 width=340><tr><td align=center width=\"100\">";
				text += j+"</td><td align=left>"+jsonData[i].playername+"</td><td align=right>"+jsonData[i].score+"</td></tr></table></div>";				
				
			}
			else
			{
				text += "<div style=\"font:16pt Tahoma bold; color:#646464;\"><table border=0 cellpadding=0 cellspacing=0 width=340><tr><td align=center width=\"100\">";
				text += j+"</td><td align=left>"+jsonData[i].playername+"</td><td align=right>"+jsonData[i].score+"</td></tr></table></div>";				
			}
		}
		
		 document.getElementById('scores').innerHTML = text;
		 document.getElementById('content_main').style.display = 'none';
		 document.getElementById('scores').style.display = 'block';
		 
	 }
	 req.open("GET", "table_model.php?gamename=Strongholds"+ver+"&offset=0&limit=15&from=site", true);
	 req.send(null);
}

function getXmlHttpRequest()
{
 if (window.XMLHttpRequest)
 {
 try
 {
 return new XMLHttpRequest();
 }
 catch (e){}
 }
 else if (window.ActiveXObject)
 {
 try
 {
 return new ActiveXObject('Msxml2.XMLHTTP');
 } catch (e){}
 try
 {
 return new ActiveXObject('Microsoft.XMLHTTP');
 }
 catch (e){}
 }
 return null;
}

