/*=============================================================================
 Updated: 30.4.2008 11:39:16
-------------------------------------------------------------------------------
 Copyright (c) 2000 - 2006 VIZUS.CZ s.r.o., All Rights Reserved.
=============================================================================*/

// retezce
var Strings = new Object();
var AsciiTableFrom = '';
var AsciiTableTo = '';
var WinXPSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);
var IE7 = (window.navigator.userAgent.indexOf("MSIE 7") != -1);
var WinVista = (window.navigator.userAgent.indexOf("Windows NT 6") != -1);
var AntiSpamChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_=?%';
var Charset = document.charset;

// nove okno
function win(url, width, height, resizable, scroll)
{
	if (!width)
		width = 300;
	if (!height)
		width = 300;
	if (scroll == null)
		scroll = 0 ;
	
	var x = Math.round(window.screen.availWidth / 2 - width / 2);
	var y = Math.round(window.screen.availHeight / 2 - height / 2);
	if (x < 0)
		x = 10;
	if (y < 0)
		y = 10;

	var features = 'height='+height+', left='+x+', location=no, menubar=no, resizable='+(resizable ? 'yes' : 'no')+', '
		+'scrollbars='+(scroll ? 'yes' : 'no')+', status=no, titlebar=no, toolbar=no, top='+y+', width='+width;
	
	window.open(url, '_blank', features);
}

// zobrazeni media
function show(url, width, height)
{
	var resizable = false;
	if (!width && !height)
	{
		width = 400;
		height = 400;
		var resizable = true;
	}
	else
	{
		width = !width ? 300 : width + 20;
		height = !height ? 300 : height + 20;
	
		if (width < 100)
			width = 100;
	}
	
	var x = Math.round(window.screen.availWidth / 2 - width / 2);
	var y = Math.round(window.screen.availHeight / 2 - height / 2);
	if (x < 0)
		x = 10;
	if (y < 0)
		y = 10;

	var features = 'height='+height+', left='+x+', location=no, menubar=no, resizable='+(resizable ? 'yes' : 'no')+', '
		+'scrollbars=no, status=no, titlebar=no, toolbar=no, top='+y+', width='+width;
	
	window.open(url, '_blank', features);
}

// nove okno
function getWin(url, width, height, resizable, scroll)
{
	if (!width)
		width = 300;
	if (!height)
		width = 300;
	if (scroll == null)
		scroll = 0;
	
	var x = Math.round(window.screen.availWidth / 2 - width / 2);
	var y = Math.round(window.screen.availHeight / 2 - height / 2);
	if (x < 0)
		x = 10;
	if (y < 0)
		y = 10;

	var features = 'height='+height+', left='+x+', location=no, menubar=no, resizable='+(resizable ? 'yes' : 'no')+', '
		+'scrollbars='+(scroll ? 'yes' : 'no')+', status=no, titlebar=no, toolbar=no, top='+y+', width='+width;
	
	return window.open(url, '_blank', features);
}

// novy dialog - modalni
function dialog(url, width, height, resizable, scroll, modeless)
{
	if (!width)
		width = 300;
	if (!height)
		width = 300;
	if (WinXPSP2)
		height += 20;
	if (IE7)
		height -= 24;

	var features = 'dialogHeight: '+height+'px; dialogWidth: '+width+'px; status: off; help: no; resizable: '+(resizable ? 'yes' : 'no')+'; '
		+'scroll: '+(scroll ? 'yes' : 'no')+'; center: yes; edge: sunken';
	
	return modeless ? window.showModelessDialog(url, window, features) : window.showModalDialog(url, window, features);
}

// dialog nahledu
function preview(url, width, height)
{
	if (!width && !height)
	{
		width = 400;
		height = 400;
	}
	else
	{
		width = !width ? 300 : width + 10;
		height = !height ? 300 : height + 30;
	
		if (width < 100)
			width = 100;
	}
	
	if (WinXPSP2)
		height += 20;
	if (IE7)
		height -= 24;

	var scrollable = width > window.screen.availWidth || height > window.screen.availHeight;
	var features = 'dialogHeight: '+height+'px; dialogWidth: '+width+'px; status: no; help: no; resizable: yes; '
		+'scroll: '+(scrollable ? 'yes' : 'no')+'; center: yes; edge: sunken';
	
	window.showModalDialog(url, window, features);
}

