function poslizpravu(add1,add2){
ajax('poslizpravucheck.php?add1=' +add1+ "&add2="+add2, 'poslizpravu2');
}
function rozroluj(id){
if(document.getElementById(id).style.visibility == "visible"){
document.getElementById(id).style.visibility = "hidden";
}
if(document.getElementById(id).style.visibility == "hidden"){
document.getElementById(id).style.visibility = "visible";
document.getElementById(id).style.fontSize = "20px";

}
}
function poslizpravu2(idkonverzace){
zpravy(1,'part=2&id='+idkonverzace);
}
function zkontrolujzpravy(pocet){
if(pocet == 0){
newImage = "url(obr/zprava0.png)";
}
if(pocet == 1){
newImage = "url(obr/zprava1.png)";
}
if(pocet > 1){
newImage = "url(obr/zprava2.png)";
}
if(document.getElementById('divzpravy').style.backgroundImage != newImage){
document.getElementById('divzpravy').style.backgroundImage = newImage;
}
}
function napoveda(par,url){
if(par == 1){
document.getElementById("helpdiv").className = "helpram";
document.getElementById("helpdiv").style.background = "white";
document.getElementById("helpdiv").onclick = "";
document.getElementById("helpdiv").style.width = "250px";
document.getElementById("helpdiv").style.height = "330px";
var iframe = 'Nápověda: <a style="cursor: pointer" onclick="napoveda(2)">Skrýt</a><br><iframe src="helpshow.php?'+url+'" width="250" height="300"></iframe>';
document.getElementById("helpdiv").innerHTML = iframe;
}else{
if(par == 2){
document.getElementById("helpdiv").style.visibility = "hidden";
}
}
}

function zpravy(par,url){
if(par == 1){
document.getElementById("clona").style.visibility = "visible";
document.getElementById("divzpravy").style.visibility = "hidden";
document.getElementById("divzpravy2").style.visibility = "visible";
document.getElementById("divzpravy2").className = "helpram";

var iframe = '<p align=\"right\"><a style="cursor: pointer" onclick="zpravy(2)"><b>X</b></a></p><iframe name="zpravyhlavni" src="zpravy.php?'+url+'" width="699" height="470"></iframe>';
document.getElementById("divzpravy2").innerHTML = iframe;
}else{
if(par == 2){
document.getElementById("clona").style.visibility = "hidden";
document.getElementById("divzpravy2").style.visibility = "hidden";
document.getElementById("divzpravy2").innerHTML = "";
document.getElementById("divzpravy").style.visibility = "visible";
}
}
}


function mt_rand( min, max ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Onno Marsman
    // *     example 1: mt_rand(1, 1);
    // *     returns 1: 1
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: mt_rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function substr_count(string,substring,start,length)
{
 var c = 0;
 if(start) { string += string.substr(start); }
 if(length) { string = string.substr(0,length); }
 for (var i=0;i<string.length;i++)
 {
  if(substring == string.substr(i,substring.length))
  c++;
 }
 return c;
}

function obnovuzivatele(url,iddivu) { //funkce pro samoaktualizování seznamu uživatelů
  if (url!=0) {
        var mistoZobrazeni=document.getElementById(iddivu);
      mistoZobrazeni.innerHTML = "<img src=\"../img/loading.gif\">";
  url = url + mt_rand(1,100);
    if (window.XMLHttpRequest) {
      httpRequest3=new XMLHttpRequest();
    }else if (window.ActiveXObject) {
      try {
        httpRequest3=new ActiveXObject('Microsoft.XMLHTTP');
      }
      catch(e) {
        httpRequest3=new ActiveXObject('Msxml2.XMLHTTP');
      }
    }else{ //pokud prohlížeč nepodporuje AJAX
alert('<strong>Omlouváme se, Váš prohlížeč bohužel nepodporuje funkce potřebné ke spuštění chatu.</strong>');
    }
    httpRequest3.open("GET", url, true);
    httpRequest3.onreadystatechange=function() {processRequest2(iddivu);};
    httpRequest3.send(null);
  }else{
    document.getElementById(iddivu).innerHTML = "<strong>Omlouváme se, ale pro funkčnost chatu musíte mít nainstalovaný JavaScript.</strong>";
  }
}

function processRequest2(iddivu) { //viz. výše
  if (httpRequest3.readyState==4) {

    if (httpRequest3.status==200) {
var mistoZobrazeni=document.getElementById(iddivu);
      mistoZobrazeni.innerHTML = httpRequest3.responseText;
    }else{
      alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}

function ajax(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') 
            {
            if (kam != 'zkontrolujzpravy'){
            if (kam != 'poslizpravu2'){
            txt = httpRequest.responseText;

          //  for(i = -1; i <= substr_count(txt,'<a href'); i++){
            txt = txt.replace(/<a href="([^"]+)">/ig, '<a onclick="ajax(\'$1\',\''+kam+'\');" style="cursor: pointer" class="odkaz">');
        //}
              document.getElementById(kam).innerHTML = txt;
              }else{
               poslizpravu2(httpRequest.responseText);
              }
              }else{
              zkontrolujzpravy(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 != '') 
        {
            //document.getElementById(kam).innerHTML = 'čekejte...';
        }
    }
       
}  
function posunout(kam){
window.location.href="#"+kam;
}
function request(passData,url,div){
document.getElementById(div).innerHTML = "<img src=\"obr/loader2.gif\">";
var AJAX = null;
if (window.XMLHttpRequest) {
   AJAX=new XMLHttpRequest();
} else {
   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
}
if (AJAX==null) {
   alert("Your browser doesn't support AJAX.");                                         
   return false
} else {
   AJAX.open("POST",url,true);
   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   AJAX.onreadystatechange = function() {                      
      if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
      if(AJAX.status == 200){
document.getElementById(div).innerHTML = AJAX.responseText;
}else{
document.getElementById(div).innerHTML = "Chyba";
}

      }                               
   }                                  
   AJAX.send(passData);
}
}


function over(passData,url){
var AJAX = null;
if (window.XMLHttpRequest) {
   AJAX=new XMLHttpRequest();
} else {
   AJAX=new ActiveXObject("Microsoft.XMLHTTP");
}
if (AJAX==null) {
   alert("Your browser doesn't support AJAX.");                                         
   return false
} else {
   AJAX.open("POST",url,true);
   AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   AJAX.onreadystatechange = function() {                      
if (AJAX.readyState==4 || AJAX.readyState=="complete") { 
if(AJAX.status == 200){
ajax(AJAX.responseText,'chat');
}else{
document.getElementById("chat").innerHTML = "Chyba!!<br>\"" + document.getElementById("chat").innerHTML + "\"";
}

      }                   
   }                                  
   AJAX.send(passData);
}
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
var browser = navigator.appName;
var curr_width = 135;
var asirka = screen.availWidth;
var soupnouto = asirka - curr_width;
var maxsoup = soupnouto;

function spust(kam){
soupani = setInterval('soupni("'+kam+'")',1);
}
function soupni(kam)
{
if(kam == '1'){
soupnouto = soupnouto - 2;
document.getElementById("adright").style.left = soupnouto+"px";
if(soupnouto == 0 || soupnouto == 1){
clearInterval(soupani); 
setTimeout('spust(2);',(mt_rand(5,10)*1000));
}
}else{
soupnouto = soupnouto + 2;
document.getElementById("adright").style.left = soupnouto+"px";
if(soupnouto == maxsoup || (soupnouto+1) == maxsoup){
clearInterval(soupani); 
}
}


}

