// pozice mysi
var mouseXJ = 0;
var mouseYJ = 0;

if(typeof jQuery == 'function'){

  jQuery(document).ready(function(){
     jQuery(document).mousemove(function(e){
        mouseXJ = e.pageX;
        mouseYJ = e.pageY;
     });
  });
}

// vlozeni souboru javascriptu
function includeJScript(JScript)
{
    window.document.write('<script type="text/javascript" src="' + JScript + '"><\/script>');
}

// videoprehravac
function resizePlayer(width,ratio){  
  var height = width * ratio; 
  document.getElementById("as4u_flvPlayer").style.width = width+"px";
  document.getElementById("as4u_flvPlayer").style.height = height+"px";
  return true;  
}

// calendar
var calendar_to_element_old = '';
var fromDateSet;
var toDateSet;
                                                                                  //30.3.2011 - pridana moznost predat event kvuli pozici mysi a korektnimu zobrazeni kalendare
function load_ajax_calendar(to_element, rok, mesic, fromDate, toDate, fromDateElm, event) {

  if(document.getElementById('global_lanG')){
    var langCalendar = document.getElementById('global_lanG').value
  } else {
    var langCalendar = getQueryString()["lanG"];
  }

  if(!document.getElementById('bs_common_calendar')){

    var calendarDiv = document.createElement('div');
    calendarDiv.setAttribute('id', 'bs_common_calendar');
    document.body.appendChild(calendarDiv);

    document.getElementById('bs_common_calendar').style.display = 'none';
    document.getElementById('bs_common_calendar').style.position = 'absolute';

    document.getElementById('bs_common_calendar').style.zIndex = 15;

    document.getElementById('bs_common_calendar').style.backgroundColor = 'white';
    document.getElementById('bs_common_calendar').style.border = '5px solid #cccccc';

    document.getElementById('bs_common_calendar').style.padding = '0px';
  }


  if((mesic == 0) && (mesic != '')){
    mesic = document.getElementById('ajax_cal_mesic').value;
  }

  var fromDateElmDate = '';
  if(document.getElementById(fromDateElm)){
    fromDateElmDate = document.getElementById(fromDateElm).value;
  }

  myDiv = document.getElementById('bs_common_calendar');

  if((myDiv.style.display == "none") || (calendar_to_element_old != to_element)){

    myDiv.innerHTML = "";
    myDiv.style.display = "";
    myDiv.innerHTML = '<img src="/images/gallery/loading.gif" />';
    if (event) {
      //console.log(event);
      if (event.pageX && event.pageY) {
        //console.log('pageX : ' + event.pageX);
        //console.log('pageY : ' + event.pageY);
        var topPos = event.pageY + 10;
        var leftPos = event.pageX;

      } else if(event.clientX && event.clientY) {
        var topPos = event.clientY + (document.documentElement.scrollTop ?
                         document.documentElement.scrollTop :
                         document.body.scrollTop) + 10;
        //var topPos = event.x + 10;
        var leftPos = event.clientX + (document.documentElement.scrollLeft ?
                                     document.documentElement.scrollLeft :
                                     document.body.scrollLeft);
        //console.log('X : ' + leftPos);
        //console.log('Y : ' + topPos);
       } else {

        var topPos = mouseYJ + 10;
        var leftPos = mouseXJ;
      }
      //console.log('mouseX : ' + mouseYJ);
      //console.log('mouseY : ' + mouseYJ);

    } else {
        var topPos = mouseYJ + 10;
        var leftPos = mouseXJ;

    }

    myDiv.style.top = topPos + 'px';
    myDiv.style.left = leftPos + 'px';

    fromDateSet = fromDate;
    toDateSet = toDate;
  }
  calendar_to_element_old = to_element;

  var params = "&lanG=" + langCalendar +
               "&toBsElement=" + to_element +
               "&rok=" + rok +
               "&mesic=" + mesic +
               "&fromDate=" + fromDateSet +
               "&toDate=" + toDateSet +
               "&fromDateElmDate=" + fromDateElmDate;

  $("div#bs_common_calendar").load('/bs/ajax.php?akce=calendar' + params);


}

function bs_common_calendar_move(){
  $(function(){
      $("#bs_common_calendar").draggable({ handle: 'div.calendar_move' });
    }
  )
}

