function calculate()
{
	var v = document.data.f.value - document.data.e.value;			// price diff

	document.data.x.value = 
		round( annualEnergyCost( document.data.h.value ), 0 );		// comp cost

	document.data.z.value = 
		round(annualEnergyCost( document.data.g.value ), 0 );		// TWMC cost

	document.data.w.value = 
		document.data.x.value - document.data.z.value;		// cost diff

	document.data.u.value = 
		round( v / -document.data.w.value, 1 );					// payback yrs

	document.data.s.value = 
		round( 360 * v / -document.data.w.value, 0 );		   	// payback days

}

function annualEnergyCost( effPct )
{	// Given percent efficiency (0 < effPct <= 100), calculate the
	// annual energy cost, based on the other form fields.
	return ( 
		document.data.a.value * .746 * 
		document.data.b.value * 
		document.data.c.value * 
		document.data.d.value *
		100 / effPct );				// divide last for greater accuracy
}

function round( n, decimals )
{
	var d = Math.pow( 10, decimals );

	return ( Math.round( n * d ) / d );
}
