var loading = new Image();
loading.src = '/img/loading.gif';

var xmlhttp;
var globaltarget = '';
var globalnum = 5;

function createRequestObject()
{
	var xmlhttp = null;

    if(window.XMLHttpRequest)
	{
        xmlhttp = new XMLHttpRequest();
    }else{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlhttp;
}

function sndRegVote(votepoint)
{
	var r_n = Math.random();
	var url = '/voting.php?voting='+votepoint+'&rn='+r_n;

	document.getElementById('voting').innerHTML = '<div style="padding:10px; text-align:center;"><img name="loader"></div>';
	document.images['loader'].src = loading.src;

	xmlhttp = createRequestObject();

	if (xmlhttp != null)
	{
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange = handleResponseVote;
		xmlhttp.send(null);
	}else
	{
		alert("Your browser does not support AJAX");
	}
}

function handleResponseVote()
{
	if(xmlhttp.readyState == 4)
	{
		if (xmlhttp.status==200)
		{
			var response = xmlhttp.responseText;

			if (response != '')
			{
				document.getElementById('voting').innerHTML = response;
			}else
			{
				document.getElementById('voting').innerHTML = 'cannot vote';
			}
		}else
		{
		    alert("Problem retrieving data:" + xmlhttp.statusText);
		}
    }
}