
// function générique d'envoi de requètes xmlhttprequest

function rateImg(rating, img)
{
  var xhr_object = null;

  if (window.XMLHttpRequest) // Firefox
     xhr_object = new XMLHttpRequest();
  else if (window.ActiveXObject) // Internet Explorer
     xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  else
  { // XMLHttpRequest non supporté par le navigateur
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
    return;
  }

  var method   = "POST";   
  var filename = "vote/maj.php";
  var data     = null;
  data = "rating="+rating+"&img="+img;

  xhr_object.open("POST", "vote/maj.php", true);

  xhr_object.onreadystatechange = function()
  {   
    if (xhr_object.readyState == 4)
    {
      var tmp = xhr_object.responseText.split(":");
      //alert(tmp[0]);
      
      rating_px = rating * 25;
      document.getElementById('current-rating').style.width = rating_px+'px';
      document.getElementById('ratelinks').style.display = 'none';
      document.getElementById('ratingtext').innerHTML = '&nbsp;&nbsp;Votre vote ('+rating+'/10) a bien été pris en compte.';
    }   
  }   

  xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

  xhr_object.send(data);
}
