<!-- Hide script from older browsers
// Original script: Anton Steenkamp
// Website: http://www.sportsdigest.co.za
// This script is protected by copyright laws and may not be copied, modified, reproduced
// or used in any form without written permission from Anton Steenkamp - info@sportsdigest.co.za.



// Variable Factors & Values - CD = Comrades Distance
CD = 89.000;

function leading(A)
	{
	if(A < 10)
		A = '0'+A;
	return A;
	}

function comrades()
	{

	foundError = false;
		if((document.comrades_ft.ad1.value == "-") && (document.comrades_ft.ad2.value == "-") && (document.comrades_ft.ad3.value == "-"))
		{
			alert("\nPlease enter at least one reasonable distance.");
			foundError = true;
			document.comrades_ft.ad1.focus();
			return false;
		}

	foundError = false;
		if(((document.comrades_ft.at1h.value == "") && (document.comrades_ft.at1m.value == "") && (document.comrades_ft.at1s.value == "")) || ((document.comrades_ft.at1h.value == "0") && (document.comrades_ft.at1m.value == "00") && (document.comrades_ft.at1s.value == "00")))
		{
			alert("\nPlease enter your actual/planned finish time for the distance.");
			foundError = true;
			document.comrades_ft.at1h.focus();
			return false;
		}


	// ACTUAL INFORMATION
	// Actual Distance One (AD1)
	AD1 = document.comrades_ft.ad1.value;

	//Actual Time One (AT1)

	AT1H = document.comrades_ft.at1h.value;
	AT1M = document.comrades_ft.at1m.value;
	AT1S = document.comrades_ft.at1s.value;

	AT1 = (AT1H * 3600) + (AT1M * 60) + (AT1S * 1);

	if(document.comrades_ft.at1h.value == "") document.comrades_ft.at1h.value = 0;
	if(document.comrades_ft.at1m.value == "") document.comrades_ft.at1m.value = "00";
	if(document.comrades_ft.at1s.value == "") document.comrades_ft.at1s.value = "00";
	if(document.comrades_ft.at1m.value < 10) document.comrades_ft.at1m.value = leading(AT1M * 1);
	if(document.comrades_ft.at1s.value < 10) document.comrades_ft.at1s.value = leading(AT1S * 1);

	// Actual Pace (AP1) Calculation
	AP1 = (AT1 / AD1);
		AP1H = Math.floor(AP1 / 3600);
		AP1M = Math.floor((AP1 - (AP1H * 3600)) / 60);
		AP1S = Math.floor(AP1 - (AP1H * 3600) - (AP1M * 60));

	document.comrades_ft.ap1m.value = leading(AP1M);
	document.comrades_ft.ap1s.value = leading(AP1S);

	I = 1;

	// Actual Distance Two (AD2)
	AD2 = document.comrades_ft.ad2.value;

	if(AD2 > 0) I = ++I;

	//Actual Time Two (AT2)
	AT2H = document.comrades_ft.at2h.value;
	AT2M = document.comrades_ft.at2m.value;
	AT2S = document.comrades_ft.at2s.value;

	AT2 = (AT2H * 3600) + (AT2M * 60) + (AT2S * 1);

	if((document.comrades_ft.ad2.value == "") || (document.comrades_ft.ad2.value == "-"))

			{
			document.comrades_ft.ad2.value = "-";
			document.comrades_ft.at2h.value = "-";
			document.comrades_ft.at2m.value = "-";
			document.comrades_ft.at2s.value = "-";
			document.comrades_ft.ap2m.value = "-";
			document.comrades_ft.ap2s.value = "-";
			}
		else
			{
			if(document.comrades_ft.at2h.value == "") document.comrades_ft.at2h.value = 0;
			if(document.comrades_ft.at2m.value == "") document.comrades_ft.at2m.value = "00";
			if(document.comrades_ft.at2s.value == "") document.comrades_ft.at2s.value = "00";
			if(document.comrades_ft.at2m.value < 10) document.comrades_ft.at2m.value = leading(AT2M * 1);
			if(document.comrades_ft.at2s.value < 10) document.comrades_ft.at2s.value = leading(AT2S * 1);

			// Actual Pace (AP2) Calculation
			AP2 = (AT2 / AD2);
				AP2H = Math.floor(AP2 / 3600);
				AP2M = Math.floor((AP2 - (AP2H * 3600)) / 60);
				AP2S = Math.floor(AP2 - (AP2H * 3600) - (AP2M * 60));

			if(document.comrades_ft.ad2.value == "-")
				{
				document.comrades_ft.ap2m.value = "-";
				document.comrades_ft.ap2s.value = "-";
				}
			else
				{
				document.comrades_ft.ap2m.value = leading(AP2M);
				document.comrades_ft.ap2s.value = leading(AP2S);
				}

			}

	// Actual Distance Three (AD3)
	AD3 = document.comrades_ft.ad3.value;

	if(AD3 > 0) I = ++I;

	//Actual Time Three (AT3)
	AT3H = document.comrades_ft.at3h.value;
	AT3M = document.comrades_ft.at3m.value;
	AT3S = document.comrades_ft.at3s.value;

	AT3 = (AT3H * 3600) + (AT3M * 60) + (AT3S * 1);

	if((document.comrades_ft.ad3.value == "") || (document.comrades_ft.ad3.value == "-"))

			{
			document.comrades_ft.ad3.value = "-";
			document.comrades_ft.at3h.value = "-";
			document.comrades_ft.at3m.value = "-";
			document.comrades_ft.at3s.value = "-";
			document.comrades_ft.ap3m.value = "-";
			document.comrades_ft.ap3s.value = "-";
			}
		else
			{
			if(document.comrades_ft.at3h.value == "") document.comrades_ft.at3h.value = 0;
			if(document.comrades_ft.at3m.value == "") document.comrades_ft.at3m.value = "00";
			if(document.comrades_ft.at3s.value == "") document.comrades_ft.at3s.value = "00";
			if(document.comrades_ft.at3m.value < 10) document.comrades_ft.at3m.value = leading(AT3M * 1);
			if(document.comrades_ft.at3s.value < 10) document.comrades_ft.at3s.value = leading(AT3S * 1);

			// Actual Pace (AP3) Calculation
			AP3 = (AT3 / AD3);
				AP3H = Math.floor(AP3 / 3600);
				AP3M = Math.floor((AP3 - (AP3H * 3600)) / 60);
				AP3S = Math.floor(AP3 - (AP3H * 3600) - (AP3M * 60));

			document.comrades_ft.ap3m.value = leading(AP3M);
			document.comrades_ft.ap3s.value = leading(AP3S);

			}

	if(I < 3)
		{
		alert("\nPlease note that for a more accurate prediction, three results are required.");
		}


	// PLANNED INFORMATION
	// Planned Distance (PD)
	PD = CD * 1;

	//Planned Time (PT)
	if(AD1 == 10) F1 = 10.93622;
	if(AD1 == 15) F1 = 7.11558;
	if(AD1 == 21.1) F1 = 4.95596;
	if(AD1 == 32) F1 = 3.18719;
	if(AD1 == 42.2) F1 = 2.37704;
	if(AD1 == 50) F1 = 1.98591;
	if(AD1 == 56) F1 = 1.72458;

	if(AD2 == 10) F2 = 10.93622;
	if(AD2 == 15) F2 = 7.11558;
	if(AD2 == 21.1) F2 = 4.95596;
	if(AD2 == 32) F2 = 3.18719;
	if(AD2 == 42.2) F2 = 2.37704;
	if(AD2 == 50) F2 = 1.98591;
	if(AD2 == 56) F2 = 1.72458;

	if(AD3 == 10) F3 = 10.93622;
	if(AD3 == 15) F3 = 7.11558;
	if(AD3 == 21.1) F3 = 4.95596;
	if(AD3 == 32) F3 = 3.18719;
	if(AD3 == 42.2) F3 = 2.37704;
	if(AD3 == 50) F3 = 1.98591;
	if(AD3 == 56) F3 = 1.72458;

	if(AD1 > 0)
		{
		PT1 = AT1 * F1;
		}
	else
		{
		PT1 = 0;
		}

	if(AD2 > 0)
		{
		PT2 = AT2 * F2;
		}
	else
		{
		PT2 = 0;
		}

	if(AD3 > 0)
		{
		PT3 = AT3 * F3;
		}
	else
		{
		PT3 = 0;
		}

	PT = (PT1 + PT2 + PT3) / I;

		PTH = Math.floor(PT / 3600);
		PTM = Math.floor((PT - (PTH * 3600)) / 60);
		PTS = Math.floor(PT - (PTH * 3600) - (PTM * 60));

		document.comrades_ft.pth.value = PTH;
		document.comrades_ft.ptm.value = leading(PTM);
		document.comrades_ft.pts.value = leading(PTS);

	// Planned Pace (PP) Calculation
	PP = (PT / PD);
		PPH = Math.floor(PP / 3600);
		PPM = Math.floor((PP - (PPH * 3600)) / 60);
		PPS = Math.floor(PP - (PPH * 3600) - (PPM * 60));

	document.comrades_ft.ppm.value = leading(PPM);
	document.comrades_ft.pps.value = leading(PPS);

}


