function ReplaceString(ABuf, AOldStr, ANewStr) {
	var tmp = "";
	if (ABuf == null) return tmp;
	var last_index = -1;
	var idx = ABuf.indexOf(AOldStr);
	while(idx >= 0) {
		var start = (last_index >= 0) ? last_index + AOldStr.length  : 0;
		tmp += ABuf.substring(start, idx) + ANewStr;
		last_index = idx;
		idx = ABuf.indexOf(AOldStr, idx + 1);
	}
	if (last_index >= 0) tmp += ABuf.substring(last_index + AOldStr.length);
	else tmp += ABuf;
	return tmp;
}

function GetTag(AName) {
	var temp = document.getElementsByName(AName);
	var tempID = document.getElementById(AName);
	if (tempID != null) return tempID;
	else if (temp != null && temp.length > 0) return temp[0];
	else return null;
}

function CheckNumber(e) {
	if (!e) e = window.event;
	if (e.charCode != null) return (e.charCode == 0 || /\d{1,1}/.test(String.fromCharCode(e.charCode)));
	else return /\d{1,1}/.test(String.fromCharCode(e.keyCode));
}

function CheckPsc(e) {
	if (!e) e = window.event;
	if (e.charCode != null) return (e.charCode == 0 || e.charCode == 32 || /\d{1,1}/.test(String.fromCharCode(e.charCode)));
	else return /\d{1,1}/.test(String.fromCharCode(e.keyCode));
}

function CheckASCII(e) {
	if (!e) e = window.event;
	if (e.charCode != null) return (e.charCode == 0 || e.charCode == 43 || /\w|\-{1,1}/.test(String.fromCharCode(e.charCode)));
	else return /\w|\-{1,1}/.test(String.fromCharCode(e.keyCode));
}

function CheckPhone(e) {
	if (!e) e = window.event;
	if (e.charCode != null) return (e.charCode == 0 || e.charCode == 43 || /\d{1,1}/.test(String.fromCharCode(e.charCode)));
	else return /\d{1,1}/.test(String.fromCharCode(e.keyCode));
}

function ZobrazSkryjFiltr() {
	var obj = GetTag("filtr-dat");
	if (obj.style.display == "none") obj.style.display = "block";
	else obj.style.display = "none";
	return false;
}

function NastavJakoDomovskouStranku() {
	if (document.all && !window.opera) {
		this.style.behavior="url(#default#homepage)";
		this.setHomePage(document.location.href);
	} else alert("Váš prohlížeč nepodporuje automatické nastavení domovské stránky.\nZkuste CTRL + D.");
	return false;
}

function PrepocitejDelku(obj, delka, pocitadlo) {
	pocitadlo = GetTag(pocitadlo);
	pocitadlo.value = obj.value.length + " " + SklonujZnaky(obj.value.length) + ".";
}

function SklonujZnaky(cislo) {
	var strNum = new String(cislo + "");
	var strLas = strNum.substr(strNum.length - 1, 1);
	var strVyj = strNum.substr(strNum.length - 2, 2);
	if (parseInt(strVyj) >= 11 && parseInt(strVyj) <= 19) return "znaků";
	else if (!isNaN(parseInt(strLas))) {
		if (parseInt(strLas) == 0 || (parseInt(strLas) >= 5 && parseInt(strLas) <= 9)) return "znaků";
		else if (parseInt(strLas) == 1) return "znak";
		else if (parseInt(strLas) >= 2 && parseInt(strLas) <= 4) return "znaky";
		else return "znaků";
	} else return "znaků";
}

function VyskakovaciOkno(adresa, sirka, vyska) {
	if (adresa != null && adresa != "") {
		sirka = sirka != null && !isNaN(parseInt(sirka)) ? sirka : 650;
		vyska = vyska != null && !isNaN(parseInt(vyska)) ? vyska : 500;
		window.open(adresa, 'marfor  ', "width=" + sirka + ",height=" + vyska + ",toolbar=no,menubar=no,scrollbars=yes,status=no,resizable=yes,left=" + parseInt((screen.width-sirka)/2) + ",top=" + parseInt((screen.height-vyska)/2) + "").focus();
	}
	return false;
}

function HlavickaAktivni(prefix, id) {
	var pozadi_1 = new Image();
	var pozadi_2 = new Image();
	var pozadi_3 = new Image();
	var pozadi_4 = new Image();
	var pozadi_5 = new Image();
	var pozadi_6 = new Image();
	pozadi_1.src = prefix+'system/design/obrazky/pozadi-menu-1.jpg';
	pozadi_2.src = prefix+'system/design/obrazky/pozadi-menu-2.jpg';
	pozadi_3.src = prefix+'system/design/obrazky/pozadi-menu-3.jpg';
	pozadi_4.src = prefix+'system/design/obrazky/pozadi-menu-4.jpg';
	pozadi_5.src = prefix+'system/design/obrazky/pozadi-menu-5.jpg';
	pozadi_6.src = prefix+'system/design/obrazky/pozadi-menu-6.jpg';
	var src;
	switch (id) {
		case 1: src = pozadi_1.src; break;
		case 2: src = pozadi_2.src; break;
		case 3: src = pozadi_3.src; break;
		case 4: src = pozadi_4.src; break;
		case 5: src = pozadi_5.src; break;
		case 6: src = pozadi_6.src; break;
	}
	GetTag('dMenu').style.backgroundImage = 'url('+src+')';
	//GetTag('dMenu').style.backgroundImage = 'url('+prefix+'system/design/obrazky/pozadi-menu-aktivni.jpg)';
}

function HlavickaNeaktivni(prefix) {
	GetTag('dMenu').style.backgroundImage = 'url('+prefix+'system/design/obrazky/pozadi-menu.jpg)';
}

