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;
}

var zvolenaFotka = '1';

function ABGalerie(obj, soubor) {
	zvolenaFotka = soubor;	
	var cil = GetTag("imgDetail");
	var cil2 = GetTag("lupaDetail");
	var i = 1;
	while (GetTag("aFotka" + i) != null) {
		GetTag("aFotka" + i).className = '';
		GetTag("aFotka" + i + "Img").className = '';
		i ++;
	}
	GetTag(obj.id + "Img").className = 'iAktivni';
	cil.src = obj.href;
	cil2.href = ReplaceString(obj.href, "f.jpg", "-velkyf.jpg");
	return false;
}

function ABGalerieSipka(pole, smer) {
	var cil = GetTag("imgDetail");
	var cil2 = GetTag("lupaDetail");
	var aktualniCesta = ReplaceString(ReplaceString(ReplaceString(ReplaceString(cil.src,"http://localhost", ""), "http://kuchyneostrava.cz", ""), "http://www.kuchyneostrava.cz", ""), "http://data.marf.cz", "");
	var aktualniPozice = 1;
	//alert(aktualniCesta);
	for (var j=1; j < pole.length; j++) {
		if (pole[j] == aktualniCesta) {
			aktualniPozice = j;
			break;
		}
	}
	aktualniPozice = aktualniPozice + smer;
	if (aktualniPozice == pole.length) aktualniPozice = 1;
	else if (aktualniPozice == 0) aktualniPozice = pole.length - 1;
	cil.src = pole[aktualniPozice];
	cil2.href = ReplaceString(pole[aktualniPozice], "f.jpg", "-velkyf.jpg");
	//alert(pole[aktualniPozice]);
	var i = 1;
	while (GetTag("aFotka" + i) != null) {
		GetTag("aFotka" + i).className = '';
		GetTag("aFotka" + i + "Img").className = '';
		i ++;
	}
	GetTag('aFotka'+aktualniPozice+"Img").className = 'iAktivni';
	return false;
}

var zvolenaDvirka = '53';

function ABDvirka(obj, soubor) {
	zvolenaDvirka = soubor;
	var cil = GetTag("imgDetail");
	var cilPopis = GetTag("popisDetail");
	var i = 1;
	while (GetTag("aDvirka" + i) != null) {
		GetTag("aDvirka" + i).className = '';
		i ++;
	}
	obj.className = 'dvirkaAktivni';
	cil.src = obj.href;
	cilPopis.innerHTML = obj.title;
	return false;
}

function ObarviDvirka(barva, zvolenaDvirka, prefix) {
	var cil = GetTag("imgDetail");
	cil.src = prefix + 'katalog-obrazku/kuchyne/dvirka/' + zvolenaDvirka + '/' + barva + '.jpg';
	return false;
}

function Menu(obj, zobraz) {
	if (povolFunkci) {
		var cil = GetTag(obj);
		if (zobraz == 1) cil.style.visibility = 'visible';
		else cil.style.visibility = 'hidden';
		return false;
	}
}