function clear1()
	{
	document.comrades_ft.at1h.value = "";
	document.comrades_ft.at1m.value = "";
	document.comrades_ft.at1s.value = "";
	document.comrades_ft.at1h.focus();
	}

function clear2()
	{
	document.comrades_ft.at2h.value = "";
	document.comrades_ft.at2m.value = "";
	document.comrades_ft.at2s.value = "";
	document.comrades_ft.at2h.focus();
	}

function clear3()
	{
	document.comrades_ft.at3h.value = "";
	document.comrades_ft.at3m.value = "";
	document.comrades_ft.at3s.value = "";
	document.comrades_ft.at3h.focus();
	}


function pacecalc()

	{

	foundError = false;
		if((document.pacechart.pth.value == "") && (document.pacechart.ptm.value == ""))
			{
			alert("\nPlease enter any reasonable time.");
			foundError = true;
			document.pacechart.pth.focus();
			return false;
			}
		else
			{
			if(document.pacechart.pth.value == "") document.pacechart.pth.value = 0;
			if(document.pacechart.ptm.value == "") document.pacechart.ptm.value = "00";
			if(document.pacechart.pts.value == "") document.pacechart.pts.value = "00";
			}

	// Factors
	// C15 = Constant 15
	// D15 = Decreased 15, etc.
	C15 = 0.168528;
	C30 = 0.337056;
	C45 = 0.505584;
	C60 = 0.674112;
	C75 = 0.842640;
	C89 = 1;
	D15 = 0.154515;
	D30 = 0.314711;
	D45 = 0.480587;
	D60 = 0.652143;
	D75 = 0.829380;
	D89 = 1;

	//Planned Time (PT)
	PTH = document.pacechart.pth.value;
	PTM = document.pacechart.ptm.value;
	PTS = document.pacechart.pts.value;

	PT = ((PTH * 3600) + (PTM * 60) + (PTS * 1));

	// Planned Pace (PP) Calculation
	PP = (PT / (89.000 * 1));
		PPH = Math.floor(PP / 3600);
		PPM = Math.floor((PP - (PPH * 3600)) / 60);
		PPS = Math.floor(PP - (PPH * 3600) - (PPM * 60));

	document.pacechart.ppm.value = leading(PPM);
	document.pacechart.pps.value = leading(PPS);

	// SPLIT INFORMATION
	// 15km Split Time (ST15)
	if(document.pacechart.pace.value == "decrease")
		{
		ST15 = PT * D15;
		}
	else
		{
		ST15 = PT * C15;
		}

	// Convert Split Time
	ST15H = Math.floor(ST15 / 3600);
	ST15M = Math.floor((ST15 - (ST15H * 3600)) / 60);
	ST15S = Math.floor(ST15 - (ST15H * 3600) - (ST15M * 60));

	document.pacechart.st15h.value = ST15H;
	document.pacechart.st15m.value = leading(ST15M);
	document.pacechart.st15s.value = leading(ST15S);

	// Calculate pace at Split
	SP15 = ST15 / 15;

	SP15H = Math.floor(SP15 / 3600);
	SP15M = Math.floor((SP15 - (SP15H * 3600)) / 60);
	SP15S = Math.floor(SP15 - (SP15H * 3600) - (SP15M * 60));

	document.pacechart.sp15m.value = leading(SP15M);
	document.pacechart.sp15s.value = leading(SP15S);

	// 30km Split Time (ST30)
	if(document.pacechart.pace.value == "decrease")
		{
		ST30 = PT * D30;
		}
	else
		{
		ST30 = PT * C30;
		}

	// Convert Split Time
	ST30H = Math.floor(ST30 / 3600);
	ST30M = Math.floor((ST30 - (ST30H * 3600)) / 60);
	ST30S = Math.floor(ST30 - (ST30H * 3600) - (ST30M * 60));

	document.pacechart.st30h.value = ST30H;
	document.pacechart.st30m.value = leading(ST30M);
	document.pacechart.st30s.value = leading(ST30S);

	// Calculate pace at Split
	SP30 = ST30 / 30;

	SP30H = Math.floor(SP30 / 3600);
	SP30M = Math.floor((SP30 - (SP30H * 3600)) / 60);
	SP30S = Math.floor(SP30 - (SP30H * 3600) - (SP30M * 60));

	document.pacechart.sp30m.value = leading(SP30M);
	document.pacechart.sp30s.value = leading(SP30S);

	// 45km Split Time (ST45)
	if(document.pacechart.pace.value == "decrease")
		{
		ST45 = PT * D45;
		}
	else
		{
		ST45 = PT * C45;
		}

	// Convert Split Time
	ST45H = Math.floor(ST45 / 3600);
	ST45M = Math.floor((ST45 - (ST45H * 3600)) / 60);
	ST45S = Math.floor(ST45 - (ST45H * 3600) - (ST45M * 60));

	document.pacechart.st45h.value = ST45H;
	document.pacechart.st45m.value = leading(ST45M);
	document.pacechart.st45s.value = leading(ST45S);

	// Calculate pace at Split
	SP45 = ST45 / 45;

	SP45H = Math.floor(SP45 / 3600);
	SP45M = Math.floor((SP45 - (SP45H * 3600)) / 60);
	SP45S = Math.floor(SP45 - (SP45H * 3600) - (SP45M * 60));

	document.pacechart.sp45m.value = leading(SP45M);
	document.pacechart.sp45s.value = leading(SP45S);

	// 60km Split Time (ST60)
	if(document.pacechart.pace.value == "decrease")
		{
		ST60 = PT * D60;
		}
	else
		{
		ST60 = PT * C60;
		}

	// Convert Split Time
	ST60H = Math.floor(ST60 / 3600);
	ST60M = Math.floor((ST60 - (ST60H * 3600)) / 60);
	ST60S = Math.floor(ST60 - (ST60H * 3600) - (ST60M * 60));

	document.pacechart.st60h.value = ST60H;
	document.pacechart.st60m.value = leading(ST60M);
	document.pacechart.st60s.value = leading(ST60S);

	// Calculate pace at Split
	SP60 = ST60 / 60;

	SP60H = Math.floor(SP60 / 3600);
	SP60M = Math.floor((SP60 - (SP60H * 3600)) / 60);
	SP60S = Math.floor(SP60 - (SP60H * 3600) - (SP60M * 60));

	document.pacechart.sp60m.value = leading(SP60M);
	document.pacechart.sp60s.value = leading(SP60S);

	// 75km Split Time (ST75)
	if(document.pacechart.pace.value == "decrease")
		{
		ST75 = PT * D75;
		}
	else
		{
		ST75 = PT * C75;
		}

	// Convert Split Time
	ST75H = Math.floor(ST75 / 3600);
	ST75M = Math.floor((ST75 - (ST75H * 3600)) / 60);
	ST75S = Math.floor(ST75 - (ST75H * 3600) - (ST75M * 60));

	document.pacechart.st75h.value = ST75H;
	document.pacechart.st75m.value = leading(ST75M);
	document.pacechart.st75s.value = leading(ST75S);

	// Calculate pace at Split
	SP75 = ST75 / 75;

	SP75H = Math.floor(SP75 / 3600);
	SP75M = Math.floor((SP75 - (SP75H * 3600)) / 60);
	SP75S = Math.floor(SP75 - (SP75H * 3600) - (SP75M * 60));

	document.pacechart.sp75m.value = leading(SP75M);
	document.pacechart.sp75s.value = leading(SP75S);

	// 89km Split Time (ST89)
	if(document.pacechart.pace.value == "decrease")
		{
		ST89 = PT * D89;
		}
	else
		{
		ST89 = PT * C89;
		}

	// Convert Split Time
	ST89H = Math.floor(ST89 / 3600);
	ST89M = Math.floor((ST89 - (ST89H * 3600)) / 60);
	ST89S = Math.floor(ST89 - (ST89H * 3600) - (ST89M * 60));

	document.pacechart.st89h.value = ST89H;
	document.pacechart.st89m.value = leading(ST89M);
	document.pacechart.st89s.value = leading(ST89S);

	// Calculate pace at Split
	SP89 = ST89 / CD;

	SP89H = Math.floor(SP89 / 3600);
	SP89M = Math.floor((SP89 - (SP89H * 3600)) / 60);
	SP89S = Math.floor(SP89 - (SP89H * 3600) - (SP89M * 60));

	document.pacechart.sp89m.value = leading(SP89M);
	document.pacechart.sp89s.value = leading(SP89S);
	}


