// Ideal Body Weight Calculator

function noteText() {
  alert('This result field is used for displaying the calculated IBW value.\n\nTo perform a calculation:\n\n1. Enter your height\n2. Press - Calculate IBW');
  }

function calcWomen(formVal) {
  var idealWeight, plusminus, totalInches;
  var f = formVal;
  var v = parseInt(f.height_ft.value);
  var u = f.height_in.value;
  var w = f.body_type.options[f.body_type.selectedIndex].value;
  if (!chkw(u)){
    var ii = 0;
    f.height_in.value = 0;
  } else {
    var ii = parseInt(f.height_in.value);
  }
  if (!chkw(v)){
    alert("Please enter a number for your height.");
    f.height_ft.focus();
    return;
  }
  totalInches = ii + (v * 12);
  if (totalInches == 60) { idealWeight = 122; }
	if (totalInches > 60 < 72) { idealWeight = 122 + (2.5 * ii); }
	if (totalInches == 72) { idealWeight = 160; }
	if (totalInches > 72) { idealWeight = 160 + (2.5 * ii); }
	if (totalInches == 48) { idealWeight = 90; }
	if (totalInches < 60) { idealWeight = 90 + (2.5 * ii); }
  plusminus = Math.round(idealWeight * .07);
	if(w==1) { idealWeight = idealWeight - plusminus; }
	if(w==3) { idealWeight = idealWeight + plusminus; }		
  f.ibwResult.value = idealWeight;
  f.ibwResult.focus();
}

function calcMen(formVal) {
  var idealWeight, plusminus, totalInches;;
  var f = formVal;
  var v = parseInt(f.height_ft.value);
  var u = f.height_in.value;
  var w = f.body_type.options[f.body_type.selectedIndex].value;
  if (!chkw(u)){
    var ii = 0;
    f.height_in.value = 0;
  } else {
    var ii = parseInt(f.height_in.value);
  }
  if (!chkw(v)){
    alert("Please enter a number for your height.");
    f.height_ft.focus();
    return;
  }
  totalInches = ii + (v * 12);
	if (totalInches == 60) { idealWeight = 130;	}
  if (totalInches > 60) { idealWeight = 130 + (2.6 * ii);	}
	if (totalInches == 72) { idealWeight = 176;	}
	if (totalInches > 72) {	idealWeight = 176 + (2.6 * ii);	}
	if (totalInches == 48) { idealWeight = 95;	}
	if (totalInches < 60) {	idealWeight = 95 + (2.6 * ii); 	}
	plusminus = Math.round(idealWeight * .07);
	if(w==1) { idealWeight = idealWeight - plusminus; }
	if(w==3) { idealWeight = idealWeight + plusminus; }		
  f.ibwResult.value = idealWeight;
  f.ibwResult.focus();
}        

function chkw(w){
  if (isNaN(parseInt(w))){
    return false;
  } else if (w < 0){
    return false;
  }
  else{
    return true;
  }
}