var http;
rateCite = function( ratingvalue, cite_id )
{
	if (window.XMLHttpRequest)
	{
		http = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	http.open("POST", "http://www.zitate-aphorismen.de/zitate/ratingeval_test.inc.php", true);
	http.onreadystatechange = confirmRating;
	http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http.send( "cite_id="+cite_id+"&ratingvalue="+ ratingvalue );
	return false;
}

confirmRating = function()
{
	if (http.readyState == 4)
	{
		data = http.responseText.split(" ");
		cite_id = data[2];		
		if (http.responseText.search(/error/) != -1)
		{
			errorCode = data[1];
		}
		else
		{
			rating_text = data[0];
			image_suffix = data[1];
			newNode = document.createElement("span");
			newClass = document.createAttribute("class");
			newClass.nodeValue = "ratingConfirm";
			newNode.setAttributeNode(newClass);
			newText = document.createTextNode("Bewertet ");
			newNode.appendChild(newText);
			document.getElementById( "ratingContainer"+cite_id ).appendChild(newNode);
			document.getElementById( "ratingimage"+cite_id ).removeAttribute("useMap");
			document.getElementById( "ratingimage"+cite_id ).src = "/images/rating"+image_suffix+".gif";
			document.getElementById( "ratingmap"+cite_id ).setAttribute("onmouseout", "hoverRate("+image_suffix+",'ratingimage"+cite_id+"');" );
			if( document.getElementById( "ratingInfo"+cite_id))
			{
				total = parseInt(document.getElementById( "ratingInfo"+cite_id ).firstChild.nodeValue.replace(/[\(\)]/g, ""));
				total++;
				document.getElementById( "ratingInfo"+cite_id ).firstChild.nodeValue = "("+total+")";
				title = total+(total == 1 ? " Bewertung" : " Bewertungen" )+" mit durchschnittlich "+rating_text+(rating_text == 1 ? " Punkt" : " Punkten");
				document.getElementById( "ratingInfo"+cite_id ).setAttribute("title", title );
			}
		}
	}
}