
function MM_preloadImages() { 		//	v3.0
	var d = document;
	if (d.images) {
		if (!d.MM_p) d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for (i = 0; i < a.length; i++) {
			if (a[i].indexOf("#")  != 0) {
				d.MM_p[j]	= new Image;
				d.MM_p[j++].src	= a[i];
			}
		}
	}
}

function isblank(s) { 
	for (var i = 0; i < s.length; i++) { 
		var c = s.charAt(i); 
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false; 
	} 
	return true; 
}

function KontrolaHledani() {
	if (isblank(document.getElementById('eshledat').value)) return false; else return true;
}

function OdeslatHledani() {
	if (KontrolaHledani() == true) {
		var allforms = document.getElementsByTagName('form');
		for (var i = 0; i < allforms.length; i++){ 
			if (allforms[i].name == 'hledani') allforms[i].submit();
		}
	}
}

function KontrolaOdeslani(typ) {
	var kont1	= 1;
	var jmheslo	= ["esusername", "esuserpass"];
	if (typ != 4) {
		for (var i = 0; i < jmheslo.length; i++) { 
			if (isblank(document.getElementById(jmheslo[i]).value))	kont1 = 0;
		}
	}
	if (typ > 1) {
		var kont2	= 1;
		var udaje	= ["esjmeno", "esulice", "escislo", "esmesto", "espsc", "estelefon", "esemail"];
		for (var i = 0; i < udaje.length; i++) { 
			if (isblank(document.getElementById(udaje[i]).value))	kont2 = 0;
		}
	}
	if (typ == 1) {	if (kont1 > 0)				return true; else return false;	}
	if (typ == 2) {	if ((kont1 + kont2) > 0)	return true; else return false;	}
	if (typ == 3) {	if ((kont1 + kont2) > 1)	return true; else return false;	}
	if (typ == 4) {	if (kont2 > 0)				return true; else return false;	}
}

function OdeslatKosik(act) {
	if (act == 'p') var kontobj = KontrolaOdeslani(1);
	if (act == 'u') var kontobj = KontrolaOdeslani(4);
	if (act == 'o') {
		var kontobj = KontrolaOdeslani(2);
		if (KontrolaOdeslani(3) == true) document.getElementById('esaction').value = "regobj";
	}
	if (act == 'r') var kontobj = KontrolaOdeslani(3);
	if (act == 'l') var kontobj = true;
	
	if (kontobj == true) {
		var allforms = document.getElementsByTagName('form');
		for (var i = 0; i < allforms.length; i++){ 
			if (allforms[i].name == 'objednavka') allforms[i].submit();
		}
	}
}

function PrihlastitPB() {
	var kont = true;	var jmheslo	= ["esusernamepb", "esuserpasspb"];
	for (var i = 0; i < jmheslo.length; i++) { 
		if (isblank(document.getElementById(jmheslo[i]).value))	kont = false;
	}
	if (kont == true) {
		var allforms = document.getElementsByTagName('form');
		for (var i = 0; i < allforms.length; i++){ 
			if (allforms[i].name == 'prihlasenipb') allforms[i].submit();
		}
	}
}

function koupitVyrobek(idz) {
	var http_request = false;
	var poc = document.getElementById('ks' + idz).value;
	document.getElementById('ks' + idz).value = 1;				vzor = /^[0-9]{1,5}$/
	
	if (poc < 1 || vzor.test(poc) == false) return;
	
	var request = "&idz=" + idz + "&poc=" + poc;
	
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (eror) {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	http_request.onreadystatechange = function() { zpracujNakup(http_request, poc); };
	http_request.open('GET', 'eshop/eshop.koupit.php?' + request, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(null);
}

function zpracujNakup(http_request, poc) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			document.getElementById('eshopobsahkosiku').innerHTML = http_request.responseText;
			document.getElementById('eshopobjedtd').style.display = "";

			if (poc == 1)	alert("Výrobek byl přidán do košíku.");
			else		alert("Výrobky byly přidány do košíku.");
		}
	}
}

