function calc (bHeight,bWeight) {
 //calculate Body Mass Index 
bWeightfinal=0.45359327*bWeight;
bHeightfinal=0.02540*bHeight;
 var bmassIndex=bWeightfinal/ Math.pow(bHeightfinal,2);
  return bmassIndex;
}

function adjustHeight(callerObj) {
  if( (callerObj.form.bFeet.value>=0 )    || (callerObj.form.bInch.value>=0) ) { 
		var bFeetVal = gMakeNumber(callerObj.form.bFeet.value, 0);
		var bInchVal = gMakeNumber(callerObj.form.bInch.value, 0 );
       
if (bInchVal >= 12) { 
		var bFeetVal =bFeetVal + Math.floor(bInchVal/12);   
		var bInchVal =bInchVal - (Math.floor(bInchVal/12)*12);   
		callerObj.form.bFeet.value = bFeetVal;
		callerObj.form.bInch.value = bInchVal;
                                            }
if ((bFeetVal*12 + bInchVal) >96) {

		callerObj.form.bFeet.value = 0;
		callerObj.form.bInch.value = 0;
       alert('Sorry, height cannot exceed 8 feet.');
   callerObj.form.bFeet.focus();
   callerObj.form.bFeet.select();
                                   } 

                                                                             }
                                 }

function Reset() {

document.BMICalculator.bWeight.value='';
document.BMICalculator.bFeet.value='';
document.BMICalculator.bInch.value='';
document.BMICalculator.bMassIndex.value='';
document.BMICalculator.bWeight.focus();

                }



function process(callerObj) {
if (!gIsNumber(callerObj.form.bWeight.value)  || (callerObj.form.bWeight.value.indexOf("-")!=-1)) { 
   alert("Please enter your weight again");
   callerObj.form.bWeight.focus();
   callerObj.form.bWeight.select();
   return false;
}
if (!gIsNumber(callerObj.form.bFeet.value) || (callerObj.form.bFeet.value.indexOf("-")!=-1)) { 
   alert("Please enter your height again");
   callerObj.form.bFeet.focus();
   callerObj.form.bFeet.select();
   return false;
}
if (!gIsNumber(callerObj.form.bInch.value) ||  (callerObj.form.bInch.value.indexOf("-")!=-1)) { 
   alert("Please enter your height again");
   callerObj.form.bInch.focus();
   callerObj.form.bInch.select();
   return false;
}

  var bFeetVal = gMakeNumber(callerObj.form.bFeet.value, 0);
  var bInchVal = gMakeNumber(callerObj.form.bInch.value, 0);
  var mNewFeetVal = Math.floor(bInchVal/12);
  bInchVal = (bInchVal%12);
  callerObj.form.bInch.value=bInchVal;
  bFeetVal+=mNewFeetVal;

bweight=parseInt( stripLeadingZeros( callerObj.form.bWeight.value ) );

  var cW = gMakeNumber(bweight, 0);

  // must have weight  and height  info:
        
  if (callerObj.form.bWeight.value == 0){
       alert('Please enter your weight again');
   callerObj.form.bWeight.focus();
   callerObj.form.bWeight.select();
   return;
                  }
 
  if ((bFeetVal == 0) && (bInchVal == 0)){
    alert('Please enter your height again');
   callerObj.form.bFeet.focus();
   callerObj.form.bFeet.select();
    return;
                                         }

  var rs = 0;
  
  var bH = gToInches(bFeetVal, bInchVal);
  

  rs=calc(bH,cW);
  callerObj.form.bMassIndex.value=roundToPennies(rs);
}

function  stripLeadingZeros( number ) {

  // convert to string
  number = "" + number;

  // strip out any leading zeros that might be interpreted as octal
  if ( number.indexOf("0") != -1 ) { //if it includes a 0 test:
    while ( number.indexOf("0") == 0 ) {
      number = number.substring( 1 );
    }
  }

  return number;

}

function roundToPennies(n)
{
   pennies = n * 100;
   pennies = Math.round(pennies);
   strp = "" + pennies;
   len = strp.length;
   return strp.substring(0,len-2) + "." + strp.substring(len-2,len);
}
