function VstepSub(f)
{
  f.vstep.value = gVstep;
  return true;
}
function VstepSub2(f)
{
  f.vstep2.value = gVstep;
  return true;
}
function Vstep(n)
{
  gVstep = n;
}
function VstepSend(f,n)
{
  f.vstep.value = n;
  f.submit();
}
function ShowHide(prvek)
{
  if (prvek.style.display == 'none')	prvek.style.display = 'inline';
	else prvek.style.display = 'none';
}
function zobrazPopisPouceni(f) 
{
  var prvek = document.getElementById('popis');
  if (f.vtyp.value == '1' || f.vtyp.value == '12' || f.vtyp.value == '13')	prvek.style.display = '';
	else prvek.style.display = 'none';
}
function ShowHideStrom(prvek,url,doc,idsb,idsl,cesta,isk,loadobr)
{
  if (prvek.style.display == 'none')
  {
    var xmlHttp;
    if (!xmlHttp) xmlHttp = novyXMLHttpRequest();

    if (xmlHttp)
    {
      loadobr.style.display = 'inline';
      xmlHttp.onreadystatechange = function()
      {
        if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
        {
          prvek.innerHTML = xmlHttp.responseText;
          prvek.style.display = 'inline';
	        
          newsb = cesta + 'images/sbal.gif';
	        if (isk == 0) newsl = cesta + 'images/slozkaB.jpg';
	        else newsl = cesta + 'images/islozkaB.jpg';
	        doc.images[idsb].src = newsb;
	        if (idsl != '') doc.images[idsl].src = newsl;

          loadobr.style.display = 'none';
        }
      }
      xmlHttp.open("GET", url, true);
      xmlHttp.send(null);
    }
  }
	else 
  {
    prvek.style.display = 'none';
	  
    newsb = cesta + 'images/rozbal.gif';
	  if (isk == 0) newsl = cesta + 'images/slozkaA.jpg';
	  else newsl = cesta + 'images/islozkaA.jpg';
	  doc.images[idsb].src = newsb;
	  if (idsl != '') doc.images[idsl].src = newsl;
  }
}
function Show(prvek)
{
  prvek.style.display = 'inline';
}
function ShowB(prvek)
{
  prvek.style.display = 'block';
}
function Hide(prvek)
{
	prvek.style.display = 'none';
}
function EnableDisableByCheckBox(box,prvek,sel)
{
  var elemBox = document.getElementById(box);
  var elemPrv = document.getElementById(prvek);
  if (elemBox && elemPrv)
  {
    var condit = (sel == 0?elemBox.checked:elemBox.selected);
    if (condit) elemPrv.disabled = '';
	  else elemPrv.disabled = 'disabled';
	}
}
function EnableZaznamTrKnihy(idPocHodin,idTema)
{
  var elemPocHodin = document.getElementById(idPocHodin);
  var elemTema = document.getElementById(idTema);
  if (elemPocHodin) elemPocHodin.disabled = '';
  if (elemTema) elemTema.disabled = '';
}
function zkopZaznamTK(hod,ident)
{
  var elemPocHodin = document.getElementById('ph' + ident);
  var elemTema = document.getElementById('t' + ident);
  
  if (elemPocHodin)
  {
    var inputElems = document.getElementsByTagName('input');
    for (var i=0; i < inputElems.length; i++) 
    {
      if (inputElems[i].id.search("^" + UdelejRegExp('ph' + hod) + "[.]*") != -1 && !inputElems[i].disabled)
      {
        inputElems[i].value = elemPocHodin.value; 
      }
    }
  } 
  if (elemTema)
  {
    var inputElems = document.getElementsByTagName('input');
    for (var i=0; i < inputElems.length; i++) 
    {
      if (inputElems[i].id.search("^" + UdelejRegExp('t' + hod) + "[.]*") != -1 && !inputElems[i].disabled)
      {
        inputElems[i].value = elemTema.value; 
      }
    }
  }
}
function rotateCheckState(idCheck)
{
  var elemCheck = document.getElementById(idCheck);
  if (elemCheck) 
  {
    var pos = elemCheck.src.lastIndexOf("/");
    if (pos != -1)
    {
      var baseStr = elemCheck.src.substr(0,pos+1);
      var checkState = elemCheck.src.slice(pos+1);
      if (checkState == 'check_blank.gif') elemCheck.src = baseStr + 'check_checked.gif'; 
      else if (checkState == 'check_checked.gif') elemCheck.src = baseStr + 'check_unchecked.gif';
      else if (checkState == 'check_unchecked.gif' && elemCheck.getAttribute('class') != 'check_blank') elemCheck.src = baseStr + 'check_checked.gif';
      else elemCheck.src = baseStr + 'check_blank.gif';
    }
  }
}
function rotateCheckStateSubmit(idRet)
{
  var elemRet = document.getElementById(idRet);
  if (!elemRet) return false;
   
  var elems = document.getElementsByTagName('img');
  for (var i=0; i < elems.length; i++) 
  {
    if (elems[i].id.search("^" + UdelejRegExp('checkimg') + "[.]*") != -1)
    {
      var pos = elems[i].src.lastIndexOf("/");
      if (pos != -1)
      {
        var value;
        var checkState = elems[i].src.slice(pos+1);
        if (checkState == 'check_blank.gif') value = 0; 
        else if (checkState == 'check_checked.gif') value = 1;
        else value = 2;
        elemRet.value += (elemRet.value != ''?';':'') + elems[i].id + ',' + value;
      }
    }
  }
  return true;
}
function rotateCheckStateMulti(datum,hodina)
{
  if ((hodina % 1) == 0) regVyraz = UdelejRegExp('checkimg_' + datum + '_' + hodina + '_');
  else regVyraz = UdelejRegExp('checkimg_' + datum + '_') + "[0-9]*" + UdelejRegExp('_' + hodina);
  var firstRow = true;
  var checkState;
  var elems = document.getElementsByTagName('img');
  for (var i=0; i < elems.length; i++) 
  {
    if (elems[i].id.search("^" + regVyraz + "[.]*") != -1)
    {
      var pos = elems[i].src.lastIndexOf("/");
      if (pos != -1)
      {
        if (firstRow)
        {
          rotateCheckState(elems[i].id);
          checkState = elems[i].src.slice(pos+1);
          firstRow = false;
        }
        else
        {
          elems[i].src = elems[i].src.substr(0,pos+1) + checkState;
        }
      }
    }
  }
}
function PouzeDostupUc(idCheck)
{
  var elemCheck = document.getElementById(idCheck);
  if (elemCheck)
  {
    var inputDisplay = (elemCheck.checked?'none':'');
    var inputElems = document.getElementsByTagName('td');
    for (var i=0; i < inputElems.length; i++) 
    {
      if (inputElems[i].id.search("^" + UdelejRegExp('ucn_') + "[.]*") != -1)
      {
        inputElems[i].style.display = inputDisplay; 
      }
    }
  }
}
function zobrazIkonyFunkceStranky(idp,pocetVyp)
{
  var elemIdp = document.getElementById(idp);
  if (elemIdp)
  {
    var elemIdpIko = document.getElementById(idp + 'iko');
    if (elemIdpIko) elemIdpIko.style.display = 'inline';
    if (pocetVyp != 1)
    {
      var elemIdpExp = document.getElementById(idp + 'exp');
      if (elemIdpExp) elemIdpExp.style.display = 'none';
      var elemIdpExp = document.getElementById(idp + 'vyb');
      if (elemIdpExp) elemIdpExp.style.display = 'none';
    }    
  }
}
function zakazSloupce(nabId,url,rel)
{
  var zakazSloupce = '';
  var elemNab = document.getElementById(nabId);      
  var inputElems = elemNab.getElementsByTagName('input');
  for (var i = 0; i < inputElems.length; i++) {
    if (!inputElems[i].checked) {
      zakazSloupce += (zakazSloupce != ''?',':'') + inputElems[i].id.substr(5);
    }
  }

  var ajaxServerRequest = novyXMLHttpRequest();
  ajaxServerRequest.onreadystatechange = function()
  {
    if (ajaxServerRequest.readyState == 4 && (ajaxServerRequest.status == 200 || ajaxServerRequest.status == 0))
    {
      //alert(ajaxServerRequest.responseText);
      if (rel) location.reload(true);
    }
  };
  ajaxServerRequest.open("POST", url, true);
  ajaxServerRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
  ajaxServerRequest.send('&sl=' + zakazSloupce);
}
function exportVypisu(element,typ)
{
  var odkaz = window.document.URL.split('#');
  element.href = odkaz[0] + '&vypexp=' + typ;
  return true;
}
function Pred(pred,pred2,stav)
{
  if (stav == 1)
  {	
    pred2.checked = false;
  }
  else if (stav == 2)
  {	
  	pred.checked = false;
  }
}
function OdDo(OdN,DoN)
{
  OdN.value=DoN.value-1;
}
function Rozsah(Max,f)
{
  not = '---';
  f.vdo1.disabled = f.vdo2.disabled = f.vdo3.disabled = f.vdo4.disabled = true;
  if (Max == 5)
  {
    f.vdo1.value = f.vod2.value = f.vdo2.value = f.vod3.value = f.vdo3.value = f.vod4.value = f.vdo4.value = f.vod5.value = '';
    f.vdo1.disabled = f.vdo2.disabled = f.vdo3.disabled = f.vdo4.disabled = false;
    f.vdo5.value = f.minb.value;
  }
  else if (Max == 4)
  {
    f.vdo1.value = f.vod2.value = f.vdo2.value = f.vod3.value = f.vdo3.value = f.vod4.value = '';
    f.vdo1.disabled = f.vdo2.disabled = f.vdo3.disabled = false;
    f.vod5.value = f.vdo5.value = not; 
    f.vdo4.value = f.minb.value;
  }
  else if (Max == 3)
  {
    f.vdo1.value = f.vod2.value = f.vdo2.value = f.vod3.value = '';
    f.vdo1.disabled = f.vdo2.disabled = false;
    f.vod4.value = f.vdo4.value = f.vod5.value =  f.vdo5.value = not; 
    f.vdo3.value = f.minb.value;
  }
  else if (Max == 2)
  {
    f.vdo1.value = f.vod2.value = '';
    f.vdo1.disabled = false;
    f.vod3.value = f.vdo3.value = f.vod4.value =  f.vdo4.value = f.vod5.value =  f.vdo5.value = not; 
    f.vdo2.value = f.minb.value;
  }
  else if (Max == 1)
  {
    f.vod2.value = f.vdo2.value = f.vod3.value =  f.vdo3.value = f.vod4.value =  f.vdo4.value = f.vod5.value =  f.vdo5.value = not; 
    f.vdo1.value = f.minb.value;
  }
}
function CancelSubm(f)
{
  f.vstep.value = 0;
}
function CancelSubm1(f)
{
  f.vstep.value = 1;
}
function CancelSubm1Str(f,opt)
{
  f.vstep.value = 1;
  f.vopt.value = opt;
}
function CheckAllE(d,f,e,checkme)
{
  for (var i=0; i < f.elements.length; i++)
  {
    if (f.elements[i].name.search("^" + UdelejRegExp(e) + "[.]*") != -1) f.elements[i].checked = d.getElementById(checkme).checked;
  }
}
function CheckAllEId(d,f,e,checkme)
{
  for (var i=0; i < f.elements.length; i++)
  {
    if (f.elements[i].id.search("^" + UdelejRegExp(e) + "[.]*") != -1) f.elements[i].checked = d.getElementById(checkme).checked;
  }
}
function CheckIfAllE(d,f,e,checkme)
{
  for (var i=0; i < f.elements.length; i++)
  {
    if (f.elements[i].name.search("^" + UdelejRegExp(e) + "[.]*") != -1) 
    {
      if (!f.elements[i].checked)
      {
        d.getElementById(checkme).checked = false;
        return;
      }
    }
  }
  d.getElementById(checkme).checked = true;
}
function CheckAllOpt(d,f)
{
  for (var i=0; i < f.elements.length; i++)
  {
    if (f.elements[i].name.search("^[s,h][.]*") != -1) 
    {
      opt1 = "x1o" + f.elements[i].name;
      opt2 = "x2o" + f.elements[i].name;
      if (d.getElementById("checkall").checked) d.getElementById(opt2).selected = true;
      else d.getElementById(opt1).selected = true;
    }
  }
}
function DisableAll(f)
{
  for (var i=0; i < f.elements.length; i++)
  {
    if (f.elements[i].name.search("^[u,p,v][c,r,p][.]*") != -1) f.elements[i].disabled = f.checkall.checked;
  }
}
function Tisk(odk,sirka)
{
  if (sirka == 0) tiskokno = window.open(odk,'','width=794,height=1123,resizable=no,menubar=no,scrollbars=yes');
  else tiskokno = window.open(odk,'','width=1123,height=794,resizable=no,menubar=no,scrollbars=yes');
	tiskokno.focus();
}
function TiskP(f)
{
  var elemDiv = document.getElementById('textNacitani');
  if (elemDiv) elemDiv.innerHTML = 'Čekejte prosím, tato operace může trvat i několik minut... <img src="images/loading.gif" alt=""/>';
  document.getElementById(f).submit();
}
function ZamenObr(doc,id,obr)
{
	doc.images[id].src = obr; 
}
function HookOpen()
{
  var i = 0;
  while (arguments[i])
  {
    document.getElementById(arguments[i]).value = arguments[i+1];
    i += 2;
  }
  var element = document.getElementById(arguments[i-2]).parentNode.parentNode;
  element.setAttribute("class",'matpolepok');
  element.setAttribute("className",'matpolepok');
}
function SbalRozbal(prvek,doc,idsb,idsl,cesta,isk)
{
  if (prvek.style.display == 'inline')
  {
	  newsb = cesta + 'images/sbal.gif';
	  if (isk == 0) newsl = cesta + 'images/slozkaB.jpg';
	  else newsl = cesta + 'images/islozkaB.jpg';
	  doc.images[idsb].src = newsb;
	  if (idsl != '') doc.images[idsl].src = newsl;
	}
	else
	{
	  newsb = cesta + 'images/rozbal.gif';
	  if (isk == 0) newsl = cesta + 'images/slozkaA.jpg';
	  else newsl = cesta + 'images/islozkaA.jpg';
	  doc.images[idsb].src = newsb;
	  if (idsl != '') doc.images[idsl].src = newsl;
  }
}
function OpenUpload(sid,uid)
{
  if (document.getElementById("upl").value != '')
  {
    upokno = window.open('upload.php?sid='+sid+'&uid='+uid,'Upload','width=380,height=60,resizable=no,scrollbars=no'); 
    upokno.focus();
  }
  return true; 
}
function OpenCiselnik(sid,typ)
{
  var i = 2;
  var param = '';
  while (arguments[i])
  {
    param = param + '&p' + (i - 1) + '=' + arguments[i];
    i++;
  }
  if (sid != '0') cisokno = window.open('m7o214.php?sid=' + sid + '&typ=' + typ + param,'Číselník','width=500,height=400,resizable=yes,scrollbars=yes');
  else cisokno = window.open('ciseln.php?typ=' + typ + param,'Číselník','width=500,height=400,resizable=yes,scrollbars=yes');
  cisokno.focus();
  return false;
}
function PocetZnaku(pocet) 
{
	var delka = document.getElementById("zpravasms").value.length;
	document.getElementById("napsano").innerHTML = delka;
	document.getElementById("rozdeleno").innerHTML = Math.ceil(delka/pocet);
}
function OpenAdresar(sid,p1,p2)
{
  adrokno = window.open('m14o103.php?sid=' + sid + '&name=' + p1 + '&typ=' + p2,'','width=630,height=500,resizable=yes,scrollbars=yes');
  adrokno.focus();
  return false;
}
function OpenKalendar(href)
{
  kalokno = window.open(href,'','width=210,height=200,resizable=yes,scrollbars=yes');
  kalokno.focus();
  return false;
}
function DisableZnamka(idp,idz)
{
  if (document.getElementById(idp).value == 0) document.getElementById(idz).disabled = 'disabled';
  else document.getElementById(idz).disabled = '';
}
function PrejdiNaKonec(f)
{
  if (ziskejTopPrvku(document.getElementById('pokracd')) > screen.height) f.action += '#pokrac';
}
function DisablePredVizo(prvekDis,prvekZdroj)
{
  if (document.getElementById(prvekDis))
  {
    var zdroj = document.getElementById(prvekZdroj);
    var pred = zdroj.options[zdroj.selectedIndex].innerHTML.substr(0,1);
    if (pred != '.') document.getElementById(prvekDis).style.display = 'none';
    else document.getElementById(prvekDis).style.display = 'inline';
  }
}
function Odpocitavej()
{
  var casDiv = document.getElementById('zbyvCas');
  if (casDiv)
  { 
    var cas = casDiv.innerHTML.split(':');
    cas[0] = parseInt(cas[0]);
    cas[1] = (cas[1][0] == '0'?parseInt(cas[1][1]):parseInt(cas[1]));
    if (cas[0] != 0 || cas[1] != 0)
    {
      if (cas[1] != 0) cas[1] -= 1;
      else
      {
        cas[0] -= 1;
        cas[1] = 59;
      }
      casDiv.innerHTML = cas[0] + ':' + (cas[1] < 10?'0':'') + cas[1];
      window.setTimeout(Odpocitavej,1000);
    }
  }
}

