//======================================================================
//
//	newdogcart.js
//
//	- written by Jerry Auld, Otago Computing Inc.
//  	- April 20, 2005
//
//	-- This code module handles all the Shopping Cart functionality
//	-- for the NewDog.com website.
//
//	Revision History:
//	- 2005-04-20 -- Initial code. (JA-OCI)
//	- 2005-06-07 -- Initial code after the fastsite rewrite. (JA-OCI)
//	- 2005-06-30 -- Add variables from Quoteform (cart) to Flyer. (JA-OCI)
//	- 2006-05-19 -- Add MinQty and Avail Colours columns to cart for the flyer. (JA-OCI)
//
//----------------------------------------------------------------------


//--- Shopping Cart Structure ------------------------------------------

	// The global Shopping Cart.
	var gscCartND = new Array(new Array(44));

	// The global line structure for each element of the Shopping Cart.
	var gscLineND = new Array(44);


//---Shopping Cart Globals ---------------------------------------------

	var glscGroupID = -1;
	var glscLineID = -1;
	var gfscOnDelete = false;
      var gfscOnEdit = false;

	var gsscCompanyName = 'Company Name';
	var gsscCustomerName = 'Customer Name';
	var gsscCustomerEmail = 'Customer E-mail';
	var gsscCustomerPhone = 'Customer Phone';

//--- Shopping Cart Indexes --------------------------------------------

	var ifscLineID = 0;
	var ifscGroupID = 1;
	var ifscType = 2;
	var ifscCurrProd = 3;
	var ifscGlobalIndex = 4;
	var ifscProdType = 5;
	var ifscColour = 6;
	var ifscPrice = 7;
	var ifscAreas = 8;
	var ifscSmallAmt = 9;
	var ifscMedAmt = 10;
	var ifscLargeAmt = 11;
	var ifscXLAmt = 12;
	var ifscXXLAmt = 13;
	var ifscXXXLAmt = 14;
	var ifscSmallCost = 15;
	var ifscMedCost = 16;
	var ifscLargeCost = 17;
	var ifscXLCost = 18;
	var ifscXXLCost = 19;
	var ifscXXXLCost = 20;
	var ifscSmallUnit = 21;
	var ifscMedUnit = 22;
	var ifscLargeUnit = 23;
	var ifscXLUnit = 24;
	var ifscXXLUnit = 25;
	var ifscXXXLUnit = 26;
	var ifsctotalUnit = 27;
	var ifsctotalCost = 28;
	var ifsctotalAmt = 29;
	var ifscinfostr = 30;
	var ifscareasstr = 31;
	var ifscXXLbase = 32;
	var ifscXXXLbase = 33;
	var ifscusRate = 34;
	var ifscUSA = 35;
	var ifscSpecClrs = 36;
	var ifscSpecClrs2 = 37;
	var ifscImprintInfo = 38;
	var ifscFullName = 39;
	var ifscSizes = 40;
	var ifscDesc = 41;
	var ifscMinQty = 42;
	var ifscAvailColours = 43;


//---------------------------------------------------------------------
//
//	scDeleteLine(LineID)
//
//	-- JA-OCI -- 2005-04-20
//
//	-- Only allowed for Setup lines. 
//	-- Deleting a Product or Size line will prompt for permission to delete the product from the cart. 
//	-- This is because the totals and unit costs would have to be refigured anyway.
//
//---------------------------------------------------------------------

	function scDeleteLine(LineID) {

		var i = 0, j = 0;

		for(i = 0; i < gscCartND.length; i++) {
			if(gscCartND[i][ifscLineID] = LineID) {

				//Delete the line by compressing the array:
				for(j = i+1; j < gscCartND.length-1; j++) {
					gscCartND[i] = gscCartND[j];
	    			}
	    			gscCartND.length = gscCartND.length - 1;
				LineID = 9999;
			}
		}

	}


//---------------------------------------------------------------------
//
//	scDeleteGroup(GroupID)
//
//	-- JA-OCI -- 2005-04-20
//	-- Deletes all the lines for a particular product from the cart.
//
//---------------------------------------------------------------------

	function scDeleteGroup(GroupID) {

		var i = 0, j = 0, k = 0;
		// alert('Deleting Group ' + GroupID);

		for(i = 1; i < gscCartND.length; i) {
			// alert('Looking at row ' + i + ' with a group of ' + gscCartND[i][ifscGroupID]);
			if((gscCartND[i][ifscGroupID]-0) == (GroupID-0)) {
				// alert('Row ' + i + ' is in the Group ' + GroupID);
				//Delete the line by compressing the array:
				k = i;
				for(j = i+1; j < gscCartND.length; j++) {
					// alert('Replacing row ' + k + ' with ' + j);
					gscCartND[k] = gscCartND[j];
					k++;
	    			}
	    			gscCartND.length = gscCartND.length - 1;
			} else {
				i++;
			}
		}

	}


