

function CAjaxJavascriptShoppingCart() {
	this.ShoppingCart = new CJavascriptShoppingCart();
	this.sAddPHPFile = "";
	this.sRemPHPFile = "";
	this.sAlterPHPFile = "";
	
	this.AddItem = function(iItem, bDoPersist) {
		bDoPersist = bDoPersist != false;
		this.ShoppingCart.AddItem(iItem);
		
		if (bDoPersist) 
			AjaxRequest.SendRequest(this.sAddPHPFile + "?partid=" + iItem.m_ID + "&qty=" + iItem.m_Quantity );
	}
	
	this.RemoveItem = function(ID) {
		var iItem = this.FindItem(ID);
		
		if (iItem != -1) {
			this.ShoppingCart.RemoveItem(ID);
			AjaxRequest.SendRequest(this.sRemPHPFile + "?partid=" + iItem.m_ID );
		}
	}
	
	this.AlterQuantity = function(pItem, iQuantity) {
		var iItem = this.FindItem(pItem.m_ID);
		
		if (iItem != -1) { 
			if (iQuantity == 0) {
				this.RemoveItem(pItem.m_ID)
			} else {
				iItem.m_Quantity = iQuantity;
				AjaxRequest.SendRequest(this.sAlterPHPFile + "?partid=" + pItem.m_ID + "&qty=" + iQuantity);
				//alert(iItem.m_Quantity);
				//alert(this.FindItem(pItem.m_ID).m_Quantity);
			}
		} else {
			pItem.m_Quantity = iQuantity;			
		//	this.AddItem(pItem);
		}
	}

	this.FindItem = function(ID) {
		return this.ShoppingCart.FindItem(ID);		
	}
	
	this.FindItemIndex = function(ID) {
		return this.ShoppingCart.FindItemIndex(ID);
	}
	
	this.GetItemByIndex = function(iIndex) {
		return this.ShoppingCart.GetItemByIndex(iIndex);
	}
	
	this.GetNoItems = function() {
		return this.ShoppingCart.GetNoItems();
	}
	
	this.GetTotalQty = function() {
		return this.ShoppingCart.GetTotalQty();
	}
	
	this.GetSubTotal = function() {
		return this.ShoppingCart.GetSubTotal();
	}
	
	this.GetVat = function() {	
		return this.ShoppingCart.GetVat();
	}
	
	this.GetGTotal = function() {
		return this.ShoppingCart.GetGTotal();
	}
	
	this.GetTotalAndPP = function(Addition, bFromStore) {
		return this.ShoppingCart.GetTotalAndPP(Addition, bFromStore);
	}
	
	this.GetPPValue = function(Addition, bFromStore) { 
		return this.ShoppingCart.GetPPValue(Addition, bFromStore);
	}
	
	this.HasItems = function() { 
		return this.ShoppingCart.HasItems();
	}
	
	this.HasPreOrderItems = function() {
		return this.ShoppingCart.HasPreOrderItems();
	}
}

var AJSCO = new CAjaxJavascriptShoppingCart();