var img1=new Image();
img1.src="menu-images/menu_minus.gif";
var img2=new Image();
img2.src="menu-images/menu_minus_corner.gif";
var height = "height";
var width = "width";

var a = screen.height;
var b = screen.width;
document.cookie=height+"="+a;
//document.cookie=width+"="+b;
document.cookie=width+"="+winW();

//alert (width + " " + winW());

/* test funkcnosti JS */
var jsOK = false;
if (document.getElementById) {
  jsOK = true;
}

function winW(w) {
   if (!w) w = top;
   if (w.innerWidth)
      /* NN4 a kompatibilní prohlížeče */
      return w.innerWidth;
   else if
   (w.document.documentElement &&
   w.document.documentElement.clientWidth)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerWidth */
      return w.document.documentElement.clientWidth;
   else if
   (w.document.body && w.document.body.clientWidth)
      /* starší MSIE + MSIE6 v quirk režimu */
      return w.top.document.body.clientWidth;
   else
      return null;
}

function winH(w) {
   if (!w) w = top;
   if (w.innerHeight)
      /* NN4 a kompatibilní prohlížeče */
      return w.innerHeight;
   else if
   (w.document.documentElement &&
   w.document.documentElement.clientHeight)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      return w.document.documentElement.clientHeight;
   else if
   (w.document.body && w.document.body.clientHeight)
      /* starší MSIE + MSIE6 v quirk režimu */
      return w.top.document.body.clientHeight;
   else
      return null;
}


function kontrolalogin(formular)
{
    if (formular.elements[0].value == '')
      {
      alert("Jméno je nutno vyplnit. Prosím vyplňte jej.");
      formular.elements[0].focus();
      return false;
      }
    if (formular.elements[1].value == '')
      {
      alert("Heslo je nutno vyplnit . Prosím vyplňte jej.");
      formular.elements[1].focus();
      return false;
      }
    return true;
}
function kontrolaheslo(formular)
{
    if (formular.elements[1].value != formular.elements[2].value)
      {
      alert("Nová hesla se neshodují. Prosím opravte je.");
      formular.elements[1].focus();
      return false;
      }
    return true;
}

function kontrolaemail(formular) {
  var eml = formular.elements[0].value;
  if (eml.indexOf("@") < 0 || eml.indexOf(".") < 0) {
    alert("E-mail nemá správný formát. Prosím opravte jej.");
    formular.elements[0].focus();
    return false;
  }
  return true;
}

function Check_a_channels(f,el) { //v main.php - zaskrtava vsechny analogove kanaly
        for (var i=0;i<f.elements.length;i++) {
                var e=f.elements[i];
                if (e.id == 'channels_a[]')
                   if (!f.check_a_chan.checked) e.checked = false;
                   else e.checked = true;
        }
}
function Check_b_channels(f,el) { //v main.php - zaskrtava vsechny binarni kanaly
        for (var i=0;i<f.elements.length;i++) {
                var e=f.elements[i];
                if (e.id == 'channels_b[]')
                   if (!f.check_b_chan.checked) e.checked = false;
                   else e.checked = true;
        }
}
function Radio_disable(f,el) { //v options.php - prepina uzivatelske/defaultni nastaveni
  for (var i=0; i<f.elements.length; i++) {
    var e=f.elements[i];
    if (e.name != 'uzivatelske_nastaveni' && e.name != 'odesli' && e.name != 'id_technologies' && e.name != 'label_station' && e.name != 'type_station' && e.name != 'id_station' && e.name != 'uzivatelske_nastaveni_P')
      if (el == "uziv") e.disabled = false;
      else e.disabled = true;
  }
}

function chngDispArea(e,flag) {                         // zobrazovani stanic v oblastech menu, nahrada za change(e, corner)
  if(!document.all && !document.getElementById) {
    return;
  }
  var target = '';
  if (!flag) flag = 0;

  if (document.getElementById('menuRoot')) target = self;
  else {
    if (top.frames["leftmenuframe"].document.getElementById('menuRoot')) target = top.frames['leftmenuframe'];
  }

  var st="s"+e
  var ob="o"+e
  var target_st = target.document.getElementById(st);
  var target_ob = target.document.getElementById(ob);
  var plus = "menuFolder_closed.png";
  var minus = "menuFolder_open.png";
  //alert(plus + ob)

  if ((target_st.style.display == "" && flag == 0) || flag == 2) {
    target_st.style.display = "none";
    //target_ob.style.background = "url(menu-images/"+plus+") no-repeat";
    target_ob.src = "menu-images/"+plus+"";
  }
  else {
    if (flag < 2) {
      target_st.style.display = "";
      //target_ob.style.background = "url(menu-images/"+minus+") no-repeat";
      target_ob.src = "menu-images/"+minus+"";
    }
  }
}

