<!-- Copyright 2002, Sandeep Gangadharan -->

function theBMI() {
var p = document.bmi.pounds.value;
var k = document.bmi.kilos.value;
var i = document.bmi.inches.value;
var f = document.bmi.feet.value;
var c = document.bmi.cms.value;

theWeight = (p / 2.205) || k;
theHeight = (((f * 12) + (i  * 1)) * 0.0254) || (c * 0.01);
document.bmi.answer.value = (Math.round((theWeight) / (theHeight * theHeight)));

if ((k >= 1) && (p >= 1)) { alert('Fill in either Kilos or Pounds, not both!'); return false; }
if ((c >= 1) && (f >= 1)) { alert('Fill in either in Feet or Centimeters, not both!'); return false; }
if ((i >= 1) && (c >= 1)) { alert('Fill in either in Feet or Centimeters, not both!'); return false; }

if ((f == "") && (c == "")) { alert('You have not filled in the Height field!'); return false; }
if ((p == "") && (k == "")) { alert('You have not filled in the Weight field!'); return false; }
if ((f == "") && (i >= 1)) { alert('You have not filled in the Feet field!'); return false; }

var ans = document.bmi.answer.value;
if (ans < 20) { document.bmi.comment.value = "You are underweight"; }
if (ans >= 20 && ans <= 22) { document.bmi.comment.value = "Desirable Weight"; }
if (ans >= 23 && ans <= 25) { document.bmi.comment.value = "Acceptable but not desirable"; }
if (ans >= 26 && ans <= 30) { document.bmi.comment.value = "Prone to health risks"; }
if (ans > 30) { document.bmi.comment.value = "High risk"; }

if (document.bmi.inches.value > 11 && document.bmi.inches.value <= 23) { (document.bmi.inches.value = parseInt(document.bmi.inches.value) - 12) && (document.bmi.feet.value = parseInt(document.bmi.feet.value) + 1); }
if (document.bmi.inches.value > 23) { (document.bmi.inches.value = parseInt(document.bmi.inches.value) - 24) && (document.bmi.feet.value = parseInt(document.bmi.feet.value) + 2); }
 }

