function 
updateRating(request) 
	{
/* alert(request.responseText);  // DEBUGGING  */
	var resp_arr = request.responseText.split("||");
	if (resp_arr[0] == 'ERR') 
		{
		//alert(resp_arr[1]);
		var type = resp_arr[1];
		var id = resp_arr[2];
        var thanks = document.getElementById("thanks" + type +  id);
        if (thanks) 
			{
			thanks.innerHTML =  resp_arr[3]; 
			}
		}

	if (resp_arr[0] == 'OK') 
		{
		var type = resp_arr[1];
		var id = resp_arr[2];
		var r = parseInt(resp_arr[3]);
		var b = 5;
		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);
		var thanks = document.getElementById("thanks" + type +  id);
		if (thanks) 
			{
			thanks.innerHTML =  "Grazie per il voto"; 
			}

		}
	}

function pushRating(type,id,r,b,total,count,a,e) 
	{
//	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/AjaxRating/mt-vote.cgi', {postBody: 'obj_type='+type+'&r='+r+'&obj_id='+id+'&blog_id='+b+'&a='+a+'&entry_id='+e, 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 / 5 * 80);
	var span_avg = document.getElementById("ajaxrating_" + type + "_" + id + "_avg");
	if (span_avg) {span_avg.innerHTML = avg; }
	var span_ttl = document.getElementById("ajaxrating_" + type + "_" + id + "_ttl");
	if (span_ttl) {span_ttl.innerHTML =  total + r; }
	var span_cnt = document.getElementById("ajaxrating_" + 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 =  new_width.toString() + "px"; }
	var thumb = document.getElementById("thumb" + type +  id);
	if (thumb) {thumb.innerHTML =  ""; }
/*
	var thanks = document.getElementById("thanks" + type +  id);
	if (thanks) 
		{
		thanks.innerHTML =  "Grazie per il voto"; 
		}
*/
	}

/*------------------------------- manageBestRate -----------------------------*/
function 
manageBestRate(minRate)
	{
	p = new Array();
	tt = document.all.tags("DIV");
	for(j = 0; j < tt.length; j++)
		{
		if(tt(j).id.toUpperCase().indexOf("COMMENT-") != -1)
			{
			dat = tt(j).id.split('-');
			if(minRate * 1 > dat[3] * 1)
				tt(j).style.display = "none";
			else
				{
				if(dat[1] * 1 > 0)
					{
					p.push('comment-0-' + dat[1] + '-');
					}
				}
			}
		}
	displayParent('comment-0-' , p);
	} // manageBestRate 

/*------------------------------- displayParent ----------------------------------*/
function 
displayParent (pref, owners)
	{
	par = document.all.tags("DIV");
	for(i = 0; i < par.length; i++)
		{
		if(par(i).id.toUpperCase().indexOf(pref.toUpperCase()) != -1)
			{
			for(ii = 0; ii < owners.length; ii++)
				{
				if(par(i).id.toUpperCase().indexOf(owners[ii].toUpperCase()) != -1)
					{
					dat = par(i).id.split('-');
					par(i).style.display = "block";
					change(dat[2]);
					break;
					}
				}
			}
		}
	} // displayParent 
/*------------------------------- vote----------------------------------*/
function 
vote (divvote, divrater)
	{
	document.getElementById(divvote).style.display='none';
	document.getElementById(divrater).style.display='block';
	} // vote

function 
sortDiv(a, b)
	{
	aa = a[0].split("-");
	bb = b[0].split("-");
	return parseFloat(bb[3]) - parseFloat(aa[3]);
	} // sortDiv

function 
MultiDimensionalArray(iRows, iCols) 
	{ 
	var a = new Array(iRows); 
	for (i = 0; i < iRows; i++)
		{ 
		a[i] = new Array(iCols); 
		} 
	return(a); 
	} // MultiDimensionalArray

function 
sortDivs(theID, theOrderID)
	{
	var theParentNode = document.getElementById(theID);
	var theParentOrderNode = document.getElementById(theOrderID);
	k = 0;
	for(i = 0; i < theParentNode.childNodes.length; i++)
		{
		if(theParentNode.childNodes[i].nodeType == 1 && theParentNode.childNodes[i].id)
			{
			vot = theParentNode.childNodes[i].id.split("-")[3];
			if(vot && vot  > 1)
				k++;
			}
		}
	currDivs = MultiDimensionalArray(k, 2);
	k = 0;
	for(i = 0; i < theParentNode.childNodes.length; i++)
		{
		if(theParentNode.childNodes[i].nodeType == 1 && theParentNode.childNodes[i].id)
			{
			vot = theParentNode.childNodes[i].id.split("-")[3];
			if(vot && vot > 1)
				{
				currDivs[k][0] = theParentNode.childNodes[i].id;
				currDivs[k][1] = theParentNode.childNodes[i];
				k++;
				}
			}
		}
	currDivs.sort(sortDiv);
	for(j = 0; j < currDivs.length; j++)
		{
		theParentNode.removeChild(currDivs[j][1]);
		theParentOrderNode.appendChild(currDivs[j][1]);
		}
	} // sortDivs

