var timeout = 1;

function sendData()
{
  tfNickText = document.getElementById("tfNick").value;
  tfDaneText = document.getElementById("tfDane").value;
  if(tfNickText == ""){
    alert("Proszę wprowadzić nick.");
    return;
  }
  if(tfDaneText == ""){
    alert("Proszę wprowadzić wypowiedź.");
    return;
  }

  url = "http://localhost/chat.php?nick=" + tfNickText;
  url += "&dane=" + tfDaneText;
  url = encodeURI(url);
  startGETRequest2(url);
}

function startChat()
{
  id = (new Date()).getTime();
  url = "http://localhost/chat.php?rows=10&id=" + id;
  startGETRequest1(url);
  setTimeout("startChat();", timeout * 1000);
}

function requestEnd()
{
}

function requestCompleted1(text, xml)
{
  var chatDiv = document.getElementById("chatDiv");
  if(text.substr(0, 5) != "error"){
    chatDiv.innerHTML = text;
  }
  else{
    arr = text.split(":");
    if(arr.length != 2){
      chatDiv.innerHTML = "Otrzymano niepoprawne dane.";
    }
    else{
      chatDiv.innerHTML = arr[1];
    }
  }
}

function requestCompleted2(text, xml)
{
  if(text.substr(0, 5) == "error"){
    arr = text.split(":");
    if(arr.length != 2){
      alert ("Otrzymano niepoprawne dane.");
    }
    else{
      alert(arr[1]);
    }
  }
  else{
    document.getElementById("tfDane").value = "";
  }
}