function installListeners()
{
	var hours_element = document.getElementById('hours');
	var days_element = document.getElementById('days');
	var submit_element = document.getElementById('submit');
	
	
	if(submit_element)
	{
		// set up the listener for the year field
		AttachEvent(submit_element, 'click', doCalculate, false);
	}

}

AttachEvent(window, 'load', installListeners, false);

function doCalculate()
{
	var table = document.getElementById('myTable');
	table.style.display = 'block';

	var hours_element = document.getElementById('hours');
	var days_element = document.getElementById('days');

	// get table cells
	var incandescent = document.getElementById('incandescent');
	var flourescent = document.getElementById('flourescent');
	var deskfan = document.getElementById('deskfan');
	var dehumidifier = document.getElementById('dehumidifier');
	var aircon = document.getElementById('aircon');
	var radiator = document.getElementById('radiator');
	var heater = document.getElementById('heater');
	var monitorcrt = document.getElementById('monitorcrt');
	var monitorlcd = document.getElementById('monitorlcd');
	var pcunit = document.getElementById('pcunit');
	var laptop = document.getElementById('laptop');
	var laserprinter = document.getElementById('laserprinter');
	var photocopier = document.getElementById('photocopier');
	var fax = document.getElementById('fax');
	var modem = document.getElementById('modem');
	var smallfridge = document.getElementById('smallfridge');
	var motor = document.getElementById('motor');
	var waterheater = document.getElementById('waterheater');
	var cooler = document.getElementById('cooler');
	var vendingmachine = document.getElementById('vendingmachine');

	var hours = hours_element.selectedIndex + 1;
	var days = days_element.selectedIndex + 1;

	incandescent.innerHTML = formatCurrency(hours * days * 0.44);
	flourescent.innerHTML = formatCurrency(hours * days * 0.29);
	deskfan.innerHTML = formatCurrency(hours * days * 0.06);
	dehumidifier.innerHTML = formatCurrency(hours * days * 0.22);
	aircon.innerHTML = formatCurrency(hours * days * 2.65);
	radiator.innerHTML = formatCurrency(hours * days * 1.55);
	heater.innerHTML = formatCurrency(hours * days * 5.26);
	monitorcrt.innerHTML = formatCurrency(hours * days * 0.42);
	monitorlcd.innerHTML = formatCurrency(hours * days * 0.26);
	pcunit.innerHTML = formatCurrency(hours * days * 0.20);
	laptop.innerHTML = formatCurrency(hours * days * 0.08);
	laserprinter.innerHTML = formatCurrency(hours * days * 0.38);
	photocopier.innerHTML = formatCurrency(hours * days * 3.59);
	fax.innerHTML = formatCurrency(hours * days * 0.02);
	modem.innerHTML = formatCurrency(hours * days * 0.07);
	smallfridge.innerHTML = formatCurrency(63.16);
	motor.innerHTML = formatCurrency(hours * days * 2.76);
	waterheater.innerHTML = formatCurrency(hours * days * 1.33);
	cooler.innerHTML = formatCurrency(196.82);
	vendingmachine.innerHTML = formatCurrency(hours * days * 1.23);

}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\£|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '&#163;' + dblValue + '.' + strCents);
}

function roundNumber(num, dec) 
{
	var result = Math.round(num * Math.pow(10,dec)) / Math.pow(10,dec);
	return result;
}