//---------------------------------------------------------------------
//
//	scReloadGroup(GroupID)
//
//	-- JA-OCI -- 2005-04-20
//	-- Loads group data into working variables and deletes from the shopping cart.
//
//---------------------------------------------------------------------

	function scReloadGroup(GroupID) {

		var i = 0;

		// Find the Product record for the Group and reload the global working variables:
		for(i = 1; i < gscCartND.length; i++) {
			if((gscCartND[i][ifscType] == "Product") && (gscCartND[i][ifscGroupID] == GroupID)) {

				//Reload the global working variables:
				// alert('Reloading ' + gscCartND[i][ifscCurrProd]);
				currProd = gscCartND[i][ifscCurrProd];
				globalIndex = gscCartND[i][ifscGlobalIndex];
				prodType = gscCartND[i][ifscProdType];
				Colour = gscCartND[i][ifscColour];
				Price = gscCartND[i][ifscPrice];
				Areas = gscCartND[i][ifscAreas];
				SmallAmt = gscCartND[i][ifscSmallAmt];
				MedAmt = gscCartND[i][ifscMedAmt];
				LargeAmt = gscCartND[i][ifscLargeAmt];
				XLAmt = gscCartND[i][ifscXLAmt];
				SmallCost = gscCartND[i][ifscSmallCost];
				MedCost = gscCartND[i][ifscMedCost];
				LargeCost = gscCartND[i][ifscLargeCost];
				XLCost = gscCartND[i][ifscXLCost];
				SmallUnit = gscCartND[i][ifscSmallUnit];
				MedUnit = gscCartND[i][ifscMedUnit];
				LargeUnit = gscCartND[i][ifscLargeUnit];
				XLUnit = gscCartND[i][ifscXLUnit];
				totalUnit = gscCartND[i][ifsctotalUnit];					
				totalCost = gscCartND[i][ifsctotalCost];					
				totalAmt = gscCartND[i][ifsctotalAmt];					
				infostr = gscCartND[i][ifscinfostr];
				areasstr = gscCartND[i][ifscareasstr];
				XXLbase = gscCartND[i][ifscXXLbase];
				XXXLbase = gscCartND[i][ifscXXXLbase];
				usRate = gscCartND[i][ifscusRate];
				USA = gscCartND[i][ifscUSA];
				SpecClrs = gscCartND[i][ifscSpecClrs];
				SpecClrs2 = gscCartND[i][ifscSpecClrs2];
				imprintInfo = gscCartND[i][ifscImprintInfo];
				gsFullName = gscCartND[i][ifscFullName];
				gsSizes = gscCartND[i][ifscSizes];
				gsDescription = gscCartND[i][ifscDesc];
				giMinQty = gscCartND[i][ifscMinQty];
				// gscCartND[i][ifscAvailColours];
			}
		}

		// Find the Setup record(s) for the Group and reload the global working variables:
		// NO NEED: this is imbedded in the cost and held in the Areas array.
		//for(i = 0; i < gscCartND.length; i++) {
		//	if((gscCartND[i][ifscType] = "Setup") && (gscCartND[i][ifscGroupID] = GroupID)) {
		//
		//		totalCost += 75;
		//
		//	}
		//}

		// Find the Size record(s) for the Group and reload the global working variables:
		//for(i = 1; i < gscCartND.length; i++) {
		//	if((gscCartND[i][ifscType] = "Size") && (gscCartND[i][ifscGroupID] = GroupID)) {

		//		XXLAmt += gscCartND[i][ifscXXLAmt];
		//		XXXLAmt += gscCartND[i][ifscXXXLAmt];
		//		XXLCost += gscCartND[i][ifscXXLCost];
		//		XXXLCost += gscCartND[i][ifscXXXLCost];
		//		XXLUnit += gscCartND[i][ifscXXLUnit];
		//		XXXLUnit += gscCartND[i][ifscXXXLUnit];

		//	}
		//}

	}


