
	var ajax_val = new Array();
	var global_action;
	

	function $(id) {
		return document.getElementById(id);
	}
	
  function openPopup(link, name, width, height, resizable) {
    if(!width)  width=400;
    if(!height) height=400;
    if(resizable!=0) resizable=1;

    wopener = window.open(link, name, 'menubar=1,toolbar=0,location=0,status=1,resizable='+ resizable +',scrollbars=1,width='+ width +',height='+ height +',top=50,left=50');
    return wopener;
  }
	
	var prev_bgcolor;
	function setSubColor(obj, action) {
		if(action == "set") {
			prev_bgcolor = obj.style.backgroundColor;
			obj.style.backgroundColor = "#05E700";
		}
		else if(prev_bgcolor){
			obj.style.backgroundColor = prev_bgcolor;
		}
	}
	
	function setRegType(type) {
		if(type == 'pravnicka') {
			$('box_pravnicka').style.display = 'block';
		}
		else {
			$('box_pravnicka').style.display = 'none';
		}
	}

  function setDelAddr() {
  	if($('same_inv_address').checked)
  		$('box_inv_addr').style.display = 'none';
  	else
  		$('box_inv_addr').style.display = 'block';
  		
  }
 
 	function addToBasket(IDproduct) {
	
		ajax_val['action'] = 'add_to_basket';
		ajax_val['IDproduct'] = IDproduct;
		
		var pcs = 1;
		if( $('pcs') ) pcs = $('pcs').value;
		
		var url = $('server_www').value+'ajax/?action='+ajax_val['action']+'&id_product='+IDproduct+'&pcs='+pcs;

		GetUrl(url);
	}
	
	function success(){

		var response = htmlConnection.responseText;

		if(global_action == 'send_tree') ;
		else if(ajax_val['action'] == 'add_to_basket') {
			var arr_response = response.split(";");
			$('basket_price').innerHTML=arr_response[0];
			$('basket_pcs').innerHTML=arr_response[1];
			$('alert_price').innerHTML=arr_response[0];
			$('alert_pcs').innerHTML=arr_response[1];


			$('alert').style.display = 'block';
			if($('item_box_' + ajax_val['IDproduct']))
				$('alert').style.top = ($('item_box_' + ajax_val['IDproduct']).offsetTop+0) + 'px';
	
			/*$('alert_price').innerHTML=arr_response[0];
			$('alert_pcs').innerHTML=arr_response[1];*/

			openAlert('alert_add_to_basket');
	  }
		else if(global_action == 'change_pcs') {
			var arr_response = response.split(";");

			document.getElementById('basket_price').innerHTML=arr_response[0];
			document.getElementById('basket_final_price').innerHTML=arr_response[0];
	
			document.getElementById('basket_pcs').innerHTML=arr_response[1];
			document.getElementById('prod_price_'+IDproduct).innerHTML=arr_response[2]+',-';
	  }
		else if(ajax_val['action'] == 'get_subcategory') 
		{

			if(response.search(/no/) > -1) 
			{
				location.href = $('server_www').value + 'eshop/c-' + ajax_val['id_category'] + '/';
			}
			else 
			{
				$('subcategory_' + ajax_val['id_category']).innerHTML = response;
				$('subcategory_' + ajax_val['id_category']).style.display = 'block';
			}
		
	  }
	  else if(ajax_val['action'] == 'change_status_of_menu')
	  {
	  	//alert(response)
	  }
	  else if(ajax_val['action'] == 'save_conf')
	  {
	  	alert(response)
	  }


	}
	
	
	function closeAlert(id) {
		
		alertController(id);
	
		$(id).style.display = 'none';
	}
	
	function openAlert(id) {
	
		alertController(id);
	
		//$(id).style.display = 'block';
	}
	
	
	function alertController(id) {

		if(id != 'alert_add_to_basket') $('alert_add_to_basket').style.display = 'none';
	}
	
	  
  function basketAction(action) {
  	$('basket_action').value = action;
  	$('basket_form').submit();
  }

	function changePcs(id, pcs) {
	
		global_action = 'change_pcs';

		IDproduct = id;

		var url = $('server_www').value+'ajax/?action='+global_action+'&id_product='+id+'&pcs='+pcs;

		GetUrl(url);
	}

	function changePcsBasket(id, pcs) {
	
		global_action = 'change_pcs';

		IDproduct = id;

		var url = $('server_www').value+'ajax/?action='+global_action+'&id_product='+id+'&pcs='+pcs+'&type=basket';

		GetUrl(url);
	}
	
	function isSouhlas() {
		if(!$('obch_souhlas').checked) 
			alert('Musíte souhlasit s obchodními podmínkami');  
		else $('order_form').submit();
	}
	
	function loadSubCategory(id_category) {

		var status;

		if(!$('subcategory_' + id_category).innerHTML)
		{
			ajax_val['action'] = 'get_subcategory';
			ajax_val['id_category'] = id_category;
	
			var url = $('server_www').value + "ajax/?action=" + ajax_val['action'] + "&id_category=" + id_category;
	
			status = 'block';
	
			GetUrl(url);
		}
		else
		{
			var display = $('subcategory_' + id_category).style.display;

			status = (display == 'none' ? 'block' : 'none');

			$('subcategory_' + id_category).style.display = status;
			
			ajax_val['action'] = 'change_status_of_menu';
	
			var url = $('server_www').value + "ajax/?action=" + ajax_val['action'] + "&id_category=" + id_category + "&status=" + status;

			GetUrl(url);
		}
		
		if(status == 'block')
		{
			$('categoryimg_' + id_category).src = $('server_www').value + 'web_img/minus.gif';
		}
		else
		{
			$('categoryimg_' + id_category).src = $('server_www').value + 'web_img/plus.gif';
		}
		
	}
	
	/* Fce na otevirani a zavirani leveho menu.
	 * Zapamatovava se stav jednotlivych slozek.
	 */
	function showSubTree(id,level) {
	
		// pokud uzivatel kliknul na slozku, ktera uz nejde otevrit
		if($('b_' + id) == null) {

			sendTree();
			location.href = $('server_www').value+'shop/t-' + id + '/';
		} else {

			if(level == 1 && $('levelStatus_1').value != id) {
			
				for(var i=1; i<=5; i++) {
	
					if($('levelStatus_' + i).value) {
						$('b_' + $('levelStatus_' + i).value).style.display = 'none';
						$('levelStatus_' + i).value = '';
					}
				}
			}
					
			if($('b_' + id).style.display == 'block') {
				$('b_' + id).style.display = 'none';
				$('levelStatus_' + level).value = '';
			}
			else {
				if($('levelStatus_' + level).value)
					$('b_' + $('levelStatus_' + level).value).style.display = 'none';
				$('b_' + id).style.display = 'block';
				$('levelStatus_' + level).value = id;
			}
		}
		
		sendTree();
		
	}
	
	function sendTree() {
	
		global_action = 'send_tree';

		var url = $('server_www').value+'index.php?page=7&l1='+$('levelStatus_1').value+
							'&l2='+$('levelStatus_2').value+
							'&l3='+$('levelStatus_3').value+
							'&l4='+$('levelStatus_4').value+'&l5='+$('levelStatus_5').value;

		GetUrl(url);
	}
	
	
	function  sendSetList(srch_where, form_name) {
	
		if(srch_where)
			$('srch_where').value = srch_where;
		
		if(srch_where == 'all')
			$(form_name).action = $('server_www').value + 'eshop/srch/';
		
		$(form_name).submit();
		
		
	}
	
	function recountPrice()
	{
		var total = 0;
		for(var i=1; i <= $('k').value; i++)
		{
			var line = $('addon_'+i).value;

			if($('addon_'+i).checked) 
			{
				$('line_'+line).style.backgroundColor = '#FE5804';
				total += $('addon_'+i+'_price').value * 1;
			}
			else
			{
				$('line_'+line).style.backgroundColor = '#FFFFFF';
			}
		}
		
		$('pc_rozsireni_price').innerHTML = total;
		$('pc_rozsireni_price_with_dph').innerHTML = Math.round(total * 1.20);

		$('pc_final_price').innerHTML = total + $('pc_price').value*1;
		$('pc_final_price_with_dph').innerHTML = Math.round((total + $('pc_price').value*1) * 1.20);
	
	}
	
	function rozsireniMouse(obj, type)
	{
	/* 
		if(type == 'over')
		{
			obj.style.backgroundColor = '#FE5804';
			obj.style.color = '#FFFFFF';
		}
		else
		{
			if(obj.id)
			{
			
			}
			else
			{
				obj.style.backgroundColor = '#FFFFFF';
				obj.style.color = '#132C42';
			}
		}
		 */
		
	
	}
	
	function ShowTitle(id_text, date)
	{
	
		if(id_text == 3) document.getElementById('dostupnost_date').innerHTML = date;
	  document.getElementById('dostupnost_id_'+id_text).style.display = "block";
	
	  document.getElementById('info_dostupnost_box').style.visibility = "visible";
	}

	function HideTitle()
	{
    document.getElementById('info_dostupnost_box').style.visibility = "hidden";
  }
  
  function clearField(id)
  {
		for(var i=1; i <= $('k').value; i++)
		{
			if($('addon_'+i).name == 'addon['+id+']') 
			{
				$('addon_'+i).checked = false;
			}
		}
		recountPrice();
  }


  
  