var idg;
var xmlhttp;

function vote(id)
{
	idg = id;
	xmlhttp = null;
	
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (xmlhttp !== null)
	{
		xmlhttp.onreadystatechange = state_Change;
		xmlhttp.open("GET", "http://www.chucknorris.si/vote.php?fact=" + idg, true);
		xmlhttp.send(null);
	}
}

function state_Change() 
{
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
        {
			document.getElementById('vote_' + idg).innerHTML = xmlhttp.responseText;
			setTimeout(vote(), 3000);
        }
	}
} 

