var interval = 60;
var lastHour = -1;
var onprogress = false;

function startRequest()
{
  if(!onprogress){
    hour = (new Date()).getHours();
    if(hour == lastHour){
      setTimeout("startRequest()", interval * 1000);
      return;
    }
    lastHour = hour;

    url = "http://localhost/adv.php?hour=" + hour;
    onprogress = true;
    startGETRequest(url, onComplete, onEnd);
  }
  setTimeout("startRequest()", interval * 1000);
}

function onComplete(text, xml)
{
  arr = text.split("\n");
  if(arr.length == 2){
    if(arr[0] != "error"){
      imgEl = document.getElementById("advImg");
      linkEl = document.getElementById("advLink");
      imgEl.src = arr[0];
      linkEl.href = arr[1];
    }
  }
}

function onEnd(text, xml)
{
  onprogress = false;
}
