function AddToFavorite ()
{
  if(document.all)
  {
    window.external.AddFavorite (location.href,document.title);
  }
  else if (window.sidebar)
  {
    window.sidebar.addPanel (document.title, location.href,'');
  }
  else
  {
     alert ('Bohužel, stránku musíte přidat do oblíbených ručně, např. stiskem stiskem <Ctrl-D>.');
  }
}

function displayNone (element) {
  element.style.display='none';
}
function displayBlock (element) {
  element.style.display='block';
}

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}


function datumInput(select, inputPole) {
  if (select.value == 1) inputPole.style.display='';
  else inputPole.style.display='none';
}

function writeBack () {
  document.write("<div class='align_right'><a href='#' title='Zpět na předchozí stránku' onclick='javascript:history.go(-1); return false;'>Zpět na předchozí stránku</a></div>");
}

function ajax(stranka, kam, waitingType)
{
    var httpRequest;
    
    if(typeof window.ActiveXObject != 'undefined')
    {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {  
        httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", stranka, true);
    httpRequest.onreadystatechange= function () 
    {
        processRequest(httpRequest, kam, waitingType);
    };
    httpRequest.send(null);
}

function ajaxPost(stranka, params, kam, waitingType)
{
    var httpRequest;
    
    if(typeof window.ActiveXObject != 'undefined')
    {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {  
        httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("POST", stranka, true);
    

    //Send the proper header information along with the request
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.setRequestHeader("Content-length", params.length);
httpRequest.setRequestHeader("Connection", "close");

    httpRequest.onreadystatechange= function () 
    {
        processRequest(httpRequest, kam, waitingType);
    };
    httpRequest.send(params);
}


function processRequest(httpRequest, kam, waitingType) 
{
    if (httpRequest.readyState == 4)
    {
        if (( httpRequest.status >= 200 && httpRequest.status < 300 ) || httpRequest.status == 304)
        {
            if (typeof kam == 'string') 
            {
                document.getElementById(kam).innerHTML = httpRequest.responseText;

           }
            if (typeof kam == 'function') 
            {
                kam(httpRequest.responseText);
            }
        }
        else
        {
            alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
        }
    }
    else 
    {
        if (typeof kam == 'string' && kam != '') 
        {
          if (waitingType == 1)
            document.getElementById(kam).innerHTML = '<div id="little_loading"><span>Prosím čekejte...<br /></span></div>';
          else if (waitingType == 2)
            document.getElementById(kam).innerHTML = '<div id="very_little_loading">&nbsp;</div>';
            
        }
    }
       
}

function showPodobor (id,typ,hash,vybraneObory) {

 if (document.getElementById("div" + id).innerHTML == '') {
  ajax('../publicphp/showNextUL.php?typ=' + typ + '&sekce=' + id + '&hash=' + hash + vybraneObory, 'div' + id, 1);
  document.getElementById("div" + id).style.display = 'block';
  document.getElementById("hyperlink" + id).innerHTML = '(Skrýt)';
 }
 else if (document.getElementById("hyperlink" + id).innerHTML == '(Skrýt)') {
  document.getElementById("div" + id).style.display = 'none'; 
  document.getElementById("hyperlink" + id).innerHTML = 'Upřesnit obor &gt;&gt;';
 }
 else if (document.getElementById("hyperlink" + id).innerHTML == 'Upřesnit obor &gt;&gt;') {
  document.getElementById("div" + id).style.display = 'block'; 
  document.getElementById("hyperlink" + id).innerHTML = '(Skrýt)';
 }

}
function showPodoborForce (id,typ,hash,vybraneObory) {

  ajax('../publicphp/showNextUL.php?typ=' + typ + '&sekce=' + id + '&hash=' + hash + vybraneObory, 'div' + id, 1);
  document.getElementById("div" + id).style.display = 'block';
  document.getElementById("hyperlink" + id).innerHTML = '(Skrýt)';

}
function showCounterForce (nadsekce,nadnadsekce,nadnadnadsekce,sekce) {
  if (nadsekce != 0) {
   document.getElementById("counter" + nadsekce).innerHTML = Number(document.getElementById("counter" + nadsekce).innerHTML) + 1;
   if (document.getElementById("counter" + nadsekce).innerHTML == '1') document.getElementById("counter" + nadsekce).style.display = 'inline';
  }
  if (nadnadsekce != 0) {
    document.getElementById("counter" + nadnadsekce).innerHTML = Number(document.getElementById("counter" + nadnadsekce).innerHTML) + 1;
    if (document.getElementById("counter" + nadnadsekce).innerHTML == '1') document.getElementById("counter" + nadnadsekce).style.display = 'inline';
  }
  if (nadnadnadsekce != 0) {
    document.getElementById("counter" + nadnadnadsekce).innerHTML = Number(document.getElementById("counter" + nadnadnadsekce).innerHTML) + 1;
    if (document.getElementById("counter" + nadnadnadsekce).innerHTML == '1') document.getElementById("counter" + nadnadnadsekce).style.display = 'inline';
  }
  document.getElementById('tmpcounter'+sekce).style.display = 'none';
}
var casovac;
function oznacObor (checkbox, spanlabel,nadsekce,nadnadsekce,nadnadnadsekce,pocet_podsekci) {
  if (checkbox.checked) {
    spanlabel.style.color = 'red';
    spanlabel.style.fontWeight = 'bold';
    
    if (pocet_podsekci > 0) {
      Tip('<strong class="blue" style="margin:0;">Opravdu chcete vybrat celý tento obor? <br />Obor se dále člení.</strong>', BGCOLOR, '#ffffff', BORDERCOLOR, '#ffffff', DELAY, 0, FADEIN, 300, FADEOUT, 300, PADDING, 0, WIDTH, 370, HEIGHT, 63, FIX, [checkbox, 20, -3], ABOVE, true, CLICKCLOSE, true, OPACITY, 100);
      clearTimeout(casovac);
      casovac = setTimeout("UnTip()", 5000);  
    } 
      if (nadsekce != 0) {
        document.getElementById("counter" + nadsekce).innerHTML = Number(document.getElementById("counter" + nadsekce).innerHTML) + 1;
        if (document.getElementById("counter" + nadsekce).innerHTML == '1') document.getElementById("counter" + nadsekce).style.display = 'inline';
      }
      if (nadnadsekce != 0) {
        document.getElementById("counter" + nadnadsekce).innerHTML = Number(document.getElementById("counter" + nadnadsekce).innerHTML) + 1;
        if (document.getElementById("counter" + nadnadsekce).innerHTML == '1') document.getElementById("counter" + nadnadsekce).style.display = 'inline';
      }
      if (nadnadnadsekce != 0) {
        document.getElementById("counter" + nadnadnadsekce).innerHTML = Number(document.getElementById("counter" + nadnadnadsekce).innerHTML) + 1;
        if (document.getElementById("counter" + nadnadnadsekce).innerHTML == '1') document.getElementById("counter" + nadnadnadsekce).style.display = 'inline';
      }
  } 
  else {
    spanlabel.style.color = 'black';
    spanlabel.style.fontWeight = 'normal';
      if (nadsekce != 0) {
        document.getElementById("counter" + nadsekce).innerHTML = Number(document.getElementById("counter" + nadsekce).innerHTML) - 1;
        if (document.getElementById("counter" + nadsekce).innerHTML == '0') document.getElementById("counter" + nadsekce).style.display = 'none';
      }
      if (nadnadsekce != 0) {
        document.getElementById("counter" + nadnadsekce).innerHTML = Number(document.getElementById("counter" + nadnadsekce).innerHTML) - 1;
        if (document.getElementById("counter" + nadnadsekce).innerHTML == '0') document.getElementById("counter" + nadnadsekce).style.display = 'none';
      }
      if (nadnadnadsekce != 0) {
        document.getElementById("counter" + nadnadnadsekce).innerHTML = Number(document.getElementById("counter" + nadnadnadsekce).innerHTML) - 1;
        if (document.getElementById("counter" + nadnadnadsekce).innerHTML == '0') document.getElementById("counter" + nadnadnadsekce).style.display = 'none';
      }
  }
}
function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}


function novyObor(email) {
  div = document.getElementById('novyObor');
  div.innerHTML = '<a href="#" title="Navrhnout nový obor" onclick="javascript: formNovyObor(\''+email+'\');return false;">Navrhnout nový obor</a>';
  div.style.width = '';
  div.style.height = '';
  div.style.border = '';
  div.style.backgroundColor = '';
}

//stejna jako ta nahore, kvuli IE
function novyObor2(email) {
  div = document.getElementById('novyObor');
  div.innerHTML = '<a href="#" title="Navrhnout nový obor" onclick="javascript: formNovyObor(\''+email+'\');return false;">Navrhnout nový obor</a>';
  div.style.width = '';
  div.style.height = '';
  div.style.border = '';
  div.style.backgroundColor = '';
}
function formNovyObor(email) {
  div = document.getElementById('novyObor');
  div.style.width = '250px';
  div.style.height = '150px';
  div.style.border = '1px solid #afafa8';
  div.style.backgroundColor = '#fafafa';
  div.innerHTML = '<div style="position:absolute;top:1px;right:2px;"><a href="#" title="Zavřít" onclick="javascript: novyObor2(\''+email+'\');return false;">X</div>';
  div.innerHTML += 'Navrhovaný obor:<br /><input style="width: 200px;height: 20px;" type="text" id="novyOborInput" name="novyObor" /><br />Email:<br /><input style="width: 200px;height: 20px;" type="text" id="novyOborEmail" name="novyOborEmail" value="'+email+'" /><br /><input type="image" src="../style/images/button_odeslat.gif" id="odeslat_button" name="submitit" alt="Odeslat" onclick="javascript: navrhniObor();return false;" />';
}
function navrhniObor() {
   div = document.getElementById('novyObor');
   ajax('../publicphp/navrhniObor.php?obor=' + Url.encode(document.getElementById('novyOborInput').value) + '&email=' + Url.encode(document.getElementById('novyOborEmail').value) + '&hash=' + randomString(),'novyObor',2);
}


function init_wait() {
  if (window.Event) {
    document.captureEvents(Event.MOUSEMOVE);
  }
  document.onmousemove = getXY;
}

function getPosition(e) {
     e = e || window.event;
     var cursor = {x:0, y:0};
     if (e.pageX || e.pageY) {
         cursor.x = e.pageX;
         cursor.y = e.pageY;
     }
     else {
         cursor.x = e.clientX +
             (document.documentElement.scrollLeft ||
             document.body.scrollLeft) -
             document.documentElement.clientLeft;
         cursor.y = e.clientY +
             (document.documentElement.scrollTop ||
             document.body.scrollTop) -
             document.documentElement.clientTop;
     }
     return cursor;
}


function getXY(e) {
  cursor = getPosition(e);
  x = cursor.x;
  y = cursor.y;
  divblock = document.getElementById('waitingDialog');
  divblock.style.left = Number(x-((Number(document.body.clientWidth)-1000)/2)+20)+'px';
  divblock.style.top = Number(y+20)+'px';
}

function showWaitingDialog() {
  divblock = document.getElementById('waitingDialog');
  divblock.style.display = 'block';
  divblock.style.position='absolute';
  divblock.style.width = '200px';
  divblock.style.height = '70px';
  divblock.innerHTML = '<strong>Prosím čekejte...</strong><br /><br />';
  divblock.style.padding = '20px';
}
var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}
function moveUpSearch() {
 if (document.getElementById('select_region2').style.display == '') {
  setTimeout("document.getElementById('search_type').style.top = '107px'",50);
  setTimeout("document.getElementById('search_type').style.top = '105px'",100);
  setTimeout("document.getElementById('search_type').style.top = '102px'",150);
  setTimeout("document.getElementById('search_type').style.top = '100px'",200);
  setTimeout("document.getElementById('search_type').style.top = '97px'",250);
  setTimeout("document.getElementById('search_type').style.top = '95px'",300);
  setTimeout("document.getElementById('search_type').style.top = '92px'",350);
  setTimeout("document.getElementById('search_type').style.top = '90px'",400);
  
  setTimeout("document.getElementById('select_region2').style.display = 'none'",300);
  
  setTimeout("document.getElementById('select_region').style.height = '18px'",50);
  setTimeout("document.getElementById('select_region').style.height = '16px'",100);
  setTimeout("document.getElementById('select_region').style.height = '14px'",150);
  setTimeout("document.getElementById('select_region').style.height = '11px'",200);
  setTimeout("document.getElementById('select_region').style.height = '8px'",250);
  setTimeout("document.getElementById('select_region').style.height = '6px'",300);
  setTimeout("document.getElementById('select_region').style.height = '3px'",350);
  setTimeout("document.getElementById('select_region').style.height = '0px'",400);
 }  
}
function moveDownSearch() {
 if (document.getElementById('select_region2').style.display == 'none') {
  setTimeout("document.getElementById('search_type').style.top = ''",450);
  setTimeout("document.getElementById('search_type').style.top = '110px'",400);
  setTimeout("document.getElementById('search_type').style.top = '107px'",350);
  setTimeout("document.getElementById('search_type').style.top = '105px'",300);
  setTimeout("document.getElementById('search_type').style.top = '102px'",250);
  setTimeout("document.getElementById('search_type').style.top = '100px'",200);
  setTimeout("document.getElementById('search_type').style.top = '97px'",150);
  setTimeout("document.getElementById('search_type').style.top = '95px'",100);
  setTimeout("document.getElementById('search_type').style.top = '92px'",50);
  
  setTimeout("document.getElementById('select_region2').style.display = ''",100);
  
  setTimeout("document.getElementById('select_region').style.height = ''",450);
  setTimeout("document.getElementById('select_region').style.height = '20px'",400);
  setTimeout("document.getElementById('select_region').style.height = '18px'",350);
  setTimeout("document.getElementById('select_region').style.height = '16px'",300);
  setTimeout("document.getElementById('select_region').style.height = '14px'",250);
  setTimeout("document.getElementById('select_region').style.height = '11px'",200);
  setTimeout("document.getElementById('select_region').style.height = '8px'",150);
  setTimeout("document.getElementById('select_region').style.height = '6px'",100);
  setTimeout("document.getElementById('select_region').style.height = '3px'",50);
 }
}


