/*** funkce pro odsraneni bilych znaku z koncu retezce ***/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
/*** test vyskytu hodnoty v poli ***/
Array.prototype.inArray = function(str) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == str) return true;
  }
	return false;
}

function obarvitTabulky() {
  var tabulky = document.getElementsByTagName("table"); //vsechny tabulky
  tabulka:
  for (var i = 0; i < tabulky.length; i++) {
    var tridy = tabulky[i].className.split(" "); //tridy v poli
    if (!tridy.inArray("obecna")) continue; //preskocit tabulky, pokud neni tridy obecna
    var bunky = tabulky[i].getElementsByTagName("th");
    for (var j = 0; j < bunky.length; j++) {
      if (bunky[j].getAttribute("colspan") > 1) continue tabulka; //preskoceni tabulky, pokud v ni jsou slucovane bunky
      if (bunky[j].getAttribute("rowspan") > 1) continue tabulka;
    }
    var bunky = tabulky[i].getElementsByTagName("td");
    for (var j = 0; j < bunky.length; j++) {
      if (bunky[j].getAttribute("colspan") > 1) continue tabulka; //preskoceni tabulky, pokud v ni jsou slucovane bunky
      if (bunky[j].getAttribute("rowspan") > 1) continue tabulka;
    }
    //pruchod po radcih
    var radky = tabulky[i].getElementsByTagName("tr");
    var cisloRadku = 0; //pocitadlo radku, ve kterych nejsou bunky zahlavi
    for (var j = 0; j < radky.length; j++) {
      //pruchod po bunkach v radku
      var bunky = radky[j].getElementsByTagName("td");
      if (bunky.length == 0) continue; //preskoceni radku, ve kterem jsou jen bunky zahlavi
      cisloRadku ++;
//      if (cisloRadku % 2 == 1) radky[j].className += (radky[j].className.length > 0 ? " " : "") + "radek_lichy";
      var bunky = bunky[0].parentNode.childNodes;
      var cisloBunky = 0; //pocitadlo bunek v radku
      for (var k = 0; k < bunky.length; k++) {
        if (!bunky[k].nodeName || (bunky[k].nodeName != "TH" && bunky[k].nodeName != "TD")) continue; //pouze bunky
        cisloBunky ++;
        if (bunky[k].nodeName == "TH") continue; //bunce zahlavi se styl nenastavuje, pouze se inkrementuje pocitadlo
        if (cisloBunky % 2 == 1 && cisloRadku % 2 == 1) bunky[k].className += (bunky[k].className.length > 0 ? " " : "") + "sloupec_lichy"; //licha bunka licheho radku
        if (cisloBunky % 2 == 0 && cisloRadku % 2 == 0) bunky[k].className += (bunky[k].className.length > 0 ? " " : "") + "sloupec_sudy";  //suda bunka sudeho radku
      }
    }
  }
}

function klikaciMapaHover() {

  var pos = navigator.userAgent.indexOf('Galeon');
  if (pos > 0) return; //v galeonu funguje spatne
  
  if (!document.getElementById("klikaci_mapa_normal") || !document.getElementById("klikaci_mapa_hover")) return;  
  var odstavec = document.getElementById("klikaci_mapa");
  if (!odstavec) return;
  var oblast = odstavec.getElementsByTagName("area");
  if (oblast[0]) oblast = oblast[0];
  if (!oblast) return;

  oblast.onmousemove = function() {
    var normal = document.getElementById("klikaci_mapa_normal");
    var hover = document.getElementById("klikaci_mapa_hover");
    if (!normal || !hover) return;
    normal.style.display = "none";
    hover.style.display = "inline";
  };
  oblast.onmouseout = function() {
    var normal = document.getElementById("klikaci_mapa_normal");
    var hover = document.getElementById("klikaci_mapa_hover");
    if (!normal || !hover) return;
    hover.style.display = "none";
    normal.style.display = "inline";
  };
  odstavec.onmouseout = function() {
    var normal = document.getElementById("klikaci_mapa_normal");
    var hover = document.getElementById("klikaci_mapa_hover");
    if (!normal || !hover) return;
    hover.style.display = "none";
    normal.style.display = "inline";
  };
}

/*** cekani na nacteni html ***/
function nacteniHtml() {
  if (!document.getElementById("zapati_kontejner")) {
    htmlCas=htmlCas*2;
    setTimeout("nacteniHtml()", htmlCas);
    return;
  }
  obarvitTabulky();
  klikaciMapaHover();
}

htmlCas=2;
nacteniHtml();
