function GetXmlHttpObject() {
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

ratingxmlhttp=GetXmlHttpObject();
favxmlhttp=GetXmlHttpObject();
removerating=GetXmlHttpObject();


function rateGame(ratinglink) {
	ratingxmlhttp.onreadystatechange=ratingStateChanged;
	ratingxmlhttp.open("GET", ratinglink,true);
	ratingxmlhttp.send(null);
}

function ratingStateChanged() {
	if (ratingxmlhttp.readyState==4) {
		var response = ratingxmlhttp.responseText;
		
		document.getElementById("ratingspan").innerHTML+="<span id='thanks_for'><br />Thanks for your rating!</span>";
		document.getElementById("current-rating").style.width=ratingxmlhttp.responseText+"%";
		document.getElementById("game_rated").innerHTML = parseInt(document.getElementById("game_rated").innerHTML)+1;
		$('#click_remove').show(0);
		$('#click_rate').hide(0);
		$('.vote_').css('display', 'none');
	}
}

function remove_vote(link) {
	$('.vote_').css('display', 'inline');
	$('#click_remove').hide(0);
	$('#click_rate').show(0);
	$('#thanks_for').remove();
	
	removerating.onreadystatechange = function(){
		if (removerating.readyState==4) {
			document.getElementById("current-rating").style.width=removerating.responseText+"%";
			document.getElementById("game_rated").innerHTML = parseInt(document.getElementById("game_rated").innerHTML)-1;
		}
	}
	removerating.open("GET", link,true);
	removerating.send(null);
}

function modFav(favlink) {
	favxmlhttp.onreadystatechange=favStateChanged;
	favxmlhttp.open("GET", favlink ,true);
	favxmlhttp.send(null);
}



function favStateChanged() {
	if (favxmlhttp.readyState==4) {
		document.getElementById("favspan").innerHTML = favxmlhttp.responseText;
	}
}

