var prevMen = 'btn_drinks';
function changeImMenu(id)
{
	
	if (prevMen != id){
		document.getElementById(prevMen).src = 'images/menu/cc/'+prevMen+'.jpg';
		prevMen = id;
	}
	
}
function swapImg(id)
{
	if (prevMen == id) {
		document.getElementById(id).src = 'images/menu/cc/'+id+'_over.jpg';
	} else {
		document.getElementById(id).src = 'images/menu/cc/'+id+'.jpg';
	}
}
function evalCals()
{
	if ((document.getElementById("txtage").value == 0)||(document.getElementById("txtage").value > 120) || (document.getElementById("txtheight").value == 0)||(document.getElementById("txtheight").value > 3) || (document.getElementById("txtweight").value == 0)||(document.getElementById("txtweight").value > 1000))
	{
		var error = ""
		if ((document.getElementById("txtage").value == 0)||(document.getElementById("txtage").value > 120))
		{
			error = error + "Please enter your age in years.\n";
		} 
		if ((document.getElementById("txtheight").value == 0)||(document.getElementById("txtheight").value > 3)) {
			error = error + "Please enter your height in metres.\n";
		} 
		if  ((document.getElementById("txtweight").value == 0)||(document.getElementById("txtweight").value > 1000)) {
			error = error + "Please enter your weight in kilograms.\n";
		} 
		alert(error);
	} else {
		var totalCals = 0;
		for (var x = 1; x <697; x++)
		{
			if(document.getElementById("txt" + x))
			{
				totalCals = totalCals + (document.getElementById("txt" + x).value * document.getElementById(x + "Calories").value);
			} 
		}	
		for (var y = 1; y <11; y++)
		{
			if(document.getElementById("othercalories" + y))
			{
				totalCals = totalCals + (document.getElementById("othercalories" + y).value - 0);
			} 
		}	
		
		var iPA;
	
		var iDaily = 0;
		var iDailyMax = 0;
	
		var sGender = "male";
		var sStatus;
		var sPStatus;
		var sActivity;
		if (document.getElementById("radgender").checked == true)
		{
			sGender = "female";
			if (document.getElementById("chkzero").checked == true)
			{
				sStatus = "0to6"
			}
			if (document.getElementById("chksix").checked == true)
			{
				sStatus = "6to12"
			}
			if (document.getElementById("chkfirst").checked == true)
			{
				sPStatus = "tri1"
			}
			if (document.getElementById("chksecond").checked == true)
			{
				sPStatus = "tri2"
			}
			if (document.getElementById("chkthird").checked == true)
			{
				sPStatus = "tri3"
			}
		}
		if (document.getElementById("radactivity1").checked == true)
		{
			sActivity = document.getElementById("radactivity1").value
		}
		if (document.getElementById("radactivity2").checked == true)
		{
			sActivity = document.getElementById("radactivity2").value
		}
		if (document.getElementById("radactivity3").checked == true)
		{
			sActivity = document.getElementById("radactivity3").value
		}
		if (document.getElementById("radactivity4").checked == true)
		{
			sActivity = document.getElementById("radactivity4").value
		}
		var iAge = document.getElementById("txtage").value
		var iHeight = document.getElementById("txtheight").value
		var iWeight = document.getElementById("txtweight").value
		if (iAge < 3)
		{
			if (iAge < 2)
			{
				iDaily = 0
			} else {
				iDaily = (89 * iWeight) - 100 + 20
			}
		} else if (iAge < 9) {
			if (sGender == "male")
			{
				if (sActivity = "sedentry")
				{
					iPA = 1.00
				} else if (sActivity == "low") {
					iPA = 1.13
				} else if (sActivity == "active") {
					iPA = 1.26
				} else {
					iPA = 1.42
				}
	
				iDaily = 88.5 - (61.9 * iAge) + iPA * (26.7 * iWeight + 903 * iHeight) + 20
			} else {
				if (sActivity == "sedentry")
				{
					iPA = 1.00
				} else if (sActivity == "low") {
					iPA = 1.16
				} else if (sActivity == "active") {
					iPA = 1.31
				} else {
					iPA = 1.56
				}
	
				iDaily = 135.3 - (30.8 * iAge) + iPA * (10.0 * iWeight + 934 * iHeight) + 20
			}
		} else if (iAge < 19) {
			if (sGender == "male") 
			{
				if (sActivity == "sedentry")
				{
					iPA = 1.00
				} else if (sActivity == "low") {
					iPA = 1.13
				} else if (sActivity == "active") {
					iPA = 1.26
				} else {
					iPA = 1.42
				}
				iDaily = 88.5 - (61.9 * iAge) + iPA * (26.7 * iWeight + 903 * iHeight) + 25
			} else {
				if (sActivity == "sedentry")
				{
					iPA = 1.00
				} else if (sActivity == "low") {
					iPA = 1.16
				} else if (sActivity == "active") {
					iPA = 1.31
				} else {
					iPA = 1.56
				}
	
				iDaily = 135.3 - (30.8 * iAge) + iPA * (10.0 * iWeight + 934 * iHeight) + 25
	
				if (sPStatus == "tri1")
				{
					iDaily = iDaily + 0 + 0
				} else if (sPStatus == "tri2") {
					iDaily = iDaily + 160 + 180
				} else if (sPStatus == "tri3") {
					iDaily = iDaily + 272 + 180
				}
				
				if (sStatus == "0to6")
				{
					iDaily = iDaily + 500 - 170
				} else if (sStatus == "6to12") {
					iDaily = iDaily + 400 - 0
				} else {
				
				}
			}
		} else {
			if (sGender == "male")
			{
				if (sActivity == "sedentry")
				{
					iPA = 1.00
				} else if (sActivity == "low") {
					iPA = 1.11
				} else if (sActivity == "active") {
					iPA = 1.25
				} else {
					iPA = 1.48
				}
	
				iDaily = 662 - (9.53 * iAge) + iPA * (15.91 * iWeight + 539.6 * iHeight)
			} else {
				if (sActivity == "sedentry")
				{
					iPA = 1.00
				} else if (sActivity == "low") {
					iPA = 1.12
				} else if (sActivity == "active") {
					iPA = 1.27
				} else {
					iPA = 1.45
				}
	
				iDaily = 354 - (6.91 * iAge) + iPA * (9.36 * iWeight + 726 * iHeight)
				
				if (sPStatus == "tri1") 
				{
					iDaily = iDaily + 0 + 0
				} else if (sPStatus == "tri2") {
					iDaily = iDaily + 160 + 180
				} else if (sPStatus == "tri3") {
					iDaily = iDaily + 272 + 180
				}
				
				if (sStatus == "0to6")
				{
					iDaily = iDaily + 500 - 170
				} else if (sStatus == "6to12") {
					iDaily = iDaily + 400 - 0
				} else {
				
				}
			}
		}
		if (iAge <2)
		{
			alert("This tool is not suitable for infants under 2 years old.")
		} else {
			iDaily = parseInt(iDaily);
			var idifference = totalCals - iDaily
			document.getElementById("calIntake").innerHTML = totalCals
			document.getElementById("recomIntake").innerHTML = iDaily
			document.getElementById("iDifference").innerHTML = idifference
			if (idifference < 0)
			{
				document.getElementById("calAmount").innerHTML = "You are eating less than your recommended daily calorie intake."
			} else if (idifference > 0){
				document.getElementById("calAmount").innerHTML = "You are eating more than your recommended daily calorie intake."
			} else {
				document.getElementById("calAmount").innerHTML = "You are eating exactly the recommended daily calorie intake."
			}
			if (idifference < 0)
			{
				document.getElementById("thisMeans").innerHTML = "This means you are <b>losing</b> weight."
			} else if (idifference > 0){
				document.getElementById("thisMeans").innerHTML = "This means you are <b>gaining</b> weight."
			} else {
				document.getElementById("thisMeans").innerHTML = "This means you are <b>maintaining</b> your weight."
			}
			
			document.getElementById("calcounter").style.display = "block"
			document.getElementById("eval").value = document.getElementById("calcounter").innerHTML
			
		}
	}

}
function showactiv()
{
	if (document.getElementById("radactivity1").checked == true)
	{
			showactivity(1)
	} else	if (document.getElementById("radactivity2").checked == true) {
			showactivity(2)
	} else if (document.getElementById("radactivity3").checked == true) {
			showactivity(3)
	} else if (document.getElementById("radactivity4").checked == true)	{
			showactivity(4)
	} else {
			showactivity(3)	
			document.getElementById("radactivity3").checked = true
	}
}
function showactivity(ilevel)
{
	if (ilevel == 1)
	{
		/*document.getElementById("activityexplanation").innerHTML = '<p>Sedentary individuals consume energy through basal energy expenditure, the thermal effect of food, and conducting the tasks necessary for independent living (e.g. sitting, standing, cooking, cleaning). They do not perform any other physical activity, such as recreational walking.</p>';*/
		document.getElementById("activityexplanation").innerHTML = '<p>I do not perform any physical activity or recreational walking. The only exercise I get is from daily living activities.</p>';
		SetActivityBorder(1);
		
	}
	else if (ilevel == 2)
	{
		/*document.getElementById("activityexplanation").innerHTML = '<p>Individuals who are categorised as low activity consume energy through the same mechanisms as sedentary individuals. In addition, an average weight individual (i.e. a person weighing 70kg) will undertake physical activity which is equivalent to walking 3.5 kilometres each day at a rate of 4.8-6.4 kilometres per hour, or roughly 45 minutes of brisk walking. Brisk walking can be considered walking which increases the heart rate to such an extent that the individual becomes slightly out of breath, but can still talk as they perform the activity. Individuals who are much lighter need to undertake greater amounts of activity, while those who are much heavier do not need to undertake as much physical activity. For example an individual who weighed only 44kg, would need to walked for 4.7 kilometres at the same speed, while one who weighed 120kg would need walk for only 2.4 kilometres. For examples of other activities which would be equivalent to walking this distance see our <a href="calc.asp?calc=energy_expenditure&sid=42">energy expenditure tool</a>.</p>';*/
		if(document.getElementById("txtweight").value < 60.5) {
			document.getElementById("activityexplanation").innerHTML = '<p>I get exercise from daily living activities plus 60 mins brisk walking or equivalent each day.</p>'; 
		} else if (document.getElementById("txtweight").value < 95) {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 45 mins brisk walking or equivalent each day.</p>'; 
		} else {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 30 mins brisk walking or equivalent each day.</p>'; 
		}
		SetActivityBorder(2);
	
	}
	else if (ilevel == 3)
	{
	/*	document.getElementById("activityexplanation").innerHTML = '<p>As with sedentary individuals, active individuals expend energy through eating and performing the tasks of everyday living. In addition, individuals weighing 70kg undertake physical activity which is equivalent to walking 11.8 kilometres per day, at a rate of 4.8-6.4 miles per hour, or roughly two hours of brisk walking. The physical activity requirement for active individuals weighing only 44kg increases to 16.0 kilometres per day, while for those weighing 120kg, the requirement decreases to 8.6 kilometres per day. For examples of other activities which would be equivalent to walking this distance see our <a href="calc.asp?calc=energy_expenditure&sid=42">energy expenditure tool</a>.</p>';*/
		if(document.getElementById("txtweight").value < 60.5) {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 2.5 hours brisk walking or equivalent each day.</p>'; 
		} else if (document.getElementById("txtweight").value < 95) {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 2 hours brisk walking or equivalent each day.</p>'; 
		} else {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 1.5 hours of brisk walking or equivalent each day.</p>'; 
		}
		SetActivityBorder(3);
	}
	else
	{
		/*document.getElementById("activityexplanation").innerHTML = '<p>Highly active individuals expend energy through the thermal effect of food and conducting the tasks of day to day living. In addition individuals weighing 70kg undertake physical activity which is equivalent to 26.9 kilometres per day of walking at a speed of 4.8-6.4 miles per hour, or roughly six hours of brisk walking. Individuals who weigh only 44kg need to walk 36.2 kilometres per day to exert the same effect, while those weighing 120kg need walk only 19.8 kilometres per day to achieve a PAL equivalent to being highly active. For examples of other activities which would be equivalent to walking this distance see our <a href="calc.asp?calc=energy_expenditure&sid=42">energy expenditure tool</a>.</p>';*/
		if(document.getElementById("txtweight").value < 60.5) {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 6 hours of brisk walking or equivalent each day.</p>'; 
		} else if (document.getElementById("txtweight").value < 95) {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 4.5 hours brisk walking or equivalent each day.</p>'; 
		} else {
			document.getElementById("activityexplanation").innerHTML =  '<p>I get exercise from daily living activities plus 3.5 hours of brisk walking or equivalent each day.</p>'; 
		}
		SetActivityBorder(4);
	}
}

