var rate_xmlHttp
function rate(item,table,rating,numvotes,ratingtotal,ratingnum) 
{
rate_xmlHttp=GetXmlHttpObject()

Gitem = item;
Gratingtotal = parseFloat(ratingtotal);
Gratingnum = parseFloat(ratingnum);
Gnumvotes = parseFloat(numvotes);
Grating = parseFloat(rating);

   if (rate_xmlHttp==null)
   {
      alert ("Browser does not support HTTP Request")
      return
   }

   var rate_url = 'ajax/rate.php';
   var rate_params = "table="+table+"&item="+item+"&rating="+rating+"&numvotes="+numvotes+"&ratingtotal="+ratingtotal+"&ratingnum="+ratingnum;

   rate_xmlHttp.open("POST", rate_url, true);
   rate_xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   rate_xmlHttp.setRequestHeader("Content-length", rate_params.length);
   rate_xmlHttp.setRequestHeader("Connection", "close");
   rate_xmlHttp.onreadystatechange = rate_statechange;
   rate_xmlHttp.send(rate_params);
}
function rate_statechange() 
{
    if (rate_xmlHttp.readyState==4 && rate_xmlHttp.status == 200)
    { 
        document.getElementById(Gitem+'rateBubble').innerHTML= rate_xmlHttp.responseText;

        if((Gratingnum+Gnumvotes)>0){
           starrating = ((Gratingtotal+Grating)/(Gratingnum+Gnumvotes));
           starrating = Math.round(starrating*100)/100;
        }else{
           starrating = 0;
        }
        ratingpercent = (starrating*(100/4)*(.6));

        document.getElementById(Gitem+'starDisplay').title=starrating+' star rating';
        document.getElementById(Gitem+'starDisplay').alt=starrating+' star rating';

   if((Gratingnum+Gnumvotes)=='1'){
        document.getElementById(Gitem+'rateText').innerHTML=(Gratingnum+Gnumvotes)+' rating';
   }else{
        document.getElementById(Gitem+'rateText').innerHTML=(Gratingnum+Gnumvotes)+' ratings';
   }

        document.getElementById(Gitem+'rateText').style.left='-'+ratingpercent+'px';
        document.getElementById(Gitem+'rateFiller').width=ratingpercent;

    } 
}
