
	var initBMICalculator = function () 
	{
		var calculate = document.getElementById('calculate');
		var feet = document.getElementById('feet');
		var inches = document.getElementById('inches');
		var pounds = document.getElementById('pounds');
		var result = document.getElementById('result');

		YAHOO.util.Event.addListener(calculate, 'click', getBMI);
		YAHOO.util.Event.addListener(feet, 'focus', function () { if (this.value == 'Feet') this.value = ''; });
		YAHOO.util.Event.addListener(feet, 'blur', function () { if (this.value == '') this.value = 'Feet'; });
		YAHOO.util.Event.addListener(inches, 'focus', function () { if (this.value == 'Inches') this.value = ''; });
		YAHOO.util.Event.addListener(inches, 'blur', function () { if (this.value == '') this.value = 'Inches'; });
		YAHOO.util.Event.addListener(pounds, 'focus', function () { if (this.value == 'Pounds') this.value = ''; });
		YAHOO.util.Event.addListener(pounds, 'blur', function () { if (this.value == '') this.value = 'Pounds'; });

		function getBMI(evnt)
		{
			YAHOO.util.Event.stopEvent(evnt);
			var bmi;
			var inchesN = parseInt(inches.value);
			var feetN = parseInt(feet.value);
			var poundsN = parseInt(pounds.value);

			if ( isNaN(feet.value) || isNaN(inches.value) || isNaN(pounds.value) )
			{ alert('Please ensure all inputs are numeric.'); }

			// BMI = 703 * (lbs / inch^2)
			// get total inches
			inchesN = inchesN + (feetN * 12);
			inchesN = (inchesN * inchesN);
			bmi = (703 * ( poundsN / inchesN) );

			if (!isNaN(bmi.toFixed(1)))
			{
				result.value = bmi.toFixed(1);
			}

			return false;
		}

	};
	
	// Register event handlers
	YAHOO.util.Event.addListener(window, 'load', initBMICalculator);
