function mod(div,base) {
return Math.round(div - (Math.floor(div/base)*base));
}
function calcBmi() {
var w = document.bmi.weight.value * 1;
var HeightFeetInt = document.bmi.htf.value * 1;
var HeightInchesInt = document.bmi.hti.value * 1;
HeightFeetConvert = HeightFeetInt * 12;
h = HeightFeetConvert + HeightInchesInt;
displaybmi = (Math.round((w * 703) / (h * h)));
var rvalue = true;
if ( (w <= 35) || (w >= 500)  || (h <= 48) || (h >= 120) ) {
alert ("Invalid data.  Please check and re-enter!");
rvalue = false;
}
if (rvalue) {
if (HeightInchesInt > 11) {
reminderinches = mod(HeightInchesInt,12);
document.bmi.hti.value = reminderinches;
document.bmi.htf.value = HeightFeetInt + 
((HeightInchesInt - reminderinches)/12);
document.bmi.answer.value = displaybmi;
}
if (displaybmi <19) 
document.bmi.comment.value = "Underweight";
if (displaybmi >=19 && displaybmi <=25) 
document.bmi.comment.value = "Desirable";
if (displaybmi >=26 && displaybmi <=29) 
document.bmi.comment.value = "prone to health risks";
if (displaybmi >=30 && displaybmi <=40) 
document.bmi.comment.value = "Obese";
if (displaybmi >40) 
document.bmi.comment.value = "Extremely obese";
document.bmi.answer.value = displaybmi; }
return rvalue;
}


function targethr() {

var age=document.target.age.value;
var targetlow;
var targethigh;
if (document.target.rad[0].checked==true)
	{targetlow=Math.round((220-age)*.65)
	targethigh=Math.round((220-age)*.85)}
	else
	if (document.target.rad[1].checked==true)
	{targetlow=Math.round((205-(age/2))*.65)
	targethigh=Math.round((205-(age/2))*.85)}
	else
	if (document.target.rad[2].checked==true)
	{targetlow=Math.round((226-age)*.65)
	targethigh=Math.round((226-age)*.85)}
	else
	if (document.target.rad[3].checked==true)
	{targetlow=Math.round((211-(age/2))*.65)
	targethigh=Math.round((211-(age/2))*.85)}
	
document.target.targetlowvalue.value=targetlow;
document.target.targethighvalue.value=targethigh;

}


function ClearForm (form) {
form.weight.value="";
form.waist.value="";
form.bodyfat.value="";
}

function VerifyForm(form) {

// Holds whether or not the form is correct
var Correct = true;

// Check for missing fields
if (form.weight.value == null || form.weight.value.length == 0 ||
form.waist.value == null || form.waist.value.length == 0) {
alert ("\nPlease fill in all of the form elements");
Correct = false;
}

// Check that only numbers are in the weight and waist fields
else {
// Holds the floats representing the weight and waist
var TestWeight;
var TestWaist;

// Parse the weight and waist values and put in the variables
TestWeight = parseFloat(form.weight.value);
TestWaist = parseFloat(form.waist.value);

// Check to see that TestWeight is a number
if (isNaN (TestWeight)) {
alert("\nMake sure to enter the weight\nas a number.");
Correct = false;
form.weight.value="";
}

// Check to see that TestWaist is a number
if (isNaN (TestWaist)) {
alert("\nMake sure to enter the waist size\nas a number.");
Correct = false;
form.waist.value="";
}

// Check that the TestWeight is greater than 0
if (TestWeight <= 0) {
alert("\nCome on.Enter a real weight.");
Correct = false;
form.weight.value=""; 
}

// Check that the TestWaist is greater than 0
if (TestWaist <= 0) {
alert("\nCome on.Enter a real waist size.");
Correct = false;
form.waist.value="";
}

}

// If the inputs are correct, calculate the bodyfat percent
if (Correct) {

// Holds the bodyfat number and percent
var BF;
var BFPercent;

// Make the male calculations 
if (form.gender[0].checked) {
BF = -98.42 + 4.15*TestWaist - .082*TestWeight;
}

// Make the female calculations
else {
BF = -76.76 + (4.15*TestWaist) - (.082*TestWeight);
}

// Calculate the bodyfat percentage
BFPercent = BF / TestWeight;
BFPercent = BFPercent * 100;
BFPercent = Math.round(BFPercent);

// Send this number to the screen
form.bodyfat.value = BFPercent + "%";
}
}