// presmerovani stranky
function pgRedirect(params, url)
{
	if (!url)
		url = document.location.toString();

	document.location = urlChange(url, params);
}

// uprava URL
function urlChange(url, params)
{
	if (!params)
		return url;

	if (url.indexOf('?'))
	{
		url.match(/^(.*)\?(.*)#?(.*)$/);
		url = RegExp.$1;
		var pairs = RegExp.$2.split('&');
		var hash = RegExp.$3 ? RegExp.$3 : null;
		var stayPairs = new Array();
		for (var i = 0; i < pairs.length; i++)
		{
			var kv = pairs[i].split('=');
			if (typeof(params[ kv[0] ]) == 'undefined')
				stayPairs[stayPairs.length] = pairs[i];
		}
		pairs = stayPairs;
		for (var key in params)
		{
			if (params[key] !== null)
				pairs[pairs.length] = EscapeURI(key)+'='+EscapeURI(params[key]);
		}
	}
	else
	{
		url.match(/^(.*)#?(.*)$/);
		url = RegExp.$1;
		var hash = RegExp.$2 ? RegExp.$2 : null;
		var pairs;
		for (var key in params)
		{
			if (params[key] !== null)
				pairs[pairs.length] = EscapeURI(key)+'='+EscapeURI(params[key]);
		}
	}
	return url+'?'+pairs.join('&')+(hash ? '#'+hash : '')
}

// zakoduje URL podle charsetu
function EscapeURI(str)
{
	if (Charset == 'utf-8')
		return encodeURI(str);
	else
		return escape(str);
}

// meni velikost obsahove casti
function pgResize()
{
	var css = document.styleSheets[2];
	if (css.rules[0].style.width == '100%')
	{
		// small
		css.rules[0].style.width = '530px';
		css.rules[1].style.left = '7px';
		css.rules[2].style.width = '300px';
		document.cookie = 'CmsPageResizeMode=1';
		document.cookie = 'CmsPageResizeQuery='+escape(document.location.search.substr(1));
	}
	else
	{
		// big
		css.rules[0].style.width = '100%';
		css.rules[1].style.left = '4px';
		css.rules[2].style.width = '400px';
		document.cookie = 'CmsPageResizeMode=3';
		document.cookie = 'CmsPageResizeQuery='+escape(document.location.search.substr(1));
	}
}

// zmena sablony
function changeStencil(sel)
{
	var elm = sel.id;
	var id = sel.value;
	var stencil = window[elm+'Stencils'][id];
	var applyTo = window[elm+'ApplyTo'];
	for (var i = 0; i < applyTo.length; i++)
	{
		var eUrl = document.all.item(applyTo[i]+'EditUrl');
		var pUrl = document.all.item(applyTo[i]+'PreviewUrl');
		
		if (!eUrl || !pUrl)
		{
			alert('WComCmsFormHtmlStencil error: DOM id "'+applyTo[i]+'" for ApplyTo not found!');
			return;
		}
		
		for (var i = 0; i < eUrl.length; i++)
		{
			if (!eUrl[i].href.match(/javascript:dialog\('([^\']+)', ?(\d+), ?(\d+), ?(\d), ?(\d)\)/))
				continue;
			
			var url = RegExp.$1;
			var res = RegExp.$4;
			var scr = RegExp.$5;
			eUrl[i].href = "javascript:dialog('"+url.replace(/stencil=\d+/, 'stencil='+id)+"', "+stencil.eWidth+', '+stencil.eHeight+', '+res+', '+scr+')';
		}
		
		for (var i = 0; i < pUrl.length; i++)
		{
			if (!pUrl[i].href.match(/javascript:dialog\('([^\']+)', ?(\d+), ?(\d+), ?(\d), ?(\d)\)/))
				continue;
			var url = RegExp.$1;
			var res = RegExp.$4;
			var scr = RegExp.$5;
			pUrl[i].href = "javascript:dialog('"+url.replace(/stencil=\d+/, 'stencil='+id)+"', "+stencil.pWidth+', '+stencil.pHeight+', '+res+', '+scr+')';
		}
	}
}

// formatuje cislo na retezec
function numFormat(num, dec, decPnt, thsSep)
{
	if (isNaN(num))
		return 'NaN';
	
	if (dec == null) dec = 0;
	if (decPnt == null) decPnt = ',';
	if (thsSep == null) thsSep = '';
	
	if (dec > 0)
	{
		var pow = Math.pow(10, dec);
		num = Math.round(num * pow) / pow;
		num = num.toString();
		if (num.indexOf('.') != -1)
		{
			var pnt = num.indexOf('.');
			var numInt = num.substr(0, pnt);
			var numDec = num.substring(pnt + 1, pnt + 1 + dec);
			while (numDec.length < dec)
				numDec += '0';
		}
		else
		{
			var numInt = num;
			var numDec = pow.toString().substr(1);
		}
	}
	else
	{
		var numDec = '';
		var numInt = Math.round(num).toString();
	}

	if (thsSep && numInt.length > 3)
	{
		var ths = new Array();
		var mod = numInt.length % 3;
		var max = Math.floor(numInt.length / 3);
		if (mod)
			ths[0] = numInt.substr(0, mod);
		for (var i = 0; i < max; i++)
			ths[ths.length] = numInt.substr(i * 3 + mod, 3);
		
		numInt = ths.join(thsSep);
	}
	
	return dec ? numInt + decPnt + numDec : numInt;
}

// kontrola input-boxu (priradit udalosti onkeypress)
function inpNumVal(obj, dec, neg)
{
	if (isNumVal(obj.value, dec, neg))
	{
		obj.style.color = '#0000FF';
		return dec ? parseFloat(obj.value.replace(/ /g, '').replace(/,/g, '.')) : parseInt(obj.value.replace(/ /g, ''));
	}
	else
	{
		obj.style.color = '#E60000';
		return dec ? numFormat(0, dec) : 0;
	}
}
/*
// kontrola input-boxu na min delku (priradit udalosti onkeypress)
function inpCheckMinLength(obj, length)
{
	if (length && obj.value.length < length)
		obj.style.color = '#E60000';
	else
		obj.style.color = '#0000FF';
}

// kontrola input-boxu na max delku (priradit udalosti onkeydown)
function inpCheckMaxLength(obj, length)
{
	if (length && obj.value.length > length)
	{
		obj.style.color = '#E60000';
		return false;
	}
	else
	{
		obj.style.color = '#0000FF';
		return true;
	}
}

// kontrola input-boxu na datum (priradit udalosti onkeypress)
function inpCheckDate(obj)
{
	if (obj.value.match(/\d{1,2}\.\d{1,2}\.\d{2,4}/))
		obj.style.color = '#0000FF';
	else
		obj.style.color = '#E60000';
}

// kontrola input-boxu na cas (priradit udalosti onkeypress)
function inpCheckTime(obj)
{
	if (obj.value.match(/\d{1,2}:\d{1,2}/))
		obj.style.color = '#0000FF';
	else
		obj.style.color = '#E60000';
}

// kontrola input-boxu na datum, cas (priradit udalosti onkeypress)
function inpCheckDatetime(obj, timeIsRequired)
{
	if ((timeIsRequired && obj.value.match(/\d{1,2}\.\d{1,2}\.\d{2,4}, \d{1,2}:\d{1,2}/)) || (!timeIsRequired && obj.value.match(/\d{1,2}\.\d{1,2}\.\d{2,4}(, \d{1,2}:\d{1,2}){0,1}/))
		obj.style.color = '#0000FF';
	else
		obj.style.color = '#E60000';
}

// kontrola input-boxu na priponu (priradit udalosti onchange)
function inpCheckExt(obj, extensions)
{
	obj.value.match(/\.(\w+)$/);
	if (extensions.length && RegExp.$1)
	{
		var ext = RegExp.$1.toLowerCase();
		var valid = false;
		for (var i = 0; i < extensions.length; i++)
		{
			if (extensions[i] == ext)
			{
				valid = true;
				break;
			}
		}
		if (valid)
			obj.style.color = '#0000FF';
		else
			obj.style.color = '#E60000';
	}
	else
		obj.style.color = '#0000FF';
}
*/
// formatovani cisla input-boxu (priradit onblur)
function inpNumFmt(obj, dec, neg)
{
	if (isNumVal(obj.value, dec, neg))
		obj.value = numFormat(parseFloat(obj.value.replace(/ /g, '').replace(/,/g, '.')), dec, ',', ' ');
}

// validace cisla
function isNumVal(num, dec, neg)
{
	num = num.toString();
	var re = dec ? (neg ? /^-?(\d+ )*\d+(|[\.,]\d+)$/ : /^(\d+ )*\d+(|[\.,]\d+)$/) : (neg ? /^-?(\d+ )*\d+$/ : /^(\d+ )*\d+$/);
	return num.match(re);
}

// validace stisknuti cisla na klavesnici
function isDigit()
{
	return ((event.keyCode >= 48) && (event.keyCode <= 57));
}

// vraci cele cislo
function getNumInt(val, defaultVal)
{
	var num = parseInt(val);
	return isNaN(num) ? (defaultVal != null ? defaultVal : 0) : num;
}
		
// vraci realne cislo
function getNumFloat(val, defaultVal)
{
	var num = parseFloat(val);
	return isNaN(num) ? (defaultVal != null ? defaultVal : 0) : num;
}
	
// vymaze obsah
function inpEmpty(obj)
{
	obj.value = '';
}

// vyjme obsah do schranky
function inpCut(obj)
{
	window.clipboardData.setData('Text', obj.value);
	obj.value = '';
}

// kopiruje obsah do schranky
function inpCopy(obj)
{
	window.clipboardData.setData('Text', obj.value);
}

// vlozi obsah ze schranky
function inpPaste(obj)
{
	var txt = window.clipboardData.getData('Text');
	obj.value = txt ? txt : '';
}

// meni label na ident
function makeIdent(obj, label, add)
{
	if (obj.value.length == 0)
	{
		add = add ? add : '';
		obj.value = toAscii(label.value).replace(/[^A-Za-z0-9]+/g, '-').replace(/^-|-$/, '').toLowerCase()+add;
	}
}

// opravuje URL: www.neco.cz na http://www.neco.cz/
function repairUrl(obj, protocol)
{
	if (!protocol)
		protocol = 'http';
	
	if (obj.value.match(/^([a-z0-9-]+\.){1,}[a-z]{2,}(\/?)$/i))
		obj.value = protocol+'://'+obj.value+(!RegExp.$2.length ? '/' : '');
	else if (obj.value.match(/^([a-z0-9-]+\.){1,}[a-z]{2,}\/.+$/i))
		obj.value = protocol+'://'+obj.value;
}

// zasobnik udalosti provadenych po uzavreni stranky
function pgUnloader()
{
	for (var i = 0; i < pgUnloaderStack.length; i++)
		pgUnloaderStack[i]();
}
var pgUnloaderStack = new Array();
window.onunload = pgUnloader;

// zasobnik udalosti provadenych po natazeni stranky
function pgOnloader()
{
	for (var i = 0; i < pgOnloaderStack.length; i++)
		pgOnloaderStack[i]();
}
var pgOnloaderStack = new Array();
window.onload = pgOnloader;

// zasobnik udalosti provadenych pred uzavreni stranky
function pgOnBeforeUnload()
{
	for (var i = 0; i < pgOnBeforeUnloadStack.length; i++)
		pgOnBeforeUnloadStack[i]();
}
var pgOnBeforeUnloadStack = new Array();
window.onbeforeunload = pgOnBeforeUnload;

// dynamicky kod
function boxDynamicCode(html)
{
	var re = /<CMS:(\w+)([\u0000-\uFFFF]*?)><!-{2}([\u0000-\uFFFF]*?)-{2}><\/CMS:\1>/ig;
	html = html.replace(re, boxDynamicCodeCallback);

	//re = /<OBJECT\s+((?:.|\n)+?)>((?:.|\n)+?)<\/OBJECT>/ig;
	//html = html.replace(re, boxObjectCallback);
	return html;
}

function boxDynamicCodeCallback(all, tag, param, content)
{
	var arr = new Array();
	var params = new Object();
	var re = /(\w+)\s*=\s*("|')([^\2]*?)\2/g;
	while ((arr = re.exec(param)) != null)
		params[ arr[1].toLowerCase() ] = arr[3];
	var re = /(\w+)\s*=\s*([^ ]+)/g;
	while ((arr = re.exec(param)) != null)
	{
		if (!params[ arr[1].toLowerCase() ])
			params[ arr[1].toLowerCase() ] = arr[2];
	}

	return '<DIV CLASS="dynamic-code" CONTENTEDITABLE="false">'+Strings.dynamicCode+(params.title ? '<BR>'+params.title : '')+all+'</DIV>';
}

function boxObjectCallback(all, param, content)
{
	var arr = new Array();
	var params = new Object();
	var re = /(\w+)\s*=\s*("|')([^\2]*?)\2/g;
	while ((arr = re.exec(param)) != null)
		params[ arr[1].toLowerCase() ] = arr[3];
	var re = /(\w+)\s*=\s*([^"' ]+)/g;
	while ((arr = re.exec(param)) != null)
	{
		if (!params[ arr[1].toLowerCase() ])
			params[ arr[1].toLowerCase() ] = arr[2];
	}
	var name = Strings.htmlObject;
	if (params.classid != undefined)
	{
		switch (params.classid)
		{
			case 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000':
			{
				name = 'Flash';
				break;
			}
		}
	}
	var width = params.width ? 'WIDTH: '+params.width+(params.width.indexOf('%') == -1 ? 'px' : '%') : 'WIDTH: 100%';
	var height = params.height ? 'HEIGHT: '+params.height+(params.height.indexOf('%') == -1 ? 'px' : '%') : '';
	return '<DIV CLASS="dynamic-code" CONTENTEDITABLE="false" style="'+width+';'+height+'">'+name+(params.title ? '<BR>'+params.title : '')+'<!--'+all+'--></DIV>';
}

function unboxDynamicCode(html)
{
//	html = html.replace(/<DIV CLASS="?dynamic-code"?[^>]*>(?:.|\n)*?<!--(<OBJECT\s[^>]*>(?:.|\n)*?<\/OBJECT>)-->(?:.|\n)*?<\/DIV>/ig, '$1');
	return html.indexOf('dynamic-code') != -1 ? html.replace(/<DIV CLASS="?dynamic-code"?[^>]*>[\u0000-\uFFFF]*?(<CMS:(\w+)[^>]*><!--[\u0000-\uFFFF]*?--><\/CMS:\2>)[\u0000-\uFFFF]*?<\/DIV>/ig, '$1') : html;
}

var tabs = new Object;
function tabSwitch(tab, name, id)
{
	var old = tabs[name];
	if (old)
	{
		old.block.style.display = 'none';
		old.tab.className = 'item';
	}
	tabs[name] = {'block': document.all.item('Tab'+name+id), 'tab': tab};
	tabs[name].block.style.display = 'block';
	tabs[name].tab.className = 'item selected';
	tabs[name].active = id;
}
function tabSwitch2(name, id)
{
	var old = tabs[name];
	if (old)
	{
		old.block.style.display = 'none';
		old.tab.className = 'item';
	}
	tabs[name] = {'block': document.all.item('Tab'+name+id), 'tab': document.all.item('Tab'+name+id+'Tab')};
	tabs[name].block.style.display = 'block';
	tabs[name].tab.className = 'item selected';
	tabs[name].active = id;
}
function tabCopyLang(tabName, elmSrc, elmDst)
{
	var tab = tabs[tabName];
	if (!tab)
		return;

	if (elmDst)
	{
		var elm = tab.block.all.item(elmSrc);
		if (elm)
		{
			for (var i = 0; i < elmDst.length; i++)
			{
				try
				{
					document.all.item(elmDst[i]).value = elm.value;
				}
				catch (e) {}
			}
		}
	}
	else
	{
		var elm = tab.block.all.item(elmSrc);
		var elms = document.all.item(elmSrc);
		if (elm && elms)
		{
			for (var i = 0; i < elms.length; i++)
				elms[i].value = elm.value;
		}
	}
}

// konverze znakovych sad
function toAscii(str)
{
	var newStr = '';
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.charAt(i);
		var pos = AsciiTableFrom.indexOf(ch);
		if (pos >= 0)
			newStr += AsciiTableTo.substr(pos, 1);
		else
			newStr += ch;
	}
	return newStr;
}

// skryje vsechny podpolozky
function hideChildren(parent, disable, unset)
{
	if (!parent)
		return;
	
	if (parent.children)
	{
		for (var i = 0; i < parent.children.length; i++)
		{
			if (parent.children[i].children)
				hideChildren(parent.children[i], disable, unset);
		}
	}
	parent.style.display = 'none';
	if (disable)
		parent.disabled = true;
	if (unset && parent.tagName != 'OPTION')
		parent.value = '';
}

// zobrazi vsechny podpolozky
function showChildren(parent, disable)
{
	if (!parent)
		return;
	
	if (parent.children)
	{
		for (var i = 0; i < parent.children.length; i++)
		{
			if (parent.children[i].children)
				showChildren(parent.children[i], disable);
		}
	}
	parent.style.display = '';
	if (disable)
		parent.disabled = false;
}

// automaticke doplneni
function inpAutocomplete(elm, names)
{
	if (elm.value == '' || event.keyCode < 31 || '46;37;38;39;40;33;34;35;36;45;'.indexOf(event.keyCode+';') != -1)
		return;
	
	for (var i = 0; i < names.length; i++)
	{
		if (names[i].indexOf(elm.value) == 0)
		{
			var src = elm.value;
			elm.value = names[i];
			var rng = elm.createTextRange();
			rng.moveStart('character', src.length);
			rng.select();
		}
	}
}

// zmena zobrazeni
function switchDisplay(id)
{
	var on = document.all.item(id+'On');
	var off = document.all.item(id+'Off');
	var img = event.srcElement;
	if (on.style.display == 'none')
	{
		on.style.display = 'block';
		off.style.display = 'none';
		img.src = img.src.replace(/plus/, 'minus');
		document.cookie = 'CmsSwitchDisplayMode=1';
	}
	else
	{
		on.style.display = 'none';
		off.style.display = 'block';
		img.src = img.src.replace(/minus/, 'plus');
		document.cookie = 'CmsSwitchDisplayMode=2';
	}
	document.cookie = 'CmsSwitchDisplayID='+id;
	document.cookie = 'CmsSwitchDisplayQuery='+escape(document.location.search.substr(1));
}

// zmena zobrazeni radky listu
function switchDisplayRow(img)
{
	var tr = img.parentElement.parentElement.nextSibling;
	if (tr.style.display == 'none')
	{
		showChildren(tr);
		img.src = img.src.replace(/plus/, 'minus');
	}
	else
	{
		hideChildren(tr);
		img.src = img.src.replace(/minus/, 'plus');
	}
}

// zvyrazni HTML syntaxi
function htmlSyntax(html)
{
	html = html.replace(new RegExp('(<SCRIP'+'T[^>]*>)((?:.|\r\n|\n)*?)(</SCRIP'+'T>)', 'gi'), '$1__LT__SPAN class="html-js"__GT__$1__LT__/SPAN__GT__$2');
	html = html.replace(/&(\w+);/g, '__LT__SPAN class="html-entity"__GT__&amp;$1;__LT__/SPAN__GT__');
	html = html.replace(/<(\/?)([\w:]+)([^>]*)>/g, htmlSyntaxCallback);
	html = html.replace(/<!--((?:.|\r\n|\n)*?)-->/g, '<SPAN class="html-comment">&lt;!--$1--&gt;</SPAN>');
	html = html.replace(/\r?\n/g, '<BR>');
	html = html.replace(/\t/g, '&nbsp;&nbsp;&nbsp;');
	html = html.replace(/__LT__/g, '<');
	html = html.replace(/__GT__/g, '>');
	return html;
}

function htmlSyntaxCallback(all, close, tag, param)
{
	if (param.length)
	{
		param = param.replace(/__LT__SPAN.+?__GT__|__LT__\/SPAN__GT__/g, '');
		param = param.replace(/&amp;/g, '&');
		param = param.replace(/(\w+)=("|')([^\2]*?)\2/g, '<SPAN class="html-attrib">$1</SPAN>=<SPAN class="html-value">$2$3$2</SPAN>');
		param = param.replace(/(\s\w+)=([^"'\s]+)/g, '<SPAN class="html-attrib">$1</SPAN>=<SPAN class="html-value">$2</SPAN>');
	}
	return '<SPAN class="html-tag">&lt;'+close+tag+(param.length ? '</SPAN>'+param+'<SPAN class="html-tag">&gt;</SPAN>' : '&gt;</SPAN>');
}

// koduje spec. HTML znaky
function htmlSpecialChars(str)
{
	return CD_INPUT(str);
}
// konverze
function CD_INPUT(str)
{
	return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
}

function CD_TEXT(str)
{
	return str.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br>');
}

function CD_JS(str)
{
	return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/'/g, '\\\'');
}

function focusFirstElement()
{
	if (!document.forms(0))
		return;
	
	var form = document.forms(0);
	for (var i = 0; i < form.elements.length; i++)
	{
		var elm = form.elements(i);
		try
		{
			elm.focus();
			break;
		}
		catch (e) {}
	}
}

function zeroPad(str, num)
{
	if (!num)
		num = 2;
	
	str = str.toString();
	return '00000000000000000000000000000000'.substr(0, num - str.length)+str;
}

function generatePassword(easy)
{
	var firstChars = 'BCDFGHJKLMNPQRSTVXZ';
	var oddChars = 'aeiou';
	var oddCharsMax = oddChars.length - 1;
	var evenChars = 'bcdfghjklmnpqrstvxz';
	var evenCharsMax = evenChars.length - 1;
	var l = 1;
	var password = '';
	
	if (!easy)
	{
		password = firstChars.substr(randomBetween(0, firstChars.length - 1), 1);
		l = 2;
	}
	
	while (1)
	{
		if (l <= 5)
		{
			if (l % 2 == 0)
				password += oddChars.substr(randomBetween(0, oddCharsMax), 1);
			else
				password += evenChars.substr(randomBetween(0, evenCharsMax), 1);
		}
		else
		{
			password += randomBetween(easy ? 1 : 100, easy ? 9 : 999).toString();
			break;
		}
		l++;
	}
	return password;
}

function randomBetween(from, to)
{
	do
	{
		var r = Math.round(Math.random() * to);
	}
	while (r < from || r > to);
	
	return r;
}

function inpDisable(obj)
{
	obj.disabled = true;
	obj.className += ' disabled';
}

function inpEnable(obj)
{
	obj.disabled = false;
	obj.className = obj.className.replace(/( ?disabled)+/, '');
}

// Dekoduje e-mail chraneny proti spamu 
function AntiSpamDecodeEmail(email, label)
{
	var decodedData = {'email':'', 'label':''};
	var encodedData = {'email':email, 'label':label};
	
	for(key in encodedData)
	{
		var k = 0;
		var Char = null;			
		
		var value = encodedData[key];
		
		for(i = 0; i < value.length; i++)
		{
			Char = value.charAt(i);
			CharIdx = AntiSpamChars.indexOf(Char);
			
			k = k > 4 ? 0 : k;
			
			switch(k)
			{
				case 0: CharIdx -= AntiSpamChars.indexOf('V'); break;
				case 1: CharIdx -= AntiSpamChars.indexOf('i'); break;
				case 2: CharIdx -= AntiSpamChars.indexOf('z'); break;
				case 3: CharIdx -= AntiSpamChars.indexOf('u'); break;
				case 4: CharIdx -= AntiSpamChars.indexOf('s'); break;
			}	
			
			k++;
			
			CharIdx = CharIdx < 0 ? AntiSpamChars.length+CharIdx : CharIdx;
				
			decodedData[key] += AntiSpamChars.charAt(CharIdx);
		}		
		decodedData[key] = decodeURIComponent(decodedData[key]);
	}
		
	document.write('<a href="mailto:'+decodedData['email']+'">'+decodedData['label']+'</a>');
}
