Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************
- The below JavaScript bike calcs are the intellectual propery and
- copyright of Roy Walter (walt_at_brookhouse_dot_co_dot_uk).
- Nothing below is rocket science but if you rip it off without
- acknowledgement your are either lazy, stupid or both.
- If you like something enough to use it in your own work
- you can always show your appreciation
- by making a PayPal donation to the email above.
- �Copyright 2008 Roy Walter. All rights reserved.
- ********************/
- function calcGearSize(mode) {
- var w = document.gearing.wheelsize.value;
- var f=document.gearing.front.value;
- var r=document.gearing.rear.value;
- if (!showError(0))
- return;
- rarr = r.split(',');
- if (rarr.length > 1) {
- calcGearSizeMulti(f,r,mode);
- return;
- }
- if (w==0)
- w = document.gearing.wheelother.value;
- var sz=(w*f)/r;
- sz = Math.round(sz*Math.pow(10,2))/Math.pow(10,2);
- document.gearing.out1.value=sz;
- }
- function calcGearSizeMulti(f,r,mode) {
- /* mode 0 means just show gear ratios
- mode 1 means show speed or cadence */
- var counter=0;
- var gears = new Array();
- if (document.gearing.wheelsize.value==0)
- var w = document.gearing.wheelother.value;
- else
- var w = document.gearing.wheelsize.value;
- farr = f.split(',');
- rarr = r.split(',');
- farr = farr.sort(sortNumbers);
- rarr = rarr.sort(sortNumbers);
- var t = "";
- t = "<html><head>";
- t = t+"<meta http-equiv=\"Content-Type\" content=\"application/xls\">";
- t = t+"<title>My Gear Table</title></head><style>td {font-family:Verdana;font-size:11px;/*width:50px;*/text-align:center;}a:hover{text-decoration:none;}</style><body>";
- t = t + "<table border=1 cellpadding=5 cellspacing=1 align=center style=\"margin-top:50\">";
- t = t + "<tr><td align=center colspan="+(rarr.length+1)+"><strong>Gear Table</strong><br>";
- if (mode==1) {
- if (document.gearing.mode.value=='rpm')
- t = t + "gear size in inches plus <font color=red>speeds</font> attained at "+document.gearing.param.value+" rpm";
- else
- t = t + "gear size in inches plus <font color=red>cadence</font> required to achieve "+document.gearing.param.value+" "+document.gearing.mode.value+")";
- } else {
- t = t + "gear size in inches";
- }
- t = t + "</td></tr>";
- t = t + "<tr><td> </td>";
- for (var n=0;n<rarr.length;n++)
- t = t+"<td bgcolor=\"CCFF66\" align=center>"+rarr[n]+"</td>";
- t = t+"</tr>";
- for (var i=0;i<farr.length;i++) {
- t = t + "<tr><td bgcolor=\"CCFF66\" width=30>"+farr[i]+"</td>";
- for (var n=0;n<rarr.length;n++) {
- counter++;
- g = (w*farr[i])/rarr[n];
- g = Math.round(g*Math.pow(10,1))/Math.pow(10,1);
- if (mode==0) {
- t = t+"<td>"+g+"</td>";
- } else {
- if (document.gearing.mode.value=='rpm')
- t = t+"<td>"+g+"<br>"+calcSpeed(g)+"</td>";
- else
- t = t+"<td>"+g+"<br><font color=red>"+calcCadence(g)+"</font></td>";
- }
- }
- t = t + "</tr>";
- }
- /*
- t = t + "<tr><td style=\"text-align:left; font-size:9px\" colspan="+(rarr.length+1)+">To download in Excel format choose File - Save As... from the menu and replace the suggested ";
- t = t + ".htm file extension with .xls, i.e. bikecalc.htm becomes bikecalc.xls.</td></tr>";
- */
- t = t + "</table>";
- // t = t + "<p align=center style=\"font-family: Verdana;font-size:10px;\"><a href=# onclick=\"window.open('aboutxls.htm','','height=200,width=200');\">about saving in Excel format</a></p>";
- t = t + "</body></html>";
- document.gearing.out1.value = "";
- document.gearing.out2.value = "";
- hwnd = window.open("geartable.xls","geartable");
- hwnd.document.write(t);
- hwnd.document.close();
- }
- function calcSpeed(g) {
- g = g*3.141;
- var vm = ((g*document.gearing.param.value)*60)/63360;
- vm = Math.round(vm*Math.pow(10,1))/Math.pow(10,1);
- vk = vm*1.6;
- vk = Math.round(vk*Math.pow(10,1))/Math.pow(10,1);
- document.gearing.out2.value = vm+" mph/"+vk+" kph";
- return "<font color=red><strong>"+vm+" mph</strong><br>"+vk+" kph</font>";
- }
- function calcCadence(g) {
- /*
- var g = document.gearing.out1.value;
- */
- var v = document.gearing.param.value;
- mode = document.gearing.mode.value;
- if (mode=='mph')
- v = 63360*v; // inches per hour
- else
- v = 39600*v;
- v = v/60; // inches per minute
- c = (v/g)/3.141;
- c = Math.round(c*Math.pow(10,1))/Math.pow(10,1);
- document.gearing.out2.value = c+" rpm";
- return c;
- }
- function calcWhat(mode) {
- if (!showError(1))
- return;
- calcGearSize(mode);
- if (document.gearing.mode.value=='rpm')
- calcSpeed(document.gearing.out1.value);
- else
- calcCadence(document.gearing.out1.value);
- }
- function sortNumbers(a,b) {
- return a-b;
- }
- function mailme() {
- var arr = new Array();
- arr[0] = "mailto:";
- arr[1] = '@';
- var addr = arr[0]+"garliestonhouse"+arr[1]+"yahoo.co.uk";
- window.location = addr;
- }
- function switchLabel(mode) {
- el = document.getElementById('label1');
- switch (mode) {
- case 'rpm':
- el.innerHTML = "calculate speed";
- break;
- default:
- el.innerHTML = "calculate cadence";
- }
- document.gearing.param.value='';
- document.gearing.out2.value='';
- }
- function makeWhite(f) {
- document.gearing[f.name].style.backgroundColor='white';
- }
- function showError(n) {
- bOK = true;
- if (!document.gearing.front.value) {
- bOK = false;
- document.gearing.front.style.backgroundColor = 'pink';
- }
- if (!document.gearing.rear.value) {
- bOK = false;
- document.gearing.rear.style.backgroundColor = 'pink';
- }
- if (n==1) {
- if (!document.gearing.param.value) {
- bOK = false;
- document.gearing.param.style.backgroundColor = 'pink';
- }
- } else {
- document.gearing.param.style.backgroundColor = 'white';
- }
- if (!bOK) {
- alert('You must enter a value in the red box(es).');
- }
- return bOK;
- }
- function resetForm() {
- el = document.getElementById('label1');
- el.innerHTML = 'calculate speed';
- document.gearing.front.style.backgroundColor='white';
- document.gearing.rear.style.backgroundColor='white';
- document.gearing.param.style.backgroundColor='white';
- document.gearing.reset();
- }
- function showMe(f,v) {
- document.gearing[f].value = v;
- }
- function sendMail() {
- var at = "@";
- window.location = "mailto:garliestonhouse"+at+"yahoo.co.uk?subject=Performance calculators";
- }
Advertisement
Add Comment
Please, Sign In to add comment