// JavaScript Document
//RETAIL PRICES for 28, 32,36, 42, 48, 96 panels, base, cap, corner guards, quarter rounds
oakList = new Array ("25.75", "27.75", "29.95", "34.95", "39.95", "66.95", "2.49", "2.06", "7.95", "5.25")
poplarList = new Array ("19.50", "21.95", "23.50", "26.95", "31.50", "45.95", "1.69", "1.40", "4.95", "2.65")
mapleList = new Array ("29.95", "34.50", "35.95", "42.50", "47.95", "71.50", "2.59", "2.20", "4.95", "2.65")

function format (expr, decplaces) {
	var str = "" + Math.ceil (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces) {
		str = "0" + str
		}
	var decpoint = str.length - decplaces
	if (decplaces == 0) {
		return str.substring(0,decpoint) + str.substring(decpoint,str.length);
		}
	else {
		return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
		}	
	}
function dollarize (expr) {
	return "$" + format(expr,2)
	}
function calculateCoverage(inputNumber) {
	 var form = document.calculator
	 o = form.wood.selectedIndex
	 z = form.height.selectedIndex
	if (o == 0) {
		var panelPrice = oakList[z]
		var basePrice = oakList[6]
		var capPrice = oakList[7]
		var cornerPrice = oakList[8]
		var qroundPrice = oakList[9]
		}
	else if (o == 1) {
		var panelPrice = poplarList[z]
		var basePrice = poplarList[6]
		var capPrice = poplarList[7]
		var cornerPrice = poplarList[8]
		var qroundPrice = poplarList[9]
		}
	else if (o == 2) { 
		var panelPrice = mapleList[z]
		var basePrice = mapleList[6]
		var capPrice = mapleList[7]
		var cornerPrice = mapleList[8]
		var qroundPrice = mapleList[9]
		}
	//this section figures out the discount
	 var discount = 0
	 var custcode = form.custcode.value
	 if (custcode){
	 	//mo93wood is for How To Extreme magazine
		if (custcode == "mo93wood" || custcode == "4i38rg") {
	 		discount = .05
			}
		else if (custcode == "bw23c") {
	 		discount = .10
			}
		else if (custcode == "buy18n") {
	 		discount = .15
			}
		else if (custcode == "lo29w") {
	 		discount = .20
			}
		else { alert("Sorry, that is not a valid customer code"); }
		 if (discount){
		 	panelDisc = panelPrice * discount
			baseDisc = basePrice * discount
			capDisc = capPrice * discount
			cornerDisc = cornerPrice * discount
			qroundDisc = qroundPrice * discount
			panelPrice = format(panelPrice - panelDisc, 2)
			basePrice = format(basePrice - baseDisc, 2)
			capPrice = format(capPrice - capDisc, 2)
			cornerPrice = format(cornerPrice - cornerDisc, 2)
			qroundPrice = format(qroundPrice - qroundDisc, 2)
			}
		}

	 var feet = form.feet.value
	 var height = form.height.value
	 var wood = form.wood.value
	 var corner = form.corner.value
	 var qround = form.qround.value
	 for (var i = 0; i < form.surface.length; i++) { 
		  	if (form.surface[i].checked) {
				var surface = form.surface[i].value
				}
			}
	 var bdlPcs = 8
     if (feet) {
          var inches = feet * 12
		  var bundles = format(inches / 26, 0)
		  if (height == "96") {
		 	bundles = format(inches / 19.5, 0)
			bdlPcs = 6
			}
		  	var wall_panel = bundles + " bdls. " + height + "'' " + wood + " " + surface + " panel @ $" + panelPrice + " ea "
		  if (custcode) {
		  	wall_panel = wall_panel + "(" + custcode + ")"
			}
		  form.item_name_1.value = wall_panel
		  form.amount_1.value = dollarize(panelPrice * bundles)
		  var grandTotal = Number(panelPrice * bundles)
		  if (form.base.checked) {
			form.item_name_2.value = feet + " ft. base @ $" + basePrice + " per linear foot"
			form.amount_2.value = dollarize(feet * basePrice)
			grandTotal = Number(grandTotal) + Number(feet * basePrice)
			}
		  if (form.cap.checked) {
		  	form.item_name_3.value = feet + " ft. cap @ $" + capPrice + " per linear foot"
			form.amount_3.value = dollarize(feet * capPrice)
			grandTotal = Number(grandTotal) + Number(feet * capPrice)
			}
		  if (corner) {
		  	form.item_name_4.value = corner + " 8' corner guards @ $" + cornerPrice + " each"
			form.amount_4.value = dollarize(corner * cornerPrice)
			grandTotal = Number(grandTotal) + Number(corner * cornerPrice)
			}
		  if (qround) {
		  	form.item_name_5.value = qround + " 8' quarter rounds @ $" + qroundPrice + " each"
			form.amount_5.value = dollarize(qround * qroundPrice)
			grandTotal = Number(grandTotal) + Number(qround * qroundPrice)
			}
		if (discount) {
			form.totalprice.value = "TOTAL COST (incl. discount) IS " + dollarize(grandTotal)
			}
		else {
			form.totalprice.value = "TOTAL COST FOR THIS PROJECT IS " + dollarize(grandTotal)
			}
          }
     }