var oCart = new function clsShoppingCart() {

		this.m_sRequestUri = "/index.php?mod=webshop&com=doAjaxRequest&";
		this.m_sPlaceHolder = 'shoppingcart';

		this.addSingleProdutToCart = function(p_iProductId, p_iQuantity, p_bRedirect) {
			var aProducts = new Array();
			aProducts.push(new Array(p_iProductId, p_iQuantity));
			if (p_bRedirect) {
				this._redirectToCart();
			} else {
				this._ajaxAddProducts(aProducts);
			}
			alert('Het product is toegevoegd aan uw winkelmandje');
		}
		
		this.updateCart = function() {
			var oHTTP = new clsHTTPRequest();
			var sUrl = this.m_sRequestUri;
			
			sUrl += "request=updateCart";
			oHTTP.setRequestURI(sUrl);
			
			oHTTP.setHTML();
			oHTTP.getHTML(this.m_sPlaceHolder);
		}
		
		this.removeSingleProduct = function(p_iProductId) {
			var aProducts = new Array();
			aProducts.push(p_iProductId);
			if (p_iProductId) {
				this._ajaxRemoveProducts(aProducts)
			}
		}
		
		this.removeAllProducts = function() {
			this._ajaxClearCart();
		}
		
		this._ajaxClearCart = function() {
			var oHTTP		= new clsHTTPRequest();
			var sUrl 		= this.m_sRequestUri;
			sUrl += "request=removeAllFromCart";
			oHTTP.setRequestURI(sUrl);
			oHTTP.setHTML();
			oHTTP.getHTML(this.m_sPlaceHolder);
			
			
		}
		
		this._ajaxRemoveProducts = function(p_aProducts) {
			var oHTTP 		= new clsHTTPRequest();
			var sUrl 		= this.m_sRequestUri;
			var aProductIds = new Array();
			sUrl += "request=removeFromCart";
			if (p_aProducts.length) {
				for (i=0; p_aProducts[i]; i++) {
					aProductIds[i] = p_aProducts[i];
				}
			}
			sUrl += "&prodids="+aProductIds.join(",");
			oHTTP.setRequestURI(sUrl);
			oHTTP.setHTML();
			oHTTP.getHTML(this.m_sPlaceHolder);
		}
		
		this._ajaxAddProducts = function(p_aProducts) {
			var oHTTP = new clsHTTPRequest();
			var sUrl =  this.m_sRequestUri;
			var aProductIds = new Array();
			var aProductQty = new Array();
			sUrl += "request=addToCart&"
			if (p_aProducts.length) {
				for (i=0; p_aProducts[i]; i++) {
					aProductIds[i] = p_aProducts[i][0];
					aProductQty[i] = p_aProducts[i][1];
				}
			}
			sUrl += "prodids="+aProductIds.join(",");
			sUrl += "&qty="+aProductQty.join(",");
			oHTTP.setRequestURI(sUrl);
			oHTTP.getHTML(this.m_sPlaceHolder);
			
		}
}
	
	function updateCartOnload() {
		if (document.getElementById('shoppingcart')) {
			oCart.updateCart();
		}
	}