//var ADRESAR = "http://localhost/algosoft/projekty/mafitel/";
var ADRESAR = "http://www.mafitel.com/";

var spustitSlideShow = false;
var okna = new Array();
var aktivniOkno = false;
function Okno(typOkna, urlAdresa, parametry) { // int, URL, array
 this.handleKaret = null;
 this.ID_OKNA = null;
 this.handleOkna = null;
 this.handleRamu = null;
 this.handleMenu = null;
 this.handleObsahu = null;
 this.index = null;
 this.nazevOkna = null;
 var e_celkovaSirka = null;
 var predesleX = 0;
 var predesleY = 0;
 var predesleH = 0;
 var predesleW = 0;
 var predesleOH = 0;
 var predesleOW = 0;
 var stav = 1;
 var Objekt = this;

 function generujID() {
  var nejvetsiH = 0;
  for(var i=0;i<okna.length;i++) {
   try { if(okna[i].ID_OKNA > nejvetsiH) nejvetsiH = okna[i].ID_OKNA; } catch(v) {}
  }
  Objekt.index = okna.length;
  return (nejvetsiH+1);
 }
 // VNEJSI FUNKCE
 this.znicit = function() {
  Objekt.schovat();
  document.body.removeChild(Objekt.handleOkna);
  if(document.getElementById("poz")) {
   document.body.removeChild(document.getElementById("poz"));
   document.body.style.overflow = "auto";
   if(navigator.appName == "Microsoft Internet Explorer") {
    document.body.scroll = "yes";
    var x = document.getElementsByTagName("HTML");
    x[0].style.overflow = "auto";
   }
  }
 };

 this.aktivovat = function(event) {
  for(var i=0;i<okna.length;i++) {
   try {
    if(okna[i].ID_OKNA == Objekt.ID_OKNA) {
     aktivniOkno = i;
    }
    okna[i].handleOkna.style.zIndex = (1000+i+1);
    okna[i].handleOkna.style.opacity = 0.8;
    try {
     var menu1 = document.getElementById("menu_"+okna[i].ID_OKNA+"_1");
     var menu2 = document.getElementById("menu_"+okna[i].ID_OKNA+"_2");
     var plovouciMenu = document.getElementById("plochaMenu_"+okna[i].ID_OKNA);
     if(event.target.parentNode != menu1 && event.target.parentNode != menu2) {
      menu1.style.display = "none";
      menu2.style.display = "none";
      okna[i].handleOkna.removeChild(plovouciMenu);
     }
    }
    catch(v) {}
   } catch(v) { continue; }
  }
  if(Objekt.handleOkna.style.display == "none") Objekt.handleOkna.style.display = "block";
  Objekt.handleOkna.style.zIndex = 500;
  Objekt.handleOkna.style.opacity = 1;
 };

 this.presunout = function(event) {
  if(!event) event = window.event;
  Objekt.aktivovat(event);
  var handleOkna;
  var handleRamu;
  if(stav == 1) {
   handleOkna = Objekt.handleOkna;
   handleRamu = Objekt.handleRamu;
   var offsetX = event.clientX - parseInt(handleOkna.style.left);
   var offsetY = event.clientY - parseInt(handleOkna.style.top);
   var sirka = parseInt(handleOkna.style.width)+30;
   var vyska = parseInt(handleOkna.style.height)+30;
   var vyskaX = vyska-30+parseInt(handleOkna.style.top);
   var sirkaX = sirka-30+parseInt(handleOkna.style.left);
   if(document.elementFromPoint(event.clientX, event.clientY) == handleOkna) {
    if(isNaN(sirka) || isNaN(vyska)) throw new Error("Chybna vyska nebo sirka.");
    if(offsetY < 10 || offsetY > vyska-22) {
     if(navigator.appName == "Microsoft Internet Explorer") {
      handleOkna.attachEvent("onmousemove", zmenVelikostV);
      handleOkna.attachEvent("onmouseup", zrusZmenVelikostV);
     }
     else {
      handleOkna.addEventListener("mousemove", zmenVelikostV, true);
      handleOkna.addEventListener("mouseup", zrusZmenVelikostV, true);
     }
    }
    else if(offsetX < 10 || offsetX > sirka-22) {
     if(navigator.appName == "Microsoft Internet Explorer") {
      handleOkna.attachEvent("onmousemove", zmenVelikostH);
      handleOkna.attachEvent("onmouseup", zrusZmenVelikostH);
     }
     else {
      handleOkna.addEventListener("mousemove", zmenVelikostH, true);
      handleOkna.addEventListener("mouseup", zrusZmenVelikostH, true);
     }
    }
    else {
     if(navigator.appName == "Microsoft Internet Explorer") {
      document.attachEvent("onmousemove", zmenPozici);
      document.attachEvent("onmouseup", zrusZmenPozici);
     }
     else {
      document.addEventListener("mousemove", zmenPozici, true);
      document.addEventListener("mouseup", zrusZmenPozici, true);
     }
    }
   }
   var krokovani = 1;
  }
  function zmenVelikostV(e) {
   if(e.clientY-offsetY > -1) {
    var k = this;
    if(navigator.appName == "Microsoft Internet Explorer") {
     k = Objekt.handleOkna;
    }
    if(offsetY < 10) { // nahore
     k.style.top = (e.clientY-offsetY)+"px";
     k.style.height = vyskaX-parseInt(k.style.top)+"px";
     handleRamu.style.height = (parseInt(k.style.height)-52)+"px";
    }
    else if(event.clientY - parseInt(k.style.top) > vyska-22) { // dole
     k.style.height = ((e.clientY-parseInt(k.style.top))-16)+"px";
     handleRamu.style.height = (parseInt(k.style.height)-52)+"px";
    }
   }
  }
  function zrusZmenVelikostV(e){
   if(navigator.appName == "Microsoft Internet Explorer") {
    Objekt.handleOkna.detachEvent("onmousemove", zmenVelikostV);
    Objekt.handleOkna.detachEvent("onmouseup", zrusZmenVelikostV);
   }
   else {
    this.removeEventListener("mousemove", zmenVelikostV, true);
    this.removeEventListener("mouseup", zrusZmenVelikostV, true);
   }
  }
  function zmenVelikostH(e) {
   if(e.clientX-offsetX > -1) {
    var k = this;
    if(navigator.appName == "Microsoft Internet Explorer") {
     k = Objekt.handleOkna;
    }
    if(offsetX < 10) { // vlevo
     k.style.left = (e.clientX-offsetX)+"px";
     k.style.width = (sirkaX-parseInt(k.style.left))+"px";
     handleRamu.style.width = (parseInt(k.style.width)-22)+"px";
    }
    else if(event.clientX - parseInt(k.style.left) > sirka-22) { // vpravo
     k.style.width = ((e.clientX-parseInt(k.style.left))-16)+"px";
     handleRamu.style.width = (parseInt(k.style.width)-22)+"px";
    }
   }
  }
  function zrusZmenVelikostH(e){
   if(navigator.appName == "Microsoft Internet Explorer") {
    Objekt.handleOkna.detachEvent("onmousemove", zmenVelikostH);
    Objekt.handleOkna.detachEvent("onmouseup", zrusZmenVelikostH);
   }
   else {
    this.removeEventListener("mousemove", zmenVelikostH, true);
    this.removeEventListener("mouseup", zrusZmenVelikostH, true);
   }
  }
  function zmenPozici(e){
   var x = Math.round(e.clientX/krokovani)*krokovani-offsetX;// < 25 ? 10 : e.clientX - deltaX;
   var y = Math.round(e.clientY/krokovani)*krokovani-offsetY;// < 25 ? 10 : e.clientY - deltaY;
   handleOkna.style.left = x + "px";
   handleOkna.style.top = y + "px";
   if(navigator.appName == "Microsoft Internet Explorer") {
    e.cancelBubble = true;
    e.returnValue = false;
   }
   else e.stopPropagation();
  }
  function zrusZmenPozici(e){
   if(navigator.appName == "Microsoft Internet Explorer") {
    document.detachEvent("onmousemove", zmenPozici);
    document.detachEvent("onmouseup", zrusZmenPozici);
   }
   else {
    document.removeEventListener("mousemove", zmenPozici, true);
    document.removeEventListener("mouseup", zrusZmenPozici, true);
   }
  }
 };

 this.maximObnov = function() {
  if(stav == 1) {
   var sirka = (navigator.appName == "Microsoft Internet Explorer") ? (document.width-14) : (screen.width-14);
   var vyska = screen.height-216;
   var okno = Objekt.handleOkna.style;
   predesleX = okno.left;
   predesleY = okno.top;
   predesleH = okno.height;
   predesleW = okno.width;
   predesleOH = Objekt.handleRamu.style.height;
   predesleOW = Objekt.handleRamu.style.width;
   okno.width = sirka+"px";
   okno.height = vyska+"px";
   okno.left = "0px";
   okno.top = "0px";
   var obsah = Objekt.handleRamu.style;
   obsah.width = sirka+"px";
   obsah.height = (vyska-30)+"px";
   try {
    Objekt.handleOkna.firstChild.nextSibling.firstChild.lastChild.previousSibling.title = "Vrátit velikost okna";
   }
   catch(v) {}
   stav = 0;
  }
  else {
   var okno = Objekt.handleOkna.style;
   okno.width = predesleW;
   okno.height = predesleH;
   okno.left = predesleX;
   okno.top = predesleY;
   Objekt.handleRamu.style.height = predesleOH;
   Objekt.handleRamu.style.width = predesleOW;
   try {
    Objekt.handleOkna.firstChild.nextSibling.firstChild.lastChild.previousSibling.title = "Maximalizovat okno";
   }
   catch(v) {}
   stav = 1;
  }
 };

 this.schovat = function() {
  Objekt.handleOkna.style.display = "none";
 };

 this.nahraditKurzor = function(event) {
  if(!event) event = window.event;
  var handleOkna = Objekt.handleOkna;
  if(document.elementFromPoint(event.clientX, event.clientY) == handleOkna) {
   var offsetX = event.clientX - parseInt(handleOkna.style.left);
   var offsetY = event.clientY - parseInt(handleOkna.style.top);
   var sirka = parseInt(handleOkna.style.width)+30;
   var vyska = parseInt(handleOkna.style.height)+30;
   if(isNaN(sirka) || isNaN(vyska)) throw new Error("Chybna vyska nebo sirka.");
   if(offsetY < 10 || offsetY > vyska-22) {
    handleOkna.style.cursor = "s-resize";
    handleOkna.title = "Změnit velikost vertikálně";
   }
   else if(offsetX < 10 || offsetX > sirka-22) {
    handleOkna.style.cursor = "w-resize";
    handleOkna.title = "Změnit velikost horizontálně";
   }
   else {
    handleOkna.removeAttribute("title");
    handleOkna.style.cursor = "move";
   }
  }
  else {
   handleOkna.style.cursor = "move";
  }
 };

 this.zmenaOdkazu = function() {
  Objekt.aktivovat();
  for(i=0;;i++) {
   try {
    document.getElementById(Objekt.ID_OKNA+"_karta_"+i).className = "karta";
   }
   catch(v) { break; }
  }
  this.className = "vybrane karta";
  return false;
 };

 this.registrace = function() {
  var panel = document.getElementById("MiniPanel");
  var prvek = document.createElement("span");
  prvek.onclick = Objekt.aktivovat;
  prvek.id = "mpanel_"+Objekt.ID_OKNA;
  prvek.appendChild(document.createTextNode(Objekt.nazevOkna));
  panel.appendChild(prvek);
 };

 this.zmenitNadpis = function(nadpis) {
  Objekt.handleOkna.firstChild.innerHTML = nadpis;
 };

 // INICIALIZACNI FUNKCE

 window.scrollTo(0,0);
 document.body.style.overflow = "hidden";
 var sirka = screen.width;
 var vyska = screen.height;
 var n = document.createElement("div");
 n.style.position = "absolute";
 n.style.top = "0px";
 n.style.left = "0px";
 n.style.width = sirka+"px";
 n.style.height = vyska+"px";
 n.style.backgroundColor = "black";
 n.style.opacity = "0.5";
 n.id = "poz";
 n.style.zIndex = "90";
 if(navigator.appName == "Microsoft Internet Explorer") {
  var x = document.getElementsByTagName("HTML");
  x[0].style.overflow = "hidden";
  n.style.filter = "alpha(opacity=50)";
 }
 document.body.appendChild(n);

 switch(typOkna) {
  case "modalni": {
   if(typeof parametry != "object") throw new Error("Neplatné vstupní údaje."); // x,y,w,h,nadpis
   this.ID_OKNA = generujID();
   this.handleOkna = document.createElement("div");
   this.handleOkna.id = this.ID_OKNA+"_okno";
   this.handleOkna.className = "plneOkno modalniOkno";
   this.handleOkna.style.top = parametry[0]+"px";
   this.handleOkna.style.left = parametry[1]+"px";
   this.handleOkna.style.zIndex = "1000";
   var sirkaHlavicky = 330;
   e_celkovaSirka = 100+sirkaHlavicky;
   if(e_celkovaSirka > parametry[2]) parametry[2] = e_celkovaSirka;
   this.handleOkna.style.width = (parametry[2]-100)+"px";
   this.handleOkna.style.height = parametry[3]+"px";                                  // JTB
   this.handleOkna.onmousemove = this.nahraditKurzor;
   this.handleOkna.onmousedown = this.presunout;
   var nadpis = document.createElement("h1");
   nadpis.innerHTML = parametry[4];
   this.nazevOkna = parametry[4];
   this.handleOkna.appendChild(nadpis);
   var hlavicka = document.createElement("div");
   hlavicka.onmousedown = this.presunout;
   hlavicka.className = "hlava";
   var ovladaciMenu = document.createElement("div");
   ovladaciMenu.className = "ovladaciMenu";
   var tlacitkoZavrit = document.createElement("img");
   tlacitkoZavrit.src = ADRESAR+"media/oknoTlacZavrit1.bmp";
   tlacitkoZavrit.alt = "Z";
   tlacitkoZavrit.title = "Zavřít okno";
   tlacitkoZavrit.onmouseover = function() { this.src = ADRESAR+"media/oknoTlacZavrit2.bmp"; };
   tlacitkoZavrit.onmouseout = function() { this.src = ADRESAR+"media/oknoTlacZavrit1.bmp"; };
   tlacitkoZavrit.onclick = this.znicit;
   ovladaciMenu.appendChild(tlacitkoZavrit);
   hlavicka.appendChild(ovladaciMenu);
   var vychoziKarta = urlAdresa;
   this.handleOkna.appendChild(hlavicka);
   this.handleRamu = document.createElement("div");
   this.handleRamu.id = this.ID_OKNA+"_obsah";
   this.handleRamu.className = "obsah";
   this.handleRamu.style.height = (parametry[3]-53)+"px";// -60
   this.handleRamu.style.width = (parametry[2]-122)+"px";
   this.handleOkna.appendChild(this.handleRamu);
   aktivniOkno = this.index;
   document.body.appendChild(this.handleOkna);
   break;
  }
  case "dialogove": {
   try {
    this.ID_OKNA = generujID();
    this.handleOkna = document.createElement("div");
    this.handleOkna.className = "okenko";
    this.handleOkna.style.zIndex = "1000";
    this.handleOkna.id = this.ID_OKNA+"_okno";
    this.handleOkna.style.top = "300px";
    this.handleOkna.style.left = "500px";
    this.handleOkna.onmousedown = this.aktivovat;
    var nadpis = document.createElement("h1");
    nadpis.appendChild(document.createTextNode(parametry[0]));
    nadpis.onmousedown = function(event) {
     Objekt.aktivovat();
     prvek = Objekt.handleOkna;
     var deltaX = event.clientX - parseInt(prvek.style.left);
     var deltaY = event.clientY - parseInt(prvek.style.top);
     document.addEventListener("mousemove", mousemove, true);
     document.addEventListener("mouseup", mouseup, true);
     var krokovani = 1;
     function mousemove(e){
      var x = Math.round(e.clientX/krokovani)*krokovani-deltaX;// < 25 ? 10 : e.clientX - deltaX;
      var y = Math.round(e.clientY/krokovani)*krokovani-deltaY;// < 25 ? 10 : e.clientY - deltaY;
      Objekt.handleOkna.style.left = x + "px";
      Objekt.handleOkna.style.top = y + "px";
      e.stopPropagation();
     }
     function mouseup(e){
      document.removeEventListener("mousemove", mousemove, true);
      document.removeEventListener("mouseup", mouseup, true);
     }
    };
    this.handleOkna.appendChild(nadpis);
    var obsah = document.createElement("p");
    obsah.appendChild(document.createTextNode(parametry[1]));
    this.handleOkna.appendChild(obsah);
    var spodek = document.createElement("div");
    spodek.className = "infoRadek";
    switch(urlAdresa) {
     case 1: {
      var tlac1 = document.createElement("button");
      tlac1.onclick = this.znicit;
      tlac1.appendChild(document.createTextNode("OK"));
      spodek.appendChild(tlac1);
      break;
     }
     case 2: {
      var tlac1 = document.createElement("button");
      tlac1.onclick = this.znicit;
      tlac1.appendChild(document.createTextNode("OK"));
      var tlac2 = document.createElement("button");
      tlac2.onclick = this.znicit;
      tlac2.appendChild(document.createTextNode("Storno"));
      spodek.appendChild(tlac1);
      spodek.appendChild(tlac2);
      break;
     }
    }
    this.handleOkna.appendChild(spodek);
    document.body.appendChild(this.handleOkna);
    aktivniOkno = this.index;
   }
   catch(v) { alert(v.message); }
   break;
  }
 }
}

