function xmlHttp() {
	var xmlHttp;
	
	this.create = function() {
		try
		{
			//gecko
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			try
			{
				//IE
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					alert("Error");
					return false;
				}
			}
		}
		
		return xmlHttp;
	}
	
	this.addVote = function(vote, id) {
		xmlHttp = this.create(); //create the xmlhttp object
		node = document.getElementById("info_"+id); //where to send the info
		restore = node.innerHTML;
		
		xmlHttp.onreadystatechange = function() {
			switch(xmlHttp.readyState) {
				case 4:
					values = xmlHttp.responseText;
					if(values != "prev") {
						values = values.split(":");
						node.innerHTML = "Currently rated "+values[0]+" out of 5 stars<br>Your rating: "+values[1];
					
						document.getElementById("current_"+id).style.width = (28 * values[0])+"px";
					} else {
						node.innerHTML = restore;
						alert("You have previous voted on this");
					}
				break;
				case 1:
					node.innerHTML = "<img src=\"/loading.gif\" alt=\"Loading...\">";
				break;
			}
		}
		
		xmlHttp.open("GET", "/addvote.php?id="+id+"&vote="+vote, true);
		xmlHttp.send(null);
	}
}

var vote = new xmlHttp();