function ziskejTopPrvku(objekt)
{		
  var vrat = objekt.offsetTop;
  while((objekt = objekt.offsetParent) != null){
    if(objekt.tagName != 'HTML') vrat += objekt.offsetTop;
  }
  return vrat;
}

function nastavNazevSestavy(idNazev,idChbox,hodnRiz,hodnZk)
{
  var elemChBox = document.getElementById(idChbox);
  var elemNazev = document.getElementById(idNazev);
  if (elemChBox && elemNazev) 
  {
    if (elemChBox.checked) elemNazev.value = hodnRiz;
    else elemNazev.value = hodnZk;
  }
}

function nastavHodnotu(idElem,hodn)
{
  var elem = document.getElementById(idElem);
  if (elem) elem.value = hodn;
}

function doplnDolozky(v,h)
{
  var inputElems = document.getElementsByTagName('input');
  for (var i=0; i < inputElems.length; i++) 
  {
    if (inputElems[i].id.search("^" + UdelejRegExp(v) + "[.]*") != -1)
    {
      inputElems[i].value = document.getElementById(h + inputElems[i].id.substr(2)).innerHTML;
    }
  }
}

// Ajax
var xmlHttp,prvek,prvek1,prvek2,prvek3,prvek4,maxId,curSel,nacitam,umozniodeslat;