var testuji = false;
function kontrolaHesla(kde) {
 if(testuji) return false;
 testuji = true;
 var test = new RegExp(/[^a-zA-Z0-9_]+/g);
 var test2 = new RegExp(/[0-9]+/g);
 var test3 = new RegExp(/[a-zA-Z_]*/g);
 var x = kde.value;
 var c = x.match(test3);
 var pocet = 0;
 for(var i=0;i<c.length;i++) {
  pocet += c[i].length;
 }
 if(test.test(x) || !test2.test(x) || x.length < 7 || pocet < 6) {
  kde.nextSibling.alt = "NE";
  kde.nextSibling.src = ADRESAR+"media/template/ne.png";
  kde.nextSibling.title = "Položka je vyplněna chybně.";
 }
 else {
  kde.nextSibling.alt = "OK";
  kde.nextSibling.src = ADRESAR+"media/template/ok.png";
  kde.nextSibling.title = "Položka je vyplněna správně.";
 }
 testuji = false;
 return true;
}
function kontrolaHesla2(kde) {
 if(testuji) return false;
 testuji = true;
 if(document.formKomentar.heslo.value == document.formKomentar.hesloKontrola.value && kde.value.length > 0) {
  kde.nextSibling.alt = "OK";
  kde.nextSibling.src = ADRESAR+"media/template/ok.png";
  kde.nextSibling.title = "Položka je vyplněna správně.";
 }
 else {
  kde.nextSibling.alt = "NE";
  kde.nextSibling.src = ADRESAR+"media/template/ne.png";
  kde.nextSibling.title = "Položka je vyplněna chybně.";
 }
 testuji = false;
}
function kontrolaEmail(kde) {
 if(testuji) return false;
 testuji = true;
 var email = kde.value;
 var test = new RegExp(/^.+@.+(\..+)+$/);
 if(email != "@" && email != "") {
  if(!test.test(email)) {
   kde.nextSibling.alt = "NE";
   kde.nextSibling.src = ADRESAR+"media/template/ne.png";
   kde.nextSibling.title = "Položka je vyplněna chybně.";
  }
  else {
   kde.nextSibling.alt = "OK";
   kde.nextSibling.src = ADRESAR+"media/template/ok.png";
   kde.nextSibling.title = "Položka je vyplněna správně.";
  }
 }
 else {
  kde.nextSibling.alt = "NE";
  kde.nextSibling.src = ADRESAR+"media/template/ne.png";
  kde.nextSibling.title = "Položka je vyplněna chybně.";
 }
 testuji = false;
 return true;
}

