{if $domain eq "ehealthcompete.com"}{assign var="pgLayout" value="file:layouts/withLeftNav.tpl"}{/if}
{* *** Container Table *** *}<table cellpadding="0" cellspacing="0" width="100%"><tr><td>
{include_php file="shared_handle:getProfile"}

Note: You must have Javascript enabled to use these calculators.
<br/>

<div class="chunk300" style="width:315px;">
<h2 class="withBG">Target Weight</h2>
<form name="TargetWeightForm" method="post" style="margin:0px;">
	Calculate your target weight by filling out the information below and clicking "Calculate"<br />
	<div class="underline">&nbsp;</div>
	<label for="pctBdyFat">Percent Body Fat</label> <input id="pctBdyFat" type="text" class="textInputNotFixed" size="3" name="percentBodyFat" value=""><br />
	<label for="wght">Current Weight</label> <input id="wght" type="text" class="textInputNotFixed" size="3" name="weight" value="{$userProfile.initialWeight}"><br />
	<label for="dsrdBdyFat">Desired Percent Body Fat</label> <input id="dsrdBdyFat" type="text" class="textInputNotFixed" size="3" name="desiredBodyFat" value=""><br />
	<div class="overline">&nbsp;</div>
	<a href="javascript:calculateTargetWeight();" class="button">Calculate</a>
	<label for="trgtWghtTxt"><textarea name="TargetWeightText" disabled="disabled" style="margin-top:5px;width:305px;height:100px;"></textarea>
	<br/>
	<dl style="text-align:left;">
	<dt>Percentage of body fat falls into these ranges:</dt>
		<dd>Decreased health risk for men is less than 25%</dd>
		<dd>Decreased health risk for women is less than 32%</dd>
		<dd>Optimal fitness performance for men is less than 15%</dd>
		<dd>Optimal performance for women is less than 23%</dd>
	</dl>
</form>
</div>

<div class="chunk300">
<h2 class="withBG">Body Mass Index</h2>
<form name="BMIForm" method="post" style="margin:4px;">
	Calculate your BMI by filling out the information below and clicking "Calculate"<br />
	<div class="underline">&nbsp;</div>
	<label for="weightlbs">Weight in lbs</label> <input id="weightlbs" type="text" class="textInputNotFixed" size="3" name="weightlbs" value="{$userProfile.initialWeight}"><br />
	<label for="height">Height in inches</label> <input type="text" class="textInputNotFixed" size="3" name="height" value="{$userProfile.height}"><br />
	<div class="overline">&nbsp;</div>
	<label for="BMIText">Body Mass Index</label> <input type="text" size="4" name="BMIText" disabled="disabled">
	<a href="javascript:calculateBMI();" class="button">Calculate</a><br />

	<dl style="text-align:left;">
	<dt>BMI is the governments standard for measuring obesity, and falls into these ranges:</dt>
		<dd>Normal = BMI less than 25</dd>
		<dd>Overweight = BMI between 25 - 30</dd>
		<dd>Obese = BMI over 30</dd>
	</dl>


</form>
</div>

<div class="chunk300">
<h2 class="withBG">Ideal Heart Rate Range</h2>
<form name="HeartRangeForm" method="post" style="margin:4px;">
	Calculate your ideal heart rate range by entering your age and clicking "Calculate"<br /><br />
	<div class="underline">&nbsp;</div>
	<label for="age">Age</label> <input type="text" class="textInputNotFixed" size="3" name="age" value="{$userProfile.age}"><br />
	<div class="overline">&nbsp;</div>
	<br />
	<label for="heartRange">Healthy Heart Range</label> <input type="text" name="HeartRangeText" size="6" disabled="disabled">
	<a href="javascript:calculateHeartRange();" class="button">Calculate</a>
</form>
</div>

<div class="chunk300" style="width:315px;">
<h2 class="withBG">Hip-to-Waist Ratio</h2>
<form name="HipWaistForm" method="post" style="margin:0px;">
	Calculate your Hip-to-Waist ratio by filling out the information below and clicking "Calculate".<br />
	<small>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.</small><br />
	<div class="underline">&nbsp;</div>
	<label for="waist">Waist circumference in inches</label>
	<input id="waist" type="text" class="textInputNotFixed" size="3" name="waist" value=""><br />
	<label for="hip">Hip circumference in inches</label>
	<input id="hip" type="text" class="textInputNotFixed" size="3" name="hip" value=""><br />
	<div class="overline">&nbsp;</div>
	<label for="hipWaistTxt">Hip-to-Waist Ratio</label> 
	<input id="hipWaistTxt" type="text" name="HipWaistText" size="6" disabled="disabled">
	<a href="javascript:calculateHipWaistRatio();" class="button">Calculate</a>

	<br/>
	<dl style="text-align:left;">
	<dt>For men:</dt>
		<dd>The ideal ratio is less than .85.</dd>
		<dd>The desireable ratio is .85 - .94.</dd>
		<dd>You are at risk at .95+</dd>
	<dt>For women:</dt>
		<dd>The ideal ratio is less than .75.</dd>
		<dd>The desireable ratio is .75 - .79.</dd>
		<dd>You are at risk at .8+</dd>
	</dl>
</form>
</div>

