
	var imgs=Array();
	imgs[1]=new Image();
	imgs[1].src='/images/main/top_051.gif';


	var loginD;
	var loginDt;

	function LoginView()
	{
		loginD=GO('login');
		if(!loginD) loginD=GO('login-2');
		loginD.style.display='block';

		if(loginDt) return;
		loginDt=true;
		LoginCycle(2);
	}


	function LoginCycle(px)
	{
		var w, h;

		w=px * 5.8;
		if(w > 200) w=200;
		h=px * 3;
		if(h > 106) h=106;

		loginD.style.width=w + 'px';
		loginD.style.height=h + 'px';

		if(px <= 105)
		{
			setTimeout('LoginCycle(' + ++px + ');', 14);
		}
		else
		{
			GO('login-name').focus();
		}
	}



	var M=Array();
	M['time']=30;
	M['pos']=0;

	function Menu(idm)
	{
		GO('ma-' + idm).blur();

		if(M['run'])
		{
			if(idm != M['idm'])
			{
				M['next']=idm;
			}
			return	;
		}

		M['run']=true;

		var elem=GO('mb-' + idm);
		M['idm']=idm;
		M['list']=elem.childNodes;

		if((elem.style.display != 'block') && (elem.style.display != 'list-item'))
		{
			M['mode']='block';
			elem.style.display='block';
			MenuChange(0);
		}
		else
		{
			M['mode']='none';
			MenuChange(M['list'].length - 1);
		}
	}



	function MenuChange(pos)
	{
		var i, ex;

		if(M['mode'] == 'block')
		{
			for(i=pos; i<M['list'].length; i++)
			{
				if((M['list'][i].nodeName == 'li') || (M['list'][i].nodeName == 'LI') || (M['list'][i].nodeName == 'ul') || (M['list'][i].nodeName == 'UL'))
				{
					if(M['list'][i].id.indexOf('mm-') != -1)
					{
						CCS(M['list'][i].id, 'display', 'list-item');

						if(++i < M['list'].length)
						{
							setTimeout('MenuChange(' + i + ');', M['time']);
							return;
						}
					}
				}
			}
		}
		else
		{
			for(i=pos; i>=0; i--)
			{
				if((M['list'][i].nodeName == 'li') || (M['list'][i].nodeName == 'LI') || (M['list'][i].nodeName == 'ul') || (M['list'][i].nodeName == 'UL'))
				{
					if(M['list'][i].id.indexOf('mm-') != -1)
					{
						ex=M['list'][i].id.split('-');
						if(GO('mb-' + ex[1]) && ((GO('mb-' + ex[1]).style.display == 'block') || (GO('mb-' + ex[1]).style.display == 'list-item')))
						{
							if(--i < M['list'].length)
							{
								M['temp_mode']=M['mode'];
								M['temp_list']=M['list'];
								M['temp_pos']=i;
								M['temp_id']=M['list'][++i].id;
								M['temp_idm']=M['idm'];
							}
							M['run']=false;
							Menu(ex[1]);
							return;
						}

						CCS(M['list'][i].id, 'display', 'none');

						if(--i > 0)
						{
							setTimeout('MenuChange(' + i + ');', M['time']);
							return;
						}
					}
				}
			}

			CCS('mb-' + M['idm'], 'display', 'none');
		}


		if(M['temp_list'])
		{
			M['list']=M['temp_list'];
			M['mode']=M['temp_mode'];
			M['idm']=M['temp_idm'];

			if(M['mode'] == 'block')
			{
				M['pos']=M['temp_pos'] + 1;
			}
			else
			{
				M['pos']=M['temp_pos'] - 1;
				if(M['temp_id'])
				{
					CCS(M['temp_id'], 'display', 'none');
				}
			}

			M['temp_idm']=false;
			M['temp_mode']=false;
			M['temp_list']=false;
			M['temp_pos']=false;
			M['temp_id']=false;

			setTimeout('MenuChange(' + M['pos'] + ');', M['time']);
			return;
		}

		setTimeout('MenuEnd();', 350);
	}



	function MenuEnd()
	{
		M['run']=false;

		if(M['next'])
		{
			var mid=M['next'];
			M['next']=false;
			Menu(mid);
		}
	}

