<!--

// constants
var TIME = 0;
var DISTANCE = 1;
var PACE = 2;
var MILES = 0;
var METERS = 1;
var YARDS = 2;
var KILOMETERS = 3;
var PER_MILE = 0;
var PER_400 = 1;
var PER_KM = 2;

// number constants
var YARDS_IN_MILE = 1760;
var METERS_IN_METER = 1;
var METERS_IN_400 = 400;
var METERS_IN_MILE = 1609.344;
var METERS_IN_KM = 1000;
var METERS_IN_YARD = METERS_IN_MILE / YARDS_IN_MILE;

/*
 * Clear the fields.
 */
function clearNums()
{
	document.Calc.timeH.value=0;
	document.Calc.timeM.value=0;
	document.Calc.timeS.value=0;
	document.Calc.distance.value=0;
	document.Calc.paceH.value=0;
	document.Calc.paceM.value=0;
	document.Calc.paceS.value=0;
}

/*
 * defaultStuff sets the defaults. It is called by the onLoad event.
 */
function defaultStuff()
{
	// set list box default to PACE
	document.Calc.CalcWhat.selectedIndex=2;
	
	// set option buttons to defaults
	document.Calc.optDist[0].checked=true;
	document.Calc.optPace[0].checked=true;
}

/*
 * This function is called to perform the calculation.
 */
function calcIT()
{
	// Time (converted to seconds)
	var hour = document.Calc.timeH.value;
	var min = document.Calc.timeM.value;
	var sec = document.Calc.timeS.value;
	var timeObj = new TimeObject(hour, min, sec);

	// Distance
	var distVal = document.Calc.distance.value;
	var distUnit = getDistanceUnit();
	var distObj = new DistanceObject(distVal, distUnit);

	// Pace (converted to seconds per)
	var hourP =document.Calc.paceH.value;
	var minP=document.Calc.paceM.value;
	var secP=document.Calc.paceS.value;
	var paceUnit = getPaceUnit();
	var paceObj = new PaceObject(hourP, minP, secP, paceUnit);
	
	// Which result
	var resultValue=document.Calc.CalcWhat.options[document.Calc.CalcWhat.selectedIndex].value;

	if (resultValue==TIME)
	{				
		timeObj.calculate(distObj, paceObj);

		document.Calc.timeH.value = timeObj.getHours();
		document.Calc.timeM.value = timeObj.getMinutes();
		document.Calc.timeS.value = timeObj.getSeconds();
	}
	else if (resultValue==DISTANCE)
	{
		distObj.calculate(timeObj, paceObj);

		// rounding
		document.Calc.distance.value = distObj.decimalPlaces(2);
	}
	else if (resultValue==PACE)
	{
		paceObj.calculate(timeObj, distObj);

		document.Calc.paceH.value = paceObj.getHours();
		document.Calc.paceM.value = paceObj.getMinutes();
		document.Calc.paceS.value = paceObj.getSeconds();
	}
}//end CalcIt

/*
 * Get the unit of measure for distance.
 */
function getDistanceUnit()
{
	var unit;
	if (document.Calc.optDist[MILES].checked)
	{
		unit = METERS_IN_MILE;
	}
	else if (document.Calc.optDist[METERS].checked)
	{
		unit = METERS_IN_METER;
	}
	else if (document.Calc.optDist[KILOMETERS].checked)
	{
		unit = METERS_IN_KM;
	}
	else if (document.Calc.optDist[YARDS].checked)
	{
		unit = METERS_IN_YARD;
	}
	
	return unit;
}

/*
 * Get the unit of measure for pace.
 */
function getPaceUnit()
{
	var unit;
	if (document.Calc.optPace[PER_MILE].checked)
	{	
		unit = METERS_IN_MILE;
	}
	else if (document.Calc.optPace[PER_400].checked)
	{
		unit = METERS_IN_400;
	}
	else if (document.Calc.optPace[PER_KM].checked)
	{
		unit = METERS_IN_KM;
	}

	return unit;
}

//-->