<div class="chunk300">
<h2 class="withBG">Calculate Calories</h2>
<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 "Calculate".<br />
	<div class="underline">&nbsp;</div>
	<label for="gender1">Male</label> <input id="gender1" type="radio" name="gender" value="male"> 
	<label for="gender2">Female</label> <input id="gender2" type="radio" name="gender" value="female"> &nbsp; &nbsp; &nbsp; 
	<label for="weightlbs">Weight in lbs</label>
	<input id="weightlbs" type="text" class="textInputNotFixed" size="3" name="weightlbs" value="{$userProfile.initialWeight}"><br />
	<label for="height">Height in inches</label>
	<input id="height" type="text" class="textInputNotFixed" size="3" name="height" value="{$userProfile.height}"><br />
	<label for="age">Age</label>
	<input id="age" type="text" class="textInputNotFixed" size="3" name="age" value="{$userProfile.age}"><br />
	<label for="poundsToLose">Pounds to lose</label>
	<input id="poundsToLose" type="text" class="textInputNotFixed" size="3" name="poundsToLose" value=""><br />
	<label for="days">Number of days</label>
	<input id="days" type="text" class="textInputNotFixed" size="3" name="days" value=""><br />
	<div class="overline pixel" style="margin-bottom:5px;">&nbsp;</div>
	<a href="javascript:calculateCalories();" class="button">Calculate</a>
	<textarea name="CalorieText" style="width:290px;height:70px;margin-top:5px;"></textarea>
</form>
</div>

{* *** END CONTAINER TABLE *** *}
</td></tr></table>

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

function calculateBMI()
{
	var weight = document.BMIForm.weightlbs.value;
	var height = document.BMIForm.height.value;

	if (height == 0)
	{
		alert("You must enter a valid height!");
		return;
	}

	if (weight == 0)
	{
		alert("You must enter a valid weight!");
	}

	var meters = height / 39.37;
	var kilograms = weight / 2.2;

	var metersSquared = Math.pow(meters, 2);
	
	var bmi = format_number(kilograms / metersSquared, 2);

	document.BMIForm.BMIText.value = bmi;
}

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

	if (age == 0)
	{
		alert("You must enter a valid age!");
		return;
	}

	var maxHeartRange = 220 - age;

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

	document.HeartRangeForm.HeartRangeText.value = Math.round(targetLow) + " - " + Math.round(targetHigh);
}

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

	if (percentBodyFat == 0)
	{
		alert("You must enter a valid Percent Body Fat");
		return;
	}

	if (weight == 0)
	{
		alert("You must enter a valid weight!");
		return;
	}

	if (desiredBodyFat == 0)
	{
		alert("You must enter a valid Desired Body Fat!");
		return;
	}

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

	var outputString = "Current Fat Weight is " + Math.round(currentFatWeight) + " lbs." +
						"\nCurrent Lean Body Weight is " + Math.round(currentLeanBodyWeight) + " lbs." +
						"\nTarget Weight should be " + Math.round(targetWeight) + " lbs." +
						"\n\nYou need to lose " + Math.round(poundsToLose) + " lbs to reach the target weight.";

	document.TargetWeightForm.TargetWeightText.value = outputString;
}

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

	if (waist == 0)
	{
		alert("You must enter a valid waist size!");
		return;
	}

	if (hip == 0)
	{
		alert("You must enter a valid hip size!");
		return;
	}

	var ratio = format_number(waist / hip, 2);

	document.HipWaistForm.HipWaistText.value = 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;

	if (document.CalorieForm.gender[0].checked == true)
	{
		value = 5;
	}
	else if (document.CalorieForm.gender[1].checked == true)
	{
		value = -161;
	}
	else
	{
		alert("You must select a gender!");
		return;
	}

	if (weight == 0)
	{
		alert("You must enter a valid weight!");
		return;
	}

	if (height == 0)
	{
		alert("You must enter a valid height!");
		return;
	}

	if (age == 0)
	{
		alert("You must enter a valid age!");
		return;
	}

	if (poundsToLose == 0)
	{
		alert("You must enter a valid entry for how many pounds to lose!");
		return;
	}

	if (days == 0)
	{
		alert("You must enter a valid entry for how many days to lose the pounds in!");
		return;
	}

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

	var restingEnergyE = 0;

	restingEnergyE = (value + (10 * kilograms) + (6.25 * centimeters) - (5 * age));
	var caloriesToLose = poundsToLose * 3500;
	var caloriesPerDay = caloriesToLose / days;

	var outputString = "The amount of calories you need at rest per activity level:\n\nSedentary: " + Math.round((restingEnergyE * SEDENTARY)) + 
					   "\nLight: " + Math.round((restingEnergyE * LIGHT)) +
					   "\nModerate: " + Math.round((restingEnergyE * MODERATE)) +
					   "\nActive: " + Math.round((restingEnergyE * ACTIVE)) + 
					   "\n\nYou need to trim " + Math.round(caloriesPerDay) + " calories per day to lose " + poundsToLose + " lbs in " + days + " days.";

	document.CalorieForm.CalorieText.value = outputString;
}

function format_number(p,d) 
{
  var r;
  if(p<0){p=-p;r=format_number2(p,d);r="-"+r;}
  else   {r=format_number2(p,d);}
  return r;
}
function format_number2(pnumber,decimals) 
{
  var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }
    decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
    Math.round(decDecimalPart); 
    decDecimalPart = parseInt(decDecimalPart)/10; 
    decDecimalPart = Math.round(decDecimalPart); 

    //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
    //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 

    if(decDecimalPart==Math.pow(10, parseInt(decimals)))
    { 
      intWholePart+=1; 
      decDecimalPart="0"; 
    } 
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 

    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  return strResult;
}

</script>  

{/literal}
</script>