function change(e, corner){                       // od spusteni viceurovnoveho menu se nepouziva
  if(!document.all&&!document.getElementById) {
    return;
  }

  var st="s"+e
  var ob="o"+e
  var plus = "menu_plus"+corner+".gif"
  var minus = "menu_minus"+corner+".gif"
  //alert(plus + ob)
  if (document.getElementById(st).style.display == "")
  {
    document.getElementById(ob).style.background="url(menu-images/"+plus+") no-repeat"
    document.getElementById(st).style.display = "none";
  }
  else
  {
    document.getElementById(ob).style.background="url(menu-images/"+minus+") no-repeat"
    document.getElementById(st).style.display = "";
  }
}

function kontrolaoblasti(formular)
{
    top.frames[1].document.location.reload(true);
    //leftmenuframe.document.location.reload(true);
    return true;
}

function kontrolaData(formular) {  // kontrola data pro zobrazeni tabulky souctu archivovaneho mesice
  if (formular.interval_sum.value == 12) {
    var int_sum_m = formular.int_sum_m.value;
    var int_sum_y = formular.int_sum_y.value;
    if (((int_sum_y < 2019 && int_sum_y > 2003) || (int_sum_y < 19 && int_sum_y > 3)) && (int_sum_m > 0 && int_sum_m < 13)) {
      //alert(int_sum_m+". "+int_sum_y)
    }
    else var spatne_datum = "Zadáno nesmyslné datum";
    if (spatne_datum) {
      alert(spatne_datum);
      return false;
    }
  }
  return true;
}

function odeslistanici(formular, b_export) {
  formular.method = "post";

  switch (b_export) {
    case 0:
     {
      formular.winWidth.value = winW();
      formular.winHeight.value = screen.availHeight ;
      formular.action = "act_sel.php";
      formular.target = "_blank"; 
      break;
     }
    case 1:
     {
      formular.action = "export_dta_station.php";
      formular.target = ""; 
      break;
     }
    case 2:
     {
      formular.winWidth.value = winW();
      formular.winHeight.value = screen.availHeight ;
      formular.action = "act_sel_sum.php";
      formular.target = "_blank"; 
      break;
     }
    case 3: // menu konfigurace
     {
      formular.action = "options_data.php";
      formular.target = "";
      formular.submit();
      break;
     }
    case 4: //export CSV
     {
      formular.action = "export_csv_station.php";
      formular.target = ""; 
      break;
     }
    
    case 5: // menu parametry
     {
      formular.action = "parametry.php";
      formular.target = "";
      formular.submit();
      break;
     }
    case 6:  // menu finance
     {
      formular.action = "finance.php";
      formular.target = "";
      formular.submit();
      break;
     }
    case 7:  // menu konfigurace parametru
     {
      formular.action = "prm_configure.php";
      formular.target = "";
      formular.submit();
      break;
     }
    case 8: // index.php - odesle formular
     {
      formular.submit();
      break;
     }
    case 9: // index.php - odesle formular
     {
      formular.reset();
      break;
     }
    case 10:  // menu nastaveni vybranych parametru
     {
      formular.action = "prm_set.php";
      formular.target = "";
      formular.submit();
      break;
     }
    /*case 11: { // zobrazeni kreditu
      formular.action = "finance.php";
      break;
    }*/
    case 12: { // export kreditu do CSV
      formular.action = "export_credit.php";
      //formular.target = "_blank";
      break;
    }
    case 13:  // menu upravy s namerenymi daty
     {
      formular.action = "data_set.php";
      formular.target = "";
      formular.submit();
      break;
     }
    case 14: { // menu konfigurace act_sel.php
      formular.action = "options_act_sel.php";
      formular.target = "";
      formular.submit();
      break;
    }
    case 15: { // menu konfigurace statistiky
      formular.action = "options_statistics.php";
      formular.target = "";
      formular.submit();
      break;
    }
    case 16: { // menu konfigurace sledovaciho agenta
      formular.action = "options_watchAgent.php";
      formular.target = "";
      formular.submit();
      break;
    }
    case 20:
     {
      formular.winWidth.value = winW();
      formular.winHeight.value = screen.availHeight ;
      formular.action = "detail_binaries.php";
      formular.target = "_blank"; 
      break;
     }

  }
   //formular.submit();  
}
/*
function style_display_int_sum (obj, value) { //pro rozeviraci nabidku intervalu sum
  var ted = new Date();
  if (obj.value == value) {  //archivovany mesic
    document.getElementById("t100").style.display = "none";
    document.getElementById("t101").style.display = "block";
  }
  else {
    if (obj.value == 13) {  //aktualni mesic
      document.getElementById("t110").value = ted.getMonth() + 1;
      document.getElementById("t111").value = ted.getYear();
    }
    if (obj.value == 11) {  //minuly mesic
      var pomDatM = ted.getMonth();
      var pomDatY = ted.getYear();
      if (pomDatM < 1) {
        pomDatM = 12;
        pomDatY--;
      }
      document.getElementById("t110").value = pomDatM;
      document.getElementById("t111").value = pomDatY;
    }
    document.getElementById("t100").style.display = "block";
    document.getElementById("t101").style.display = "none";
  }
}*/

