var lockForm = function(state)
{
	var form = document.getElementsByTagName("form")[0];
	var s = form.getElementsByTagName("select");
	for(var i = 0; i < s.length; i++)
		if(s[i].value == s[i].options[0].value) s[i].disabled = state;
};

var dl = document.getElementById("forms");
if(dl)
{
	var templates = {dt: document.createElement("dt"), dd: document.createElement("dd"), a: document.createElement("a"), form: document.createElement("form"), p: document.createElement("p"), ul: document.createElement("ul"), source: {
		"html":
		{
			"HTML 4.01 Strict": "<!doctype html public \"-//W3C//DTD HTML 4.01//EN\">\n<html lang=\"cs\">\n  <head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.\n  </body>\n</html>",
			"HTML 4.01 Transitional": "<!doctype html public \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html lang=\"cs\">\n  <head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.\n  </body>\n</html>",
			"HTML 4.01 Frameset": "<!doctype html public \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n<html lang=\"cs\">\n  <head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n    <title>Titulek</title>\n  </head>\n  <frameset rows=\"*\">\n    <frame name=\"n\u011Bco\" src=\"http://www.webylon.info\">\n    <noframes>\n      <p>Cokoliv.\n    </noframes>\n  </frameset>\n</html>",
/*			"HTML 4.01 Transitional (minim\u00E1ln\u00ED)": "<!doctype html public \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<title>Titulek</title>\nCokoliv.",*/
			"HTML 4.01 + RDFa": "<!doctype html public \"-//W3C//DTD HTML 4.01+RDFa//EN\">\n<html lang=\"cs\">\n  <head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.\n  </body>\n</html>",
			"ISO HTML": "<!doctype html public \"ISO/IEC 15445:2000//DTD HTML//EN\">\n<html lang=\"cs\">\n  <head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.\n  </body>\n</html>",
			"HTML 3.2": "<!doctype html public \"-//W3C//DTD HTML 3.2//EN\">\n<html>\n  <head>\n    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.\n  </body>\n</html>"
		},
		"xml":
		{
			"XHTML 1.0 Strict": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"XHTML 1.0 Transitional": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"XHTML 1.0 Frameset": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <frameset cols=\"*\">\n    <frame name=\"nic\"/>\n    <noframes>\n      <body>\n        <p>Cokoliv.</p>\n      </body>\n    </noframes>\n  </frameset>\n</html>",
			"XHTML + RDFa 1.0": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"XHTML 1.1": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"XHTML Basic 1.0": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML Basic 1.0//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"WAP 1.2": "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/dtd/wml12.dtd\">\n<wml>\n  <card title=\"Titulek\">\n    <p>Cokoliv.</p>\n  </card>\n</wml>",
			"WAP 2.0": "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD WML 2.0//EN\" \"http://www.wapforum.org/DTD/wml20.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"XHTML Mobile 1.0": "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p>Cokoliv.</p>\n  </body>\n</html>",
			"MathML 2.0": "<!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd\">\n<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n  <mrow>\n    <mn>E</mn>\n    <mo>=</mo>\n    <mrow>\n      <mi>m</mi>\n      <mo>&InvisibleTimes;</mo>\n      <msup>\n        <mi>c</mi>\n        <mn>2</mn>\n      </msup>\n    </mrow>\n  </mrow>\n</math>",
			"MathML 2.0 (Strict)": "<!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd\" [\n  <!ENTITY % MathMLstrict \"INCLUDE\">\n]>\n<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n  <mrow>\n    <mn>E</mn>\n    <mo>=</mo>\n    <mrow>\n      <mi>m</mi>\n      <mo>&InvisibleTimes;</mo>\n      <msup>\n        <mi>c</mi>\n        <mn>2</mn>\n      </msup>\n    </mrow>\n  </mrow>\n</math>",
			"SVG 1.1": "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 13 12\">\n  <title>Domov jednoro\u017Ece</title>\n  <rect x=\"0\" y=\"0\" width=\"13\" height=\"12\" fill=\"#73B1F7\"/>\n  <polygon fill=\"#FFFFFF\"\n           stroke=\"#0053A0\"\n           stroke-width=\"0.25\"\n           points=\"1,1 4,1 4,4 5,4 5,1 8,1 8,4 9,4 9,1 12,1 12,7 9,7 9,8 12,8 12,11 1,11 1,8 4,8 4,7 1,7\"/>\n</svg>",
			"XHTML 1.1 + MathML 2.0 + SVG 1.1": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\" \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xml:lang=\"cs\">\n  <head>\n    <title>Titulek</title>\n  </head>\n  <body>\n    <p><cite>Albert Einstein</cite> pravil:</p>\n    <blockquote>\n      <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n        <mrow>\n          <mn>E</mn>\n          <mo>=</mo>\n          <mrow>\n            <mi>m</mi>\n            <mo>&InvisibleTimes;</mo>\n            <msup>\n              <mi>c</mi>\n              <mn>2</mn>\n            </msup>\n          </mrow>\n        </mrow>\n      </math>\n    </blockquote>\n    <p>A j\u00E1 mu na to odv\u011Btil:</p>\n    <blockquote>\n      <svg:svg viewBox=\"0 0 13 12\" width=\"120px\" height=\"130px\">\n        <svg:rect x=\"0\" y=\"0\" width=\"13\" height=\"12\" fill=\"#73B1F7\"/>\n        <svg:polygon fill=\"#FFFFFF\"\n                     stroke=\"#0053A0\"\n                     stroke-width=\"0.25\"\n                     points=\"1,1 4,1 4,4 5,4 5,1 8,1 8,4 9,4 9,1 12,1 12,7 9,7 9,8 12,8 12,11 1,11 1,8 4,8 4,7 1,7\"/>\n      </svg:svg>\n    </blockquote>\n    <p>Z toho byl paf.</p>\n  </body>\n</html>"

		}
	}};
	
	dl.appendChild(templates.dt);
	dl.appendChild(templates.dd);
	templates.dt.id = "validate-template";
	templates.dd.appendChild(templates.form);
	templates.form.appendChild(templates.p);
	templates.form.appendChild(templates.ul);
	templates.dt.appendChild(document.createTextNode("Z \u0161ablony"));
	templates.p.appendChild(document.createTextNode("Vyberte si \u0161ablonu k\u00F3du\u002C kterou si p\u0159ejete dosadit do formul\u00E1\u0159e pro p\u0159\u00EDm\u00FD vstup\u003A"));
	for(var mime in templates.source)
	{
		var li = document.createElement("li");
		var ul = document.createElement("ul");
		templates.ul.appendChild(li);
		li.appendChild(document.createTextNode("p\u0159i MIME typu: " + {html: "text/html", xml: "application/xml, text/xml, */*+xml"}[mime]));
		li.appendChild(ul);
		for(var t in templates.source[mime])
		{
			var a = document.createElement("a");
			ul.appendChild(document.createElement("li")).appendChild(a).appendChild(document.createTextNode(t));
			a.source = templates.source[mime][t];
			a.mime = mime;
			a.href = "#validate-by-input";
			a.onclick = function()
			{
				dl.className = "by-input";
				document.getElementById("fragment").value = this.source;
				document.getElementById("fragment").focus();
				document.getElementById("type-small").value = this.mime;
			}
		}
	}

	dl.id = "forms-js";

	var dts = dl.getElementsByTagName("dt");
	
	for(var i = 0; i < dts.length; i++)
	{
		var a = document.createElement("a");
		a.innerHTML = dts[i].firstChild.nodeValue;
		a.href = "#" + dts[i].id;
		dts[i].className = dts[i].id.substr(9);
		dts[i].id = "";
		dl.getElementsByTagName("dd")[i].className = dts[i].className;
		a.autofocus = document.getElementById(["uri", "uploaded_file", "fragment"][i]);
		a.onclick = function()
		{
			dl.className = this.parentNode.className;
			if(this.autofocus)this.autofocus.focus();
		};
		dts[i].replaceChild(a, dts[i].firstChild);
		dl.insertBefore(dts[i], dl.getElementsByTagName("dd")[0]);
	}
	if(location.hash && location.hash.substr(0, 10) == "#validate-")
	{
		dl.className = location.hash.substr(10);
	}
	else
	{
		document.getElementById("uri").focus();
	}

	dl.getElementsByTagName("form")[0].onsubmit = function()
	{
		var uri = document.getElementById("uri");
		if(uri.value.match(/(^file:\/)|(^\w:\\\w+)|(^(http:\/\/)?localhost\/)/))
		{
			dl.className = "by-upload not-by-uri";
			location.hash = "validate-by-upload";
			return false;
		}
		uri.value = uri.value.replace(/(^\s*)|(\s*$)|(\u00A8$)/g, "");
		return true;
	};
}

