<!-- 

var RowsInForm = 5          //How many line items will be in the order form?
var ProductsInList = 16     //How many products in your product list?
var SalesTaxRate = 0.0825   //Set to sales tax rate in decimal. e.g. 0.0775 is 6.00%.
var TaxableState = "California"     //Set to name of state you charge sales tax in.
var ProdSubscript = 0       //Identifies subscript of selected product in current row.

function MakeArray(n) {
   this.length = n
   for (var i=1;i<=n;i++) {this[i]=0}
   return this
}

function BuildZeroArray(n) {
   this.length = n
   for (var i=0;i<=n;i++) {this[i]=0}
   return this
}

function prodobj(name, unitprice) {
   this.name = name
   this.unitprice = unitprice
}

function ordobj(prodsub, qty, unitprice, extprice) {
   this.prodsub = prodsub
   this.qty = qty
   this.unitprice = unitprice
   this.extprice = extprice
}

function updateRow(rownum){
   var exeLine='ProdSubscript=document.ordform.prodchosen'+rownum+'.selectedIndex'
   eval(exeLine)
   ordData[rownum].prodsub=ProdSubscript
   var exeLine='tempqty=document.ordform.qty'+rownum+'.value'
   eval(exeLine)
   ordData[rownum].qty=tempqty-0   //-- Gets unit price from the product price list.
   ordData[rownum].unitprice=prodlist[ProdSubscript].unitprice
   ordData[rownum].extprice=(ordData[rownum].qty)*ordData[rownum].unitprice
   var exeLine='document.ordform.unitprice'+rownum+'.value=currency(ordData['+rownum+'].unitprice,10)'
   eval (exeLine)
   var exeLine='document.ordform.extprice'+rownum+'.value=currency(ordData['+rownum+'].extprice,10)'
   eval(exeLine)
   updateTotals()
}

function updateTotals() {
   var subtotal = 0
   for (var i=1;i<=RowsInForm;i++) {
      subtotal=subtotal+ordData[i].extprice
   }
   document.ordform.subtotal.value = currency(subtotal,10)
   salestax=0
   if (document.ordform.Taxable.checked) {
      salestax = SalesTaxRate*subtotal
   }
   document.ordform.salestax.value = currency(salestax,10)
   shipping=1
   document.ordform.shipping.value = currency(shipping,10)
   document.ordform.grandtotal.value = currency(subtotal+salestax+shipping,10)
}

function copyAddress() {
   document.ordform.shipName.value=document.ordform.billName.value
   document.ordform.shipCompany.value=document.ordform.billCompany.value
   document.ordform.shipAdd1.value=document.ordform.billAdd1.value
   document.ordform.shipAdd2.value=document.ordform.billAdd2.value
   document.ordform.shipCity.value=document.ordform.billCity.value
   document.ordform.shipState.value=document.ordform.billState.value
   document.ordform.shipZip.value=document.ordform.billZip.value
   document.ordform.shipPhone.value=document.ordform.billPhone.value
   document.ordform.shipEmail.value=document.ordform.billEmail.value
}

function currency(anynum,width) {
   anynum=eval(anynum)
   workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
   if (workStr.indexOf(".")==-1){workStr+=".00"}
   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
   pStr=workStr.substr(workStr.indexOf("."))
   while (pStr.length<3){pStr+="0"}

   if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }

   if (dNum>=1000000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
   }
   retval=dStr+pStr 
   if (anynum < 0) {
      retval=retval.substring(1,retval.length)
      retval="("+retval+")"        
   }
   retval = "$"+retval
   //--Pad with leading blanks to better align numbers.
   while (retval.length<width){retval=" "+retval}

   return retval
}
//-->