var puvodniUID = "";
function generovatUID() {
 var cil = document.getElementById("genuid");
 puvodniUID = cil.value;
 if(cil.value.length > 0) {
  var httpRequest = typeof window.ActiveXObject != 'undefined' ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  httpRequest.open("GET", ADRESAR+"/zjistiuid/"+encodeURI(puvodniUID), true);
  httpRequest.onreadystatechange = function () {
   if(httpRequest.readyState == 4) {
    if((httpRequest.status >= 200 && httpRequest.status < 300 ) || httpRequest.status == 304) {
     zobrazAlert("Chyba", httpRequest.responseText, 1);
     cil.value = puvodniUID;
    }
    else { zobrazAlert("Chyba", "Chyba spojení.", 1); cil.value = puvodniUID; }
   }
   else cil.value = "čekejte....";
  }
  httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  httpRequest.send();
 }
 else {
  zobrazAlert("Chyba", "Nejdříve vyplňte přihlašovací jméno.", 1);
 }
}

var provadiSeKontrola = false;
function kontrola(text) {
 if(provadiSeKontrola) return;
 provadiSeKontrola = true;
 var pole = document.getElementById("pocetZnaku").childNodes[0];
 var uk = document.getElementById("ukazatel").firstChild.style;
 var max = new Number(pole.nodeValue);
 var pocet = text.value.length;
 if(pocet > max) text.value = text.value.substr(0, max);
 pocet = text.value.length; 
 uk.width = (pocet/max)*100+"%";
 provadiSeKontrola = false;
}

