
// Root Values
var iWattHourRate = .09357
var iCustomerCharge = 11.00

// Running Total
var subtotal = 0

// Appliance Object
function objAppliance(name, watts, hours, kWH)
{
	this.name    = name
	this.watts   = watts
	this.hours   = hours
}

// Item Definitions
var item = new Array(86)
item[0] = new objAppliance("Air Cleaner", 75, 240)
item[1] = new objAppliance("Air Conditioner, 8000 BTU", 900, 200)
item[2] = new objAppliance("Air Cooler, Evaporative", 700, 90) 
item[3] = new objAppliance("Air Conditioner, Room", 1200, 90)
item[4] = new objAppliance("Battery Charger", 150, 6)
item[5] = new objAppliance("Blender", 300, 5)
item[6] = new objAppliance("Bottle Warmer", 350, 8)
item[7] = new objAppliance("Can Opener", 100, 1)
item[8] = new objAppliance("Carving Knife", 95, 1)
item[9] = new objAppliance("Clock", 3, 730)
item[10] = new objAppliance("Ceiling Fan", 100, 100)
item[11] = new objAppliance("Christmas Tree Lights", 480, 115)
item[12] = new objAppliance("Circular Saw", 1150, 2)
item[13] = new objAppliance("Clothes Dryer (electric)", 5000, 20)
item[14] = new objAppliance("Clothes Washer", 500, 12)
item[15] = new objAppliance("Coffee Maker", 800, 15)
item[16] = new objAppliance("Corn Popper", 575, 2)
item[17] = new objAppliance("Computer", 200, 60)
item[18] = new objAppliance("Crock Pot&#174;", 250, 40)
item[19] = new objAppliance("Curling Iron", 40, 12)
item[20] = new objAppliance("Dehumidifier", 500, 360)
item[21] = new objAppliance("Dish Washer (w/o hot wtr)", 200, 20)
item[22] = new objAppliance("Dish Washer (Dry Cycle)", 1200, 20)
item[23] = new objAppliance("Electric Blanket", 180, 120)
item[24] = new objAppliance("Fan (attic)", 400, 200)
item[25] = new objAppliance("Fan (furnace)", 200, 240)
item[26] = new objAppliance("Fan (window)", 200, 200)
item[27] = new objAppliance("Fax Machine", 300, 170)
item[28] = new objAppliance("Fish Tank", 110, 365)
item[29] = new objAppliance("Floor Polisher", 400, 2)
item[30] = new objAppliance("Fondue/Chafing Dish", 800, 2)
item[31] = new objAppliance("Food Processor", 350, 2)
item[32] = new objAppliance("Frying Pan, Electric", 600, 10)
item[33] = new objAppliance("Freezer (16 cu.ft)", 350, 292)
item[34] = new objAppliance("Freezer (16 cu.ft. nofrost)", 400, 292)
item[35] = new objAppliance("Garage Door Opener", 350, 1)
item[36] = new objAppliance("Garbage Disposal", 440, 3)
item[37] = new objAppliance("Griddle", 1200, 4)
item[38] = new objAppliance("Hair Dryer", 1500, 10)
item[39] = new objAppliance("Heater, Portable", 1500, 45)
item[40] = new objAppliance("Heating Pad", 60, 10)
item[41] = new objAppliance("Heating System blower fan", 400, 292)
item[42] = new objAppliance("Hedge Clipper", 250, 3)
item[43] = new objAppliance("Hot Tub", 1500, 73)
item[44] = new objAppliance("Humidifier", 200, 200)
item[45] = new objAppliance("Ice Cream Freezer", 130, 5)
item[46] = new objAppliance("Ice Crusher", 100, 3)
item[47] = new objAppliance("Iron", 1100, 3)
item[48] = new objAppliance("Lamp 100w", 100, 90)
item[49] = new objAppliance("Lamp, Fluorescent ", 27, 90)
item[50] = new objAppliance("Mixer (hand held)", 100, 20)
item[51] = new objAppliance("Mixer (stand)", 150, 20)
item[52] = new objAppliance("Microwave Oven", 1400, 30)
item[53] = new objAppliance("Oven (electric)", 5000, 5)
item[54] = new objAppliance("Range- Broiler", 3100, 10)
item[55] = new objAppliance("Refrigerator", 350, 237)
item[56] = new objAppliance("Refrigerator, Energy-Eff", 600, 237)
item[57] = new objAppliance("Refrigerator, Frost Free", 800, 237)
item[58] = new objAppliance("Roaster", 1425, 8)
item[59] = new objAppliance("Rotisserie", 1400, 8)
item[60] = new objAppliance("Sewing Machine", 100, 8)
item[61] = new objAppliance("Shaver, Electric", 15, 3)
item[62] = new objAppliance("Stereo", 120, 120)
item[63] = new objAppliance("Sun Lamp/Heat Lamp", 250, 15)
item[64] = new objAppliance("Swimming Pool - 1/2 HP", 500, 360)
item[65] = new objAppliance("TV, B&W 13 inch", 60, 120)
item[66] = new objAppliance("TV, Color 25 inch", 165, 120)
item[67] = new objAppliance("TV, Color 35 inch", 210, 120)
item[68] = new objAppliance("Toaster 2 slice", 1100, 4)
item[69] = new objAppliance("Toaster Oven", 1500, 10)
item[70] = new objAppliance("Tools - Bench Grinder", 500, 1)
item[71] = new objAppliance("Tools - Circular Saw", 1100, 1)
item[72] = new objAppliance("Tools - Drill", 440, 1)
item[73] = new objAppliance("Tools - Sabre Saw", 360, 1)
item[74] = new objAppliance("Tools - Sander, Belt", 600, 1)
item[75] = new objAppliance("Tools - Sander, Disc", 280, 1)
item[76] = new objAppliance("Tools - Soldering Gun", 600, 1)
item[77] = new objAppliance("Trash Compactor", 400, 1)
item[78] = new objAppliance("Typewriter", 100, 4)
item[79] = new objAppliance("Vacuum", 600, 4)
item[80] = new objAppliance("Vacuum - Central", 800, 5)
item[81] = new objAppliance("Vacuum - Electric Broom", 1000, 10)
item[82] = new objAppliance("VCR", 45, 30)
item[83] = new objAppliance("Warming Tray", 140, 5)
item[84] = new objAppliance("Water Heater, Electric ", 4500, 90)
item[85] = new objAppliance("Waterbed Heater- Double", 375, 250)