function SetActivityBorder(ilevel)
{
	if (ilevel == 1)
	{
		SetTDNone(); 
		document.getElementById("tdsed").style.borderLeft = "1px solid #666666";
		document.getElementById("tdsed").style.borderTop = "1px solid #666666";
		document.getElementById("tdsed").style.borderRight = "1px solid #666666";
		document.getElementById("tdsed").style.backgroundColor = "#c2e0fc";
		document.getElementById("activityexplanation").style.backgroundColor = "#c2e0fc";
		document.getElementById("activityexplanation").style.border = "1px solid #666666";
	}
	else if (ilevel == 2)
	{
		SetTDNone();
		document.getElementById("tdlow").style.borderLeft = "1px solid #666666";
		document.getElementById("tdlow").style.borderTop = "1px solid #666666";
		document.getElementById("tdlow").style.borderRight = "1px solid #666666";
		document.getElementById("tdlow").style.backgroundColor = "#9ccdf9";
		document.getElementById("activityexplanation").style.backgroundColor = "#9ccdf9";
		document.getElementById("activityexplanation").style.border = "1px solid #666666";
	}
	else if (ilevel == 3)
	{
		SetTDNone();
		document.getElementById("tdactive").style.borderLeft = "1px solid #666666";
		document.getElementById("tdactive").style.borderTop = "1px solid #666666";
		document.getElementById("tdactive").style.borderRight = "1px solid #666666";
		document.getElementById("tdactive").style.backgroundColor = "#7ebffa";
		document.getElementById("activityexplanation").style.backgroundColor = "#7ebffa";
		document.getElementById("activityexplanation").style.border = "1px solid #666666";
	}
	else
	{
		SetTDNone();
		document.getElementById("tdhigh").style.borderLeft = "1px solid #666666";
		document.getElementById("tdhigh").style.borderTop = "1px solid #666666";
		document.getElementById("tdhigh").style.borderRight = "1px solid #666666";
		document.getElementById("tdhigh").style.backgroundColor = "#6fb8fb";
		document.getElementById("activityexplanation").style.backgroundColor = "#6fb8fb";
		document.getElementById("activityexplanation").style.border = "1px solid #666666";
	}
	
}

