function popupWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=320,height=240,screenX=150,screenY=150,top=150,left=150');
}

function TextWindow(url, w, h) {
  window.open(url,'TextWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=' + w + ',height=' + h + ',screenX=150,screenY=150,top=150,left=150');
}


function tree_zmena(objLI, objIMG){
	objLI = document.getElementById(objLI);
	objIMG = document.getElementById(objIMG);
	if (objIMG.className == 'plus') {
		objIMG.className = 'minus';
		objLI.style.display = 'block';
	} else {
		objIMG.className = 'plus'
		objLI.style.display = 'none';
	}
}

function vyrobce(formular){
	window.location.href = document.form2.search.options[formular.selectedIndex].value;
}

function popupCalc(url) {
	window.open(url,'popupCalc','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=600,height=500,screenX=100,screenY=100,top=100,left=100');
}

function popupSplatky(url) {
	window.open(url,'popupSplatky','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=500,screenX=50,screenY=50,top=50,left=50');
}


var request = null;

function createRequest(){
	try{
		request = new XMLHttpRequest();
	}catch (trymicrosoft){
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (othermicrosoft){
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (failed){
				request = null;
			}
		}
	}
	if (request == null){
		alert("Váš prohlížeč nepodporuje technologii AJAX!");
	}
}

function setHodnoceni(hod, produkt){
	var url = "/hodnoceni-hlas.php?hod=" + hod + "&id=" + produkt;
	url = url + "&time=" + new Date().getTime();
	createRequest();
	request.open("GET", url, true);
	request.onreadystatechange = updHodnoceni;
	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=Windows-1250');
	request.send(null);
}

function updHodnoceni(){
	if (request.readyState == 4){
		if(request.status == 200) {
			var html = request.responseText;
			document.getElementById("hodnoceni").innerHTML = html;
		}
	}
}


function setCena(id){
	var url = "/changecena.php?id=" + id;
	url = url + "&time=" + new Date().getTime();
	createRequest();
	request.open("GET", url, true);
	request.onreadystatechange = updCena;
	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=Windows-1250');
	request.send(null);
}

function updCena(){
	if (request.readyState == 4){
		if(request.status == 200) {
			var html = request.responseText;
			if (html != '')	{
				var cena = html.split("|");
				document.getElementById("cena").innerHTML = cena[0];
				document.getElementById("cenabezdph").innerHTML = cena[1];
			}
		}
	}
}


function closepopup(){
	var obj = document.getElementById('zoom');
	obj.style.display = 'none';
	var bigimg = document.getElementById('zoomimg');
	bigimg.src = '/images/loading.gif';
}

function zoompopupWindow(img, w, h){
	var scrWidth = document.body.clientWidth;
	var scrHeight = document.body.clientHeight + 35;
	var brWidth = document.documentElement.clientWidth;
	var brHeight = document.documentElement.clientHeight;
	if (scrHeight < brHeight) scrHeight = brHeight;

	var zoom = document.getElementById('zoom');
	zoom.style.width = scrWidth + 'px';
	zoom.style.height = scrHeight + 'px';

	var bigimg = document.getElementById('zoomimg');
	bigimg.src = img;

	var div = document.getElementById('zoomdiv');
	div.style.width = w + 'px';
	div.style.height = (h + 20) + 'px';

	var obj = document.getElementById('zoom');
	obj.style.display = 'block';

	if (typeof(window.pageXOffset) == 'number'){
		var scrollX = window.pageXOffset;
		var scrollY = window.pageYOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		var scrollX = document.body.scrollLeft;
		var scrollY = document.body.scrollTop;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		var scrollX = document.documentElement.scrollLeft;
		var scrollY = document.documentElement.scrollTop;
	}
	if (typeof(scrollX) != 'number') scrollX = 0;
	if (typeof(scrollY) != 'number') scrollY = 0;

	var x = (brWidth - div.offsetWidth) / 2;
	var y = (brHeight - div.offsetHeight) / 2;
	if (x < 0) x = 0;
	if (y < 0) y = 0;

	div.style.left = scrollX + x + 'px';
	div.style.top = scrollY + y + 'px';
}