// Set Initial Form Values
function InitializeForm()
{
	//BillEstimator.CustomerCharge.value = '$' + iCustomerCharge;
	BillEstimator.WattHourRate.value = iWattHourRate;
}

// Populate Text Fields
function populate()
{
	var x = BillEstimator.items.options[BillEstimator.items.selectedIndex].value
	
	if (x == "") {}
	else
	{
		BillEstimator.amount.value = '1'
		BillEstimator.watt.value   = item[x].watts
		BillEstimator.hourly.value = item[x].hours
	}
}

// Calculate Charge
function calculate()
{
	var quantity = BillEstimator.amount.options[BillEstimator.amount.selectedIndex].text

	var x = (iWattHourRate) * quantity
	x *= (BillEstimator.watt.value / 1000) * (BillEstimator.hourly.value)
	x = parseFloat(x, 10)
	subt = Math.round((x) * 100)
	subt = (subt / 100)
	x = subt
	subtotal = subtotal + x
	
	writeIt(x)
}

// Print the currect calculation to the form
function writeIt(x)
{
	var Item    = BillEstimator.items.options[BillEstimator.items.selectedIndex].text
	var temp    = BillEstimator.ApplianceList.value
	
	var front   = temp 
	var mid     = Item
	var spacer  = " "
	var end     = "Cost: $" + x + " "
	var cost    = Item + spacer + end
	
	for (var i = (cost.length); i < 43; i++)
    {
		if (cost.length < 43)
		{
 			spacer = spacer + " "
			cost   = Item + spacer + end
		}else{
			break;
		}
	}
	
	BillEstimator.ApplianceList.value = temp + cost
	
	// Format the subtotal
	var stri   = "$" + subtotal
	var point = stri.indexOf(".")
	var front = stri.substring(0, (point + 1))
	var decimal = stri.substring((point + 1), stri.length)
	
	if (decimal.length > 2){decimal = decimal.substring(0, 2)}
	if (decimal.length == 1){decimal = decimal + "0"}
	if (decimal.length == 0){decimal = decimal + "00"}
	
	var newtotal = front + decimal
	
	BillEstimator.MonthlyBill.value  = newtotal
}

//               Check the values in the form.  1st to see if they exist, then to see if they are numbers
function checkform()
{
	var y = 0
	
	if (BillEstimator.items.value == "") {
		alert("Please Select an Appliance.");
		y += 1;
	}

	if (BillEstimator.watt.value != "")
	{
		inputStr = (BillEstimator.watt.value).toString()
		for (var i = 0; i < inputStr.length; i++)
		{
			var oneChar = inputStr.charAt(i)
			if (oneChar < "0" || oneChar > "9")
			{
				alert("Please enter a positive number in the Watts field.")
				y += 1
				break;
			}
		}
	}

	if ( y==0 && BillEstimator.hourly.value != "")
	{
		inputStr = (BillEstimator.hourly.value).toString()
		for (var i = 0; i < inputStr.length; i++)
		{
			var oneChar = inputStr.charAt(i)
			if (oneChar < "0" || oneChar > "9")
			{
				alert("Please enter a positive number in the Hours/month field.")
				y += 1
				break;
			}
		}
	}
	
	if (y == 0) { calculate(); }

}

//                           This prints out the help screen
function help()
{
	window.open('help.html','RMLD','width=350,height=375,toolbar=no,location=no,scrollbars=no,resizable=no');
     	return false;
}

function clearcalc() {

    BillEstimator.reset();
    subtotal = 0;
    
}


