{include_php file="shared_handle:getProfile"}

<form name="BMIForm" method="post" style="margin:4px;">
	Calculate your Body Mass Index (BMI) by filling out the information below and clicking "Submit"<br /><br />
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td align="right"><b>Weight in lbs</b></td>
		  	<td><input type="text" class="textInput" name="weightlbs" value="{$userProfile.initialWeight}"></td>
		</tr>
		<tr>
			<td align="right"><b>Height in inches</b></td>
			<td><input type="text" class="textInput" name="height" value="{$userProfile.height}"></td>
		</tr>
		<tr>
		  	<td align="right"></td>
		  	<td><a href="javascript:calculateBMI();" class="button">Submit</a></td>
		</tr>
	</table>
</form>
<hr>

<form name="HeartRangeForm" method="post" style="margin:4px;">
	Calculate your ideal heart rate range by filling out the information below and clicking "Submit"<br /><br />
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td align="right"><b>Age</b></td>
		  	<td><input type="text" class="textInput" name="age" value="{$userProfile.age}"></td>
		</tr>
		<tr>
		  	<td align="right"></td>
		  	<td><a href="javascript:calculateHeartRange();" class="button">Submit</a></td>
		</tr>
	</table>
</form>
<hr>

<form name="TargetWeightForm" method="post" style="margin:4px;">
	Calculate your target weight by filling out the information below and clicking "Submit"<br /><br />
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td align="right"><b>Percent Body Fat</b></td>
		  	<td><input type="text" class="textInput" name="percentBodyFat" value=""></td>
		</tr>
		<tr>
			<td align="right"><b>Current Weight</b></td>
			<td><input type="text" class="textInput" name="weight" value="{$userProfile.initialWeight}"></td>
		</tr>
		<tr>
			<td align="right"><b>Desired Percent Body Fat</b></td>
			<td><input type="text" class="textInput" name="desiredBodyFat" value=""></td>
		</tr>
		<tr>
			<td align="right"></td>
			<td><a href="javascript:calculateTargetWeight();" class="button">Submit</a></td>
		</tr>
	</table>
	<br/>
	Percentage of body fat falls into the following ranges:<br/>
	Acceptable percentage for decreased health risk for men is less than 25%<br/>
	Acceptable percentage for decreased health risk for women is less than 32%<br/>
	Acceptable percentage for optimal fitness performance for men is less than 15%<br/>
	Acceptable percentage for optimal fitness performance for women is less than 23%<br/>
	<br/>
</form>
<hr>

<form name="HipWaistForm" method="post" style="margin:4px;">
	Calculate your Hip-to-Waist ratio by filling out the information below and clicking "Submit".<br />
	If you bend to the side, the place where your stomach creases is where you should measure your waist. Measure your hips around the largest part of your buttocks.<br />
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td align="right"><b>Your waist circumference in inches</b></td>
		  	<td><input type="text" class="textInput" name="waist" value=""></td>
		</tr>
		<tr>
			<td align="right"><b>Your hip circumference in inches</b></td>
			<td><input type="text" class="textInput" name="hip" value=""></td>
		</tr>
		<tr>
			<td align="right"></td>
			<td><a href="javascript:calculateHipWaistRatio();" class="button">Submit</a></td>
		</tr>
	</table>
	<br/>
	For men:<br/>
	The ideal ratio is less than .85.<br/>
	The desireable ratio is .85 - .94.<br/>
	You are at risk at .95+<br/>
	<br/>
	For women:<br/>
	The ideal ratio is less than .75.<br/>
	The desireable ratio is .75 - .79.<br/>
	You are at risk at .8+<br/>
	<br/>
	<br/>
</form>
<hr>