//---------------------------------------------------------------------
//
//	scAddGroup()
//
//	-- JA-OCI -- 2005-04-20
//	-- Adds a product estimate to the cart, breaking out the setup and oversizes to separate lines.
//
//---------------------------------------------------------------------

	function scAddGroup() {

		var i = 0;

		// Get the latest Group Number:
		glscGroupID = getNextGroupID();

		// Get the latest Line Number:
		glscLineID = getNextLineID();

		// Construct the Product line:
		gscLineND = new Array(44);

		gscLineND[ifscLineID] = gscLineND;
		gscLineND[ifscGroupID] = glscGroupID;
		gscLineND[ifscType] = 'Product';
		gscLineND[ifscCurrProd] = currProd;
		gscLineND[ifscGlobalIndex] = globalIndex;
		gscLineND[ifscProdType] = prodType;
		gscLineND[ifscColour] = Colour;
		gscLineND[ifscPrice] = Price;
		gscLineND[ifscAreas] = Areas;
		gscLineND[ifscSmallAmt] = SmallAmt;
		gscLineND[ifscMedAmt] = MedAmt;
		gscLineND[ifscLargeAmt] = LargeAmt;
		gscLineND[ifscXLAmt] = XLAmt;
		gscLineND[ifscXXLAmt] = 0;
		gscLineND[ifscXXXLAmt] = 0;
		gscLineND[ifscSmallCost] = SmallCost;
		gscLineND[ifscMedCost] = MedCost;
		gscLineND[ifscLargeCost] = LargeCost;
		gscLineND[ifscXLCost] = XLCost;
		gscLineND[ifscXXLCost] = 0;
		gscLineND[ifscXXXLCost] = 0;
		gscLineND[ifscSmallUnit] = SmallUnit;
		gscLineND[ifscMedUnit] = MedUnit;
		gscLineND[ifscLargeUnit] = LargeUnit;
		gscLineND[ifscXLUnit] = XLUnit;
		gscLineND[ifscXXLUnit] = 0;
		gscLineND[ifscXXXLUnit] = 0;
		gscLineND[ifsctotalUnit] = totalUnit;

		if(totalUnit == 0) { gscLineND[ifsctotalUnit] = '0'; }
		if(gscLineND[ifsctotalUnit]=='0') { gscLineND[ifsctotalUnit] = gscLineND[ifscSmallCost]; }
		if(gscLineND[ifsctotalUnit]=='0') { gscLineND[ifsctotalUnit] = gscLineND[ifscMedCost]; }
		if(gscLineND[ifsctotalUnit]=='0') { gscLineND[ifsctotalUnit] = gscLineND[ifscLargeCost]; }
		if(gscLineND[ifsctotalUnit]=='0') { gscLineND[ifsctotalUnit] = gscLineND[ifscXLCost]; }

		gscLineND[ifsctotalCost] = totalCost;
		gscLineND[ifsctotalAmt] = totalAmt; // (SmallAmt - 0) + (MedAmt - 0) + (LargeAmt - 0) + (XLAmt - 0); // totalAmt;
		gscLineND[ifscinfostr] = infostr;
		gscLineND[ifscareasstr] = areasstr;
		gscLineND[ifscXXLbase] = XXLbase;
		gscLineND[ifscXXXLbase] = XXXLbase;
		gscLineND[ifscusRate] = usRate;
		gscLineND[ifscUSA] = USA;
		gscLineND[ifscSpecClrs] = SpecClrs;
		gscLineND[ifscSpecClrs2] = SpecClrs2;

		// Add in the Imprint Type info:
		var sImprints = '';

		if(top.prodType == 'Specialty') {
	   	    sImprints = '';
		} else {
	   	    for (var i = 0; i < top.Areas.length; i++) {
			if(top.Areas[i][1] > 0) {
			   if(sImprints.length > 0) sImprints += " and ";
			   sImprints += '<br>' + top.prodType + ' ';
			   if(top.prodType == 'Silkscreened') {
			    	sImprints += top.Areas[i][0] + ' using ';
			   } else {
			    	sImprints += top.Areas[i][0] + ' using a maximum of ';
			   }
			   sImprints += top.Areas[i][1];
			   if(top.Areas[i][1]>8) {
		   	    	sImprints += " stitches"
			   } else {
		   	   	sImprints += " colour(s)"
			   }
	   	    	}
		    }
	   	    sImprints += ".";
		}
		gscLineND[ifscImprintInfo] = sImprints;

		gscLineND[ifscFullName] = gsFullName;
		gscLineND[ifscSizes] = gsSizes;

		var sDesc = top.gsDescription;

		// Strip off the ending: Minimum Imprinted Order Quantity:
		var ipos = sDesc.indexOf("<br>Minimum Imprinted Quantity");
		if(ipos>-1) {
	   	   sDesc = sDesc.slice(0,ipos)
		}
		if(top.prodType == 'Specialty') {
		   // Strip out the default available locations and add the actual locations:
		   var ipos = sDesc.indexOf("ed in ");
		   if(ipos>-1) {
	   		var sDescStart = sDesc.slice(0,ipos)
			var sDescEnd = sDesc.slice(ipos,sDesc.length)
			// Now find the end of the phrase:
			ipos = sDescEnd.indexOf(".");
		   	if(ipos>-1) {
	   		   sDescEnd = sDescEnd.slice(ipos,sDesc.length)
			}
			if(top.SpecLoc2 == true) {
		         sDesc = sDescStart + "ed in 2 locations with " + top.SpecClrs + " and " + top.SpecClrs2 + " imprint colours" + sDescEnd
			} else {
		         sDesc = sDescStart + "ed in 1 location with " + top.SpecClrs + " imprint colour(s)" + sDescEnd
			}
		   }
		}
		gscLineND[ifscDesc] = sDesc;

		// Two new lines for the Flyer output:
		gscLineND[ifscMinQty] = giMinQty;
		gscLineND[ifscAvailColours] = gsAvailColours;

		gscCartND[gscCartND.length] = gscLineND;

		// If there is any setup charges on the Areas, then:
		// Construct the Setup line:
		var liSetup = 0;
		var llSetup = 0;
		for(i = 0; i < Areas.length; i++) {
			if(Areas[i][2] > 0) {
				llSetup += (Areas[i][2] - 0);
				liSetup += 1;
			}
		}

		if(liSetup > 0) {
			gscLineND = new Array(44);

			// Get the latest Line Number:
			glscLineID = getNextLineID();

			// Write the data to the record:
			gscLineND[ifscLineID] = gscLineND;
			gscLineND[ifscGroupID] = glscGroupID;
			gscLineND[ifscType] = 'Setup';
			gscLineND[ifscCurrProd] = currProd;
			gscLineND[ifscGlobalIndex] = globalIndex;
			gscLineND[ifscProdType] = prodType;
			gscLineND[ifscColour] = Colour;
			gscLineND[ifscPrice] = Price;
			gscLineND[ifscAreas] = Areas;
			gscLineND[ifscSmallAmt] = 0;
			gscLineND[ifscMedAmt] = 0;
			gscLineND[ifscLargeAmt] = 0;
			gscLineND[ifscXLAmt] = 0;
			gscLineND[ifscXXLAmt] = 0;
			gscLineND[ifscXXXLAmt] = 0;
			gscLineND[ifscSmallCost] = 0;
			gscLineND[ifscMedCost] = 0;
			gscLineND[ifscLargeCost] = 0;
			gscLineND[ifscXLCost] = 0;
			gscLineND[ifscXXLCost] = 0;
			gscLineND[ifscXXXLCost] = 0;
			gscLineND[ifscSmallUnit] = 0;
			gscLineND[ifscMedUnit] = 0;
			gscLineND[ifscLargeUnit] = 0;
			gscLineND[ifscXLUnit] = 0;
			gscLineND[ifscXXLUnit] = 0;
			gscLineND[ifscXXXLUnit] = 0;
			gscLineND[ifsctotalUnit] = 75;
			gscLineND[ifsctotalCost] = llSetup;
			gscLineND[ifsctotalAmt] = liSetup;
			gscLineND[ifscinfostr] = ''; // infostr;
			gscLineND[ifscareasstr] = ''; // areasstr;
			gscLineND[ifscXXLbase] = XXLbase;
			gscLineND[ifscXXXLbase] = XXXLbase;
			gscLineND[ifscusRate] = usRate;
			gscLineND[ifscUSA] = USA;
			gscLineND[ifscSpecClrs] = SpecClrs;
			gscLineND[ifscSpecClrs2] = SpecClrs2;
			gscLineND[ifscImprintInfo] = ''; // imprintInfo;

			gscCartND[gscCartND.length] = gscLineND;

		}


		// Construct the XXL line:
		if((XXLAmt > 0) || (XXXLAmt > 0)) {
			gscLineND = new Array(44);

			// Get the latest Line Number:
			glscLineID = getNextLineID();

			// Write the oversize data to the record:
			gscLineND[ifscLineID] = gscLineND;
			gscLineND[ifscGroupID] = glscGroupID;
			gscLineND[ifscType] = 'Size';
			gscLineND[ifscCurrProd] = currProd;
			gscLineND[ifscGlobalIndex] = globalIndex;
			gscLineND[ifscProdType] = prodType;
			gscLineND[ifscColour] = Colour;
			gscLineND[ifscPrice] = Price;
			gscLineND[ifscAreas] = Areas;
			gscLineND[ifscSmallAmt] = 0;
			gscLineND[ifscMedAmt] = 0;
			gscLineND[ifscLargeAmt] = 0;
			gscLineND[ifscXLAmt] = 0;
			gscLineND[ifscXXLAmt] = XXLAmt;
			gscLineND[ifscXXXLAmt] = XXXLAmt;
			gscLineND[ifscSmallCost] = 0;
			gscLineND[ifscMedCost] = 0;
			gscLineND[ifscLargeCost] = 0;
			gscLineND[ifscXLCost] = 0;
			gscLineND[ifscXXLCost] = XXLCost;
			gscLineND[ifscXXXLCost] = XXXLCost;
			gscLineND[ifscSmallUnit] = 0;
			gscLineND[ifscMedUnit] = 0;
			gscLineND[ifscLargeUnit] = 0;
			gscLineND[ifscXLUnit] = 0;
			gscLineND[ifscXXLUnit] = XXLUnit;
			gscLineND[ifscXXXLUnit] = XXXLUnit;
			if(XXLAmt > 0) {
				gscLineND[ifsctotalUnit] = XXLCost;
			} else {
				gscLineND[ifsctotalUnit] = XXXLCost;
			}
			gscLineND[ifsctotalCost] = 0;
			gscLineND[ifsctotalAmt] = (XXXLAmt - 0) + (XXLAmt - 0);	
			gscLineND[ifscinfostr] = ''; // infostr;
			gscLineND[ifscareasstr] = ''; // areasstr;
			gscLineND[ifscXXLbase] = XXLbase;
			gscLineND[ifscXXXLbase] = XXXLbase;
			gscLineND[ifscusRate] = usRate;
			gscLineND[ifscUSA] = USA;
			gscLineND[ifscSpecClrs] = SpecClrs;
			gscLineND[ifscSpecClrs2] = SpecClrs2;
			gscLineND[ifscImprintInfo] = imprintInfo;

			gscCartND[gscCartND.length] = gscLineND;

		}

		// Construct the Total line:
		gscLineND = new Array(44);

		// Get the latest Line Number:
		glscLineID = getNextLineID();

		// Write the oversize data to the record:
		gscLineND[ifscLineID] = gscLineND;
		gscLineND[ifscGroupID] = glscGroupID;
		gscLineND[ifscType] = 'Total';
		gscLineND[ifscCurrProd] = currProd;
		gscLineND[ifscGlobalIndex] = globalIndex;
		gscLineND[ifscProdType] = prodType;
		gscLineND[ifscColour] = Colour;
		gscLineND[ifscPrice] = Price;
		gscLineND[ifscAreas] = Areas;
		gscLineND[ifscSmallAmt] = 0;
		gscLineND[ifscMedAmt] = 0;
		gscLineND[ifscLargeAmt] = 0;
		gscLineND[ifscXLAmt] = 0;
		gscLineND[ifscXXLAmt] = 0;
		gscLineND[ifscXXXLAmt] = 0;
		gscLineND[ifscSmallCost] = 0;
		gscLineND[ifscMedCost] = 0;
		gscLineND[ifscLargeCost] = 0;
		gscLineND[ifscXLCost] = 0;
		gscLineND[ifscXXLCost] = 0;
		gscLineND[ifscXXXLCost] = 0;
		gscLineND[ifscSmallUnit] = 0;
		gscLineND[ifscMedUnit] = 0;
		gscLineND[ifscLargeUnit] = 0;
		gscLineND[ifscXLUnit] = 0;
		gscLineND[ifscXXLUnit] = 0;
		gscLineND[ifscXXXLUnit] = 0;
		gscLineND[ifsctotalUnit] = 0;
		gscLineND[ifsctotalCost] = totalCost;
		gscLineND[ifsctotalAmt] = totalAmt;	
		gscLineND[ifscinfostr] = ''; // infostr;
		gscLineND[ifscareasstr] = ''; // areasstr;
		gscLineND[ifscXXLbase] = XXLbase;
		gscLineND[ifscXXXLbase] = XXXLbase;
		gscLineND[ifscusRate] = usRate;
		gscLineND[ifscUSA] = USA;
		gscLineND[ifscSpecClrs] = SpecClrs;
		gscLineND[ifscSpecClrs2] = SpecClrs2;
		gscLineND[ifscImprintInfo] = imprintInfo;

		gscCartND[gscCartND.length] = gscLineND;

		// alert('After adding this product the cart length is: ' + gscCartND.length);
	}