function date2element(elm2, dateFormat){
  var el = document.getElementById(elm2);
  el.value = dateFormat;
  el.focus();
  el.blur();
  $(el).trigger('change'); // trigger change event in input - Ing. Jindrich Ruzicka
  close_common_calendar();
}

function close_common_calendar(){
  $("#bs_common_calendar").hide(300);
}


// nova galerie

var galSizeH = 0;
var galSizeW = 0;
var galScroll = 0;
var galMiniH = 0;
var galTopDivH = 0;
var galId = 0;

var aktualFoto = 0;
var predesleFoto = 0;
var dalsiFoto = 0;
var oldFoto = 0;

var casovacBloku;
var casovacPrehravani;
var gallang = 'cs';

var jMousePosX = 0;
var jMousePosY = 0;

var jMousePosXold = 0;
var jMousePosYold = 0;

if(typeof jQuery == 'function'){
jQuery(document).ready(function() {
   jQuery(document).mousemove( function(e) {
      jMousePosX = e.pageX;
      jMousePosY = e.pageY;
   }); 
});
}

function showOvlGal(){
  if(document.getElementById('galery_view_transparent').style.display == ""){
    if((jMousePosXold == jMousePosX) && (jMousePosYold == jMousePosY) && (oldFoto == aktualFoto)){
      
      jQuery("#gal_popis_transparent").hide(500);
      jQuery("#gal_popis").hide(10);
      jQuery("#gal_a_predchozi").hide(10);
      jQuery("#gal_a_dalsi").hide(10);
      jQuery("#gal_a_close").hide(10);
      
      setTimeout("showOvlGal()", 100);
      
    } else {
      
      oldFoto = aktualFoto;
      
      jQuery("#gal_popis_transparent").show(200);
      jQuery("#gal_popis").show(10);
      jQuery("#gal_a_predchozi").show(10);
      jQuery("#gal_a_dalsi").show(10);
      jQuery("#gal_a_close").show(10);
      
      setTimeout("showOvlGal()", 3000);
      
    }
    
    jMousePosXold = jMousePosX;
    jMousePosYold = jMousePosY;
  }
  
}


function imageStarSelected(iStar){

  for (var i=1;i<=5;i++){
    if(i <= iStar){
      jQuery("#imageStar" + i).attr("src","/images/gallery/hvezdicka_zluta.png");
    } else {
      jQuery("#imageStar" + i).attr("src","/images/gallery/hvezdicka_cerna.png");
    }

  }
}

function imgReviewsSet(imgSet, score){
  
  var params = "&imgSet=" + imgSet +
               "&score=" + score +
               "&subakce=set_score";

  jQuery('#image_hodnoceni_div_star').load('/galerie/ajax.php?akce=gal_mini&lanG=' + gallang + params, function(){});

/*
  jQuery.get('/galerie/ajax.php?akce=gal_mini&lanG=' + gallang + params' + params,
    function(xml) {
      jQuery(xml).find('response').each(function(){
        alert(jQuery(this).find('status').text());
     });
		}, "xml");
 */ 
}


function galWinDim(){
  
	if (window.innerHeight){
    galSizeH = window.innerHeight;
    galSizeW = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight){
		galSizeH = document.documentElement.clientHeight;
		galSizeW = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientHeight){
		galSizeH = document.body.clientHeight;
		galSizeW = document.body.clientWidth;
  }
  
  if(jQuery.browser.msie == undefined){
    galSizeW = galSizeW - 18;
  }

  
  if(galSizeH == 0){
    alert('Error');
  } else {
    document.getElementById('galery_view_transparent').style.height = (galSizeH) + 'px';
    document.getElementById('galery_view').style.height = (galSizeH) + 'px';
    document.getElementById('galery_view_transparent').style.width = (galSizeW) + 'px';
    document.getElementById('galery_view').style.width = (galSizeW) + 'px';
    casovacBloku = setTimeout('galWinDim()',100);
  }

  if (document.documentElement && document.documentElement.scrollTop) {
    galScroll = document.documentElement.scrollTop;
  } else if (document.body) {
    galScroll = document.body.scrollTop;
  } else {
    galScroll = 0;
  }
  document.getElementById('galery_view_transparent').style.top = (galScroll) + 'px';
  document.getElementById('galery_view').style.top = (galScroll) + 'px';
  
  if(document.getElementById('gal_minidiv')){
    galTopDivH = galSizeH - galMiniH ;
    document.getElementById('gal_topdiv').style.height = (galTopDivH) + 'px';
    document.getElementById('gal_topdiv').style.width = (galSizeW) + 'px';
    document.getElementById('gal_minidiv').style.width = (galSizeW) + 'px';
  }
  if(document.getElementById('gal_miniobal')){
    document.getElementById('gal_miniobal').style.width = (galSizeW) + 'px';
  }  
}

