function resetAll(doc) {
        for (var i = 0; i < doc.forms.length; i++) {
                doc.forms[i].reset()    
        }
        if (Nav4) {
                for (var j = 0; j < doc.layers.length; j++) {
                        resetAll(doc.layers[j].document)
                }               
        }
}

function cleanUp() {
   setTimeout("restoreFlip()", 50)
   setTimeout("showTotal()", 100)
}


function calculateSubtotal() {
  var p = parent.mainFrame.document;
  subtotal = 0;
  price = 0;
  quantity = 0;
  for (i = 0 ; i < p.forms[0].elements.length ; i++) {
    if ((p.forms[0].elements[i].name.substring(0,5) == "item-") && (p.forms[0].elements[i].value > 0)) {
      quantity = p.forms[0].elements[i].value;
      itemname = p.forms[0].elements[i].name;
      itemid = itemname.substring(5,itemname.indexOf("|"));
      itemname = itemname.substring(itemname.indexOf("|")+1);
      itemname = itemname.substring(itemname.indexOf("|")+1);
      price  = itemname.substring(0,itemname.indexOf("|"));
      for (j = 0; j < p.forms[0].elements.length;j++) {optionname = p.forms[0].elements[j].name;
        if (optionname.substring(0,6) == "option") {
          optionid = optionname.substring(optionname.indexOf("|")+1);
          optionid = optionid.substring(optionid.indexOf("|")+1);
          if (optionid == itemid) {optionvalue = p.forms[0].elements[j].value;
            optionprice = "0.00";
            if (optionvalue == null || (optionvalue.indexOf("|") < 1)) {
              index = p.forms[0].elements[j].selectedIndex;
              optionvalue = p.forms[0].elements[j].options[index].value;
              optionprice = optionvalue.substring(optionvalue.indexOf("|")+1);
            } else {
              if (p.forms[0].elements[j].checked != false) {optionprice = optionvalue.substring(optionvalue.indexOf("|")+1);
              }
            }
            price = "" + (parseFloat(price) + parseFloat(optionprice));
          }
        }
      }
      subtotal += quantity * price;
    }
    
  }
  subtotaltext = subtotal + "";
  decimalstart = subtotaltext.indexOf(".");
  if (decimalstart > 0) {subtotaltext = subtotaltext.substring(0,decimalstart+3);
  }
  if (decimalstart < 0) {subtotaltext = subtotaltext + ".00";
  }
  if (subtotaltext.substring(decimalstart+1).length < 2) {subtotaltext = subtotaltext + "0";
  }
  parent.cartFrame.document.forms[0].subtotal.value = subtotaltext
}