function vytvorXMLHttpRequest() 
{
  if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
}

function novyXMLHttpRequest() 
{
  if (window.ActiveXObject) return(new ActiveXObject("Microsoft.XMLHTTP"));
  else if (window.XMLHttpRequest) return(new XMLHttpRequest());
}
      
function OtevriAdresar(prvekzdroj,prvekcil,url)
{
  vyber = new Array(); 
  prvek = prvekcil;
  var sel = document.getElementById(prvekzdroj);
  for (var k = 0; k < sel.options.length; k++) if (sel.options[k].selected) vyber.push(sel.options[k].value);

  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    url += "&adresar=" + vyber.toString();
    xmlHttp.onreadystatechange = zpracujZmenuStavu;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}

function OtevriIzo(p1,p2,p3,p4,prvekzdroj,url)
{
  prvek1 = p1;
  prvek2 = p2;
  prvek3 = p3;
  prvek4 = p4;
  
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    url += "&name=" + document.getElementById(prvekzdroj).value;
    xmlHttp.onreadystatechange = zpracujZmenuStavu2;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}

function PrectenyPrispevek(prvekcil,prispevek,url)
{
  prvek = prvekcil;
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    url += "&name=" + prispevek;
    xmlHttp.onreadystatechange = zpracujZmenuStavu3;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}

