function compute(){
  var f = self.document.forms[0];
  // Set up variables for calculation
  yr = f.age.value;
  sx = f.sex.value;
  wt = f.wt.value;
  ht = f.ht.value;
  // Do validation checking to ensure existence of values
  if (yr == 0){
    alert("Please select your child's age.");
    f.age.focus();
    return;
  }  
  if (!f.sex[0].checked && !f.sex[1].checked) {
    alert("Please select your child's sex.");
    return;
  }    
  if (wt == 0){
    alert("Please select your child's weight.");
    f.wt.focus();
    return;
  }
  if (ht == 0){
    alert("Please select your child's height.");
    f.ht.focus();
    return;
  }
  bmi = calc_bmi(wt, ht);
  phy = calc_phy(yr, sx, bmi);
  if (phy == 'Underweight') {
    txt = "According to your weight and height the BMI score shows your child is below the healthy weight range for their age. If you have any concerns, you should seek advice from your child's doctor.";
  } else if (phy == 'Healthyweight') {
    txt = "According to your weight and height the BMI score shows your child has a healthy weight for their age and height and you don't need to attend a Boost programme. Contact the Boost team at Croydon for further fun ways for all your family to  keep healthy and active!";
  } else if (phy == 'Overweight') {
    txt = "According to your weight and height the BMI score shows your child is above the healthy weight range for their age and height. A doctor would use the term 'overweight', which means your child's health could be at risk. Please register for a Boost Croydon course so we can help you to get back on track.";
  } else {
    txt = "According to your weight and height the BMI score shows your child is above the healthy weight range for their age and height. A doctor would use the term 'very overweight', which means your child's health could be at risk. Please register for a Boost Croydon course so we can help you to get back on track.";
  }
  f.bmi.value = bmi;
  f.txt.value = txt;
  f.bmi.focus();
}

function calc_bmi(wt, ht){
  m = ht/100;
  h2 = m * m;
  bmi = wt/h2;
  f_bmi = Math.floor(bmi);
  diff = bmi - f_bmi;
  diff = diff * 10;
  diff = Math.round(diff);
  if (diff == 10){
  // Need to bump up the whole thing instead
    f_bmi += 1;
    diff = 0;
  }
  bmi = f_bmi + "." + diff;
  return bmi;
}

function calc_phy(yr, sx, bmi){
  if (yr == 5) {
    if (sx == 'b') {
      if (bmi <= 13.5) {
        phy = 'Underweight';
      } else if (bmi < 17.4) {
        phy = 'Healthyweight';
      } else if (bmi < 18.6) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 13.1) {
        phy = 'Underweight';
      } else if (bmi < 17.7) {
        phy = 'Healthyweight';
      } else if (bmi < 19.1) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 6) {
    if (sx == 'b') {
      if (bmi <= 13.4) {
        phy = 'Underweight';
      } else if (bmi < 17.5) {
        phy = 'Healthyweight';
      } else if (bmi < 18.8) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 12.9) {
        phy = 'Underweight';
      } else if (bmi < 17.9) {
        phy = 'Healthyweight';
      } else if (bmi < 19.5) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 7) {
    if (sx == 'b') {
      if (bmi <= 13.3) {
        phy = 'Underweight';
      } else if (bmi < 17.8) {
        phy = 'Healthyweight';
      } else if (bmi < 19.3) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 13) {
        phy = 'Underweight';
      } else if (bmi < 18.4) {
        phy = 'Healthyweight';
      } else if (bmi < 20.2) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 8) {
    if (sx == 'b') {
      if (bmi <= 13.3) {
        phy = 'Underweight';
      } else if (bmi < 18.3) {
        phy = 'Healthyweight';
      } else if (bmi < 20) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 13.1) {
        phy = 'Underweight';
      } else if (bmi < 19) {
        phy = 'Healthyweight';
      } else if (bmi < 21.1) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 9) {
    if (sx == 'b') {
      if (bmi <= 13.4) {
        phy = 'Underweight';
      } else if (bmi < 18.8) {
        phy = 'Healthyweight';
      } else if (bmi < 20.8) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 13.3) {
        phy = 'Underweight';
      } else if (bmi < 19.7) {
        phy = 'Healthyweight';
      } else if (bmi < 22) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 10) {
    if (sx == 'b') {
      if (bmi <= 13.7) {
        phy = 'Underweight';
      } else if (bmi < 19.4) {
        phy = 'Healthyweight';
      } else if (bmi < 21.7) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 13.6) {
        phy = 'Underweight';
      } else if (bmi < 20.4) {
        phy = 'Healthyweight';
      } else if (bmi < 22.9) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 11) {
    if (sx == 'b') {
      if (bmi <= 14) {
        phy = 'Underweight';
      } else if (bmi < 20.1) {
        phy = 'Healthyweight';
      } else if (bmi < 22.6) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 14) {
        phy = 'Underweight';
      } else if (bmi < 21.2) {
        phy = 'Healthyweight';
      } else if (bmi < 23.9) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 12) {
    if (sx == 'b') {
      if (bmi <= 14.4) {
        phy = 'Underweight';
      } else if (bmi < 20.9) {
        phy = 'Healthyweight';
      } else if (bmi < 23.4) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 14.5) {
        phy = 'Underweight';
      } else if (bmi < 22) {
        phy = 'Healthyweight';
      } else if (bmi < 24.8) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }  
  if (yr == 13) {
    if (sx == 'b') {
      if (bmi <= 14.8) {
        phy = 'Underweight';
      } else if (bmi < 21.6) {
        phy = 'Healthyweight';
      } else if (bmi < 24.3) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    } else {  
      if (bmi <= 15) {
        phy = 'Underweight';
      } else if (bmi < 22.8) {
        phy = 'Healthyweight';
      } else if (bmi < 25.7) {
        phy = 'Overweight';
      } else {
        phy = 'Obese';
      }
    }
  }    
  return phy;
}