	var agt=navigator.userAgent.toLowerCase();
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);

	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	var is_nav2 = (is_nav && (is_major == 2));
	var is_nav3 = (is_nav && (is_major == 3));
	var is_nav4 = (is_nav && (is_major == 4));
	var is_nav4up = (is_nav && (is_major >= 4));
	var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
	var is_nav6 = (is_nav && (is_major == 5));
	var is_nav6up = (is_nav && (is_major >= 5));
	var is_gecko = (agt.indexOf('gecko') != -1);

	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_ie3 = (is_ie && (is_major < 4));
	var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
	var is_ie4up = (is_ie  && (is_major >= 4));
	var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
	var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
	var is_ie5up = (is_ie  && !is_ie3 && !is_ie4);
	var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);

	var is_aol = (agt.indexOf("aol") != -1);
	var is_aol3 = (is_aol && is_ie3);
	var is_aol4 = (is_aol && is_ie4);

	var is_opera = (agt.indexOf("opera") != -1);
	var is_opera4 = (agt.indexOf("opera 4") != -1);
	var is_opera5 = (agt.indexOf("opera 5") != -1);
	var is_opera5up = (is_opera && (is_major >=4));

	var is_webtv = (agt.indexOf("webtv") != -1); 

	var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
	var is_AOLTV = is_TVNavigator;

	var is_hotjava = (agt.indexOf("hotjava") != -1);
	var is_hotjava3 = (is_hotjava && (is_major == 3));
	var is_hotjava3up = (is_hotjava && (is_major >= 3));

	var is_js;
	if (is_nav2 || is_ie3) is_js = 1.0;
	else if (is_nav3 || is_opera) is_js = 1.1;
	else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
	else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
	else if (is_hotjava3up) is_js = 1.4;
	else if (is_nav6 || is_gecko) is_js = 1.5;
	else if (is_ie && (is_major > 5)) is_js = 1.3

	var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
	var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

	var is_win16 = ((agt.indexOf("win16")!=-1) || (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("windows 16-bit")!=-1) );  

	var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) || (agt.indexOf("windows 16-bit")!=-1));

	var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
	var is_win32 = (is_win95 || is_winnt || is_win98 || ((is_major >= 4) && (navigator.platform == "Win32")) || (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
	var is_os2 = ((agt.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (agt.indexOf("ibm-webexplorer")!=-1));

	var is_mac = (agt.indexOf("mac")!=-1);
	var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || (agt.indexOf("68000")!=-1)));
	var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1)));

	var is_sun = (agt.indexOf("sunos")!=-1);
	var is_sun4 = (agt.indexOf("sunos 4")!=-1);
	var is_sun5 = (agt.indexOf("sunos 5")!=-1);
	var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
	var is_irix = (agt.indexOf("irix") !=-1);    // SGI
	var is_irix5 = (agt.indexOf("irix 5") !=-1);
	var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
	var is_hpux = (agt.indexOf("hp-ux")!=-1);
	var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
	var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
	var is_aix = (agt.indexOf("aix") !=-1);      // IBM
	var is_aix1 = (agt.indexOf("aix 1") !=-1);
	var is_aix2 = (agt.indexOf("aix 2") !=-1);
	var is_aix3 = (agt.indexOf("aix 3") !=-1);
	var is_aix4 = (agt.indexOf("aix 4") !=-1);
	var is_linux = (agt.indexOf("inux")!=-1);
	var is_sco = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
	var is_unixware = (agt.indexOf("unix_system_v")!=-1);
	var is_mpras = (agt.indexOf("ncr")!=-1);
	var is_reliant = (agt.indexOf("reliantunix")!=-1);
	var is_dec = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
	var is_sinix = (agt.indexOf("sinix")!=-1);
	var is_freebsd = (agt.indexOf("freebsd")!=-1);
	var is_bsd = (agt.indexOf("bsd")!=-1);
	var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux || is_sco ||is_unixware || is_mpras || is_reliant || is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

	var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

function processForm1(){
	var weight, height, age, gender, form1List;

	if (document.form1.weight.value == ""){
		alert("You need to enter your weight.");
		return;
	}
	if (document.form1.height.value == ""){
		alert("You need to enter your height.");
		return;
	}
	if (document.form1.age.value == ""){
		alert("You need to enter your age.");
		return;
	}
	if (!document.form1.gender[0].checked && !document.form1.gender[1].checked){
		alert("You need to enter your gender.");
		return;
	}

	weight = document.form1.weight.value;
	height = document.form1.height.value;
	age = document.form1.age.value;
	if (document.form1.gender[0].checked){
		gender = document.form1.gender[0].value;
	}else if (document.form1.gender[1].checked){
		gender = document.form1.gender[1].value;
	}

	if (document.form1.weight_units[1].checked){
		weight = weight/2.2;
	}

	if (document.form1.weight_units[1].checked){
		height = height*2.54;
	}

	form1List = [weight, height, age, gender];
	return form1List;
}