function addzoom(){
	document.getElementById('zoom-block').innerHTML =
	'<div id="zoom" onclick="closepopup(); return false;">' +
	'<div id="zoomdiv" class="detail">' +
	'<img id="zoomimg" src="/images/loading.gif" alt="loading" />' +
	'<div class="close"><a href="#" onclick="closepopup(); return false;">Zavřít</a></div>' +
	'</div>' +
	'</div>';
}

function addzoom18(){
	document.getElementById('zoom-block').innerHTML =
	'<div id="zoom">' +
	'<div id="zoomdiv">' +
	'<img id="zoomimg" src="/images/loading.gif" />' +
	'<div class="text">' +
	'<h4>Upozornění!</h4>' +
	'<p><strong>Chystáte se vstoupit na stránky obsahující materiály s erotickou nebo sexuálně orientovanou tématikou.</strong></p>' +
	'<p>Jsem dospělý ve věku 18 let nebo starší.</p>' +
	'<p>Sexuálně orientované materiály mne neurážejí, nepohoršují ani mne nijak nohrožují a na tyto stránky vstupuji dobrovolně.</p>' +
	'<p>Neposkytnu ani svým chováním přímo či nepřímo neumožním přístup k obsahu těchto stránek osobám mladším 18 let.</p>' +
	'<a href="#" onclick="closepopup18(); return false;" class="svstup" title="Vstoupit na stránky"><img src="/images/18-vstup.gif" width="160" height="50" alt="Vstoupit na stránky" /></a>' +
	'<a href="http://www.google.com" class="odejit" title="Opustit stránky"><img src="/images/18-odejit.gif" width="160" height="50" alt="Opustit stránky" /></a>' +
	'</div>' +
	'</div>' +
	'</div>';
	zoompopupWindow('/images/18.gif', 580, 290);
}

function closepopup18(){
	addzoom();
	closepopup();
	request = null;
	createRequest();
	request.open("GET", '/vstup18.php', true);
	request.send(null);
}


var casovac = 0;
var akce_pos = 1;
var akce_oldpos = 0;

function akce(n){
	if (n > 0) {		akce_stop();
		akce_pos = n;
	}

	if (akce_oldpos > 0) document.getElementById(String('akce_list_' + akce_oldpos)).className = '';
	akce_oldpos = akce_pos;
	document.getElementById(String('akce_list_' + akce_pos)).className = 'active';

    var img = akce_banner[akce_pos][0];
    var url = akce_banner[akce_pos][1];
    var title = akce_banner[akce_pos][2];
    var flash = akce_banner[akce_pos][3];

	if (flash == 1){		document.getElementById('flash_bg').innerHTML = img;
		document.getElementById('flash_bg').style.display = 'block';
		document.getElementById('akce_bg').style.display = 'none';
	} else {
		document.getElementById('flash_bg').style.display = 'none';
		document.getElementById('akce_bg').style.display = 'block';
	    document.getElementById('akce_img').style.background = 'url(' + img + ') no-repeat';
    	document.getElementById('akce_url').href = url;
	    document.getElementById('akce_url').title = title;
    }

	akce_pos = akce_pos + 1;
	if (akce_pos > akce_banner.length - 1) akce_pos = 1;
	if (n > 0) akce_start();
}

function akce_start(){
	if (casovac == 0) casovac = setInterval("akce(0)", 5000);
}

function akce_stop(){
	if (casovac > 0) {		clearInterval(casovac);
		casovac = 0;
	}
}


function box_show(objname){
	var obj = document.getElementById(objname);
	if ((obj.style.display == 'block') || (obj.style.display == '')){
		obj.style.display = 'none';
		var stav = 1;
	} else {
		obj.style.display = 'block';
		var stav = 0;
	}

	var url = "/setshowbox.php?obj=" + objname + "&stav=" + stav + "&time=" + new Date().getTime();
	createRequest();
	request.open("GET", url, true);
	request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=Windows-1250');
	request.send(null);
}


function setmnozstvi(objname, zmena){
	var obj = document.getElementById(objname);
	var pocet = (obj.value * 1);
	pocet = pocet + zmena;
	if (pocet <= 0) pocet = 1;
	if (pocet > 100000) pocet = 100000;
	obj.value = pocet;
}
