function calcbmi(){
 
   
   w = document.getElementById('q3').value; //weight, pounds
   v = document.getElementById('q1').value; //height, feet
   u = document.getElementById('q2').value; //height, inches
   
   if(v > 0 && w > 0)
   {
	   var display = '';
	   
	   if(v > 9 || u >= 12 || (v > 8 && u >= 12) )
	   {
	   		display = '<div class=\'bmistatus\'>Error</div><div class="divider"></div>Our system threshold is 9 feet.<br />Inches value must be less than 12.';
			document.getElementById('results').innerHTML = display;
			document.getElementById('q1').focus();
	   }
		else
		{
		   var i =  parseInt(v * 12) + u*1.0;  // var i = fi + ii; aeisenberg@air.org: now the height in inches is correctly summed
		
		  // Do validation of remaining fields to check for existence of values
			
		   var newbmi = cal_bmi(w, i);
		   
		   document.getElementById('q10').value = newbmi;
		   
		   document.getElementById('bmi').innerHTML = "<strong>" + newbmi + "</strong>";
		   
			var always = '<div class=\'bmistatus\'>* NHI Qualifies Obesity as<br />a BMI of 30 or greater</div>';
			
			if(newbmi < 18.5) { display = '<div class=\'bmistatus\'>You Are Underweight</div> BMI < 18.5<div class="divider"></div>' + always; }
			if(newbmi > 18.5 && newbmi <= 24.9) { display = '<div class=\'bmistatus\'>You Are  Normal weight</div> BMI 18.5-24.9<div class="divider"></div>'  + always; }
			if(newbmi > 24.9 && newbmi <= 29.9) { display = '<div class=\'bmistatus\'>You Are Overweight</div> BMI 25-29.9<div class="divider"></div>'  + always; }
			if(newbmi > 29.9) { display = '<div class=\'bmistatus\'>Obesity</div> BMI of 30 or greater'; }
			
			document.getElementById('results').innerHTML = display;
		}
	

   }
   else
   {
	   display = '<div class=\'bmistatus\'>Error</div><div class="divider"></div>You Must Have Values Entered for Height and Weight.';
		document.getElementById('results').innerHTML = display;
		document.getElementById('q1').focus();
   }
   
   
}

function calcbmiquiet(){
 
   
   w = document.getElementById('q3').value; //weight, pounds
   v = document.getElementById('q1').value; //height, feet
   u = document.getElementById('q2').value; //height, inches
   
   if(v > 0 && w > 0)
   {
	   
		   var i =  parseInt(v * 12) + u*1.0;  // var i = fi + ii; aeisenberg@air.org: now the height in inches is correctly summed
		
		  // Do validation of remaining fields to check for existence of values
			
		   var newbmi = cal_bmi(w, i);
		   
		   document.getElementById('q10').value = newbmi;
	

   }
   
   
}

function cal_bmi(lbs, ins)
{
   h2 = ins * ins;
   bmix = lbs/h2 * 703 /* seems we have to redeclare this due to the #bmi on the page */
   f_bmi = Math.floor(bmix);
   diff  = bmix - 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;
   }
   bmix = f_bmi + "." + diff;   
   return bmix;
}

function chkw(w){
   if (isNaN(parseInt(w))){
      return false;
   } else if (w < 0){
  return false;
  }
  else{
  return true;
  }
}

function masque(field, event)
{
	/* debug: */
	/* alert(field.name + ":" + String.fromCharCode(event.which)); */
	
	var key, keyChar;
	if(window.event)
		key = window.event.keyCode;
	else if (event)
		key = event.which;
	else
		return true;
	
	//chekc for special chars like backspace
	if(key==null || key == 0 || key == 8 || key == 13 || key == 27)
		return true;
	//Check and see if it's a number
	keyChar = String.fromCharCode(key);
	if(/\d/.test(keyChar))
	{
		window.status = "";
		return true;
	}
	else
	{
		window.status = "Field accepts numbers only";
		return false;
	}
}