var i2 = 0;



function checkNumber(input, min, max, msg) {



    msg = msg + " Field has invalid data: " + input.value;



    var str = input.value;



    for (var i = 0; i < str.length; i++) {



        var ch = str.substring(i, i + 1)



        if ((ch < "0" || "9" < ch) && ch != '.') {



            alert(msg);

            

            return false;



        }



    }



    var num = 0 + str



    if (num < min || max < num) {



        alert(msg + " not in range [" + min + ".." + max + "]");



        return false;



    }



    input.value = str;



    return true;



}



function computecalories2(input) {



 var calories=0;

 if (exercise=="Kickboxing" || exercise=="kickboxing") calories=.08;

 if (exercise=="DiscoDancing" || exercise=="discodancing") calories=.046;

 if (exercise=="Football" || exercise=="football") calories=.061; 

 if (exercise=="Golf" || exercise=="golf") calories=0.029; 

 if (exercise=="WalkDog" || exercise=="walkdog") calories=.033; 

 if (exercise=="WalkStroller" || exercise=="walkstroller") calories=.033; 

 if (exercise=="Stroll" || exercise=="stroll") calories=.023; 

 if (exercise=="Jogging" || exercise=="jogging") calories=.075; 

 if (exercise=="Bicycling" || exercise=="bicycling") calories=.049; 

 if (exercise=="Raking" || exercise=="raking") calories=.038; 

 if (exercise=="Shoveling" || exercise=="shoveling") calories=.045; 

 if (exercise=="Stacking" || exercise=="stacking") calories=0.046; 

 if (exercise=="Hiking" || exercise=="hiking") calories=.046; 

 if (exercise=="RollerBlade" || exercise=="rollerblade") calories=.053; 

 if (exercise=="Tennis" || exercise=="tennis") calories=.061; 

 if (exercise=="Dancing" || exercise=="dancing") calories=.038; 

 if (exercise=="BallroomDance" || exercise=="ballroomdance") calories=.034; 

 if (exercise=="Cards" || exercise=="cards") calories=.013; 
 
 if (exercise=="Piano" || exercise=="piano") calories=.021; 

 if (exercise=="IceSkate" || exercise=="iceskate") calories=0.046; 

 if (exercise=="DownhillSki" || exercise=="downhillski") calories=.049; 

 if (exercise=="CCSki" || exercise=="ccski") calories=.061; 

 if (exercise=="IndoorSki" || exercise=="indoorski") calories=.072; 

 if (exercise=="IceHockey" || exercise=="icehockey") calories=.052; 

 if (exercise=="Sledding" || exercise=="sledding") calories=.053; 

 if (exercise=="Racquetball" || exercise=="racquetball") calories=.049; 

 if (exercise=="Swimming" || exercise=="swimming") calories=.067; 

 if (exercise=="Kicking" || exercise=="kicking") calories=0.052; 

 if (exercise=="Backpacking" || exercise=="backpacking") calories=.045; 

 if (exercise=="Basketball" || exercise=="basketball") calories=.045; 

 if (exercise=="Aerobics" || exercise=="aerobics") calories=.045; 

 if (exercise=="WorkingOut" || exercise=="workingout") calories=.042; 

 if (exercise=="Mopping" || exercise=="mopping") calories=.034;
 
 if (exercise=="Badminton" || exercise=="badminton") calories=.071;
 
 if (exercise=="Ballet" || exercise=="ballet") calories=.038;
 
 if (exercise=="Baseball" || exercise=="baseball") calories=.039;
 
 if (exercise=="BrushingTeeth" || exercise=="brushingteeth") calories=.019;
 
 if (exercise=="BeachVolleyball" || exercise=="beachvolleyball") calories=.064;
 
 if (exercise=="Canoeing" || exercise=="canoeing") calories=.045;
 
 if (exercise=="Frisbee" || exercise=="frisbee") calories=.024;
 
 if (exercise=="Gardening" || exercise=="gardening") calories=.036;
 
 if (exercise=="Grocery" || exercise=="grocery") calories=.027;
 
 if (exercise=="Handball" || exercise=="handball") calories=.078;
 
 if (exercise=="Horseback" || exercise=="horseback") calories=.032;
 
 if (exercise=="Housecleaning" || exercise=="housecleaning") calories=.048;
 
 if (exercise=="Ironing" || exercise=="ironing") calories=.017;
 
 if (exercise=="Karate" || exercise=="karate") calories=.049;
 
 if (exercise=="Kissing" || exercise=="kissing") calories=.008;
 
 if (exercise=="Lacrosse" || exercise=="lacrosse") calories=.052;
 
 if (exercise=="Mowing" || exercise=="mowing") calories=.036;
 
 if (exercise=="Painting" || exercise=="painting") calories=.038;
 
 if (exercise=="PingPong" || exercise=="pingpong") calories=.030;
 
 if (exercise=="Furniture" || exercise=="furniture") calories=.05;
 
 if (exercise=="Ascending" || exercise=="ascending") calories=.083;
 
 if (exercise=="Repelling" || exercise=="repelling") calories=.061;
 
 if (exercise=="RopeJumping" || exercise=="ropejumping") calories=.076;
 
 if (exercise=="Rowing" || exercise=="rowing") calories=.08;
 
 if (exercise=="Rugby" || exercise=="rugby") calories=.076;
 
 if (exercise=="Soccer" || exercise=="soccer") calories=.052;
 
 if (exercise=="Spinning" || exercise=="spinning") calories=.053;
 
 if (exercise=="Stairclimbing" || exercise=="stairclimbing") calories=.068;
 
 if (exercise=="Surfing" || exercise=="surfing") calories=.023;
 
 if (exercise=="SwingDancing" || exercise=="swingdancing") calories=.03;
 
 if (exercise=="TaeKwonDo" || exercise=="taekwondo") calories=.038;
 
 if (exercise=="TaiChi" || exercise=="taichi") calories=.030;
 
 if (exercise=="Tennisdoubles" || exercise=="tennisdoubles") calories=.038;
 
 if (exercise=="Volleyball" || exercise=="volleyball") calories=.023;
 
 if (exercise=="WashingCar" || exercise=="washingcar") calories=.034;
 
 if (exercise=="WashingDishes" || exercise=="washingdishes") calories=.017;
 
 if (exercise=="WatchingTV" || exercise=="watchingtv") calories=.008;
 
 if (exercise=="WaterAerobics" || exercise=="wateraerobics") calories=.032;
 
 if (exercise=="WaterPolo" || exercise=="waterpolo") calories=.08;
 
 if (exercise=="WaterSkiing" || exercise=="waterskiing") calories=.048;
 
 if (exercise=="WeightLifting" || exercise=="weightlifting") calories=.023;
 
 if (exercise=="Rafting" || exercise=="rafting") calories=.04;
 
 if (exercise=="Yoga" || exercise=="yoga") calories=.04;
 
     return calories;

     }

