/*
 *  Description: Process votes using AJAX
 *  Author:      Ervin Nagy
 *  Copyright:   TopFeast (www.topfeast.com)
 */

var scrpt = "processvote.php";  // the server-side script
var http = getHTTPObject(); // the HTTP Object

// instantiating the HTTP Object
function getHTTPObject()
{
	var xmlhttp;
	
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (!xmlhttp)
		{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	return xmlhttp;
}

function ajaxVote(id,vType,i)
{
	document.getElementById('vReply' + vType + i).innerHTML = 'Processing...';
	http.open("GET", scrpt + "?id=" + escape(id) + "&t=" + escape(vType) + "&s=" + screen.width + "x" + screen.height, true);
	http.onreadystatechange = function()
								{
									if(http.readyState == 4)
									{
										if(http.status == 200)
										{
											document.getElementById('vReply' + vType + i).innerHTML = http.responseText;
										}
										else
										{
											document.getElementById('vReply' + vType + i).innerHTML = "Error (" + http.status + ") " + http.statusText;
										}
									}
								};
	http.send(null);
}

// toggle visibility of voting button
function enableVote(s) { document.getElementById(s).style.display = "inline"; }
function disableVote(s) { document.getElementById(s).style.display = "none"; }