function style_display_int(obj) { //pro rozeviraci nabidku
  var seznam_intervalu = new Array("int_graf","int_cal"); //(hodnota obj: 6, 7)
  var i = 6;
  for (i = 6; i < seznam_intervalu.length+6; i++) {
    if (obj.value == i) document.getElementById(seznam_intervalu[i-6]).style.display = "block"; //prvni prvek z nabidky se neotvira
    else document.getElementById(seznam_intervalu[i-6]).style.display = "none";
  }
}

/*function display_arch_month(obj, id, cislo) { //pro rozeviraci nabidku - arch. mesic
  if (obj.value == cislo)
    document.getElementById(id).style.display = "block";
  else
    document.getElementById(id).style.display = "none";
}*/
function selectBox_SumTable(obj) { //pro rozeviraci nabidku tabulky sum - nahrada za function display_arch_month(obj, id, cislo)
  for (var index in intervalsum) {
    if (intervalsum[index])
      document.getElementById(intervalsum[index]).style.display = "none";
  }
  if (intervalsum[obj.value])
    document.getElementById(intervalsum[obj.value]).style.display = "block";

  if (document.getElementById('int_calStat'))
    document.getElementById('int_calStat').style.display = (obj.value == 14)? 'block' : 'none'; 
}

function disp_mzMch(obj, id) { //pro zadani mezi u vicecaroveho grafu
   if (obj.value == "4")
      for (var i = 1; i < 5; i++)
        document.getElementById(id+i).style.display = "block";
   else
      for (var i = 1; i < 5; i++)
        document.getElementById(id+i).style.display = "none";
}

function style_display_nab(obj,index) { //pro rozeviraci nabidku bargrafu
    var seznam_bargrafu = new Array("bargraf_0m","bargraf_mm","bargraf_mz","bargraf_limn","bargraf_mch", "bargraf_wr","bargraf_hv","bargraf_bs","bargraf_sr");   //,"technologie");
    var i = 0;

    for (i = 0; i < seznam_bargrafu.length; i++) {
       if ((obj.value - 2) == i) document.getElementById(seznam_bargrafu[i]+index).style.display = "block"; //prvni prvek z nabidky se neotvira
       else document.getElementById(seznam_bargrafu[i]+index).style.display = "none";
    }

    hide_chcbKor(obj.value,index);
}

function onitem_b(obj, btext, bpoz) {
    obj.style.color = btext;
    obj.style.backgroundColor = bpoz;
}

