// JavaScript Document
function vote(user,comment,type)
{
	document.getElementById('voteId').value = comment;
	makeRequest2('vote_comment.php?user=' + user + '&comment=' + comment + '&type=' + type);
}

function makeRequest2(url)
{	
	if (window.XMLHttpRequest) request2 = new XMLHttpRequest();
	else if (typeof ActiveXObject != "undefined")	request2 = new ActiveXObject("Microsoft.XMLHTTP");
	sendRequest2(url);
}

function sendRequest2(url)
{
	request2.onreadystatechange = onResponse2;
	request2.open("GET",url,true);
	request2.send(null);
}

function onResponse2()
{
	if(checkReadyState2(request2))
	{
		var response = request2.responseXML.documentElement;
		var note = response.getElementsByTagName('note')[0].firstChild.data;
		if(note == "false") alert("Oops...You voted this comment in the past!");
		else
		{
			comment = response.getElementsByTagName('comment')[0].firstChild.data;
			total = response.getElementsByTagName('total')[0].firstChild.data;
			document.getElementById('vote' + comment).innerHTML = total + " Votes";
		}
	}
}

function checkReadyState2(obj)
{
	var voteid = document.getElementById('voteId').value;
	if(obj.readyState == 0){}
	if(obj.readyState == 1){}
	if(obj.readyState == 2){}
	if(obj.readyState == 3){}
	if(obj.readyState == 4)
		if(obj.status == 200)	return true;
		else if(obj.status == 404)	document.getElementById('vote' + voteid).innerHTML = "File not found";
		else document.getElementById('vote' + voteid).innerHTML = "there was a problem retrieving the XML";
}

