
function submitSpecial(){
	alert('Je transmets mon code...');
}


function increaseQuantity(productId){
	var newQuantity = parseInt($F('quantity:'+productId)) + 1;
	new Ajax.Request("cart/update?id="+productId+"&quantity="+newQuantity+"&mode=increase", {
		onSuccess: function(transport){ eval(transport.responseText); },
		onFailure: fail
	});
}


function decreaseQuantity(productId){
	var newQuantity = parseInt($F('quantity:'+productId)) - 1;
	if( newQuantity < 1 ) {
		if (!confirmDeleteItem()) {
			return false;
		}
	}

	new Ajax.Request("cart/update?id="+productId+"&quantity="+newQuantity+"&mode=decrease", {
		onSuccess: function(transport){ eval(transport.responseText); },
		onFailure: fail
	});
}

function updateQuantity(productId){
	var newQuantity = parseInt($F('quantity:'+productId));
	if( newQuantity < 1 && !confirmDeleteItem() ) {
		new Ajax.Request("cart/retrieve?id="+productId, {
			asynchronous: false,
			onSuccess: function(transport){ eval(transport.responseText); },
		onFailure: fail
		});
		return;
	}
	new Ajax.Request("cart/update?id="+productId+"&quantity="+newQuantity+"&mode=increase", {
		onSuccess: function(transport){ eval(transport.responseText); },
		onFailure: fail
	});
}

function updateCart() {
	var prices = $$('.prices');
	var zero = 0;
	var total = 0;
	var totalUpgradeDiscount = 0;
	for( var i = 0; i < prices.length; i++ ) {
		var quantity = prices[i].id.replace('price', 'quantity');
		var unitPrice = parseFloat($(prices[i].id.replace('price', 'unit-price')).innerHTML.replace(' ', ''));
		var upgradeDiscount = parseFloat($(prices[i].id.replace('price', 'upgrade')).innerHTML.replace(' ', ''));
		var price = parseFloat(prices[i].innerHTML.replace(' ', ''));
		/*if( 0 <= $F(quantity) / 4 ) {
			price -= (parseInt($F(quantity) / 4) * unitPrice);
		}*/
		total += price;
		totalUpgradeDiscount += upgradeDiscount;
	}
	totalWithUpgradeDiscount = total - totalUpgradeDiscount;
	if (0 >= totalWithUpgradeDiscount) {
		$('cart:summary').innerHTML = getTotalStr()+'&nbsp;'+zero.toFixed(2)+'&nbsp;&euro;<br /><small>'+getApproxStr()+'&nbsp;$'+zero.toFixed(2)+'</small>';
		$('cart-checkout-button').hide();
	} else {
		$('cart-checkout-button').show();
		if (0 < totalUpgradeDiscount) {
			$('cart:summary').innerHTML = getTotalStr()+'&nbsp;<strike><small>'+total.toFixed(2)+'&nbsp;&euro;</small></strike>&nbsp;'+totalWithUpgradeDiscount.toFixed(2)+'&nbsp;&euro;<br /><small>'+getApproxStr()+'&nbsp;$'+getTotalDollar(totalWithUpgradeDiscount)+'</small>';
		} else {
			$('cart:summary').innerHTML = getTotalStr()+'&nbsp;'+total.toFixed(2)+'&nbsp;&euro;<br /><small>'+getApproxStr()+'&nbsp;$'+getTotalDollar(totalWithUpgradeDiscount)+'</small>';
		}
	}
	$('cart:summary').show();
}
