<!-- Begin of JavaScript code; this code is only for JavaScript-capable browsers
// Original script: Anton Steenkamp
// Website: http://www.sportsdigest.co.za
// This script may be copied and used without any changes or modifications.
// If you so wish to use this script on your site, feel free. I am only asking
// a linked reference to www.sportsdigest.co.za. If you let me know the website
// where you are using it, I'll create a link to yours as well.

function newWindow()
	{
	helpWindow = window.open('hlp_bin/cyclhlp.htm','hlpWin','width=580,height=330')
	}


function leading(A)
	{
	if(A < 10)
		A = '0'+A;
	return A;
	}
	
function runcalc()
		{
		foundError = false;
		if(document.cycleprediction.ad.value == "")
			{
			alert("\nPlease enter any reasonable distance.");
			foundError = true;
			document.cycleprediction.ad.focus();
			return false;
			}
	
	foundError = false;
		if((document.cycleprediction.ath.value == "") && (document.cycleprediction.atm.value == "") && (document.cycleprediction.ats.value == ""))
			{
			alert("\nPlease enter your actual/planned finish time for the distance.");
			foundError = true;
			document.cycleprediction.ath.focus();
			return false;
			}
		else
			{
			if(document.cycleprediction.ath.value == "") document.cycleprediction.ath.value = 0;
			if(document.cycleprediction.atm.value == "") document.cycleprediction.atm.value = "00";
			if(document.cycleprediction.ats.value == "") document.cycleprediction.ats.value = "00";
			}

	// Factors
	F1 = 1.06;
	F2 = 1.245;

	// ACTUAL INFORMATION
	// Actual Distance (AD)
	AD = document.cycleprediction.ad.value;

	//Actual Time (AT)
	ATH = document.cycleprediction.ath.value;
	ATM = document.cycleprediction.atm.value;
	ATS = document.cycleprediction.ats.value;

	AT = ((ATH * 3600) + (ATM * 60) + (ATS * 1));

	// Actual Pace (AP) Calculation
	AP = Math.floor(((AD / AT) * 3600) * 10) / 10;
		
	document.cycleprediction.ap.value = AP;
	
	// Planned Distance (PD)
	PD = document.cycleprediction.pd.value;

	if(PD == "")
		{
		PD = AD;
		}
	else
		{
		PD = PD * 1;
		}

	document.cycleprediction.pd.value = PD;

	// Predicted Time (PT) Calculation
	PT = Math.pow((PD / AD),F1) * AT;
	
		PTH = Math.floor(PT / 3600);
		PTM = Math.floor((PT - (PTH * 3600)) / 60);
		PTS = Math.floor(PT - (PTH * 3600) - (PTM * 60));

	document.cycleprediction.pth.value = PTH;
	document.cycleprediction.ptm.value = leading(PTM);
	document.cycleprediction.pts.value = leading(PTS);

	// Predicted Pace (PP)
	PP = Math.floor(((PD / PT) * 3600) * 10) / 10;

	document.cycleprediction.pp.value = PP;
	
	// INFORMATION FOR TIME TABLE
	// 30km Calculations
	
	// Planned Distance - 30km (PD30)
	PD30 = 30;
	
	// Predicted Time Calculation - 30km (PT30)
	PT30 = Math.pow((PD30 / AD),F1) * AT;

		PT30H = Math.floor(PT30 / 3600);
		PT30M = Math.floor((PT30 - (PT30H * 3600)) / 60);
		PT30S = Math.floor(PT30 - (PT30H * 3600) - (PT30M * 60));

	document.timetable.pt30h.value = PT30H;
	document.timetable.pt30m.value = leading(PT30M);
	document.timetable.pt30s.value = leading(PT30S);


	// Predicted Pace - 30km (PP30)
	PP30 = (Math.floor(((PD30 / PT30) * 3600) * 10) / 10);
	
	document.timetable.pp30.value = PP30;
	
	// 50km Calculations
	// Planned Distance - 50km (PD50)
	PD50 = 50;

	// Predicted Time Calculation - 50km (PT50)
	PT50 = Math.pow((PD50 / AD),F1) * AT;

		PT50H = Math.floor(PT50 / 3600);
		PT50M = Math.floor((PT50 - (PT50H * 3600)) / 60);
		PT50S = Math.floor(PT50 - (PT50H * 3600) - (PT50M * 60));

	document.timetable.pt50h.value = PT50H;
	document.timetable.pt50m.value = leading(PT50M);
	document.timetable.pt50s.value = leading(PT50S);


	// Predicted Pace - 50km (PP50)
	PP50 = Math.floor(((PD50 / PT50) * 3600) * 10) / 10;

	document.timetable.pp50.value = PP50;

	// 60km Calculations
	// Planned Distance - 60km (PD60)
	PD60 = 60;

	// Predicted Time Calculation - 60km (PT60)
	PT60 = Math.pow((PD60 / AD),F1) * AT;

		PT60H = Math.floor(PT60 / 3600);
		PT60M = Math.floor((PT60 - (PT60H * 3600)) / 60);
		PT60S = Math.floor(PT60 - (PT60H * 3600) - (PT60M * 60));

	document.timetable.pt60h.value = PT60H;
	document.timetable.pt60m.value = leading(PT60M);
	document.timetable.pt60s.value = leading(PT60S);

	// Predicted Pace - 60km (PP60)
	PP60 = Math.floor(((PD60 / PT60) * 3600) * 10) / 10;

	document.timetable.pp60.value = PP60;

	// 75km Calculations
	// Planned Distance - 75km (PD75)
	PD75 = 75;

	// Predicted Time Calculation - 75km (PT75)
	PT75 = Math.pow((PD75 / AD),F1) * AT;

		PT75H = Math.floor(PT75 / 3600);
		PT75M = Math.floor((PT75 - (PT75H * 3600)) / 60);
		PT75S = Math.floor(PT75 - (PT75H * 3600) - (PT75M * 60));

	document.timetable.pt75h.value = PT75H;
	document.timetable.pt75m.value = leading(PT75M);
	document.timetable.pt75s.value = leading(PT75S);


	// Predicted Pace - 75km (PP75)
	PP75 = Math.floor(((PD75 / PT75) * 3600) * 10) / 10;

	document.timetable.pp75.value = PP75;

	// 90km Calculations
	// Planned Distance - 90km (PD90)
	PD90 = 90;

	// Predicted Time Calculation - 90km (PT90)
	PT90 = Math.pow((PD90 / AD),F1) * AT;

		PT90H = Math.floor(PT90 / 3600);
		PT90M = Math.floor((PT90 - (PT90H * 3600)) / 60);
		PT90S = Math.floor(PT90 - (PT90H * 3600) - (PT90M * 60));

	document.timetable.pt90h.value = PT90H;
	document.timetable.pt90m.value = leading(PT90M);
	document.timetable.pt90s.value = leading(PT90S);


	// Predicted Pace - 90km (PP90)
	PP90 = Math.floor(((PD90 / PT90) * 3600) * 10) / 10;

	document.timetable.pp90.value = PP90;

	// 100km Calculations
	// Planned Distance - 100km (PD100)
	PD100 = 100;

	// Predicted Time Calculation - 100km (PT100)
	PT100 = Math.pow((PD100 / AD),F1) * AT;

		PT100H = Math.floor(PT100 / 3600);
		PT100M = Math.floor((PT100 - (PT100H * 3600)) / 60);
		PT100S = Math.floor(PT100 - (PT100H * 3600) - (PT100M * 60));

	document.timetable.pt100h.value = PT100H;
	document.timetable.pt100m.value = leading(PT100M);
	document.timetable.pt100s.value = leading(PT100S);


	// Predicted Pace - 100km (PP100)
	PP100 = Math.floor(((PD100 / PT100) * 3600) * 10) / 10;

	document.timetable.pp100.value = PP100;

	// 120km Calculations
	// Planned Distance - 120km (PD120)
	PD120 = 120;

	// Predicted Time Calculation - 120km (PT120)
	PT120 = Math.pow((PD120 / AD),F1) * AT;

		PT120H = Math.floor(PT120 / 3600);
		PT120M = Math.floor((PT120 - (PT120H * 3600)) / 60);
		PT120S = Math.floor(PT120 - (PT120H * 3600) - (PT120M * 60));

	document.timetable.pt120h.value = PT120H;
	document.timetable.pt120m.value = leading(PT120M);
	document.timetable.pt120s.value = leading(PT120S);


	// Predicted Pace - 120km (PP120)
	PP120 = Math.floor(((PD120 / PT120) * 3600) * 10) / 10;

	document.timetable.pp120.value = PP120;

	// 180km Calculations
	// Planned Distance - 180km (PD180)
	PD180 = 180;

	// Predicted Time Calculation - 180km (PT180)
	PT180 = Math.pow((PD180 / AD),F1) * AT;

		PT180H = Math.floor(PT180 / 3600);
		PT180M = Math.floor((PT180 - (PT180H * 3600)) / 60);
		PT180S = Math.floor(PT180 - (PT180H * 3600) - (PT180M * 60));

	document.timetable.pt180h.value = PT180H;
	document.timetable.pt180m.value = leading(PT180M);
	document.timetable.pt180s.value = leading(PT180S);


	// Predicted Pace - 180km (PP180)
	PP180 = Math.floor(((PD180 / PT180) * 3600) * 10) / 10;

	document.timetable.pp180.value = PP180;

	}

