// Body Mass Index (BMI) Calculator, version 1.0
function valButton(btn) {var cnt = -1;for (var i=btn.length-1; i > -1; i--) {   if (btn[i].checked) {cnt = i; i = -1;}}if (cnt > -1) return btn[cnt].value;else return null;}function stripBlanks(fld) {var result = "";var c = 0;for (i=0; i < fld.length; i++) {if (fld.charAt(i) != " " || c > 0) {result += fld.charAt(i);if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);}function calc(thisform) {var d = valButton(thisform.d);if (d == null) {alert("Please indicate whether your height and weight information in entered in centimetres/kilograms or inches/pounds.");return false;}cv = d.split(',');;var h = stripBlanks(thisform.h.value);if (h == '') {alert("You must enter your height before your Body Mass Index can be calculated.");thisform.h.focus();return false;}if (h != Number(h) || (h = Number(h*cv[0]/100)) < 1 || h > 2.5) {alert("The height information you have entered appears to be invalid. Please try again.");thisform.h.focus();return false;}var w = stripBlanks(thisform.w.value);if (w == '') {alert("You must enter your weight before your Body Mass Index can be calculated.");thisform.w.focus();return false;}if (w != Number(w) || (w = Number(w/cv[1])) < 25 || w > 250) {alert("The weight you have entered appears to be invalid. Please try again.");thisform.w.focus();return false;} thisform.f.value = Math.round(w / (h*h)*100)/100;}