function getCookie()
{
	index = document.cookie.indexOf("TheBasket");
	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('<center><table width="600" cellpadding="2" cellspacing="2">');
	document.writeln('<tr>');
	document.writeln('<td bgcolor="#FFCC00" colspan="4"><font face="Verdana, Arial"><b>Volcanix Order</b></font></td>');
	document.writeln('</tr><tr>');
	document.writeln('<td bgcolor="#FF0000"><font face="Verdana, Arial" size="2"><b>Item</b></font></td>');
	document.writeln('<td bgcolor="#FF0000" align="center" width="75"><font face="Verdana, Arial" size="2"><b>Quantity</b></font></td>');
	document.writeln('<td bgcolor="#FF0000" align="center" width="75"><font face="Verdana, Arial" size="2"><b>Cost Each</b></font></td>');
	document.writeln('<td bgcolor="#FF0000" align="center" width="75"><font face="Verdana, Arial" size="2"><b>Remove?</b></font></td>');
	document.writeln('</tr>');

	itemlist = 0;
      var x = 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) == ']')
		{
                  var formnumber = x + 30;
                  x++;
			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>');
			document.writeln('<td bgcolor="#dddddd"><font face="Verdana, Arial" size="2">'+theitem+'</font></td>');
			document.writeln('<td bgcolor="#dddddd" align="right"><font face="Verdana, Arial" size="2">'+thequantity+'</font></td>');
			document.writeln('<td bgcolor="#dddddd" align="right"><font face="Verdana, Arial" size="2">$'+theprice+'</font></td>');
			document.writeln('<td bgcolor="#dddddd" align="center"><font face="Verdana, Arial" size="2"><a href="javascript:removeItem('+itemlist+')">Remove</a></font></td>');
			document.writeln('</tr>');
                  document.writeln('<input type="hidden" name="'+formnumber+'\)" value="Item'+x+': '+theitem+' Qty: '+thequantity+' at $'+theprice+' each">');
		}
		else if (fulllist.substring(i, i + 1) == ',')
		{
			theitem = 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>');
	document.writeln('<td colspan="2" bgcolor="#ffffff"><font face="Verdana, Arial"><b>Total</b></font></td>');
	document.writeln('<td bgcolor="#ffffff" align="right"><font face="Verdana, Arial">$'+totprice+'</font></td>');
      document.writeln('<td bgcolor="#ffffff">&nbsp;</td>');
	document.writeln('</tr>');
	document.writeln('</table>');
      document.writeln('<input type="hidden" name="'+9000+'\)" value="Total: $'+totprice+'">');
}

function getCookie2()
{
	index = document.cookie.indexOf("TheBasket");
	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('<center><table width="600" cellpadding="2" cellspacing="2">');
	document.writeln('<tr>');
	document.writeln('<td bgcolor="#FFFFFF"><font face="Verdana, Arial" size="2"><b>Item</b></font></td>');
	document.writeln('<td bgcolor="#FFFFFF" align="center" width="75"><font face="Verdana, Arial" size="2"><b>Quantity</b></font></td>');
	document.writeln('<td bgcolor="#FFFFFF" align="center" width="75"><font face="Verdana, Arial" size="2"><b>Cost Each</b></font></td>');
	document.writeln('<td></td>');
	document.writeln('</tr>');

	itemlist = 0;
      var x = 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) == ']')
		{
                  var formnumber = x + 30;
                  x++;
			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>');
			document.writeln('<td bgcolor="#ffffff"><font face="Verdana, Arial" size="2">'+theitem+'</font></td>');
			document.writeln('<td bgcolor="#ffffff" align="right"><font face="Verdana, Arial" size="2">'+thequantity+'</font></td>');
			document.writeln('<td bgcolor="#ffffff" align="right"><font face="Verdana, Arial" size="2">$'+theprice+'</font></td>');
			document.writeln('<td bgcolor="#ffffff" align="center"></td>');
			document.writeln('</tr>');
                  document.writeln('<input type="hidden" name="'+formnumber+'\)" value="Item'+x+': '+theitem+' Qty: '+thequantity+' at $'+theprice+' each">');
		}
		else if (fulllist.substring(i, i + 1) == ',')
		{
			theitem = 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>');
	document.writeln('<td colspan="2" bgcolor="#ffffff"><font face="Verdana, Arial"><b>Total</b></font></td>');
	document.writeln('<td bgcolor="#ffffff" align="right"><font face="Verdana, Arial">$'+totprice+'</font></td>');
      document.writeln('<td bgcolor="#ffffff"></td>');
	document.writeln('</tr><tr height="20"><td colspan="4"></td></tr>');
	document.writeln('</table>');
      document.writeln('<input type="hidden" name="'+9000+'\)" value="Total: $'+totprice+'">');
}


function setCookie(name, price, quantity)
{
var expires = new Date();
expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 31));

	  if (quantity <= 0)
	  {
		  rc = alert('The quantity entered is incorrect');
		  return false;
	  }
	  if (confirm('Add ' + name + ' to your basket?'))
	  {
		  index = document.cookie.indexOf("TheBasket");
		  countbegin = (document.cookie.indexOf("=", index) +1);
		  countend = document.cookie.indexOf(";", index);

		  if (countend == -1)
		  {
			  countend = document.cookie.length;
		  }
		  document.cookie = "TheBasket=" +
			  document.cookie.substring(countbegin, countend) + "[" +
			  name + "," + price + "#" + quantity + "]; expires=" + expires.toGMTString();
                  window.close();
	  }
	  return true;
}

function removeItem(itemno)
{
var expires = new Date();
expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * 31));

	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("TheBasket");
	document.cookie = "TheBasket="+newItemList+"; expires=" + expires.toGMTString();
        location.reload();
}

function clearBasket()
{
		index = document.cookie.indexOf("TheBasket=");
		document.cookie = "TheBasket=.";
		location.replace('index.htm');
}

function clearOrder()
{
	if (confirm('Are you sure? Your cart will be cleared.'))
	{
		index = document.cookie.indexOf("TheBasket=");
		document.cookie = "TheBasket=.";
		location.replace('index.htm');
	}
}