function maxWindow() {
    window.moveTo(0,0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth,screen.availHeight);
    }
    else if (document.layers||document.getElementById) {
        if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

/* PRO NASTAVENI SLEDOVACIHO AGENTA - begining...*/
  function displayWa2Delete(obj,sel) {
    //document.getElementById("eml2del").style.display = (obj.value == sel)? "block" : "none";
  }

  var seznamUpozorneni = new Array("hodnLim","chAnalog","chBinar","chRele","hystLim");
  function display_upozorneni(obj,index) { //pro rozeviraci nabidku bargrafu
    for (var i = 0; i < seznamUpozorneni.length; i++) {
      document.getElementById(seznamUpozorneni[i]+index).style.display = "none";
    }
    // podle doplnkovych parametru
    switch (obj.value) {
      // hodnota limitu
      case '20':                                                            // Překročení nad mez
      case '21':                                                            // Pokles pod mez
                   document.getElementById(seznamUpozorneni[0]+index).style.display = "block";
                   document.getElementById(seznamUpozorneni[4]+index).style.display = "block";
                   break;
      // zadne paramery
      case '0':                                                             // Vypnuto
      case '1':                                                             // Alarm - nastavení
      case '2':                                                             // Alarm - zrušení
      case '5':                                                             // Výpadek napájení
      case '6':                                                             // Obnovení napájení
      case '3':                                                             // Nízké napětí AKU
      case '7':                                                             // Nízký kredit
      case '8':                                                             // Expirace kreditu
      case '9':                                                             // Chyba na měřících kanálech
      case '10':                                                            // Slovo v tabulce událostí
      case '22':                                                            // Chyba konkrétního kanálu
      case '25':                                                            // Sepnutí binárního kanálu
      case '26':                                                            // Vypnutí binárního kanálu
      case '29':                                                            // Sepnutí relé
      case '30':                                                            // Vypnutí relé
      case '40':                                                            // Nejde celá oblast
      case '41':                                                            // Nejde 60% oblasti
      default:     document.getElementById(seznamUpozorneni[0]+index).style.display = "none";
                   document.getElementById(seznamUpozorneni[4]+index).style.display = "none";
                   break;
    }
  
    // podle typu kanalu
    switch (obj.value) {
      // analogy
      case '20':                                                            // Překročení nad mez
      case '21':                                                            // Pokles pod mez
      case '22':                                                            // Chyba konkrétního kanálu
                   document.getElementById(seznamUpozorneni[1]+index).style.display = "block";
                   document.getElementById("dVyhInt"+index).style.display = "block";
                   break;
      // binary
      case '25':                                                            // Sepnutí binárního kanálu
      case '26':                                                            // Vypnutí binárního kanálu
                   document.getElementById(seznamUpozorneni[2]+index).style.display = "block";
                   document.getElementById("dVyhInt"+index).style.display = "block";
                   break;
      // rele
      case '29':                                                            // Sepnutí relé
      case '30':                                                            // Vypnutí relé
                   document.getElementById(seznamUpozorneni[3]+index).style.display = "block";
                   document.getElementById("dVyhInt"+index).style.display = "block";
                   break;
      case '10':                                                            // Slovo v tabulce událostí
                   document.getElementById("dVyhInt"+index).style.display = "block";
                   break;
      // vypnuty
      case '0':                                                             // Vypnuto
      case '1':                                                             // Alarm - nastavení
      case '2':                                                             // Alarm - zrušení
      case '5':                                                             // Výpadek napájení
      case '6':                                                             // Obnovení napájení
      case '3':                                                             // Nízké napětí AKU
      case '7':                                                             // Nízký kredit
      case '8':                                                             // Expirace kreditu
      case '40':                                                            // Nejde celá oblast
      case '41':                                                            // Nejde 60% oblasti
      default:     document.getElementById("dVyhInt"+index).style.display = "none";
                   break;
    }
    if (obj.value == '10') {
      document.getElementById("textPole"+index).style.display = "block";
    }
  
    document.getElementById("emlText"+index).value = textMailuSpPodm_ar[obj.value]; // text emailu
  
    if (obj.value == 0)
      document.getElementById("mail_"+index).style.display = "none";
    else
      document.getElementById("mail_"+index).style.display = "block";

    display_up2tmInt(index,obj,1);
  }

  //schovava checkboxy - minima/maxima, splneni podminky
  function display_up2tmInt(index,val,flag) {
    var podm_val = 0;
    var obd_vl = 0;
    switch (flag) {
      case 1: podm_val = val.value;
              //obd_vl = obd_val[index];
              obd_vl = document.getElementById("vInt"+index).value;
              break;
      case 2: podm_val = document.getElementById("podminka"+index).value;
              obd_vl = val.value;
              break;
    }
    if (podm_val >= 20 && podm_val < 40 && obd_vl > 0) {
      document.getElementById("cbx_HM_"+index).style.display = "block";
      if (podm_val <= 21) {
        document.getElementById("cbx_MM_"+index).style.display = "block";
      }
      else {
        document.getElementById("cbx_MM_"+index).style.display = "none";
      }
    }
    else {
      document.getElementById("cbx_HM_"+index).style.display = "none";
      document.getElementById("cbx_MM_"+index).style.display = "none";
    }
    
    if (podm_val == 40 || podm_val == 41) {
      document.getElementById("cbx_IJ_"+index).style.display = "none";
    }
    else {
      document.getElementById("cbx_IJ_"+index).style.display = "block";
    }

    if (podm_val == 10) {
      //alert(index+' -true- '+val.value+' -- '+flag);
      document.getElementById("cbx_CU_"+index).style.display = "block";
    }
    else {
      document.getElementById("cbx_CU_"+index).style.display = "none";
    }
  }

  function sendForm(id,el_id,el_val) {
    if (el_id) {
      document.getElementById(el_id).value = el_val;
    }
    document.getElementById(id).submit();
  }
  // kontrola emailove adresy
  function controlEmlList(pocRd) {
    var objAdresa = "";
    var adresa = "";
    var jmeno = "";
    for (var i = 0; i < pocRd; i++) {
      objAdresa = document.getElementById("emlAd"+i);
      adresa = document.getElementById("emlAd"+i).value;
      jmeno = document.getElementById("nmAd"+i).value;
      //if (i < 7) alert(i + ": " + adresa + " --- " + jmeno);
      if (adresa == "" && jmeno == "") continue;
      //alert(adresa + " --- " + jmeno);
      if (jmeno == "") {
        alert(strings4areaWatchAgent[0]);
        document.getElementById("nmAd"+i).focus();
        return false;
      }
      var pozice_zavinace = adresa.indexOf("@");
      if (pozice_zavinace < 0) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      var cast_pred_zavinacem = adresa.substring(0,pozice_zavinace);
      var cast_po_zavinaci = adresa.substring(pozice_zavinace+1,adresa.length);
      if (cast_po_zavinaci.indexOf("@") >= 0) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      if (cast_pred_zavinacem.length <= 0) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      if (cast_po_zavinaci.length <= 0) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      var pozice_posledni_tecky = cast_po_zavinaci.lastIndexOf(".");
      if (pozice_posledni_tecky < 0) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      var pocet_znaku_za_posledni_teckou = cast_po_zavinaci.length - pozice_posledni_tecky - 1;
      if (pocet_znaku_za_posledni_teckou < 2  ||  pocet_znaku_za_posledni_teckou > 3) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      var pozice_dvou_tecek_vedle_sebe = adresa.indexOf("..");
      if (pozice_dvou_tecek_vedle_sebe >= 0) {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      if (cast_pred_zavinacem.charAt(0) == "."  ||  cast_pred_zavinacem.charAt(cast_pred_zavinacem.length-1) == ".") {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
      if (cast_po_zavinaci.charAt(0) == "."  ||  cast_po_zavinaci.charAt(cast_po_zavinaci.length-1) == ".") {
          alert(strings4areaWatchAgent[1]);
          objAdresa.focus();
          return false;
      }
    }

    var toAlert = "";
    var pocAll = 0;
    var pocChck = 0;
    var form = document.getElementById('areaWatchAgent');
    var i_podmSet = document.getElementById('podminka0').value;
    var i_podmDel = document.getElementById('podm2del').value;
    var i_emlDel = document.getElementById('eml2del').value;
    var podm2delOff = (i_podmDel == 0)? true : false;
    var eml2delOff = (i_emlDel == 'mailOff')? true : false;
    var forArea = (i_podmSet == 40 || i_podmSet == 41 || i_podmDel == 40 || i_podmDel == 41 || i_emlDel.indexOf('§AR§') >= 0)? true : false;
    //alert(i_podmSet+' -- '+i_podmDel+' -- '+i_emlDel+' -- '+forArea);
    var osbID = document.getElementById('osbID0').value;
    for (var i = 0; i < form.elements.length; i++) {
      var el = form.elements[i];
      if (el.id.search(/^cbxSt\d{0,3}_/) >= 0) {
        if (document.getElementById(el.id).checked) pocChck++;
        pocAll++;
      }
    }
    alert(pocChck+' -- '+pocAll);

    if (podm2delOff && eml2delOff) {    // kontrola vyplneneho adresata pri nastaveni podminky
      if (osbID < 100) {
        if (!document.getElementById('emlAd'+osbID).value || !document.getElementById('nmAd'+osbID).value) {
          alert(strings4areaWatchAgent[2]);
          document.getElementById('nmAd'+osbID).focus();
          return false;
        }
      }
    }
    if (!forArea) {
      if (pocAll == pocChck) {    // zaskrtnute vsechny stanice
        return confirm(strings4areaWatchAgent[3]);
      }
      if (pocChck == 0) {         // nezaskrtnuta zadna stanice
        alert(strings4areaWatchAgent[4]);
        return false;
      }
    }
    return true;
  }
  // skrta vsechny stanice ze seznamu
  function chngAllStats(form,strName) {
    var first = true;
    var is_checked = true;
    for (var i = 0; i < form.elements.length; i++) {
      var el = form.elements[i];
      if (el.name == strName) {
        if (first) {
          is_checked = el.checked;
          first = false;
        }
        if (is_checked) el.checked = false;
        else el.checked = true;
      }
    }
  }
  // vklada udaje o adresatovi do formulare - obe fce
  function setNumIntoAdr(emlNum,countAdr) {
    var emlName = allMails_ar[emlNum.value];
    setIntoAdr(emlName,countAdr);
  }
  function setIntoAdr(emlName,countAdr) {
    var name = emlName.substring(0,emlName.indexOf(' ('));
    var email = emlName.substring(emlName.indexOf(' (')+2,emlName.length - 1);
    var emlVal = "";
    var nmVal = "";
  
    for (var i = 0; i < countAdr; i++) {
      emlVal = document.getElementById('emlAd'+i).value;
      if (emlVal == email) {
        return false;
      }
    }
    for (var i = 0; i < countAdr; i++) {
      emlVal = document.getElementById('emlAd'+i).value;
      if (!emlVal) {
        document.getElementById('emlAd'+i).value = email;
        document.getElementById('nmAd'+i).value = name;
        return true;
      }
    }
    return true;
  }
  // zobrazovani informacnich indexovanych mailu a podminek u stanic v nastaveni pro oblast
  var ar_WAopened = new Array();
  function zobrazPodminky(obj,flag) {
    var form = document.getElementById('areaWatchAgent');
    var strings = "";
    var chcbxSt = new Array();
    for (var i = 0; i < form.elements.length; i++) {
      var el = form.elements[i];
      if (el.id.search(/^cbxSt\d{0,3}_/) >= 0) {
        chcbxSt[el.id.substring(5,el.id.indexOf('_'))] = document.getElementById(el.id).checked;
      }
    }
  
    var s_val = "";
    switch (flag) {
      case 0: s_val = "pm"+obj.value+"_"; break;
      case 1: s_val = "a"+obj.value+"d"; break;
      case 2: s_val = "st"+obj+"_"; break;
      case 3: s_val = "st"+obj+"_"; break;
    }
    //alert(s_val);
    var pocdiv = 0;
    var docDiv = document.getElementsByTagName("div");
    for (var i = 0; i < docDiv.length; i++) {
      if (docDiv[i].id.search(/^st\d{0,3}_pm\d{0,2}_(a\d{0,999}d)*/) >= 0) {
        if (flag != 2 && !chcbxSt[docDiv[i].id.substring(2,docDiv[i].id.indexOf('_'))]) {
          docDiv[i].style.display = "none";
          continue;
        }
        switch (flag) {
          case 0:
          case 1: docDiv[i].style.display = (docDiv[i].id.indexOf(s_val) >= 0)? "block" : "none"; // mail nebo podminka
                  break;
          case 2: docDiv[i].style.display = (allWAopened)? "none" : "block";      // zobrazit vsechny
                  break;
          case 3: if (docDiv[i].id.indexOf(s_val) >= 0)
                    docDiv[i].style.display = (ar_WAopened[obj])? "none" : "block"; // zobrazit stanici
                  break;
        }
      }
      pocdiv++;
    }
    if (flag == 2) {  // zobrazit vsechny
      allWAopened = (allWAopened)? false : true;
    }
    if (flag == 3) {  // zobrazit stanice
      ar_WAopened[obj] = (ar_WAopened[obj])? false : true;
    }
  }

/* PRO NASTAVENI SLEDOVACIHO AGENTA - end...*/


// v main_inc - kalendar pro zobrazeni binaru
  var myWin = window.myWin;
  function new_window(link) {
    if (myWin!=null && !myWin.closed)
      myWin.focus();
    else
      myWin = window.open(link,'','width=220,height=170,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=500,top=300,resizable', true);
  }

function Check_allCheckboxes(obj, form, id) { // zaskrtne vsechny checkboxy ve form, ktere maji id
    for (var i=0; i<form.elements.length; i++) {
      var e = form.elements[i];
      if (e.id == id)
        if (!obj.checked) e.checked = false;
        else e.checked = true;
    }
}

// najeti leveho menu na oblast
function displayMenuArea(areaId) {
  var a_obj = top.frames["leftmenuframe"].document.getElementById('o'+areaId);
  chngDispArea(areaId,1);
  if (a_obj) a_obj.scrollIntoView(true);
}

// presmerovani stranky s potvrzenim - pouziva se pri overeni smazani neceho
function redirect_confirm(path,hlaska) {
  if (hlaska) {
    if (confirm(hlaska)) location.href = path;
  }
  else {
    location.href = path;
  }
}

/* Absolutni pozice prvku */
function FindAbsPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
  	do {
      obj = obj.offsetParent
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj.offsetParent);
  }
  return [curleft,curtop];
}

/* ======================================= *
 * === Ajax === *
 * ======================================= */

function Zobrazit_napovedu(obj_id,p_X,p_Y,inPage,path) {
  var obj = document.getElementById(obj_id);
  var aktValue = (obj)? obj.value : '';
  if (aktValue.length < 2) {
    editWindow.style.visibility = 'hidden';
    return false;
  }
  if (!inPage) {
    var posistions_ar = FindAbsPos(obj);
    editWindow.style.top = parseInt((posistions_ar[1]+p_Y),10) + 'px';
    editWindow.style.left = parseInt((posistions_ar[0]-p_X),10) + 'px';
    //alert(editWindow.style.top+' -- '+editWindow.style.left);

    /*promt_startZaznam = 0;
    promt_endZaznam = promt_pocPolOnPage;
    promt_zaznamu = 0;*/
  }

  Set_newHttpRequest(encodeURI(path),editWindow,0);
  return true;
} 

function Zobrazit_stranku(obj_id,p_X,p_Y,inPage,path) {
  var obj = document.getElementById(obj_id);
  if (!inPage) {
    var posistions_ar = FindAbsPos(obj);
    editWindow.style.top = parseInt((posistions_ar[1]+p_Y),10) + 'px';
    editWindow.style.left = parseInt((posistions_ar[0]-p_X),10) + 'px';
    //alert(editWindow.style.top+' -- '+editWindow.style.left);
  }

  Set_newHttpRequest(encodeURI(path),editWindow,0);
  return true;
}

function Set_newHttpRequest(path,obj,act) {
  var httpRequest = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
  if (!httpRequest) return false;

  httpRequest.open("GET", path);
  httpRequest.onreadystatechange = function() {
    OnLoadHTTPRequest(httpRequest,obj,act);
  };
  httpRequest.send(null);
  return true;
}
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function OnLoadHTTPRequest(httpRequest,obj,act) {
  if (httpRequest.readyState == 4) { // aktualizace odpovědí na základě aktuálního stavu
    if(httpRequest.status == 200) {
      var txt = httpRequest.responseText.trim();
      //alert(act+'\n-'+txt+'-');
      //var txt = httpRequest.responseText;
      switch (act) {
        case 6:   Result_insertAlternativePart(txt);  // soubor skladVydat_det.php
                  break;
        case 5:   Result_moveSklad(txt);  // soubor skladVydat_det.php
                  break;
        case 3:   //alert('txt: '+txt);
                  obj.innerHTML += txt;
                  errorsCountInForm -= (txt == '')? 1 : 0;
                  if (txt.indexOf('<!--cfObs-->') >= 0)  CheckFormErrorsCount('cfObsazeno');
                  else  CheckFormErrorsCount('cf');
                  break;
        default:  if (txt) {
                    obj.innerHTML = txt;
                    obj.style.visibility = 'visible';
                  }
                  else {
                    obj.style.visibility = 'hidden';
                  }
      }
    }
    else {
      alert("Chyba pri nacitani stanky"+ httpRequest.status +":\n"+ httpRequest.statusText);
      return false;
    }
  }
  return false;
}

/* ======================================= *
 * === Konec Ajax === *
 * ======================================= */
