														//Global Variables 
var RowsInForm = 2	 									//How many rows will be in the order details form 
var ProductsInList = 4      							//Must equal highest subscript in product list 
var ProdSubscript = 0 									//Identifies subscript of selected product in current row. 
var ShippingAmount = 0.50								//Set Shipping Amount e.g. 8.95 is $8.95
														//End of Global Variables
function MakeArray(n) { 								// Function to create a new empty array that starts at 1. 
this.length = n 
for (var i = 1; i<= n; i++) { 
this[i] = 0 
} 
return this 
} 
 	
function BuildZeroArray(n) { 							// Function to create a new, empty array that starts at zero.
this.length = n 
for (var i = 0; i<= n; i++) { 
this[i] = 0  
} 
return this 
} 

function prodobj(name, unitprice) { 					// Define a custom object named prodobj (Product Object). 
this.name = name 										// An array of these objects will act as our product/price list.
this.unitprice = unitprice 
} 

 
function ordobj(prodsub, qty, unitprice, extprice) { 	// Define a new custom object named ordobj (Order Object). 
this.prodsub = prodsub 									// Will house real numbers from order form to help with math.
this.qty = qty 
this.unitprice = unitprice 
this.extprice = extprice 
} 
 
function strToZero(anyval) { 							//convert any non-numeric value to a zero.
anyval = ""+anyval 
if (anyval.substring(0,1) < "0" || anyval.substring(0,1) > "9") { 
anyval = "0" 
} 
return eval(anyval) 
} 
 
function updateRow(rownum){ 							//update current row in order array and form.
var exec = 'ProdSubscript = document.ordform.prodchosen'+rownum+'.selectedIndex' 
eval (exec) 
ordData[rownum].prodsub=ProdSubscript //get qty from the form 
var exec='tempqty=document.ordform.qty'+rownum+'.value' 
eval (exec) 
ordData[rownum].qty = strToZero(tempqty) 				//get unit price from the product price list. 
ordData[rownum].unitprice=prodlist[ProdSubscript].unitprice 
ordData[rownum].extprice = (ordData[rownum].qty) * ordData[rownum].unitprice 
var exec = 'document.ordform.unitprice'+rownum+'.value = currencyPad(ordData['+rownum+'].unitprice,10)' 
eval (exec) 
var exec = 'document.ordform.extprice'+rownum+'.value = currencyPad(ordData['+rownum+'].extprice,10)' 
eval (exec) 
updateTotals()  										//update totals at bottom of form 
} 

function updateTotals() { 								//update the totals in the lower part of order details. 
var subtotal = 0 
for (var i=1; i<=RowsInForm; i++) { 
subtotal = subtotal + ordData[i].extprice 
} 
document.ordform.subtotal.value = currencyPad(subtotal,10) 
document.ordform.shipping.value = currencyPad(ShippingAmount,10)
document.ordform.grandtotal.value = currencyPad((subtotal+ShippingAmount),10) 
} 

function currencyPad(anynum,width) { 					//returns number as string in $xxx,xxx.xx format.
anynum = "" + eval(anynum) 								//evaluate (in case an expression sent)
                intnum=0 
                if (anynum >= 1) { 
                  intnum = parseInt(anynum) 
                }     
intstr = ""+intnum 										//isolate integer portion
if (intnum >= 1000) { 									//add comma in thousands place.
intlen = intstr.length 
temp1=parseInt(""+(intnum/1000)) 
temp2=intstr.substring(intlen-3,intlen) 
intstr = temp1+","+temp2 
        } 
if (intnum >= 1000000) { 
intlen = intstr.length 
temp1=parseInt(""+(intnum/1000000)) 
temp2=intstr.substring(intlen-7,intlen) 
intstr = temp1+","+temp2         
} 
decnum = Math.abs(parseFloat(anynum)-intnum) 			//isolate decimal portion 
decnum = decnum * 100 									// multiply decimal portion by 100. 
decstr = "" + Math.abs(Math.round(decnum)) 
while (decstr.length < 2) { 
decstr += "0" 
} 
retval = intstr + "." + decstr 
if (intnum < 0) { 
retval=retval.substring(1,retval.length) 
retval="("+retval+")"         
}        
retval = "$"+retval 
while (retval.length < width){ 
retval=" "+retval 
} 
return retval 
} 