function Psaci_Stroj (objekt, rychlost, status, PocetZnaku, ce)
{
	if (!status)
	{
		Text = document.getElementById (objekt).innerHTML;
		PocetZnaku = Text.length;
		ce = 0;
		status = true;
	}

  if (ce < PocetZnaku)
	{
		ce ++;
		document.getElementById (objekt).innerHTML = Text.substring (0, ce);
  	setTimeout ("Psaci_Stroj ('"+objekt+"', "+rychlost+", "+status+", "+PocetZnaku+", "+ce+")", rychlost);
  }
}

function NactiCookie (nazev)
{ 
	nazev += "=";
	DelkaCookieHledane = nazev.length;
	DelkaCookieVsech = document.cookie.length;
	zacatek = 0;
	while (zacatek < DelkaCookieVsech)
	{
		var konec = zacatek + DelkaCookieHledane;
		if (document.cookie.substring (zacatek, konec) == nazev)
		{
			PoziceZnaku = document.cookie.indexOf (";", konec);
			if (PoziceZnaku == -1)
			{ 
				PoziceZnaku = document.cookie.length;
			}

			return unescape (document.cookie.substring (konec, PoziceZnaku));
		}
		zacatek = document.cookie.indexOf (" ", zacatek) + 1;
		if (zacatek == 0) {break;}
	}
	
	return null;
}

function SubStr_Count (kde, co)
{
	if (!co) {return alert ("CHYBA:\r\n\r\nParametr [\"co\"] je prázdný\r\n\r\n\"Preg_Count (kde, co)\"")}
	
	var pocet = 0;
	var pozice = kde.indexOf (co, 0);
	while (pozice != -1)
	{
		pocet ++
		var pozice = kde.indexOf (co, pozice + 1);
	}
	return pocet;
}

function Preg_Count (kde, co)
{
	if (!co) {return alert ("CHYBA:\r\n\r\nParametr [\"co\"] je prázdný\r\n\r\n\"Preg_Count (kde, co)\"")}
	
	var pole = kde.match (co);
	if (pole)	return pole.length;
	return 0;
}

function Preg_Replace (co, cim, kde)
{
	if (!co) {return kde;}
	
	return kde.split (co).join (cim);
}

var ShowSingleOpened = new Array ();

function Display_Single (skupina, prvek)
{	
	if (prvek == ShowSingleOpened[skupina])
	{
		document.getElementById (prvek).style.display = "none";
		document.getElementById (prvek+"-obr-left").src = "/images/ikony/closed.gif";
		document.getElementById (prvek+"-obr-right").src = "/images/ikony/closed.gif";
		ShowSingleOpened[skupina] = 0;
		return true;
	}
	if ((ShowSingleOpened[skupina] == 0 || !ShowSingleOpened[skupina]))
	{
		document.getElementById (prvek).style.display = "block";
		document.getElementById (prvek+"-obr-left").src = "/images/ikony/opened.gif";
		document.getElementById (prvek+"-obr-right").src = "/images/ikony/opened.gif";
		ShowSingleOpened[skupina] = prvek;
		return true;
	}
	document.getElementById (ShowSingleOpened[skupina]).style.display = "none";
	document.getElementById (ShowSingleOpened[skupina]+"-obr-left").src = "/images/ikony/closed.gif";
	document.getElementById (ShowSingleOpened[skupina]+"-obr-right").src = "/images/ikony/closed.gif";
	document.getElementById (prvek).style.display = "block";
	document.getElementById (prvek+"-obr-left").src = "/images/ikony/opened.gif";
	document.getElementById (prvek+"-obr-right").src = "/images/ikony/opened.gif";
	ShowSingleOpened[skupina] = prvek;
	
	return true;
}

var ShowMultiOpened = new Array ();

function Display_Multi (skupina)
{
	if (ShowMultiOpened[skupina] == 1)
	{
		document.getElementById(skupina).style.display = "none";
		ShowMultiOpened[skupina] = 0;
	}
	else
	{
		document.getElementById(skupina).style.display = "";
		ShowMultiOpened[skupina] = 1;
	}
}

