function changeFields()
{
	if(document.getElementById('scale_imperial').checked == true)
	{
		document.getElementById('imperial_fields').style.display = 'block';
		document.getElementById('metric_fields').style.display = 'none';
	}
	else
	{
		document.getElementById('imperial_fields').style.display = 'none';
		document.getElementById('metric_fields').style.display = 'block';
	}
}

function calculateBmi()
{
	if(document.getElementById('scale_imperial').checked == true)
	{
		// Validate fields
		var bmi_feet_val = document.getElementById('bmi_feet').options[document.getElementById('bmi_feet').selectedIndex].value;
		var bmi_inches_val = document.getElementById('bmi_inches').options[document.getElementById('bmi_inches').selectedIndex].value;
		var bmi_stone_val = document.getElementById('bmi_stone').options[document.getElementById('bmi_stone').selectedIndex].value;
		var bmi_lbs_val = document.getElementById('bmi_lbs').options[document.getElementById('bmi_lbs').selectedIndex].value;
		
		if((bmi_feet_val == 0) || (bmi_stone_val == 0))
		{
			document.getElementById('error').innerHTML = "You must enter your height and weight";
			document.getElementById('bmi_text').innerHTML = "__";
		}
		else
		{
			// Calulate BMI
			var weight_in_lbs = (parseInt(bmi_stone_val) * 14) + parseInt(bmi_lbs_val);
			var height_in_inches = (parseInt(bmi_feet_val) * 12) + parseInt(bmi_inches_val);
			var bmi_figure = ((parseInt(weight_in_lbs) * 703)) / (parseInt(height_in_inches) * parseInt(height_in_inches));
			var final_bmi = Math.round(bmi_figure*10)/10;
					
			// Write BMI to screen
			document.getElementById('error').innerHTML = "";
			document.getElementById('bmi_text').innerHTML = final_bmi;
		}
	}
	else
	{
		// Validate fields
		var bmi_cm_val = document.getElementById('bmi_cm').options[document.getElementById('bmi_cm').selectedIndex].value;
		var bmi_kgs_val = document.getElementById('bmi_kgs').options[document.getElementById('bmi_kgs').selectedIndex].value;
				
		if((bmi_cm_val == 0) || (bmi_kgs_val == 0))
		{
			document.getElementById('error').innerHTML = "You must enter your height and weight";
			document.getElementById('bmi_text').innerHTML = "__";
		}
		else
		{
			// Calulate BMI
			var weight_in_kgs = parseInt(bmi_kgs_val);
			var height_in_cm = parseInt(bmi_cm_val);
			var height_in_m = parseInt(bmi_cm_val) / 100;
			var height_in_m_sq = parseFloat(height_in_m) * parseFloat(height_in_m);
			var bmi_figure = parseInt(weight_in_kgs) / parseFloat(height_in_m_sq);
			var final_bmi = Math.round(bmi_figure*10)/10;
				
			// Write BMI to screen
			document.getElementById('error').innerHTML = "";
			document.getElementById('bmi_text').innerHTML = final_bmi;
		}
	}
}