function Webshop(freeshipping, freeshippingbuitenland, shippingcost, binnenland){
	this.freeshipping = freeshipping;
	this.freeshippingbuitenland = freeshippingbuitenland;
	this.shippingcost = shippingcost;
	this.binnenland = binnenland;

	this.addToCart = function(id){
		this.changeCart('add', id);
		try{
			var el = Ext.get('cart-product-'+id+'-aantal');
			var value = parseInt(el.getValue()) +1;
			el.dom.value = value;
			this.updateSummaryTotals();
		} catch(e){}
	}

	this.removeOneFromCart = function(id){
		this.changeCart('removeone', id);
		try{
			var el = Ext.get('cart-product-'+id+'-aantal');
			var value = parseInt(el.getValue()) -1;
			el.dom.value = value;
			if(el.getValue()=='0'){
				el = Ext.get('cart-product-'+id);
				el.remove();
			}
			this.updateSummaryTotals();
		} catch(e){}
	}

	this.removeFromCart = function(id){
		this.changeCart('remove', id);
		try{
			var el = Ext.get('cart-product-'+id);
			el.remove();
			this.updateSummaryTotals();
		} catch(e){}
	}

	this.changeCart = function(action, id){
		Ext.Ajax.request({
			url: 'webshop/webshop.php',
			params: {
				action: action,
				id: id
			},
			success: function(response, opts){
				try{
					Ext.fly('headcart').dom.innerHTML = response.responseText;
				} catch(e){}
			}
		});
	}

	this.updateCart = function(id, aantal){
		if(aantal=='0'){
			var el = Ext.get('cart-product-'+id);
			el.remove();
		} else {
			this.updateProductTotals();
			this.updateSummaryTotals();
		}

		Ext.Ajax.request({
			url: 'webshop/webshop.php',
			params: {
				action: 'update',
				id: id,
				aantal: aantal
			},
			success: function(response, opts){
				try{
					Ext.fly('headcart').dom.innerHTML = response.responseText;
					this.updateSummaryTotals();
				} catch(e){}
			}
		});
	}

	this.getProductaantalCount = function(){
		var numbers = Ext.select('.cartnumbers').elements;
		var aantal = 0;
		for(var i = 0; i < numbers.length; i++){
			aantal += numbers[i].value*1;
		}
		return aantal;
	}

	this.updateProductTotals = function(){
		var products = Ext.select('.product').elements;
		for(var i = 0; i < products.length; i++){
			var id = products[i].id;
			var aantal = Ext.fly(id+'-aantal').getValue();
			var prijs = this.priceToFloat(Ext.fly(id+'-prijs').dom.innerHTML);
			Ext.fly(id+'-totaal').dom.innerHTML = this.floatToPrice(aantal*prijs);
		}
	}

	this.updateSummaryTotals = function(){
		this.updateProductTotals();
		
		var totals = Ext.select('.product .producttotal').elements;
		var total = 0;
		for(var i = 0; i < totals.length; i++){
			total += this.priceToFloat(totals[i].innerHTML);
		}

		try {
			Ext.fly(Ext.select('.tip').elements[0]).setVisibilityMode(Ext.Element.DISPLAY);
			Ext.fly('order-now').setVisibilityMode(Ext.Element.DISPLAY);
			Ext.fly('order-now-disable').setVisibilityMode(Ext.Element.DISPLAY);
			
			if(this.binnenland){
				if(total >= this.freeshipping){
					Ext.fly(Ext.select('.tip').elements[0]).hide();
				} else {
					Ext.fly(Ext.select('.tip').elements[0]).show({
						callback: function(){
							Ext.fly(Ext.select('.tip').elements[0]).removeClass('hide');
						}
					});
				}
			} else {
				if(total >= this.freeshippingbuitenland){
					Ext.fly(Ext.select('.tip').elements[0]).hide();
					Ext.fly('order-now-disable').hide();
					Ext.fly('order-now').show({
						callback: function(el){
							Ext.fly(Ext.select('.order-now').elements[0]).removeClass('hide');
						}
					});
				} else {
					Ext.fly(Ext.select('.tip').elements[0]).show({
						callback: function(el){
							Ext.fly(Ext.select('.tip').elements[0]).removeClass('hide');
						}
					});
					Ext.fly('order-now').hide();
					Ext.fly('order-now-disable').show({
						callback: function(el){
							Ext.fly(Ext.select('.order-now-disable').elements[0]).removeClass('hide');
						}
					});
				}
			}
		} catch(e){}

		var products = Ext.select('.product').elements;
		var btwtotal = 0;
		for(i = 0; i < products.length; i++){
			var price = this.priceToFloat(Ext.get(products[i]).select('.producttotal').elements[0].innerHTML);
			var btw = Ext.get(products[i]).select('.btw').elements[0].innerHTML*1;
			btwtotal += price*btw/100;
		}
		
		Ext.select('.pricetotal').elements[0].innerHTML = this.floatToPrice(total);
		var shipping = 0;
		if(this.freeshipping > total || this.binnenland == "0"){
			shipping = this.shippingcost*1;
			btwtotal += shipping*0.21;
		}
		Ext.select('.priceshipping').elements[0].innerHTML = this.floatToPrice(shipping);
		Ext.select('.btwpay').elements[0].innerHTML = this.floatToPrice(btwtotal);
		Ext.select('.pricepay').elements[0].innerHTML = this.floatToPrice(total+shipping+btwtotal);
	}

	this.priceToFloat = function(price){
		price = price.toString();
		price = price.replace(/\./g, "");
		price = price.replace(/,/g, ".");
		price = price.replace(/ /g, "");
		return price*1;
	}

	this.floatToPrice = function(price){
		price = price.toFixed(2);
		price = price.replace(/\./g, ",");
		return price;
	}
}