function Odkaz_Email (login, server, domena, atributy, jmeno, title)
{
	if (!title)	{title = "Poslat e-mail";}
	if (jmeno)
	{
  	odkaz = "<a href='mailto: " + login + "@" + server + "&#046" + domena + "'" + atributy + " title='" + title + "'>" + jmeno + "</a>";
	}
	else
	{
		odkaz = "<a href='mailto: " + login + "@" + server + "&#046" + domena + "'" + atributy + " title='" + title + "'>" + login + "@" + server + "&#046" + domena + "</a>";
	}
	document.write (odkaz);
}

function Maximalizace_Okna ()
{
 	var b = navigator.appName;
 	var v = parseInt (navigator.appVersion);
 	if ((b == "Microsoft Internet Explorer" & v >= 4) || (b == "Netscape" && v >= 4))
  {
  	top.moveTo (0, 0);
		if ((screen.Width) && (screen.Height))	{top.resizeTo (screen.Width, screen.Height);}
		else																		{top.resizeTo (screen.availWidth, screen.availHeight);}
  }
	window.focus ();
}

function Datum_A_Hodiny ()
{
	today		= new Date ();
	den     = today.getDate ();
	mesic   = today.getMonth () + 1;
	rok     = today.getFullYear ();
	hodina	= today.getHours ();
	minuta	= today.getMinutes ();
	sekunda	= today.getSeconds ();
	if (mesic < 10) {mesic = "0" + mesic;}
	if (den < 10) {den = "0" + den;}
	DatumVypis = rok + "-" + mesic + "-" + den;
	if (minuta < 10) {minuta = "0" + minuta;}
	if (sekunda < 10) {sekunda = "0" + sekunda;}
	CasVypis = hodina + ":" + minuta + ":" + sekunda;
	document.getElementById ("MainDatum").innerHTML = DatumVypis;
	document.getElementById ("MainHodiny").innerHTML = CasVypis;
	setTimeout ("Datum_A_Hodiny ()", 1000);
}

function Otevri_Form (close, open, focus)
{
	if (document.getElementById (close)) document.getElementById (close).style.display = "none";
	document.getElementById (open).style.display = "";
	if (focus)
	{
		document.getElementById (focus).focus ();
	}
	
	return true;
}

function Otevri_Fotku (stranka, fotka, titulek)
{
	if (document.all)
	{
		sirka = screen.availWidth / 2 - (100 + 10) / 2;
		vyska = screen.availHeight / 2 - (100 + 31) / 2;
	}
	else
	{
		sirka = screen.availWidth / 2 - (100 + 6) / 2;
		vyska = screen.availHeight / 2 - (100 + 50) / 2;
	}

  parametr = "status='no', resizable='yes', menubar='no', directories='no', scrollbars='no', toolbar='no', height=100, width=100, left="+ sirka +", top="+ vyska;
  if (stranka.search ("[\?]") == -1)	{stranka += "?";}
  else																{stranka += "&";};
	
	stranka += "fotka=" + fotka + "&titulek=" + titulek;
  fotoalbum = window.open (stranka, "Fotoalbum", parametr);
  if (typeof (fotoalbum) == "object")
  {
  	fotoalbum.focus ();
  	return true;
  }
  return false;
}

function Potvrzeni_Odkazu (hlaska, odkaz, prikaz)
{
	if (confirm ("Opravdu si přejete vykonat příkaz:\r\n\r\n" + hlaska))
	{
		if (typeof (odkaz) != "undefined" && typeof (odkaz.href) != "undefined")
		{
			odkaz.href += prikaz;
		}
		else if (typeof (odkaz) != "undefined" && typeof (odkaz.form) != "undefined")
		{
			odkaz.form.action += prikaz;
		}
		return true;
	}

	return false;
}

function Pridej_Parametr (objekt, parametr)
{
	if (typeof (objekt.href) != "undefined")
	{
		objekt.href += parametr;
	}
	else if (typeof (objekt.form) != "undefined")
	{
		objekt.form.action += parametr;
	}
	
	return true;
}

