

function showIt(item,i,j,max){
   var id;
   actualItem = item;

   // Show the selected boxes
   for (var x=1;x<=i;x++){
      id = item + "_" + x;

    document.getElementById(id).src = "stars/rating_over.gif";
   }

   // Display the not selected ones
   for (var x=i+1;x<=max;x++){
      id = item + "_" + x;

      if (x<=j) document.getElementById(id).src = "stars/rating_on.gif";
      else document.getElementById(id).src = "stars/rating_off.gif";
   }
}

function showOriginal(i,max){
   for (var x=1;x<=max;x++){
      id = actualItem + "_" + x;
      if (x<=i) document.getElementById(id).src = "stars/rating_on.gif";
      else document.getElementById(id).src = "stars/rating_off.gif";
   }
}

// Get the HTTP Object
function getHTTPObject(){
   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
   else if (window.XMLHttpRequest) return new XMLHttpRequest();
   else {
      alert("Your browser does not support AJAX.");
      return null;
   }
}



function createRequestObject(){
	var ro;
	var roTimeout;
	  if (window.XMLHttpRequest) {
        try {
            ro = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            ro = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                ro = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }

    return ro;
}

 function submitRating(item,i,max,rating,count) {
   var alreadyvote=0;
   var t;
   var nrating=rating+i;
   var ncount=count+1;
    var vote=nrating/ncount;
    var nvote=vote.toFixed(2);
    //alert(nvote+" "+nrating+" "+ncount); 	var http = createRequestObject();
	http.open('GET', '/voting.php?topic_id='+escape(item)+'&vote='+escape(i)+'&r='+alreadyvote, true);
     http.onreadystatechange = function(){

		if(http.readyState == 4){
			   if(http.status == 200){
				A=http.responseText.split('|');
				if(A[0]==0){
								 vote=A[2];
                 document.getElementById('vote_count').innerHTML=nvote+' / '+ncount+' Votes';
               showOriginal(nvote,max);
                                  for (var x=1;x<=max;x++){
							      id = item + "_" + x;
							                          t = document.getElementById(id);
													         t.onmouseover = null;
													         t.onmouseout  = null;
													         t.onclick     = null;
               								 }
               								}
               								document.getElementById('vote_errmsg').innerHTML=A[1];
			                         }
		                         }
	                                       }

  http.send(null);
	return true;                   }


var httpObject = null;
var actualItem = null;

