	// showItems() - displays shopping basket in a table
	function showItems() {
		index = document.cookie.indexOf("NiteBasket");
		
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0;
		document.writeln('<TABLE border=0 cellpadding=2 cellspacing=0 bordercolor=#01A1B1 bgcolor="#F7F7F7" style="border: 1px solid #3E4A58">');
				//document.writeln('<TR><TD width=10 background=../images/button_left_corner.jpg></TD><TD width=300 background=../images/button_middle.jpg><font size="2"><b>Item</b></TD><TD background=../images/button_middle.jpg><font size="2"><b>Qty</b></TD><TD align=right background=../images/button_middle.jpg><font size="2"><b>Cost Ea</b></TD><td background=../images/button_middle.jpg><font size="2"><b>Total</b><TD background=../images/button_middle.jpg><font face="Arial" size="2"><b>Action</b></TD><TD width=14 background=../images/button_right_corner.jpg></TD></TR>');

		document.writeln('<TR style="background-color: #3E4A58; color:#FFF;"><TD width=300><font size="2"><b>Item</b></TD><TD><font size="2"><b>Qty</b></TD><TD align=right><font size="2"><b>Cost Ea</b></TD><td><font size="2"><b>Total</b><TD><font face="Arial" size="2"><b>Action</b></TD></TR>');
		
		
		
		
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;
				itemlist=itemlist+1;
				
				
				
				
document.writeln('<tr><td width=300 style="border: 1px solid #aaaaaa"><font size=2><B>'+theitem+'</B></td><td align=center style="border: 1px solid #aaaaaa"><font size=2>'+thequantity+'</td><td align=right style="border: 1px solid #aaaaaa"><font size=2>'+theprice+'</td><td align=right style="border: 1px solid #aaaaaa"><font size=2>'+alterError(itemtotal)+'</td><td style="border: 1px solid #aaaaaa"><a href="javascript:removeItem('+itemlist+')"><img src="images/delete.gif" border="0" hspace="10px"></a></td></tr>');
			
			
			
			
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
				
			} else if (fulllist.substring(i,i+1) == '*') {
			theweight = fulllist.substring(itemstart, i);
			itemstart = i+1;

				
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
				
				
				
			}
		}
	

		
		
		//document.writeln('<tr><TD></TD><TD colspan=5><hr color=#01a1b1 width=100% size=1></td></tr>');


		document.writeln('<tr style="color:#000;"><td colspan=3><b><font size=2>Total</b></td><td align=right><B>$'+alterError(totprice)+'<font color=#ff0000>*</B></td></tr>');
		document.writeln('</TABLE>');
	}

	
	
	
	
	// Remove an item from the list
	function removeItem(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		index = document.cookie.indexOf("NiteBasket");
		document.cookie="NiteBasket="+newItemList;
		location = "cart.php";
	}

	
	
	
	
	// clearBasket() - removes all items from the basket
	function clearBasket() {
		if (confirm('Are you sure you wish to clear the basket')) {
			index = document.cookie.indexOf("NiteBasket");
			document.cookie="NiteBasket=.";
			parent.frames[0].location = "cart.php";
		}
	}


	// alterError - fixes a rounding bug in Netscape 2
	function alterError(value) {
		if (value<=0.99) {
			newPounds = '0';
		} else {
			newPounds = parseInt(value);
		}
		newPence = parseInt((value+.0008 - newPounds)* 100);
		if (eval(newPence) <= 9) newPence='0'+newPence;
		newString = newPounds + '.' + newPence;
		return (newString);
	}

	// buyItem - adds an item to the shooping basket
	function buyItem(newItem, newWeight, newPrice, newQuantity) {
		if (newQuantity <= 0) {
			rc = alert('The quantity entered is incorrect');
			return false;
		}
		if (confirm('Add '+newQuantity+' x '+newItem+' at $'+newPrice+'. to your ordered items')) {		
		
		
		
			index = document.cookie.indexOf("NiteBasket");
			countbegin = (document.cookie.indexOf("=", index) + 1);
        		countend = document.cookie.indexOf(";", index);
	        	if (countend == -1) {
        	    		countend = document.cookie.length;
        		}
	                document.cookie="NiteBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newWeight+"*"+newPrice+"#"+newQuantity+"]";
	              
					


	               
		}
		return true;
		
	}

	// resetShoppingBasket - resets to shopping basket to empty
	function resetShoppingBasket() {
		index = document.cookie.indexOf("NiteBasket");
		document.cookie="NiteBasket=.";
		
		
		
		}
		
		
		

	function showCartFields() {
		varItemsList = "";
		index = document.cookie.indexOf("NiteBasket");
		
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
		totprice = 0;

		
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;
				itemlist=itemlist+1;
				
				
				
				
              varItemsList = (varItemsList +theitem+' x '+thequantity+' at $'+alterError(itemtotal)+'\n');
			
			
			
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
				
			} else if (fulllist.substring(i,i+1) == '*') {
			theweight = fulllist.substring(itemstart, i);
			itemstart = i+1;

				
			} else if (fulllist.substring(i,i+1) == '#') {
				theprice = fulllist.substring(itemstart, i);
				itemstart = i+1;
				
				
				
			}
		}	
	

		
		//ITEMS PASSED TO SSL
		document.writeln('<input type="hidden" name="purchasedItems" value="'+varItemsList+'">');
		document.writeln('<input type="hidden" name="purchasedItemsTotal" value="'+alterError(totprice)+'">');
		
		
	}	
	
	