var testuji = false;
function zobrazAlert(nadpis, text, vaznost) {
 var data = nadpis+"|"+text;
 okna.push(new Okno("dialogove", vaznost, data.split("|")));
}

function login(form) {
 try {
  if(!form.prihlasovaciJmeno.value || !form.heslo.value) throw new Error("Nejsou vyplněny všechny přihlašovací údaje.");
  zakladniOkno = document.getElementById("zakladniOkno");
  if(navigator.cookieEnabled == false) {
   throw new Error('Používáte prohlížeč, který má buď vypnutou podporu cookies nebo je nepodporuje vůbec. Chcete-li, můžete ve stávající konfiguraci přejít na <a href="http://www.livetosee.cz/pda/index.php">textovou verzi</a>.');
  }
  if(navigator.onLine !== undefined && navigator.onLine == false) throw new Error("Prohlížeč je offline.");
  var prohlizec = navigator.appName+"|"+navigator.appVersion+"|"+navigator.appCodeName+"|"+navigator.appMinorVersion+"|"+navigator.vendor+"|"+navigator.vendorSub+"|"+navigator.userAgent+"|"+navigator.product+"|"+navigator.productSub;
  var nastaveniProhlizece = navigator.cookieEnabled+"|"+navigator.javaEnabled();
  var jazyk = navigator.browserLanguage+"|"+navigator.language+"|"+navigator.userLanguage;
  var pocitac = navigator.cpuClass+"|"+navigator.platform;
  var rozliseni = screen.availHeight+"|"+screen.availWidth+"|"+screen.pixelDepth;
  var xml = typeof window.ActiveXObject != 'undefined' ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if(!xml) throw new Error("Prohlížeče nepodporuje technologii AJAX. Není možné se přihlásit, aktualizujte svůj prohlížeč.");
  xml.open("POST", ADRESAR+"login/prohlizec", true);
  xml.onreadystatechange = function() {
   if(xml.readyState == 4) {
    try {
     if(((xml.status >= 200 && xml.status < 300) || xml.status == 304)) {
      //if(navigator.javaEnabled() == false) throw new Error("Pro tuto akci je zapotřebí mít aktivovanou podporu Javy. Pokud ji nemáte nainstalovanou, <a href=\"http://www.java.com/en/download/index.jsp\" target=\"blank\">nainstalujte</a> ji.");
      if(xml.responseText == "0") {
       zobrazAlert("Chyba", "Server odmítl operaci, nebylo možné se přihlásit. Zkuste to později. Také je možné, že nemáte nainstalovanou podporu Javy - nainstalujte ji (http://www.java.com/en/download/index.jsp).", 1);
       //document.getElementById("qvf").contentDocument.location.reload(true);
       return false;
      }
      form.submit();
     }
    }
    catch(v) {
     zobrazAlert("Chyba", v.message, 1);
    }
   }
  }
  xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xml.send("prohl="+prohlizec+"&nastaveniProhlizece="+nastaveniProhlizece+"&jazyk="+jazyk+"&pocitac="+pocitac+"&rozliseni="+rozliseni);
 }
 catch(v) {
  zobrazAlert("Chyba", v.message, 1);
 }
}

