function round2DP(num) {
 // rounds a number to 2 decimal places
 return Math.round(num*100) / 100
} 
function cal_bmi(lbs, ins){
 //calculate height in metres
 ht = ins *2.54/100  
 //calculate wt in kg
 wt = lbs * .4536
 //calculate BMI (wt / height squared
 bmi = round2DP(wt/(ht*ht))

return bmi;
}

function showBMI(){
 var f = document.bmiform;
 var lbs, ins
 
 // Validate fields to check for existence of values
 if (!isposno(f.htfeet.value)){
  alert("Please enter a number for your height in feet.");
  f.htfeet.focus();
  return;
 }
 if (!isposno(f.htins.value)){
  alert("Please enter a number for your height in inches.");
  f.htins.focus();
  return;
 }
 if (!isposno(f.wtstone.value)){
  alert("Please enter a number for your weight in stones.");
  f.wtstone.focus();
  return;
 }
 if (!isposno(f.wtlbs.value)){
  alert("Please enter a number for your weight in pounds.");
  f.wtlbs.focus();
  return;
 }
 
 // Format values for the BMI calculation
 lbs = parseInt(f.wtstone.value*14) + parseInt(f.wtlbs.value)
 ins = parseInt(f.htfeet.value*12) + parseInt(f.htins.value)
 
 // Perform the calculation
 
f.bmi.value = cal_bmi(lbs, ins);
}

function isposno(no){
 // checks to see if a value is a positive number
 if (isNaN(parseInt(no))){
  return false;
 } else if (no < 0){
  return false;
 }
 else{
  return true;
 }
}