function clearall() {

	document.cycleprediction.ad.value = "";
	document.cycleprediction.ath.value = "";
	document.cycleprediction.atm.value = "";
	document.cycleprediction.ats.value = "";
	document.cycleprediction.ap.value = "";
	document.cycleprediction.pth.value = "";
	document.cycleprediction.ptm.value = "";
	document.cycleprediction.pts.value = "";
	document.cycleprediction.pp.value = "";
	document.cycleprediction.pd.value = "";
	document.timetable.pt30h.value = "";
	document.timetable.pt30m.value = "";
	document.timetable.pt30s.value = "";
	document.timetable.pp30.value = "";
	document.timetable.pt50h.value = "";
	document.timetable.pt50m.value = "";
	document.timetable.pt50s.value = "";
	document.timetable.pp50.value = "";
	document.timetable.pt60h.value = "";
	document.timetable.pt60m.value = "";
	document.timetable.pt60s.value = "";
	document.timetable.pp60.value = "";
	document.timetable.pt75h.value = "";
	document.timetable.pt75m.value = "";
	document.timetable.pt75s.value = "";
	document.timetable.pp75.value = "";
	document.timetable.pt90h.value = "";
	document.timetable.pt90m.value = "";
	document.timetable.pt90s.value = "";
	document.timetable.pp90.value = "";
	document.timetable.pt100h.value = "";
	document.timetable.pt100m.value = "";
	document.timetable.pt100s.value = "";
	document.timetable.pp100.value = "";
	document.timetable.pt120h.value = "";
	document.timetable.pt120m.value = "";
	document.timetable.pt120s.value = "";
	document.timetable.pp120.value = "";
	document.timetable.pt180h.value = "";
	document.timetable.pt180m.value = "";
	document.timetable.pt180s.value = "";
	document.timetable.pp180.value = "";
	document.cycleprediction.ad.focus();

	}

// End of JavaScript code -->	
