function presentValue(value)
{
   if(value<=0.9999)
   {
      newPounds='0';
   }
   else
   {
      newPounds=parseInt(value);
   }

   if (value>0)
   {
      newPence=Math.round((value+.000008 - newPounds)*100);
   }
   else
   {
      newPence=0;
   }
   if (eval(newPence) >= 100) 
   {
      newPence='0';
      newPounds=eval(newPounds)+1;
   }
   if (eval(newPence) <= 9) newPence='0'+newPence;

   newString='£' + newPounds + '.' + newPence + '';
   return (newString);
}


function minibasket()
{
  newString='<font face=Arial size=2><b>Your Shopping Basket</b></font><br><table width=100% class=minibasket><tr><td><u><b>Item</b></u></td><td width=20><u>Qty</u></td><td width=50 align=right><u>Total</u></td></tr>';

   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;
   ordertotal=0;
   itemlist=0;
   delivery=0;
   deferred_credit=0;
   free_delivery=9;   /* 9-Initial state, free delivery off, 1-Free Delivery, 0-Not Free delivery */

   for (var i=0; i<=fulllist.length;i++)
   {
      if (fulllist.substring(i,i+1)==']')
      {
         itemlist=itemlist+1;
      }
   }

   if (itemlist==0)
   {    
      newString+='Shopping Basket is empty!';
   }
   else
   {
      itemlist=0;
      for (var i=0; i<=fulllist.length;i++)
      {
         if (fulllist.substring(i,i+1)=='[')
         {
            itemstart=i+1;
            thisitem=1;
         }
         else if (fulllist.substring(i,i+1)==']')
         {
            itemend=i;
            thequantity=fulllist.substring(itemstart,itemend);

            if (theitem.substring(0,8)=='Gliptone')
            {
               if (delivery==35)
               {
                  delivery=35;
               }
               else
               {
                  delivery=1.95;
               }
            }
            else
            {
               delivery=35;
            }
            itemtotal=0;
            dc_loc=theCode.indexOf("{DC}");
            if (dc_loc > 0)
            {
               deferred_credit=1;
            }
            fd_loc=theCode.indexOf("{FD}");
            if (fd_loc > 0)
            {
               if (free_delivery==0)
               {
                  /* there is already a chargeable item */
                  free_delivery=0;
               }
               else
               {
                  free_delivery=1;
               }
            }
            else
            {
               free_delivery=0;
            }
            itemtotal=(eval(theprice*thequantity));
            temptotal=itemtotal*100;
            totprice=totprice+itemtotal;
            itemlist=itemlist+1;

            newString+='<tr><td valign=top>'+theitem+'</td>';
            //newString+=' '+presentValue(eval(theprice));
            newString+='<td valign=top>'+thequantity+'</td>';
            newString+='<td valign=top align=right>'+presentValue(itemtotal)+'</td>';
            newString+='</tr>';
         }
         else if (fulllist.substring(i,i+1)=='|')
         {
            if (thisitem== 1) theitem    = fulllist.substring(itemstart,i);
            if (thisitem== 2) theprice   = fulllist.substring(itemstart,i);
            if (thisitem== 3) thetaxable = fulllist.substring(itemstart,i);
            if (thisitem== 4) theCode    = fulllist.substring(itemstart,i);
            if (thisitem== 5) theFabric  = fulllist.substring(itemstart,i);
            if (thisitem== 6) thepage    = fulllist.substring(itemstart,i);

            thisitem++; itemstart=i+1;
         }
      }
      if (totprice > 300)
      {
        delivery=00;
      }
      if (free_delivery==1)
      {
         delivery=00;
      }
      totprice=totprice+delivery;      
      //document.writeln('<tr>');

      newString+='<tr><td align=right>Delivery</td><td></td><td align=right>'+presentValue(delivery)+'</td></tr>';
      newString+='<tr><td align=right>Total</td><td></td><td align=right>'+presentValue(totprice)+'</td></tr></table>';

   }
   return (newString);   
}

