liltype.XHReq = function(handlerObj, handlerMethodName, url)
{
	if (liltype.XHReq.parent)
	{
		this.method = "get";
		this.data = "";
		this.url = url;
		this.asyncFlag = null;
		this.userName = null;
		this.password = null;
		this.serial = liltype.XHReq.reqSerial++;
		this.req = null;
		this.nextReq = null;
		this.handled = false;
		this.onTimeout = null;
		this.handlerObj = handlerObj;
		this.handlerMethodName = handlerMethodName;
	}
}
new liltype.XHReq();
liltype.XHReq.prototype = new liltype();
liltype.XHReq.parent = liltype;

liltype.XHReq.reqSerial = 1;
liltype.XHReq.reqs = null;
liltype.XHReq.timeout = 15000; // 15 seconds
liltype.XHReq.reqAsynch = true;

liltype.XHReq.prototype.contentTypePost = "application/x-www-form-urlencoded";

//
// Request list funcs
	liltype.XHReq.addReq = function(req)
	{
		if (this.reqs == null)
		{
			this.reqs = req;
		}
		else
		{
			this.reqs.addReq(req);
		}
	}
	
	liltype.XHReq.getReq = function(serial)
	{
		if (this.reqs == null)
		{
			return null;
		}
		else
		{
			return this.reqs.getReq(serial);
		}
	}
	
	liltype.XHReq.delReq = function(serial)
	{
		if (this.reqs != null)
		{
			if (this.reqs.serial == serial)
			{
				this.reqs = this.reqs.nextReq;
			}
			else
			{
				this.reqs.delReq(serial);
			}
		}
	}
	

	liltype.XHReq.prototype.addReq = function(req)
	{
		if (this.nextReq == null)
		{
			this.nextReq = req;
		}
		else
		{
			this.nextReq.addReq(req);
		}
	}
	
	liltype.XHReq.prototype.getReq = function(serial)
	{
		if (this.serial == serial)
		{
			return this;
		}
		else if (this.nextReq != null)
		{
			return this.nextReq.getReq(serial);
		}
		else
		{
			return null;
		}
	}
	
	liltype.XHReq.prototype.delReq = function(serial)
	{
		var req = this.nextReq;
		if (req == null)
		{
			return;
		}
		else if (req.serial == serial)
		{
			this.nextReq = req.nextReq;
			req.nextReq = null;
		}
		else
		{
			req.delReq(serial);
		}
	}
	
	liltype.XHReq.onErrNoReq = function()
	{
	 	// Override
	}

//
// Request constructor wrapper
	liltype.XHReq.newReq = function()
	{
		var req;
		if(window.XMLHttpRequest)
		{
			try
			{
				req = new XMLHttpRequest();
			}
			catch(e)
			{
				req = null;
			}
		}
		else if(window.ActiveXObject)
		// branch for IE/Windows ActiveX version
		{
			try
			{
				req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					req = null;
				}
			}
		}
		
		if (req == null)
		{
			this.onErrNoReq();
		}
		return req;
	}
	
	
	
	if (liltype.XHReq.newReq() != null)
	/* Define methods */
	{
		liltype.XHReq.prototype.request = function()
		{
			this.handled = false;
			if ((!liltype.XHReq.reqAsynch) && (this.reqs != null))
			{
				if (this.nonAsynchHandler != null)
				{
					this.nonAsynchHandler();
				}
				return;
			}
			this.req = liltype.XHReq.newReq();
			this.req.onreadystatechange = liltype.XHReq.onreadystatechange;
	
			if ((this.asyncFlag == null) &&
					(this.userName == null) &&
					(this.password == null))
			{
				try
				{
					this.req.open(this.method, this.url);
				}
				catch (e)
				{
					document.write(e);
					return;
				}
			}
			else if ((this.userName == null) &&
							 (this.password == null))
			{
				this.req.open(this.method, this.url, this.asyncFlag);
			}
			else if (this.password == null)
			{
				this.req.open(this.method, this.url, this.asyncFlag, this.userName);
			}
			else
			{
				this.req.open(this.method, this.url, this.asyncFlag, this.userName, this.password);
			}
	
			if (this.method == 'post')
			{
				this.req.setRequestHeader('Content-Type', this.contentTypePost);
			}

			liltype.XHReq.addReq(this);

			try
			{
				this.req.send(this.data);
			}
			catch (e)
			{
				document.write(e);
				return;
			}
			
			setTimeout("liltype.XHReq.reqTimeout("+this.serial+");", liltype.XHReq.timeout);
			return false;
		}
		
		liltype.XHReq.onreadystatechange = function()
		{
			var req, i, serials = new Array();
			for (req = liltype.XHReq.reqs; req != null; req = req.nextReq)
			{
				if (!req.handled)
				{
					if (req.onreadystatechange())
					{
						serials.push(req.serial);
					}
				}
			}
			
			for (i = 0; i < serials.length; i++)
			{
				liltype.XHReq.delReq(serials[i]);
			}
		}
	
		liltype.XHReq.prototype.onreadystatechange = function()
		{
			this.handlerObj[this.handlerMethodName](this.req);
			if (this.req.readyState == 4)
			{
				this.handled = true;
				return true;
			}
			return false;
		}
		
		liltype.XHReq.reqTimeout = function(serial)
		{
			var req;
			if (req = this.getReq(serial))
			{
				if (req.onTimeout !== null)
				{
					req.onTimeout();
				}
				this.delReq(serial);
			}
		}
		
	}
	else
	/* Define empty methods */
	{
		liltype.XHReq.prototype.request = function()
		/* Override to extend */
		{
			return false;
		}
	}
