function gObj(obj) {
var theObj;
if(document.all){
if(typeof obj=="string"){
return document.all(obj);
}else{
return obj.style;
}
}
if(document.getElementById){
if(typeof obj=="string"){
return document.getElementById(obj);
}else{
return obj.style;
}
}
return null;
}
function trimAll(sString){
while (sString.substring(0,1) == " "){
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == " "){
sString = sString.substring(0,sString.length-1);
}
return sString;
}
function isNumber(val){
val=val+"";
if (val.length<1) return false; if (isNaN(val)){ return false; }else{ return true; } } function formatNum(inNum){ outStr = ""+inNum; inNum = parseFloat(outStr); if ((outStr.length)>10){
outStr = "" + inNum.toPrecision(10);
}
if (outStr.indexOf(".")>-1){
while (outStr.charAt(outStr.length-1) == "0"){
outStr = outStr.substr(0,(outStr.length-1));
}
if (outStr.charAt(outStr.length-1) == ".") outStr = outStr.substr(0,(outStr.length-1));
return outStr;
}else{
return outStr;
}
}
function showquickmsg(inStr, isError){
if (isError) inStr = "" + inStr + "";
gObj("bmicoutput").innerHTML = inStr;
}
var girlA = new Array();
girlA[0] = new Array(0,0,0);
girlA[1] = new Array(0,0,0);
girlA[2] = new Array(14.4, 18, 19.1);
girlA[3] = new Array(14, 17.2, 18.3);
girlA[4] = new Array( 13.7, 16.8, 18);
girlA[5] = new Array( 13.5, 16.8, 18.3);
girlA[6] = new Array( 13.4, 17.1, 18.8);
girlA[7] = new Array( 13.4, 17.6, 19.6);
girlA[8] = new Array( 13.5, 18.3, 20.7);
girlA[9] = new Array( 13.7, 19.1, 21.8);
girlA[10] = new Array( 14, 19.9, 22.9);
girlA[11] = new Array( 14.4, 20.8, 24.1);
girlA[12] = new Array( 14.8, 21.7, 25.2);
girlA[13] = new Array( 15.3, 22.5, 26.5);
girlA[14] = new Array( 15.8, 23.5, 27.2);
girlA[15] = new Array( 16.3, 24, 28.1);
girlA[16] = new Array( 16.8, 24.7, 28.9);
girlA[17] = new Array( 17.2, 25.2, 29.6);
girlA[18] = new Array( 17.5, 25.7, 30.3);
girlA[19] = new Array( 17.8, 26.1, 31);
girlA[20] = new Array( 17.8, 26.5, 31.8);
var boyA = new Array();
boyA[0] = new Array(0,0,0);
boyA[1] = new Array(0,0,0);
boyA[2] = new Array(14.7, 18.2, 19.3);
boyA[3] = new Array( 14.4, 17.4, 18.3);
boyA[4] = new Array( 14, 16.9, 17.8);
boyA[5] = new Array( 13.8, 16.8, 17.9);
boyA[6] = new Array( 13.7, 17, 18.4);
boyA[7] = new Array( 13.7, 17.4, 19.1);
boyA[8] = new Array( 13.8, 17.9, 20);
boyA[9] = new Array( 14, 18.6, 21.1);
boyA[10] = new Array( 14.2, 19.4, 22.1);
boyA[11] = new Array( 14.5, 20.2, 23.2);
boyA[12] = new Array( 15, 21, 24.2);
boyA[13] = new Array( 15.5, 21.8, 25.1);
boyA[14] = new Array( 16, 22.6, 26);
boyA[15] = new Array( 16.5, 23.4, 26.8);
boyA[16] = new Array( 17.1, 24.2, 27.5);
boyA[17] = new Array( 17.7, 24.9, 28.2);
boyA[18] = new Array( 18.2, 25.6, 28.9);
boyA[19] = new Array( 18.7, 26.3, 29.7);
boyA[20] = new Array( 19.1, 27, 30.6);
function showCalc(inval){
if (inval == 2){
gObj("standardheightweight").style.display = "none";
gObj("metricheightweight").style.display = "block";
}else{
gObj("standardheightweight").style.display = "block";
gObj("metricheightweight").style.display = "none";
}
}
function getTheWeight(bmiNum, heightNum, weightUnit){
outPutNum = 0;
if (weightUnit == "kg"){
outPutNum = bmiNum * heightNum * heightNum / 10000;
outPutNum = outPutNum.toFixed(1);
}else{
outPutNum = bmiNum * heightNum * heightNum / 4535.92;
outPutNum = outPutNum.toFixed(1);
}
return outPutNum;
}
function bmicalc(){
showquickmsg("calculating...",true);
cage = gObj("cage").value;
cheightfeet = gObj("cheightfeet").value;
cheightinch = gObj("cheightinch").value;
cpound = gObj("cpound").value;
cheightmeter = gObj("cheightmeter").value;
ckg = gObj("ckg").value;
ctype = "metric";
ismale=false;
if (gObj("csex1").checked){
ismale = true;
}
if (!isNumber(cage) || (cage.length<1)){ showquickmsg("age need to be numeric",true); return; }else{ if ((cage < 2) || (cage > 120)){
showquickmsg("age need to be between 2 and 120",true);
return;
}
}
if (ctype=="standard"){
if ((!isNumber(cheightfeet)) || (!isNumber(cheightinch)) || (cheightfeet.length<1) || (cheightinch.length<1)){ showquickmsg("height need to be numeric",true); return; }else if (!isNumber(cpound) || (cpound.length<1)){ showquickmsg("weight need to be numeric",true); return; } cheightmeter = 30.48 * parseFloat(cheightfeet) + 2.54 * parseFloat(cheightinch); ckg = parseFloat(cpound) * 0.453592; }else{ if (!isNumber(cheightmeter) || (cheightmeter.length<1)){ showquickmsg("height need to be numeric",true); return; }else if (!isNumber(ckg) || (ckg.length<1)){ showquickmsg("weight need to be numeric",true); return; } ckg=parseFloat(ckg); cheightmeter=parseFloat(cheightmeter); } cage=parseFloat(cage); cbmi = 10000*ckg/cheightmeter/cheightmeter; cbmi = parseFloat(formatNum(cbmi)).toFixed(2); outPutStr = "BMI = " + cbmi + " kg/m2 (";
if (cage > 20){
if (cbmi<16.5){ outPutStr += "severely underweight";
}else if(cbmi<18.5){ outPutStr += "Underweight";
}else if(cbmi<25){ outPutStr += "Normal";
}else if(cbmi<30){ outPutStr += "Overweight";
}else if(cbmi<35){ outPutStr += "Obese Class I";
}else if(cbmi<40){ outPutStr += "Obese Class II";
}else{
outPutStr += "Obese Class III";
}
outPutStr += ")";
outPutStr += " normal BMI range: 18.5 - 25 kg/m2";
if (ctype=="standard"){
outPutStr += " normal weight range for the height: " + getTheWeight(18.5, cheightmeter, "lb") + " - " + getTheWeight(25, cheightmeter, "lb") + " lbs";
}else{
outPutStr += " normal weight range for the height: " + getTheWeight(18.5, cheightmeter, "kg") + " - " + getTheWeight(25, cheightmeter, "kg") + " kgs";
}
}else{
line5 = 0;
line85 = 0;
line95 = 0;
if (ismale){
line5 = boyA[cage][0];
line85 = boyA[cage][1];
line95 = boyA[cage][2];
}else{
line5 = girlA[cage][0];
line85 = girlA[cage][1];
line95 = girlA[cage][2];
}
if (cbmi
}else if(cbmi
}else if(cbmi
}else{
outPutStr += "Overweight";
}
outPutStr += ")";
outPutStr += " normal BMI range: " + line5 + " - " + line85 + " kg/m2";
if (ctype=="standard"){
outPutStr += " normal weight range for the height: " + getTheWeight(line5, cheightmeter, "lb") + " - " + getTheWeight(line85, cheightmeter, "lb") + " lbs";
}else{
outPutStr += " normal weight range for the height: " + getTheWeight(line5, cheightmeter, "kg") + " - " + getTheWeight(line85, cheightmeter, "kg") + " kgs";
}
}
outPutStr += " ";
showquickmsg(outPutStr, false);
}