var req;

function rezerviraj()
{
  var query = '/index.php?a=mala_rezervacija_send&osoba=' + unicodeEscape(document.getElementById('r_osoba').value) +
              '&soba=' + unicodeEscape(document.getElementById('r_soba').value) +
              '&ime=' + unicodeEscape(document.getElementById('r_ime').value) +
              '&mail=' + unicodeEscape(document.getElementById('r_mail').value) +
              '&do=' + unicodeEscape(document.getElementById('r_do').value) +
              '&od=' + unicodeEscape(document.getElementById('r_od').value) +
              '&pusac=' + (document.getElementById('r_pusac').checked ? '1' : '0')+
              '&invalid=' + (document.getElementById('r_invalid').checked ? '1' : '0');

  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = processReqChange;
    req.open("GET", query);
    req.send(null);
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
      req.onreadystatechange = processReqChange;
      req.open("GET", query);
      req.send();
    }
  }
}

function processReqChange()
{
  if (req.readyState == 4) {
    if (req.status == 200) {
      document.getElementById('mfl').style.display = 'none';
      if (req.responseText == '1') {
        document.getElementById('mfg').style.display = 'block';
      } else if (req.responseText == '2') {
        document.getElementById('mfp').style.display = 'block';
      } else {
        document.getElementById('mfn').style.display = 'block';
      }
    }
  } else {
    document.getElementById('mf').style.display = 'none';
    document.getElementById('mfl').style.display = 'block';
  }
}

function show_mf()
{
  document.getElementById('mf').style.display = 'block';
  document.getElementById('mfg').style.display = 'none';
  document.getElementById('mfl').style.display = 'none';
  document.getElementById('mfn').style.display = 'none';
}

// Copyright & author: Atamyrat Mary, Turkmenistan - http://www.kanolife.com/escape/
function unicodeEscape (pstrString) {
  if (pstrString == "") {
    return "";
  }
  var iPos = 0;
  var strOut = "";
  var strChar;
  var strString = escape(pstrString);
  while (iPos < strString.length) {
    strChar = strString.substr(iPos, 1);
    if (strChar == "%") {
      strNextChar = strString.substr(iPos + 1, 1);
      if (strNextChar == "u") {
        strOut += strString.substr(iPos, 6);
        iPos += 6;
      }
      else {
        strOut += "%u00" +
                  strString.substr(iPos + 1, 2);
        iPos += 3;
      }
    }
    else {
      strOut += strChar;
      iPos++;
    }
  }
  return strOut;
}

// kalendar
var cals = [];

function cal (target_)
{
  this.popup = popup_cal;
  this.target = target_;

  this.id = cals.length;
  cals[this.id] = this;
}

function popup_cal (dt, name)
{

  var w = window.open(
    '/index.php?a=cal&date=' + dt + '&id=' + this.id,
    name, 'width=200,height=140,status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes');
  w.opener = window;
  w.focus();
}