var xmlhttp = new Object();

function nacist(dom_id,url) {
  if(xmlhttp[dom_id]!=undefined) xmlhttp[dom_id].abort();
  xmlhttp[dom_id] = (window.XMLHttpRequest?new XMLHttpRequest():(window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):false));
  if(!xmlhttp[dom_id]) return alert("Váš prohlížeč nepodporuje AJAX");
  xmlhttp[dom_id].open("GET",url);
  xmlhttp[dom_id].onreadystatechange = function () {
    if(xmlhttp[dom_id].readyState!=4) return false;
    if(xmlhttp[dom_id].status==0) return false;
    document.getElementById(dom_id).innerHTML = xmlhttp[dom_id].responseText;
  };
  xmlhttp[dom_id].setRequestHeader("X-Requested-With","XMLHttpRequest");
  xmlhttp[dom_id].send(null);
  return true;
}

function hodnotit(dom_id,hodnotit,id,h) {
  return nacist(dom_id,'?hodnotit='+hodnotit+'&id='+id+'&h='+h);
}

var tmp_obrazek = new Image();

function ukazat2() {
  if(!document.getElementById("obrazek2")) return false;

  var vyska = tmp_obrazek.height;
  var sirka = tmp_obrazek.width;
  var vyska_str;
  var sirka_str;

  if(typeof window.innerWidth!="undefined") {
    sirka_str = window.innerWidth;
    vyska_str = window.innerHeight;
  }
  else if(typeof document.documentElement!="undefined" && typeof document.documentElement.clientWidth!="undefined" && document.documentElement.clientWidth!=0) {
    sirka_str = document.documentElement.clientWidth;
    vyska_str = document.documentElement.clientHeight;
  }
  else {
    sirka_str = document.getElementsByTagName('body')[0].clientWidth;
    vyska_str = document.getElementsByTagName('body')[0].clientHeight;
  }
    
  sirka_str-=80;
  vyska_str-=80;

  if(sirka>sirka_str) {
    var procenta = sirka_str/sirka;
    vyska *= procenta;
    sirka *= procenta;
  }
  if(vyska>vyska_str) {
    var procenta = vyska_str/vyska;
    vyska *= procenta;
    sirka *= procenta;
  }
  
  document.getElementById("obrazek2").innerHTML = "<img src='"+tmp_obrazek.src+"' style='border:5px solid #eee;position:fixed;left:50%;top:50%;margin:-"+(vyska/2)+"px 0 0 -"+(sirka/2)+"px;z-index:999;width:"+sirka+"px;height:"+vyska+"px;'>";
}

function ukazat(url) {
  tmp_obrazek.src = false;
  document.body.innerHTML += "<a href='#' onclick='document.body.removeChild(document.getElementById(\"obrazek2\"));document.body.removeChild(this);' id='obrazek' style='display:block;position:fixed;top:0;left:0;right:0;bottom:0;background:#000 url(\"/img/loading.gif\") 50% 50% no-repeat;z-index:999;opacity:0.5;filter:alpha(opacity=50);'></a>";
  document.body.innerHTML += "<a href='#' onclick='document.body.removeChild(document.getElementById(\"obrazek\"));document.body.removeChild(this);' id='obrazek2'></a>";
  tmp_obrazek.src = url;
  tmp_obrazek.onload = ukazat2;
}

var zmenit_opacity = 1;
var zmenit_el_aktualni = null;
var zmenit_el_novy = null;
var zmenit_a = false;
var zmenit_c = false;
var zmenit_tn = null;
var zmenit_t = null;

function zmenit() {
  zmenit_el_aktualni = document.getElementById(zmenit_prefix+zmenit_aktual);
  zmenit_el_novy = document.getElementById(zmenit_prefix+zmenit_novy);
  zmenit_opacity = 0;
  zmenit_a = true;
  zmenit2();
}

function zmenit2() {
  if(zmenit_opacity>100) {
    zmenit_el_aktualni.style.display = 'none';
    zmenit_aktual = zmenit_novy;
    zmenit_novy++;
    if(zmenit_novy>zmenit_celkem) zmenit_novy=1;
    zmenit_a = false;
    zmenit_t = setTimeout('zmenit();',zmenit_timeout);
    return true;
  }
  zmenit_el_aktualni.style.opacity = Math.round(100-zmenit_opacity)/100;
  zmenit_el_novy.style.opacity = Math.round(zmenit_opacity)/100;
  zmenit_el_aktualni.style.filter = 'alpha(opacity='+Math.round(100-zmenit_opacity)+')';
  zmenit_el_novy.style.filter = 'alpha(opacity='+Math.round(zmenit_opacity)+')';
  zmenit_el_aktualni.style.display = 'block';
  zmenit_el_novy.style.display = 'block';
  zmenit_opacity += 10;
  setTimeout('zmenit2();',50);
}

function zmenit3(novy) {
  zmenit_tn = novy;
  if(zmenit_c) return false;
  zmenit_c = true;
  setTimeout('zmenit4();',40);
}

function zmenit4() {
  if(zmenit_a) setTimeout('zmenit4();',40); else {
    if(zmenit_aktual==zmenit_tn) return false;
    clearTimeout(zmenit_t);
    zmenit_novy = zmenit_tn;
    zmenit_c = false;
    zmenit();
  }
}



window.onload = function() {
  var hledani = document.getElementById('hledani_input');
  hledani.onfocus = function() {if(this.value=='Hledaný výraz …'){this.value='';}}
  hledani.onblur = function() {if(this.value=='')this.value='Hledaný výraz …';}

  var kon_jmeno = document.getElementById('kon_jmeno');
  if(kon_jmeno) kon_jmeno.onblur = function() {
    var fak_jmeno = document.getElementById('fak_jmeno');
    if(fak_jmeno.value=='') fak_jmeno.value = this.value;
  }
  var kon_prijmeni = document.getElementById('kon_prijmeni');
  if(kon_prijmeni) kon_prijmeni.onblur = function() {
    var fak_prijmeni = document.getElementById('fak_prijmeni');
    if(fak_prijmeni.value=='') fak_prijmeni.value = this.value;
  }
}