//---------------------------------------------------------------------
//
//	scClearCart()
//
//	-- JA-OCI -- 2005-04-20
//	-- Empties the cart. Reinitializes all variables to do with the cart (calls scResetVars())
//
//---------------------------------------------------------------------

	function scClearCart() {
		gscCartND = new Array(new Array(44));
		gscLineND = new Array(44);
		scResetVars();
	}


//---------------------------------------------------------------------
//
//	scResetVars()
//
//	-- JA-OCI -- 2005-04-20
//	-- Reinitializes all variables to do with the cart. Called at the start to ensure the cart is ready.
//
//---------------------------------------------------------------------

	function scResetVars() {
		glscGroupID = -1;
		glscLineID = -1;
		gfscOnEdit = false;
		gfscOnDelete = false;
	}


//---------------------------------------------------------------------
//
//	scDrawGroup(GroupID)
//
//	-- JA-OCI -- 2005-04-20
//	-- Draw the lines from the Shopping Cart for a specific product (all lines).
//
//---------------------------------------------------------------------

	function scDrawGroup(GroupID) {

	}


//---------------------------------------------------------------------
//
//	scCheckGroup(ProdID)
//
//	-- JA-OCI -- 2005-06-07
//	-- See if the product is already in the cart, return the group ID.
//
//---------------------------------------------------------------------

	function scCheckGroup(ProdID) {
		
		var i = 0;
		var lGroupID = -1;

		// Find the Product record for the Group and return the group ID:
		for(i = 1; i < gscCartND.length; i++) {
			if(gscCartND[i][ifscCurrProd] == ProdID) {
				lGroupID = gscCartND[i][ifscGroupID];
			}
		}
		return lGroupID;
	}