function computeField(input) {

    var str = input.value;
	
    for (var i = 0; i < str.length; i++) {

        var ch = str.substring(i, i + 1)

        if ((ch < "0" || "9" < ch) && ch != '.') {

            alert("Non numeric data in numeric field! Re-Enter");

            input.focus();                

            return;

        }

    }

    if (input.value != null && input.value.length != 0)



        input.value = "" + eval(input.value);



        computeForm(input.form);



}



function computeForm(form) {



    i2=0; exercise="";



    getExercise(form.Exercise);

       

    if ((form.mins.value == null || form.mins.value.length == 0)) {



        alert("Invalid entry in Minutes field! Re-Enter.");

            

        form.mins.focus(0);



        return;



    }

	if ((form.weight.value == null || form.weight.value.length == 0)) {



        alert("Invalid entry in Weight field! Re-Enter.");

            

        form.weight.focus(0);



        return;



    }



    var str = form.mins.value;



    for (var i = 0; i < str.length; i++) {



        var ch = str.substring(i, i + 1)



        if ((ch < "0" || "9" < ch) && ch != '.') {



            alert("Non numeric data in Minutes field! Re-Enter");

        

            form.mins.focus(0);

                

            return;



        }



        }

            



    if (!checkNumber(form.mins, .1, 999, "mins")) {

                

        form.mins.focus();



        return;



    }

//this is where calculation occurs

    form.exercisepoints.value = ((computecalories2(exercise.value) * form.weight.value) * 

form.mins.value);



}