function roluj() {
 if(navigator.appName == "Microsoft Internet Explorer") {
  window.scrollTo(0,0);
 }
 else {
  funkce = setInterval(function() {
   window.scrollBy(0,-100);
   if(window.scrollY == 0) this.clearInterval(funkce);
  }, 8);
 }
}

var find = false;
function titulek(kde, event, akce) {
 if(akce == 1) {
  var titulek = document.getElementById("titulek");
  if(!titulek) {
   titulek = document.createElement("div");
   titulek.className = "titulek";
   titulek.id = "titulek";
   titulek.appendChild(document.createTextNode(kde.title));
   document.body.appendChild(titulek);
  }
  var top = (event.clientY+15);
  var left = (event.clientX+15);
  if(left > (screen.width-300)) left = screen.width-300;
  titulek.style.top = top+"px";
  titulek.style.left = left+"px";
 }
 else if(akce == 2) {
  var titulek = document.getElementById("titulek");
  document.body.removeChild(titulek);
 }
}

var permalinkPracuje = false;
function fPermalink(odkud2) {
 if(permalinkPracuje) return;
 permalinkPracuje = true; 
 var odkud = odkud2.value.toLowerCase();
 var kam = document.getElementById("permalink");
 var vysledek = odkud.replace(/[^\wěščřžýáíéďťňůúó\-]+/g, "-");
 var v = "";
 for(var i=0; i<vysledek.length; i++) {
  switch(vysledek.charAt(i)) {
   case 'á': { v += 'a'; break; }
   case 'ě':
   case 'é': { v += "e"; break; }
   case 'í': { v += "i"; break; }
   case 'ó': { v += "o"; break; }
   case 'ů':
   case 'ú': { v += "u"; break; }
   case 'ý': { v += "y"; break; }
   case 'ž': { v += "z"; break; }
   case 'š': { v += "s"; break; }
   case 'č': { v += "c"; break; }
   case 'ř': { v += "r"; break; }
   case 'ď': { v += "d"; break; }
   case 'ť': { v += "t"; break; }
   case 'ň': { v += "n"; break; }
   default: { v += vysledek[i]; }
  }
 }
 kam.value = v;
 permalinkPracuje = false;
}

