function get_selected(elm) { if ((elm.type == "select-one") || (elm.type == "select-multiple")) { value = " "; for (var i = 0; i < elm.options.length; i++) { if (elm.options[i].selected) value += elm.options[i].value; } } else { value = null; } return value; } function format_dollars(inAmount) { var isNeg = ""; if (inAmount < 0) { isNeg = "-"; inAmount = 0 - inAmount; } var num = inAmount.toString().replace(/\$|\,|\s/g,''); if (isNaN(num)) num = "0"; var cents = Math.floor((num*100+0.5)%100); num = Math.floor(num).toString(); if (isNaN(cents)) return ""; if (cents < 10) cents = "0" + cents; return (isNeg + num + '.' + cents); } function calc(f) { var watts_val = f.inc_watts.value; //get_selected(f.watts); var kWh_val = get_selected(f.kWh); var led_val = f.led_watts.value; var quantity = f.quantity.value; var dailyHours = f.hours.value; var inc_bulb_cost = f.inc_bulb_cost.value; var led_bulb_cost = f.led_bulb_cost.value; var led_bulb_life = get_selected(f.led_bulb_life); var current_lamp_hours_val = f.current_lamp_hours.value; var labor_cost = f.labor.value; if (isNaN(watts_val)) watts_val = 0; if (isNaN(kWh_val)) kWh_val = 0; if (isNaN(current_lamp_hours_val)) current_lamp_hours_val = 0; if (isNaN(led_val)) led_val = 0; if (isNaN(quantity)) quantity = 0; if (isNaN(dailyHours)) dailyHours = 0; if (isNaN(inc_bulb_cost)) inc_bulb_cost = 0; if (isNaN(led_bulb_cost)) led_bulb_cost = 0; if (isNaN(labor_cost)) labor_cost = 0; inc_cost = monthly_energy_savings(watts_val, kWh_val, dailyHours) * quantity; led_cost = monthly_energy_savings(led_val, kWh_val, dailyHours) * quantity; savings = inc_cost - led_cost; switch_cost = (led_bulb_cost-inc_bulb_cost)*quantity; payback_period = switch_cost/savings; var LampLife = 1000; var sLampLife = led_bulb_life; LifeAfterPayback = sLampLife/(dailyHours*30) - payback_period; //in months total_energy_savings = LifeAfterPayback * savings; led_incremental_savings = ((led_bulb_life/current_lamp_hours_val)*inc_bulb_cost)-led_bulb_cost; ext_labor_cost = (led_bulb_life/current_lamp_hours_val) * quantity * labor_cost; bulb_replacement_cost = led_incremental_savings * quantity; energy_savings = (watts_val-led_val)*led_bulb_life*kWh_val*quantity/1000; // initialize these to 0 if they are Not A Number (NaN) if (isNaN(total_energy_savings)) total_energy_savings = 0; if (isNaN(energy_savings)) energy_savings = 0; if (isNaN(ext_labor_cost)) ext_labor_cost = 0; if (isNaN(bulb_replacement_cost)) bulb_replacement_cost = 0; long_term_savings = total_energy_savings + ext_labor_cost + bulb_replacement_cost; f.inc_cost.value = "$" + format_dollars(inc_cost); f.led_cost.value = "$" + format_dollars(led_cost); f.savings.value = "$" + format_dollars(savings); f.switch_cost.value = "$" + format_dollars(switch_cost); f.payback_period.value = format_dollars(payback_period); f.total_energy_savings.value = "$" + format_dollars(energy_savings); f.labor_cost.value = "$" + format_dollars(ext_labor_cost); f.long_term_savings.value = "$" + format_dollars(long_term_savings); f.new_lamp_cost.value = "$" + format_dollars(led_bulb_cost); return false; } function monthly_energy_savings(watts, kWh, dailyHours) { return (watts * dailyHours * 30 * kWh)/1000; } function go() { calc(document.calc_form); } function gohome() { window.location('index.htm'); } //-->
|