var button = document.getElementById("revalidate")
if(button)
{
	var form = document.getElementsByTagName("form")[0];
	form.className = "static";
	var original = button.value;
	button.value = button.alt;
	button.alt = original;
	button.onclick = function()
	{
		form.className = "dynamic";
		button.value = button.alt;
		this.onclick = null;
		return false;
	};
	form.onsubmit = function()
	{
		lockForm(true);
		setTimeout(function()
		{
			lockForm(false);
		}, 100);
	};
	form.className = "static";
}

var buttonD = document.getElementById("validate")
if(buttonD)
{
	var form = document.getElementsByTagName("form")[0];
	form.onsubmit = function()
	{
		lockForm(true);
		setTimeout(function()
		{
			lockForm(false);
		}, 100);
	};
	var http = document.getElementsByTagName("form")[0].getElementsByTagName("fieldset")[0].getElementsByTagName("table")[0];
	for(var i = 0; i < http.rows.length; i++)
		(function()
		{
			var tr = http.rows[i];
			var c = tr.insertCell(-1);
			c.className = "advanced";
			var b = document.createElement("button");
			b.innerHTML = "vlastn\u00ED";
			c.appendChild(b);
			var d = tr.getElementsByTagName("div")[0];
			var s = d.getElementsByTagName("select")[0];
			var t = document.createElement("input");
			d.appendChild(t);
			
			b.onclick = function()
			{
				if(d.className == "wrap-text")
				{
					b.innerHTML = "vlastn\u00ED";
					s.name = t.name;
					t.name = "";
					d.className = "wrap-select";
					s.focus();
				}
				else
				{
					b.innerHTML = "ze seznamu";
					t.name = s.name;
					s.name = "";
					t.value = (s.value == "(none)" && s.selectedIndex == 0) ? "" : s.value;
					d.className = "wrap-text";
					t.focus();
				}
				return false;
			};
		})();
}