var polozka = 0;
function aktualizujSeznam(odkud, co) {
 var kam = document.getElementById("okres");
 if(!co) {
  polozka = odkud.selectedIndex;
 }
 else {
  var kraje = new Array("Hlavní město Praha", "Jihočeský kraj", "Jihomoravský kraj", "Karlovarský kraj", "Kraj Vysočina", "Královéhradecký kraj", "Liberecký kraj", "Moravskoslezský kraj", "Olomoucký kraj", "Pardubický kraj", "Plzeňský kraj", "Středočeský kraj", "Ústecký kraj", "Zlínský kraj");
  var okresy = new Array(
  new Array("Hlavní město Praha"),
  new Array("České Budějovice", "Český Krumlov", "Jindřichův Hradec", "Písek", "Prachatice", "Strakonice", "Tábor"),
  new Array("Blansko", "Brno-město", "Brno-venkov", "Břeclav", "Hodonín", "Vyškov", "Znojmo"),
  new Array("Cheb", "Karlovy Vary", "Sokolov"),
  new Array("Havlíčkův Brod", "Jihlava", "Pelhřimov", "Třebíč", "Žďár nad Sázavou"),
  new Array("Hradec Králové", "Jičín", "Náchod", "Rychnov nad Kněžnou", "Trutnov"),
  new Array("Česká Lípa", "Jablonec nad Nisou", "Liberec", "Semily"),
  new Array("Bruntál", "Frýdek-Místek", "Karviná", "Nový Jičín", "Opava", "Ostrava-město"),
  new Array("Jeseník", "Olomouc", "Prostějov","Přerov","Šumperk"),
  new Array("Chrudim", "Pardubice", "Svitavy", "Ústí nad Orlicí"),
  new Array("Domažlice", "Klatovy", "Plzeň-jih", "Plzeň-město", "Plzeň-sever", "Rokycany", "Tachov"),
  new Array("Benešov", "Beroun", "Kladno" , "Kolín" , "Kutná Hora" , "Mělník", "Mladá Boleslav", "Nymburk", "Praha-východ", "Praha-západ", "Příbram", "Rakovník"),
  new Array("Děčín", "Chomutov",  "Litoměřice", "Louny", "Most", "Teplice", "Ústí nad Labem"),
  new Array("Kroměříž", "Uherské Hradiště","Vsetín", "Zlín")
  );
  if(odkud.selectedIndex != polozka) {
   kam.options.length = 0;
   for(var i=0; i<okresy[odkud.selectedIndex].length; i++) {
    var polozka = document.createElement("option");
    polozka.value = (i+1);
    polozka.text = okresy[odkud.selectedIndex][i];
    kam.appendChild(polozka);
   }
  }
 }
}

