<!--
//Global Variables

var RowsInForm = 1		//How many rows will be in the order details form
var ProductsInList = 0       //Must equal highest subscript in product list
var SalesTaxRate = 0.06		//Set to sales tax rate in decimal. e.g. 0.045 is 4.5%
var TaxableState = "CT"		//Set to name of state you charge sales tax in
var ProdSubscript = 0		//Identifies subscript of selected product in current row.
var Qty = 0



	// 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
	}

	// Define 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
	}



	// Define a new custom object named ordobj (Order Object).
	// Will house real numbers from order form to help with math.

	function ordobj(prodsub, Qty, UnitPrice, Price) {
		this.prodsub = prodsub
		this.Qty = Qty
		this.UnitPrice = UnitPrice
		this.Price = Price
	}



	//convert any non-numeric value to a zero.
	function strToZero(anyval) {
		anyval = ""+anyval
		if (anyval.substring(0,1) < "0" || anyval.substring(0,1) > "9") {
			anyval = "0"
		}
		return eval(anyval)
	}



	//update current row in order array and form.

	function updateRow(rownum){	
		var exec = 'ProdSubscript = document.ordform.Product'+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].Price = (ordData[rownum].Qty) * ordData[rownum].UnitPrice
		var exec = 'document.ordform.UnitPrice'+rownum+'.value = currencyPad(ordData['+rownum+'].UnitPrice,3)'
		eval (exec)
		var exec = 'document.ordform.Price'+rownum+'.value = currencyPad(ordData['+rownum+'].Price,3)'
		eval (exec)
		updateTotals() 			//update totals at bottom of form
	}

		

	//update 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].Price		}
		document.ordform.SubTotal.value = currencyPad(SubTotal,3)
		Shipping = 0
if ((SubTotal > 0) && (SubTotal <= 10.99)) {
			Shipping = SubTotal*25/100
		}

	if ((SubTotal >= 11.00) && (SubTotal <= 29.99)) {
			Shipping = SubTotal*13/100	
		}
		
	if ((SubTotal >= 30.00) && (SubTotal <= 74.99)) {
			Shipping = SubTotal*9/100	
		}		
		
	if (SubTotal >= 75) {
			Shipping = SubTotal*8/100
		}
				




		document.ordform.Shipping.value = currencyPad(Shipping,3)
		SalesTax = 0
		if (document.ordform.Taxable.checked) {
			SalesTax = SalesTaxRate * (SubTotal + Shipping)                    //make shipping taxable
		}
		document.ordform.SalesTax.value = currencyPad(SalesTax,3)
		document.ordform.GrandTotal.value = currencyPad(SubTotal+Shipping+SalesTax,3)
	}





	//copy the "Bill To" information to the "Ship To" information.

	function copyAddress() {
		document.ordform.ShipName.value = document.ordform.BuyerName.value
		document.ordform.ShipCompany.value = document.ordform.BuyerCompany.value
		document.ordform.ShipAdd1.value = document.ordform.BuyerAdd1.value
		document.ordform.ShipAdd2.value = document.ordform.BuyerAdd2.value
		document.ordform.ShipCSZ.value = document.ordform.BuyerCSZ.value
		document.ordform.ShipCountry.value = document.ordform.BuyerCountry.value
	}



	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)
                }    

		//isolate integer portion

		intstr = ""+intnum
		//add comma in thousands place.
		if (intnum >= 1000) {
			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"+decstr
		}
		retval = intstr + "." + decstr
		if (intnum < 0) {
			retval=retval.substring(1,retval.length)
			retval="("+retval+")"
		}
		retval = "$"+retval
		while (retval.length < width){
			retval=" "+retval
		}
		return retval
	}

//-->
