// JavaScript Document
var VOTE_URL = "http://www.goodhostbadhost.com/castvote.php";
var VOTEREQUEST_ = null;

function DrawRateButtons(id){
document.getElementById("rating"+id).style.display='none';
document.getElementById("buttons"+id).style.display='inline';
}
function HideRateButtons(id){
document.getElementById("rating"+id).style.display='inline';
document.getElementById("buttons"+id).style.display='none';
}

function castVote(ID,voteID) {
  document.getElementById("rating"+ID).innerHTML="WAIT";
  VOTEREQUEST_ = new XMLHttpRequest();
  try {
    VOTEREQUEST_.open("GET", VOTE_URL+"?id="+ID+"&vote="+voteID+"&date="+Date(), true);
  } catch (e) {
 	document.getElementById("rating"+ID).innerHTML="ERR";
    VOTEREQUEST_ = null;
    return;
  }
  // Set the callback for when the downloading is completed (or failed)
  VOTEREQUEST_.onreadystatechange = onIPdata;

  // Start the download
  try {
    VOTEREQUEST_.send(null);
  } catch (e) {
	document.getElementById("rating"+ID).innerHTML="ERR";
  }
}

function onIPdata() {
  // Verify that the download completed
  if (VOTEREQUEST_.readyState != 4)  return;
  // show the new IP address
  //statusLabel.innerText = IPRequest_.responseText;
  txt=VOTEREQUEST_.responseText;
  //alert(txt);
  
  cmd=txt.substr(0,2);
  par=txt.substr(2);
  
  //alert(cmd+":"+par);
  
  if(cmd=="OK"){	
  	p = par.split(",");
	id=p[0];
	rating=p[1];
	document.getElementById("rate"+id).innerHTML=rating;
  }else if(cmd=="ER"){
    //error = p[1];
  }
  
  //statusLabel.visible = true;
  // Destroy the XMLHttpRequest object since it isn't being used anymore
  VOTEREQUEST_ = null;
}
