function ccLiveNoPass(e){
var key = (window.Event) ? e.which : e.keyCode;
if ((key < 48 || key > 57) && (key < 0 || key > 9) && (key < 96 || key > 105) && (key != 37) && (key != 39)){
	if (key == 13) {
	self.compute();
	}
	return false;
}}

function ccEndCatch(e){
var key = (window.Event) ? e.which : e.keyCode;
	if (key == 13 || key == 9) {
	self.document.forms[1].htf.focus();
	}
}

function ccClearResults(){
var ccClearAllString = self.document.forms[1];
ccClearAllString.htf.value = "";
ccClearAllString.hti.value = "";
ccClearAllString.wt.value = "";
ccClearAllString.bmi.value = "";
changeResults(0);
ccClearAllString.htf.focus();
}

function cal_bmi(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){
      f_bmi += 1;
      diff   = 0;
   }
   bmi = f_bmi + "." + diff;
   return bmi;
}



function compute(){
   var f = self.document.forms[1];
   w = f.wt.value;
   v = f.htf.value;
   u = f.hti.value;
   
   if (!chkw(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;

   if (!chkw(v)){
     alert("Please enter a number for your height.");
     f.htf.focus();
     return;
   }
   if (!chkw(w)){
     alert("Please enter a number for your weight.");
     f.wt.focus();
     return;
   }
   f.bmi.value = cal_bmi(w, i);
   changeResults(cal_bmi(w, i));
   f.bmi.focus();
}



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



function changeResults(jjFinalBMI){
var ccCheckBMI = document.getElementById('bmiResults');
if (ccCheckBMI){
	var ni = document.getElementById('bmiResults');
	var divIdName = "bmiResultsSub";
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id",divIdName);
	if (ni.hasChildNodes()) {
		removeResults('bmiResultsSub');
		newdiv.innerHTML = jjPlainTextResults(jjFinalBMI);
		ni.appendChild(newdiv);
	} else {
		newdiv.innerHTML = jjPlainTextResults(jjFinalBMI);
		ni.appendChild(newdiv);
		}
	}
}



function removeResults(divNum){
var d = document.getElementById('bmiResults');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}


function jjPlainTextResults(ccBmiNumber){

jjPrintHighlightPRE = "<div style='color:#FFFFFF;font-weight: bold;background-color:#005751;padding: 2px 0px 2px 0px;margin:0px;width:190px'><span style='padding:0px 0px 0px 10px;'>"
jjPrintHighlightPOST = "</span></div>"

jjPrintNormPRE = "<div style='padding : 2px 0px 2px 10px;'>"
jjPrintNormPOST = "</div>"

jjResult001 = "Underweight less than 18.5"
jjResult002 = "Normal 18.5-24.9"
jjResult003 = "Overweight 25-29.9"
jjResult004 = "Obese I 30-34.9"
jjResult005 = "Obese II 35-39.9"
jjResult006 = "Morbid Obesity 40 and above"

jjResultsARR_001 = new Array (jjPrintNormPRE + jjResult001 + jjPrintNormPOST,jjPrintHighlightPRE + jjResult001 + jjPrintHighlightPOST)
jjResultsARR_002 = new Array (jjPrintNormPRE + jjResult002 + jjPrintNormPOST,jjPrintHighlightPRE + jjResult002 + jjPrintHighlightPOST)
jjResultsARR_003 = new Array (jjPrintNormPRE + jjResult003 + jjPrintNormPOST,jjPrintHighlightPRE + jjResult003 + jjPrintHighlightPOST)
jjResultsARR_004 = new Array (jjPrintNormPRE + jjResult004 + jjPrintNormPOST,jjPrintHighlightPRE + jjResult004 + jjPrintHighlightPOST)
jjResultsARR_005 = new Array (jjPrintNormPRE + jjResult005 + jjPrintNormPOST,jjPrintHighlightPRE + jjResult005 + jjPrintHighlightPOST)
jjResultsARR_006 = new Array (jjPrintNormPRE + jjResult006 + jjPrintNormPOST,jjPrintHighlightPRE + jjResult006 + jjPrintHighlightPOST)

	if ((ccBmiNumber > 0) && (ccBmiNumber < 18.5)) {
		jjLightswitch = new Array (1,0,0,0,0,0);
	} else if ((ccBmiNumber >= 18.5) && (ccBmiNumber <= 24.9)) {
		jjLightswitch = new Array (0,1,0,0,0,0);
	} else if ((ccBmiNumber >= 25) && (ccBmiNumber <= 29.9)) {
		jjLightswitch = new Array (0,0,1,0,0,0);
	} else if ((ccBmiNumber >= 30) && (ccBmiNumber <= 34.9)) {
		jjLightswitch = new Array (0,0,0,1,0,0);
	} else if ((ccBmiNumber >= 35) && (ccBmiNumber <= 39.9)) {
		jjLightswitch = new Array (0,0,0,0,1,0);
	} else if (ccBmiNumber >= 40) {
		jjLightswitch = new Array (0,0,0,0,0,1);
	} else {
		jjLightswitch = new Array (0,0,0,0,0,0);
	}
	 
	jjPrintResults = new Array (jjResultsARR_001[(jjLightswitch[1])],jjResultsARR_002[(jjLightswitch[1])],jjResultsARR_003[(jjLightswitch[2])],jjResultsARR_004[(jjLightswitch[3])],jjResultsARR_005[(jjLightswitch[4])],jjResultsARR_006[(jjLightswitch[5])]);
	if (ccBmiNumber > 0){
		jjPrintFinal = jjPrintResults.join("");
		jjPrintFinal = jjPrintFinal + "<img src='0i/sb_hdv_003.gif' alt='' height='24' width='228' border='0'>";
	} else {
		jjPrintFinal = "";
	}
return jjPrintFinal;
}

