	
	//------------------------------------------
	// Product Functions
	//------------------------------------------

	function addToCart( id ){
		
		var n = $('#qty_'+id).val()
		if( n > 0 )
			$.getJSON( ajaxurl, { module:"product", cp:"shopping_cart/add", n: n, id: id}, function( data ){
				if( data['return'] )
					refreshCart();
			});
		else{
			alert( "La quantit&agrave; deve essere almeno 1" );
			$('#qty').val(1);
		}
	}



	function refreshCart( msg ){
		$.get( ajaxurl, { module:'product', cp:'shopping_cart/refresh' }, function( html ){
			$('#shopping_cart_div').hide()
			$('#shopping_cart_div').html(html);
			$('#shopping_cart_div').fadeIn("slow", function(){ if(msg) alert(msg) });
		});
	}


	
	function addQuantity( id ){
		var n = $('#qty_'+id).html()*1+1
		$('#qty_'+id).html( n )
		setQuantity( id, n )
	}



	function redQuantity( id ){
		var n = $('#qty_'+id).html()*1-1
		if( n == 0 )
			delProduct( id )
		else
			setQuantity( id, n )
	}



	function setQuantity( id, n ){
		$('#qty_'+id).html(n)
		$.getJSON( ajaxurl, { module:"product", cp:"shopping_cart/set", id:id, n: n }, function(data){ 
			$('#shipping_weight').html(data['shipping_weight']);
			$('#shipping_cost').html(data['shipping_cost']);
			$('#tot_prod').html(data['tot_prod']);
			$('#tot').html(data['tot_order']);
			$('#tot_single_prod_'+id).html(data['tot_single_prod']);
			refreshCart() 
		} )
	}



	function delProduct( id ){
		$('#product_'+id).slideUp();
		$.getJSON( ajaxurl, { module:"product", cp:"shopping_cart/del", id: id }, function(data){ 
			$('#shipping_weight').html(data['shipping_weight']);
			$('#shipping_cost').html(data['shipping_cost']);
			$('#tot_prod').html(data['tot_prod']);
			$('#tot').html(data['tot_order']);
			refreshCart()
		} )
	}

