// Copyright 2004, YukonSoft Corporation //
// --------------------------------------		

function getCart() {
  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;
  
  var option1 = 0;
  var option2 = 0;
  var option3 = 0;
  var subItemID = 0;
  var taxable = 0;
  var taxtotal = 0;

  itemlist = 0;
  thisitem = 0;
  thequantity = 0;
  var totalnumber = 0;
  var totalnumitems = 0;
  var cart = readCookie('TheBasket');    

  for (var i = 0; i <= fulllist.length; i++) {
  	if (fulllist.substring(i,i+1) == '[') {
  		thisitem = 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;
		 var actualprice = 0;
		 var individualprice = 0;
		 individualprice = eval(getPrice(theitem,thequantity) + eval(theprice));
		 actualprice = eval(thequantity * individualprice);
			
         if (eval(taxable) == 1) {
            taxtotal = taxtotal + actualprice;
         }
         totprice = totprice + actualprice;
         itemlist=itemlist+1;
		 totalweight += eval(thequantity)*eval(theweight);
         totalnumitems += eval(thequantity);
         itemend = i;
         
         var nameandvalues;
         var nameandoptions;
         nameandvalues = thename;         
         nameandoptions = thename;
         
         if (eval(option1) != 0) {
            nameandoptions = nameandoptions + "|" + option1;
            nameandvalues = nameandvalues + " (" + getValueName(eval(option1)) + ") ";
         }
         if (eval(option2) != 0) {
            nameandoptions = nameandoptions + "|" + option2;
            nameandvalues = nameandvalues + " (" + getValueName(eval(option2)) + ") ";
         }
         if (eval(option3) != 0) {
            nameandoptions = nameandoptions + "|" + option3;
            nameandvalues = nameandvalues + " (" + getValueName(eval(option3)) + ") ";
         } 
        
         itemsonOrder += addSpaceR(theitem, 12) + addSpaceR(nameandoptions, 34);
         itemsonOrder += addSpaceL(format1000(formatNum(thequantity,2)), 10) +  addSpaceL( format1000(formatNum(individualprice,2)), 13) + "\n";

	     if (taxable == 1) {
           pnptaxable = "y";
         }
		 else
		 {
		   pnptaxable = "n";
		 }

		 } else if (fulllist.substring(i,i+1) == '|') {
			if (thisitem==1) theitem = fulllist.substring(itemstart, i);
			if (thisitem==2) thename = fulllist.substring(itemstart, i);
			if (thisitem==3) theprice = fulllist.substring(itemstart, i);
			if (thisitem==4) theweight = fulllist.substring(itemstart, i);
         if (thisitem==5) thequantity = fulllist.substring(itemstart, i);
         if (thisitem==6) option1 = fulllist.substring(itemstart, i);
			if (thisitem==7) option2 = fulllist.substring(itemstart, i);
			if (thisitem==8) option3 = fulllist.substring(itemstart, i);
         if (thisitem==9) subItemID = fulllist.substring(itemstart, i);
         if (thisitem==10) taxable = fulllist.substring(itemstart, i);
			thisitem++;
			itemstart=i+1;
          //totalnumitems += totalnumitems + thequantity;
            
		}
	}

	if (thisitem != 0) {
      document.getElementById('cart').innerHTML = "<font size='1' color='#ffffff' face='Arial'>Your Cart Contains: "+totalnumitems+" Item(s)<br> for a total of "+format1000(formatNum(totprice,2)) +"</FONT";
	} else {
 	  document.getElementById('cart').innerHTML = "<font size='1' color='#ffffff' face='Arial'>Your cart is empty</FONT>";
	}
    
}     

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

