function getPage(stranka, kam){
  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);
  }

  div=document.getElementById(kam).style;
  div.display=(div.display == 'none')?'':'none';
  
  httpRequest.send(null);
}

function getPageX(stranka, kam){
  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);
  }

  httpRequest.send(null);
}

function processRequest(httpRequest, kam) {
  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{
      document.getElementById(kam).innerHTML ='Chyba!';
    }
  }else{
    if (typeof kam =='string' && kam !=''){
      document.getElementById(kam).innerHTML =document.getElementById(kam).innerHTML ;
    }
  }
}

function insertText(elname, what, formname) {
   if (formname == undefined) formname = 'inputform';
   if (document.forms[formname].elements[elname].createTextRange) {
       document.forms[formname].elements[elname].focus();
       document.selection.createRange().duplicate().text = what;
   } else if ((typeof document.forms[formname].elements[elname].selectionStart) != 'undefined') {
       var tarea = document.forms[formname].elements[elname];
       var selEnd = tarea.selectionEnd;
       var txtLen = tarea.value.length;
       var txtbefore = tarea.value.substring(0,selEnd);
       var txtafter =  tarea.value.substring(selEnd, txtLen);
       var oldScrollTop = tarea.scrollTop;
       tarea.value = txtbefore + what + txtafter;
       tarea.selectionStart = txtbefore.length + what.length;
       tarea.selectionEnd = txtbefore.length + what.length;
       tarea.scrollTop = oldScrollTop;
       tarea.focus();
   } else {
       document.forms[formname].elements[elname].value += what;
       document.forms[formname].elements[elname].focus();
   }
}

function addText(elname, strFore, strAft, formname) {
   if (formname == undefined) formname = 'inputform';
   if (elname == undefined) elname = 'message';
   element = document.forms[formname].elements[elname];
   element.focus();
   if (document.selection) {
	   var oRange = document.selection.createRange();
	   var numLen = oRange.text.length;
	   oRange.text = strFore + oRange.text + strAft;
	   return false;
   } else if (element.setSelectionRange) {
      var selStart = element.selectionStart, selEnd = element.selectionEnd;
			var oldScrollTop = element.scrollTop;
      element.value = element.value.substring(0, selStart) + strFore + element.value.substring(selStart, selEnd) + strAft + element.value.substring(selEnd);
      element.setSelectionRange(selStart + strFore.length, selEnd + strFore.length);
			element.scrollTop = oldScrollTop;      
      element.focus();
   } else {
			var oldScrollTop = element.scrollTop;
      element.value += strFore + strAft;
			element.scrollTop = oldScrollTop;      
      element.focus();
	}
}

var clock_stamp;
	
function clock_output(){
    var now = new Date(clock_stamp * 1000);
    var h = now.getHours();
    var m = now.getMinutes();
    var s = now.getSeconds();
    if(h < 10) h = "0" + h;
    if(m < 10) m = "0" + m;
    if(s < 10) s = "0" + s;
    var ___hodiny = document.getElementById('clock');
     ___hodiny.innerHTML = h + ":" + m + ":" + s;
}


function clock_update(){
    clock_stamp += 1;
    var _hodiny = document.getElementById('clock');
    if (!_hodiny) return;
    clock_output();
}


function clock_boot(stamp){
    clock_stamp = stamp;
    clock_output();
    setInterval("clock_update();", 1000);
}  

function auto_refresh(sekund,adresa)
{
    obnovit_sekund = sekund;
    presmeruj = adresa;
    setInterval("autoref();", 1000);
    
}  

sib = null;

function UpdateInfoBox(e)
{
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (sib != null) {
		sib.style.left = (x + 20) + "px";
		sib.style.top 	= (y + 20) + "px";
	}
}

function ShowInfoBox(id)
{
	document.onmousemove = UpdateInfoBox;
	sib = document.getElementById(id);
	sib.style.display = "block";
}

function HideInfoBox()
{
	sib.style.display = "none";
	document.onmousemove = "none";
}

function ShowServerImage(serverid,bannerid,servername)
{
  self.document['ob'].src='http://'+servername+'/status/'+bannerid+'/'+serverid+'.png';
  
  var menuobj = document.getElementById? document.getElementById("obdata") : document.all? document.all.describe : document.layers? document.dep1.document.dep2 : ""

  thecontent = '<strong>HMTL</strong>:<br><textarea class="genbox" style="width:468px;height:40px;">&lt;a target=&quot;_blank&quot; href=&quot;http://'+servername+'/&quot;&gt;&lt;img src=&quot;http://'+servername+'/status/'+bannerid+'/'+serverid+'.png&quot; alt=&quot;'+servername+'&quot; title=&quot;'+servername+'&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;</textarea><br><br><strong>BBcode</strong>:<br><textarea class="genbox" style="width:468px;height:40px;">[url=http://'+servername+'/][img]http://'+servername+'/status/'+bannerid+'/'+serverid+'.png[/img][/url]</textarea>';
  menuobj.innerHTML=thecontent
}

function zobraz(id)
{
  el=document.getElementById(id).style;
  el.display=(el.display == 'none')?'':'none';
}

function ShowElement(element) {
  document.getElementById(element).style.visibility = "visible";
}

function HideElement(element) {
  document.getElementById(element).style.visibility = "hidden";
}


var ExDataElement = "none";

function ExElement(element)
{
  if(ExDataElement!="none")
  {
    document.getElementById(ExDataElement).style.visibility = "hidden";
  }
  if(ExDataElement == element)
  {
    document.getElementById(element).style.visibility = "hidden";
    ExDataElement = "none";
  } else {
    document.getElementById(element).style.visibility = "visible";
    ExDataElement = element;
  }
}