//---------------------------------------------------------------------
//
//	scDrawCart()
//
//	-- JA-OCI -- 2005-04-20
//	-- Draw all lines from the Shopping Cart to an HTML form.
//
//---------------------------------------------------------------------

	function scDrawCart() {


		var i = 0;
		var sDrawnCart = '';
		var sDesc = '';
		var dTotal = 0.0;
		var dCost = 0.0;

		// Draw the table header:
		sDrawnCart = '<table width="100%" border="0" class="fourteen">';
  		sDrawnCart += '<tr class="sixteen" bgcolor="#CCCCCC">'; 
    		sDrawnCart += '<td width="400" align="center" bordercolor="#000000">Description</td>';
    		sDrawnCart += '<td align="center">Quantity</td>';
    		sDrawnCart += '<td align="center"><nobr>Unit Price</nobr></td>';
    		sDrawnCart += '<td align="center">Total</td>';
    		sDrawnCart += '<td width="50" align="center"></td>';
    		sDrawnCart += '<td width="50" align="center"></td>';
  		sDrawnCart += '</tr>';

		// Loop through the current cart and draw out all records:
		for(i = 1; i < gscCartND.length; i++) {

		   // alert("i = " + i + " and gscCartND.length = " + gscCartND.length + " and gscCartND[i][ifscType] = " + gscCartND[i][ifscType] + " and gscCartND[i][ifscCurrProd] = " + gscCartND[i][ifscCurrProd]);
		   switch(gscCartND[i][ifscType]) {
		     	case "Product":

				sDesc = '';  // Re-initialize.

				// Make the description string:
				sDesc = "<b>" + gscCartND[i][ifscFullName] + "</b> ";
				if(gscCartND[i][ifscColour] != "N/A") {
					sDesc += gscCartND[i][ifscColour] + ". ";
				}
				sDesc += gscCartND[i][ifscDesc] + " ";
				 if(gscCartND[i][ifscSizes]) {
					sDesc += "<br>Sizes Available: " + gscCartND[i][ifscSizes] + ". ";
				 }
				if(gscCartND[i][ifscProdType] != 'Blank') sDesc += gscCartND[i][ifscImprintInfo];

				if (top.isAgent) {
				sDesc += '<br>Product: <b>' + gscCartND[i][ifscCurrProd] + '</b>';
				} else {
				sDesc += '<br><span class="micro">' + gscCartND[i][ifscCurrProd] + '</span>';
				}

				// Draw the Product line:
				sDrawnCart += '<tr><td class="fourteen" width="400">';
				sDrawnCart += sDesc + '</td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				// sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + gscCartND[i][ifsctotalUnit] + '</td>';
				} else {
				   sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				}
				sDrawnCart += '<td align="center"></td>';
				sDrawnCart += '<td class="sixteen" align="center">';
				sDrawnCart += '</td>';
				sDrawnCart += '<td></td>';
				sDrawnCart += '</tr>';

				// dTotal += parseFloat(gscCartND[i][ifsctotalCost].slice,(1,gscCartND[i][ifsctotalCost].length));
				// alert('Drawing a Product line.');
				break;

		   	case "Size":
				// Draw the Oversize lines:
				sDrawnCart += '<tr><td class="fourteen" width="400" align="Right">';
				sDrawnCart += 'Oversize Unit Costs:</td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				// sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + gscCartND[i][ifsctotalUnit] + '</td>';
				} else {
				   sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				}
				sDrawnCart += '<td align="center"></td>';
				sDrawnCart += '<td class="sixteen" align="center">';
				sDrawnCart += '</td>';
				sDrawnCart += '<td></td>';
				sDrawnCart += '</tr>';
				break;

			case "Setup":
				// Draw the setup charges line:
				sDrawnCart += '<tr><td class="fourteen" width="400" align="Right">';
				sDrawnCart += 'Minimum Embroidery Setup Charges:</td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				// sDrawnCart += '<td align="center">' + makeString(gscCartND[i][ifsctotalCost]) + '</td>';
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + makeString(gscCartND[i][ifsctotalCost]) + '</td>';
				} else {
				   sDrawnCart += '<td align="center">' + makeString(gscCartND[i][ifsctotalCost]) + '</td>';
				}
				sDrawnCart += '<td align="center"></td>';
				sDrawnCart += '<td class="sixteen" align="center">';
				sDrawnCart += '</td>';
				sDrawnCart += '<td></td>';
				sDrawnCart += '</tr>';
				break;

			case "Total":
				sDrawnCart += '<tr bgcolor="#CDCDCD"><td class="fourteen" width="400" align="Right">';
				sDrawnCart += '<b>Sub-Total Cost:</b></td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				sDrawnCart += '<td align="center"></td>';
				// sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalCost] + '</td>';
				dCost = gscCartND[i][ifsctotalCost].slice(1) - 0;
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + gscCartND[i][ifsctotalCost] + '</td>';
				   dTotal += (dCost - 0);
				} else {
				   sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalCost] + '</td>';
				   dTotal += (dCost - 0);