function dropDecimalPlaces(theNumber){
	var theString, decimalIndex
	theString = theNumber.toString();
	decimalIndex = theString.indexOf('.');
	if (decimalIndex != -1){
		theString = theString.slice(0, decimalIndex+2);
		return theString;
	}else{
		return theString;
	}
}


var dailyResultCalculated = 0;

function clearResult(){
	if (!dailyResultCalculated)
		return;
	if (is_nav3 || is_nav4){
		dailyDisplay("<a class=\"nsresultlink\" href=\"javascript:dailyCalculate();\">Calculate Calories</a>");
	}else{   // For other browsers
		dailyDisplay("<span class=\"biggreen\">&nbsp;</span><input type=\"button\" name=\"calculate\" class=\"formbutton1\" onMouseUp=\"javascript:dailyCalculate();\" value=\"Calculate Calories\"><span class=\"biggreen\">&nbsp;</span>");
	}
	dailyResultCalculated = 0;
}

function dailyDisplay(text){
	var lyr;
	if (is_nav3 || is_nav4){
		lyr = document.layers["nsbs"].document.layers["nsresult"].document;
		lyr.open();
		lyr.write(text);
		lyr.close();
	}else if (is_nav6up || is_ie5up){
		document.getElementById("result").innerHTML = text;
	}else{
		document.all["result"].innerHTML = text;
	}
	dailyResultCalculated = 1;	
}

function dailyCalculate(){
	var form1List, weight, height, age, gender
	var restingTime, inactiveTime, vlaTime, lightTime, moderateTime, heavyTime
	var bmrPerDay, bmrPerHour, resultString, totalBurned, totalTime, resting, inactive, vla, light, moderate, heavy

	form1List = processForm1();
	if (!form1List){
		return;
	}else{
		weight = form1List[0];
		height = form1List[1];
		age = form1List[2];
		gender = form1List[3];
	}	
	
	if (gender == 'm'){
		bmrPerDay = 66 + (13.7 * weight) + (5 * height) - (6.8 * age);
	}else if (gender == 'f'){
		bmrPerDay = 655 + (9.6 * weight) + (1.7 * height) - (4.7 * age);
	}

	bmrPerHour = bmrPerDay / 24;
	totalBurned = totalTime = 0;
	restingTime = document.form2.resting.value;
	inactiveTime = document.form2.inactive.value;
	vlaTime = document.form2.vla.value;
	lightTime = document.form2.light.value;
	moderateTime = document.form2.moderate.value;
	heavyTime = document.form2.heavy.value;

	if (restingTime == ""){
		resting = 0;
	}else{
		resting = 0;
		totalTime = totalTime + parseFloat(restingTime);
	}
	if (inactiveTime == ""){
		inactive = 0;
	}else if(inactiveTime != "" && gender == 'f'){
		inactive = 0.24 * inactiveTime;
		totalTime = totalTime + parseFloat(inactiveTime);
	}else if(inactiveTime != "" && gender == 'm'){
		inactive = 0.45 * inactiveTime;
		totalTime = totalTime + parseFloat(inactiveTime);
	}
	if (vlaTime == ""){
		vla = 0;
	}else if(vlaTime != "" && gender == 'f'){
		vla = 0.75 * vlaTime;
		totalTime = totalTime + parseFloat(vlaTime);
	}else if(vlaTime != "" && gender == 'm'){
		vla = 1.08 * vlaTime;
		totalTime = totalTime + parseFloat(vlaTime);
	}
	if (lightTime == ""){
		light = 0;
	}else if(lightTime != "" && gender == 'f'){
		light = 1.59 * lightTime;
		totalTime = totalTime + parseFloat(lightTime);
	}else if(lightTime != "" && gender == 'm'){
		light = 1.89 * lightTime;
		totalTime = totalTime + parseFloat(lightTime);
	}
	if (moderateTime == ""){
		moderate = 0;
	}else if(moderateTime != "" && gender == 'f'){
		moderate = 2.76 * moderateTime;
		totalTime = totalTime + parseFloat(moderateTime);
	}else if(moderateTime != "" && gender == 'm'){
		moderate = 3.06 * moderateTime;
		totalTime = totalTime + parseFloat(moderateTime);
	}
	if (heavyTime == ""){
		heavy = 0;
	}else if(heavyTime != "" && gender == 'f'){
		heavy = 3.30 * heavyTime;
		totalTime = totalTime + parseFloat(heavyTime);
	}else if(heavyTime != "" && gender == 'm'){
		heavy = 3.72 * heavyTime;
		totalTime = totalTime + parseFloat(heavyTime);
	}
	totalBurned = (bmrPerHour * totalTime) + (weight * (resting + inactive + vla + light + moderate + heavy));

	totalBurned = dropDecimalPlaces(totalBurned);
	resultString = "<span class=\"biggreen\">" + totalBurned + " kcal</span>";
	dailyDisplay(resultString);
}
