function showIt(item,i,j,max,thema){
   var id;
   actualItem = item;
   thema_path = thema;

   // Show the selected boxes
   for (var x=1;x<=i;x++){
      id = item + "_" + x;
      document.getElementById(id).src = thema_path+"/images/rate/b.gif";
   }

   // Display the not selected ones
   for (var x=i+1;x<=max;x++){
      id = item + "_" + x;
      if (x<=j) document.getElementById(id).src = thema_path+"/images/rate/y.gif";
      else document.getElementById(id).src = thema_path+"/images/rate/w.gif";
   }
}

function showOriginal(i,max){
   for (var x=1;x<=max;x++){
      id = actualItem + "_" + x;
      if (x<=i) document.getElementById(id).src = thema_path+"images/rate/y.gif";
      else document.getElementById(id).src = thema_path+"images/rate/w.gif";
   }
}

// Get the HTTP Object
function getHTTPObject()
{
   var xhr = false;//set to false, so if it fails, do nothing
   if(window.XMLHttpRequest) //detect to see if browser allows this method
   {
      var xhr = new XMLHttpRequest(); //set var the new request
   }
   else
   if(window.ActiveXObject) //detect to see if browser allows this method
   {
      try
      {
         var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
      }
      catch(e) //if it fails move onto the next
      {
         try
         {
            var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
         }
         catch(e)
         {
            var xhr = false;
         }
      }
   }
   return xhr;//return the value of xhr
}

function responseProcessing(){
   var result;
   var data;
   var rating;
   var totalRates;
   var max;
   if(httpObject.readyState == 4)
   {
      if(httpObject.status == 200)
      {
         result = httpObject.responseText;
         data = result.split(':::');
         rating     = data[0];
         totalRates = data[1];
         max        = data[2];
         httpObject = null;
         removeActions(Math.round(rating),max);
         updateTextRating(actualItem,rating,totalRates);
      }
      else
      {

      }
   }
}

function removeActions(rating,max){
   showOriginal(rating,max);
   var t;
   for (var x=1;x<=max;x++){
      id = actualItem + "_" + x;
      t = document.getElementById(id);
      t.onmouseover = null;
      t.onmouseout  = null;
      t.onclick     = null;
   }
}

function updateTextRating(item,rating,total){
   var itemRating;
   var totalRating;
   var id;

   id = item + "_ir";
   itemRating = document.getElementById(id);
   id = item + "_tr";
   totalRating = document.getElementById(id);

   if (itemRating != null) itemRating.innerHTML = rating;
   if (totalRating != null) totalRating.innerHTML = total;

}

// Implement business logic
function submitRating(item,rate,max){
   httpObject = getHTTPObject();
   actualItem = item;
   if (httpObject != null) {
      httpObject.open("GET", "./script/rating/db/submitRating.php?item_rated="+item+"&item_rating="+rate+"&max_star="+max, true);
      httpObject.send(null); //send the request with parameters
      httpObject.onreadystatechange = responseProcessing;
   }
}
var actualItem = null;
var httpObject = null;
