// This function creates the options in the list
function Object(value) {
        this.value=value;
 
}

//////////////////////////////////////////////////////
// This part is what will be dynamic:

// This array will hold the tire cross-section values
var sectarray = new Array();
sectarray[0] = new Object("175");
sectarray[1] = new Object("185");
sectarray[2] = new Object("195");
sectarray[3] = new Object("205");
sectarray[4] = new Object("215");
sectarray[5] = new Object("225");
sectarray[6] = new Object("235");
sectarray[7] = new Object("245");
sectarray[8] = new Object("255");
sectarray[9] = new Object("265");
sectarray[10] = new Object("275");
sectarray[11] = new Object("285");
sectarray[12] = new Object("295");
sectarray[13] = new Object("305");
sectarray[14] = new Object("315");
sectarray[15] = new Object("325");
sectarray[16] = new Object("335");
sectarray[17] = new Object("345");

// This array will hold the tire cross-section values
var aspectarray = new Array();
aspectarray[0] = new Object("30");
aspectarray[1] = new Object("35");
aspectarray[2] = new Object("40");
aspectarray[3] = new Object("45");
aspectarray[4] = new Object("50");
aspectarray[5] = new Object("55");
aspectarray[6] = new Object("60");
aspectarray[7] = new Object("65");
aspectarray[8] = new Object("70");
aspectarray[9] = new Object("75");

// This array will hold the wheel diameter values
var wheelarray = new Array();
wheelarray[0] = new Object("13");
wheelarray[1] = new Object("14");
wheelarray[2] = new Object("15");
wheelarray[3] = new Object("16");
wheelarray[4] = new Object("17");
wheelarray[5] = new Object("18");
wheelarray[6] = new Object("19");
wheelarray[7] = new Object("20");
wheelarray[8] = new Object("21");
wheelarray[9] = new Object("22");
wheelarray[10] = new Object("23");
wheelarray[11] = new Object("24");


//
//////////////////////////////////////////////////////

// Functions to write options into HTML list.
function writeList1() {
 for(var i=0;i<sectarray.length;i++) {
	if (sectarray[i].value == "205") {
	   document.write("<OPTION SELECTED Value=\""+sectarray[i].value+"\">"+sectarray[i].value+"</OPTION>");
	}
	else {
	   document.write("<OPTION Value=\""+sectarray[i].value+"\">"+sectarray[i].value+"</OPTION>");
	}
 }
}

function writeList2() {
 for(var i=0;i<aspectarray.length;i++) {
	if (aspectarray[i].value == "50") {
	   document.write("<OPTION SELECTED Value=\""+aspectarray[i].value+"\">"+aspectarray[i].value+"</OPTION>");
	}
	else {
	   document.write("<OPTION Value=\""+aspectarray[i].value+"\">"+aspectarray[i].value+"</OPTION>");
	}
 }
}

function writeList3() {
 for(var i=0;i<wheelarray.length;i++) {
	if (wheelarray[i].value == "15") {
	   document.write("<OPTION SELECTED Value=\""+wheelarray[i].value+"\">"+wheelarray[i].value+"</OPTION>");
	}
	else {
	   document.write("<OPTION Value=\""+wheelarray[i].value+"\">"+wheelarray[i].value+"</OPTION>");
	}
 }
}

function calcnow(form) {
        var dia=0.5, revpermi=0.5, factor=0.5, sect=0.5, aspect=0.5, wheel=0.5;
        var idx1=document.calc1.sect.selectedIndex;
        sect=sectarray[idx1].value;
        idx1=document.calc2.aspect.selectedIndex;
        aspect=aspectarray[idx1].value;
        idx1=document.calc3.wheel.selectedIndex;
        wheel=wheelarray[idx1].value;
        var sectUS = (sect/25.4)
        var factor = (aspect/50)
        dia = (sectUS * factor);
        for(var i=0;i<wheel;i++) {
             dia++;
 }
        revpermi = (20168.06723/dia);
	var rim = (sectUS * (Math.cos(Math.asin((sectUS * (aspect/100))/sectUS))))

// round the answers to appropriate decimals

	dia = dia * 100;
        dia = Math.round(dia);
	dia = dia / 100;
        sectUS = sectUS * 100;
        sectUS = Math.round(sectUS);
        sectUS = sectUS / 100;
        revpermi = Math.round(revpermi);
	rim = rim * 10;
        rim = Math.round(rim);
	var x = rim % 5
	if (x < 3) {
		rim = rim - x
	}
	else {
		rim = (rim + (5 - x))
	}
	rim = rim / 10;

// display the answers

        document.answer1.diameter.value = dia;
        document.answer2.width.value = sectUS;
        document.answer3.revmi.value = revpermi;
        document.answer4.rim.value = rim;
}

        function resetAnswers(form) {
        document.answer1.diameter.value = "";
        document.answer2.width.value = "";
        document.answer3.revmi.value = "";
        document.answer4.rim.value = "";
}