// parseFloat(gscCartND[i][ifsctotalCost].slice,(1,gscCartND[i][ifsctotalCost].length));
				}
// alert(dCost);
// alert(dTotal);
				sDrawnCart += '<td class="sixteen" align="center" bgcolor="#FF0000">';
				sDrawnCart += '<input type="checkbox" value=' + gscCartND[i][ifscGroupID] + '></td>';
				sDrawnCart += '<td><input type="button" value="Edit" class="fourteenBoldRed" onClick="javascript: EditGroup(' + gscCartND[i][ifscGroupID] + ');"></td>';
				sDrawnCart += '</tr>';
				// alert('Drawing a Total line.');
				break;
 
		   } 

		}

		// Draw the table footer:
		sDrawnCart += '<tr bgcolor="#CCCCCC"><td align="right"><b>Total Cost:<b></td><td></td><td></td><td align="center">' + makeString(dTotal) + '</td><td></td><td></td></tr>';
		sDrawnCart += '</table>';

		return sDrawnCart;

	}


//---------------------------------------------------------------------
//
//	scDrawCartPrint()
//
//	-- JA-OCI -- 2008-01-09
//	-- Draw all lines from the Shopping Cart to an HTML form.
//	   without the edit and line count cells.
//
//---------------------------------------------------------------------

	function scDrawCartPrint() {


		var i = 0;
		var sDrawnCart = '';
		var sDesc = '';
		var dTotal = 0.0;
		var dCost = 0.0;

		// Draw the table header:
		sDrawnCart = '<table width="100%" border="0" class="fourteen">';
  		sDrawnCart += '<tr class="sixteen" bgcolor="#CCCCCC">'; 
    		sDrawnCart += '<td width="400" align="center" bordercolor="#000000">Description</td>';
    		sDrawnCart += '<td align="center">Quantity</td>';
    		sDrawnCart += '<td align="center"><nobr>Unit Price</nobr></td>';
    		sDrawnCart += '<td align="center">Total</td>';
    		// sDrawnCart += '<td width="50" align="center"><img src="http://www.new-dog.com/doohickeys/delete.gif" border="0"></td>';
    		// sDrawnCart += '<td width="50" align="center"></td>';
  		sDrawnCart += '</tr>';

		// Loop through the current cart and draw out all records:
		for(i = 1; i < gscCartND.length; i++) {

		   // alert("i = " + i + " and gscCartND.length = " + gscCartND.length + " and gscCartND[i][ifscType] = " + gscCartND[i][ifscType] + " and gscCartND[i][ifscCurrProd] = " + gscCartND[i][ifscCurrProd]);
		   switch(gscCartND[i][ifscType]) {
		     	case "Product":

				sDesc = '';  // Re-initialize.

				// Make the description string:
				sDesc = "<b>" + gscCartND[i][ifscFullName] + "</b> ";
				if(gscCartND[i][ifscColour] != "N/A") {
					sDesc += gscCartND[i][ifscColour] + ". ";
				}
				sDesc += gscCartND[i][ifscDesc] + " ";
				 if(gscCartND[i][ifscSizes]) {
					sDesc += "<br>Sizes Available: " + gscCartND[i][ifscSizes] + ". ";
				 }
				if(gscCartND[i][ifscProdType] != 'Blank') sDesc += gscCartND[i][ifscImprintInfo];

				if (top.isAgent) {
				sDesc += '<br>Product: <b>' + gscCartND[i][ifscCurrProd] + '</b>';
				} else {
				sDesc += '<br><span class="micro">' + gscCartND[i][ifscCurrProd] + '</span>';
				}

				// Draw the Product line:
				sDrawnCart += '<tr><td class="fourteen" width="400">';
				sDrawnCart += sDesc + '</td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				// sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + gscCartND[i][ifsctotalUnit] + '</td>';
				} else {
				   sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				}
				sDrawnCart += '<td align="center"></td>';
				// sDrawnCart += '<td class="sixteen" align="center">';
				// sDrawnCart += '</td>';
				// sDrawnCart += '<td></td>';
				sDrawnCart += '</tr>';

				// dTotal += parseFloat(gscCartND[i][ifsctotalCost].slice,(1,gscCartND[i][ifsctotalCost].length));
				// alert('Drawing a Product line.');
				break;

		   	case "Size":
				// Draw the Oversize lines:
				sDrawnCart += '<tr><td class="fourteen" width="400" align="Right">';
				sDrawnCart += 'Oversize Unit Costs:</td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				// sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + gscCartND[i][ifsctotalUnit] + '</td>';
				} else {
				   sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalUnit] + '</td>';
				}
				sDrawnCart += '<td align="center"></td>';
				// sDrawnCart += '<td class="sixteen" align="center">';
				// sDrawnCart += '</td>';
				// sDrawnCart += '<td></td>';
				sDrawnCart += '</tr>';
				break;

			case "Setup":
				// Draw the setup charges line:
				sDrawnCart += '<tr><td class="fourteen" width="400" align="Right">';
				sDrawnCart += 'Minimum Embroidery Setup Charges:</td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				// sDrawnCart += '<td align="center">' + makeString(gscCartND[i][ifsctotalCost]) + '</td>';
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + makeString(gscCartND[i][ifsctotalCost]) + '</td>';
				} else {
				   sDrawnCart += '<td align="center">' + makeString(gscCartND[i][ifsctotalCost]) + '</td>';
				}
				sDrawnCart += '<td align="center"></td>';
				// sDrawnCart += '<td class="sixteen" align="center">';
				// sDrawnCart += '</td>';
				// sDrawnCart += '<td></td>';
				sDrawnCart += '</tr>';
				break;

			case "Total":
				sDrawnCart += '<tr bgcolor="#CDCDCD"><td class="fourteen" width="400" align="Right">';
				sDrawnCart += '<b>Sub-Total Cost:</b></td>';
				sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalAmt] + '</td>';
				sDrawnCart += '<td align="center"></td>';
				// sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalCost] + '</td>';
				dCost = gscCartND[i][ifsctotalCost].slice(1) - 0;
				if(gscCartND[i][ifscUSA]) {
				   sDrawnCart += '<td align="center">US ' + gscCartND[i][ifsctotalCost] + '</td>';
				   dTotal += (dCost - 0);
				} else {
				   sDrawnCart += '<td align="center">' + gscCartND[i][ifsctotalCost] + '</td>';
				   dTotal += (dCost - 0);
// parseFloat(gscCartND[i][ifsctotalCost].slice,(1,gscCartND[i][ifsctotalCost].length));
				}