function showgalery(obr, gal, minisize, lang){
  var galeryDiv;
  minisize = 120;
  galMiniH = minisize;
  galId = gal;
  gallang = lang;
  document.getElementById('galery_view').style.display = '';
  document.getElementById('galery_view_transparent').style.display = '';
  //document.getElementById('galery_view').focus();
  galeryDiv = '<div style="width: 0px; height: ' + (minisize) + 'px; padding: 0px;	margin: 0px;" id="gal_minidiv"></div>';
  galeryDiv += '<div style="width: 0px; padding: 0px; margin: 0px; height: 0px;" id="gal_topdiv"></div>';
  
  document.getElementById('galery_view').innerHTML = galeryDiv;

  galWinDim();  
  showObrGal(obr);
  setTimeout('loadMiniWait()',100);
  
  showOvlGal();
  
}

function loadMiniWait(){
  if(document.getElementById('gal_topdiv').innerHTML != ''){
    loadMini();
  } else {
    setTimeout('loadMiniWait()',100);
  }
}



function showObrGal(obr){
  if(aktualFoto != obr){
    if(document.getElementById('igal4u' + aktualFoto)){
      document.getElementById('igal4u' + aktualFoto).style.border = '2px solid black';
    }
    if(document.getElementById('igal4u' + obr)){
      document.getElementById('igal4u' + obr).style.border = '2px solid white';
    }
    
    aktualFoto = obr;
    //myDiv = document.getElementById('gal_topdiv');
    var params = "&subakce=obrshow" +
                 "&obr=" + obr + 
                 "&galTopDivH=" + galTopDivH + 
                 "&galSizeW=" + galSizeW;

    jQuery("#gal_topdiv").load('/galerie/ajax.php?akce=gal_mini&lanG=' + gallang + params, '',
      function(){
        afterLoadMini();
      }
    );
    /*    
    if (xmlHttp)
    {
      try
      {
        xmlHttp.open('GET', '/galerie/ajax.php?akce=gal_mini&lanG=' + gallang + params, true);
        xmlHttp.onreadystatechange = handleRequestStateChange;
        xmlHttp.send(null);
      }
      catch (e)
      {
        alert("Can't connect to server 2:\n" + e.toString());
      }
    }
    afterLoadMini();
    */
  }
}

function loadMini(){

  //myDiv = document.getElementById('gal_minidiv');
  var params = "&subakce=mini" +
               "&gal=" + galId + 
               "&galSizeW=" + galSizeW +
               "&minih=" + galMiniH;

  jQuery("#gal_minidiv").load('/galerie/ajax.php?akce=gal_mini&lanG=' + gallang + params, '',
    function(){
      afterLoadMini();
    }
  );
  /*        
  if (xmlHttp)
  {
    try
    {
      xmlHttp.open('GET', '/galerie/ajax.php?akce=gal_mini&lanG=' + gallang + params, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }
    catch (e)
    {
      alert("Can't connect to server 2:\n" + e.toString());
    }
  }
  
  setTimeout('loadAfterMiniWait()',100);
  */
  
}
/*
function loadAfterMiniWait(){
  if(document.getElementById('seznam_fotek')){
    afterLoadMini();
  } else {
    setTimeout('loadAfterMiniWait()',100);
  }
}
*/

function afterLoadMini(){
  if(document.getElementById('seznam_fotek')){
    var minuleVpoli = 0;
    var nastavDalsi = 0;
    
    document.getElementById('agal4u' + aktualFoto).focus();
    
    document.getElementById('igal4u' + aktualFoto).style.border = '2px solid white'; // style=\"border: 2px solid black;\"
  
    var sznFoto = document.getElementById('seznam_fotek').innerHTML;
    var sznFotoArr = sznFoto.split(',');
    
    predesleFoto = 0;
    dalsiFoto = 0;
    
    for (i=0;i<sznFotoArr.length;i++){
      
      if(aktualFoto == sznFotoArr[i]){
        predesleFoto = minuleVpoli;
        nastavDalsi = 1;
      } else if (nastavDalsi == 1){
        dalsiFoto = sznFotoArr[i];
        break;
      }
      minuleVpoli = sznFotoArr[i];
    }
    setTimeout('waitLoadPopis()',100);
  }
}

