<!-- 

//-- JavaScript code written by Alan Simpson - www.coolnerds.com
//-- Global Variables
var RowsInForm = 4          //How many line items will be in the order form?
var ProductsInList = 9     //How many products in your product list?
var SalesTaxRate = 0.0500   //Set to sales tax rate in decimal. e.g. 0.0775 is 6.00%.
var TaxableState = "MA"     //Set to name of state you charge sales tax in.
var ProdSubscript = 0       //Identifies subscript of selected product in current row.
var ShipRate = .10
 
//-- Function to create a new empty array that starts at 1.
function MakeArray(n) {
   this.length = n
   for (var i=1;i<=n;i++) {this[i]=0}
   return this
}

//-- Function to create a new, empty array that starts at zero.
function BuildZeroArray(n) {
   this.length = n
   for (var i=0;i<=n;i++) {this[i]=0}
   return this
}

//-- Defines a custom object named prodobj (Product Object).
//-- An array of these objects will act as our product/price list.
function prodobj(name, unitprice) {
   this.name = name
   this.unitprice = unitprice
}

//-- Defines a new custom object named ordobj (Order Object).
//-- Will house data displayed in order form line items.
function ordobj(prodsub, qty, unitprice, extprice) {
   this.prodsub = prodsub
   this.qty = qty
   this.unitprice = unitprice
   this.extprice = extprice
}

//-- Updates current row in order array and form.
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()
}

//-- Updates the totals in the lower part of order details.
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)
   document.ordform.ototal.value = currency(subtotal+salestax,10)  	
   
  //-- ----------Bruce's shipping play 
    ototal = subtotal+salestax
    shiptotal=0
	   		if (ototal >= 0.01)
			{
	//-- If order is more than a penny, calculate shipping
					
			 if (subtotal<=15) { shiptotal=6} 
			  else {  if (subtotal<=25){shiptotal=7.5 }
				else { if (subtotal<=50) {shiptotal = 9 }
				  else { if (subtotal<=75) {shiptotal = 10.5 }
				    else { if (subtotal<=100) {shiptotal = 12}
					  else { if (subtotal<=150) {shiptotal = 14}
					   else	{ shiptotal = subtotal*ShipRate
					   }
					  }
					}
				  }
				}
			 }
			 
			}

	document.ordform.shiptotal.value = currency(shiptotal,10)
    document.ordform.grandtotal.value = currency(ototal+shiptotal,10)	
  
}
 

//-- order up to $15....$6.00 
//-- $15.01  to  $25.....$7.50 
//-- $25.01  to  $50.....$9.00 
//-- $50.01  to  $75.....$10.50 
//-- $75.01  to  $100...$12.00 
//-- $100.01 to $150..$14.00 
//-- over $150.....add 10% 
//-- ---------End  Bruce's shipping play 




//-- Copies the "Bill To" information to the "Ship To" information.
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.shipCSZ.value=document.ordform.billCSZ.value
   document.ordform.shipPhone.value=document.ordform.billPhone.value
   document.ordform.shipEmail.value=document.ordform.billEmail.value
}

//-- Shows number in $$xxx,xxx.xx format and pads left side with blanks.
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"}

   //--- Adds comma in thousands place.
   if (dNum>=1000) {
      dLen=dStr.length
      dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
   }

   //-- Adds comma in millions place.
   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
}
 -->
