
	function AXProducts () {
		
		this.product = new Array ();
		
	}
	
	
	AXProducts.prototype.addProduct = function (oProduct) {
		
		this.product.push (oProduct);
		
	}
	
	
	AXProducts.prototype.getProduct = function (sProductId) {
		
		for (var i = 0; i < this.product.length; i++) {
			
			if (this.product[i].id == sProductId)
				return this.product[i];
			
		}
		
	}
	
	
	AXProducts.prototype.toggleCart = function (sProductId) {
		
		var oProduct = this.getProduct (sProductId);
		
		if (oProduct)
			oProduct.toggleCart ();
		
	}
	
	
	AXProducts.prototype.changeCartStatus = function (sProductId, bInsideCart) {
		
		var oProduct = this.getProduct (sProductId);
		
		if (oProduct)
			oProduct.changeCartStatus (bInsideCart);
		
	}
	
	
	AXProducts.prototype.alterPrices = function (iDiscount, arrayDepartment, sAxicode) {
		
		this.resetPrices ();
		
		for (var i = 0; i < this.product.length; i++) {
			
			for (var j = 0; j < arrayDepartment.length; j++) {
				
				if (this.product[i].departmentId == arrayDepartment[j]) {
					
					this.product[i].alterPrice (iDiscount, sAxicode);
					
				}
				
			}
			
		}
		
	}
	

	AXProducts.prototype.resetPrices = function () {
		
		for (var i = 0; i < this.product.length; i++) {
			
			this.product[i].resetPrice ();
			
		}
		
	}
	
	
	AXProducts.prototype.selectLevel = function (iLevel, sProductId) {
		
		var oProduct = this.getProduct (sProductId);
		
		if (oProduct)
			oProduct.selectLevel (iLevel);
		
	}
	
	
	
	// Object for describing a product 
	function AXProduct (sId, sCode, sPrice, sName, sDepartmentId, sDescription, bPhotoAvailable, bAdditionalCosts, sMaxAmount) {
		
		// Unique identifier for this product.
		this.id = sId;
		
		// Article code Axitraxi.
		this.code = sCode;
		
		// Product price.
		this.price = parseFloat (sPrice);
		
		// Product name.
		this.name = sName;
		
		// Product department Id.
		this.departmentId = sDepartmentId;
		
		// Product description.
		this.description = sDescription;
		
		// Is product photo available.
		this.productPhotoAvailable = bPhotoAvailable;
		
		this.additionalCosts = bAdditionalCosts;
		
		this.productMax = sMaxAmount;
		
		// Is the product added to the cart.
		this.insideCart = false;
		
		this.axicode = new String ();
		
		this.discount = 0;
		
	}
	
	
	AXProduct.prototype.changeCartStatus = function (bInsideCart) {
		
		var oCartToggleButton = document.getElementById ('cartToggleButton' + this.id);
		
		if (oCartToggleButton) {
			
			if (bInsideCart)
				oCartToggleButton.src = 'images/layout/knoppen/cart_del.gif';
			else
				oCartToggleButton.src = 'images/layout/knoppen/cart_add.gif';
			
		}
		
		this.insideCart = bInsideCart;
		
	}
	
	
	AXProduct.prototype.getAdditionalCosts = function () {
		
		return this.additionalCosts;
		
	}
	
	
	AXProduct.prototype.toggleCart = function () {
		
		if (this.insideCart) {
			
			oCart.removeProduct (oCart.getProductIndex (this.id));
			
		} else {
			
			var sPrice = this.price * (1-(this.discount/100));
			
			oCart.addProduct (this.id, this.code, this.name, this.description, sPrice, 0, this.productPhotoAvailable, this.departmentId, this.getAdditionalCosts (), 1, this.productMax, this.axicode);
			
		}
		
	}
	
	
	AXProduct.prototype.alterPrice = function (iDiscount, sAxicode) {
		
		if (iDiscount >= 0 && iDiscount <= 100)
			this.discount = iDiscount;
		
		this.updatePrice ();
		
		this.axicode = sAxicode;
		
	}
	
	
	AXProduct.prototype.resetPrice = function () {
		
		this.discount = 0;
		
		this.updatePrice ();
		
	}
	
	AXProduct.prototype.updatePrice = function () {
		
		var oPrice = document.getElementById ('price' + this.id);
		var oPriceOld = document.getElementById ('priceOld' + this.id);
		
		var iPrice = this.price * (1-(this.discount/100));
		
		if (oPrice)
			document.getElementById ('price' + this.id).innerHTML = CurrencyFormatted (iPrice);
		
		if (oPriceOld && this.discount > 0)
			document.getElementById ('priceOld' + this.id).style.display = 'block';
		else if (oPriceOld)
			document.getElementById ('priceOld' + this.id).style.display = 'none';
		
	}
	
	
	AXProductSL.prototype = new AXProduct ();
	
	// Object for describing a product with serice levels.
	function AXProductSL (sId, sCode, sPrice, sName, sDepartmentId, sDescription, arrayServiceLevel, bPhotoAvailable, sMaxAmount) {
		
		// Unique identifier for this product.
		this.id = sId;
		
		// Article code Axitraxi.
		this.code = sCode;
		
		// Product price.
		this.price = parseFloat (sPrice);
		
		// Product name.
		this.name = sName;
		
		// Product department Id.
		this.departmentId = sDepartmentId;
		
		// Product description.
		this.description = sDescription;
		
		// Is product photo available.
		this.productPhotoAvailable = true;
		
		this.additionalCosts = false;
		
		this.productMax = sMaxAmount;
		
		// Is the product added to the cart.
		this.insideCart = false;
		
		// Service levels of the product.
		this.serviceLevels = arrayServiceLevel;
		
		this.axicode = new String ();
		
		this.discount = 0;
		
		OnLoadObject (this);
		
	}
	
	
	AXProductSL.prototype.init = function () {
		
		this.totalPriceElem = document.getElementById ('price' + this.id);
		this.totalPriceOldElem = document.getElementById ('priceOld' + this.id);
		this.additCosts = document.getElementById ('transportkostenTekst');
		
		var iToSelect;
		
		for (var i = 0; i < this.serviceLevels.length; i++) {
			
			if (!this.serviceLevels[i].disabled) {
				iToSelect = i;
				break;
			}
			
		}
		
		this.selectLevel (iToSelect);
		
	}
	
	
	AXProductSL.prototype.selectLevel = function (iLevel) {
		
		for (var i = 0; i < this.serviceLevels.length; i++) {
			
			if (i <= iLevel)
				this.serviceLevels[i].select ();
			else
				this.serviceLevels[i].deselect ();
			
		}
		
		this.selectedLevel = iLevel;
		
		if (this.getAdditionalCosts ())
			this.additCosts.style.visibility = 'visible';
		else
			this.additCosts.style.visibility = 'hidden';

		
		this.price = this.getTotalPrice ();
		this.description = this.getSelectedLevelName ();

		this.updatePrice ();
		
	}
	
	
	AXProductSL.prototype.getAdditionalCosts = function () {
		
		if (this.selectedLevel > 0)
			return true;
		else
			return false;
		
	}
	
	
	AXProductSL.prototype.getTotalPrice = function () {
		
		var iTotalPrice = 0;
		
		for (var i = 0; i < this.serviceLevels.length; i++) {
			
			if (!this.serviceLevels[i].selected)
				break;
				
			iTotalPrice += this.serviceLevels[i].price;
			
		}
		
		return iTotalPrice;
		
	}
	
	
	AXProductSL.prototype.getSelectedLevelName = function () {
		
		return this.serviceLevels[this.selectedLevel].levelName;
		
	}

	
	AXProductSL.prototype.updatePrice = function () {
		
		var oPrice = document.getElementById ('price' + this.id);
		var oPriceOld = document.getElementById ('priceOld' + this.id);
		
		var iPrice = this.getTotalPrice () * (1-(this.discount/100));
		var iPriceOriginal = this.getTotalPrice ();
		
		if (oPrice) {
			oPrice.innerHTML = CurrencyFormatted (iPrice);
			oPriceOld.innerHTML = CurrencyFormatted (iPriceOriginal);
		}
		
		if (oPriceOld && this.discount > 0)
			document.getElementById ('priceOld' + this.id).style.display = 'block';
		else if (oPriceOld)
			document.getElementById ('priceOld' + this.id).style.display = 'none';
		
	}
	
	
	
	function ServiceLevel (iType, sName, sPrice, sDisabled) {
		
		this.type = iType;
		this.levelName = sName;
		this.price = parseFloat (sPrice);
		this.selected = false;
		
		if (sDisabled == 'Waar')
			this.disabled = true;
		else
			this.disabled = false;
			
		OnLoadObject (this);
		
	}
	
	ServiceLevel.prototype.init = function () {
		
		this.radioButton = document.getElementById ('ServiceLevelRadio' + this.type);
		this.calcPrice = document.getElementById ('ServiceLevelCalcPrice' + this.type);
		
	}
	
	
	ServiceLevel.prototype.select = function () {
		
		this.radioButton.checked = true;
		this.calcPrice.style.visibility = 'visible';
		this.selected = true;
		
	}
	
	
	ServiceLevel.prototype.deselect = function () {
		
		this.radioButton.checked = false;
		this.calcPrice.style.visibility = 'hidden';
		this.selected = false;
		
	}
