/* pridavani do onload dokumentu */
function pridatOnload(func)
{
	var onload = window.onload;
	if(typeof window.onload != "function")
		window.onload = func
	else
	{
		window.onload = function() 
		{
			if(onload) { onload(); }
			func();
		}
	}
}

/* prepinani katalogu */
function rozbalitKatalog()
{
	if(document.getElementById("catalog_on").style.display == "none")
	{
		document.getElementById("catalog_on").style.display = "block";
		document.getElementById("catalog_off").style.display = "block";
	}
	else
	{
		document.getElementById("catalog_on").style.display = "block";
		document.getElementById("catalog_off").style.display = "block";
	}
}

/* vrati XHR */
function vratXHR()
{
	var xhr;
	try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
	catch (e)
	{
		try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
		catch (e2)
		{
			try { xhr = new XMLHttpRequest(); }
			catch (e3) { xhr = false; }
		}
	}

	return xhr;
}

/* nacitani obsahu aktualit pomoci XHR */
function nacistAktuality(url)
{
	var xhr = vratXHR();

	xhr.onreadystatechange  = function()
	{
		if(xhr.readyState  == 4)
		{
			var obj = document.getElementById("aktuality_xhr");
			if(xhr.status  == 200)
				obj.innerHTML = xhr.responseText; 
			else
				obj.innerHTML = "Chyba (" + xhr.status + ")";
		}
	};

	xhr.open("GET", url,  true);
	xhr.send(null);
}

/* nacitani obsahu slev pomoci XHR */
function nacistSlevy(url)
{
	var xhr = vratXHR();

	xhr.onreadystatechange  = function()
	{
		if(xhr.readyState  == 4)
		{
			var obj = document.getElementById("slevy_xhr");
			if(xhr.status  == 200)
				obj.innerHTML = xhr.responseText; 
			else
				obj.innerHTML = "Chyba (" + xhr.status + ")";
		}
	};

	xhr.open("GET", url,  true);
	xhr.send(null);
}

/* nacitani obsahu noveho zbozi pomoci XHR */
function nacistNoveZbozi(url)
{
	var xhr = vratXHR();

	xhr.onreadystatechange  = function()
	{
		if(xhr.readyState  == 4)
		{
			var obj = document.getElementById("novezbozi_xhr");
			if(xhr.status  == 200)
				obj.innerHTML = xhr.responseText; 
			else
				obj.innerHTML = "Chyba (" + xhr.status + ")";
		}
	};

	xhr.open("GET", url,  true);
	xhr.send(null);
}

/* main */
pridatOnload(function() {
	if(rozbalit_katalog_zbozi) 
	{
		document.getElementById("catalog_on").style.display = "block";
		document.getElementById("catalog_off").style.display = "none";
	}
	else
	{
		document.getElementById("catalog_on").style.display = "none";
		document.getElementById("catalog_off").style.display = "block";
	}
});
