// JavaScript Document

function calculate_bmi(lbs, inches){
	   h2 = inches * inches;
	   bmi = lbs/h2 * 703
	   bmifloor = Math.floor(bmi);
	   d  = bmi - bmifloor;
	   d = d * 10;
	   d = Math.round(d);
	   if (d == 10){
	      // Add up to next
	      bmifloor += 1;
	      d = 0;
	   }
	   bmi = bmifloor + "." + d;
	   return bmi;
	}
	function compute(){
	   var f = document.forms[0];
	   var fi = parseInt(f.feetH.options[f.feetH.selectedIndex].value * 12);
	   var ii = parseInt(f.inchH.options[f.inchH.selectedIndex].value);
	   var i = fi + ii;
	   w = f.wt.value;
	   if (chkw(w)){
	      f.bmi.value = calculate_bmi(w, i);
	   } else { alert("Please enter your weight."); }
	}
	function chkw(w){
	   if (isNaN(parseInt(w))){
	      return false;
	   } else if (w < 0){
	      return false;
	   }
	   else{
	      return true;
	   }
	}

function computeForm(form) { 
if ((form.age.value == null ||
form.age.value.length == 0) || (form.restinghr.value == null ||
form.restinghr.value.length == 0)) { return; }

if (form.sex[0].checked) {
       Item = 0;}
	
      else {Item = 1;} 
       
var maxhr = form.maxhr.value;
if (form.maxhr.value.length == 0 && Item == 0){
 maxhr = 208-parseInt(form.age.value*0.7);}
if (form.maxhr.value.length == 0 && Item == 1){
 maxhr = 208-parseInt(form.age.value*0.7);}
var resthr = form.restinghr.value;
var range = maxhr-resthr;

var easy1 = parseInt(range*0.60) + parseInt(resthr);
var easy2 = parseInt(range*0.75) + parseInt(resthr);
var tempo1 =  parseInt(range*0.85) + parseInt(resthr);
var tempo2 =  parseInt(range*0.90)+ parseInt(resthr);

var vo2max2 =  parseInt(range) + parseInt(resthr);

form.maxhr.value =  maxhr;
form.easyhr.value = easy1+"-"+easy2;
form.tempohr.value =tempo1+"-"+tempo2;
form.vo2maxhr.value = tempo2+"-"+maxhr;


 } 

function clearForm(form) { 
form.age.value = ""; form.restinghr.value = "";
form.easyhr.value = "";form.tempohr.value = ""; 
form.vo2maxhr.value = "";}

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);

function startCalc(){
			document.whr.calcval.value=0;
			interval = setInterval("calc()",1);
		}
		function calc(){
			one = document.whr.inchesW.value;
			two = document.whr.inchesH.value; 
			document.whr.calcval.value = Math.round(one/two * 100) / 100;
		}
		function stopCalc(){
			clearInterval(interval);
		}