function SetTDNone()
{
	document.getElementById("tdsed").style.borderStyle = "none";
	document.getElementById("tdsed").style.backgroundColor = "#FFFFFF";

	document.getElementById("tdlow").style.borderStyle = "none";
	document.getElementById("tdlow").style.backgroundColor = "#FFFFFF";

	document.getElementById("tdactive").style.borderStyle = "none";
	document.getElementById("tdactive").style.backgroundColor = "#FFFFFF";

	document.getElementById("tdhigh").style.borderStyle = "none";
	document.getElementById("tdhigh").style.backgroundColor = "#FFFFFF";
}

function boxcheck(thecheckbox)
{
//	alert(thecheckbox);
//	alert(document.getElementById('radgender').checked);
	
	var frmcc;
	frmcc = document.getElementById("frmcaloriecounter");

	if (thecheckbox == 'chkzero')
	{
		document.getElementById('chksix').checked = "";
		
		document.getElementById('radgender').checked = "checked";
		//document.getElementById('radgender').checked = "checked";				
	}
	
	if (thecheckbox == 'chksix')
	{
		document.getElementById('chkzero').checked = "";

		document.getElementById('radgender').checked = "checked";
		//document.getElementById('radgender').checked = "checked";
	}
	
	if (thecheckbox == 'chkfirst')
	{
		document.getElementById('chksecond').checked = "";
		document.getElementById('chkthird').checked = "";
		
		document.getElementById('radgender').checked = "checked";	
		//document.getElementById('radgender').checked = "checked";
	}
	
	if (thecheckbox == 'chksecond')
	{
		document.getElementById('chkfirst').checked = "";
		document.getElementById('chkthird').checked = "";

		document.getElementById('radgender').checked = "checked";
		//document.getElementById('radgender').checked = "checked";
	}
	
	if (thecheckbox == 'chkthird')
	{
		document.getElementById('chkfirst').checked = "";
		document.getElementById('chksecond').checked = "";

		document.getElementById('radgender').checked = "checked";
		//document.getElementById('radgender').checked = "checked";
	}
	
	if (thecheckbox == 'radgender2')
	{
		document.getElementById('chkfirst').checked = "";
		document.getElementById('chksecond').checked = "";
		document.getElementById('chkthird').checked = "";
		document.getElementById('chkzero').checked = "";
		document.getElementById('chksix').checked = "";
		
	}

}
	