if (!liltype.cart)
{
	liltype.cart = new liltype();
}

liltype.cart.Currency = function(name, code, symbol, rate)
{
	if (liltype.cart.Currency.parent)
	{
		this.inherited = liltype.cart.Currency.parent;
		this.inherited();
		this.name = name;
		this.code = code;
		this.symbol = symbol;
		this.rate = rate;
		liltype.cart.Currency.actual = this;
	}
}
new liltype.cart.Currency();
liltype.cart.Currency.prototype = new liltype();
liltype.cart.Currency.parent = liltype;
liltype.cart.Currency.actual = null;

/* Prototype methods */
	liltype.push(liltype.cart.Currency.prototype);

	liltype.top().classNames = new Array
	(
		"currency_symbol",
		"currency_code",
		"currency_name"
	);
	
	liltype.top().currencyConv = function(usd, code, dec_max, dec_min)
	{
		return this.currencyFmt(usd * this.rate, dec_max ? dec_max : 2, dec_min ? dec_min : 2);
	}
	
	liltype.top().currencyFmt = function(amt, decMax, decMin)
	{
	  var decPlaces, decPos;
		var conv = ""+(Math.round(amt * Math.pow(10, decMax)) / (Math.pow(10, decMax)));

		decPos = conv.indexOf(".");
		if (decPos == -1)
		{
			conv += ".";
			decPos = conv.length - 1;
		}
		decPlaces = conv.length - decPos - 1;

		while (decPlaces < decMin)
		{
		  conv += "0";
		  decPlaces++;
		}

		return conv;
	}

	liltype.pop();

/* Class methods */
	liltype.push(liltype.cart.Currency);
	
	liltype.top().get = function()
	{
		return this.actual;
	}
	
	liltype.pop();


if (!liltype.cart)
{
	liltype.cart = new liltype();
}

liltype.cart.Cart = function(items)
{
	var i, c, item;
	if (liltype.cart.Cart.parent)
	{
		this.inherited = liltype.cart.Cart.parent;
		this.inherited();
		this.grandTotal = 0;
		this.unitCount = 0;
		this.currency = liltype.cart.Currency.get();
		liltype.cart.Cart.actual = this;

		this.items = new Array();
		for (i = 0, c = items.length; i < c; i++)
		{
			item = items[i];
			this.items.push(items[i]);
			this.unitCount += parseInt(item.item_qty);
			this.grandTotal += ((parseInt(item.item_qty) * parseFloat(item.unit_price)) + parseFloat(item.extra_price));
		}
	}
}
new liltype.cart.Cart();
liltype.cart.Cart.prototype = new liltype();
liltype.cart.Cart.parent = liltype;
liltype.cart.Cart.actual = null;

