http = '';

function setStars(id, rating) {
  http = createRequestObject();
  http.open('get', URL+'/ajax.php?action=rating&gameID='+id+'&rating='+rating);
  http.onreadystatechange = function() {
    if(http.readyState == 4){
      var response = parseInt(http.responseText);
  	
  		if (response > 0){
  			message = 'Vielen Dank.';
  		  initStars(id, response);
  		}
  		else {
  			message = 'Fehler beim Bewerten.';
  			initStars(id, rating);
  		}
    	document.getElementById('rating_'+id).innerHTML += '<br />'+message;
  
    }
  };
  http.send(null);
}

function initStars(id, rating) {
  var html = '';
  for(i=1;i<=rating;i++) {
    html += '<img id="rating_'+id+'_'+i+'" src="'+URL+'/images/star_full.gif" alt="Bewertung" />';
  }
  rating++;
  for(i=rating;i<=5;i++) {
    html += '<img id="rating_'+id+'_'+i+'" src="'+URL+'/images/star_empty.gif" alt="Bewertung" />';
  }
  var obj = document.getElementById('rating_'+id);
  obj.onmouseout = '';
  obj.innerHTML = html;
}

function showStars(id, rating) {
    for(i=1;i<=rating;i++) {
      document.getElementById('rating_'+id+'_'+i).src = URL+'/images/star_full.gif';
    }
    rating++;
    for(i=rating;i<=5;i++) {
      document.getElementById('rating_'+id+'_'+i).src = URL+'/images/star_empty.gif';
    }
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        ro = new XMLHttpRequest();
    }
    return ro;    
}