function waitLoadPopis(){
  if(document.getElementById('galIdPopisObr')){
    if(document.getElementById('galIdPopisObr').innerHTML == aktualFoto){

      var widthPop = document.getElementById('gal_popis').offsetWidth;
      var heightPop = document.getElementById('gal_popis').offsetHeight;

      document.getElementById('gal_popis_transparent').style.width = widthPop + 'px';
      document.getElementById('gal_popis_transparent').style.height = heightPop + 'px';
    
    } else {
      setTimeout('waitLoadPopis()',100);
    }
  } else {
    setTimeout('waitLoadPopis()',100);
  }
}

function galPopisClose(){
  document.getElementById('gal_popis').style.display = 'none';
  document.getElementById('gal_popis_transparent').style.display = 'none';
}


function prevFoto(){
  if(predesleFoto > 0){
    showObrGal(predesleFoto);
  }
}

function nextFoto(){
  if(dalsiFoto > 0){
    showObrGal(dalsiFoto);
  }
}

function galPlay(){
  if(dalsiFoto > 0){
    nextFoto();
    casovacPrehravani = setTimeout('galPlay()', 5000);
  } else {
    clearTimeout(casovacPrehravani);
  }
}

function galPlayStop(){
  clearTimeout(casovacPrehravani);
}

function closeGalery(){
  clearTimeout(casovacPrehravani);
  document.getElementById('galery_view').style.display = 'none';
  document.getElementById('galery_view').style.height = '0px';
  document.getElementById('galery_view').style.width = '0px';

  document.getElementById('galery_view_transparent').style.display = 'none';
  document.getElementById('galery_view_transparent').style.height = '0px';
  document.getElementById('galery_view_transparent').style.width = '0px';


  document.getElementById('galery_view').style.innerHTML = '';

  aktualFoto = 0;
  predesleFoto = 0;
  dalsiFoto = 0;
}

function checkKey(evt){

  var charCode = (evt.which) ? evt.which : event.keyCode

  if(charCode == 37){
    prevFoto();
  } else if(charCode == 39){
    nextFoto();
  } else if(charCode == 80){
    galPlay();
  } else if(charCode == 83){
    galPlayStop();
  } else if(charCode == 27){
    closeGalery();
  } 

}






// konec nove galsrie

var neww = false;
function openw(co,okno,jak,nazev){
  var verze = parseInt(navigator.appVersion);
  var wi = 'width=';
  var hi = 'height=';
  var res = 'resizable=';
  var scr = 'scrollbars=';

  if (verze >= 4){

    sirkao = screen.width;
    vyskao = screen.height;

    var sirkaz = co.indexOf('x=') + 2;
    var sirkat = co.substr(sirkaz);
    var sirkak = sirkat.indexOf('&');
    if(sirkak > 0){
      var sirka = sirkat.substr(0, sirkak);
    }
    else{
      var sirka = sirkat;
    }

    var vyskaz = co.indexOf('y=') + 2;
    var vyskat = co.substr(vyskaz);
    var vyskak = vyskat.indexOf('&');

    if(vyskak > 0){
      var vyska = vyskat.substr(0, vyskak);
    }
    else{
      var vyska = vyskat;
    }

    sirka = sirka * 1;
    vyska = vyska * 1;

    if((isNaN(sirka) == true) && (isNaN(vyska) == true)){
      var res2cd1 = co.split('_');
      sirka = res2cd1[1];
      var res2cd2 = res2cd1[2].split('.');
      vyska = res2cd2[0];
    }

//    vyska = (vyska * 1) + 30;

  	if(sirka > sirkao){
  	  wih = sirkao;
      resh = 1;
      scrh = 1;
    }
    else{
      wih = sirka;
      resh = 0;
      scrh = 0;
    }

  	if(vyska > (vyskao - 30)){
  	  hih = vyskao;
      resh = 1;
      scrh = 1;
    }
    else{
      hih = vyska;
      if(scrh == 0){
        resh = 0;
        scrh = 0;
      }
    }

    wih = wih * 1;
    hih = hih * 1;

    if(scrh == 1){
      if((wih + 19) < sirkao){
        wih = wih + 19;
      }
      if((hih + 19) < vyskao){
        hih = hih + 19;
      }
    }

    var odshora = (vyskao - hih) / 2;
    if(odshora < 0){
      odshora = 0;
    }

    odboku = (sirkao - wih) / 2;
    if(odboku < 0){
      odboku = 0;
    }

    jak = wi + wih + ', ' + hi + hih + ', ' + res + resh + ', ' + scr + scrh + ', top=' + odshora + ', left=' + odboku;
  }

  if(neww != false){
	  if (typeof(neww.document) == "object"){
	   try {
		  neww.window.close();
		  } catch(e) {}
		}
	}

	neww=window.open('',okno,jak);
	neww.document.write("<html>\n<head>\n");
	neww.document.write("<title>"+nazev+"</title>\n</head>\n");
	neww.document.write("<body style=\"margin: 0;\">\n");
	neww.document.write("<div style=\"width: 100%; position: absolute; top: 40%; left: 0px; text-align: center; z-index: 1;\">Please wait ...</div>\n");
	neww.document.write("<a href=\"javascript:window.close()\" style=\"position: absolute; top: 0px; left: 0px; z-index: 2;\"><img src=\""+co+"\" border=\"0\" alt=\""+nazev+"\"></a>\n");
	neww.document.write("</body>\n");
	neww.document.write("</html>");
}