function OverZaznamMatriky(prvekcil,text,kod,p,url)
{  
  prvek1  = prvekcil;
  prvek2  = text;
  prvek3  = kod;
  prvek4  = p;
  
  if (document.getElementById('matrform')) mid = document.getElementById('matrform').vid.value;
  else mid = '';
  
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();
  
  if (xmlHttp)
  {
    url += "&mid=" + mid + "&pol=" + prvekcil + "&p=" + p + "&text=" + document.getElementById(text).value + (kod != ''?"&kod=" + document.getElementById(kod).value:'');
    xmlHttp.onreadystatechange = zpracujZmenuStavu4;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}

function VystupniDokument(prvekcil,data,url)
{
  prvek = prvekcil;
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    xmlHttp.onreadystatechange = zpracujZmenuStavu3;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    xmlHttp.send(data);
    document.getElementById(prvek).innerHTML = 'Čekejte prosím. Tato operace může trvat i několik minut.';
  }
}

function UrciMaxHodinu(prvekcil,tr,pol,url)
{  
  prvek1 = prvekcil;
  
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();
  
  if (xmlHttp)
  {
    url += "&pr=" + document.getElementById('idpr').value + "&tr=" + tr + "&p=" + pol;
    xmlHttp.onreadystatechange = zpracujZmenuStavu5;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}

function ZakodujURL(str)
{
  var ret = str.replace(/%/g, "%25");
  ret = ret.replace(/ /g, "%20");
  ret = ret.replace(/#/g, "%23");
  ret = ret.replace(/\$/g, "%24");
  ret = ret.replace(/&/g, "%26");  
  ret = ret.replace(/\+/g, "%2B");
  ret = ret.replace(/,/g, "%2C");
  ret = ret.replace(/\//g, "%2F");  
  ret = ret.replace(/:/g, "%3A");
  ret = ret.replace(/;/g, "%3B");
  ret = ret.replace(/</g, "%3C");
  ret = ret.replace(/=/g, "%3D");
  ret = ret.replace(/>/g, "%3E");
  ret = ret.replace(/\?/g, "%3F");
  ret = ret.replace(/~/g, "%7E");
  return (ret);
}

function ZpravaPro(val)
{
  var selectElem = document.getElementById(prvek3);
  for (var i=0; i < selectElem.options.length; i++)
  {
    if (val == selectElem.options[i].value) 
    {
      selectElem.selectedIndex = i;
      break;
    }
  }
}

function OdesliZpravu(f,url,prvekcil)
{
  if (!umozniodeslat) return;
  umozniodeslat = false;    
  window.setTimeout(UmozniOdeslatInt,1000);
  
  prvek = prvekcil;
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    xmlHttp.onreadystatechange = function()
    {
      if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
      {
        document.getElementById(prvek).innerHTML = '';
        f.vzprava.value = '';
      }
    }
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
    xmlHttp.send('&vzprava='+ZakodujURL(f.vzprava.value)+'&vkomu='+f.vkomu.value);
    document.getElementById(prvek).innerHTML = 'Odesílám...';
  }
}

function UmozniOdeslatInt()
{
  umozniodeslat = true;
}

function vyberZeSelektu(idElem,val)
{
  var selectElem = document.getElementById(idElem);
  if (selectElem)
  {
    for (var i=0; i < selectElem.options.length; i++)
    {
      if (val == selectElem.options[i].value) 
      {
        selectElem.selectedIndex = i;
        return;
      }
    }
  }
}

function ziskejObsahViceSelectu(url,reg)
{
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    xmlHttp.onreadystatechange = function()
    {
      if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
      {
        var pole = xmlHttp.responseText.split(";");
        for (var i=0; i < pole.length; i++)
        {
          var pole2 = pole[i].split(",");
          vyberZeSelektu(reg + pole2[0],pole2[1]);
        }
      }
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
  }
}

function VlozEmot(e)
{
  var eCis = parseInt(e.substr(1));
  if (eCis > 0 && eCis < 115) return '<img src="images/' + eCis + '.gif" alt=""/>';
  else return e;
}

function VlozEmotText(e)
{
  var zpr = document.getElementById('zprava');
  zpr.value += e;
  zpr.focus();
}

function OnLoadChat(idm,sid,prvekcil)
{
  prvek1 = prvekcil;
  prvek2 = '&sid='+sid+'&name='+idm;
  maxId  = 0;
  nacitam = false;
  umozniodeslat = true;
  NactiChatInt();
}

function NactiChatInt()
{
  window.setTimeout(NactiChatInt,5000);
  NactiChat();
}

function NactiChat()
{
  if (nacitam) return;
  nacitam = true;
  var xmlHttpPozadavek = false;
  xmlHttpPozadavek = novyXMLHttpRequest();

  if (xmlHttpPozadavek)
  {
    xmlHttpPozadavek.onreadystatechange = function()
    {
      if (xmlHttpPozadavek.readyState == 4 && (xmlHttpPozadavek.status == 200 || xmlHttpPozadavek.status == 0))
      {
        var divy = xmlHttpPozadavek.responseXML.getElementsByTagName('zprava');
        for (var i=0; i < divy.length; i++)
        {
          var divId = divy[i].getAttribute('id');
          if (divId.search("^[z][p][r][.]*") != -1)
          {
            var zprId = parseInt(divId.substr(3));
            if (zprId > maxId) maxId = zprId;
            var novyDiv  = document.createElement('div');
            var vyslText = divy[i].firstChild.data;
            vyslText = vyslText.replace(/(\*\d+\*)/g,VlozEmot);
            novyDiv.innerHTML = vyslText;
            
            var divClass = divy[i].getAttribute('class');
            if (divClass)
            {
              novyDiv.setAttribute("class",divClass);
              novyDiv.setAttribute("className",divClass);
            }
            
            var divSpec = divy[i].getAttribute('spec');
            if (divSpec)
            {
              if (divSpec == '1' || divSpec == '2') 
              {
                var spravce = document.getElementById('spravce');
                if (spravce)
                {
                  if (divSpec == 1) spravce.style.display = 'inline';
                  else if (divSpec == '2') spravce.style.display = 'none';
                }
              }
            }
            
            var divBarva = divy[i].getAttribute('barva');
            if (divBarva) novyDiv.style.color = divBarva;
            
            var zpravy = document.getElementById(prvek1);
            zpravy.appendChild(novyDiv);
            zpravy.scrollTop = zpravy.scrollHeight;
          }
        }
      }
    }
    xmlHttpPozadavek.open("GET",'m6o204.php?step=6'+prvek2+'&x='+maxId+'&cas='+new Date().getTime(), true);
    xmlHttpPozadavek.send(null);
  }
  nacitam = false;
}

function OnLoadLideMistnosti(idm,sid,prvekcil)
{
  prvek3 = prvekcil;
  prvek4 = '&sid='+sid+'&name='+idm;
  NactiLideMistnosti();
}

function NactiLideMistnosti()
{
  window.setTimeout(NactiLideMistnosti,15000);
  var xmlHttpPozadavek = false;
  xmlHttpPozadavek = novyXMLHttpRequest();

  var selectElem  = document.getElementById(prvek3);
  var selectIndex = selectElem.selectedIndex;
  if (selectIndex != -1) curSel = selectElem.options[selectElem.selectedIndex].value;
  else curSel = '0_';
  
  if (xmlHttpPozadavek)
  {
    xmlHttpPozadavek.onreadystatechange = function()
    {
      if (xmlHttpPozadavek.readyState == 4 && (xmlHttpPozadavek.status == 200 || xmlHttpPozadavek.status == 0))
      {
        var osoby     = xmlHttpPozadavek.responseXML.getElementsByTagName('osoba');
        var nabidka   = document.getElementById(prvek3);
        var cilovyDiv = document.getElementById('lide');
        var staryDiv  = document.getElementById('lideobs');          
        var novyDiv   = document.createElement('div');
        novyDiv.setAttribute('id','lideobs');
        for (var i=0; i < nabidka.options.length; i++) nabidka.removeChild(nabidka.options[i]);
        for (var i=0; i < osoby.length; i++)
        {
          var osobaid  = osoby[i].getElementsByTagName('osobaid');
          var osobaval = osoby[i].getElementsByTagName('osobaval');
          var osobatyp = osoby[i].getElementsByTagName('osobatyp');
          var osobaspr = osoby[i].getElementsByTagName('osobaspr');
          var osobacas = osoby[i].getElementsByTagName('osobacas');
          
          nabidka.options[i] = new Option(osobaval[0].firstChild.data);
          nabidka.options[i].value = osobaid[0].firstChild.data;
          if (nabidka.options[i].value == curSel) nabidka.options[i].selected = true;
          
          var novyA = document.createElement('a');
          if (osobaspr[0] && osobaspr[0].firstChild.data == '1') novyA.style.color = 'red';
          if (osobacas[0]) novyA.setAttribute('title',osobacas[0].firstChild.data);
          novyA.setAttribute('href','#zprava');
          novyA.onclick = new Function("ZpravaPro('"+osobaid[0].firstChild.data+"');");
          novyA.appendChild(document.createTextNode(osobaval[0].firstChild.data));
          
          var novyRadek = document.createElement('div');
          if (osobatyp[0])
          {            
            var novyObr = document.createElement('img');
            novyObr.setAttribute('src','images/sm'+osobatyp[0].firstChild.data+'.gif');
            novyRadek.appendChild(novyObr);
          }
          novyRadek.appendChild(novyA);
          novyDiv.appendChild(novyRadek);
        }
        cilovyDiv.replaceChild(novyDiv,staryDiv);
        document.getElementById('pocetLidi').innerHTML = osoby.length-1;
      }
    }
    xmlHttpPozadavek.open("GET",'m6o204.php?step=7'+prvek4+'&cas='+new Date().getTime(), true);
    xmlHttpPozadavek.send(null);
  }
}

function ziskejCelkHodnMaturity(url,prefZn,prefMax,prvekcil)
{
  if (xmlHttp == null) vytvorXMLHttpRequest();
  else if (xmlHttp) xmlHttp.abort();

  if (xmlHttp)
  {
    var znamky = '';
    var vlozeno = 0;
    for (var i = 1; i <= prefMax; i++) 
    {
      var selectElem = document.getElementById(prefZn + i);
      if (selectElem && !selectElem.disabled)
      {
        znamky += (vlozeno? ',' : '') + selectElem.options[selectElem.selectedIndex].value;
        vlozeno++; 
      }
    }

    xmlHttp.onreadystatechange = function()
    {
      if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
      {
        var selectElem = document.getElementById(prvekcil);
        var val = xmlHttp.responseText;
        for (var i=0; i < selectElem.options.length; i++)
        {
          if (val == selectElem.options[i].value) 
          {
            selectElem.selectedIndex = i;
            break;
          }
        }
      }
    }
    xmlHttp.open("GET", url + '&zn=' + znamky, true);
    xmlHttp.send(null);
  }
}

function zpracujZmenuStavu() 
{
  if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
  {
    document.getElementById(prvek).value += (document.getElementById(prvek).value == ""?"":",") + xmlHttp.responseText;
  }
}

function zpracujZmenuStavu2() 
{
  if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
  {
    var pole = xmlHttp.responseText.split(";");
    document.getElementById(prvek1).value = pole[0];
    document.getElementById(prvek2).value = pole[1];
    document.getElementById(prvek3).value = pole[2];
    document.getElementById(prvek4).value = pole[3];
  }
}

function zpracujZmenuStavu3() 
{
  if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
  {
    document.getElementById(prvek).innerHTML = xmlHttp.responseText;
  }
}

function zpracujZmenuStavu4() 
{
  if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
  {
    var pole = xmlHttp.responseText.split(";");
    var element = document.getElementById(prvek1);
    element.setAttribute("class",pole[0]);
    element.setAttribute("className",pole[0]);
    
    if (prvek4 == 0) 
    {
      document.getElementById(prvek2).focus();
      document.getElementById(prvek3).value = pole[1];
    }
    else if (prvek4 == 1) 
    {
      document.getElementById(prvek3).focus();
      document.getElementById(prvek2).value = pole[1];
    }
  }
}

function zpracujZmenuStavu5() 
{
  if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.status == 0))
  {    
    document.getElementById(prvek1).value = xmlHttp.responseText;
  }
}

