//--------------------------------
//				add_to_cart 
//--------------------------------

function add_to_cart()
{
	var items = $("#atc_items").attr("value");
	var product_id = $("#atc_product_id").html();
	var package_id = $("#atc_package_id").html();
	
	$.post("/ajax.php", { section: "add_to_cart", items: items, product_id: product_id, package_id: package_id}, 
	function(data) 
	{
		$.post("/ajax.php", { section: "check_cart"}, 
		function(data) 
		{		
			$("#index_cart").html(data);
			$("#added_to_cart").fadeIn(300).delay(600).fadeOut(1000);
		});
	});
}

//--------------------------------
//				row_items 
//--------------------------------

function row_items(id)
{
	var items = $("#items_"+id).attr("value");
	$.post("/ajax.php", { section: "row_items", items: items, id: id}, 
	function(data) 
	{
		$.post("/ajax.php", { section: "cart_result"}, 
		function(data) 
		{		
			$("#cart_result").html(data);
			$.post("/ajax.php", { section: "check_cart"}, 
			function(data) 
			{		
					$("#index_cart").html(data);
			});

			$.post("/ajax.php", { section: "cart_price"}, 
			function(data) 
			{		
				$("#cart_price").html(data);
			});

			$("#added_to_cart").fadeIn(300).delay(600).fadeOut(1000);
		});
	});
}

//--------------------------------
//					row_delete 
//--------------------------------

function row_delete(id)
{
	$.post("/ajax.php", { section: "row_delete", id: id}, 
	function(data) 
	{
		$.post("/ajax.php", { section: "cart_result"}, 
		function(data) 
		{	
			// ked uz v kosiku nic nezostalo
			if(data == "empty")
			{
				// cart_price // odstranit
				$("#cart_price").hide();
				$("#cart_navigation").hide();
				$("#cart_table_result").hide();
				$("#cart_error").show();
			}
			else
			{
				$("#cart_result").html(data);
			}
			$.post("/ajax.php", { section: "check_cart"}, 
			function(data) 
			{		
				$("#index_cart").html(data);
				
				$.post("/ajax.php", { section: "cart_price"}, 
				function(data) 
				{		
					$("#cart_price").html(data);
				});
			});
		
			$("#added_to_cart").fadeIn(300).delay(600).fadeOut(1000);
		});
	});
}

//--------------------------------
//		  select_delivery 
//--------------------------------

function select_delivery(id)
{
	// --- selectnutie dopravy ---
	$.post("/ajax.php", { section: "select_delivery", id: id}, 
	function(data) 
	{
		$("a[id*='delivery_']").attr("class", "radio");
		$("#delivery_"+id).attr("class", "radio_selected");

		// --- sposoby platby ---
		$.post("/ajax.php", { section: "cart_payment"}, 
		function(data) 
		{
			$("#payment_method").html(data);

			// --- ceny ---
			$.post("/ajax.php", { section: "cart_price"}, 
			function(data) 
			{		
				$("#cart_price").html(data);
			});
		});		
		
		$("#icon_delivery").fadeIn(300).delay(600).fadeOut(1000);
	});
}

//--------------------------------
//			select_payment 
//--------------------------------

function select_payment(id)
{
	// --- selectnutie platby ---
	$.post("/ajax.php", { section: "select_payment", id: id}, 
	function(data) 
	{
		$("a[id*='payment_']").attr("class", "radio");
		$("#payment_"+id).attr("class", "radio_selected");
		
		// --- ceny ---
		$.post("/ajax.php", { section: "cart_price"}, 
		function(data) 
		{		
			$("#cart_price").html(data);
		});
		
		$("#icon_delivery").fadeIn(300).delay(600).fadeOut(1000);
	});
}

//--------------------------------
//		select_delivery_address 
//--------------------------------

function select_delivery_address(type, show)
{
	$("a[id*='delivery_address_']").attr("class", "radio");
	$("#delivery_address_"+type).attr("class", "radio_selected");
	
	$.post("/ajax.php", { section: "select_delivery_address", type: type}, 
	function(data) 
	{
		if(type == "1")
		{
			if(show == "show")
			{
				$("#delivery_address").show();
			}
			else
			{
				$("#delivery_address").slideDown("slow");
			}
		}
		else
		{
			$("#delivery_address").slideUp("slow");
		}
		// zapise do hiddenu, ci je adresa alebo ee
		$("#input_delivery_address").attr("value", type);
	});
}



