function rounding(number,decimal) 
{
multi = Math.pow(10,decimal);
number = Math.round(number * multi) / multi;
return number;
}
var feet_units = new Array();
feet_units[0]= new Array(0, 0, 'Units?');
feet_units[1]= new Array(2.54, 12, 'Ft/In');
feet_units[2]= new Array(1, 100, 'Mtr/Cen');
var pounds_units = new Array();
pounds_units[0]= new Array(0, 'Units?');
pounds_units[1]= new Array(2.2, 'Pounds');
pounds_units[2]= new Array(1, 'Kilos');
var sex = new Array();
sex[0]= new Array(0, 0, 0, 0, '(Please select)');
sex[1]= new Array(128, 50, 0, 0, 'Male');
sex[2]= new Array(148, 45.5, 0, 0, 'Female');
function calcular(form, sex_conversor, feet, feet_conversion, inches, pounds, pounds_conversor, years, activity)
{
if ((isNaN(sex_conversor)) || (sex_conversor == null)  || (sex_conversor == "") || (sex_conversor <= 0)) {alert("man or woman?!"); return false;}
if ((isNaN(feet_conversion)) || (feet_conversion == null)  || (feet_conversion == "") || (feet_conversion <= 0)) {alert("You must choose the height units!"); return false;}
if ((isNaN(pounds_conversor)) || (pounds_conversor == null)  || (pounds_conversor == "") || (pounds_conversor <= 0)) {alert("You must choose the weight units!"); return false;}
if ((isNaN(inches)) || (inches == null)  || (inches == "") || (inches < 0)) inches = 0;
Kilos       = pounds/pounds_units[pounds_conversor][0];
if (Kilos < 10) { alert("Weights should be heavier than 10 kilograms (22 pounds)."); return false;	}
if (Kilos > 200) { alert("Weights should be lighter than 200 kilograms (441 pounds).");	return false; }
Age         = years;
AgeCat      = 25; 
if ((isNaN(Age)) || (Age == null)  || (Age == "")) { alert("Please enter a specific age"); return false; }
else 
{
if ( Age < 1 ) { alert("Ages younger than 1 year old are too young for this calculation. Sorry."); return false; } 
if (Age > 120) { alert("All ages from 70 to 120 are treated as age 75."); return false;	}
}	
if (Age > 18) {  AgeCat = 25 } 
else { AgeCat = 26	}
TotalInches  = eval(feet*feet_units[feet_conversion][1]) + eval(inches);
Height       = TotalInches * feet_units[feet_conversion][0];
HeightMeters = Height/100;
HeightInches = Height/2.54;
if (HeightMeters < 0.33) { alert("Heights should be taller than 33 centimeters (31.5 inches)."); return false; }
if (HeightMeters > 2.41) { alert("Heights should be shorter than 241 centimeters ( 7 feet, 11 inches)."); return false; }
// Calculate BSA
bsa = Math.sqrt((HeightMeters * 100 * Kilos) / 3600);	// Mosteller method.
bsa = rounding(bsa,2);
// Calculate BMI
bmi = Kilos / Math.pow(HeightMeters,2);
bmi = rounding(bmi,1);
// SHOWING RESULTS
form.bsa.value = bsa;
form.bmi.value = bmi;
// Calculate Lean Body Weight and Ideal Body Weight
LeanConvert = sex[sex_conversor][0];
IdealConvert = sex[sex_conversor][1];
var LeanKg = 1.1 * Kilos - LeanConvert * (Math.pow(Kilos,2) / Math.pow((100 * HeightMeters),2));
var IdealKg = IdealConvert + 2.3 * (HeightInches - 60);
form.lean.value = Math.round(LeanKg * pounds_units[pounds_conversor][0]) + " " + pounds_units[pounds_conversor][1];
// 1 = weight in kg.
if (sex_conversor == 2) 
{  // sex is female. (sex_conversor=2)
if (Age > 18) 
{
IdealMin = Math.round((1.4106 * HeightInches) - 34.304);
IdealMax = Math.round((1.4674 * HeightInches) - 31.837);;
} 
else 
{  // age < 18
Ideal = Math.round(0.031*HeightInches*HeightInches - 1.7307*HeightInches + 35.446);
IdealMin = Ideal;
IdealMax = Ideal;
}
} 
if  (sex_conversor == 1) 
{										// sex is male.
if (Age > 18) 
{
IdealMin = Math.round((1.3122 * HeightInches) - 22.955);
IdealMax = Math.round((1.4774 * HeightInches) - 28.792);
} 
else 
{ // age < 18
Ideal = Math.round(0.0336*HeightInches*HeightInches - 1.9844*HeightInches + 40.93);
IdealMin = Ideal;
IdealMax = Ideal;
}
}
form.ideal.value = IdealMin*pounds_units[pounds_conversor][0] + " - " + IdealMax*pounds_units[pounds_conversor][0] + " " + pounds_units[pounds_conversor][1];
// Set Body Description.
var Interpret = "in Normal Range";
var OldAdj = 0;
var WeightKids = Kilos / Math.pow(HeightMeters,2.88);
if (Age > 64.9) { OldAdj = 3;}
else 
if (Age > 54.9) { OldAdj = 2; } 
else 
if (Age > 44.9) { OldAdj = 1; }
else OldAdj = 1;
// sex is female. (sex_conversor=2)
if (Age < 20) {	// Use W/H^2.88 instead of bmi for children.  
var WeightKids = kg / Math.pow(heightMeters,2.88);
if (sex_conversor == 2) {	// sex is female.
if (Age < 12) {
if (WeightKids > 15.82) {		// over 95th percentile. 97%ile = 16.33
Interpret = "Obese";
} else {
if (WeightKids > 14.17) {		// over 85th percentile. 90%ile = 14.55
Interpret = "Overweight";				// 75%ile = 13.4
} else {
if (WeightKids < 10.23) {		// under 5th percentile.  97%ile = 10.08
Interpret = "Underweight";
} else {
if (WeightKids < 10.85) {		// under 15th percentile. 90%ile = 10.61
Interpret = "Thin";    // under 75%ile = 11.34
}
}
}
}
} else {	// post-pubertal girls.
if (WeightKids > 15.80) {		// over 95th percentile. 97%ile = 15.89
Interpret = "Obese";
} else {
if (WeightKids > 15.21) {		// over 85th percentile.  90%ile = 15.58
Interpret = "Overweight";		// 75%ile = 14.46
} else {
if (WeightKids < 11.23) {		// under 5th percentile.  97%ile = 11.06
Interpret = "Underweight";
} else {
if (WeightKids < 12.01) {		// under 15th percentile.  90%ile = 11.64
Interpret = "Thin";		// 25%ile = 12.74
}
}
}
}
} 
} else {									// sex is male.
if (WeightKids > 15.77) {		// over 95th percentile.  97%ile = 16.16
Interpret = "Obese";
} else {
if (WeightKids > 14.45) {		// over 85th percentile.  90%ile = 14.81
Interpret = "Overweight";		// 75%ile = 13.73
} else {
if (WeightKids < 10.65) {		// under 5th percentile.  97%ile = 10.46
Interpret = "Underweight";
} else {
if (WeightKids < 11.36) {		// under 15th percentile.  90%ile = 11.14
Interpret = "Thin";		// 25%ile = 11.81
}
}
}
}
}
} else {		// Use bmi for adults over 19 year old.
if (sex_conversor == 2)  {  // sex is female.
if (bmi < (19.1+OldAdj)) {
Interpret = "Underweight";
} else {
if (bmi < (25.8+OldAdj)) {
Interpret = "in Normal Range";
} else {
if (bmi < (27.3+OldAdj)) {
Interpret = "Marginally Overweight";
} else {
if (bmi < (32.2+OldAdj)) {
Interpret = "Overweight";
} else {
Interpret = "Obese";
}
}
}
}
} else {										// sex is male.
if (bmi < (20.7+OldAdj)) {
Interpret = "Underweight";
} else {
if (bmi < (26.4+OldAdj)) {
Interpret = "in Normal Range";
} else {
if (bmi < (27.8+OldAdj)) {
Interpret = "Marginally Overweight";
} else {
if (bmi < (31.1+OldAdj)) {
Interpret = "Overweight";
} else {
Interpret = "Obese";
}
}
}
}
}
if (bmi < 10 || bmi > 50) Interpret = "Check your numbers";
}
form.Interpret.value = Interpret;
}