function Smaz_Objekt (objekt, text)
{
	if (objekt.value == text)
	{
  	objekt.value = "";
	}
}

function Upload_File_Validace ()
{
  var PoleOdkazu = document.getElementsByTagName ("input");
  for (var ce in PoleOdkazu)
  {
  	var reg = /^UploadFile\[[0-9]+\]$/;
  	if (typeof (PoleOdkazu[ce]) == "object" && reg.test (PoleOdkazu[ce].name) && PoleOdkazu[ce].value)
  	{
			return true;
		}
	}
	alert ("!!! Pozor, nevybrali jste žádný soubor k uploadu !!!");
	return false;
}

function Upload_File_Add (objekt, sirka, typ)
{
	var MainAll = document.getElementById ("UploadFileAll");
	
	var input = document.createElement ("input"); 
	input.setAttribute ("type", "file");
	if (typ == "fotky") {input.setAttribute ("accept", "image/*");}
	input.setAttribute ("name", "UploadFile["+objekt+"]");
	input.setAttribute ("id", "UploadFile["+objekt+"]");
	input.setAttribute ("size", sirka);
	input.className = "file";
	
	var span = document.createElement	("span");
	span.setAttribute ("id", "UploadFileSpan["+objekt+"]");
	
	var a = document.createElement ("a");
	a.setAttribute ("href", "");
	a.setAttribute ("onClick", "return !Upload_File_Remove ("+objekt+")");
	a.setAttribute ("title", "Smazat kolonku");
	a.appendChild (document.createTextNode (" "));
	
	var img = document.createElement ("img");
	img.setAttribute ("src", "/images/ikony/delete.png");
	img.setAttribute ("alt", "delete");
	img.className = "ikona";
	
	var br = document.createElement ("br");
	
	a.appendChild (img);
	span.appendChild (input);
	span.appendChild (a);
	span.appendChild (br);
	MainAll.appendChild (span);

	document.getElementById ("UploadFileNew").href = "";
	document.getElementById ("UploadFileNew").onClick = "return !Upload_File_Add ("+(objekt+1)+","+sirka+", '"+typ+"');";
	
	return true;
}

function Upload_File_Remove (objekt)
{
	var MainAll = document.getElementById ("UploadFileAll");  
	var span = document.getElementById ("UploadFileSpan["+objekt+"]");  
	MainAll.removeChild (span);
	
	return true;
}

function Anketa_Nacitani_Simple (id, sirka, PomSirka)
{
	if (typeof (PomSirka) == "undefined")	{var PomSirka = 0;}
	else																	{PomSirka ++;}
	document.getElementById (id).style.width = PomSirka+"px";
	barva = Math.round (255 / sirka * PomSirka);
	if (barva < 0)				{barva = 0;}
	else if (barva > 255)	{barva = 255;}
	red = 0 + barva;
	green = 255 - barva;
	blue = 0;
	document.getElementById (id).style.background = "Rgb("+red+","+green+", "+blue+")";
	if (PomSirka <= sirka)
	{
		setTimeout ("Anketa_Nacitani_Simple ('"+id+"', "+sirka+", "+PomSirka+")", 50);
	}
}

function Anketa_Nacitani ()
{
	// cyklus vracející indexy všech položek v poli
	for (var ce in AnketaNacitani)
	{
		Anketa_Nacitani_Simple (ce, AnketaNacitani[ce]);
	}
}

function Odkaz_Barevny ()
{
	var id = new Array ();
	var rgb = new Array ();
	
	function Start (objekt)
	{
		objekt.style.color = "Rgb(255, "+rgb[objekt]+", 0)";
		rgb[objekt] += 15;
		if (rgb[objekt] <= 255)
		{
			id[objekt] = setTimeout (function () {Start (objekt);}, 45);
		}
	}
		
	function Stop (objekt)
	{
		clearTimeout (id[objekt]);
		rgb[objekt] = 0;
		objekt.style.color = "Rgb(255, 0, 0)";
	}
	
  var PoleOdkazu = document.getElementsByTagName ("a");
  for (var ce in PoleOdkazu)
  {
  	PoleOdkazu[ce].onmouseover =	function () {Stop (this);};
    PoleOdkazu[ce].onmouseout =		function () {Stop (this); Start (this);};
  	PoleOdkazu[ce].onfocus =			function () {Stop (this);};
    PoleOdkazu[ce].onblur =				function () {Stop (this); Start (this);};
  }
}

