/* This function takes input from the user regarding his or her last fuel bill,
*  converts the amount of energy received into kilowatt-hours to find the 
*  base cost of each kilowatt-hour, and then accepts the efficiency of the user's
*  furnace to give a more accurate estimate of their actual cost/kilowatt-hour.
*  It then computes how much it would have cost them to buy the same number of
*  kilowatt-hours of the other fuel types so the user can tell how much money
*  he would have saved. 
*/

function compare(form,fuel_type) {

var bill_amount = "";
var quantity = "";
var efficiency = "";
var fuel = fuel_type;

if (fuel == 'oil') {
bill_amount = form.oil_bill_amount.value;
quantity = form.oil_quantity.value;
efficiency = form.oil_efficiency.value;
conversion_rate = 40.17341;
}

else if (fuel == 'gas') {
bill_amount = form.gas_bill_amount.value;
quantity = form.gas_quantity.value;
efficiency = form.gas_efficiency.value;
conversion_rate = 28.90173;
}

else if (fuel == 'propane') {
bill_amount = form.propane_bill_amount.value;
quantity = form.propane_quantity.value;
efficiency = form.propane_efficiency.value;
conversion_rate = 26.30058;
}

else if (fuel == 'electricity') {
bill_amount = form.electricity_bill_amount.value;
quantity = form.electricity_quantity.value;
efficiency = form.electricity_efficiency.value;
conversion_rate = 1;
}

if (bill_amount == "") {
    alert('Please enter your Bill Amount.');
    }
if (quantity == "") {
    alert('Please enter the total number of units of fuel. For oil and propane, this is measured in Gallons; for gas in Therms; and for electricity in kilowatt-hours.');
    }
if (efficiency == "") {
    alert('Please enter your Furnace Efficiency. If you don\'t know, use 75.');
    }
        
    base_cost_kwh = bill_amount/quantity/conversion_rate;
    
    // convert efficiency into a percentage
    efficiency = efficiency/100;
    
    real_cost_kwh = base_cost_kwh/efficiency;
    
if (fuel == 'oil') {
    form.oil_real_cost.value = real_cost_kwh; 
}

else if (fuel == 'gas') {
    form.gas_real_cost.value = real_cost_kwh; 
}

else if (fuel == 'propane') {
    form.propane_real_cost.value = real_cost_kwh; 
}

else if (fuel == 'electricity') {    
    form.electricity_real_cost.value = real_cost_kwh; 
}

} 