// alert(dCost);
// alert(dTotal);
				// sDrawnCart += '<td class="sixteen" align="center">';
				// sDrawnCart += '<input type="checkbox" value=' + gscCartND[i][ifscGroupID] + '></td>';
				// sDrawnCart += '<td><input type="button" value="Edit" onClick="javascript: EditGroup(' + gscCartND[i][ifscGroupID] + ');"></td>';
				sDrawnCart += '</tr>';
				// alert('Drawing a Total line.');
				break;
 
		   } 

		}

		// Draw the table footer:
		sDrawnCart += '<tr bgcolor="#CCCCCC"><td align="right"><b>Total Cost:<b></td><td></td><td></td><td align="center">' + makeString(dTotal) + '</td><td></td><td></td></tr>';
		sDrawnCart += '</table><br>';

		return sDrawnCart;

	}


//---------------------------------------------------------------------
//
//	getNextGroupID()
//
//	-- JA-OCI -- 2005-04-20
//	-- Increment the latest Group ID from the global variable.
//
//---------------------------------------------------------------------

	function getNextGroupID() {
		return glscGroupID += 1;
	}


//---------------------------------------------------------------------
//
//	getNextLineID()
//
//	-- JA-OCI -- 2005-04-20
//	-- Increment the latest Line ID from the global variable.
//
//---------------------------------------------------------------------

	function getNextLineID() {
		return glscLineID += 1;
	}


//---------------------------------------------------------------------
//
//	Constructor Function()
//
//	-- JA-OCI -- 2005-06-07
//	-- Functions called when the code is first loaded.
//
//---------------------------------------------------------------------

	scClearCart();

//======================================================================