<form name="CalorieForm" method="post" style="margin:4px;">
	Calculate the number of calories you need at rest and how many calories you have to cut out to lose a certain amount of weight by filling out the information below and clicking "Submit".<br />
	<table cellspacing="2" cellpadding="2" border="0">
		<tr>
			<td align="right"><b>Weight in lbs</b></td>
		  	<td><input type="text" class="textInput" name="weightlbs" value="{$userProfile.initialWeight}"></td>
		</tr>
		<tr>
			<td align="right"><b>Height in inches</b></td>
			<td><input type="text" class="textInput" name="height" value="{$userProfile.height}"></td>
		</tr>
		<tr>
			<td align="right"><b>Age</b></td>
		  	<td><input type="text" class="textInput" name="age" value="{$userProfile.age}"></td>
		</tr>
		<tr>
			<td align="right"><b>Pounds to lose</b></td>
		  	<td><input type="text" class="textInput" name="poundsToLose" value=""></td>
		</tr>
		<tr>
			<td align="right"><b>Time frame to lose them in days</b></td>
		  	<td><input type="text" class="textInput" name="days" value=""></td>
		</tr>
		<tr>
			<td align="right"></td>
			<td><a href="javascript:calculateCalories();" class="button">Submit</a></td>
		</tr>
	</table>
	<br/>
</form>
<hr>
<hr>

<script language="JavaScript" type="text/javascript">
{literal}

function calculateBMI()
{
	var weight = document.BMIForm.weightlbs.value;
	var height = document.BMIForm.height.value;
	
	var meters = height / 39.37;
	var kilograms = weight / 2.2;

	//alert("Meters: " + meters);
	//alert("Kilograms: " + kilograms);
	
	var metersSquared = Math.pow(meters, 2);
	
	//alert("Meters squared: " + metersSquared);

	var bmi = kilograms / metersSquared;

	alert("BMI: " + bmi);
}

function calculateHeartRange()
{
	var maxHeartRange = 220 - document.HeartRangeForm.age.value;

	var targetLow = .6 * maxHeartRange;
	var targetHigh = .9 * maxHeartRange;

	alert("Range: " + targetLow + " - " + targetHigh);
}

function calculateTargetWeight()
{
	var percentBodyFat = document.TargetWeightForm.percentBodyFat.value;
	var weight = document.TargetWeightForm.weight.value;
	var desiredBodyFat = document.TargetWeightForm.desiredBodyFat.value;

	//alert("PercentBodyFat: " + percentBodyFat);
	//alert("Weight: " + weight);
	//alert("DesiredBodyFat: " + desiredBodyFat);
	//alert("DesiredBodyFat100: " + (desiredBodyFat / 100));

	var currentFatWeight = (percentBodyFat / 100) * weight;
	var currentLeanBodyWeight = weight - currentFatWeight;
	var targetWeight = currentLeanBodyWeight / (1 - (desiredBodyFat / 100));
	var poundsToLose = weight - targetWeight;

	alert("CurrentFatWeight: " + currentFatWeight);
	alert("CurrentLeanBodyWeight: " + currentLeanBodyWeight);
	alert("TargetWeight: " + targetWeight);
	alert("PoundsToLose: " + poundsToLose);
}

function calculateHipWaistRatio()
{
	var waist = document.HipWaistForm.waist.value;
	var hip = document.HipWaistForm.hip.value;

	var ratio = waist / hip;

	alert("Ratio: " + ratio);
}

function calculateCalories()
{
	var SEDENTARY = 1.1;
	var LIGHT = 1.2;
	var MODERATE = 1.3;
	var ACTIVE = 1.4;

	var weight = document.CalorieForm.weightlbs.value;
	var height = document.CalorieForm.height.value;
	var age = document.CalorieForm.age.value;
	var poundsToLose = document.CalorieForm.poundsToLose.value;
	var days = document.CalorieForm.days.value;

	var centimeters = (height / 39.37) * 100;
	var kilograms = weight / 2.2;

	var gender = "M";
	var restingEnergyE = 0;

	if (gender == "M")
	{
		value = 5;
	}
	else
	{
		value = -161;
	}

	restingEnergyE = (value + (10 * kilograms) + (6.25 * centimeters) - (5 * age));
	var outputString = "The amount of calories you need at rest per activity level:\nSedentary: " + (restingEnergyE * SEDENTARY) + 
					   "\nLight: " + (restingEnergyE * LIGHT) +
					   "\nModerate: " + (restingEnergyE * MODERATE) +
					   "\nActive: " + (restingEnergyE * ACTIVE);

	alert(outputString);

	var caloriesToLose = poundsToLose * 3500;
	var caloriesPerDay = caloriesToLose / days;

	alert("You need to trim " + caloriesPerDay + " calories per day to lose " + poundsToLose + " lbs in " + days + " days.");
}

{/literal}
</script>