function zmenitNakup(idz, akce) {
	var http_request = false;
	var poc = document.getElementById('ks' + idz).value;		vzor = /^[0-9]{1,5}$/
//	document.getElementById('ks' + idz).value = 1;				
	
	if (poc < 1 || (vzor.test(poc) == false && akce != "d")) { document.getElementById('ks' + idz).value = 1; return; }
	
	var request = "&idz=" + idz + "&poc=" + poc + "&akce=" + akce + "&ajax=1";
	
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (eror) {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	http_request.onreadystatechange = function() { zpracujZmenuNakupu(http_request); };
	http_request.open('GET', 'eshop/eshop_kosik.php?' + request, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(null);
}

function zpracujZmenuNakupu(http_request) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var rozdeleno = http_request.responseText.split("###");
			if ((rozdeleno[1] == 0 || rozdeleno[1] == "") && (rozdeleno[2] == 0 || rozdeleno[2] == "" || rozdeleno[2] == "0,00")) {
				document.getElementById('eshopkosik').innerHTML = rozdeleno[0];
				document.getElementById('eshopobsahkosiku').innerHTML = (rozdeleno[2] == "" ? "0,-" : rozdeleno[2]) + " Kč";
				document.getElementById('eshopobjedtd').style.display = "none";
			} else {
				document.getElementById('eshopkosik').innerHTML = rozdeleno[0];
				document.getElementById('eshopobsahkosiku').innerHTML = rozdeleno[2] + " Kč";
				document.getElementById('eshopobjedtd').style.display = "";
			}
		}
	}
}

function OdeslatRegEmail() {
	if (isblank(document.getElementById('eszaplogemail').value) == false) {
		var allforms = document.getElementsByTagName('form');
		for (var i = 0; i < allforms.length; i++){ 
			if (allforms[i].name == 'odeslatregmail') allforms[i].submit();
		}
	}
}

function poziceL(el) {
	var x; x = el.offsetLeft; if (el.offsetParent != null)	x += poziceL(el.offsetParent); return x;
}

function poziceT(el) {
	var y; y = el.offsetTop; if (el.offsetParent != null)	y += poziceT(el.offsetParent); return y;
}

function zobrazVolby(chov) {
	skryjProfil();
	var p	= document.getElementsByTagName('body')[0];		var l = document.getElementById('volbylink');
	var im	= document.createElement('div');			im.style.position = 'absolute';
	im.id	= "volbydiv";						im.className	= "esdivvolby";							
	
	var iHTML	 = "<div style=\"padding-left: 0px;\"><img style=\"cursor: pointer;\" onclick=\"skryjVolby();\" src=\"esimages/close.jpg\" align=right alt=\"\" border=0 vspace=0 hspace=0><b style=\"cursor: pointer;\" onclick=\"skryjVolby();\">Možnosti</b></div>";
//	iHTML		+= "<div>Zobrazovat výpis jako <a href=\"?esdisp=k\">katalog</a><br>Zobrazovat výpis jako <a href=\"?esdisp=s\">seznam</a></div>";
	if (chov != 1) {
	iHTML		+= "<div>Třídit podle <a href=\"?essort=pv\">definovaného pořadí</a><br>";
	iHTML		+= "Třídit podle <a href=\"?essort=ov\">kódu vzestupně</a><br>Třídit podle <a href=\"?essort=os\">kódu sestupně</a><br>";
	iHTML		+= "Třídit podle <a href=\"?essort=nv\">názvu vzestupně</a><br>Třídit podle <a href=\"?essort=ns\">názvu sestupně</a><br>";
	iHTML		+= "Třídit podle <a href=\"?essort=cv\">ceny vzestupně</a><br>Třídit podle <a href=\"?essort=cs\">ceny sestupně</a></div>";
	}
	iHTML		+= "<div style=\"border: 0px;\">Zobrazovat <a href=\"?eszobrpocet=6\">6</a>, <a href=\"?eszobrpocet=12\">12</a>, ";
	iHTML		+= "<a href=\"?eszobrpocet=18\">18</a> produktů na stránku<br>Zobrazovat produkty <a href=\"?eszobrpocet=b\">bez omezení</a></div>";
	
	im.innerHTML	 = iHTML;			//		im.onmouseout = skryjVolby;	
	im.style.top	 = (poziceT(l) - 14) + 'px';			im.style.left	= (poziceL(l) - 12) + 'px';
	p.appendChild(im);
}