function openWin1() {
  myWin= open("", "displayWindow", 
    "width=500,height=200,status=no,toolbar=no,menubar=no");

  // open document for further output
  myWin.document.open();
  
  // create document
  myWin.document.write("<html><head><title>Note on Tire Diameter");
  myWin.document.write("</title></head><body bgcolor=\"#FFFFFF\">");
  myWin.document.write("<left><font size=3>");
  myWin.document.write("This width is calculated from the nominal dimensions you selected. ");
  myWin.document.write("The actual diameter of a tire varies depending on ");
  myWin.document.write("the tread depth. Competition tires can have as ");
  myWin.document.write("little as 6/32 \" of tread, while a snow ");
  myWin.document.write("tire will have considerably more. This can change the actual ");
  myWin.document.write("diameter by as much as 3/8\", or .125\".");
  myWin.document.write("<p>For precise information, consult the tire manufacturer's specs.");
  myWin.document.write("</font>");
  myWin.document.write("</body></html>");

  myWin.document.close();  
}


function openWin2() {
  myWin= open("", "displayWindow", 
    "width=500,height=220,status=no,toolbar=no,menubar=no");

  // open document for further output
  myWin.document.open();
  
  // create document
  myWin.document.write("<html><head><title>Note on Cross-Section Width");
  myWin.document.write("</title></head><body bgcolor=\"#FFFFFF\">");
  myWin.document.write("<left><font size=3>");
  myWin.document.write("This calculation is the straight inch equivalent of the section width you selected. ");
  myWin.document.write("The section width of a tire varies depending on ");
  myWin.document.write("the width of the wheel on which it is mounted. ");
  myWin.document.write("Tire manufacturers list a \"design rim width\" for ");
  myWin.document.write("each tire. This rim is used to determine the official section width. ");
  myWin.document.write("Most manufacturers say that the section width changes about ");
  myWin.document.write("2/10 inch for each 1/2 inch change from the design wheel width. ");
  myWin.document.write("<p>For precise information, consult the tire manufacturer's specs.");
  myWin.document.write("</font>");
  myWin.document.write("</body></html>");

  myWin.document.close();  
}


function openWin3() {
  myWin= open("", "displayWindow", 
    "width=500,height=180,status=no,toolbar=no,menubar=no");

  // open document for further output
  myWin.document.open();
  
  // create document
  myWin.document.write("<html><head><title>Note on Rim Width");
  myWin.document.write("</title></head><body bgcolor=\"#FFFFFF\">");
  myWin.document.write("<left><font size=3>");
  myWin.document.write("This approximate rim width is based on a rough calculation of tread width. ");
  myWin.document.write("The rule of thumb I have found useful is to have the rim width be ");
  myWin.document.write("approximately equal to the tread width of the tire. ");
  myWin.document.write("Tire manufacturers list a \"design rim width\" for ");
  myWin.document.write("each tire. They also list a range of acceptable rim widths. ");
  myWin.document.write("For precise information, consult the tire manufacturer's specs. ");
  myWin.document.write("Use this information as food for thought only.");
  myWin.document.write("</font>");
  myWin.document.write("</body></html>");

  myWin.document.close();  
}

function Calculate1 ( section1, profile1, diameter1 ) {
	rollingradius1=Math.round((((diameter1/2)*25.4)+(section1*(profile1/100)))*100)/100;
	circumference1=Math.round((rollingradius1*2*3.14159)*100)/100;
	document.wheelsizes.rollingradius1.value=rollingradius1;
	document.wheelsizes.circumference1.value=circumference1;
}
function Calculate2 ( section2, profile2, diameter2 ) {
	rollingradius2=Math.round((((diameter2/2)*25.4)+(section2*(profile2/100)))*100)/100;
	circumference2=Math.round((rollingradius2*2*3.14159)*100)/100;
	document.wheelsizes.rollingradius2.value=rollingradius2;
	document.wheelsizes.circumference2.value=circumference2;
}
function Difference ( circumference1, circumference2 ) {
	difference=Math.round((circumference2-circumference1)*100)/100;
	differencepercent=Math.round(((difference/circumference1)*100)*100)/100;
	realspeed=Math.round((((differencepercent/100)*70)+70)*100)/100;
	document.wheelsizes.difference.value=difference;
	document.wheelsizes.differencepercent.value=differencepercent;
	document.wheelsizes.realspeed.value=Math.round((realspeed*1.6));
}