/*
	function Cart(input, total, mode)
	{
		var elem, val;

		elem=GO(input);

		val=Math.abs(elem.value);

		if(val % total)
		{
			val=val + (total - (val % total));
		}

		if(mode == 2)
		{
			val-=total;
		}
		else
		{
			val+=total;
		}

		if(val < 0) val=0;

		elem.value=val;
	}
*/

	function ImgNew(i_url, i_width, i_height)
	{
		if(i_height > (screen.height - 150))
		{
			i_width+=20;
		}

		window.open(i_url, '_blank', 'width=' + (i_width + 40) + ',height=' + (i_height + 20) + ',scrollbars=1,resizable=yes');
	}



	ST=Array();
	ST['run']=Array();
	ST['direct']=Array();
	ST['alpha']=Array();
	ST['zindex']=100;

	function Store(id)
	{
		if(ST['run'][id])
		{
			ST['direct'][id]=1;
			return;
		}

		ST['run'][id]=true;
		ST['direct'][id]=1;
		ST['alpha'][id]=1;

		CCO('store-' + id, 1);
		CCS('store-' + id, 'display', 'block');
		CCS('store-' + id, 'zIndex', ST['zindex']++);

		StoreV(id);
	}



	function StoreV(id)
	{
		var t=25, t2=3000;

		CCO('store-' + id, ST['alpha'][id]);


		if(ST['direct'][id] == 1)
		{
			ST['alpha'][id]+=7;

			if(ST['alpha'][id] < 100)
			{
				setTimeout('StoreV(' + id + ');', t);
			}
			else
			{
				ST['direct'][id]=2;
				setTimeout('StoreV(' + id + ');', t2);
			}
		}
		else
		{
			ST['alpha'][id]-=4;

			if(ST['alpha'][id] > 10)
			{
				setTimeout('StoreV(' + id + ');', t);
			}
			else
			{
				CCS('store-' + id, 'display', 'none');
				ST['run'][id]=false;
			}
		}
	}



	function Dex(night, privat)
	{
		var elem;

		if(night)
		{
			if((night == 2) && GO('dex-p-2').checked)
			{
				GO('dex-p-2').checked=false;
				GO('dex-p-1').checked='checked';
			}
		}
		else
		{
			if((privat == 2) && GO('dex-n-2').checked)
			{
				GO('dex-n-1').checked=false;
				GO('dex-n-1').checked='checked';
			}
		}
	}



	function Dex2(id)
	{
		if(id > 2)
		{
			CCS('dex-21', 'display', 'none');
		}
		else
		{
			CCS('dex-21', 'display', 'block');
		}
	}



	function Deli()
	{
		CCS('deli-1', 'display', 'none');
		CCS('deli-2', 'display', 'block');
	}



	function MoveDeli()
	{
		var i

		for(i=1; i<=6; i++)
		{
			if(!GO('delimv-' + i).value)
			{
				GO('delimv-' + i).value=GO('delim-' + i).value;
			}
		}

		if(!GO('delimv-7').value)
		{
			var tit_before=GO('delima-1').value;
			var surname=GO('delima-2').value;
			var name=GO('delima-3').value;
			var tit_after=GO('delima-4').value;

			GO('delimv-7').value=(tit_before ? tit_before + ' ' : '') + surname + ' ' + name + (tit_after ? ' ' + tit_after : '');
		}
	}



	function Cokl_View()
	{
		CCS('cokl-button', 'display', 'none');
		CCS('cokl-form', 'display', 'block');
	}



	function ADM_StoreDel(url)
	{
		if(confirm('Opravdu smazat?'))
		{
			location.href=url;
		}
	}


	function DP_View()
	{
		CCS('dp-button', 'display', 'none');
		CCS('dp', 'display', 'block');
	}


	function DTH_Kraje(value)
	{
		var elem;

		if(!value) return;

		for(i=1; i<=13; i++)
		{
			if(i == value)
			{
				CCS('okresy-' + i, 'display', 'block');
			}
			else
			{
				CCS('okresy-' + i, 'display', 'none');
			}
		}
	}



	function ADM_Amd()
	{
		CCS('amd-1', 'display', 'none');
		CCS('amd-2', 'display', 'block');
	}



	function ADM_Client(client)
	{
		if(client)
		{
			GO('client-admin').value=client;
			GO('pform').submit();
		}
		else
		{
			window.open('/admin/zakaznici/seznam/select/', '_blank', 'width=990,height=650,scrollbars=1,resizable=yes');
		}
	}


	function ADM_Tymy(mode)
	{
		var elem, elem2;

		for(i=1; i<=4; i++)
		{
			elem=GO('tymy-hide-' + mode + '-' + i);
			elem2=GO('tymy-hide-' + ((mode == 1) ? 2 : 1) + '-' + i);

			if(elem || elem2)
			{
				//alert('tymy-hide-' + ((mode == 1) ? 2 : 1) + '-' + i);
				if(elem) CCS('tymy-hide-' + mode + '-' + i, 'display', 'none');
				if(elem2) CCS('tymy-hide-' + ((mode == 1) ? 2 : 1) + '-' + i, 'display', 'table-row');
			}
		}
	}



	function CartPM(cid, mode, adm)
	{
		var elem, val, val2;

		elem=GO('cart-total-' + cid);

		val=Math.abs(elem.value);

		if(mode == 2)
		{
			if(val == CP['total'][cid])
			{
				return;
			}

			if(val % CP['quantity'][cid])
			{
				val=val + (CP['quantity'][cid] - (val % CP['quantity'][cid]));
			}

			val2=val;
			val=CP['total'][cid];
		}

		CP['total_before'][cid]=val;

		if(isNaN(val)) val=1;

		if(mode == 2)
		{
			val=val2;
		}
		else if(mode)
		{
			//val-=1;
			val-=CP['quantity'][cid];
		}
		else
		{
			//val+=1;
			val+=CP['quantity'][cid];
		}

		if(val < 0) val=0;

		if(val == 0)
		{
			elem.style.color='silver';
			elem.style.fontWeight='normal';
		}
		else
		{
			elem.style.color='black';
			elem.style.fontWeight='bold';
		}

		elem.value=val;

		CP['total'][cid]=val;

		if(!adm)
		{
			Cart_Price(cid);
		}

		return val;
	}


	var CP=Array();
	CP['ids']=Array();
	CP['total']=Array();
	CP['total_before']=Array();
	CP['price']=Array();
	CP['price_wo']=Array();
	CP['quantity']=Array();
	CP['quantity_price']=Array();

	function Cart_Price(cidz)
	{
		var cid, sum=0, sum_wo=0, last;

		for(key in CP['ids'])
		{
			cid=CP['ids'][key];

			if(cid == cidz)
			{
				if(CP['total_before'][cid] != CP['total'][cid])
				{
					if(CP['quantity_price'][cid])
					{
						for(key in CP['quantity_price'][cid])
						{
							if(key <= CP['total'][cid])
							{
								last=key;
							}
						}

						if(last)
						{
							CP['price'][cid]=CP['quantity_price'][cid][last];
							GO('cart-price-one-' + cid).innerHTML=Price(CP['price'][cid]);
						}
					}

					SL('cartsl-' + cid, '/mwjs/cart/total/' + cid + '/' + CP['total'][cid] + '/');
					PriceF('cart-price-' + cid, CP['price'][cid] * CP['total_before'][cid], CP['price'][cid] * CP['total'][cid]);
				}
			}
			else
			{
				//GO('cart-price-' + cid).innerHTML=Price(CP['price'][cid] * CP['total'][cid]);
			}

			sum+=CP['price'][cid] * CP['total'][cid];
			sum_wo+=CP['price_wo'][cid] * CP['total'][cid];
		}

		PriceF('cart-sum-price', CP['sum'], sum, true);
		PriceF('cart-sum-price-wo', CP['sum_wo'], sum_wo, true);

		CP['sum']=sum;
		CP['sum_wo']=sum_wo;

		//GO('cart-sum-price').innerHTML=Price(sum);
		//GO('cart-sum-price-wo').innerHTML=Price(sum_wo);
	}


	var PriceFR=Array();
	PriceFR['run']=Array();
	PriceFR['stop']=Array();

	function PriceF(id, before, after, main)
	{
		if(PriceFR['run'][id])
		{
			PriceFR['stop'][id]=true;
		}

		PriceFR['run'][id]=true;

		setTimeout("PriceFG('" + id + "', " + before + ", " + after + ", " + main + ")", 50);
	}



	function PriceFG(id, before, after, main)
	{
		var roz;

		if(PriceFR['stop'][id])
		{
			PriceFR['stop'][id]=false;
			return;
		}

		if(after > before)
		{
			roz=(after - before) / 5;
			roz=(roz < 1) ? 1 : roz;
			before=before + roz;

			if(before >= after)
			{
				GO(id).innerHTML=Price(after, main);
				PriceFR['run'][id]=false;
				return;
			}
		}
		else if(after < before)
		{
			roz=(before - after) / 5;
			roz=(roz < 1) ? 1 : roz;
			before=before - roz;

			if(before <= after)
			{
				GO(id).innerHTML=Price(after, main);
				PriceFR['run'][id]=false;
				return;
			}
		}

		GO(id).innerHTML=Price(before, main);

		setTimeout("PriceFG('" + id + "', " + before + ", " + after + ", " + main + ")", 10);
	}



	function Price(price, main)
	{
		var d, i, e, rst='', small, eur, ex;

		if(CP['state'] != 1)
		{
			eur=true;
			price=price / CP['eur'];
		}

		if(price < 5)
		{
			small=true;
			price=String(price);
			price=price.substr(0, 4);
			price=price.replace('.', ',');
		}
		else
		{
			if(eur)
			{
				price=String(Math.round(price * 100) / 100);
				ex=price.split('.', price);

				if(!ex[1])
				{
					price+='.00';
				}
				else if(ex[1].length == 1)
				{
					price+='0';
				}
			}
			else
			{
				price=String(Math.round(price));
			}
		}
		d=price.length;

		for(i=d, e=0; i>0; i--)
		{
			if(small)
			{

			}
			else
			{
				if(!eur && !(e++ % 3) && ((d - i) > 1))
				{
					rst='.' + rst;
				}
			}

			rst=price.substr([i-1], 1) + rst;
		}

		var add=(CP['state'] == 1) ? ' Kč' : ' EUR';

		if(small || eur)
		{
			rst=rst.replace('.', ',');
			rst+=(main ? add : '');
		}
		else
		{
			rst+=',-' + (main ? add : '');
		}

		return rst;
	}


	function SL(id, url)
	{
		var head, loader, script, cache;

		head=document.getElementsByTagName('head')[0];
	    	loader=document.getElementById('loader');

	    	if(loader) head.removeChild(loader);

	    	script=document.createElement('script');
	    	script.id='loader-' + id;
		script.src=url + Math.random() + 'a/';

		cache=document.getElementsByTagName('head')[0];
	    	cache.appendChild(script);
	}



	function Fatcha()
	{
		var mode, first, second, result;

		mode=Number(GO('fatcha-mode').value);
		first=Number(GO('fatcha-first').value);
		second=Number(GO('fatcha-second').value);

		if(!(mode % 8))
		{
			result=first / second;
		}
		else if(!(mode % 4))
		{
			result=first + second;
		}
		else if(!(mode % 2))
		{
			result=first - second;
		}
		else
		{
			result=first * second;
		}

		GO('fatcha-result').value=Math.ceil(result);
		GO('fatcha-form').submit();
	}
