function updateRating(request) {
	//alert(request.responseText); 
	var resp_arr = request.responseText.split("||");
	if (resp_arr[0] == 'ERR') {
		alert(resp_arr[1]);
	}

	if (resp_arr[0] == 'OK') {
		var type = resp_arr[1];
		var id = resp_arr[2];
		var r = parseInt(resp_arr[3]);
		var b = 2;
		var total = parseInt(resp_arr[4]) - r;
        var count = parseInt(resp_arr[5]) -1;
        var a = 0;
//          var theUL = document.getElementById('rater_ul'+type+id); // the UL
//	        if (theUL) { theUL.innerHTML = '<li id="rater_li'+type+id+'" class="current-rating" style="width:0px"></div>'; }
        updatePage(type,id,r,b,total,count,a);
	}
}

function pushRating(type,id,r,b,total,count,a,num_units,image,w) {
	updatePage(type,id,r,b,total,count,a);
//		var theUL = document.getElementById('rater_ul'+type+id); // the UL
//		if (theUL) { theUL.innerHTML = '<div class="loading"></div>'; }
	new ajax('/cgi-bin/plugins/RatingSystem/mt-vote.cgi', {postBody: 'obj_type='+type+'&r='+r+'&obj_id='+id+'&blog_id='+b+'&a='+a+'&num_units='+num_units+'&image_file='+image+'&unit_width='+w, onComplete: updateRating});
}

function updatePage (type,id,r,b,total,count,a) {
                        var avg = Math.round(((total + r)/(count + 1))*10)/10;
                        var new_width =  Math.round(avg / 10 * 300);
                        var span_avg = document.getElementById("ratingsystem_" + type + "_" + id + "_avg");
                        if (span_avg) {span_avg.innerHTML = avg; }
                        var span_ttl = document.getElementById("ratingsystem_" + type + "_" + id + "_ttl");
                        if (span_ttl) {span_ttl.innerHTML =  total + r; }
                        var span_cnt = document.getElementById("ratingsystem_" + type + "_" + id + "_cnt");
                        if (span_cnt) {span_cnt.innerHTML =  count + 1; }
                        var rater_li = document.getElementById("rater_li" + type +  id);
                        if (rater_li) {rater_li.style.width =  "0px"; }
                        var thumb = document.getElementById("thumb" + type +  id);
                        if (thumb) {thumb.innerHTML =  ""; }
                        var thanks = document.getElementById("thanks" + type +  id);
                        if (thanks) {thanks.innerHTML =  "Thanks for voting!"; }
}
function reportComment (id,to) {
    if (confirm("Are you sure you want to report this item?")) {
        new ajax('http://telepixtvcgi.warnerbros.com/bin/report.cgi', {postBody: 'id='+id+'&to='+to, onComplete: updateRating});
        var comment = document.getElementById("comment-" + id);
        if (comment) {comment.style.display = "none"; }
    }
}

