﻿function imperial_BMI() {
	var feet = document.form1.feet.value;
	var inches = document.form1.inches.value;
	var weight = document.form1.weight.value;
	if ((! inches) || isNaN(inches))
     inches = 0;
	var inchtotal = eval(feet*12) + eval(inches);
	var BMI = Math.round(weight * 703 * 10 / inchtotal / inchtotal) / 10;
	var bmi1 = document.getElementById("bmi1").innerHTML;
	if (BMI < 18.5) {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which is usually classed as underweight. You might want to speak to your GP about whether gaining some weight would benefit your health. Why not try some of our delicious " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + " or find out more about " + "healthy eating".link("http://www.wcrf-uk.org/cancer_prevention/diet/index.php") + ".";
	} else if (BMI < 25) {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which means you are in the healthy weight range. To help you maintain a healthy weight, try some of our delicious " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + " or our " + "healthy weight tips".link("http://www.wcrf-uk.org/cancer_prevention/weight/index.php") + ".";		
	} else if (BMI < 30) {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which means you are in the overweight range. Losing some weight would benefit your health and reduce your risk of cancer. Try our delicious " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + " and " + "healthy weight tips".link("http://www.wcrf-uk.org/cancer_prevention/weight/index.php") + " to get you started.";
	} else {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which means you are in the very overweight or obese category. Losing weight would make a big difference to your health - you might want to speak to your GP about the best way to do this. Find out more about the link between " + "overweight and cancer".link("http://www.wcrf-uk.org/cancer_prevention/recommendations/weight_and_cancer.php") + " or try some of our delicious healthy " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + ".";	
	}
	document.getElementById('bmi1').innerHTML = newBMI;
}
function metric_BMI() {
	var regexp = /,/;
	var height = document.form2.height.value;
	var height2 = height.replace(regexp, ".");
	var weight = eval(document.form2.weight.value);
  	var BMI = weight  / (height2 * height2);
	var head1 = document.getElementById("bmi1").innerHTML;
	if (BMI < 18.5) {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which is usually classed as underweight. You might want to speak to your GP about whether gaining some weight would benefit your health. Why not try some of our delicious " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + " or find out more about " + "healthy eating".link("http://www.wcrf-uk.org/cancer_prevention/diet/index.php") + ".";
	} else if (BMI < 25) {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which means you are in the healthy weight range. To help you maintain a healthy weight, try some of our delicious " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + " or our " + "healthy weight tips".link("http://www.wcrf-uk.org/cancer_prevention/weight/index.php") + ".";		
	} else if (BMI < 30) {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which means you are in the overweight range. Losing some weight would benefit your health and reduce your risk of cancer. Try our delicious " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + " and " + "healthy weight tips".link("http://www.wcrf-uk.org/cancer_prevention/weight/index.php") + " to get you started.";
	} else {
		var newBMI = "Your BMI is " + custRound(BMI,1) + ", which means you are in the very overweight or obese category. Losing weight would make a big difference to your health - you might want to speak to your GP about the best way to do this. Find out more about the link between " + "overweight and cancer".link("http://www.wcrf-uk.org/cancer_prevention/recommendations/weight_and_cancer.php") + " or try some of our delicious healthy " + "recipes".link("http://www.wcrf-uk.org/cancer_prevention/healthy_recipes.php") + ".";	
	}
	document.getElementById('bmi1').innerHTML = newBMI;
}
function custRound(x,places) {
  return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

function formatMoneyOut(n) {
    return n.toLocaleString().split(".")[0] + "," + n.toFixed(1).split(".")[1];
}

