<!--
	function getUnit(frmObj)
	{
		if(frmObj.options[0].selected == true)
			return 'Miles';
		else if(frmObj.options[1].selected == true)
			return 'Kilometers';
		else if(frmObj.options[2].selected == true)
			return 'Meters';
		else
			return 'Yards';
	}

	function getTimeString(argHours, argMin, argSec)
	{
		var retVal;
		retVal = '';
		if(argHours > 0)
		{
			retVal = argHours + ':';
			if(argMin > 9)
				retVal = retVal + argMin + ':';
			else
				retVal = retVal + '0' + argMin + ':';
		} else
			retVal = argMin + ':';
		if(argSec > 9)
			retVal = retVal + argSec;
		else
			retVal = retVal + '0' + argSec;
		
		return retVal;
	}

	function ConvertUnits(fromUnit, toUnit)
	{
		var retVal;
		retVal = 1;
		if(fromUnit == 'Miles')
		{
			if(toUnit == 'Kilometers')
				retVal = 1.6093;
			else if(toUnit == 'Meters')
				retVal = 1609.3;
			else if(toUnit == 'Yards')
				retVal = 1761;
		} else if(fromUnit == 'Kilometers')
		{
			if(toUnit == 'Miles')
				retVal = 1 / 1.6093;
			else if(toUnit == 'Meters')
				retVal = 1000;
			else if(toUnit == 'Yards')
				retVal = 1093.6;
		} else if(fromUnit == 'Meters')
		{
			if(toUnit == 'Miles')
				retVal = 1 / 1609.3;
			else if(toUnit == 'Kilometers')
				retVal = 1 / 1000;
			else if(toUnit == 'Yards')
				retVal = 1.0936;
		} else if(fromUnit == 'Yards')
		{
			if(toUnit == 'Miles')
				retVal = 1 / 1761;
			else if(toUnit == 'Kilometers')
				retVal = 1 / 1093.6;
			else if(toUnit == 'Meters')
				retVal = 1 / 1.0936;
		}

		return retVal;
	}
	
	function ConvertDistance()
	{
		var userMsg, tmpVal;
		var fromUnits, toUnits;
		userMsg = '';
		
		tmpVal = parseFloat(document.frmCalcDistance.convertFrom.value);
		if(isNaN(tmpVal))
			userMsg = 'Please enter a valid distance to convert from.';
		else
		{
			fromUnits = getUnit(document.frmCalcDistance.convertFromUnits);
			toUnits = getUnit(document.frmCalcDistance.convertToUnits);

			userMsg = tmpVal + ' ' + fromUnits + ' = ' + (Math.round(100 * tmpVal * ConvertUnits(fromUnits, toUnits)) / 100) + ' ' + toUnits;
		}
		document.getElementById('divDistanceConvert').innerHTML = '<span class="hot"><strong>' + userMsg + '</strong></span>';
	}
	
	function CalcCalories()
	{
		var userMsg, ct, x, calValue, tmpVal;
		userMsg = '';
		
		calValue = 0.79;		/* Default to running */
		ct = document.frmCalcCalorie.activity;
		for(x = 0; x < ct.options.length; x++)
		{
			if(ct.options[x].selected == true)
			{
				switch(ct.options[x].value)
				{
					case 'swim' :	calValue = 2.93;
									userMsg = 'Swimming ';
							break;
					case 'bike' :	calValue = 0.28;
									userMsg = 'Biking ';
							break;
					case 'run' :	calValue = 0.79;
									userMsg = 'Running ';
							break;
				}
			}
		}

		ct = document.frmCalcCalorie;
		tmpVal = parseFloat(ct.distance.value);
		if(isNaN(tmpVal))
			tmpVal = 0;
		calValue = calValue * tmpVal * ConvertUnits(getUnit(ct.distanceUnits), 'Miles');
		userMsg = userMsg + tmpVal + ' ' + getUnit(ct.distanceUnits).toLowerCase() + ', Weight ';
		if(tmpVal <= 0)
			userMsg = 'Please enter a valid distance.';
		else
		{
			tmpVal = parseFloat(ct.myWeight.value);
			if(isNaN(tmpVal))
				tmpVal = 0;
			if(ct.weightUnits.options[1].selected == true)
			{
				userMsg = userMsg + tmpVal + ' kilograms<br>';
				tmpVal = tmpVal * 2.2046;
			} else
				userMsg = userMsg + tmpVal + ' pounds<br>';
	
			calValue = calValue * tmpVal;
			if(tmpVal > 0)
				userMsg = userMsg + 'Calories burned is appoximately ' + Math.round(calValue) + '.';
			else
				userMsg = 'Please enter a valid weight.';
		}
		document.getElementById('divCalorieMsg').innerHTML = '<span class="hot"><strong>' + userMsg + '</strong></span>';
	}
	
	function PlanRace()
	{
		var thisHour, thisMin, thisSec, thisTime, raceDistance, timeStep, raceTime, endTime;
		var tblHTML, mile_count, this_unit;
		var userMsg, frm;
		var dst_offset;
		
		userMsg = '';
		tblHTML = '';
		frm = document.frmCalcRace;
		thisHour = parseInt(frm.raceHours.value);
		if(isNaN(thisHour))
			thisHour = -1;
		thisMin = parseInt(frm.raceMinutes.value);
		if(isNaN(thisMin))
			thisMin = -1;
		thisSec = parseInt(frm.raceSeconds.value);
		if(isNaN(thisSec))
			thisSec = -1;
		if(thisSec >= 0 && thisMin >= 0 && thisHour >= 0 && (thisSec + thisMin + thisHour > 0))
		{
			raceDistance = parseFloat(frm.raceDistance.value);
			if(isNaN(raceDistance))
				raceDistance = 0;
			
			if(raceDistance <= 0 || raceDistance > 1000)
				userMsg = '<span class="hot"><strong>Please enter a valid distance</strong></span>';
			else
			{
				userMsg = '<table cellspacing="0" cellpadding="5" border="1" bordercolor="#DDEBF8">\n' + 
						'<tr><td align="center" colspan="2"><strong>' + raceDistance + ' ' + getUnit(frm.raceDistanceUnits) + ' in ';

				// Calculate Daylight Savings Time Offset. Get current time in milliseconds. Then set this time into
				// GMT. Calculate the difference between the two to include the DST offset as well as difference between
				// GMT and local timezone.
				thisTime = new Date();
				dst_offset = thisTime.getTime();
				thisTime.setTime((((thisTime.getHours() * 60) + thisTime.getMinutes()) * 60 + thisTime.getSeconds()) * 1000);
				dst_offset = dst_offset - thisTime.getTime();
				
				//Old method...this might have been causing problems from DST? Use above method instead for DST Offset
				//thisTime.setTime((((thisHour * 60) + thisMin) * 60 + thisSec + (thisTime.getTimezoneOffset() * 60)) * 1000);

				thisTime.setTime(((((thisHour * 60) + thisMin) * 60 + thisSec) * 1000) + dst_offset);
				endTime = thisTime.getTime();

				userMsg = userMsg + getTimeString(thisTime.getHours(), thisTime.getMinutes(), thisTime.getSeconds()) + '</strong><br>\n';

				thisTime.setTime((((thisHour * 60) + thisMin) * 60 + thisSec) * 1000);
				timeStep = thisTime.getTime() / raceDistance;
				raceTime = timeStep + dst_offset;
				thisTime.setTime(raceTime);
				this_unit = getUnit(frm.raceDistanceUnits).toLowerCase();
				userMsg = userMsg + '(' + getTimeString(thisTime.getHours(), thisTime.getMinutes(), thisTime.getSeconds()) + '/' +
						this_unit.substring(0, this_unit.length - 1) + ')</td></tr>\n';

				mile_count = 1;
				while(raceTime < endTime)
				{
					thisTime.setTime(raceTime);
					if(mile_count == 1)
						tblHTML = tblHTML + '<tr>\n<td>1 ' + this_unit.substring(0, this_unit.length - 1) + '</td>\n';
					else
						tblHTML = tblHTML + '<tr>\n<td>' + mile_count + ' ' + this_unit + '</td>\n';
					tblHTML = tblHTML + '<td align="right">' + getTimeString(thisTime.getHours(), thisTime.getMinutes(), thisTime.getSeconds()) + '</td></tr>\n';

					raceTime = raceTime + timeStep;
					mile_count = mile_count + 1;
				}
				thisTime.setTime(endTime);
				tblHTML = tblHTML + '<tr>\n<td>' + raceDistance + ' ' + this_unit + '</td>\n';
				tblHTML = tblHTML + '<td>' + getTimeString(thisTime.getHours(), thisTime.getMinutes(), thisTime.getSeconds()) + '</td></tr>\n';
				tblHTML + '</table>';
				
				userMsg = userMsg + tblHTML;
			}
		} else
			userMsg = '<span class="hot"><strong>Please enter a valid time.</strong></span>';
		
		document.getElementById('divRacePlanner').innerHTML = userMsg;
	}

	function ChangePaceOption(paceType)
	{
		document.getElementById('tdPaceTime1').style.background = '#DDEBF8';
		document.getElementById('tdPaceTime2').style.background = '#FFFFFF';
		document.getElementById('tdPaceDistance1').style.background = '#DDEBF8';
		document.getElementById('tdPaceDistance2').style.background = '#FFFFFF';
		document.getElementById('tdPace1').style.background = '#DDEBF8';
		document.getElementById('tdPace2').style.background = '#FFFFFF';

		document.frmCalcPace.MyPaceMinutes.disabled = false;
		document.frmCalcPace.MyPaceMinutes.readonly = false;
		document.frmCalcPace.MyPaceSeconds.disabled = false;
		document.frmCalcPace.MyPaceSeconds.readonly = false;
		document.frmCalcPace.PaceUnits.disabled = false;
		document.frmCalcPace.PaceUnits.readonly = false;

		document.frmCalcPace.MyHours.disabled = false;
		document.frmCalcPace.MyHours.readonly = false;
		document.frmCalcPace.MyMinutes.disabled = false;
		document.frmCalcPace.MyMinutes.readonly = false;
		document.frmCalcPace.MySeconds.disabled = false;
		document.frmCalcPace.MySeconds.readonly = false;

		document.frmCalcPace.MyDistance.disabled = false;
		document.frmCalcPace.MyDistance.readonly = false;
		document.frmCalcPace.DistanceUnits.disabled = false;
		document.frmCalcPace.DistanceUnits.readonly = false;
		switch(paceType)
		{
			case 'pace' :
				document.getElementById('tdPace1').style.background = '#E9E9E9';
				document.getElementById('tdPace2').style.background = '#E9E9E9';
				document.frmCalcPace.MyPaceMinutes.disabled = true;
				document.frmCalcPace.MyPaceMinutes.readonly = true;
				document.frmCalcPace.MyPaceSeconds.disabled = true;
				document.frmCalcPace.MyPaceSeconds.readonly = true;
				document.frmCalcPace.PaceUnits.disabled = true;
				document.frmCalcPace.PaceUnits.readonly = true;
				break;
			case 'time' :
				document.getElementById('tdPaceTime1').style.background = '#E9E9E9';
				document.getElementById('tdPaceTime2').style.background = '#E9E9E9';
				document.frmCalcPace.MyHours.disabled = true;
				document.frmCalcPace.MyHours.readonly = true;
				document.frmCalcPace.MyMinutes.disabled = true;
				document.frmCalcPace.MyMinutes.readonly = true;
				document.frmCalcPace.MySeconds.disabled = true;
				document.frmCalcPace.MySeconds.readonly = true;
				break;
			case 'distance' :
				document.getElementById('tdPaceDistance1').style.background = '#E9E9E9';
				document.getElementById('tdPaceDistance2').style.background = '#E9E9E9';
				document.frmCalcPace.MyDistance.disabled = true;
				document.frmCalcPace.MyDistance.readonly = true;
				document.frmCalcPace.DistanceUnits.disabled = true;
				document.frmCalcPace.DistanceUnits.readonly = true;
				break;
		}
	}

	function CalculatePace()
	{
		var userMsg;
		userMsg = '';

		var thisTime, thisDistance, thisPace, thisHour, thisMin, thisSec;
		var frm, thisVal, thisTimeVal, dst_offset;
			
		frm = document.frmCalcPace;
		if(frm.whichOption[0].checked == true || frm.whichOption[2].checked == true)
		{
			thisVal = parseInt(frm.MyHours.value);
			if(isNaN(thisVal))
				thisHour = -1;
			else
				thisHour = thisVal;
			thisVal = parseInt(frm.MyMinutes.value);
			if(isNaN(thisVal))
				thisMin = -1;
			else
				thisMin = thisVal;
			thisVal = parseInt(frm.MySeconds.value);
			if(isNaN(thisVal))
				thisSec = -1;
			else
				thisSec = thisVal;

			if(thisHour >= 0 && thisMin >= 0 && thisSec >= 0 && (thisHour + thisMin + thisSec > 0))
			{
				thisTime = ((thisHour * 3600) + (thisMin * 60) + thisSec) * 1000;
			} else
				userMsg = 'Please enter a valid time.';
		}

		if(frm.whichOption[0].checked == true && userMsg == '')
		{
			/* Get Pace .... knowing the time and distance */

			if(thisHour >= 0 && thisMin >= 0 && thisSec >= 0)
			{
				thisVal = parseFloat(frm.MyDistance.value);
				if(isNaN(thisVal))
					thisVal = -1;
				else if(thisVal > 0)
					thisVal = Math.round(thisVal * 100) / 100;

				if(thisVal <= 0)
					userMsg = 'Please enter a valid distance.';
			}

			if(thisHour >= 0 && thisMin >= 0 && thisSec >= 0 && userMsg == '')
			{
				userMsg = 'If you run ' + thisVal + ' ' + getUnit(frm.DistanceUnits) + ' in ' + getTimeString(thisHour, thisMin, thisSec);
				thisVal = ((((thisHour * 60) + thisMin) * 60) + thisSec) / thisVal;
				thisHour = Math.floor(thisVal / 3600);
				thisVal = thisVal - (thisHour * 3600);
				thisMin = Math.floor(thisVal / 60);
				thisSec = Math.floor(thisVal - (thisMin * 60));
				if(thisHour < 0)
					thisHour = 0;
				if(thisMin < 0)
					thisMin = 0;
				if(thisSec < 0)
					thisSec = 0;
					
				userMsg = userMsg + ',<br>your pace is ' + getTimeString(thisHour, thisMin, thisSec);
				userMsg = userMsg + ' per ' + getUnit(frm.DistanceUnits).toLowerCase();
				userMsg = userMsg.substring(0, userMsg.length - 1) + '.';
			}
		} else if(frm.whichOption[1].checked == true && userMsg == '')
		{
			/* Get time .... knowing pace and distance */
			thisVal = parseInt(frm.MyPaceMinutes.value);
			if(isNaN(thisVal))
				thisMin = -1;
			else
				thisMin = thisVal;
			thisVal = parseInt(frm.MyPaceSeconds.value);
			if(isNaN(thisVal))
				thisSec = -1;
			else
				thisSec = thisVal;

			if(thisMin >= 0 && thisSec >= 0 && (thisMin + thisSec) > 0)
			{
				thisTime = ((thisMin * 60) + thisSec) * 1000;
				
				thisVal = parseFloat(frm.MyDistance.value);
				if(isNaN(thisVal))
					userMsg = 'Please enter a valid distance.';
				else
				{
					userMsg = 'If you run for ' + (Math.round(thisVal * 10) / 10) + ' ' + getUnit(frm.DistanceUnits) + ' at ';
					userMsg = userMsg + thisMin + ':';
					if(thisSec > 9)
						userMsg = userMsg + thisSec;
					else
						userMsg = userMsg + '0' + thisSec;
					userMsg = userMsg + ' per ' + getUnit(frm.PaceUnits).toLowerCase();
					/* Trim lower case 's' at end of units */
					userMsg = userMsg.substring(0, userMsg.length - 1) + ',<br>your time is ';

					thisVal = (thisVal * thisTime * ConvertUnits(getUnit(frm.DistanceUnits), getUnit(frm.PaceUnits))) / 1000;
					thisHour = Math.floor(thisVal / 3600);
					thisVal = thisVal - (thisHour * 3600);
					thisMin = Math.floor(thisVal / 60);
					thisSec = Math.floor(thisVal - (thisMin * 60));
					
					userMsg = userMsg + thisHour + ':';
					if(thisMin > 9)
						userMsg = userMsg + thisMin + ':';
					else
						userMsg = userMsg + '0' + thisMin + ':';
					if(thisSec > 9)
						userMsg = userMsg + thisSec;
					else
						userMsg = userMsg + '0' + thisSec;
					userMsg = userMsg + '.';
				}
			} else
				userMsg = 'Please enter a valid pace.';

		} else if(frm.whichOption[2].checked == true && userMsg == '')
		{
			/* Get distance  .... knowing time and pace */
			userMsg = 'If you run for ' + getTimeString(thisHour, thisMin, thisSec);

			/* Get pace time */
			thisMin = parseInt(frm.MyPaceMinutes.value);
			if(isNaN(thisVal))
				thisMin = -1;
			thisSec = parseInt(frm.MyPaceSeconds.value);
			if(isNaN(thisVal))
				thisSec = -1;

			if(thisMin >= 0 && thisSec >= 0 && (thisMin + thisSec) > 0)
			{
				userMsg = userMsg + ' at ' + thisMin;
				if(thisSec > 9)
					userMsg = userMsg + ':' + thisSec;
				else
					userMsg = userMsg + ':0' + thisSec;
				userMsg = userMsg + ' per ' + getUnit(frm.PaceUnits).toLowerCase();

				/* this time was setup above....this is the TIME that they run */
				/* tmpVal, assinged below...is their PACE */
				tmpVal = ((thisMin * 60) + thisSec) * 1000;
				
				/* now calculate how many UNITS they would run during this time */
				tmpVal = Math.round((thisTime/tmpVal) * 100) / 100;

				userMsg = userMsg.substring(0, userMsg.length - 1) + ',<br>your distance is ' + tmpVal + ' ' + getUnit(frm.PaceUnits).toLowerCase() + '.';
			} else
				userMsg = 'Please enter a valid pace.';
		}
		document.getElementById('CalculatorMessage').innerHTML = '<span class="hot"><strong>' + userMsg + '</strong></span>';
	}
// -->
