//----------------------------------------------------------------------------------------------------------------------------------
var xshoppingcart_js = "xShoppingCart.js";						// Flag to show this js library has been loaded
/*
	SHOPPINGCART
		This javascript object provides the features for embedding shopping cart capabilities
		into web pages.  The object has been written based in part on the prototype and
		related Ajax enabled libraries.

		Author: W. Sietz Copyright 2006
		Copyright (c) 2005 W. Sietz Copyright 2006 (www.FlowTech-Solutions.com)

		Permission is hereby granted, free of charge, to any person obtaining
		a copy of this software and associated documentation files (the
		"Software"), to deal in the Software without restriction, including
		without limitation the rights to use, copy, modify, merge, publish,
		distribute, sublicense, and/or sell copies of the Software, and to
		permit persons to whom the Software is furnished to do so, subject to
		the following conditions:

		The above copyright notice and this permission notice shall be
		included in all copies or substantial portions of the Software.
		
		THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
		EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
		MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
		NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
		LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
		OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
		WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


	REQUIRED LIBRARY COMPONENTS:
		ShoppingCart.Require("script/prototype-1.5.0_rc0.js");		see http://prototype.conio.net for details
		ShoppingCart.Require("script/xEffects.js");							see (http://script.aculo.us, http://mir.aculo.us) for details (requires themes)
		ShoppingCart.Require("script/xString.js");							culmination of String object snippits
		ShoppingCart.Require("script/xCookie.js");							see www.FlowTech-Solutions.com for details
		ShoppingCart.Require("script/xDate.js");							see www.FlowTech-Solutions.com for details
		ShoppingCart.Require("script/xWindow.js");						see (http://xilinus.com, http://itseb.com) for details version 0.85


	CONSIDERATIONS:
		To utilize this facility requires some minimal web page integration and a backend (server based) page
		that processes product information requests and returns a properly formatted XML string.

		Web page integration consists of 3 basic components.

		1.	Script include of this ShoppingCart.js file via use of script tag in the HEAD section of the web page

		2.	Instantiation, Initialization, and Configuration of the ShoppingCart object (s/b injected where mini cart is to be displayed)

			javascript e.g.
				ShoppingCart.Initialize();
				ShoppingCart.token='<%=Session.SessionID%>';		or some other validation token for the xml request page authenication

				// establish callback routine to update mini cart contents on the web page when use changes quantities or removes items from the cart
				ShoppingCart.refresh=refreshcartdisplay;
				function refreshcartdisplay() {
					$("CARTCONTENTS").innerHTML = ShoppingCart.Render();
				}

		3.	Mechanism for the user to add items to the shopping cart

			HTML  e.g. 
				<P><IMG src="images/addtocart.gif" border=0  onclick="AddToShoppingCart('NF','CATALOGVIEW','PRODUCTDETAIL','T1005',1);" />Product Description</P>

			The AddToShoppingCart() can be found at the bottom of this page. This is not part of the formal definition of the ShoppingCart
			but enables the interface between the user click event, retrieval of product info to add and the actual addition of the item to the cart.


	SERVER XML REQUEST PAGE REQUIREMENT:
			A backend page to process XML information requests is required.  The page is used to retrieve product detail information.
			The page can be written in any language and reside on any web server.

			Example URL for making the XML request
				XmlRequest.asp?token=AB2h75Kq8wP&p=NF&s=COMMON&f=PRODUCTDETAIL&k=" + code; 

			Example XML response from the XML request page
				<root>
					<item	Catalog_ID='158' 
								ProductSKU='T1005' 
								ProductName='Rake 8&quot;' 
								ProductDesc='Rake 8&quot; A description of the production. This is displayed in the Product Detail window' 
								ProductThumbNailURL='CATALOG IMAGES/THUMBNAILS/Rake.jpg' 
								ThumbNailAlternateText='Rake' 
								ProductPhotoURL='CATALOG IMAGES/PHOTOS/Rake.jpg' 
								ProductIllustrationURL='' ProductSpecURL='' 
								UnitOfMeasure='EA' UnitListPrice='20' 
								Instock='1' 
								LengthDesc='22.00 Inch' 
								FK_RelatedCode='' 
								Dimensions='' 
								WeightDesc='' 
								/>
				</root>

			The Ajax request to the server XML request page is enabled with a authentication token. The token can be established for the
			shopping cart via the token property.  The server XML request page name can be established via the xmlRequestURL property. 
			Ideally this is an encrypted (using safe base 64 char set) value provided by the backend web server.  This token is then 
			provided with each XML request to the server XML request page.  The request page could then validate the token to ensure its 
			a proper request.

	PUBLIC METHODS:
		Require()				Loads the dedendent libraries
		Initialize()				Initializes the shopping cart, perform this before using any methods
		Count()				Returns the number of items in the shopping cart
		Total()					Returns an estimated dollar value of the shopping cart
		AddItem()				Add an item to the cart via XML string
		Add()					Add an item to the cart via specific product info
		Clear()					Clears all items from the cart
		Render()				Renders a mini cart in HTML format
		ListOfCodes()		Returns an array of codes suitable for use in the SQL IN clause
		ListOfQuantities() Returns an array of codes suitable for use in the SQL
		ShowDetail()		Display a windows with detailed product info
		ShowCart()			Displays the cart contents and allows the user to update its contents
		Xml()					Returns an XML string of the shopping cart contents
		Remove()				Removes an tiem from the shopping cart
		Order_ID(value)	Get/Set Order_ID	 only used if an order has been created from the shopping cart
		OrderNbr(value)	Get/Set OrderNbr only used if an order has been created from the shopping cart

*/


//----------------------------------------------------------------------------------------------------------------------------------
// Create the loadXML method and xml getter for Mozilla
if (window.DOMParser &&
	window.XMLSerializer &&
	window.Node && Node.prototype && Node.prototype.__defineGetter__) {

	// XMLDocument did not extend the Document interface in some versions of Mozilla. Extend both!
	//XMLDocument.prototype.loadXML =
	Document.prototype.loadXML = function (s) {

		// parse the string to a new doc
		var doc2 = (new DOMParser()).parseFromString(s, "text/xml");

		// remove all initial children
		while (this.hasChildNodes())
			this.removeChild(this.lastChild);

		// insert and import nodes
		for (var i = 0; i < doc2.childNodes.length; i++) {
			this.appendChild(this.importNode(doc2.childNodes[i], true));
		}
	};

	/* xml getter
	 * This serializes the DOM tree to an XML String
	 * Usage: var sXml = oNode.xml
	 */
	Document.prototype.__defineGetter__("xml", function () {
		return (new XMLSerializer()).serializeToString(this, "text/xml");
	});
}