function Iframe_Rozmery (prvek)
{
	prvek.style.height = prvek.contentWindow.document.body.scrollHeight;
  prvek.style.width = prvek.contentWindow.document.body.scrollWidth;
}

function Ajax_Include (stranka, kam)
{
	document.getElementById (kam).innerHTML = "Odesílám požadavek ...";

	ProgressImage = new Image ();
	ProgressImage.src = "/images/ikony/progress.gif";
	div = "\r\n<div id=\"ProgressStatus"+kam+"\"></div>\r\n";
	objekt = document.getElementById (kam);
	if (!document.getElementById ("ProgressStatus"+kam))
	{
		objekt.innerHTML = div+objekt.innerHTML;
	}
	
	status = false;
	
	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 ("ProgressStatus"+kam).innerHTML = "Chyba při načítání stránky " + httpRequest.status +": "+ httpRequest.statusText;
			}
		}
		else
		{
			if (typeof (kam) == "string" && status == false)
			{
				status = true;
				document.getElementById ("ProgressStatus"+kam).innerHTML = "<img alt=\"progress\" id=\"ProgressImage"+kam+"\" style=\"width: 90%; height: 12px;\"><div style=\"color: black; margin-top: -15px;\" id=\"ProgressText"+kam+"\">Aktualizace</div>";
				document.getElementById ("ProgressImage"+kam).src = ProgressImage.src;
				if (document.all) {document.getElementById ("ProgressText"+kam).style.marginTop = "-13px";}
			}
		}
	}

	var httpRequest;
	
	if (typeof window.ActiveXObject != "undefined")
	{
		httpRequest = new ActiveXObject ("Microsoft.XMLHTTP");
	}
	else
	{
		httpRequest = new XMLHttpRequest ();
	}
	httpRequest.open ("GET", stranka, true);
	// POST
	// httpRequest.open ("POST", stranka, true);
	// httpRequest.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	httpRequest.setRequestHeader ("encoding", "utf8");
	
	httpRequest.onreadystatechange = function ()
	{
		ProcessRequest (httpRequest, kam)
	};
	httpRequest.send (null);
	// POST
	// httpRequest.send ("pokus=aa"); 
}

