var items  = 0;var pieces = 0;var money  = 0;var vyberOrigin;var personOrgFee = 80;var lastPiecesValue;onload = initfunction init() {	vyberOrigin = document.getElementById('vyber').innerHTML;	if (screen.width < 1024) { 		document.getElementById('krok-3-offer').style.display = 'none';		for (n=1;n<=3;n++) document.getElementById('footer-'+n).style.display = 'none';	}	writeMoney();}function addProduct(id) {	if (!document.getElementById('p'+id)) {		var item  = '<div class="l"><div class="pname">'+Produkty[id][1]+'</div><div class="links">›&nbsp;<a href="#" onclick="openDetail('+id+')">Detail</a></div></div>\n';		item += '<div class="r"><div>\n';		item += '	<p>Počet&nbsp;ks</p>\n';		item += '	<input type="text" id="p'+id+'pieces" name="p'+id+'pieces" value="0" maxlength="2" onfocus="lastPiecesValue = this.value" onchange="addPiece('+id+', parseInt(this.value - lastPiecesValue), false)">\n';		item += '	<a href="#" onclick="addPiece('+id+', -1, true)"><img src="/img/u/deti/kalkulacka/btn_smazat.gif" alt="Smazat" width="14" height="14" border="0"></a>\n';		item += '</div></div>\n';		item += '<div class="clear">&nbsp;</div>\n';		var eVyber 		= document.getElementById('vyber');		var eProduct 	= document.createElement('div');		if (eVyber && eProduct) {			eProduct.id = 'p'+id;			eProduct.innerHTML = item;			eProduct.className = 'item';			if (items == 0) eVyber.innerHTML = '';			if (eVyber.appendChild(eProduct)) items++;		}	}	addPiece(id, 1, true);}function removeProduct(id) {	var eVyber 		= document.getElementById('vyber');	var eProduct 	= document.getElementById('p'+id);	if (eVyber && eProduct) {		try {			eVyber.removeChild(eProduct);			if (items - 1 == 0) eVyber.innerHTML = vyberOrigin;		} catch(e) {			return false;		}		items--;		return true;	}}function removeAllProduct() {	items  = 0;	pieces = 0;	money  = 0;	writeMoney();	var eVyber = document.getElementById('vyber');	if (eVyber) eVyber.innerHTML = vyberOrigin;}function getMoney(id, num) {	money = money + num * Produkty[id][2];	writeMoney();}function writeMoney() {	var orgFee = 0;	//	var ePiecesSum = document.getElementById('pieces-sum');//	if (ePiecesSum) ePiecesSum.innerHTML = indentNum(pieces) + '&nbsp;ks';	var eChildNum = document.getElementById('childNum');	var eOrgFee   = document.getElementById('orgFee');	if (eChildNum && eOrgFee) {		if (parseInt(eChildNum.value) < 0) eChildNum.value = 0;		if (isNaN(eChildNum.value)) eChildNum.value = 1;		orgFee = eChildNum.value * personOrgFee;		eOrgFee.innerHTML = indentNum(orgFee) + '&nbsp;Kč';	}	if (money < 0) money = 0;	var eMenuPrice = document.getElementById('menuPrice-step2');	if (eMenuPrice) eMenuPrice.innerHTML = indentNum(money) + '&nbsp;Kč';	var eMenuPrice = document.getElementById('menuPrice-step3');	if (eMenuPrice) eMenuPrice.innerHTML = indentNum(money) + '&nbsp;Kč';	var eTotalPrice = document.getElementById('price-sum');	if (eTotalPrice) eTotalPrice.innerHTML = indentNum(parseInt(orgFee + money)) + '&nbsp;Kč';}function addPiece(id, pCountDifference, incPValue) {	var pRealDifference;	var ePieces = document.getElementById('p'+id+'pieces');	if (ePieces && parseInt(ePieces.value) >= 0) {		var tmpPiecesValue = (incPValue) ? ePieces.value : lastPiecesValue;		if (pCountDifference > 0 && parseInt(tmpPiecesValue) >= 0 && parseInt(tmpPiecesValue) < 99) {			pieces += pRealDifference = (parseInt(tmpPiecesValue) + pCountDifference > 99) ? parseInt(tmpPiecesValue) - 99 : pCountDifference;			if (incPValue) ePieces.value = parseInt(tmpPiecesValue) + pRealDifference;			getMoney(id, pRealDifference);		} else if (pCountDifference < 0 && parseInt(tmpPiecesValue) > 1 && ePieces.value > 0) {			pieces += pRealDifference = (parseInt(tmpPiecesValue) + pCountDifference < 1) ? parseInt(tmpPiecesValue) - 1 : pCountDifference;			if (incPValue) ePieces.value = parseInt(tmpPiecesValue) + pRealDifference;			getMoney(id, pRealDifference);		} else if (pCountDifference < 0) {			if (removeProduct(id)) {				pieces += -1;				getMoney(id, pCountDifference);			}		}		if (ePieces.value) lastPiecesValue = ePieces.value;	} else if (ePieces) {		pieces += pRealDifference = 0 - parseInt(lastPiecesValue);		ePieces.value = 0;		if (removeProduct(id)) pieces += -1;		getMoney(id, pRealDifference);	}}function openDetail(id) {	var html = '	<img name="produkt-img" src="" alt="" width="214" height="132" border="0"><br>\n';	html += '	<div class="text">\n';	html += '		<div id="produkt" class="pname"></div>\n';	html += '		<div id="p-slozeni">\n';	if (Produkty[id][3]) {		html += '			<div class="popis2">Složení:</div>\n';		html += '			<div id="slozeni" class="indent-bottom"></div>\n';	}	html += '			<div class="l"><div class="popis2">Cena: <span>'+Produkty[id][2]+' Kč</span></div></div>\n';	html += '			<div class="r"><div class="close"><a href="#" onclick="closeDetail()"><img src="/img/u/deti/kalkulacka/btn_smazat.gif" alt="Zavřít" width="14" height="14" border="0"></a></div></div>\n';	html += '			<div class="clear">&nbsp;</div>\n';	html += '		</div>\n';	html += '	</div>\n';	var eDetail		= document.getElementById('detail');	var eContainer	= document.createElement('div');	if (eDetail && eContainer) {		eContainer.innerHTML = html;		eContainer.className = 'cont';		try {			eDetail.innerHTML = '';			eDetail.appendChild(eContainer);		} catch(e) {}	}	document.images["produkt-img"].src = "/img/u/deti/kalkulacka/produkty/prod_"+Produkty[id][0]+".jpg";	obj("produkt").innerHTML = Produkty[id][1];	if (Produkty[id][3]) obj("slozeni").innerHTML = Produkty[id][3];	obj("detail").style.visibility = "visible";}function closeDetail() {	obj("detail").style.visibility = "hidden";	obj("detail").innerHTML = '';}function indentNum(num) {	var num = new String(num);	var numBackup = num;	var temp = new String;	for (n=num.length; n>0; n--)		// vrati invertni cislo (1234 => 4321)		temp += num.substring(n-1,n);	regexp = /\d{3}/g;	if (temp.replace(regexp,"$& ").indexOf('&') == -1) { // osetreni pro IE 5.0 - nechape vyraz '$&'		temp = temp.replace(regexp,"$& "); 	// vlozi za kazdy treti znak mezeru		var num = new String;		for (n=temp.length; n>0; n--) 		// vrati invertni cislo (432 1 => 1 234)			num += temp.substring(n-1,n);	} else num = numBackup;	if (num == '') num = 0;	return num;}
