<!-- 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/gearhlp.htm','hlpWin','width=580,height=300')
	}

function setWheelOption()
	{
	document.gearratio.wheelsize.value = "Custom";
	}

function setWheel()
	{
	WC = Math.round(document.gearratio.wheelsize.value * 25.4 * 22 / 7);
	
	document.gearratio.wc.value = WC;
	}
	
function gearcalc() {

	foundError = false;
		if(document.gearratio.wc.value == "") {
		alert("\nPlease enter any reasonable circumference value.");
		foundError = true;
		document.gearratio.wc.focus();
		return false;
		}
	
	foundError = false;
		if(document.gearratio.cad.value == "") {
		alert("\nPlease enter your actual/planned cadence in rpm.");
		foundError = true;
		document.gearratio.cad.focus();
		return false;
		}
	
	foundError = false;
		if((document.gearratio.cr1.value == "") && (document.gearratio.cr2.value == "") && (document.gearratio.cr3.value == "")) {
		alert("\nPlease enter at least one chainring size.");
		foundError = true;
		document.gearratio.cr1.focus();
		return false;
		}
	
	foundError = false;
		if((document.gearratio.spr1.value == "") && (document.gearratio.spr2.value == "") && (document.gearratio.spr3.value == "") && (document.gearratio.spr4.value == "") && (document.gearratio.spr5.value == "") && (document.gearratio.spr6.value == "") && (document.gearratio.spr7.value == "") && (document.gearratio.spr8.value == "") && (document.gearratio.spr9.value == "")) {
		alert("\nPlease enter at least one one sprocket size.");
		foundError = true;
		document.gearratio.spr1.focus();
		return false;
		}

	// ACTUAL INFORMATION
	// Actual Wheel Circumference (WC)
	WC = document.gearratio.wc.value;

	// Preferred Cadence (CAD)
	CAD = document.gearratio.cad.value;

	// Chainring Values (CR)
	CR1 = document.gearratio.cr1.value;
	if(CR1 == "") document.gearratio.cr1.value = "-";

	CR2 = document.gearratio.cr2.value;
	if(CR2 == "") document.gearratio.cr2.value = "-";
		
	CR3 = document.gearratio.cr3.value;
	if(CR3 == "") document.gearratio.cr3.value = "-";
	
	// Sprocket Information (SP)
	SPR1 = document.gearratio.spr1.value;
	if(SPR1 == "") document.gearratio.spr1.value = "-";
	
	SPR2 = document.gearratio.spr2.value;
	if(SPR2 == "") document.gearratio.spr2.value = "-";

	SPR3 = document.gearratio.spr3.value;
	if(SPR3 == "") document.gearratio.spr3.value = "-";

	SPR4 = document.gearratio.spr4.value;
	if(SPR4 == "") document.gearratio.spr4.value = "-";

	SPR5 = document.gearratio.spr5.value;
	if(SPR5 == "") document.gearratio.spr5.value = "-";

	SPR6 = document.gearratio.spr6.value;
	if(SPR6 == "") document.gearratio.spr6.value = "-"

	SPR7 = document.gearratio.spr7.value;
	if(SPR7 == "") document.gearratio.spr7.value = "-"

	SPR8 = document.gearratio.spr8.value;
	if(SPR8 == "") document.gearratio.spr8.value = "-"

	SPR9 = document.gearratio.spr9.value;
	if(SPR9 == "") document.gearratio.spr9.value = "-"
	
	// Chainring Sprocket Calculation (GR)
	// Gear Ratio (GR)
	// Gear Speed (GS) = GR * WC * CAD * 60 / 1000
	if(((CR1 == "") || (SPR1 == "")) || ((CR1 == "-") || (SPR1 == "-")))  {
		GR1_1 = "-";
		GS1_1 = "-";
		}
	else{	
		GR1_1 = Math.round((CR1 / SPR1) * 100) / 100;
		GS1_1 = Math.round(((GR1_1 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_1.value = GR1_1;
	document.ratiotable.gs1_1.value = GS1_1;
	
	if(((CR1 == "") || (SPR2 == "")) || ((CR1 == "-") || (SPR2 == "-")))  {
		GR1_2 = "-";
		GS1_2 = "-";
		}
	else{	
		GR1_2 = Math.round((CR1 / SPR2) * 100) / 100;
		GS1_2 = Math.round(((GR1_2 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_2.value = GR1_2;
	document.ratiotable.gs1_2.value = GS1_2;

	if(((CR1 == "") || (SPR3 == "")) || ((CR1 == "-") || (SPR3 == "-")))  {
		GR1_3 = "-";
		GS1_3 = "-";
		}
	else{	
		GR1_3 = Math.round((CR1 / SPR3) * 100) / 100;
		GS1_3 = Math.round(((GR1_3 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_3.value = GR1_3;
	document.ratiotable.gs1_3.value = GS1_3;

	if(((CR1 == "") || (SPR4 == "")) || ((CR1 == "-") || (SPR4 == "-")))  {
		GR1_4 = "-";
		GS1_4 = "-";
		}
	else{	
		GR1_4 = Math.round((CR1 / SPR4) * 100) / 100;
		GS1_4 = Math.round(((GR1_4 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_4.value = GR1_4;
	document.ratiotable.gs1_4.value = GS1_4;

	if(((CR1 == "") || (SPR5 == "")) || ((CR1 == "-") || (SPR5 == "-")))  {
		GR1_5 = "-";
		GS1_5 = "-";
		}
	else{	
		GR1_5 = Math.round((CR1 / SPR5) * 100) / 100;
		GS1_5 = Math.round(((GR1_5 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_5.value = GR1_5;
	document.ratiotable.gs1_5.value = GS1_5;

	if(((CR1 == "") || (SPR6 == "")) || ((CR1 == "-") || (SPR6 == "-")))  {
		GR1_6 = "-";
		GS1_6 = "-";
		}
	else{	
		GR1_6 = Math.round((CR1 / SPR6) * 100) / 100;
		GS1_6 = Math.round(((GR1_6 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_6.value = GR1_6;
	document.ratiotable.gs1_6.value = GS1_6;

	if(((CR1 == "") || (SPR7 == "")) || ((CR1 == "-") || (SPR7 == "-")))  {
		GR1_7 = "-";
		GS1_7 = "-";
		}
	else{	
		GR1_7 = Math.round((CR1 / SPR7) * 100) / 100;
		GS1_7 = Math.round(((GR1_7 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_7.value = GR1_7;
	document.ratiotable.gs1_7.value = GS1_7;

	if(((CR1 == "") || (SPR8 == "")) || ((CR1 == "-") || (SPR8 == "-")))  {
		GR1_8 = "-";
		GS1_8 = "-";
		}
	else{	
		GR1_8 = Math.round((CR1 / SPR8) * 100) / 100;
		GS1_8 = Math.round(((GR1_8 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_8.value = GR1_8;
	document.ratiotable.gs1_8.value = GS1_8;

	if(((CR1 == "") || (SPR9 == "")) || ((CR1 == "-") || (SPR9 == "-")))  {
		GR1_9 = "-";
		GS1_9 = "-";
		}
	else{	
		GR1_9 = Math.round((CR1 / SPR9) * 100) / 100;
		GS1_9 = Math.round(((GR1_9 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr1_9.value = GR1_9;
	document.ratiotable.gs1_9.value = GS1_9;

	if(((CR2 == "") || (SPR1 == "")) || ((CR2 == "-") || (SPR1 == "-")))  {
		GR2_1 = "-";
		GS2_1 = "-";
		}
	else{	
		GR2_1 = Math.round((CR2 / SPR1) * 100) / 100;
		GS2_1 = Math.round(((GR2_1 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_1.value = GR2_1;
	document.ratiotable.gs2_1.value = GS2_1;
	
	if(((CR2 == "") || (SPR2 == "")) || ((CR2 == "-") || (SPR2 == "-")))  {
		GR2_2 = "-";
		GS2_2 = "-";
		}
	else{	
		GR2_2 = Math.round((CR2 / SPR2) * 100) / 100;
		GS2_2 = Math.round(((GR2_2 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_2.value = GR2_2;
	document.ratiotable.gs2_2.value = GS2_2;

	if(((CR2 == "") || (SPR3 == "")) || ((CR2 == "-") || (SPR3 == "-")))  {
		GR2_3 = "-";
		GS2_3 = "-";
		}
	else{	
		GR2_3 = Math.round((CR2 / SPR3) * 100) / 100;
		GS2_3 = Math.round(((GR2_3 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_3.value = GR2_3;
	document.ratiotable.gs2_3.value = GS2_3;

	if(((CR2 == "") || (SPR4 == "")) || ((CR2 == "-") || (SPR4 == "-")))  {
		GR2_4 = "-";
		GS2_4 = "-";
		}
	else{	
		GR2_4 = Math.round((CR2 / SPR4) * 100) / 100;
		GS2_4 = Math.round(((GR2_4 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_4.value = GR2_4;
	document.ratiotable.gs2_4.value = GS2_4;

	if(((CR2 == "") || (SPR5 == "")) || ((CR2 == "-") || (SPR5 == "-")))  {
		GR2_5 = "-";
		GS2_5 = "-";
		}
	else{	
		GR2_5 = Math.round((CR2 / SPR5) * 100) / 100;
		GS2_5 = Math.round(((GR2_5 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_5.value = GR2_5;
	document.ratiotable.gs2_5.value = GS2_5;

	if(((CR2 == "") || (SPR6 == "")) || ((CR2 == "-") || (SPR6 == "-")))  {
		GR2_6 = "-";
		GS2_6 = "-";
		}
	else{	
		GR2_6 = Math.round((CR2 / SPR6) * 100) / 100;
		GS2_6 = Math.round(((GR2_6 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_6.value = GR2_6;
	document.ratiotable.gs2_6.value = GS2_6;

	if(((CR2 == "") || (SPR7 == "")) || ((CR2 == "-") || (SPR7 == "-")))  {
		GR2_7 = "-";
		GS2_7 = "-";
		}
	else{	
		GR2_7 = Math.round((CR2 / SPR7) * 100) / 100;
		GS2_7 = Math.round(((GR2_7 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_7.value = GR2_7;
	document.ratiotable.gs2_7.value = GS2_7;

	if(((CR2 == "") || (SPR8 == "")) || ((CR2 == "-") || (SPR8 == "-")))  {
		GR2_8 = "-";
		GS2_8 = "-";
		}
	else{	
		GR2_8 = Math.round((CR2 / SPR8) * 100) / 100;
		GS2_8 = Math.round(((GR2_8 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_8.value = GR2_8;
	document.ratiotable.gs2_8.value = GS2_8;

	if(((CR2 == "") || (SPR9 == "")) || ((CR2 == "-") || (SPR9 == "-")))  {
		GR2_9 = "-";
		GS2_9 = "-";
		}
	else{	
		GR2_9 = Math.round((CR2 / SPR9) * 100) / 100;
		GS2_9 = Math.round(((GR2_9 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr2_9.value = GR2_9;
	document.ratiotable.gs2_9.value = GS2_9;

	if(((CR3 == "") || (SPR1 == "")) || ((CR3 == "-") || (SPR1 == "-")))  {
		GR3_1 = "-";
		GS3_1 = "-";
		}
	else{	
		GR3_1 = Math.round((CR3 / SPR1) * 100) / 100;
		GS3_1 = Math.round(((GR3_1 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_1.value = GR3_1;
	document.ratiotable.gs3_1.value = GS3_1;
	
	if(((CR3 == "") || (SPR2 == "")) || ((CR3 == "-") || (SPR2 == "-")))  {
		GR3_2 = "-";
		GS3_2 = "-";
		}
	else{	
		GR3_2 = Math.round((CR3 / SPR2) * 100) / 100;
		GS3_2 = Math.round(((GR3_2 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_2.value = GR3_2;
	document.ratiotable.gs3_2.value = GS3_2;

	if(((CR3 == "") || (SPR3 == "")) || ((CR3 == "-") || (SPR3 == "-")))  {
		GR3_3 = "-";
		GS3_3 = "-";
		}
	else{	
		GR3_3 = Math.round((CR3 / SPR3) * 100) / 100;
		GS3_3 = Math.round(((GR3_3 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_3.value = GR3_3;
	document.ratiotable.gs3_3.value = GS3_3;

	if(((CR3 == "") || (SPR4 == "")) || ((CR3 == "-") || (SPR4 == "-")))  {
		GR3_4 = "-";
		GS3_4 = "-";
		}
	else{	
		GR3_4 = Math.round((CR3 / SPR4) * 100) / 100;
		GS3_4 = Math.round(((GR3_4 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_4.value = GR3_4;
	document.ratiotable.gs3_4.value = GS3_4;

	if(((CR3 == "") || (SPR5 == "")) || ((CR3 == "-") || (SPR5 == "-")))  {
		GR3_5 = "-";
		GS3_5 = "-";
		}
	else{	
		GR3_5 = Math.round((CR3 / SPR5) * 100) / 100;
		GS3_5 = Math.round(((GR3_5 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_5.value = GR3_5;
	document.ratiotable.gs3_5.value = GS3_5;

	if(((CR3 == "") || (SPR6 == "")) || ((CR3 == "-") || (SPR6 == "-")))  {
		GR3_6 = "-";
		GS3_6 = "-";
		}
	else{	
		GR3_6 = Math.round((CR3 / SPR6) * 100) / 100;
		GS3_6 = Math.round(((GR3_6 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_6.value = GR3_6;
	document.ratiotable.gs3_6.value = GS3_6;

	if(((CR3 == "") || (SPR7 == "")) || ((CR3 == "-") || (SPR7 == "-")))  {
		GR3_7 = "-";
		GS3_7 = "-";
		}
	else{	
		GR3_7 = Math.round((CR3 / SPR7) * 100) / 100;
		GS3_7 = Math.round(((GR3_7 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_7.value = GR3_7;
	document.ratiotable.gs3_7.value = GS3_7;

	if(((CR3 == "") || (SPR8 == "")) || ((CR3 == "-") || (SPR8 == "-")))  {
		GR3_8 = "-";
		GS3_8 = "-";
		}
	else{	
		GR3_8 = Math.round((CR3 / SPR8) * 100) / 100;
		GS3_8 = Math.round(((GR3_8 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_8.value = GR3_8;
	document.ratiotable.gs3_8.value = GS3_8;

	if(((CR3 == "") || (SPR9 == "")) || ((CR3 == "-") || (SPR9 == "-")))  {
		GR3_9 = "-";
		GS3_9 = "-";
		}
	else{	
		GR3_9 = Math.round((CR3 / SPR9) * 100) / 100;
		GS3_9 = Math.round(((GR3_9 * (WC / 1000) * CAD * 60) / 1000) * 10) / 10;
		}
	
	document.ratiotable.gr3_9.value = GR3_9;
	document.ratiotable.gs3_9.value = GS3_9;

	}


function clearall() {

	document.gearratio.wheelsize.value = "Custom";
	document.gearratio.wc.value = "";
	document.gearratio.cad.value = "90";
	document.gearratio.cr1.value = "";
	document.gearratio.cr2.value = "";
	document.gearratio.cr3.value = "";
	document.gearratio.spr1.value = "";
	document.gearratio.spr2.value = "";
	document.gearratio.spr3.value = "";
	document.gearratio.spr4.value = "";
	document.gearratio.spr5.value = "";
	document.gearratio.spr6.value = "";
	document.gearratio.spr7.value = "";
	document.gearratio.spr8.value = "";
	document.gearratio.spr9.value = "";
	document.ratiotable.gr1_1.value = "";
	document.ratiotable.gs1_1.value = "";
	document.ratiotable.gr1_2.value = "";
	document.ratiotable.gs1_2.value = "";
	document.ratiotable.gr1_3.value = "";
	document.ratiotable.gs1_3.value = "";
	document.ratiotable.gr1_4.value = "";
	document.ratiotable.gs1_4.value = "";
	document.ratiotable.gr1_5.value = "";
	document.ratiotable.gs1_5.value = "";
	document.ratiotable.gr1_6.value = "";
	document.ratiotable.gs1_6.value = "";
	document.ratiotable.gr1_7.value = "";
	document.ratiotable.gs1_7.value = "";
	document.ratiotable.gr1_8.value = "";
	document.ratiotable.gs1_8.value = "";
	document.ratiotable.gr1_9.value = "";
	document.ratiotable.gs1_9.value = "";
	document.ratiotable.gr2_1.value = "";
	document.ratiotable.gs2_1.value = "";
	document.ratiotable.gr2_2.value = "";
	document.ratiotable.gs2_2.value = "";
	document.ratiotable.gr2_3.value = "";
	document.ratiotable.gs2_3.value = "";
	document.ratiotable.gr2_4.value = "";
	document.ratiotable.gs2_4.value = "";
	document.ratiotable.gr2_5.value = "";
	document.ratiotable.gs2_5.value = "";
	document.ratiotable.gr2_6.value = "";
	document.ratiotable.gs2_6.value = "";
	document.ratiotable.gr2_7.value = "";
	document.ratiotable.gs2_7.value = "";
	document.ratiotable.gr2_8.value = "";
	document.ratiotable.gs2_8.value = "";
	document.ratiotable.gr2_9.value = "";
	document.ratiotable.gs2_9.value = "";
	document.ratiotable.gr3_1.value = "";
	document.ratiotable.gs3_1.value = "";
	document.ratiotable.gr3_2.value = "";
	document.ratiotable.gs3_2.value = "";
	document.ratiotable.gr3_3.value = "";
	document.ratiotable.gs3_3.value = "";
	document.ratiotable.gr3_4.value = "";
	document.ratiotable.gs3_4.value = "";
	document.ratiotable.gr3_5.value = "";
	document.ratiotable.gs3_5.value = "";
	document.ratiotable.gr3_6.value = "";
	document.ratiotable.gs3_6.value = "";
	document.ratiotable.gr3_7.value = "";
	document.ratiotable.gs3_7.value = "";
	document.ratiotable.gr3_8.value = "";
	document.ratiotable.gs3_8.value = "";
	document.ratiotable.gr3_9.value = "";
	document.ratiotable.gs3_9.value = "";
	document.gearratio.wc.focus();

	}

// End of JavaScript code -->	
