var HQS_ProductAdded = false;
var HQS_ProductAddedMsg = '';

function HQS_AddProduct(product, quantity, objcaller) {
	objcaller.disabled = true;
	new Ajax.Request('/_lib/shopfunctions.php?do=addproduct&product='+product+'&quant='+quantity+'&rnd=' + new Date().getTime(), {
		method: 'get',
		onSuccess: function(transport){HQS_ProcessAddProduct(transport, objcaller);}
	});
}

function HQS_ProcessAddProduct(transport, objcaller) {
	objcaller.disabled = false;
	if (transport.getHeader("HQS_Error") == 'true') {
		alert(transport.getHeader("HQS_ErrorMsg"));
	}
	else {
		HQS_ProductAdded = true;
		HQS_ProductAddedMsg = transport.responseText;
		HQS_UpdateMiniCart();
		alert('Product is toegevoegd aan uw winkelmand, klik op Afrekenen om te bestellen');
	}
}

function HQS_UpdateMiniCart() {
	new Ajax.Request('/_lib/shopfunctions.php?do=getminicart&rnd=' + new Date().getTime(), {
		method: 'get',
		onSuccess: HQS_ProcessUpdateMiniCart
	});
}

function HQS_ProcessUpdateMiniCart(transport) {
	if (transport.getHeader("HQS_Error") == 'true') {
		alert(transport.getHeader("HQS_ErrorMsg"));
	}
	else {
		$('minicartcontents').update(transport.responseText);
		if (HQS_ProductAdded) {
			HQS_ProductAdded = false;
			$('minicartcontents').insert(HQS_ProductAddedMsg, 'after');
		}
	}
}

function HQS_EmptyCart() {
	if (confirm('Wilt u uw winkelmand volledig legen?')) {
		if (typeof(IsShoppingCart) == 'undefined') {
			new Ajax.Request('/_lib/shopfunctions.php?do=emptycart&rnd=' + new Date().getTime(), {
				method: 'get',
				onSuccess: HQS_UpdateMiniCart
			});
		}
		else {
			new Ajax.Request('/_lib/shopfunctions.php?do=emptycart&rnd=' + new Date().getTime(), {
				method: 'get',
				onSuccess: function(transport) {
					document.location = document.location;
					//document.location = '/do;shoppingcart/reload;' + new Date().getTime();
				}
			});
		}
	}
}