function upravPopisek(popisek, obrazek) {
 try {
  var puvodniPopisek = popisek.previousSibling.value;
  var xml = typeof window.ActiveXObject != 'undefined' ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if(!xml) throw new Error("Prohlížeče nepodporuje technologii AJAX.");
  xml.open("POST", "./fotografie/upravitPopisek");
  xml.onreadystatechange = function() {
   if(xml.readyState == 4) {
    try {
     if(((xml.status >= 200 && xml.status < 300) || xml.status == 304)) {
      var data = xml.responseText.split("|");
      if(data[0] == "0") {
       popisek.previousSibling.style.color = '#232A58';
      }
      else {
       zobrazAlert("Nastala chyba", xml.responseText, 1);
       popisek.previousSibling.style.color = 'red';
      }
      popisek.previousSibling.value = puvodniPopisek;
      document.body.cursor = "default";
     }
    }
    catch(v) {
     zobrazAlert("Chyba", v.message, 1);
     document.body.cursor = "default";
     popisek.previousSibling.value = puvodniPopisek;
    }
   }
   else {
    popisek.previousSibling.value = "čekejte...";
    document.body.cursor = "wait";
   }
  }
  xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xml.send("obrazek="+obrazek+"&popisek="+puvodniPopisek);
 }
 catch(v) {
  zobrazAlert("Chyba", v.message, 1);
 }
 return false;
}

function vyberKlub(odkud) {
 if(odkud.selectedIndex != 0) {
  odkud.nextSibling.disabled = true;
  odkud.nextSibling.style.backgroundColor = "#363636";
 }
 else {
  odkud.nextSibling.disabled = false;
  odkud.nextSibling.style.backgroundColor = "#B5B7C3";
 }
}

function vyberKrajKlubu(odkud) {
 location.replace("./kluby/strana/0/kraj/"+odkud.previousSibling.previousSibling.options[odkud.previousSibling.previousSibling.selectedIndex].value);
}

function ohodnotObrazek(odkud, album, obrazek) {
 try {
  znamka = odkud.alt;
  if(znamka < 1 || znamka > 5) throw new Error("Neplatné ohodnocení.");
  var xml = typeof window.ActiveXObject != 'undefined' ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  if(!xml) throw new Error("Prohlížeče nepodporuje technologii AJAX.");
  xml.open("POST", "./fotografie/hlasovat");
  xml.onreadystatechange = function() {
   if(xml.readyState == 4) {
    try {
     if(((xml.status >= 200 && xml.status < 300) || xml.status == 304)) {
      if(xml.responseText == "0") {
       for(var i=1; i<=5; i++) {
        var tlacitko = odkud.parentNode.childNodes[i*2-1];
        if(i > odkud.alt*1) {
         tlacitko.src = "./media/template/starn.png";
        }
        else {
         tlacitko.src = "./media/template/star.png";
        }
        tlacitko.removeAttribute("onclick");
        tlacitko.removeAttribute("onmouseover");
        tlacitko.removeAttribute("onmouseout");
        tlacitko.removeAttribute("style");
       }
      }
      else {
       zobrazAlert("Nastala chyba", xml.responseText, 1);
      }
      document.body.cursor = "default";
     }
    }
    catch(v) {
     zobrazAlert("Chyba", v.message, 1);
     document.body.cursor = "default";
    }
   }
   else {
    document.body.cursor = "wait!important";
   }
  }
  xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xml.send("obrazek="+obrazek+"&album="+album+"&znamka="+znamka);
 }
 catch(vyjimka) {
  zobrazAlert("Chyba", vyjimka.message, 1);
 }
}

