function SetTopGameImage(imageid, src)
{
	var img = document.getElementById(imageid);
	img.src = src;
}

var xmlhttp = CreateXmlHttp();
function Vote(type, id, vote)
{
	if (xmlhttp == null)
	{
		alert('Your browser does not support AJAX.');
	}
	else
	{
		xmlhttp.onreadystatechange = ProcessResponse;
		xmlhttp.open("POST", "/vote.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send("vote="+vote+"&type="+type+"&id="+id);
	}
	DisableVoting();
}

function ProcessResponse()
{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var result = xmlhttp.responseText;
		if (result.indexOf("Invalid") == 0)
		{
			alert("Error");
		}
		else if (result.indexOf("You") == 0)
		{
			alert(result);
		}
		else if (result.indexOf("|"))
		{
			res = result.split("|");
			
			var countUp = document.getElementById("countUp");
			countUp.innerHTML = res[0];
			
			var countDown = document.getElementById("countDown");
			countDown.innerHTML = res[1];
		}
		else if (result.indexOf(".png") > 0)
		{
			var pointer = document.getElementById("pointer");
			if (pointer != null)
			{
				pointer.src = result;
			}
		}
	}
}

function DisableVoting()
{
	var thumbUp = document.getElementById("thumbUp");
	var thumbDown = document.getElementById("thumbDown");
	thumbUp.onclick = null;
	thumbUp.style.cursor = "default";
	thumbDown.onclick = null;
	thumbDown.style.cursor = "default";
}

function CreateXmlHttp()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		// for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}
