function calcRec() {
	if(document.form1.theRunnerWidth.value == "") {
		alert("Please enter a width measurement!")
		document.form1.theRunnerWidth.focus()
		return false
	}
	if(document.form1.theRunnerHeight.value == "") {
		alert("Please enter a height measurement!")
		document.form1.theRunnerHeight.focus()
		return false
	}
	theWidth = document.form1.theRunnerWidth.value
	theHeight = document.form1.theRunnerHeight.value
	theArea = theWidth * theHeight
	theArea = parseInt(theArea * 100) / 100
	document.form1.area.value = theArea
}

function calcTrap() {
	if(document.form4.width1.value == "") {
		alert("Please enter a \"Width1\" measurement!")
		document.form4.width1.focus()
		return false
	}
	if(document.form4.width2.value == "") {
		alert("Please enter a \"Width2\" measurement!")
		document.form4.width2.focus()
		return false
	}
	if(document.form4.runnerHeight.value == "") {
		alert("Please enter a height measurement!")
		document.form4.runnerHeight.focus()
		return false
	}
	theWidth = (parseFloat(document.form4.width1.value) + parseFloat(document.form4.width2.value)) / 2
	theHeight = document.form4.runnerHeight.value
	theArea = theWidth * theHeight
	theArea = parseInt(theArea * 100) / 100
	document.form4.area.value = theArea
}

function calcCircle() {
	if(document.form2.diameter.value == "") {
		alert("Please enter a diameter measurement!")
		document.form2.diameter.focus()
		return false
	}
	theDiameter = document.form2.diameter.value
	theArea = Math.pow(theDiameter / 2, 2) * Math.PI
	theArea = parseInt(theArea * 100) / 100
	document.form2.area.value = theArea
}

function calcOval() {
	if(document.form3.diameter1.value == "") {
		alert("Please enter a \"Diameter1\" measurement!")
		document.form3.diameter1.focus()
		return false
	}
	if(document.form3.diameter2.value == "") {
		alert("Please enter a \"Diameter2\" measurement!")
		document.form3.diameter2.focus()
		return false
	}
	theDiameter1 = document.form3.diameter1.value
	theDiameter2 = document.form3.diameter2.value
	theDiameter = (parseFloat(theDiameter1) + parseFloat(theDiameter2)) / 2
	theArea = Math.pow(theDiameter / 2, 2) * Math.PI
	theArea = parseInt(theArea * 100) / 100
	document.form3.area.value = theArea
}

function calcD() {
	if(document.form5.width1.value == "") {
		alert("Please enter a \"Width1\" measurement!")
		document.form5.width1.focus()
		return false
	}
	if(document.form5.width2.value == "") {
		alert("Please enter a \"Width2\" measurement!")
		document.form5.width2.focus()
		return false
	}
	if(document.form5.baseHeight.value == "") {
		alert("Please enter a height measurement!")
		document.form5.baseHeight.focus()
		return false
	}
	Width1 = parseFloat(document.form5.width1.value)
	Width2 = parseFloat(document.form5.width2.value)
	theHeight = parseFloat(document.form5.baseHeight.value)

	// Half-circle
	DArea = (Math.pow(Width1 / 2, 2) * Math.PI)
	DArea = DArea / 2

	// Base
	theWidth = (Width1 + Width2) / 2
	baseArea = theWidth * theHeight
	theArea = baseArea + DArea
	theArea = parseInt(theArea * 100) / 100
	document.form5.area.value = theArea
}

function calcDisp() {
	if(document.form1.bore.value == "") {
		alert("Please enter a Bore measurement!")
		document.form1.bore.focus()
		return false
	}
	if(document.form1.stroke.value == "") {
		alert("Please enter a Stroke measurement!")
		document.form1.stroke.focus()
		return false
	}
	if(document.form1.cylinders.value == "") {
		alert("Please enter the number of cylinders!")
		document.form1.cylinders.focus()
		return false
	}
	boreRadius = document.form1.bore.value / 2
	Stroke = document.form1.stroke.value
	Cylinders = document.form1.cylinders.value
	boreArea = Math.pow(boreRadius, 2) * Math.PI
	theDisplacement = boreArea * Stroke * Cylinders
	theLitres = parseInt(((theDisplacement * Math.pow(2.54, 3) / 1000) * 10) + 0.5) / 10
	document.form1.displacement.value = parseInt(theDisplacement + 0.5)
	document.form1.litres.value = theLitres
}

function calcCompRatio() {
	if(document.form1.bore.value == "") {
		alert("Please enter a Bore measurement!")
		document.form1.bore.focus()
		return false
	}
	if(document.form1.stroke.value == "") {
		alert("Please enter a Stroke measurement!")
		document.form1.stroke.focus()
		return false
	}
	if(document.form1.gasket.value == "") {
		alert("Please enter a gasket thickness measurement!")
		document.form1.gasket.focus()
		return false
	}
	if(document.form1.deck.value == "") {
		alert("Please enter a deck height measurement!")
		document.form1.deck.focus()
		return false
	}
	if(document.form1.piston.value == "") {
		alert("Please enter a piston top volume!")
		document.form1.piston.focus()
		return false
	}
	if(document.form1.chamber.value == "") {
		alert("Please enter a chamber volume!")
		document.form1.chamber.focus()
		return false
	}
	boreRadius = document.form1.bore.value / 2
	Stroke = document.form1.stroke.value
	boreArea = Math.pow(boreRadius, 2) * Math.PI
	theDisplacement = boreArea * Stroke
	theDisplacement = theDisplacement * 16.387064	// Convert to cc's
	daGasket = document.form1.gasket.value
		daGasket = daGasket * boreArea * 16.387064
	daDeck = document.form1.deck.value
		daDeck = daDeck * boreArea * 16.387064
	daPiston = document.form1.piston.value
	daChamber = document.form1.chamber.value
	compressedVolume = parseFloat(daGasket) + parseFloat(daDeck) - parseFloat(daPiston) + parseFloat(daChamber)
	totalVolume = parseFloat(theDisplacement) + parseFloat(compressedVolume)
	daRatio = parseInt((totalVolume / compressedVolume) * 100) / 100
	document.form1.ratio.value = daRatio
}

function horsepower() {
	Weight = document.form1.weight.value
	TireWidth = document.form1.tirewidth.value
	AspectRatio = document.form1.aspectratio.value / 100
	WheelDiameter = document.form1.wheeldiameter.value
	for (i = 1; i < 11; i++) {
		g = eval("document.form1.g" + i + ".value") * 32.2
		speed = eval("document.form1.speed" + i + ".value")
		hp = eval("document.form1.hp" + i)
			force = (Weight / 32.2) * g
			radius = ((TireWidth * AspectRatio / 25.4) + (WheelDiameter / 2)) / 12
			torque = force * radius
			circumference = radius * 2 * Math.PI
			rpm = speed * 5280 / 60 / circumference
			daHorsepower = parseInt(torque * rpm / 5252)
			hp.value = daHorsepower
	}
}