if(window.netscape)
{
	var transformListing = function(e)
	{
		if(!e) return false;
		var li = e.getElementsByTagName("li");
		for(var i = 0, l = li.length; i < l; i++)
		{
			var d = document.createElement("div");
			d.innerHTML = li[0].innerHTML;
			d.id = li[0].id;
			d.className = li[0].className;
			li[0].parentNode.appendChild(d);
			li[0].parentNode.removeChild(li[0]);
		}
		return "Yabba Dabba Doo";
	};
	document.addEventListener("DOMContentLoaded", function()
	{
		transformListing(document.getElementById("source"));
		transformListing(document.getElementById("http"));
	}, false);
}
if(document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule) document.styleSheets[0].addRule("ol.listing", "word-break: break-all");

var Page = {
	"lastUI": { group: "false" },
	"loadUI": function()
	{
		window.ui = {};
		for(var i = 0, c = document.cookie.split("; "); i < c.length; i++) Page.lastUI[c[i].split("=")[0]] = c[i].split("=")[1];
		Page.lastUI["group"] = Page.lastUI["group"] != "false";
		for(var c in Page.lastUI) ui[c] = Page.lastUI[c];
	},
	"saveUI": function()
	{
		for(var c in ui) if(ui[c] != Page.lastUI[c]) document.cookie = c + "=" + ui[c] + "; expires=" + (new Date(2030, 12, 31)).toGMTString();
	},
	"init": function()
	{
		Page.loadUI();
		window.onunload = function()
		{
			Page.saveUI();
		};
	}
};
Page.init();

function group(a, b)
{
	if(!a)
	{
		if(!group.init)
		{
			document.write("<label for=\"group-check\" id=\"group-label\">\u00A0seskupovat podobn\u00E9 hl\u00E1\u0161ky <input type=\"checkbox\" id=\"group-check\" " + (ui.group ? "checked" : "")  + " disabled></label>");
			group.init = true;
			group.ungrouped = [];
			group.grouped = [];
		}
		else
		{
			if(ui.group)
				for(var i = 0; i < group.ungrouped.length; i++)
				{
					group.ungrouped[i].parentNode.removeChild(group.ungrouped[i]);
					group.ungrouped[i].style.display = "";
				}

			document.getElementById("group-check").disabled = false;
			document.getElementById("group-check").checked = ui.group;
			document.getElementById("group-check").onclick = function()
			{
				ui.group = !ui.group;
				if(ui.group)
				{
					var result = group.grouped[0].parentNode;
					for(var i = 0; i < group.ungrouped.length; i++)
						result.removeChild(group.ungrouped[i]);
					for(var i = 0; i < group.grouped.length; i++)
						group.grouped[i].appendChild(group.grouped[i].group);
				}
				else
				{
					var result = group.grouped[0].parentNode;
					for(var i = 0; i < group.ungrouped.length; i++)
						result.insertBefore(group.ungrouped[i], group.ungrouped[i].before.nextSibling);

					for(var i = 0; i < group.grouped.length; i++)
						group.grouped[i].group.parentNode.removeChild(group.grouped[i].group);
				}
				if(window.opera) Page.saveUI();
			}
		}
	}
	else
	{
		var ae = document.getElementById("msg-" + a);
		var be = document.getElementById("msg-" + b);
		var b2 = be.cloneNode(true);
		b2.removeChild(b2.getElementsByTagName("img")[0]);

		if(!ae.group)
		{
			ae.group = document.createElement("div");
			ae.group.className = "grouped";
			ae.group.innerHTML = "<ol></ol>";
			if(ui.group) ae.appendChild(ae.group);
			group.grouped[group.grouped.length] = ae;
		}
		ae.group.getElementsByTagName("ol")[0].appendChild(b2);
		if(ui.group) be.style.display = "none";

		be.before = be.previousSibling;
		group.ungrouped[group.ungrouped.length] = be;
	}
}