// Calorie Calculator

function noteText() {
  alert('This result field is used for displaying the calculated calorie value.\n\nTo perform a calculation:\n\n1. Enter your height, weight, age & exercise level\n2. Press - Calculate Calories');
  }

function calcWomen(formVal) {
  var weight, height, age;
  var f = formVal;
  var v = parseInt(f.height_ft.value);
  var u = f.height_in.value;
  var w = parseInt(f.weight_lbs.value);
  var y = parseInt(f.age.value);
  var a = f.exercise.options[f.exercise.selectedIndex].value;
  if (!chkw(u)){
    var ii = 0;
    f.height_in.value = 0;
  } else {
    var ii = parseInt(f.height_in.value);
  }
  var fi = v * 12;
  var i = fi + ii;
  if (!chkw(v)){
    alert("Please enter a number for your height.");
    f.height_ft.focus();
    return;
  }
  if (!chkw(w)){
    alert("Please enter a number for your weight.");
    f.weight_lbs.focus();
    return;
  }
  if (!chkw(y)){
    alert("Please enter a number for your age.");
    f.age.focus();
    return;
  }
  weight = 655 + (9.6 * (w/2.2));
  height = 1.7 * (i*2.54);
  age = 4.7 * y;
  f.resultWomen.value = (Math.round(weight + height - age) * a)
}


function calcMen(formVal) {
  var weight, height, age;
  var f = formVal;
  var v = parseInt(f.height_ft.value);
  var u = f.height_in.value;
  var w = parseInt(f.weight_lbs.value);
  var y = parseInt(f.age.value);
  var a = f.exercise.options[f.exercise.selectedIndex].value;
  if (!chkw(u)){
    var ii = 0;
    f.height_in.value = 0;
  } else {
    var ii = parseInt(f.height_in.value);
  }
  var fi = v * 12;
  var i = fi + ii;
  if (!chkw(v)){
    alert("Please enter a number for your height.");
    f.height_ft.focus();
    return;
  }
  if (!chkw(w)){
    alert("Please enter a number for your weight.");
    f.weight_lbs.focus();
    return;
  }
  if (!chkw(y)){
    alert("Please enter a number for your age.");
    f.age.focus();
    return;
  }
  weight = 66 + (13.7 * (w/2.2));
  height = 5 * (i*2.54);
  age = 6.8 * y;
  f.resultMen.value = (Math.round(weight + height - age) * a)
}

function chkw(w){
  if (isNaN(parseInt(w))){
    return false;
  } else if (w < 0){
    return false;
  }
  else{
    return true;
  }
}