function getExercise(Exercise) {

    

    for (i2 == 0; i2 < Exercise.options.length; i2++) {

            

            if (Exercise.options[i2].selected==true) {

                        if (i2 == 0) {exercise = "Aerobics";

                        }

                        else if (i2 == 1) {exercise = "Backpacking";

                        }

                       
                        else if (i2 == 2) {exercise="Badminton";

						}

                        else if (i2 == 3) {exercise="Ballet";

						}

                        else if (i2 == 4) {exercise="BallroomDance" ;

						}

                        else if (i2 == 5) {exercise="Baseball" ;

						}

                        else if (i2 == 6) {exercise="Basketball";

						}

                        else if (i2 == 7) { exercise="Bicycling" ;

						}

                        else if (i2 == 8) { exercise="WalkStroller";

						}

                        else if (i2 == 9) { exercise="WalkDog";

						}

                        else if (i2 == 10) {exercise="BrushingTeeth";

						}

                        else if (i2 == 11) { exercise="Canoeing" ;

						}

                        else if (i2 == 12) {exercise="Dancing" ;

						}

                        else if (i2 == 14) { exercise="Frisbee" ;

						}

                        else if (i2 == 15) {exercise="Gardening" ;

						}

                        else if (i2 == 16) {exercise="Golf" ;

						}

                        else if (i2 == 17) {exercise="Grocery" ;

						}

                        else if (i2 == 18) {exercise="Handball" ;

						}

                        else if (i2 == 19) { exercise="Hiking" ;

						}

                        else if (i2 == 20) {exercise="Horseback";

						}

                        else if (i2 == 21) {exercise="Housecleaning" ;

						}

                        else if (i2 == 22) {exercise="IceHockey" ;

						}

                        else if (i2 == 23) {exercise="IceSkate";

						}

                        else if (i2 == 24) {exercise="IndoorSki";

						}

                        else if (i2 == 25) {exercise="Ironing" ;

						}

                        else if (i2 == 26) { exercise="Jogging";

						}

                        else if (i2 == 27) { exercise="Karate" ;

						}

                        else if (i2 == 28) { exercise="Kicking" ;

						}

                        else if (i2 == 30) {exercise="Kissing" ;

						}

                        else if (i2 == 31) {exercise="Lacrosse";

						}

                        else if (i2 == 32) { exercise="Mopping" ;

						}

                        else if (i2 == 33) { exercise="Mowing" ;
                                    
						}
								
						else if (i2 == 34) { exercise="Painting";

						}
						
                        else if (i2 == 35) { exercise="PingPong";

						}
						
                        else if (i2 == 36) { exercise="Cards";

						}
						
                        else if (i2 == 37) { exercise="Piano";

						}
						
                        else if (i2 == 38) { exercise="Racquetball";

						}
						
						else if (i2 == 39) { exercise="Raking";

						}
						
                        else if (i2 == 40) { exercise="Furniture";

						}
						
                        else if (i2 == 41) { exercise="Ascending";

						}
						
                        else if (i2 == 42) { exercise="Repelling";

						}
						
                        else if (i2 == 43) { exercise="RollerBlade";

						}
						
                        else if (i2 == 44) { exercise="RopeJumping";

						}
						
                        else if (i2 == 45) { exercise="Rowing";

						}
						
                        else if (i2 == 46) { exercise="Rugby";

						}
						
                        else if (i2 == 47) { exercise="Shoveling";

						}
						
                        else if (i2 == 48) { exercise="Sledding";

						}
						
                        else if (i2 == 49) { exercise="CCSki";

						}
						
                        else if (i2 == 50) { exercise="DownhillSki";

						}
						
                        else if (i2 == 51) { exercise="Soccer";

						}
						
                        else if (i2 == 52) { exercise="Spinning";

						}
						
                        else if (i2 == 53) { exercise="Stacking";

						}
						
                        else if (i2 == 54) { exercise="Stairclimbing";

						}
						
                        else if (i2 == 55) { exercise="Surfing";

						}
						
                        else if (i2 == 56) { exercise="Swimming";

						}
						
                        else if (i2 == 57) { exercise="SwingDancing";

						}
						
                        else if (i2 == 58) { exercise="TaeKwonDo";

						}
						
                        else if (i2 == 59) { exercise="TaiChi";

						}
						
                        else if (i2 == 60) { exercise="Stroll";

						}
						
                        else if (i2 == 61) { exercise="Tennis";

						}
						
                        else if (i2 == 62) { exercise="Tennisdoubles";

						}
						
                        else if (i2 == 63) { exercise="Football";

						}
						
                        else if (i2 == 64) { exercise="BeachVolleyball";

						}
						
                        else if (i2 == 65) { exercise="Volleyball";

						}
						
                        else if (i2 == 66) { exercise="WashingCar";

						}
						
                        else if (i2 == 67) { exercise="WashingDishes";

						}
						
                        else if (i2 == 68) { exercise="WatchingTV";

						}
						
                        else if (i2 == 69) { exercise="WaterAerobics";

						}
						
                        else if (i2 == 70) { exercise="WaterPolo";

						}
						
                        else if (i2 == 71) { exercise="WaterSkiing";

						}
						
                        else if (i2 == 72) { exercise="WeightLifting";

						}
						
                        else if (i2 == 73) { exercise="Rafting";

						}
						
                        else if (i2 == 74) { exercise="WorkingOut";

						}
						
                        else if (i2 == 75) { exercise="Yoga";

						}
						
						else if (i2 == 29) { exercise="Kickboxing";

						}
						
                        else if (i2 == 13) { exercise="DiscoDancing";

						}
						
	
									}

                        

                        

                        }



            }

             







