var i, thisItem, thisLink;
var agent  = navigator.userAgent.toLowerCase();

function fixTransparency (code) {
	var searchStr = 'TYPE="application/x-shockwave-flash"';
	var re = new RegExp(searchStr, "gi");
	code = code.replace(re, searchStr + ' wmode="transparent"');
	//alert (code);
	return (code);
}

function fixJS (code) {
	var searchStr = "<PARAM[^>]+>";
	var re = new RegExp(searchStr, "gi");
	code = code.replace(re, '');
	//alert (code);
	return (code);
}

// menu - zobraz
function menuShowSub () {
	if (thisItem && thisLink) {
		thisItem.style.visibility = 'hidden';
		thisLink.className = 'nula';
	}

	if (this.getElementsByTagName('ul').length > 0) {
		this.getElementsByTagName('a')[0].className = 'nula selected';
		for (i = 0 ; i < this.getElementsByTagName('ul').length ; i++) {
			this.getElementsByTagName('ul')[i].style.visibility = 'visible';
		}
	}
}

// menu - skryj
function menuHideSub () {
	if (this.getElementsByTagName('ul').length > 0) {
		this.getElementsByTagName('a')[0].className = 'nula';
		for (i = 0 ; i < this.getElementsByTagName('ul').length ; i++) {
			this.getElementsByTagName('ul')[i].style.visibility = 'hidden';
		}
	}
	
	if (thisItem && thisLink) {
		thisItem.style.visibility = 'visible';
		thisLink.className = 'nula selected';
	}
}

// menu - inicializace
function menuInit (id, visible) {
	var thisMenu = myGet(id);
	thisItem = myGet('menu_top_' + visible);
	thisLink = myGet('menu_top_' + visible + '_link');

	if (thisMenu && thisMenu.getElementsByTagName('ul').length > 0){
		if (thisMenu.getElementsByTagName('ul').length > 0) {
			for (i = 0 ; i < thisMenu.getElementsByTagName('ul').length ; i++) {
				if (i != visible) {
					thisMenu.getElementsByTagName('ul')[i].style.visibility = 'hidden'; 
				}
			}
		}
	
		var li = thisMenu.firstChild;
		while (li) {
			li.onmouseover = menuShowSub;
			li.onmouseout  = menuHideSub;
			li = li.nextSibling;
		}
	}
}

// oblibene
function AddFavorites () {
	if (agent.indexOf("msie") != -1) {
		window.external.AddFavorite('http://www.golias.cz', 'GOLIAS.cz, Váš rádce pro nákup spotřební elektroniky')
	}
}

// shop
function CountShop (id, cenakc) {
	var pocet = myGet(id);
	var cena = myGet('cena');
	var cena_1 = myGet('cena_kozoroh_1');
	var cena_2 = myGet('cena_bobby');

	if (pocet && cena && cena_1 && cena_2) {
		kusu = pocet.selectedIndex;
		if (id == "kozoroh_1") {
			cena_1.value = cenakc * kusu
		} else if (id == "bobby") {
			cena_2.value = cenakc * kusu
		}
		cena.innerHTML = parseInt(cena_1.value) + parseInt(cena_2.value);
	}
}

// objednavani casopisu
function ShowKusu (id, cenakc) {
	var kusu = myGet('kusu_' + id);

	if (kusu) {
		if (kusu.className == "hidden") {
			kusu.className = "visible";
			CountCena (id, cenakc);
		} else {
			kusu.className = "hidden";
			CountCena (id, 0);
		}
	}
}

// objednavani casopisu
function CountCena (id, cenakc) {
	var pocet = myGet('pocet_' + id);
	var cena = myGet('cena_' + id);

	if (pocet && cena) {
		kusu = pocet.selectedIndex + 1;
		cena.innerHTML = cenakc * kusu;
	}
}

// listování archivem
function list_archiv (c) {
	var form = myGet('archiv');
	
	if (form) {
		form.seq.value = c;
		form.submit();
	}
}

// ziskani elementu
function myGet (name) {
	if (document.getElementById)
		return document.getElementById(name);
	else if (document.all)
		return document.all(name);
	else
		return null;
}