var difference=0;
var http = createRequestObject();
var thediv = "";

function setDifference(diff) {
	difference = diff;
}

function rateImg(rating,imgId)  {
		document.getElementById('current-rating'+imgId).style.width = (rating * 28)+'px';
		document.getElementById('frev'+imgId).selectedIndex  = rating + difference; 
		//difference should be 0 if "No Rating" is allowed, and -1 if not
}

function showImages(imgId) {
		document.getElementById('frev'+imgId).style.visibility = 'hidden';
		document.getElementById('ratingcontainer'+imgId).style.visibility = 'visible';
		return true;
}

//AJAX Components

function getUseful(comment_id, useful, div, ip) {
	thediv = div;
	http.open('get', '/wp-content/plugins/RatingDominator/frevuseful.php?id=' + comment_id + '&u=' + useful + '&ip=' + ip);
	http.onreadystatechange = handleInfo;
	http.send(null);
	return false;
}

function createRequestObject(){
	var request_;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_ = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_ = new XMLHttpRequest();
	}
	return request_;
}

function handleInfo(div){
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById(thediv).innerHTML = response;
	}
}

