function switchRating (itemId, numStars) {
	for(var i = 1; i <= 5; i++) {
		if(i <= numStars) {
			document.getElementsByName(itemId + "_star_" + i).item(0).src = "/itemdb/img/page/star_on.gif";
		} else {
			document.getElementsByName(itemId + "_star_" + i).item(0).src = "/itemdb/img/page/star_off.gif";
		}
	}
}

function ratingStats(caller, avg,count,usr) {
	infoElem = document.getElementById("itemInfo");
	infoElem.style.display = "block";
	/*var x = getElementPosition(caller).left;
	var y = (getElementPosition(caller).top - infoElem.clientHeight - 2);
	if(pageWidth() < screen.width) {
		x += Math.round((screen.width - pageWidth()) / 2);
	}
	infoElem.style.left = x + "px";
	infoElem.style.top = y + "px";*/
	setItemInfoPosition(caller);
	infoElem.style.left = (infoElem.style.left + 30) + "px";
	infoElem.style.top = (infoElem.style.top - 60) + "px";
	infoElem.innerHTML = count + " Bewertungen<br />Durchschnitt: " + avg + "<br />Eigene: " + usr;
}
	
function displayItemInfo(img) {
	infoElem = document.getElementById("itemInfo");
	infoElem.style.display = "block";
	infoElem.innerHTML = "<img src=\"/itemdb/img/page/" + img + "\" alt=\"" + img + "\" />";
}

function closeItemInfo() {
	if (infoElem) {
		infoElem.style.display = "none";
	}
	infoElem = null;
}

/*function moveItemInfo(e) {
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (infoElem != null) {
		infoElem.style.left = (x + 20) + "px";
		infoElem.style.top   = (y + 20) + "px";
	}
}*/

function rate(type2, itemid, value) {
	http_request = false;
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!http_request) {
		alert('Error receiving form data (1)...');
		return false;
	}
	http_request.onreadystatechange = doneRating;
	http_request.open('GET', '/itemdb/rate/' + type2 + '/' + itemid + '/' + value + '/1/', true);
	http_request.send(null);
}

function doneRating() {
	
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var doc = http_request.responseText;
			var values = doc.split(",");
			var div = document.getElementById("rating_" + values[1]);
			div.innerHTML = values[2];
			div.onmouseover = new Function("ratingStats(this, " + values[3] + "," + values[4] + "," + values[5] + ")");
			div.onmouseout = new Function("closeItemInfo()");
		} else {
			alert('Error receiving form data (' + http_request.status + ')...');
		}
	}
}