<!-- Begin of JavaScript code; this script 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/walkhlp.htm','hlpWin','width=580,height=330')
	}
	
function leading(A)
	{
	if(A < 10)
		A = '0'+A;
	return A;
	}

function walkcalc() {

	foundError = false;
		if(document.walkpredict.rd.value == "")    {
		alert("\nPlease enter a valid Race Distance.");
		foundError = true;
		document.walkpredict.rd.focus();
		return false;
		}

	foundError = false;
		if((document.walkpredict.rth.value == "") && (document.walkpredict.rtm.value == "") && (document.walkpredict.rts.value == ""))    {
		alert("\nPlease enter a planned finish time.");
		foundError = true;
		document.walkpredict.rth.focus();
		return false;
		}
	else {
		if(document.walkpredict.rth.value == "") document.walkpredict.rth.value = 0;
		if(document.walkpredict.rtm.value == "") document.walkpredict.rtm.value = "00";
		if(document.walkpredict.rts.value == "") document.walkpredict.rts.value = "00";
	  	}

	//INFORMATION REQUEST
	//Race Details
	//Race Name (RN)
	RN = document.walkpredict.rn.value;

	//Race Date (RDATE)
	RDATE = document.walkpredict.rdate.value;

	//Race Distance (RD)
	RD = document.walkpredict.rd.value;

	//Race Time (RT)
	RTH = document.walkpredict.rth.value;
	RTM = document.walkpredict.rtm.value;
	RTS = document.walkpredict.rts.value;

	RT = ((RTH * 3600) + (RTM * 60) + (RTS * 1))

	//Race Pace (RP)
	RP = (RT / RD);
		RPH = Math.floor(RP / 3600);
		RPM = Math.floor((RP - (RPH * 3600)) / 60);
		RPS = Math.floor(RP - (RPH * 3600) - (RPM * 60));

	document.walkpredict.rpm.value = leading(RPM);
	document.walkpredict.rps.value = leading(RPS);

	//Walking Information
	//Walking Interval (WI)
	WI = document.walkpredict.wi.value;

	//Number of Walks (WN)
	WN = Math.round((RD / WI) - 1);

	document.walkpredict.wn.value = WN;

	//Walking Time (WT)

	WTM = document.walkpredict.wtm.value;
	WTS = document.walkpredict.wts.value;

	WT = ((WTM * 60) + (WTS * 1));

	//Total Walking Time (TWT)
	TWT = (WN * WT);
		TWTH = Math.floor(TWT / 3600);
		TWTM = Math.floor((TWT - (TWTH * 3600)) / 60);
		TWTS = Math.floor(TWT - (TWTH * 3600) - (TWTM * 60));

	document.walkpredict.twth.value = TWTH;
	document.walkpredict.twtm.value = leading(TWTM);
	document.walkpredict.twts.value = leading(TWTS);

	//Walking Speed (WS)
	WS = document.walkpredict.ws.value;

	//Walking Distance (WD)
	WD = Math.floor(((WS / 3600) * WT) * 1000) / 1000;

	document.walkpredict.wd.value = WD;
	
	//Total Walking Distance (TWD)
	TWD = WN * WD;
	document.walkpredict.twd.value = TWD;

	//Revised Walking Interval (RWI)
	RWI = Math.round(((RD - TWD) / (WN + 1) * 10)) / 10;

	//Revised Race Time (RRT)
	RRT = RT - TWT;

	//Revised Race Distance (RRD)
	RRD = RD - TWD;

	//Revised Race Pace (RRP)
	RRP = RRT / RRD;
		RRPH = Math.floor(RRP / 3600);
		RRPM = Math.floor((RRP - (RRPH * 3600)) / 60);
		RRPS = Math.floor(RRP - (RRPH * 3600) - (RRPM * 60));

	document.walkpredict.rrpm.value = leading(RRPM);
	document.walkpredict.rrps.value = leading(RRPS);

	//Start Interval Distance (SID)
	SID = RWI;

	document.walkpredict.sid.value = SID;

	//Start Interval Time (SIT)
	SIT = RWI * RRP;
		SITH = Math.floor(SIT / 3600);
		SITM = Math.floor((SIT - (SITH * 3600)) / 60);
		SITS = Math.floor(SIT - (SITH * 3600) - (SITM * 60));

	document.walkpredict.sith.value = SITH;
	document.walkpredict.sitm.value = leading(SITM);
	document.walkpredict.sits.value = leading(SITS);

	//Start Interval Walking Time (SIWT)
	SIWT = WT;
		SIWTH = Math.floor(SIWT / 3600);
		SIWTM = Math.floor((SIWT - (SIWTH * 3600)) / 60);
		SIWTS = Math.floor(SIWT - (SIWTH * 3600) - (SIWTM * 60));

	document.walkpredict.siwth.value = SIWTH;
	document.walkpredict.siwtm.value = leading(SIWTM);
	document.walkpredict.siwts.value = leading(SIWTS);

	//Final Interval Distance (FID)
	FID = Math.round((RD - TWD - (WN * RWI)) * 1000) / 1000;

	document.walkpredict.fid.value = FID;

	//Final Interval Time (FIT)
	FIT = FID * RRP;
		FITH = Math.floor(FIT / 3600);
		FITM = Math.floor((FIT - (FITH * 3600)) / 60);
		FITS = Math.floor(FIT - (FITH * 3600) - (FITM * 60));

	document.walkpredict.fith.value = FITH;
	document.walkpredict.fitm.value = leading(FITM);
	document.walkpredict.fits.value = leading(FITS);
}

// End of JavaScript -->

