
var xmlhttp;

function getXmlHttpRequest() {
  var xmlHttpObj;
  if (window.XMLHttpRequest) {
    xmlHttpObj = new XMLHttpRequest();
  } 
  else {
    try {
      xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        xmlHttpObj = false;
      }
    }
  }
  return xmlHttpObj;
};

function vote(iid, v) {
  xmlhttp = getXmlHttpRequest();
  url = '/3dartists/artgallery/vote?iid=' + iid + '&v=' + v
  xmlhttp.open('GET', url, true);
  xmlhttp.onreadystatechange = vote_callback;
  xmlhttp.send(null);
}

function vote_callback() {
   if (xmlhttp.readyState == 4) {
     if (xmlhttp.status == 200) {
       voteBox = document.getElementById('vote_box');
       voteBox.innerHTML = 'Your vote was submitted successfully. Thank you.';
     }
     else {
       voteBox = document.getElementById('vote_box');
       voteBox.innerHTML = 'Oops! An error occurred while processing your vote.';
     }
   }
   else if (xmlhttp.readyState == 2) {
     voteBox = document.getElementById('vote_box');
     voteBox.innerHTML = 'Processing vote...';
   }

}

var rated = false;
var rating_text = ['click on the stars to rate this image', 'bad', 'average', 'good', 'very good', 'perfect'];

var current_value = 0;

var img = new Image(20,17);
img.src = "/3dartists/design/star_on.gif";

function show_stars(value){
  if ((!rated) && (value != current_value)) {
    document.getElementById('rating_text').innerHTML = rating_text[value];
    for (var i = 1; i <= value; i++) {
      document.getElementById('hv' + i).innerHTML = '<img src="/3dartists/design/star_on.gif" alt="1" width="20" height="17" />';
    }
    for (var i = value + 1; i <= 5; i++) {
      document.getElementById('hv' + i).innerHTML = '<img src="/3dartists/design/star_off.gif" alt="0" width="20" height="17" />';
    }
    current_value = value;
  }
}

function rate(iid, v) {
  if (!rated) {
    xmlhttp = getXmlHttpRequest();
    url = '/3dartists/artgallery/rate?iid=' + iid + '&v=' + v
    xmlhttp.open('GET', url, true);
    xmlhttp.onreadystatechange = rate_callback;
    xmlhttp.send(null);
  }
}

function rate_callback() {
   rated = true;
   if (xmlhttp.readyState == 4) {
     if (xmlhttp.status == 200) {
       rateBox = document.getElementById('rating_text');
       rateBox.innerHTML = 'Your vote was submitted successfully. Thank you.';
     }
     else {
        //fkdmlfksdk;
       rateBox = document.getElementById('rating_text');
       rateBox.innerHTML = 'Oops! An error occurred while processing your vote.';
     }
   }
   else if (xmlhttp.readyState == 2) {
     rateBox = document.getElementById('rating_text');
     rateBox.innerHTML = 'Processing vote...';
   }

}
