


var POMOCNE_MENU = new function () {



	this.ID_POMOCNE_MENU = "inaPanelPomocneMenu";
	this.URL_KONTAKTY = "index.php?akce=Katalog-Pruzkumnik/KontaktniUdaje";



	this.vytvor = function ()
	{
		var panel = document.getElementById (this.ID_POMOCNE_MENU);
		if (! panel)
		{
		    return;
		}
		var sablona = this.ziskejSablonu (panel);
		if (! sablona)
		{
		    return;
		}
		this.vytvorTlacitka (
			panel, sablona[0], sablona[1], sablona[2]);

	}


	this.vytvorTlacitkoTiskni = function (panel, text)
	{
		var tisk = document.createElement ("a");
		tisk.setAttribute ('class', 'tisk');
		tisk.appendChild (
			document.createTextNode (text)
		);
		SABLONA_XHTML.nastavOvladacUdalosti (
			tisk,
			'click',
			function ()
			{
				window.print();
			}
		);
		panel.appendChild (tisk);
	}



	this.vytvorTlacitkoKOblibenym = function (panel, text)
	{
		if (window.sidebar || window.external)
		{
			var kOblibenym = document.createElement ("a");
		    kOblibenym.setAttribute ('class', 'oblibene');
			kOblibenym.appendChild (document.createTextNode (text));
			SABLONA_XHTML.nastavOvladacUdalosti (
				kOblibenym,
				'click',
				function ()
				{
					var text = document.title;
					var url = window.location.href;
					if (window.sidebar)
					{
						window.sidebar.addPanel (text, url, "");
					}
					else if (window.external)
					{
						window.external.AddFavorite (url, text);
					}
				}
			);
			panel.appendChild (kOblibenym);
		}
	}



	this.ziskejSablonu = function (panel)
	{
		var sablona = "";
		var deti = panel.childNodes;
		for (var i = 0; i < deti.length; i ++)
		{
		    if (deti[i].nodeType == 8) // comment node
		    {
			    sablona = deti[i].data;
			}
		}
		if (sablona == "")
		{
		    return false;
		}
		sablona = sablona.split ("|", 3);
		if (sablona.length < 3)
		{
		    return false;
		}
		return sablona;
	}



	this.vytvorTlacitka = function (
		panel, textTelefon, textTiskni, textKOblibenym)
	{
		try {
			var httpRequest = new XMLHttpRequest ();
		}
		catch (e)
		{
			return;
		}
		httpRequest.open ("GET", this.URL_KONTAKTY, true);
		httpRequest.onreadystatechange =
		function ()
		{
			if (
				httpRequest.readyState == 4 &&
				httpRequest.status == 200
			)
			{
				try {
					eval ("var data = " + httpRequest.responseText + ";");
				}
				catch (e)
				{
					return;
				}
				if (data.telefon != "")
				{
				    textTelefon += data.telefon;
				}
				else
				{
				    textTelefon = "";
				}
				POMOCNE_MENU.dokonciVytvoreniTlacitek (
					panel, data.email, textTelefon, textTiskni, textKOblibenym
				);
			}
		};
		httpRequest.send (null);
	}



	this.dokonciVytvoreniTlacitek = function (
		panel, textEmail, textTelefon, textTiskni, textKOblibenym)
	{
		if (textEmail != "")
		{
			var email = document.createElement ("a");
			email.appendChild (
				document.createTextNode (textEmail)
			);
			email.setAttribute ('href', 'mailto:' + textEmail);
		    email.setAttribute ('class', 'email');
			panel.appendChild (email);
		}
		if (textTelefon != "")
		{
			var telefon = document.createElement ("span");
		    telefon.setAttribute ('class', 'telefon');
			telefon.appendChild (
				document.createTextNode (textTelefon)
			);
			panel.appendChild (telefon);
		}
		if (textTiskni != "")
		{
			this.vytvorTlacitkoTiskni (panel, textTiskni);
		}
		if (textKOblibenym != "")
		{
			this.vytvorTlacitkoKOblibenym (panel, textKOblibenym);
		}
	}


}



var SABLONA_XHTML = new function () {



	this.inicializator = "";



	this.pridejInicializator = function (text)
	{
		this.inicializator += text + ";";
	};



	this.__provedInicializaci = function ()
	{
	    POMOCNE_MENU.vytvor ();
		eval (this.inicializator);
		this.inicializator = "";
	}



	this.ukazPrilohu = function (src, width, height)
	{
		if (
			window.KATALOG_PRUZKUMNIK_FOTOGALERIE &&
			navigator.appVersion.indexOf("MSIE 6") == -1 &&
			navigator.userAgent.indexOf("Opera") == -1
		)
		{
			KATALOG_PRUZKUMNIK_FOTOGALERIE.inicializuj ();
			KATALOG_PRUZKUMNIK_FOTOGALERIE.otevriObrazek (src);
			return false;
		}
		width += 35;
		height += 35;
		var okno = open("", "_blank", "width=" + width + ",height=" + height + "");
		okno.document.open();
		okno.document.writeln('<html>');
		okno.document.writeln('<head>');
		okno.document.writeln('<title>Příloha</title>');
		okno.document.writeln('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
		okno.document.writeln('<meta http-equiv="imagetoolbar" content="no" />');
		okno.document.writeln('</head>');
		okno.document.writeln('<body style="margin: 0px; padding: 0px; cursor: pointer;" onclick="window.close();">');
		okno.document.writeln('<iframe src="' + src + '" style="width: ' + width + 'px; height: ' + height + 'px;"></iframe>');
		okno.document.writeln('</body>');
		okno.document.writeln('</html>');
		okno.document.close();
		return false;
	}


	/*

	// Pouziti funkce nastavOvladacUdalosti:

	function ovladacKliknuto () {window.alert("Kliknuto!");}
	SABLONA_XHTML.nastavOvladacUdalosti(window.document, 'click', ovladacKliknuto);
	
	function ovladacNahrano () {window.alert("Nahrano!");}
	SABLONA_XHTML.nastavOvladacUdalosti(window, 'load', ovladacNahrano);

	*/

	this.nastavOvladacUdalosti = function (element, typUdalosti, funkce)
	{
		if (element.addEventListener)
		{
			element.addEventListener(typUdalosti, funkce, false);
		}
		else if (element.attachEvent)
		{
			element.attachEvent("on" + typUdalosti, funkce);
		}
		else
		{
			eval ("element.on" + typUdalosti + " = funkce;")
		}
	}


}


//SABLONA_XHTML.provedInicializaci ();

var jizInicializovano = 0;

if (document.addEventListener)
{
	document.addEventListener(
		"DOMContentLoaded",
		function () {jizInicializovano = 1; SABLONA_XHTML.__provedInicializaci ();},
		false);
}
else
{
	if (document.all && ! window.opera)
	{
		document.write ('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
		var contentloadtag = document.getElementById ("contentloadtag");
		contentloadtag.onreadystatechange = function ()
		{
			if (this.readyState == "complete")
			{
				jizInicializovano = 1;
				SABLONA_XHTML.__provedInicializaci ();
			}
		}
	}
}

window.onload = function ()
{
	setTimeout (
		"if (! jizInicializovano) {SABLONA_XHTML.__provedInicializaci ();}", 0);
}