function zobrazProfil() {
	skryjVolby();
	var p	= document.getElementsByTagName('body')[0];		var l = document.getElementById('profillink');
	var im	= document.createElement('div');			im.style.position = 'absolute';
	im.id	= "profildiv";						im.className	= "esdivvolby";
	
	var iHTML	 = "<div style=\"padding-left: 0px;\"><img style=\"cursor: pointer;\" onclick=\"skryjProfil();\" src=\"esimages/close.jpg\" align=right alt=\"\" border=0 vspace=0 hspace=0><b style=\"cursor: pointer;\" onclick=\"skryjProfil();\">Můj profil</b></div>";
	iHTML		+= "<div>Změnit <a href=\"eshop-profil?estyp=h\">heslo</a><br>Změnit <a href=\"eshop-profil?estyp=u\">osobní údaje</a></div>";

	iHTML		+= "<div><a href=\"eshop-objednavky\">Objednávky</a></div>";

	iHTML		+= "<div style=\"border: 0px;\"><a href=\"eshop-prihlasit?esaction=odhl\">Odhlásit se</a></div>";
	
	im.innerHTML	 = iHTML;			//		im.onmouseout = skryjProfil;
	im.style.top	 = (poziceT(l) - 14) + 'px';			im.style.left	= (poziceL(l) - 12) + 'px';
	p.appendChild(im);
}

function skryjVolby() {
	if (document.getElementById('volbydiv') != null) {
		var p	= document.getElementsByTagName('body')[0];
		p.removeChild(document.getElementById('volbydiv'));
	}
}

function skryjProfil() {
	if (document.getElementById('profildiv') != null) {
		var p	= document.getElementsByTagName('body')[0];
		p.removeChild(document.getElementById('profildiv'));
	}
}

function nastavitKategorie(cnt, uri) {
	var arrInputs = document.getElementsByTagName('input');	var hodnota = "|";
	for(var i = 0; i < arrInputs.length; i++){
		if (arrInputs[i].type=='checkbox' && arrInputs[i].id.indexOf("omezkateg") > -1 && arrInputs[i].checked == true) {
			hodnota += "|" + arrInputs[i].value;
		}
	}
	hodnota = hodnota.replace("||", "");		if (hodnota == "|") hodnota = "x";
	if (uri.indexOf("?") > -1) hodnota = "&omezitkategorii=" + hodnota; else hodnota = "?&omezitkategorii=" + hodnota; 
	window.location = uri + hodnota;
}

function VytisknoutObjednavku(id, action){

	var scw		= window.screen.availWidth;	var sch		= window.screen.availHeight;
	var winwidth	= 700;				var winheigh	= sch;

	if (winwidth > scw) {	 winheigh = (scw / winwidth) * winheigh;	winwidth = scw; }
	if (winheigh > sch) {	 winwidth = (sch / winheigh) * winwidth;	winheigh = sch; }

	wtop = (sch / 2) - (winheigh / 2); if (wtop < 0) wtop = 0;	wleft = (scw / 2) - (winwidth / 2); if (wleft < 0) wleft = 0;

	ZobrazitDetail = window.open('eshop_soubor.php?esfileact=' + action + '&esobjid=' + id, 'OknoObjednavky', 'resizable=0, status=0, menubar=0, scrollbars=0, location=0, directories=0, width='+winwidth+', height='+winheigh+', top='+wtop+', left='+wleft);

}

function zobrazPopisPlatby(id) {
	document.getElementById('espopisplatby').innerHTML = document.getElementById('espopispldopr' + id).innerHTML; 
	document.getElementById('esdoprava').value = id;
}