/* Cookies - uz ani nevim kde jsem to sebral */

function prectiCookie(nazev)
{
  cookobsah=document.cookie; upravene=cookobsah.split(';');
  velikost=upravene.length; kusy=""; vrat="";

  for (x=0;(x<velikost && vrat=="");x++) 
  {
    kusy=upravene[x].split('=');
    if (kusy[0].substring(0,1)==' ') 
      kusy[0]=kusy[0].substring(1,kusy[0].length);
    if (kusy[0]==nazev) vrat=kusy[1];
  }
  if (vrat) return unescape(vrat);
    else return false;
}

function zapisCookie(nazev,hodnota,vyprsi)
{
  datum=new Date();

  if(vyprsi) {
    datum.setTime(datum.getTime()+vyprsi);
    document.cookie=nazev+"="+escape(hodnota)
     +"; expires="+datum.toGMTString(); }

    else document.cookie=nazev+"="+escape(hodnota);
}
function vyprsi(dt)
{
  obdobi=0; //den
  if (dt==0) return 0;
    else if (obdobi==0) return 86400000*dt;
    else if (obdobi==1) return 2678400000*dt;
    else if (obdobi==2) return 31536000000*dt;
}

/* * * * * * * * * * * * * * * * * * * *
XHTML Parser
Stará se o zpracování XML souboru. Není potřeba měnit
Zdroj : http://www.grallandco.com/blog/archives/ajax/
* * * * * * * * * * * * * * * * * * * * */
jeToIe=(navigator.appName=="Microsoft Internet Explorer") & (!window.opera);
var ajaxmode=false;
function loadXmlData(url)
	{
    // create the object, careful to the MSFT/Other method
	if (window.XMLHttpRequest)
		{
		xmlHttpRequest = new XMLHttpRequest();
		}
	else if (window.ActiveXObject)
		{
		xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}

    // executing the request, passing the targetted object
	xmlHttpRequest.open("GET", url, true);
	xmlHttpRequest.onreadystatechange = function () {processRequestChange()};
	xmlHttpRequest.send(null);
	}

  /**
   * Handle the events of the XMLHttpRequest Object
   */
function processRequestChange()
	{
	if (xmlHttpRequest.readyState == 4)
		{
     		if(xmlHttpRequest.status == 200)
			{
			document.getElementById("statusZone").style.display="block";
			parseData();
			document.getElementById("statusZone").style.display="none";
			}
		else
			{
			alert("Nelze načíst zdroj dat.\n"+ xmlHttpRequest.status +":"+ xmlHttpRequest.statusText);
			}
		// end of the request, change the status zone
  		}
	else
		{
		// Indicates that the client is *busy*
		document.getElementById("statusZone").style.display="block";
		}
	}

function loadData(slink)
	{
	document.getElementById("statusZone").style.display="block";
	adresa=slink.href;
	adresa=adresa.substring(adresa.indexOf("?")+1);
	if (adresa.indexOf("#")>=0)
		{
		adresa=adresa.substring(0,adresa.indexOf("#"));
		}
	loadXmlData("xml.php?"+adresa);
	return true;
	}

function docParser()
	{
	if (ajaxmode==1)
		{
		odkaz=document.getElementById("hlavni").getElementsByTagName("a");
		for (var i=0; i<odkaz.length; i++)
			{
			if (((odkaz[i].href.indexOf("x=")>=0) | (odkaz[i].href.indexOf("runscript")>=0) | (odkaz[i].href.indexOf("links")>=0) | (odkaz[i].href.indexOf("content")>=0) | (odkaz[i].href.indexOf("search")>=0)) & (odkaz[i].className!="out"))
				{
				odkaz[i].onclick=new Function("return !loadData(this);");
				}
			}
		}
	}
function parseData()
	{
	titulek="";
	var data_obsah = xmlHttpRequest.responseXML.getElementsByTagName("data");
	if (data_obsah[1].textContent) // jen pro mozillu a jeji kamose
		{
		titulek=data_obsah[0].textContent;
		document.getElementById("obsah").innerHTML=data_obsah[1].textContent;
		}
	else
		{
		if (data_obsah[0].innerHTML) titulek=data_obsah[0].innerHTML;
		document.getElementById("obsah").innerHTML=data_obsah[1].firstChild.nodeValue;
		}
	document.title=titulek+"JavaScript - příkazy/příklady";
	docParser();
	}

function init()
	{
	ajaxmode=prectiCookie("ajaxmode");


	if (ajaxmode==1)
		{
		ver="<a href=\"#\" onclick=\"zapisCookie('ajaxmode',0,vyprsi(0));document.location.reload();return false;\" title=\"Kliknutím přepenete na klasickou verzi\">AJAX</a>";
		}
	else
		{
		ver="<a href=\"#\" onclick=\"zapisCookie('ajaxmode',1,vyprsi(30));document.location.reload();return false;\" title=\"Kliknutím přepnete na verzi pro počítače s pomalým připojením\">HTML</a>";
		}		
	document.getElementById("paticka").innerHTML+=" Verze:"+ver;
	var objInfo=document.createElement('div');
	objInfo.id="statusZone";
	prvek="<img src=\"/images/load.gif\" alt=\"Načítám\" width=\"91\" height=\"20\" /> Načítám zdroj dat";
	objInfo.innerHTML=prvek;

	/* IE pristupuje k insertBefore nestandartne, tak mu to umoznime */
	if (jeToIe)
		{
		document.getElementById("hlavni").insertBefore(objInfo);
		}
	else
		{
		document.getElementById("hlavni").insertBefore(objInfo,document.getElementById("hlavni").childNodes[0]);
		}




	document.getElementById("statusZone").style.display="none";
	hleda=document.location.hash.substring(1);
	parametr="FCE";
	if (hleda.indexOf(parametr)==0)
		{
		hleda=hleda.substring(parametr.length+1);
		loadXmlData("xml.php?x="+hleda);
		}
/*	else
		{
		loadXmlData("xml.php");
		}*/
	docParser();
	h_init();
	}


window.onload=new Function("init();");