function Zmena_Obrazku (objekt1, objekt2, ArrayImages, ArrayText, interval)
{
	if (ArrayImages["random"] != null)
	{
		random = ArrayImages["random"];
		while (random == ArrayImages["random"])
		{
			random = Math.round (Math.random () * ArrayImages["onload"].length - 0.5);
		}
		
		random2 = ArrayText["random"];
		while (random2 == ArrayText["random"])
		{
			random2 = Math.round (Math.random () * ArrayText["text"].length - 0.5);
		}
		
		document.getElementById (objekt2).src = document.getElementById (objekt1).src;
		document.getElementById (objekt1).style.opacity = 0;
		document.getElementById (objekt1).style.filter = "alpha(opacity=0)";
		document.getElementById (objekt1).src = ArrayImages["image"][ArrayImages["onload"][random]].src;
		
		document.getElementById ("NadpisText2").innerHTML = document.getElementById ("NadpisText1").innerHTML;
		document.getElementById ("NadpisText1").style.opacity = 0;
		document.getElementById ("NadpisText1").style.filter = "alpha(opacity=0)";
		document.getElementById ("NadpisText1").innerHTML = ArrayText["text"][random2];
		
		function Pruhlednost (cislo1, cislo2)
		{
			cislo1 += 4;
			cislo2 -= 4;
			document.getElementById (objekt1).style.opacity = cislo1 / 100;
			document.getElementById (objekt1).style.filter = "alpha(opacity="+cislo1+")";
			
			document.getElementById ("NadpisText2").style.opacity = cislo2 / 100;
			document.getElementById ("NadpisText2").style.filter = "alpha(opacity="+cislo2+")";	
			
			document.getElementById ("NadpisText1").style.opacity = cislo1 / 100;
			document.getElementById ("NadpisText1").style.filter = "alpha(opacity="+cislo1+")";			
			
			if (cislo1 < 100)
			{
				setTimeout (function () {Pruhlednost (cislo1, cislo2);}, 20);
			}
			else
			{
				setTimeout (function () {Zmena_Obrazku (objekt1, objekt2, ArrayImages, ArrayText, interval);}, interval);
			}
		}
		
		ArrayImages["random"] = random;
		ArrayText["random"] = random2;
		Pruhlednost (0, 100);
	}
	else
	{
		ArrayImages["image"] = new Array ();
		ArrayImages["onload"] = new Array ();
		ArrayImages["random"] = 0;
		ArrayText["random"] = 0;
		for (var i = 0; i < ArrayImages["src"].length; i ++)
		{
			ArrayImages["image"][i] = new Image();
			// Využití funkce, aby zůstala zachována hodnota proměnné i
			// Jinak, až by se podmínka splnila, tak by v proměnné i byla stejná maximální hodnota
			(
				function (i)
				{
					ArrayImages["image"][i].onload = function ()
					{
						ArrayImages["onload"].push (i);
						if (ArrayImages["onload"].length == 2)
						{
							setTimeout (function () {Zmena_Obrazku (objekt1, objekt2, ArrayImages, ArrayText, interval);}, interval);
						}
						// Postupné načítání obrázků do cache, aby při hromadném načítání nezamrzl prohlížeč
						// setTimeout je tam kvůli IE - bez něj to vyhodí alert ("Stack overflow at line: 0")
						setTimeout (function () {if (ArrayImages["src"][i + 1]) ArrayImages["image"][i + 1].src = ArrayImages["src"][i + 1];}, 1);
					};
				}
			)(i);
			if (i === 0) ArrayImages["image"][0].src = ArrayImages["src"][0];
		}
	}
}

/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Global - Komentáře XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */

/*
objekt				string		ID elementu
TagStart			string    Začátek tagu
TagEnd				string		Konec tagu
TagText				string    Obsah tagu, výchozí hodnotou je vybraný text
prependText		string    Text vkládaný před tag. Výchozí null
appendText		string    Text vkládaný za tag. Výchozí null
*/

