var image1 = new Image();
image1.src = "layout/star.gif";

function changePic(num)
{
  for (var i=1; i<=num; i++)
  {
    document.getElementById("pic"+i).src = "layout/star.gif";
  }
  return true;
}

function resetPic()
{
  for (var i=1; i<=10; i++)
  {
    document.getElementById("pic"+i).src = "layout/dot.gif";
  }
  return true;
}

function sendmail(user)
{
  var tmp = 'mailto:'+user+'@janesgallery.com';
  location.href=tmp;
}

function showcomments()
{
  if (document.getElementById('morecomments').style.display != "block") {
    document.getElementById('morecomments').style.display = "block";
    document.getElementById('arrow').src = "layout/arrow-down.png";
  }
  else {
    document.getElementById('morecomments').style.display = "none";
    document.getElementById('arrow').src = "layout/arrow-right.png";
  }
}

function ratingdetails(id)
{
  ratingDetails = window.open("ratingdetails.php?id="+id, "_blank", "height=220,width=300,location=no,menubar=no,scrollbars=no,toolbar=no,resizable=no,status=no,border=no");
  return false;
}

// AJAX-Routinen fuer das Rating
var xmlHttp;
function getXMLHttpRequest() 
{
  if (window.XMLHttpRequest) {
    // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
    return new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    try {   
      // XMLHTTP (neu) für Internet Explorer 
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {        
        // XMLHTTP (alt) für Internet Explorer
        return new ActiveXObject("Microsoft.XMLHTTP");  
      } catch (e) {
        return null;
      }
    }
  }
  return false;
}

function vote(id, points) {
  xmlHttp = getXMLHttpRequest();
  if (xmlHttp == null) {
    alert ("Sorry, your browser does not support AJAX!");
    return false;
  }
  var url="vote.php?id="+id;
  url=url+"&points="+points;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=readyStateHandlerVote;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function readyStateHandlerVote() {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200 || status == 304) {
      document.getElementById('ratingdiv').innerHTML=xmlHttp.responseText;
    }
    else {
      alert("Error: "+xmlHttp.status+" "+xmlHttp.statusText);
    }
  }
}

function addComment() {
  var words = document.forms['commentform'].elements['comment'].value.split(" ");
  if (words.length < 2) {
    alert("Please write a bit more than just one word. Thank you!");
    return false;
  }
  xmlHttp = getXMLHttpRequest();
  if (xmlHttp == null) {
    alert ("Sorry, your browser does not support AJAX!");
    return false;
  }
  var url="comment.php?id="+document.forms['commentform'].elements['id'].value;
  url=url+"&comment="+document.forms['commentform'].elements['comment'].value;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=readyStateHandlerComment;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  return false;
}

function readyStateHandlerComment() {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200 || status == 304) {
      var comments = document.getElementById('comments');
      var new_comment = document.createElement('div');
      new_comment.innerHTML=xmlHttp.responseText;
      comments.insertBefore(new_comment, comments.firstChild);
      document.getElementById('commentdiv').innerHTML="Thanks! Your comment has been saved<br>and will be visible after our approval.";
    }
    else {
      alert("Error: "+xmlHttp.status+" "+xmlHttp.statusText);
    }
  }
}