function prihlaseni(url) {
	var w=370;
	var h=280;
	var windowfeatures='toolbar=no, scrollbars=yes, resizable=yes, menubar=no';
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
	win = window.open(url, "prihlaseni", winprops+windowfeatures)
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

function regwindow(url){
	var w=600;
	var h=400;
	var windowfeatures='toolbar=0, scrollbars=1, resizable=1, menubar=0';
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
	win = window.open(url, "registrace", winprops+windowfeatures)
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

function appwindow(url, wu, hu, wname){

	var w;
	var h;

  sirkao = screen.width;
  vyskao = screen.height;

  if(wu >= sirkao){wu = (sirkao - 40)}
  if(hu >= vyskao){hu = (vyskao - 50)}

	if(wu > 0){
    w = wu;
  }
  else{
    w = 600;
  }
	if(hu > 0){
    h = hu;
  }
  else{
    h = 400;
  }

  if(wname == ''){
    wname = 'registrace';
  }

  var windowfeatures='toolbar=0, scrollbars=1, resizable=1, menubar=0';
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
	win = window.open(url, "registrace", winprops+windowfeatures)
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

function appopen(url){
  if(opener == '[object]'){
    window.open(url);
    window.close();
  }
  else{
    parent.location.href=url;
  }
}

function datetoform(datum, kam){
  window.opener.document.getElementById(kam).value = datum;
  window.close();
}


function confirmLink(theLink, theMsg){
    var is_confirmed = confirm(theMsg);
    if (is_confirmed) {
    }
    return is_confirmed;
}

// obecna kontrole emailu
function as4u_kontrola_emailu(adresa){
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,6}$/;
  return adresa.search(re) == 0;
}


// komunita
function komunita_kontrola_reg_formulare(){
  if (document.getElementById('uzivatelske_jmeno').value == ""){
    alert("Musíte si zvolit uživatelské jméno (nickname)!");
    document.getElementById('uzivatelske_jmeno').focus();
    return false;
  } else if (document.getElementById('heslo').value == ""){
    alert("Musíte si zvolit heslo!");
    document.getElementById('heslo').focus();
    return false;
  } else if (document.getElementById('heslok').value != document.getElementById('heslo').value){
    alert("Zadaná hesla jsou rozdílná!");
    document.getElementById('heslo').focus();
    return false;
  } else if (!as4u_kontrola_emailu(document.getElementById('emailreg').value)){
    alert("Zadaný email je neplatný!");
    document.getElementById('emailreg').focus();
    return false;
  } else if (document.getElementById('souhlas_podminek').checked == false){
    alert("S podmínkami musíte souhlasit!");
    document.getElementById('souhlas_podminek').focus();
    return false;
  } else {
    return true;
  }
}



function komunita_kontrola_pis_reg_formulare(){
  if (document.getElementById('uzivatelske_jmeno').value == ""){
    alert("Musíte si zvolit uživatelské jméno (nickname)!");
    document.getElementById('uzivatelske_jmeno').focus();
    return false;
  } else if (document.getElementById('heslo').value == ""){
    alert("Musíte si zvolit heslo!");
    document.getElementById('heslo').focus();
    return false;
  } else if (document.getElementById('heslok').value != document.getElementById('heslo').value){
    alert("Zadaná hesla jsou rozdílná!");
    document.getElementById('heslo').focus();
    return false;
  } else if (document.getElementById('jmeno').value == ""){  
    alert("Musíte zadat jméno!");
    document.getElementById('jmeno').focus();
    return false;
  } else if (document.getElementById('prijmeni').value == ""){
    alert("Musíte zadat příjmení!");
    document.getElementById('prijmeni').focus();
    return false;
  } else if (document.getElementById('ulice').value == ""){
    alert("Musíte zadat ulici!");
    document.getElementById('ulice').focus();
    return false;
  } else if (document.getElementById('cislo_popisne').value == ""){
    alert("Musíte zadat číslo popisné!");
    document.getElementById('cislo_popisne').focus();
    return false;
  } else if (document.getElementById('cislo_popisne').value != parseInt(document.getElementById('cislo_popisne').value)){
    alert("Číslo popisné  není platné!");
    document.getElementById('cislo_popisne').focus();
    return false;
  } else if (document.getElementById('orientacni_cislo').value == ""){
    alert("Musíte zadat orientační číslo!");
    document.getElementById('orientacni_cislo').focus();
    return false;
  } else if (document.getElementById('orientacni_cislo').value != parseInt(document.getElementById('orientacni_cislo').value)){
    alert("Orientační číslo není platné!");
    document.getElementById('orientacni_cislo').focus();
    return false;
  } else if (document.getElementById('mesto').value == ""){
    alert("Musíte zadat město/obec!");
    document.getElementById('mesto').focus();
    return false;
  } else if (document.getElementById('psc').value == ""){
    alert("Musíte zadat PSČ!");
    document.getElementById('psc').focus();
    return false;
  } else if (document.getElementById('psc').value != parseInt(document.getElementById('psc').value) || document.getElementById('psc').value.length != 5){
    alert("PSČ není platné!");
    document.getElementById('psc').focus();
    return false;
  } else if (document.getElementById('telefon').value == ""){
    alert("Musíte zadat telefon!");
    document.getElementById('telefon').focus();
    return false;
  } else if (document.getElementById('telefon').value != parseInt(document.getElementById('telefon').value)){
    alert("telefoní číslo není platné!");
    document.getElementById('telefon').focus();
    return false;
  } else if (!as4u_kontrola_emailu(document.getElementById('emailreg').value)){
    alert("Zadaný email je neplatný!");
    document.getElementById('emailreg').focus();
    return false;
  } else if (document.getElementById('souhlas_podminek').checked == false){
    alert("S podmínkami musíte souhlasit!");
    document.getElementById('souhlas_podminek').focus();
    return false;
  } else {
    return true;
  }
}


function as4ucheckun(as4u_elm_un){

  var uname = document.getElementById(as4u_elm_un).value;
  if(uname != ''){

    myDiv = document.getElementById(as4u_elm_un);

    var params = '&subakce=overeni_jmena_as4u' +
                 '&uname=' + uname;

    if (xmlHttp)
    {
      try
      {
        xmlHttp.open('GET', 'http://' + document.location.host + '/registrace/ajax.php?akce=registrace&lanG=cs' + params, true);
        xmlHttp.onreadystatechange = handleRequestOvereniJmenaAs4u;
        xmlHttp.send(null);
      }
      catch (e)
      {
        alert("Can't connect to server 2:\n" + e.toString());
      }
    }
  }
}

function handleRequestOvereniJmenaAs4u(){
  if (xmlHttp.readyState == 4)
  {
    if (xmlHttp.status == 200)
    {
      try
      {
        handleServerOvereniJmenaAs4u();
      }
      catch(e)
      {
        alert("Error reading the response: " + e.toString());
      }
    }
    else
    {
      alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
    }
  }
}

function handleServerOvereniJmenaAs4u(){
  var xmlResponse = xmlHttp.responseXML;
  if (!xmlResponse || !xmlResponse.documentElement)
    throw("Invalid XML structure:\n" + xmlHttp.responseText);
  var rootNodeName = xmlResponse.documentElement.nodeName;
  if (rootNodeName == "parsererror")
    throw("Invalid XML structure:\n" + xmlHttp.responseText);
  xmlRoot = xmlResponse.documentElement;

  if (rootNodeName != "response" || !xmlRoot.firstChild)
    throw("Invalid XML structure:\n" + xmlHttp.responseText);

  if(xmlRoot.getElementsByTagName("odp").item(0).firstChild.data != 'OK'){
    alert(xmlRoot.getElementsByTagName("alert").item(0).firstChild.data);
    myDiv.value = "";
    myDiv.focus();
  }


}

// ajaxove okno
function as4uAjaxAlertShow(aaWidth, aaHeight){

  document.getElementById('ajax_transparent').style.display = '';
  document.getElementById('ajax_view').style.display = '';
  as4uAjaxAlertShowSize(aaWidth, aaHeight);

}


function as4uAjaxAlertShowSize(aaWidth, aaHeight){
  aaWidth = aaWidth * 1;
  aaHeight = aaHeight * 1;

  aaWidthOriginal = aaWidth;
  aaHeightOriginal = aaHeight;

  if(document.getElementById('ajax_transparent').style.display != 'none'){

    wSizeH = jQuery(window).height();
    wSizeW = jQuery(window).width();

    if(!jQuery.browser.msie){
      wSizeW = wSizeW - 20;
    }

    if(aaHeight > wSizeH){
      aaHeight = wSizeH - 40;
      aaWidth = aaWidth + 20;
    }
    
    if(aaWidth > wSizeW){
      aaWidth = wSizeW - 20;
    }

    if(wSizeH == 0){
    } else {
      document.getElementById('ajax_transparent').style.height = wSizeH + 'px';
      document.getElementById('ajax_transparent').style.width = wSizeW + 'px';

      ajaxSizeObH = (aaHeight * 1) + 20;
      ajaxSizeObW = (aaWidth * 1);

      document.getElementById('ajax_view').style.height = ajaxSizeObH + 'px';
      document.getElementById('ajax_view').style.width = ajaxSizeObW + 'px';
      document.getElementById('ajax_view_close').style.width = ajaxSizeObW + 'px';

      ajaxSizeH = ajaxSizeObH - 20;
      ajaxSizeW = ajaxSizeObW;

      document.getElementById('ajax_content').style.height = ajaxSizeH + 'px';
      document.getElementById('ajax_content').style.width = ajaxSizeW + 'px';

      posAjaxH = ((wSizeH - ajaxSizeObH) / 2);
      posAjaxW = ((wSizeW - ajaxSizeW) / 2);

      if (document.documentElement && document.documentElement.scrollTop) {
        winScroll = document.documentElement.scrollTop;
      } else if (document.body) {
        winScroll = document.body.scrollTop;
      } else {
        winScroll = 0;
      }
      
      document.getElementById('ajax_transparent').style.top = (winScroll) + 'px';
      
      document.getElementById('ajax_view').style.top = (winScroll + posAjaxH) + 'px';
      document.getElementById('ajax_view').style.left = (posAjaxW) + 'px';
      
      setTimeout('as4uAjaxAlertShowSize(' + aaWidthOriginal + ', ' + aaHeightOriginal + ')', 100);
      
    }
  
  }
}

function closeajax(){

  document.getElementById('ajax_transparent').style.display = 'none';
  document.getElementById('ajax_view').style.display = 'none';
  document.getElementById('ajax_content').innerHTML = '';

  after_closeajax();

}

function after_closeajax(){};

function setCookie(key, value, days, path) {
  var date = new Date();
  date.setTime(date.getTime() - 365 * 24 * 60 * 60 * 1000);

  document.cookie = key + '=""; expires=' + date.toGMTString();

  value = encodeURIComponent(value);
  value+='; domain='+location.host;
  value+='; path='+path;
  
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
  value+='; expires=' + date.toGMTString();
  
  document.cookie = key + '=' + value;
  
}

function readCookie(cookName){
  cookieArr = document.cookie.split(";");
  for (var i=0;i<cookieArr.length;i++){
    cook = cookieArr[i].split("=");
    if(jQuery.trim(cook[0]) == cookName){
      return jQuery.trim(cook[1]);
      break;
    }
  }

}

function getQueryString() {
  var result = {}, queryString = location.search.substring(1),
      re = /([^&=]+)=([^&]*)/g, m;

  while (m = re.exec(queryString)) {
    result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  }

  return result;
}


// RS
function as4u_rs(){
  if(document.getElementById('redakcni_system')){
    document.getElementById('redakcni_system').style.display = 'none';
  }
}

if(typeof jQuery === 'function'){
  jQuery(document).ready(function() {
    as4u_rs();
  });
};
