$(function (){
	$(".calculate_bmi").click(function(){
		var height = $("#bmi_height").val();
		var weight = $("#bmi_weight").val();
		
		var error = validateBmi(height, weight);
		
		if(error != ""){
			alert(error);
			return false;
		}
		
		var bmi = Math.round(weight / Math.pow(height / 100,2), 1);
		
		$("#bmi_result").html(bmi);
		$(".results").show();
		
	});
});

function validateBmi(height, weight){
	var error = "";

	if(isNaN(height)){
		error += "Height must be a number\n";
	}
	if(height == ""){
		error += "Height must be a number\n";
	}
	if(isNaN(weight)){
		error += "Weight must be a number";
	}
	if(weight == ""){
		error += "Weight must be a number\n";
	}
	
	return error;
}