function nameDefined(ckie,nme)
{
   var splitValues
   var i
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0]==nme) return true
   }
   return false
}
function delBlanks(strng)
{
   var result=""
   var i
   var chrn
   for (i=0;i<strng.length;++i) {
      chrn=strng.charAt(i)
      if (chrn!=" ") result += chrn
   }
   return result
}
function getCookieValue(ckie,nme)
{
   var splitValues
   var i
   for(i=0;i<ckie.length;++i) {
      splitValues=ckie[i].split("=")
      if(splitValues[0]==nme) return splitValues[1]
   }
   return ""
}

function getCookie(cname) {  //Tests to see if the cookie 
   var cookie=document.cookie           //with the name and value 
   var chkdCookie=delBlanks(cookie)  //are on the client computer
   var nvpair=chkdCookie.split(";")
   if(nameDefined(nvpair,cname))       //See if the name is in any pair
   {   
      return getCookieValue(nvpair,cname)  //Gets the value of the cookie
   }
   else return ""
}

function currencyformat(price)
{
  var cardinal = items(price, 1, ".");
  var mantissa = items(price, 2, ".");
  
  if (mantissa.length > 2)
  {
    var addone = (mantissa.substring(2,3) > 4);
    mantissa = mantissa.substring(0,1);
    if (addone) mantissa = mantissa*1 + 1;
  }
  if (mantissa.length == 0) mantissa = "00";
  if (mantissa.length == 1) mantissa = mantissa+"0";
  return cardinal+"."+mantissa;
}

var numitems = 0;
var total = 0;

  var numitems = getCookie("numitems");
  if (numitems == "") numitems = 0;
  var total = 0;
  var subtotal = 0;
  var cnt = 1;
  do
  {
    if (cnt > numitems) break;
    fieldname = "orderline-"+cnt;
    orderline = getCookie(fieldname);
    price = items(orderline, 6, "%7C");
    qty = items(orderline, 3, "%7C");
    subtotal = price * qty;
    total = total + subtotal;    
    cnt++;
  } while (1==1);
  // format the total 
  total = total.toFixed(2);
document.write(numitems+" items - <b>"+total+"</b>");
