     // this function converts the string into $00.00 form      
     // origval should be a valid number 
          function str2currency(origval) {
                if (origval.indexOf('.')==-1)                         // this makes "12" -> "12.00"
                        return origval + '.00'
                else if (origval.indexOf('.') == (origval.length-2))  // this makes "12.0" -> "12.00"
                        return origval + '0'
                else if (origval.length == (origval.indexOf('.') + 3))     // this returns if origval = "12.00" already
                        return origval
                else {
                        var nextNum = origval.substring((3 + parseInt(origval.indexOf('.'))),                                 (3 + parseInt(origval.indexOf('.'))) + 1);
                        // this makes "12.011" -> "12.01" (no rounding)
                        if (parseInt(nextNum) < 5) {
                                return (origval.substring(0, (origval.indexOf('.') + 3)));
                        } else {
                                // this makes "12.016" -> "12.02" (round up)
                                // i have to do it this way because the round function is buggy
                                var oneMore = .005 + parseFloat(origval);
                                return (str2currency("" + oneMore));
                        }
                }
     }
     // this function checks if the value is a number
     function isNum(valstr) {
                if (valstr.charAt(0) != '0' &&
                         valstr.charAt(0)!= '1' &&
                         valstr.charAt(0)!= '2' &&
                         valstr.charAt(0)!= '3' &&
                         valstr.charAt(0)!= '4' &&
                         valstr.charAt(0)!= '5' &&
                         valstr.charAt(0)!= '6' &&
                         valstr.charAt(0)!= '7' &&
                         valstr.charAt(0)!= '8' &&
                         valstr.charAt(0)!= '9' &&
                         valstr.charAt(0)!= '10')
                        return false;
                else
                        return true;
        } 
     // this function converts the number to float and returns 0 if it isnt a number
     function parseFloatNoFail(val) {
                if (isNum(val) == false)
                        return 0;
                else
                        return parseFloat(val);
        } 
     // this function calculates the order sub total
     function doSubTot() {
        }
     // this function calculates the line tot based on the value sent      
     function calcLineTot (qtyindex, totindex, p1) {
                var qtyarea = document.orderform.elements[qtyindex];
                var totarea = document.orderform.elements[totindex];
                // if we are working on a blank field clear the totarea, then just return
                if (qtyarea.value.length <= 0) {
                        totarea.value = "";
                        doBottomTots();
                        return;
                }
                // make sure the user enters a number
                if (isNum(qtyarea.value) == false) 
                {
                        alert("You must enter an integer in the QTY field.");
                        qtyarea.select();
                        qtyarea.focus();
                        return;                }
                // eliminates bad chars from the qty field
                qtyarea.value = parseInt(qtyarea.value);
                totarea.value = str2currency("" + (qtyarea.value * p1));
                //calc the totals at the bottom of the form
                doBottomTots();     }

     // this function calculates the subtot, shipping, tax, Total
     function doBottomTots() {
                // first calculate the subtot
                var subtot = 0;
                subtot =
                parseFloatNoFail(document.orderform.item01tot.value) +
                parseFloatNoFail(document.orderform.item02tot.value) +                                                		    parseFloatNoFail(document.orderform.item03tot.value) +
                parseFloatNoFail(document.orderform.item04tot.value) +                		                    		    parseFloatNoFail(document.orderform.item05tot.value) +
                parseFloatNoFail(document.orderform.item06tot.value) +                		    		    		    parseFloatNoFail(document.orderform.item07tot.value);
                document.orderform.subtotal.value = str2currency("" + subtot);                
                // calculate the shipping
                // domestic shipping
                var shippingindex = document.orderform.domestic_shipping.selectedIndex;
                var rate = 0;
                if (shippingindex == 0) rate = 0.00;
                if (shippingindex == 1) rate = 3.95;
                if (shippingindex == 2) rate = 10.00;
                var shipping = rate;
                if (rate != 0) { shipping = rate; }
                document.orderform.shipping.value = str2currency("" + shipping);  
                // calculate the tax
                var stateindex = document.orderform.statetax.selectedIndex;
                var rate = 0;                
                if (stateindex == 1) rate = .0675;
                var tax = subtot * rate;
                document.orderform.salestax.value = str2currency("" + tax);
                 // calculate the grand total
                var grand = subtot + tax + shipping;
                document.orderform.Total.value = str2currency("" + grand);
                }
                         
     // this function recomputes all the totals on the page
     function recomputeForm() {                // first calculate all the line totals
                calcLineTot(0, 1, 15.00);
                calcLineTot(2, 3, 10.00);
                calcLineTot(4, 5, 15.00);
                calcLineTot(6, 7, 10.00);
                calcLineTot(8, 9, 15.00);
                calcLineTot(10, 11, 15.00);
                calcLineTot(12, 13, 3.00);
                // do the bottom calculations
                doBottomTots();        }
