// JavaScript Document
// JavaScript Document

<!--

function weight_ok(f) {

	var wt

	wt = parseInt(f.weight.value)

	if (isNaN(wt)) {

		return false

	} else if (wt <= 0) {

		return false

	} else if (wt > 999) {

		return false

	} else {

		return true;

	}

}

function get_weight(f) {

	var wt = f.weight.value * 1;

	var units = parseInt(f.weight_units.options[f.weight_units.selectedIndex].value);

	if (units == 0) {

	return wt

	} else {

	return (wt / 2.2)	

	}

}

function compute_bmi(f) {

	var ht_ft = parseInt(f.feet.options[f.feet.selectedIndex].value);

	var ht_in = parseInt(f.inches.options[f.inches.selectedIndex].value);

	var ht_m = (ht_ft * 12 + ht_in) * 2.54 / 100;

	var bmi;

	if (weight_ok(f)) {

		bmi = get_weight(f) / (ht_m * ht_m)

		//round "bmi_result" to one decimals:

		f.bmi_result.value = Math.round(bmi*10)/10

	} else { alert("Please enter a valid number for your weight."); }	

}

function interpret_bmi(f) {

	var bmindex = f.bmi_result.value * 1;

	if (bmindex < 0) 

		alert ("A BMI of less than 0 does not make any sense. Please check your numbers.")

	else if (bmindex < 35) 

		alert ("Your BMI is less than 35. Weight loss surgery is usually reserved for individuals with a BMI more than 35 - 40.") 

	else if (bmindex < 40)

		alert ("Your BMI is between 35 and 40. You may be a candidate for weight loss surgery if you have a major health problem caused by your obesity.") 

	else

		alert ("Your BMI is greater than 40. You may very well be a good candidate for weight loss surgery. Please consider a consultation with one of our surgeons for a more detailed evaluation.") 			

}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

//-->