function insertTag (objekt, TagStart, TagText, prependText, appendText)
{
	// inicializace proměných
	var element = document.getElementById (objekt);

	if (typeof (TagText) == "undefined")	{TagText = getDocumentSelection () ? getDocumentSelection () : getTextareaSelection (objekt);}
	
	if (typeof (prependText) == "undefined")	{var prependText = "";}
	
	if (typeof (appendText) == "undefined")	{var appendText = "";}
	
	var TagType = TagStart.charAt (0)+TagStart.charAt (TagStart.length - 1);
	
	var TagValue = TagStart.substring (1, (TagStart.indexOf ("=") >= 1 ? TagStart.indexOf ("=") : TagStart.length - 1));
	
	var TagEnd = TagType.charAt (0)+"/"+TagValue+TagType.charAt (1);

	// přepsání výchozích hodnot pro specifické tagy
	if (TagValue == "list")
	{
		if (TagType == "[]")
		{
			TagStart += "\r\n"+TagType.charAt (0)+"*"+TagType.charAt (1);
			TagEnd = "\r\n"+TagEnd;
		}
		else if (TagValue == "list")
		{
			TagStart = "<ul>\r\n<li>";
			TagEnd = "</li>\r\n</ul>\r\n";
		}
		else
		{
			TagStart = "<ul style=\"list-style-type: ;\">\r\n<li>";
			TagEnd = "</li>\r\n</ul>\r\n";
		}
	}
	else if (TagType == "**" || TagValue == "*")
	{
		TagEnd = "";
	}
	else if (TagValue == "url")
	{
		if (TagText == "")
		{
			TagText = "Odkaz";
		}
		var regexp = new RegExp("^((http|https|ftp)\\://)([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&:|\(\)\*\[\];%\\$#\\=~_\\-@]*)*$");
		var regexp2 = new RegExp("^([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|www\\.([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\'\\\\/\\+&:|\(\)\*\[\];%\\$#\\=~_\\-@]*)*$");
		
		if (regexp.test (TagText))
		{
			TagStart = TagType.charAt (0)+"url="+TagText+TagType.charAt (1);
		}
		else if (regexp2.test (TagText))
		{
			TagStart = TagType.charAt (0)+"url=http://"+TagText+TagType.charAt (1);
		}
		else
		{
			TagStart = TagType.charAt (0)+"url=http://www.priklad.cz"+TagType.charAt (1);
			selectionStart = prependText.length-Preg_Count (prependText, /\r/g)+16;
			selectionEnd = prependText.length-Preg_Count (prependText, /\r/g)+26;
		}
	}
		
	// vytvoření textu pro vložení
	var text2insert = prependText+TagStart+TagText+TagEnd+appendText;
	
	element.focus ();
	
	// zjištění pozice scrollu
	var scrollTop = element.scrollTop;
	
	// vložení
	if (typeof (element.selectionStart) != "undefined")
	{
		var start = element.selectionStart;
		var end = element.selectionEnd;
		
		element.value = element.value.substr (0, start)+text2insert+element.value.substr (end);
		
		// nastavení kurzoru na správné místo / vybrání požadovaného textu
		if (typeof (selectionStart) != "undefined" && typeof (selectionEnd) != "undefined")
		{
			element.selectionStart = start+selectionStart;
			element.selectionEnd = start+selectionEnd;
		}
		else
		{
			if (TagText == "")
			{
				// skočení mezi tagy
				element.selectionStart = start+prependText.length-Preg_Count (prependText, /\r/g)+TagStart.length-Preg_Count (TagStart, /\r/g);
				element.selectionEnd = start+prependText.length-Preg_Count (prependText, /\r/g)+TagStart.length-Preg_Count (TagStart, /\r/g);
			}
			else
			{
				// skočení za poslední tag
				element.selectionStart = start+text2insert.length-Preg_Count (text2insert, /\r/g);
				element.selectionEnd = start+text2insert.length-Preg_Count (text2insert, /\r/g);
			}
		}
	}
	else if (typeof (document.selection) != "undefined")
	{
		var range = document.selection.createRange ();
		range.text = text2insert;
		
		// nastavení kurzoru na správné misto / vybrání požadovaného textu
		if (typeof (selectionStart) != "undefined" && typeof (selectionEnd) != "undefined")
		{
			range.moveStart("character", -(text2insert.length-Preg_Count (text2insert, /\r/g))+selectionStart);
			range.moveEnd("character", -(text2insert.length-Preg_Count (text2insert, /\r/g))+selectionEnd);
		}
		else
		{
			if (TagText == "")
			{
				// skočení mezi tagy
				range.move ("character", -((TagEnd.length-Preg_Count (TagEnd, /\r/g))+(appendText.length-Preg_Count (appendText, /\r/g))));
			}
			else
			{
				// skočení za poslední tag
				// protože prohlížeč v tomto případě skočí za poslední tag automaticky, není třeba nic posouvat	
			}
		}
		range.select ();
	}
	
	element.scrollTop = scrollTop + text2insert.length;

	// unset proměných
	delete selectionStart;
	delete selectionEnd;
}

function getTextareaSelection (objekt)
{
	var element = document.getElementById (objekt);
	if (typeof (element.selectionStart) != "undefined")
	{
		var selection = element.value.substring (element.selectionStart, element.selectionEnd);
	}
	else if (typeof (document.selection) != "undefined")
	{
		var selection = document.selection.createRange ().text;
	}
	else
	{
		// alert("Bug!");
	}
	return selection;
}

function getDocumentSelection ()
{
	if (document.getSelection) selection = document.getSelection ();
	else if (document.selection) selection = document.selection.createRange ().text;
	else if (window.getSelection) selection = window.getSelection;
	else selection = "";
	return selection;
}

