﻿function startRequest()
{
  tfUserText = document.getElementById('tfUser').value;
  tfPassText = document.getElementById('tfPass').value;
  var btnWejdz = document.getElementById('btnWejdz');
  btnWejdz.disabled = true;

  passHash = hex_sha1(tfPassText);
  url = "http://tis.berbo.pl:800/login.php?user=" + tfUserText;
  url += "&pass=" + passHash;
  url = encodeURI(url);

  startGETRequest(url, onComplete, onEnd);
}

function onComplete(text, xml)
{
  if(text.substr(0, 5) == "error"){
    arr = text.split("\n");
    if(arr.length != 2){
      alert("Nieprawidłowa odpowiedź serwera.\n"+text);
    }
    else{
      alert(arr[1]);
    }
  }
  else{
//    var mainDiv = document.getElementById('mainDiv');
    var mainDiv = document.getElementById('container');
    mainDiv.innerHTML = text;
  }
}

function onEnd()
{
  var btnWejdz = document.getElementById('btnWejdz');
  if(btnWejdz)
    btnWejdz.disabled = false;
}