var jeZmena = false;
function zmenaObr(odkud) {
 jeZmena = true;
 var vrsek = odkud.parentNode;
 for(var i=1; i<=5; i++) {
  if(i > odkud.alt*1) {
   vrsek.childNodes[i*2-1].src = "./media/template/starn.png";
  }
  else {
   vrsek.childNodes[i*2-1].src = "./media/template/star.png";
  }
 }
 jeZmena = false;
}

function zmenaObr2(odkud) {
 for(var i=1; i<=5; i++) if(!jeZmena) odkud.parentNode.childNodes[i*2-1].src = "./media/template/starn.png";
}

var skryvany = -1;
var zobrazovany = -1;
var predchoziSmer = -1;
var beziAnimace = false;
function slider(smer) {
 try {
  if(navigator.appName == "Microsoft Internet Explorer" && parseFloat(navigator.appVersion.split(";")[1].split(" ")[2]) < 8) throw new Error("");
  if(!beziAnimace) {
   beziAnimace = true;
   var kontejner = document.getElementById("seznam");
   var prvky = null;
   if(navigator.appName == "Microsoft Internet Explorer" && parseFloat(navigator.appVersion.split(";")[1].split(" ")[2]) <= 8) {
    prvky = new Array();
    for(var i=0;;i++) {
     if(kontejner.childNodes[i] !== undefined) {
      prvky[i] = kontejner.childNodes[i].style;
     }
     else {
      break;
     }
    }
   }
   else {
    prvky = new Array();
    for(var i=1,j=0;;i+=2,j++) {
     if(kontejner.childNodes[i] !== undefined) {
      prvky[j] = kontejner.childNodes[i].style;
     }
     else {
      break;
     }
    }
   }
   var pocet = prvky.length;
   var sirka = 600;
   if(smer == 1) { // doleva
    if(skryvany == -1 && zobrazovany == -1) zobrazovany = 0;
    else {
     if(predchoziSmer == 0) {
      zobrazovany = skryvany < pocet-1 ? skryvany+1 : 0;
     }
     predchoziSmer = true;
    }
    var aktualniPozice = sirka;
    animace = setInterval( function() {
     if(aktualniPozice < 0) {
      prvky[zobrazovany].left = "0px";
      if(skryvany > -1) {
       prvky[skryvany].left = (-sirka)+"px";
      }
      skryvany = zobrazovany;
      zobrazovany = zobrazovany < prvky.length-1 ? zobrazovany+1 : 0;
      clearInterval(animace);
      beziAnimace = false;
      return;
     }
     else {
      prvky[zobrazovany].left = aktualniPozice+"px";
      if(skryvany > -1) {
       prvky[skryvany].left = (aktualniPozice-sirka)+"px";
      }
      aktualniPozice -= 100;    
     }  
    }, 50);
   }
   else { // doprava
    var aktualniPozice = sirka*(-1);
    if(skryvany == -1 && zobrazovany == -1) zobrazovany = pocet-1;   
    else {
     if(predchoziSmer == 1) {
      zobrazovany = skryvany >= 0 ? skryvany -1 : pocet-1;
     }
     predchoziSmer = false;
    }
    animace = setInterval( function() {
     if(aktualniPozice > 0) {
      prvky[zobrazovany].left = "0px";
      if(skryvany > -1) {
       prvky[skryvany].left = sirka+"px";      
      }
      skryvany = zobrazovany;
      zobrazovany = zobrazovany > 0 ? zobrazovany-1 : pocet-1;     
      clearInterval(animace);
      beziAnimace = false;
      return;
     }
     else {
      prvky[zobrazovany].left = aktualniPozice+"px";
      if(skryvany > -1) {
       prvky[skryvany].left = (sirka+aktualniPozice)+"px";      
      }
      aktualniPozice += 100;
     }  
    }, 0);
   }
  }
 }
 catch(vyjimka) {

 }
}

var head = document.getElementsByTagName("head");
var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.media = "screen";
if(navigator.appName == "Microsoft Internet Explorer") {
 var verze = parseFloat(navigator.appVersion.split(";")[1].split(" ")[2]);
 var head = document.getElementsByTagName("link")[1];
 if(verze < 8) {
  document.getElementsByTagName("link")[1].href = "";
 }
}


hs.graphicsDir = './scripts/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.wrapperClassName = 'dark borderless floating-caption';
hs.fadeInOut = true;
hs.dimmingOpacity = .75;
if (hs.addSlideshow) hs.addSlideshow({
 //slideshowGroup: 'group1',
 interval: 5000,
 repeat: false,
 useControls: true,
 fixedControls: 'fit',
 overlayOptions: {
  opacity: 1,
  position: 'bottom center',
  hideOnMouseOut: true
 }
});

   
 