function computesumForm(form) {

     

      document.forms[6].exercisepoints.value=0;



      document.forms[6].mins.value=0;



      document.forms[6].exercise.value="";



     for(var i=0; i<6; i++) {



        if (!(document.forms[i].mins.value == null || document.forms[i].mins.value.length == 0)) {



           if (!(document.forms[i].mins.value == null || document.forms[i].mins.value.length == 0)) {



                var temp=computeField(document.forms[i].exercisepoints);



                var temp=computeField(document.forms[i].mins);



                var temp=computeForm(document.forms[i]);



           if (!(document.forms[i].exercisepoints.value == 0))



           document.forms[6].exercisepoints.value =  eval(document.forms[6].exercisepoints.value)+(eval(document.forms[i].exercisepoints.value));    



           if (!(document.forms[i].mins.value == 0))



           document.forms[6].mins.value = eval(document.forms[6].mins.value)+(eval(document.forms[i].mins.value));    



           }



      }



   }



if (!(document.forms[6].mins.value == 0))



document.forms[6].exercise.value=(((eval(document.forms[6].exercisepoints.value)/(eval(document.forms[6].mins.value))+.000000001)));



  



}



function clearForm(form) {



    form.mins.value = "";



    form.exercisepoints.value = "";



    exercise = "";



    i2 = 0;



}