function hrcalc() {

	foundError = false;
		if(document.hrprediction.age.value == "")    {
		alert("\nPlease enter any reasonable age.");
		foundError = true;
		document.hrprediction.age.focus();
		return false;
		}

	foundError = false;
		if(document.hrprediction.rhr.value == "")    {
		alert("\nPlease enter your resting heart rate.");
		foundError = true;
		document.hrprediction.rhr.focus();
		return false;
		}

	// Codes
	// MHR - Maximum Heart Rate
	// MMHR - Maximum Heart Rate
	// RHR - Resting Heart Rate
	// HRR - Heart Rate Reserve

	// ACTUAL INFORMATION
	// Actual Age (AGE)
	AGE = document.hrprediction.age.value;

	// Measured Maximum Heart Rate (MMHR)
	MMHR = document.hrprediction.mmhr.value;

	// Actual Resting Heart Rate (RHR)
	RHR = document.hrprediction.rhr.value;

	// Predict MHR
	if(document.hrprediction.sex.value == "male")
		MHR = Math.round(205 - (0.5 * AGE));
	if(document.hrprediction.sex.value == "female")
		MHR = Math.round(211 - (0.5 * AGE));
	if(MMHR > "0") MHR = MMHR;
	if(MMHR == "") MMHR = MHR;

	document.hrprediction.mmhr.value = MMHR;

	// Predict Heart Rate Reserve (HRR)
	HRR = (MHR - RHR);

//	document.hrprediction.hrr.value = HRR;

	// CALCULATE VALUES FOR TABLE
	// Zone 1
	MIN1 = document.hrprediction.min1.value;
	MAX1 = document.hrprediction.max1.value;

	MINHR1 = Math.round((MIN1 / 100) * (HRR * 1) + (RHR * 1));
	MAXHR1 = Math.round((MAX1 / 100) * (HRR * 1) + (RHR * 1));

	document.hrprediction.minhr1.value = MINHR1;
	document.hrprediction.maxhr1.value = MAXHR1;

	}

function clearall()
	{
	document.hrprediction.age.value = "";
	document.hrprediction.mmhr.value = "";
	document.hrprediction.rhr.value = "55";
	document.hrprediction.min1.value = "70";
	document.hrprediction.max1.value = "80";
	document.hrprediction.minhr1.value = "";
	document.hrprediction.maxhr1.value = "";
	document.hrprediction.age.focus();
	}




// End hiding script from older browsers -->