String.prototype.trim = function ()
{
	return this.replace (/^\s+|\s+$/g, "");
}

function Comments_Format_Info (objekt, text)
{
	var element = document.getElementById (objekt);
	if (text)	{element.innerHTML = text;}
	else			{element.innerHTML = "Pro rychlejší formátování nejprve označte nějaký text";}
}

function Komentare_Kontrola ()
{
	function Validace_Kontrola ()
	{
		var objekt = document.getElementById ("kontrola1");
		if (!objekt) {return true;}
		cislo = /^[0-9]{5}$/
		if (!cislo.test (objekt.value))
		{
			alert ("!!! Číselný kód byl zadán ve špatném tvaru !!!");
			objekt.focus ();
			return false;
		}
		return true;
	}
	
	function Validace_Jmeno ()
	{
		var objekt = document.getElementById ("jmeno");
		if (!objekt) {return true;}
		if (Preg_Count (objekt.value, /\S/g) < 3)
		{
			alert ("!!! Jméno musí obsahovat minimálně 3 znaky !!!");
			objekt.focus ();
			return false;
		}
		if (objekt.value.length > 25)
		{
			alert ("!!! Jméno nesmí obsahovat více než 25 znaků !!!");
			objekt.focus ();
			return false;
		}
		return true;
	}
	
	function Validace_Email ()
	{
		var objekt = document.getElementById ("email");
		if (!objekt) {return true;}
		
		mail = /^[a-z0-9]+[a-z0-9\.\-_]*[a-z0-9]+@[a-z0-9]+[a-z0-9\.\-_]*[a-z0-9]+\.[a-z]{2,4}$/
		
		if (objekt.value && !mail.test(objekt.value))
		{
			alert ("!!! E-mail byl zadán ve špatném tvaru !!!");
			objekt.focus ();
			return false;
		}
		if (objekt.value.length > 50)
		{
			alert ("!!! E-mail nesmí obsahovat více než 50 znaků !!!");
			objekt.focus ();
			return false;
		}
		return true;
	}
	
	function Validace_Web ()
	{
		var objekt = document.getElementById ("web");
		if (!objekt) {return true;}
		
		web = /^(http|https|ftp|ftps):\/\/(www\.)?([a-z0-9]+[a-z0-9\.\-]*\.[a-z]{2,4}|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(\/\S*|\/)?$/
		
		if (objekt.value && objekt.value != "http://" && !web.test(objekt.value))
		{
			alert ("!!! Web byl zadán ve špatném tvaru !!!");
			objekt.focus ();
			return false;
		}
		if (objekt.value.length > 50)
		{
			alert ("!!! Web nesmí obsahovat více než 50 znaků !!!");
			objekt.focus ();
			return false;
		}
		return true;
	}
	
	function Validace_Prispevek ()
	{
		var objekt = document.getElementById ("komentar");
		var ZnakyTisk = Preg_Replace (/\s/g, "", objekt.value);
		if (ZnakyTisk.length < 1 || objekt.value == "Text komentáře")
		{
			alert ("!!! Musíte vložit nějaký komentář !!!");
			objekt.focus ();
			return false;
		}
		if (objekt.value.length > 5000)
		{
			alert ("!!! Komentář nesmí obsahovat více než 5 000 znaků !!!");
			objekt.focus ();
			return false;
		}
		if (Preg_Count (objekt.value, /\n/g) + 1 > 15)
		{
			alert ("!!! Komentář nesmí obsahovat více než 15 řádků !!!");
			objekt.focus ();
			return false;
		}
		return true;
	}
	
	function Kontrola_Znaku ()
	{
		var PocetSmajliku = 0;
		var pole = new Array();
		var BezHvezdicek = new Array();
		if (document.getElementById ("jmeno")) {pole[0] = document.getElementById ("jmeno");}
		pole[1] = document.getElementById ("komentar");
		
		// speciální cyklus vracející indexy všech položek v poli
		for (var cu in pole)
		{
			PocetSmajliku += Preg_Count (pole[cu].value, /\*([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-4])\*/g);
			
			if (PocetSmajliku > 10)
			{
				alert ("!!! Můžete použít maximálně 10 smajlíků !!!");
				pole[cu].focus ();
				return false;
			}
		}
		return true;
	}

	if (!Validace_Kontrola () || !Validace_Jmeno () || !Validace_Email () || !Validace_Web () || !Validace_Prispevek () || !Kontrola_Znaku ())
	{
		alert ("Opravte chyby nebo nebude možné komentář odeslat");
		return false;
	}
	return true;
}

function Komentare_Statistika ()
{
	var objekt1 = document.getElementById ("jmeno");
	var objekt2 = document.getElementById ("komentar");
	var PocetSmajliku = 0;

	// Délka jména
	if (objekt1)
	{
		var JmenoDelka = objekt1.value.length;

		document.getElementById ("JmenoDelka").innerHTML = JmenoDelka;
		PocetSmajliku += Preg_Count (objekt1.value, /\*([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-4])\*/g);
		
		if (JmenoDelka > 25 || JmenoDelka < 3)
		{
			document.getElementById ("JmenoDelka").className = "StatistikaChyba";
		}
		else
		{
			document.getElementById ("JmenoDelka").className = "";
		}
	}
	
	var PrispevekDelka = objekt2.value.length;
	var PrispevekRadek = Preg_Count (objekt2.value, /\n/g) + 1;
	
	// Délka příspěvku
	document.getElementById ("KomentarDelka").innerHTML = PrispevekDelka;
	if (PrispevekDelka > 5000 || PrispevekDelka < 1)
	{
		document.getElementById ("KomentarDelka").className = "StatistikaChyba";
		
	}
	else
	{
		document.getElementById ("KomentarDelka").className = "";
	}
	
	// Počet řádků příspěvku
	document.getElementById ("KomentarRadek").innerHTML = PrispevekRadek;
	if (PrispevekRadek > 15)
	{
		document.getElementById ("KomentarRadek").className = "StatistikaChyba";
		
	}
	else
	{
		document.getElementById ("KomentarRadek").className = "";
	}
	
	// Počet smajlíků
	PocetSmajliku += Preg_Count (objekt2.value, /\*([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-4])\*/g);
	document.getElementById ("KomentarSmajlik").innerHTML = PocetSmajliku;
	if (PocetSmajliku > 10)
	{
		document.getElementById ("KomentarSmajlik").className = "StatistikaChyba";
		
	}
	else
	{
		document.getElementById ("KomentarSmajlik").className = "";
	}

/*	
	// Nejdelší slovo
	PoziceOddelovac = -1;
	NejdelsiSlovo = 0;
	for (var pozice = 0; pozice <= objekt2.value.length; pozice ++)
	{
		if (pozice == objekt2.value.length || objekt2.value.charAt (pozice) == " " || objekt2.value.charAt (pozice) == "\r" || objekt2.value.charAt (pozice) == "\n")
		{
			DelkaSlova = pozice - PoziceOddelovac - 1;
			PoziceOddelovac = pozice;
			if (DelkaSlova > NejdelsiSlovo)
			{
				NejdelsiSlovo = DelkaSlova;
			}
		}
	}
	document.getElementById ("KomentarNejdelsiSlovo").innerHTML = NejdelsiSlovo;
	if (NejdelsiSlovo > 50)
	{
		document.getElementById ("KomentarNejdelsiSlovo").className = "StatistikaChyba";
		
	}
	else
	{
		document.getElementById ("KomentarNejdelsiSlovo").className = "";
	}
*/
}

function Komentare_Focus (objekt)
{
	if (document.getElementById ("kontrola1"))
	{
		document.getElementById ("kontrola1").focus ();
	}
	else
	{
		if (objekt)
		{
			document.getElementById (objekt).focus ();
		}
		else
		{
			document.getElementById ("komentar").focus ();
		}
	}
}

/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX jQuery XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */

function jQuery_Include (stranka, kam)
{
	$("#"+kam).load (stranka);
	
	// $.post (stranka, {string: "Petr"}, function (vystup) {$("#"+kam).html (vystup);});
}