function change_measuring(type)
{
	f_standart = self.document.forms['bmi_input_standart'];
	f_metric = self.document.forms['bmi_input_metric'];
	if (type == 'standart')
	{
		f_standart.style.display = 'none';
		f_metric.style.display = '';
		document.getElementById('tab_standart').className = 'unselect-left';
		document.getElementById('tab_spacer').className = 'bmi-spacer-right';
		document.getElementById('tab_metric').className = 'select-right';
	}
	else
	{
		f_metric.style.display = 'none';
		f_standart.style.display = '';
		document.getElementById('tab_standart').className = 'select-left';
		document.getElementById('tab_spacer').className = 'bmi-spacer-left';
		document.getElementById('tab_metric').className = 'unselect-right';
	}
}

function cal_bmi_standart(lbs, ins)
{
   h2 = ins * ins;
   bmi = lbs/h2 * 703
   f_bmi = Math.floor(bmi);
   diff  = bmi - 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;
   }
   bmi = f_bmi + "." + diff;
   return bmi;
}
function compute_standart(){
   var f = self.document.forms['bmi_input_standart'];
   w = f.wt.value;
   v = f.htf.value;
   u = f.hti.value;
   if (!chkw_standart(u))
   {
     var ii = 0;
     f.hti.value = 0;
   } else
   {
     var it = f.hti.value*1;
     var ii = parseInt(it);
    }
   var fi = parseInt(f.htf.value * 12);
   var i =  parseInt(f.htf.value * 12) + f.hti.value*1.0;  // var i = fi + ii; aeisenberg@air.org: now the height in inches is correctly summed
   if (!chkw_standart(v))
   {
     alert("Please enter a number for your height.");
     f.htf.focus();
     return;
   }
   if (!chkw_standart(w))
   {
     alert("Please enter a number for your weight.");
     f.wt.focus();
     return;
   }
	f.bmi.value = cal_bmi_standart(w, i);
   //f.bmi.focus();
}

function chkw_standart(w){
   if (isNaN(parseInt(w)) || isNaN(w)){
      return false;
   } else if (w < 0){
  return false;
  }
  else{
  return true;
  }
}

function cal_bmi_metric(kg, htc){
   m = htc/100;
   h2 = m * m;
   bmi = kg/h2;
   f_bmi = Math.floor(bmi);
   diff  = bmi - 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;
   }
   bmi = f_bmi + "." + diff;
   return bmi;
}
function compute_metric(){
   var f = self.document.forms['bmi_input_metric'];
   w = f.kg.value;
   i = f.htc.value;
   if (!chkw_metric(i)){
     alert("Please enter a number for your height.");
     f.htc.focus();
     return;
   }
   if (!chkw_metric(w)){
     alert("Please enter a number for your weight.");
     f.kg.focus();
     return;
   }
   f.bmi.value = cal_bmi_metric(w, i);
   //f.bmi.focus();
}
function chkw_metric(w){
   if (isNaN(parseInt(w)) || isNaN(w)){
	  return false;
   } else if (w < 0){
  return false;
  }
  else{
  return true;
  }
}
