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

function saveDesc(imgName)
{
  tfDescTxt = document.getElementById('tfDesc').value;
  url = "http://localhost/galeria.php?desc=" + tfDescTxt;
  url += "&imgname=" + imgName;
  url = encodeURI(url);
  startGETRequest(url, onSDComplete, onEnd);
}

function onComplete(text, xml)
{
  arr = text.split("\n");
  if(arr.length == 2){
    if(arr[0] == 'error')
      alert(arr[1]);
    else
      alert("Nieprawidłowa odpowiedź serwera.");
  }
  else if(arr.length == 4){
    var img1 = document.getElementById('img1');
    var spanDiv = document.getElementById('spanDiv');
    var descDiv = document.getElementById('descDiv');
    var descDiv2 = document.getElementById('descDiv2');
    img1.src = arr[3];
    descDiv.innerHTML = arr[0];
    descDiv2.innerHTML = arr[1];
    spanDiv.innerHTML = arr[2];
  }
  else{
    alert("Nieprawidłowa odpowiedź serwera.");
  }
}

function onSDComplete(text, xml)
{
  if(text.substr(0, 5) == "error"){
    arr = text.split("\n");
    if(arr.length != 2){
      alert("Nieprawidłowa odpowiedź serwera.");
    }
    else{
      alert(arr[1]);
    }
  }
}

function onEnd()
{
}
