function initLbAutors()
{
  url = "http://localhost/dane.php?id=autors";
  startGETRequest(url, onAutorsComplete, onEnd);
}

function onAutorsComplete(text, xml)
{
  autors = text.split("\n\n");
  if(autors[0] == "error"){
    if(autors.length == 2){
      alert(autors[1]);
    }
    else{
      alert("Błąd podczas przetwarzania danych.");
    }
  }
  else{
    var lbAutors = document.getElementById('lbAutors');
    lbAutors.options.length = 0;
    lbAutors[0] = new Option("Wybierz autora", "");

    for(i = 0; i < autors.length; i++){
      items = autors[i].split("\n");
      if(items.length == 2){
        lbAutors[i + 1] = new Option(items[0], items[1]);
      }
    }
    lbAutors.disabled = false;
  }
}

function lbBooksChange()
{
  var div = document.getElementById("dataDiv");
  var lbBooks = document.getElementById("lbBooks");
  id = lbBooks[lbBooks.selectedIndex].value;
  if(id == "") return;

  tytul = lbBooks[lbBooks.selectedIndex].text;
  str = "Wybrana została książka " + tytul;
  str += " o identyfikatorze " + id + ".";
  div.innerHTML = str;
}

function lbAutorsChange()
{
  var lbAutors = document.getElementById("lbAutors");
  var id = lbAutors[lbAutors.selectedIndex].value;
  if(id == "") return;

  var lbBooks = document.getElementById("lbBooks");
  lbBooks.disabled = true;

  url = "http://localhost/dane.php?id=" + id;
  startGETRequest(url, onBooksComplete, onEnd);
}

function onBooksComplete(text, xml)
{
  books = text.split("\n\n");
  if(books[0] == "error"){
    if(rows.length == 2){
      alert(books[1]);
    }
    else{
      alert("Błąd podczas przetwarzania danych.");
    }
  }
  else{
    var lbBooks = document.getElementById('lbBooks');
    lbBooks.options.length = 0;
    lbBooks[0] = new Option("Wybierz książkę", "");

    for(i = 0; i < books.length; i++){
      items = books[i].split("\n");
      if(items.length == 2){
        lbBooks[i + 1] = new Option(items[0], items[1]);
      }
    }
    lbBooks.disabled = false;
  }
}

function onEnd()
{
}
