// AJAX
var load = "<img src='/soubory/load.gif' alt='načítám ...' class='center' />";
var xmlHttp;
function vytvorXMLHttpRequest() {
  if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }
}
function selectGun(id) {
  var url = "/zbrane_action.php?action=selectGun&id="+id;
  vytvorXMLHttpRequest();
  xmlHttp.onreadystatechange = function () { boxZbrane(id) };
  xmlHttp.open("GET", url, true);
  xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.send(null);
}
function boxZbrane(id) {
  if(xmlHttp.readyState == 4) {
    if(xmlHttp.status == 200) {   
      document.getElementById("boxZbrane"+id).innerHTML = xmlHttp.responseText;
    }
  }
}
function gunAction(action, id) {
  var url = "/zbrane_action.php?action="+action+"&id="+id;
  vytvorXMLHttpRequest();
  xmlHttp.onreadystatechange = boxGunAction;
  xmlHttp.open("GET", url, true);
  xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.send(null);
}
function boxGunAction() {
  if(xmlHttp.readyState == 4) {
    if(xmlHttp.status == 200) {
      document.getElementById("boxGunAction").innerHTML = xmlHttp.responseText;
    }
  }
}
function addPole(id) {
  var newID = id;
  newID++;
  var obsahPole = "<input type='text' name='pole"+id+"' size='20' maxlength='50' /> -> <input type='text' name='hodnota"+id+"' size='50' maxlength='200' /><br /><br /><div id='pole"+newID+"'><a href='javascript:void(0)' onclick=\"addPole('"+newID+"');\">Přidat pole</a></div>";
  document.getElementById("pole"+id).innerHTML = obsahPole;
}
function hlasuj(anketa, hlas) {
  var url = "/anketa.php?action=vote&anketa="+anketa+"&hlas="+hlas;
  vytvorXMLHttpRequest();
  xmlHttp.onreadystatechange = zobrazVysledekHlasovani;
  xmlHttp.open("GET", url, true);
  xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.send(null);
}
function zobrazVysledekHlasovani () {
  document.getElementById("anketa").innerHTML = load;
  if(xmlHttp.readyState == 4) {
    if(xmlHttp.status == 200) {   
      document.getElementById("anketa").innerHTML = xmlHttp.responseText;
    }
  }
}
function zkontrolujNick() {
  var nick = document.all["nick"].value;
  var url = "/register_action.php?action=nickControl&nick="+nick;
  vytvorXMLHttpRequest();
  xmlHttp.onreadystatechange = boxNickControl;
  xmlHttp.open("GET", url, true);
  xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.send(null);
}
function boxNickControl () {
  if(xmlHttp.readyState == 4) {
    if(xmlHttp.status == 200) {   
      if(xmlHttp.responseText == 'TRUE') {
        document.getElementById("boxNickStatus").innerHTML = "<span style='color:green'>Nick je volný</span> <br /> ";
      }
      else {
        document.getElementById("boxNickStatus").innerHTML = "<span style='color:red'>Nick je již obsazen</span> <br />";
        document.all["nick"].focus();
      }
    }
  }
}
function refreshCaptcha() {
    var numer = Math.round(Math.random()*1000);
    document.getElementById("captcha").src="/soubory/captcha.php?n="+numer ;
    //self.document['captcha'].src='/soubory/captcha.php';
}
function closeMessageBox() {
  document.getElementById('messageBox').style.display = 'none';
}
function addGrupe() {
    if(document.getElementById('skupina').value == 'new') {
      document.getElementById("addGrupeBox").innerHTML = "Název nové položky:<br /><input type='text' name='novy_nazev' size='75' class='left60' /><br /><br />";
    }
    else {
      document.getElementById("addGrupeBox").innerHTML = "";
    }
}
function controlAddLink() {
  if(document.all['skupina'].value != '' ) {
    if(document.all['nazev'].value != '' ) {
      if(document.all['url'].value != '' ) {
            return true;
      }
      else { document.getElementById("zprava").innerHTML = "Není vyplněna URL adresa"; return false; }
    }
    else { document.getElementById("zprava").innerHTML = "Není vyplněn název"; return false; }
  }
  else { document.getElementById("zprava").innerHTML = "Nebyla vybrána skupina"; return false; }
}
function controlAddItem() {
  if(document.all['skupina'].value != '' ) {
    if(document.all['nazev'].value != '' ) {
      if(document.all['editor1'].value != '' ) {
            return true;
      }
      else { document.getElementById("zprava").innerHTML = "Není vyplněna text článku"; return false; }
    }
    else { document.getElementById("zprava").innerHTML = "Není vyplněn název článku"; return false; }
  }
  else { document.getElementById("zprava").innerHTML = "Nebyla vybrána kategorie článku"; return false; }
}
