function cSMBasketGUIColumn(id, caption){
	this.styleHeader = new cSMStyleBox();
	this.styleBody = new cSMStyleBox();
	this.id = id;
	this.index = 0;
	this.product = null;
	this.caption = caption;
	this.gui = null;
	this.render = null;
	this.renderXML = null;
	};

function cSMBasketGUIFooterItem(id, caption){
	this.styleCaption = new cSMStyleBox();
	this.styleValue = new cSMStyleBox();
	this.id = id;
	this.basket = null;
	this.caption = caption;
	this.gui = null;
	this.render = null;
	this.renderXML = null;
	this.cancel = false;
	};

function cSMBasketGUI(id){
	this.id = id;
	this.hideColumnHeaders = false;
	this.base = new cSMBase(this.id);
	this.shop = SMShop;
	this.basket = this.shop.basket;
	this.columns = new Array();
	this.footerItems = new Array();
	this.styleTable = new cSMStyleBox();
	// add as basket event member
	this.basket.base.addMember(this.id);
	};

cSMBasketGUI.prototype.addColumn = function(id, caption){
var c = new cSMBasketGUIColumn(id, caption);
	this.columns[this.columns.length] = c; c.gui = this;
	return(c);
	};

cSMBasketGUI.prototype.addFooterItem = function(id, caption){
var f = new cSMBasketGUIFooterItem(id, caption);
	this.footerItems[this.footerItems.length] = f; f.gui = this;
	return(f);
	};

cSMBasketGUI.prototype.render = function(){
var s = fc = "", xb = this.basket.xml, xc = null, p = null,
		c = null, f = null, tro = "<TR>", trc = "</TR>", tho = "<TH", thc = "</TH>", tdo = "<TD", tdc = "</TD>", cl = null, fset = false;
	s += "<FORM" + this.htAttrib("style", "display:inline") + "><TABLE id=\"basket\"" + this.styleTable.createInlineCode() + ">";
	// reset basket if another order has been previously completed
	with(this.basket.parent){
		if(getAttribute(_SMAOComplete)=="true"){
			reinitOrder();
			};
		};
	// continue
	if(!this.hideColumnHeaders){
		s += "<THEAD>" + tro;
		for(var i=0; i<this.columns.length; i++){
			c = this.columns[i];
			c.index = i;c.product = p;
			s += tho + c.styleHeader.createInlineCode() + " nowrap>" + c.caption + thc;
			};
		s += trc + "</THEAD>";
		};
	s += "<TBODY>";
	if(xb.selectNodes(_SMPrd).length()==0){
		s += tro + tdo + " colspan=\"" + this.columns.length + "\">";
		s += "Your Basket has no items in it.  Please add at least one article to your Basket." + tdc + trc;
		}
	else{
		for(var i=0; i<xb.selectNodes(_SMPrd).length(); i++){
			xc = xb.selectNodes(_SMPrd).item(i);
			p = new cSMProduct(_SMPrd);p.shop = this.shop;p.basket = this.basket;p.parent = this.basket;p.init(xc);
			s += tro;
			for(var j=0; j<this.columns.length; j++){
				c = this.columns[j];c.index = i;c.product = p;
				cl = new Array();
				if(c.render!=null){
					if(i==0) cl[cl.length] = "first-item";
					cl[cl.length] = ((i%2==1) ? "alt-item" : "");
					s += tdo
						+ ((cl.length!=0) ? " class=\"" + cl.join(" ") + "\"" : "")
						+ c.styleBody.createInlineCode() + ">" + c.render() + tdc;
					};
				};
			s += trc;
			};
		};
	s += "</TBODY>";
	if(this.footerItems.length>0&&this.basket.getAttribute(_SMAItems)!="0"){
		s += "<TFOOT>";
		for(var i=0; i<this.footerItems.length; i++){
			f = this.footerItems[i]; f.basket = f.gui.basket; f.cancel = false;
			fc = tro + tdo + ((i==0||!fset) ? " class=\"first-item\"" : "") + this.htAttrib("colspan", (this.columns.length-1)) + f.styleCaption.createInlineCode() + ">";
			fc += f.caption + tdc;
			cl = new Array();
			if(i==0||!fset) cl[cl.length] = "first-item";
			cl[cl.length] = "basket-summary";
			fc += tdo + this.htAttrib("class", cl.join(" ")) + f.styleValue.createInlineCode() + " nowrap>";
			if(f.render!=null) fc += f.render();
			fc += tdc + trc;
			if(!f.cancel){
				s += fc;
				fset = true;
				}
			else if(i==0) fset = false;
			};
		s += "</TFOOT>";
		};
	s += "</TABLE>";
	s += "</FORM>";
	xc = document.getElementById("basket-buttons"); if(xc) xc.style.display = ((xb.selectNodes(_SMPrd).length()!=0) ? "inline" : "none");
	return(s);
	};

cSMBasketGUI.prototype.renderXML = function(){
var dom = new SXMLDom(), xc = p = c = f = xf = null;
	with(dom){
		documentElement = createNode("SMBasketXML");
		with(documentElement){
			with(appendChild(dom.createNode("SMColumns"))){
				for(var i=0; i<this.columns.length; i++){
					c = this.columns[i]; c.index = i; c.product = p;
					with(appendChild(dom.createNode("SMColumn"))){
						setAttribute("id", c.id);
						setAttribute("caption", c.caption);
						};
					};
				};
			with(appendChild(dom.createNode("SMPositions"))){
				xb = this.basket.xml.selectNodes(_SMPrd);
				for(var i=0; i<xb.length(); i++){
					xc = xb.item(i);
					p = new cSMProduct(_SMPrd); p.shop = this.shop; p.basket = this.basket; p.parent = this.basket; p.init(xc);
					with(appendChild(dom.createNode("SMPosition"))){
						for(var j=0; j<this.columns.length; j++){
							c = this.columns[j]; c.index = i; c.product = p;
							with(appendChild(dom.createNode("SMColumn"))){
								setAttribute("id", c.id);
								if(c.renderXML!=null){
									text = c.renderXML();
									}
								else if(c.render!=null) text = c.render();
								};
							};
						};
					};
				};
			with(appendChild(dom.createNode("SMFooterItems"))){
				for(var i=0; i<this.footerItems.length; i++){
					f = this.footerItems[i]; f.basket = f.gui.basket;
					xf = dom.createNode("SMFooterItem");
					with(xf){
						setAttribute("id", f.id);
						setAttribute("caption", f.caption);
						if(f.renderXML!=null){
							text = f.renderXML();
							}
						else if(f.render!=null) text = f.render();
						};
					if(!f.cancel) appendChild(xf);
					};
				};
			};
		};
	return(dom);
	};

cSMBasketGUI.prototype.htAttrib = function(p, v){
var s = "";
	if(p!=""&&v!=""){
		s += " " + p + "=\"";
		s += v + "\"";
		};
	return(s);
	};