// HTML Editor
var editor;

function InitEditor()
{
  editor = document.getElementById('iEditor');
  if (editor) editor.contentWindow.document.designMode = 'on';
  if (navigator.appName == 'Netscape') editor.contentWindow.document.execCommand('styleWithCSS',false,false);
}  
function iZvyrazni(p,t)
{
  var prvek = document.getElementById(p);
  if (t == 0) 
  {
    prvek.style.border = '1px black solid';
    prvek.style.backgroundColor = '#ffffff';
  }
  else
  {
    prvek.style.border = '1px #cccccc solid';
    prvek.style.backgroundColor = '#cccccc';
  }
}  
function fUndo()
{
 editor.contentWindow.document.execCommand('undo',false,null);
}
function fRedo()
{
 editor.contentWindow.document.execCommand('redo',false,null);
}
function fCut()
{
 editor.contentWindow.document.execCommand('cut',false,null);
}
function fCopy()
{
 editor.contentWindow.document.execCommand('copy',false,null);
}
function fPaste()
{
 editor.contentWindow.document.execCommand('paste',false,null);
}
function fBold()
{
 editor.contentWindow.document.execCommand('bold',false,null);
}
function fItalic()
{
  editor.contentWindow.document.execCommand('italic',false,null);
}
function fUnderline()
{
  editor.contentWindow.document.execCommand('underline',false,null);
}  
function fSup()
{
 editor.contentWindow.document.execCommand('superscript',false,null);
}
function fSub()
{
 editor.contentWindow.document.execCommand('subscript',false,null);
}  
function fUnformat()
{
 editor.contentWindow.document.execCommand('removeformat',false,null);
}
function fLeft()
{
  editor.contentWindow.document.execCommand('justifyleft',false,null);
}
function fCenter()
{
  editor.contentWindow.document.execCommand('justifycenter',false,null);
}
function fRight()
{
  editor.contentWindow.document.execCommand('justifyright',false,null);
}
function fFull()
{
  editor.contentWindow.document.execCommand('justifyfull',false,null);
}
function fOList()
{
  editor.contentWindow.document.execCommand('insertorderedlist',false,null);
}
function fUList()
{
  editor.contentWindow.document.execCommand('insertunorderedlist',false,null);
}  
function fBarvaTextu()
{
  if (document.getElementById('iPaleta').style.visibility == 'hidden') document.getElementById('iPaleta').style.visibility = '';
  else document.getElementById('iPaleta').style.visibility = 'hidden';
}
function fLink()
{
  var p = prompt('Zadejte URL odkazu', '');    
  editor.contentWindow.document.execCommand('createlink',false,p);
}  
function fImg()
{
  var p = prompt('Zadejte URL obrázku', '');    
  if(p != null) editor.contentWindow.document.execCommand('insertimage',false,p);
}  
function fRule()
{
  editor.contentWindow.document.execCommand('inserthorizontalrule',false,null);
}  
function fFont(p)
{
  if(p != '') editor.contentWindow.document.execCommand('fontname',false,p);
}  
function fVel(p)
{
  if(p != '') editor.contentWindow.document.execCommand('fontsize',false,p);
}  
function fNadp(p)
{
  if(p != '')
  {      
    fUnformat();
    editor.contentWindow.document.execCommand('formatblock',false,'<'+p+'>');
    fFont(vFont.options[vFont.selectedIndex].value);
  }
  else 
  {      
    editor.contentWindow.document.execCommand('formatblock',false,'<p>');
    editor.contentWindow.document.execCommand('fontname',false,'Sans Serif');
    editor.contentWindow.document.execCommand('fontsize',false,'3');
  }
}  
function fProm(p)
{
  var sel = document.getElementById(p);
  var hod = sel.options[sel.selectedIndex].value;
  if (navigator.appName == 'Microsoft Internet Explorer') 
  {
    document.frames['iEditor'].focus();
    editor.contentWindow.document.selection.createRange().text = hod;
  }
  else editor.contentWindow.document.execCommand('inserthtml',false,hod);
}
function odesliiForm()
{  
  document.getElementById('iForm').vtext.value = editor.contentWindow.document.body.innerHTML;
  document.getElementById('iForm').submit();
}
function AddDelAbs(p,fr,n)
{
  var telo  = document.getElementById(fr);
  var divy  = telo.contentWindow.document.getElementsByTagName('div');
  var pocet = 0;
  var pabs  = (p < 0?-p:p);
  for (var i=0; i < divy.length; i++)
  {
    if (divy[i].id.search("^[o][b][d]"+UdelejRegExp(pabs)+"[_][.]*") != -1) pocet++;
  }
  if (p >= 0)
  {
    var div  = telo.contentWindow.document.createElement('div');
    var divi = "obd" + p + '_' + ++pocet;
    div.setAttribute("style", "position:absolute; left:0px; top:0px; width:120px; height:21px; z-index:1; background-color: blue; border: 1px black solid; color: white;");
    div.style.cssText = "position:absolute; left:0px; top:0px; width:120px; height:21px; z-index:1; background-color: blue; border: 1px black solid; color: white;";
    div.setAttribute("id",divi);
    telo.contentWindow.document.body.appendChild(div);
    telo.contentWindow.document.getElementById(divi).appendChild(telo.contentWindow.document.createTextNode(n + pocet));
    window.frames[fr].ADD_DHTML(divi);
  }
  else
  {
    var div = telo.contentWindow.document.getElementById('obd' + pabs + '_' + pocet);
    if (div) telo.contentWindow.document.body.removeChild(div);
  }
}
function UlozAbsPrvky(f,fr)
{
  var telo = document.getElementById(fr);
  var divy = telo.contentWindow.document.getElementsByTagName('div');
  var ret  = '';
  for (var i=0; i < divy.length; i++)
  {
    if (divy[i].id.search("^[o][b][d][.]*") != -1) ret += (ret != ''?';':'') + divy[i].id + ',' + divy[i].style.left + ',' + divy[i].style.top + ',' + divy[i].style.width + ',' + divy[i].style.height;
  }
  f.vret.value = ret;
  f.submit();
}
function VykresliSestavu(b,sest,abs,txt)
{
  var telo    = document.getElementById(b);
  var divy    = telo.getElementsByTagName('div');
  var divyvel = divy.length;
  var ymax    = 0;
  
  for (var a = 0; a < divyvel; a++)
  {
    if (divy[a].id.search("^[" + abs + "][1][.]*") != -1)
    {
      var vel = parseInt(divy[a].style.top) + parseInt(divy[a].style.height);
      if (vel > ymax) ymax = vel;
    }
  }
  for (var s = 0; s < divyvel; s++)
  {
    if (divy[s].id.search("^[" + sest + "][.]*") != -1) 
    {
      var t = document.getElementById(txt+divy[s].id.substr(1));
      if (t.scrollHeight > ymax) ymax = t.scrollHeight;
      divy[s].style.height = parseInt(divy[s].style.height) + ymax;
    }
  }
}
function UdelejRegExp(str)
{
  exp = "";
  for (var j=0; j < str.toString().length; j++) exp = exp + "["+ str.toString().charAt(j) +"]";
  return (exp);
}
function DoplnVse(f,h,k)
{
  var hod = document.getElementById(h).value;
  for (var i=0; i < f.elements.length; i++)
  {
    if (f.elements[i].id.search("^[v][h][.]*") != -1) f.elements[i].value = hod;
  }
  if (k != '')
  {
    var kod = document.getElementById(k).value;
    for (var i=0; i < f.elements.length; i++)
    {
      if (f.elements[i].id.search("^[v][k][.]*") != -1) f.elements[i].value = kod;
    }
  }
}
