timeout = 5;

function startRequest(id)
{
  url = "http://localhost/index.php?id=" + id;
  url = encodeURI(url);
  startGETRequest(url, onComplete, onEnd);
}


function onComplete(text, xml)
{
  arr = text.split("\n");
  var div = document.getElementById("mainDiv");
  if(arr.length != 2){
    div.innerHTML = "Nieprawidłowa odpowiedź serwera.";
  }
  else if(arr[0] == 'error'){
    div.innerHTML = arr[1];
  }
  else{
    id = arr[0];
    div.innerHTML = "<img src='" + arr[1] + "' alt=''>";
    setTimeout("startRequest(" + id + ")", timeout * 1000);
  }
}

function onEnd()
{
}