//----------------------------------------------------------------------------------------------------------------------------------
var ShoppingCart = {

	//
	// -----------------------------------------------------------------------------------------------------------------------------------------
	//					DATA MEMBERS
	//
	xmlDoc:			null,
	cookiename:		'SC',								// Is used as the cookie name, form field ID
	token:				'TOKEN',							// Token is provided by backend and sent with each server request
	xmlRequestURL:	 'XmlRequest.asp',		// Page to place Xml requests to
	//checkOutURL:	'FormTemplatePage.aspx?module=CHECKOUT',	// URL to navigate to when the user wishes to place the order
	checkOutURL:	'https://www.flowtech-solutions.com/WorldlySecured/FormTemplatePage.aspx?module=CHECKOUT',	// URL to navigate to when the user wishes to place the order
	refresh:			null,									// if a function is provided the shopping cart render is refreshed


	//
	// -----------------------------------------------------------------------------------------------------------------------------------------
	//					PUBLIC METHODS
	//

	//	Require()						Enable the inclusion of dependent library components
	Require: function(libraryName) {
		// inserting via DOM fails in Safari 2.0, so brute force approach
		document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
		},


	//	Initialize()						Establish and initialize the shopping cart to empty
	//		Try loading the shopping cart cookie if available, else load an empty shopping cart
	//		Recommeded use default CookieName = SC
	Initialize:	function (CookieName)	{
		ShoppingCart.cookiename = (!CookieName || typeof(CookieName) == 'undefined' || CookieName=='' ? ShoppingCart.cookiename:CookieName);
		try{

			// try loading the cart from the cookie
			var sc = xCookie.get( ShoppingCart.cookiename );
			if ((!sc  ||  sc=='') && $(ShoppingCart.cookiename))	 {
				// if no cookie and the form field by the same ID exists, collect from the field
				var fld = $(ShoppingCart.cookiename);
				if (fld && fld.value)  sc = fld.value;
				else if (fld && fld.innerText)	sc = fld.innerText;
				else if (fld && fld.innerHTML) sc = fld.innerHTML;
				}

			// If no cookie and no field then create an empty shopping cart
			if (!sc  ||  sc=='')	{
				var dt = new Date;	// get current date
				dt.add('d',30);			// add 30 days to current date
				sc = '<?xml version="1.0" encoding="ISO-8859-1"?><cart expires="' + dt.format("MM/dd/yyyy") + '" total="0.00"></cart>';
				}

			// Establish an XML document object to hold the shopping cart contents
/*
			ShoppingCart.xmlDoc = new createXMLDocument();
			ShoppingCart.xmlDoc.loadXML(sc);
*/

			if ( document.implementation && document.implementation.createDocument )	{
				// Mozilla (ie. Firefox) based
				ShoppingCart.xmlDoc=document.implementation.createDocument("","",null);
				if (!ShoppingCart.xmlDoc) throw "Mozilla Browser is not providing XML document support.";

				// some versions of Moz do not support the readyState property
				// and the onreadystate event so we patch it!
				if (ShoppingCart.xmlDoc.readyState == null) {
					ShoppingCart.xmlDoc.readyState = 1;
					var self = this;
					ShoppingCart.xmlDoc.addEventListener("load", function () {
						self.xmlDoc.readyState = 4;
						if (typeof self.xmlDoc.onreadystatechange == "function")
							self.xmlDoc.onreadystatechange();
						}, false);
					}				

				ShoppingCart.xmlDoc.onload= function () {return (parent.xmlDoc.readyState == 4 ? true:false);};
				ShoppingCart.xmlDoc.loadXML(sc);
				}
			else if (window.ActiveXObject)	{
				// IE browser
				ShoppingCart.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
				if (!ShoppingCart.xmlDoc) throw "IE Browser is not providing XML document support.";
				self = this;
				ShoppingCart.xmlDoc.onreadystatechange = function ()  {return (ShoppingCart && ShoppingCart.xmlDoc && ShoppingCart.xmlDoc.readyState && ShoppingCart.xmlDoc.readyState == 4 ? true:false); };
				ShoppingCart.xmlDoc.async="false";
				if ( !ShoppingCart.xmlDoc.loadXML(sc) )
					throw "xmlDoc.LoadXML('"+sc+"') ERROR: bad xml form.";
				}
			else
				{
				throw "Browser does not provide xml document support";
				ShoppingCart.xmlDoc=null;
				}

			// Save the empty shopping cart to a cookie as well as hidden form field (if exists as back up for lack of support for browser cookies)
			xCookie.set(ShoppingCart.cookiename, ShoppingCart.xmlDoc.xml);

			// Save the shopping cart into the form field if it exists.			
			var fld = $(ShoppingCart.cookiename);
			if (fld && fld.value)  fld.value = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerText)	fld.innerText = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerHTML)	fld.innerHTML = ShoppingCart.xmlDoc.xml;

			return true;
			}
		catch (err)	 {
			alert("Error: Initialize('"+CookieName+"')  " + err.description + ".  Could not establish the Shopping Cart" );
			}

		return false;
	},


	// Count()					returns the number of items in the shopping cart		(Read Only)
	Count:	function ()	{
			if (!ShoppingCart.xmlDoc) return 0;
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if (!Cart) return 0;
			var i;
			var items = Cart.getElementsByTagName("item");
			for (i=0; i<items.length; i++);
			return i;
	},


	// Total()				returns an estimate the shopping cart total  (does not include tax, freight, etc)				(Read Only)
	Total:	function ()	{
			if (!ShoppingCart.xmlDoc) return 0.0;
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if (!Cart) return 0.0;
			var CartTotal = Cart.getAttribute("total");
			CartTotal = (!CartTotal || isNaN(CartTotal) ? 0.0:parseFloat(CartTotal));
			return CartTotal;
	},


	// Order_ID()				set/get method for Order_ID if already established for the shopping cart
	Order_ID:	function ()	{
		if (arguments.length == 0)	 {
			// get method
			if (!ShoppingCart.xmlDoc) return "";
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if (!Cart) return "";
			var AttribValue = Cart.getAttribute("order_id");
			return AttribValue;
		} else {
			// set method
			if (!ShoppingCart.xmlDoc) ShoppingCart.xmlDoc=ShoppingCart.Initialize();
			var Cart = (ShoppingCart.xmlDoc ? ShoppingCart.xmlDoc.getElementsByTagName("cart")[0] : null);
			if (!ShoppingCart.xmlDoc || !Cart ) throw "Error: ShoppingCart.Order_ID(" + arguments[0] + ") Unable to set value.";
			Cart.setAttribute("order_id",arguments[0]);

			// Save the cart to the cookie and the hidden field
			xCookie.set( ShoppingCart.cookiename, ShoppingCart.xmlDoc.xml );
			var fld = $(ShoppingCart.cookiename);
			if (fld && fld.value)  fld.value = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerText)	fld.innerText = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerHTML)	fld.innerHTML = ShoppingCart.xmlDoc.xml;

			var AttribValue = Cart.getAttribute("order_id");
			return AttribValue;
			}
	},


	// OrderNbr()				set/get method for OrderNbr if already established for the shopping cart
	OrderNbr:	function ()	{
		if (arguments.length == 0)	 {
			// get method
			if (!ShoppingCart.xmlDoc) return "";
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if (!Cart) return "";
			var AttribValue = Cart.getAttribute("ordernbr");
			return AttribValue;
		} else {
			// set method
			if (!ShoppingCart.xmlDoc) ShoppingCart.xmlDoc=Initialize();
			var Cart = (ShoppingCart.xmlDoc ? ShoppingCart.xmlDoc.getElementsByTagName("cart")[0] : null);
			if (!ShoppingCart.xmlDoc || !Cart ) throw "Error: ShoppingCart.OrderNbr(" + arguments[0] + ") Unable to set value.";
			Cart.setAttribute("ordernbr",arguments[0]);

			// Save the cart to the cookie and the hidden field
			xCookie.set( ShoppingCart.cookiename, ShoppingCart.xmlDoc.xml );
			var fld = $(ShoppingCart.cookiename);
			if (fld && fld.value)  fld.value = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerText)	fld.innerText = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerHTML)	fld.innerHTML = ShoppingCart.xmlDoc.xml;

			var AttribValue = Cart.getAttribute("ordernbr");
			return AttribValue;
			}
	},



	// AddItem()		adds an item to the shopping cart based on the xml string containing <item> element
	AddItem: function (quantity, xmlstring) { 
		if (!ShoppingCart.xmlDoc) ShoppingCart.Initialize();
		if (!ShoppingCart.xmlDoc) throw "Shopping Cart could not be established";
		var xmlItem = null;
		try	{
				// Establish an XML document object to hold the shopping cart contents
				if ( document.implementation && document.implementation.createDocument )	{
					// Mozilla (ie. Firefox) based
					xmlItem=document.implementation.createDocument("","",null);
					if (!xmlItem) throw "Mozilla Browser is not providing XML document support.";

					// some versions of Moz do not support the readyState property
					// and the onreadystate event so we patch it!
					if (xmlItem.readyState == null) {
						xmlItem.readyState = 1;
						xmlItem.addEventListener("load", function () {
							parent.xmlItem.readyState = 4;
							if (typeof parent.xmlItem.onreadystatechange == "function")
								parent.xmlItem.onreadystatechange();
							}, false);
						}				
					xmlItem.onload= function () {return (parent.xmlItem.readyState == 4 ? true:false);};
					xmlItem.loadXML(xmlstring);
					}
				else if (window.ActiveXObject)	{
					// IE browser
					xmlItem=new ActiveXObject("Microsoft.XMLDOM");
					if (!xmlItem) throw "IE Browser is not providing XML document support.";
					xmlItem.onreadystatechange = function () {return (parent.xmlItem.readyState == 4 ? true:false); };
					xmlItem.async="false";
					if ( !xmlItem.loadXML(xmlstring) )
						//alert( "xmlItem.LoadXML('"+xmlstring+"') ERROR: bad xml form." );
						throw "BAD XML FORMAT";
					}
				else
					{
					throw ( "Browser does not provide xml document support" );
					}
				}
		catch (err)	{
				//alert("AddItem()  Error: " + err.description  + '   xmlstring=' + xmlstring );
				alert("We appologize, but this feature is unavailable at the moment. Product could not be retrieved."); 
				return false;
				}

		var items = xmlItem.getElementsByTagName("item"); 
		if (items.length == 0)	{
			alert("We appologize, but this feature is unavailable at the moment. Product not found."); 
			return false;
			}
		Dialog.info("The item has been added to your shopping cart.", {windowParameters: {width:250, height:55}}); 
		setTimeout("Dialog.closeInfo()", 1300); 
		try	{
				var item = items[0]; 
				var Catalog_ID = (item.getAttribute("Catalog_ID") ? item.getAttribute("Catalog_ID"):"0"); 
				var ProductSKU = (item.getAttribute("ProductSKU") ? item.getAttribute("ProductSKU"):""); 
				var ProductName = (item.getAttribute("ProductName") ? item.getAttribute("ProductName"):""); 
				var ProductDesc = (item.getAttribute("ProductDesc") ? item.getAttribute("ProductDesc"):""); 
				var ProductThumbNailURL = (item.getAttribute("ProductThumbNailURL") ? item.getAttribute("ProductThumbNailURL"):""); 
				var ThumbNailAlternateText = (item.getAttribute("ThumbNailAlternateText") ? item.getAttribute("ThumbNailAlternateText"):""); 
				var ProductPhotoURL = (item.getAttribute("ProductPhotoURL") ? item.getAttribute("ProductPhotoURL"):""); 
				var ProductIllustrationURL = (item.getAttribute("ProductIllustrationURL") ? item.getAttribute("ProductIllustrationURL"):""); 
				var ProductSpecURL = (item.getAttribute("ProductSpecURL") ? item.getAttribute("ProductSpecURL"):""); 
				var UnitOfMeasure = (item.getAttribute("UnitOfMeasure") ? item.getAttribute("UnitOfMeasure"):"EA"); 
				var UnitListPrice = (item.getAttribute("UnitListPrice") ? item.getAttribute("UnitListPrice"):"0"); 
				var Instock = (item.getAttribute("Instock") ? item.getAttribute("Instock"):"0"); 
				var LengthDesc = (item.getAttribute("LengthDesc") ? item.getAttribute("LengthDesc"):""); 
				var FK_RelatedCode = (item.getAttribute("FK_RelatedCode") ? item.getAttribute("FK_RelatedCode"):""); 
				var Dimensions = (item.getAttribute("Dimensions") ? item.getAttribute("Dimensions"):""); 
				var WeightDesc = (item.getAttribute("WeightDesc") ? item.getAttribute("WeightDesc"):""); 
				quantity = (!quantity || isNaN(quantity) ? 0:parseFloat(quantity)); 
				UnitListPrice = (!UnitListPrice || isNaN(UnitListPrice) ? 0:parseFloat(UnitListPrice)); 
				ShoppingCart.Add(ProductSKU,ProductName,quantity,UnitOfMeasure,UnitListPrice); 
				$("CARTCONTENTS").innerHTML = ShoppingCart.Render(); 
				}
		catch (err)	{
				alert("AddItem() Error: " + err.description + ' Data Issue');
				return false;
				}
		}, 


	//	Add(code,name,qty,um,unitprice)	
	Add:	function (code,name,quantity,untmeas,unitprice)		{
		try{
			if (!ShoppingCart.xmlDoc) ShoppingCart.Initialize();
			if (!ShoppingCart.xmlDoc) throw "Shopping Cart could not be established";
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if (!Cart) throw "Shopping Cart has been corrupted";
			var CartTotal = Cart.getAttribute("total");
			CartTotal = (!CartTotal || isNaN(CartTotal) ? 0.0:parseFloat(CartTotal));

			// Data scrub the parameters
			code = (!code ? "":code);
			name = (!name ? "":name) ;
			quantity = (!quantity || isNaN(quantity) ? 0:parseFloat(quantity));
			untmeas = (!untmeas ? "EA":untmeas);
			unitprice = (!unitprice || isNaN(unitprice) ? 0:parseFloat(unitprice));

			// Determine if item is already in the shopping cart, if so update the quantity
			var i;
			var items = Cart.getElementsByTagName("item");
			for (i=0; i<items.length && items[i].getAttribute("code")!=code; i++);
			if (i<items.length && items[i].getAttribute("code")==code)	{
				// Item exists in the shopping cart, update the quantity, unitprice
				var _quantity = (items[i].getAttribute("quantity") ? items[i].getAttribute("quantity"):0);
				var _unitprice = (items[i].getAttribute("unitprice") ? items[i].getAttribute("unitprice"):0), 
				_quantity = (!_quantity || isNaN(_quantity) ? 0:parseFloat(_quantity));
				_unitprice = (!_unitprice || isNaN(_unitprice) ? 0:parseFloat(_unitprice));
				var _itemtotal = _quantity * _unitprice;
				_quantity += quantity;
				_unitprice = (unitprice!=0 && _unitprice==0 ? unitprice:_unitprice);
				var itemtotal = _quantity * _unitprice;

				items[i].setAttribute("quantity", _quantity );
				items[i].setAttribute("unitprice",  "%-.2f".format(_unitprice));
				items[i].setAttribute("itemtotal", "%-.2f".format(itemtotal));

				CartTotal += itemtotal - _itemtotal;
				Cart.setAttribute("total","%-.2f".format(CartTotal));
				return true;
				}

			// Add a NEW item to the shopping cart
			var item = ShoppingCart.xmlDoc.createElement("item");
			item.setAttribute("code", code );
			item.setAttribute("pname", name );
			item.setAttribute("quantity", quantity );
			item.setAttribute("untmeas", untmeas );
			item.setAttribute("unitprice", "%-.2f".format(unitprice));
			item.setAttribute("itemtotal", "%-.2f".format(quantity * unitprice));
			Cart.appendChild(item);
			CartTotal += quantity * unitprice;
			Cart.setAttribute("total","%-.2f".format(CartTotal));

			// Save the cart to the cookie and the hidden field
			xCookie.set( ShoppingCart.cookiename, ShoppingCart.xmlDoc.xml );
			var fld = $(ShoppingCart.cookiename);
			if (fld && fld.value)  fld.value = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerText)	fld.innerText = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerHTML)	fld.innerHTML = ShoppingCart.xmlDoc.xml;

			return true;
			}
		catch (err)
			{
			alert("Add()  Error: " + err.description);
			return false;
			}
		},


	//	Remove	(code,name,qty,um,unitprice)	
	Remove:	function (fieldname, fieldvalue)	{
		try{
			if (!fieldname || fieldname==''  || !fieldvalue)	return false;						// missing arguments
			if ("code,name,qty,um,unitprice,itemtotal".indexof(fieldname) < 0)	return false;		// unrecognized fieldname
			if (!ShoppingCart.xmlDoc) return true;			// no shopping cart, no items to remove
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if (!Cart) return true;				// no items in the shopping cart, nothing to remove

			var CartTotal = Cart.getAttribute("total");
			CartTotal = (!CartTotal || isNaN(CartTotal) ? 0.0:parseFloat(CartTotal));

			// Data scrub the parameters
			code = (!code ? "":code);
			name = (!name ? "":name) ;
			quantity = (!quantity || isNaN(quantity) ? 0:parseFloat(quantity));
			untmeas = (!untmeas ? "EA":untmeas);
			unitprice = (!unitprice || isNaN(unitprice) ? 0:parseFloat(unitprice));

			// Determine if item is already in the shopping cart, if so update the quantity
			var i;
			var items = Cart.getElementsByTagName("item");
			for (i=0; i<items.length && items[i].getAttribute(fieldname)!=fieldvalue; i++);
			if (i<items.length && items[i].getAttribute(fieldname)==fieldvalue)	{
				// Item exists in the shopping cart, remove it
				var itemtotal = (items[i].getAttribute("itemtotal") ? items[i].getAttribute("itemtotal"):0.0);
				CartTotal -= itemtotal;
				Cart.setAttribute("total","%-8.2f".format(CartTotal));
				Cart.removeChild(item[i]);
				}
			if (ShoppingCart.Count() == 0){
				ShoppingCart.Clear();
				}
			return true;
			}
		catch (err)
			{
			alert("Remove()  Error: " + err.description);
			return false;
			}
		},


	//	Clear()					Clear the shopping cart contents
	Clear:	function ()		{
		try{
			xCookie.remove(ShoppingCart.cookiename);
			if (!ShoppingCart.xmlDoc) ShoppingCart.Initialize();
			ShoppingCart.Order_ID('');
			ShoppingCart.OrderNbr('');
			var fld = $(ShoppingCart.cookiename);
			if (fld && fld.value)  fld.value = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerText)	fld.innerText = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerHTML)	fld.innerHTML = ShoppingCart.xmlDoc.xml;
			return true;
			}
		catch (err)
			{
			alert("Clear()  Error: " + err.description);
			return false;
			}
		},


	//	Render()	
	//		Returns a small HTML table listing cart contents  Qty UM, Name
	//		Enable a hyperlink using ShopDetail() to display product detail
	//		passing an argument value of "NOCHECKOUT" disables the checkout process
	Render:	function ()	{
		var HTML = '';
		try{
			if (!ShoppingCart.xmlDoc) ShoppingCart.Initialize();
			if (!ShoppingCart.xmlDoc) return '';
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if ( !Cart ) return '';
			// Pull the shopping cart items	from the xmlDoc and assemble into an HTML table
			var CartTotal = 0;
			HTML =	'<TABLE cellSpacing=0 cellPadding=1 width="140px" bgcolor=#ffffcc style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid; FONT-SIZE: 7pt; BORDER-LEFT: black thin solid; BORDER-BOTTOM: black thin solid; FONT-FAMILY: Arial, Verdana, Tahoma;">' +
						'<TR><TD style="BORDER-BOTTOM: black thin solid"><IMG src="images/ShoppingCart.gif" height="22px" border=0 title="View Shopping Cart and Checkout" onclick="ShoppingCart.ShowCart();"/></TD>' + 
							'<TD style="BORDER-BOTTOM: black thin solid" align=right><IMG src="images/CheckOut.gif" border=0  title="View Shopping Cart and Checkout" ' + (arguments.length==0 || arguments[0]!="NOCHECKOUT" ? 'onclick="ShoppingCart.ShowCart();"':"") + ' /></TD></TR>';
			var items = Cart.getElementsByTagName("item");
			if (items.length == 0) return '';
			for (var i=0; i<items.length; i++)	{
				var item = {	"code":			(items[i].getAttribute("code")), 
									"name":		(items[i].getAttribute("pname") ? items[i].getAttribute("pname"):""), 
									"quantity":	(items[i].getAttribute("quantity") ? items[i].getAttribute("quantity"):"0"), 
									"untmeas":	(items[i].getAttribute("untmeas") ? items[i].getAttribute("untmeas"):"EA"), 
									"unitprice":	(items[i].getAttribute("unitprice") ? items[i].getAttribute("unitprice"):"0.00"), 
									"itemtotal":	((isNaN(items[i].getAttribute("quantity")+"0") ? 0:parseFloat(items[i].getAttribute("quantity")+"0")) * (isNaN(items[i].getAttribute("unitprice")+"0") ? 0:parseFloat(items[i].getAttribute("unitprice")+"0")))
								};
				HTML += '<TR><TD valign="top">' +item.quantity + '&nbsp;' + item.untmeas + '</TD>' +
									'<TD valign="top">&nbsp;<A href="" title="Click to view product details." onclick="ShoppingCart.ShowDetail(\''+item.code+'\'); return false;">' + item.name + '</A></TD></TR>';
				CartTotal += item.itemtotal;
				}
			HTML += "</TABLE>";
			HTML += '<INPUT id="SC" name="SC" type="hidden" value="" />';
			}
		catch (err)
			{
			alert("ShoppingCart.Render() Error: " + err.description + "\n");
			}
		 return HTML;
		},


	//	Xml()				Returns an XML string of the shopping cart contents
	Xml:	function ()	{
		if (ShoppingCart.xmlDoc && ShoppingCart.xmlDoc.xml) 
			return ShoppingCart.xmlDoc.xml;
		return '';
	},


	// ShowDetail()
	//		Retrieves product detail information from the backend server via   the XML request page specified in ShoppingCart.xmlRequestURL
	//		and displays an embedded window with the product detail
	//		http://localhost/WorldlyTreasures/xmlrequest.asp?token=SNHDJTYE&p=WT&s=COMMON&f=PRODUCTDETAIL&k=N1000
	ShowDetail: function (code) { 
		var params = "token=" + ( ShoppingCart.token ? ShoppingCart.token:"") +"&p=WT&s=COMMON&f=PRODUCTDETAIL&k=" + code; 
		var req = new Ajax.Request(ShoppingCart.xmlRequestURL,	{method: "get",  parameters: params, onSuccess: ShoppingCart._ShowDetailWindow, onFailure: ShoppingCart._ShowAjaxError }  ); 
		},


	//	ShowCart()	
	//		DIsplays a popup window displaying cart contents and allows user to change qty or remove an item
	ShowCart:	function ()	{
		var HTML = '';
		try{
			if (!ShoppingCart.xmlDoc) ShoppingCart.Initialize();
			if (!ShoppingCart.xmlDoc) return '';
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if ( !Cart ) return '';

			// Display shopping cart items	and allow the user to change the quantity
			var SubTotal = 0;
			HTML ='<FORM ID=frm>' +
						'<DIV align=center style="font-weight:700; FONT-SIZE:12pt; COLOR:Black; FONT-FAMILY: Arial, Verdana, Tahoma;">Shopping Cart</DIV>' +
						'<TABLE style="font-weight: medium; FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: Arial, Verdana, Tahoma;" cellspacing="0" cellpadding="3" align="center" border="0">' + 
						'<TR style="background-color:#D0D0D0">' +
								'<TD style="BORDER-BOTTOM: black thin solid; BORDER-RIGHT: black thin solid" align=center width="33px"><IMG src="images/trash.gif" border=0 title="Click the X in this column to remove the item from the Shopping Cart."/></TD>' +
								'<TD style="BORDER-BOTTOM: black thin solid; BORDER-RIGHT: black thin solid" align=left width="75px">ITEM#</TD>' + 
								'<TD style="BORDER-BOTTOM: black thin solid; BORDER-RIGHT: black thin solid" align=left width="200px">ITEM NAME</TD>' + 
								'<TD style="BORDER-BOTTOM: black thin solid; BORDER-RIGHT: black thin solid" align=center width="60px">QUANTITY</TD>' + 
								'<TD style="BORDER-BOTTOM: black thin solid; BORDER-RIGHT: black thin solid" align=right width="65px">UNIT PRICE&nbsp;</TD>' + 
								'<TD style="BORDER-BOTTOM: black thin solid" align=right width="65px">TOTAL&nbsp;</TD>' + 
						'</TR>';
			var items = Cart.getElementsByTagName("item");
			//if (items.length == 0) return '';
			for (var i=0; i<items.length; i++)	{
				var item = {	"code":			(items[i].getAttribute("code") ? items[i].getAttribute("code"):""), 
									"name":		(items[i].getAttribute("pname") ? items[i].getAttribute("pname"):""), 
									"quantity":	(items[i].getAttribute("quantity") ? items[i].getAttribute("quantity"):0), 
									"untmeas":	(items[i].getAttribute("untmeas") ? items[i].getAttribute("untmeas"):"EA"), 
									"unitprice":	(items[i].getAttribute("unitprice") ? items[i].getAttribute("unitprice"):0.0), 
									"itemtotal":	((isNaN(items[i].getAttribute("quantity")+"") ? 0:parseFloat(items[i].getAttribute("quantity")+"")) * (isNaN(items[i].getAttribute("unitprice")+"") ? 0:parseFloat(items[i].getAttribute("unitprice"))))
								};
				HTML+='<TR style="background-color:#E0E0E0" ID="TR' + i + '">' +
									'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=center width="33px"><IMG src="images/deletefromcart.gif" onclick="ShoppingCart._ShowCartDeleteItem('+i+','+item.unitprice+'); " border=0  title="Click here to remove the item from Cart"/></TD>' +
									'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=left width="75px">' + item.code + '</TD>' + 
									'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=left width="200px">' + item.name + '</TD>' + 
									'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=center width="60px"><INPUT type="text" value="' + item.quantity + '" ID="Q' + i + '" onblur="ShoppingCart._ShowCartRecalcTotal('+i+','+item.unitprice+','+item.quantity+'); "  maxlength=7 size=7 width="52px" style="background-color:White" title="Change the quantity as needed. 0 quantity items are dropped."/></TD>' + 
									'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=right width="65px"><SPAN ID="P' + i + '">' + item.unitprice + '</SPAN>' + item.untmeas + '</TD>' + 
									'<TD style="BORDER-TOP: black thin solid" align=right width="65px"><SPAN ID="S' + i + '">' + ShoppingCart._Number2(item.itemtotal) + '</SPAN></TD>' + 
							'</TR>';
				SubTotal += item.itemtotal;
				}
			HTML+='<TR style="background-color:#D0D0D0">' +
								'<TD style="BORDER-TOP: black thin solid" align=center width="33px">&nbsp;</TD>' +
								'<TD style="BORDER-TOP: black thin solid" align=left width="75px">&nbsp;</TD>' + 
								'<TD style="BORDER-TOP: black thin solid" align=left width="200px">&nbsp;</TD>' + 
								'<TD style="BORDER-TOP: black thin solid" align=center width="60px">&nbsp;</TD>' + 
								'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=right width="65px">SUBTOTAL&nbsp;</TD>' + 
								'<TD style="BORDER-TOP: black thin solid" align=right width="65px"><SPAN ID="T">' + ShoppingCart._Number2(SubTotal) + '</SPAN></TD>' + 
						'</TR>' +
						'<TR style="background-color:Gainsboro">' +
								'<TD align=center width="33px">&nbsp;</TD>' +
								'<TD align=left width="335px" colspan="3" style="FONT-WEIGHT: thin; FONT-SIZE: 7pt; COLOR: black; FONT-FAMILY: Arial, Verdana, Tahoma;">Shipping and Handling costs are additional and calculated based on ship-to address and method of delivery.</TD>' + 
								'<TD style="BORDER-TOP: black thin solid; BORDER-RIGHT: black thin solid" align=center width="65px">S&nbsp;&amp;&nbsp;H&nbsp;</TD>' + 
								'<TD style="BORDER-TOP: black thin solid" align=right width="65px">TBD</TD>' + 
						'</TR>' +
						'</TABLE>' +
						'</FORM>';
			var win = Dialog.confirm(HTML, {windowParameters: {width:515}, ok:ShoppingCart._Submit, okLabel:"Place Order", cancel:ShoppingCart._Cancel, cancelLabel:"Cancel", showEffectOptions:Effect.Puff}); 
			win.getContent().style.backgroundColor="#E8E8E8";
			}
		catch (err)
			{
			alert("ShowCart() Error: " + err.description + "\n");
			}
		return;
		},


	//	ListOfCodes()	
	//		Returns an array of string values of "code" (ProductSKU), 
	//		Primary purpose is is for use in the  SQL clause IN	(sp_AddItemsToOrder)
	ListOfCodes:	function ()	{
		var Ary = new Array();
		try{
			//if (!ShoppingCart.xmlDoc) ShoppingCart.xmlDoc=Initialize();
			if (!ShoppingCart.xmlDoc) return Ary;
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if ( !Cart ) return '';

			// Pull the shopping cart items	from the xmlDoc and assemble into an HTML table
			var items = Cart.getElementsByTagName("item");
			if (items.length == 0) return '';
			for (var i=0; i<items.length; i++)	{
				Ary[i] = (items[i].getAttribute("code") ? items[i].getAttribute("code"):"");
				}
			}
		catch (err)
			{
			alert("ShoppingCart.ListOfCodes() Error: " + err.description + "\n");
			}
		 return Ary;
		},


	//	ListOfQuantities()	
	//		Returns an array of quantities (same order as ListOfCodes)
	//		Primary purpose is is for use in the  SQL (sp_AddItemsToOrder)
	ListOfQuantities:	function ()	{
		var Ary = new Array();
		try{
			//if (!ShoppingCart.xmlDoc) ShoppingCart.xmlDoc=ShoppingCart.Initialize();
			if (!ShoppingCart.xmlDoc) return Ary;
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if ( !Cart ) return '';

			// Pull the shopping cart items	from the xmlDoc and assemble into an HTML table
			var items = Cart.getElementsByTagName("item");
			if (items.length == 0) return '';
			for (var i=0; i<items.length; i++)	{
				Ary[i] = (items[i].getAttribute("quantity") ? items[i].getAttribute("quantity"):"");
				}
			}
		catch (err)
			{
			alert("ShoppingCart.ListOfQuantities() Error: " + err.description + "\n");
			}
		 return Ary;
		},

	//
	// -----------------------------------------------------------------------------------------------------------------------------------------
	//					PRIVATE METHODS
	//


	// _ShowDetailWindow()
	//		Displays the actual window and display information
	_ShowDetailWindow: function (originalRequest) { 
		var xmlstring = originalRequest.responseText; 
		var xmlItem = null;
		try	{// Establish an XML document object to hold the shopping cart contents
				if ( document.implementation && document.implementation.createDocument )	{
					// Mozilla (ie. Firefox) based
					xmlItem=document.implementation.createDocument("","",null);
					if (!xmlItem) throw "Mozilla Browser is not providing XML document support.";

					// some versions of Moz do not support the readyState property
					// and the onreadystate event so we patch it!
					if (xmlItem.readyState == null) {
						xmlItem.readyState = 1;
						xmlItem.addEventListener("load", function () {
							parent.xmlItem.readyState = 4;
							if (typeof parent.xmlItem.onreadystatechange == "function")
								parent.xmlItem.onreadystatechange();
							}, false);
						}				

					xmlItem.onload= function () {return (parent.xmlItem.readyState == 4 ? true:false);};
					xmlItem.loadXML(xmlstring);
					}
				else if (window.ActiveXObject)	{
					// IE browser
					xmlItem=new ActiveXObject("Microsoft.XMLDOM");
					if (!xmlItem) throw "IE Browser is not providing XML document support.";
					xmlItem.onreadystatechange = function () {return (xmlItem.readyState == 4 ? true:false); };
					xmlItem.async="false";
					if ( !xmlItem.loadXML(xmlstring) )
						throw "xmlItem.LoadXML('"+xmlstring+"') ERROR: bad xml form.";
					}
				else	{
					throw "Browser does not provide xml document support";
					}
				}
		catch (err)	{
				alert("ShowProductInfo() Error: " + err.description + "   xmlstring=" + xmlstring );
				return false;
				}
		var items = xmlItem.getElementsByTagName("item"); 
		if (items.length == 0)	{
			alert("We appologize, but this feature is unavailable at the moment. Product could not be retrieved."); 
			}
		var item = items[0]; 
		var Catalog_ID = (item.getAttribute("Catalog_ID") ? item.getAttribute("Catalog_ID"):"0"); 
		var ProductSKU = (item.getAttribute("ProductSKU") ? item.getAttribute("ProductSKU"):""); 
		var ProductName = (item.getAttribute("ProductName") ? item.getAttribute("ProductName"):""); 
		var ProductDesc = (item.getAttribute("ProductDesc") ? item.getAttribute("ProductDesc"):""); 
		var ProductThumbNailURL = (item.getAttribute("ProductThumbNailURL") ? item.getAttribute("ProductThumbNailURL"):""); 
		var ThumbNailAlternateText = (item.getAttribute("ThumbNailAlternateText") ? item.getAttribute("ThumbNailAlternateText"):""); 
		var ProductPhotoURL = (item.getAttribute("ProductPhotoURL") ? item.getAttribute("ProductPhotoURL"):""); 
		var ProductIllustrationURL = (item.getAttribute("ProductIllustrationURL") ? item.getAttribute("ProductIllustrationURL"):""); 
		var ProductSpecURL = (item.getAttribute("ProductSpecURL") ? item.getAttribute("ProductSpecURL"):""); 
		var UnitOfMeasure = (item.getAttribute("UnitOfMeasure") ? item.getAttribute("UnitOfMeasure"):"EA"); 
		var UnitListPrice = (item.getAttribute("UnitListPrice") ? item.getAttribute("UnitListPrice"):"0"); 
		var Instock = (item.getAttribute("Instock") ? item.getAttribute("Instock"):"0"); 
		var LengthDesc = (item.getAttribute("LengthDesc") ? item.getAttribute("LengthDesc"):""); 
		var FK_RelatedCode = (item.getAttribute("FK_RelatedCode") ? item.getAttribute("FK_RelatedCode"):""); 
		var Dimensions = (item.getAttribute("Dimensions") ? item.getAttribute("Dimensions"):""); 
		var WeightDesc = (item.getAttribute("WeightDesc") ? item.getAttribute("WeightDesc"):""); 
		var fUnitListPrice = (!UnitListPrice || isNaN(UnitListPrice) ? 0:parseFloat(UnitListPrice)); 
		fUnitListPrice = "%-9.2f".format(fUnitListPrice);

		var URLbase = location.protocol + '//' + location.host + '/'  + location.pathname;
		URLbase = URLbase.substr(0,URLbase.lastIndexOf("/")+1);
		ProductThumbNailURL = encodeURI(URLbase + ProductThumbNailURL);
		ProductPhotoURL = encodeURI(URLbase + ProductPhotoURL);
		ProductIllustrationURL = encodeURI(URLbase + ProductIllustrationURL);
		ProductSpecURL = encodeURI(URLbase + ProductSpecURL);

		var click="";
		if (ProductIllustrationURL != encodeURI(URLbase))	{
			click=' onclick="	if ($(\'PI\').src == \'' + ProductIllustrationURL + '\') {$(\'PI\').src=\'' + ProductPhotoURL + '\';} else {$(\'PI\').src=\'' + ProductIllustrationURL + '\';}"  >' +
				'<BR>&nbsp;<I>Click on the image to see a close up.</I>';
			}
		var popwincontents=	
			"<TABLE style='FONT-WEIGHT: medium; FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Arial, Verdana, Tahoma' 	cellSpacing='2' cellPadding='3' width='100%' align='center' border='0'>" + 
			"	<TR><TD vAlign='center' align='center' width='210px'><IMG ID=PI BorderStyle='Outset' BorderColor='#FFFFFF' BorderWidth='5px' src='"+ProductPhotoURL+"' Width='205' "+click+"</IMG></TD>" +
			"		<TD vAlign='top' align='left'><B>ITEM#</B>&nbsp;"+ProductSKU+"<BR><BR>" + 
							"<B>NAME:</B>&nbsp;"+ProductName+"<BR><BR>" + 
							"<B>DESCRIPTION:</B>&nbsp;"+ProductDesc+"<BR>" + 
							Dimensions+"&nbsp;"+LengthDesc+"<BR><BR>" + 
							"<B>PRICE:</B>&nbsp;$"+fUnitListPrice+"<BR></TD></TR>" +
			"</TABLE>";
		var win = Dialog.alert(popwincontents, {windowParameters: {maxWidth:525}}); 
		},


	_ShowAjaxError: function (originalRequest, exception) { 
		alert("We appologize, but this feature is unavailable at the moment."); 
		alert(originalRequest.responseText);
		},


	// User selected PLACE ORDER button on the ShowCart() window
	_Submit: function()	{
		ShoppingCart._ShowCartSave();
		if (typeof ShoppingCart.refresh == 'function') ShoppingCart.refresh();
		if (ShoppingCart.Count() == 0) return false;
		var Order_ID = ShoppingCart.Order_ID();
		if (!Order_ID || Order_ID=="")	
			parent.location.href=ShoppingCart.checkOutURL + "&ACTION=EDIT&ID=0";
		else
			parent.location.href=ShoppingCart.checkOutURL + "&ACTION=EDIT&ID=" + 	Order_ID;
		return true;
	},


	// User cancelled from the Cart View, but will save quantity changes anyway
	_Cancel: function()	{
		ShoppingCart._ShowCartSave();
		if (typeof ShoppingCart.refresh == 'function') ShoppingCart.refresh();
		return true;
	},


	// ShowCart save helper routine     (used by ShowCart)
	_ShowCartSave: function()	{
		try{
			if (!ShoppingCart.xmlDoc) ShoppingCart.Initialize();
			if (!ShoppingCart.xmlDoc) return true;
			var Cart = ShoppingCart.xmlDoc.getElementsByTagName("cart")[0];
			if ( !Cart ) return true;

			// Extract Quantities from popup and apply to shopping cart
			var CartTotal = 0;
			var items = Cart.getElementsByTagName("item");
			for (var i=items.length-1; i>=0; i--)	{
				var qtyelm = $("Q"+i);
				if (qtyelm && qtyelm.value)	 {
					var quantity = (isNaN(qtyelm.value) ? 0:parseInt(qtyelm.value));
					if (quantity!=0) {
						items[i].setAttribute("quantity",quantity);
						var prcelm = $("P"+i);
						if (prcelm && prcelm.innerHTML)	 {
							var unitprice = parseFloat(prcelm.innerHTML);
							CartTotal += quantity * unitprice;
							}
						}
					else {
						// Quantity is 0, remove item from the shopping cart
						Cart.removeChild(items[i]);
						items = Cart.getElementsByTagName("item");
						i = (i>items.length ?  i=items.length:i);
						}
					}
				}
			Cart.setAttribute("total", ShoppingCart._Number2(CartTotal));

			// Save the cart to the cookie and the hidden field
			xCookie.set( ShoppingCart.cookiename, ShoppingCart.xmlDoc.xml );
			var fld = $(ShoppingCart.cookiename);
			if (fld && fld.value)  fld.value = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerText)	fld.innerText = ShoppingCart.xmlDoc.xml;
			else if (fld && fld.innerHTML)	fld.innerHTML = ShoppingCart.xmlDoc.xml;
			}
		catch (err)
			{
			alert("ShowCartSave() Error: " + err.description + "\n");
			}

		return true;
	},


	// Private internal method Formats floating number to 2 decimal places
	_Number2: function (flote)	{
		var t=(Math.round(flote*100)/100).toString();
		t += (t.indexOf(".") < 0 ? ".00000000 ":"00000000 ");
		return (t.substring(0,t.indexOf(".")+1+2));
	},


	// Private internal method to recalcuate the shopping cart total $   (used by ShowCart)
	_ShowCartRecalcTotal: function (i,uprice,oqty){
		var tot=parseFloat(document.getElementById("T").innerHTML);
		var qty=parseInt(document.getElementById("Q"+i).value);
		var itot=qty*uprice;
		document.getElementById("S"+i).innerHTML=ShoppingCart._Number2(itot);
		tot+=(qty-oqty)*uprice;
		document.getElementById("T").innerHTML=ShoppingCart._Number2(tot);
		},

	// Private internal method to perform (virtual) removal of an item from the shopping cart (used by ShowCart)
	_ShowCartDeleteItem: function (i,uprice){
		var tot=parseFloat(document.getElementById("T").innerHTML);
		var qty=parseInt(document.getElementById("Q"+i).value);
		var itot=0;
		tot -= qty*uprice;
		document.getElementById("Q"+i).value="0";
		document.getElementById("S"+i).innerHTML=ShoppingCart._Number2(itot);
		document.getElementById("T").innerHTML=ShoppingCart._Number2(tot);
		document.getElementById("TR"+i).style.display="none";
		}

}