/* Prototype methods */
	liltype.push(liltype.cart.Cart.prototype);
	
	liltype.top().classNames = new Array
	(
		"unit_count",
		"grand_total",
		"unit_count_multi",
		"unit_count_single"
	);
	liltype.top().classNames = liltype.top().classNames.concat(liltype.cart.Currency.prototype.classNames);

	liltype.top().dollarFormat = function(amt)
	{
		this.items.push(item);
	}

	liltype.top().addItem = function(item)
	{
		this.items.push(item);
	}

	liltype.top().populateSummary = function(rootId)
	{
		var n = new liltype.NGC(liltype.ds(rootId), this.classNames);
		n.setInnerHTML("unit_count", this.unitCount);
		n.setInnerHTML("grand_total", this.currency.currencyConv(this.grandTotal));
		n.setInnerHTML("currency_symbol", this.currency.symbol);
		n.setInnerHTML("currency_code", this.currency.code);

		if (this.unitCount != 1)
		{
			n.setStyle("unit_count_multi", "display", "inline");
			n.setStyle("unit_count_single", "display", "none");
		}
		else
		{
			n.setStyle("unit_count_multi", "display", "none");
			n.setStyle("unit_count_single", "display", "inline");
		}
	}

	liltype.pop();

/* Class methods */
	liltype.push(liltype.cart.Cart);
	
	liltype.top().get = function()
	{
		return this.actual;
	}
	
	liltype.top().populateSummary = function(rootId)
	{
		if (this.actual)
		{
			this.actual.populateSummary(rootId);
		}
	}
	
	liltype.pop();


liltype.bb.Cart = function()
{
	if (liltype.bb.Cart.parent)
	{
		this.inherited = liltype.bb.Cart.parent;
		this.inherited(arguments);
	}
}
new liltype.bb.Cart();
liltype.bb.Cart.prototype = new liltype.cart.Cart("");
liltype.bb.Cart.parent = liltype.cart.Cart;
liltype.bb.cart = null;

/* Class methods */
	liltype.push(liltype.bb.Cart);
	
	liltype.top().populateSummary = function(rootId)
	{
		liltype.bb.Cart.parent.populateSummary(rootId);
	}
	
	liltype.pop();

if (!liltype.cart)
{
	liltype.cart = new liltype();
}

liltype.cart.GroupCategory = function(dat)
{
	var k;
	if (liltype.cart.GroupCategory.parent)
	{
		this.inherited = liltype.cart.GroupCategory.parent;
		this.inherited();
		this.itemGroups = new Array();
		this.currency = liltype.cart.Currency.get();
		this.nodes = null;
		for (k in dat)
		{
			this[k] = dat[k];
		}
	}
}
new liltype.cart.GroupCategory();
liltype.cart.GroupCategory.prototype = new liltype();
liltype.cart.GroupCategory.parent = liltype;
liltype.cart.GroupCategory.actual = null;

/* Prototype methods */
	liltype.push(liltype.cart.GroupCategory.prototype);
	
	liltype.top().classNames = new Array
	(
		"item_group_same_price",
		"item_group_price"
	);
	liltype.top().classNames = liltype.top().classNames.concat(liltype.cart.Currency.prototype.classNames);


	liltype.top().add = function(itemGroup)
	{
		this.itemGroups[itemGroup.item_group_id] = itemGroup;
	}
	
	liltype.top().populateItemGroup = function(itemGroupId)
	{
		var group = this.itemGroups[itemGroupId];
		var nodes = this.fetchNodes(itemGroupId);
		this.setStdNodes(nodes, group);
	}
		/* Auxilliary functions */
		liltype.top().fetchNodes = function(itemGroupId)
		{
			return new liltype.NGC(liltype.ds("item_group_"+itemGroupId), this.classNames);
		}

		liltype.top().setStdNodes = function(nodes, group)
		{
			nodes.setInnerHTML("item_group_price", this.currency.currencyConv(group.items[0].unit_price));
			nodes.setInnerHTML("currency_symbol", this.currency.symbol);
			nodes.setInnerHTML("currency_code", this.currency.code);
		}

	liltype.pop();

liltype.bb.GroupCategory = function(dat)
{
	if (liltype.bb.GroupCategory.parent)
	{
		this.inherited = liltype.bb.GroupCategory.parent;
		this.inherited(dat);
	}
}
new liltype.bb.GroupCategory();
liltype.bb.GroupCategory.prototype = new liltype.cart.GroupCategory("");
liltype.bb.GroupCategory.parent = liltype.cart.GroupCategory;
liltype.bb.cats = new Array();

/* Prototype methods */
	liltype.push(liltype.bb.GroupCategory.prototype);

	liltype.top().populateItemGroup = function(itemGroupId)
	{
	}

	liltype.pop();
	
/* Class methods */
	liltype.push(liltype.bb.GroupCategory);
	
	liltype.top().add = function(dat)
	{
		liltype.bb.cats[dat.cat_id] = new liltype.bb.GroupCategory(dat);
	}

	liltype.pop();
