/*
webshop azzuri

*/

function AddToCart(id)
{
	var id = arguments[0];
	var aantal = arguments[1];
	var update = arguments[2];
	if(update === undefined)
	{
		update = "nieuw";
	}
	if(aantal === undefined)
	{
		aantal = "1";
	}
	if(isInt(aantal))
	{
		if(id != '')
		{
			var product_id = id;
			$.post("webshop/cart.php", { productid: product_id, aantal: aantal, update: update}, function(data) {
				$(".cartBox").replaceWith(data);
			});
		}
	}else
	{
		jAlert(aantal+' is geen getal, voer alleen een getal in','Winkelwagen');
	}
}

function clearCart()
{
	$.post("webshop/cart.php", { clearcart: 1 }, function(data) {
		$(".cartBox").replaceWith(data);
	});
}

function deleteFromCart(id)
{
	var id = arguments[0];
	var remove = arguments[1];
	if(remove === undefined)
	{
		remove = "1";
	}
	$.post("webshop/cart.php", { productid: id, remove: remove }, function(data) {
		$(".cartBox").replaceWith(data);
	});
}

function updateCart(id)
{
	
	aantal = $("#update-"+id).val();
	if(aantal == '0')
	{
		result = deleteFromCart(id,"2");
	}else
	{
		result = AddToCart(id,aantal,'update');
	}
}


/* utils */
function isInt(x)
{
	var y = parseInt( x );
	if ( isNaN( y ) ) return false;
	return x==y && x.toString()==y.toString();
}