//----------------------------------------------------------------------------------------------------------------------------------
/*
// Load the required library components for the Shopping Cart to work properly
ShoppingCart.Require("script/prototype.js");
ShoppingCart.Require("script/xEffects.js");
ShoppingCart.Require("script/xString.js");
ShoppingCart.Require("script/xCookie.js");
ShoppingCart.Require("script/xDate.js");
ShoppingCart.Require("script/xWindow.js");
//ShoppingCart.Require("script/XMLDocument.js");
*/


//
//	----------------------------------------------------------------------------------------------------------------------------------------------------------------
//				Following routines are a bit more specific to the local page implementation, although
//				we are fairly consistant in our usage via the Dot.Net web template implementation
//				Dot.Net web template is heavily dependent on meta configuration data from the tConfig file (project, section, field, value)


// Create and initialize the shopping cart
//		Usage:	 AddToShoppingCart("NF","CATALOGVIEW","PRODUCTDETAIL","T1035",1);
//													(tConfig.Project, tConfig.Section, tConfig.FieldName, ProductCode, Quantity)
var SelectedQuantity=0;

function AddToShoppingCart(p,s,f,code,quantity)	{ 
	SelectedQuantity=quantity
	var url = 'XMLRequest.asp'; 
	//alert('AddToShoppingCart()  p='+p+'  s='+s+'  f='+f+'  k='+code);
	var params = "token=" + ( ShoppingCart.token ? ShoppingCart.token:"none") + "&p="+p +"&s="+s +"&f="+f +"&k="+code; 
	//alert('AddToShoppingCart()  '+url+'?'+params );
	var req = new Ajax.Request(url,	{method: "get",  parameters: params, onSuccess: AddItemToShoppingCart, onFailure: ShoppingCart._ShowAjaxError }  ); 
} 

function AddItemToShoppingCart (originalRequest) { 
	//alert(originalRequest.responseText);
	ShoppingCart.AddItem(SelectedQuantity, originalRequest.responseText);
}

