var weight, eTime;
var horsepower1, horsepower2, horsepower3, horsepower4;
var temp1, temp2, temp3, temp4;
var speed;
var finalhp1, finalhp2, finalhp3, finalhp4, finalhp5, finalhp6;
function create(form){
eTime = form.elapsedTime.value;
weight = form.vehicleWeight.value;
temp1 = eTime / 5.825;
temp1 = temp1 * temp1 * temp1;
horsepower1 = weight / temp1;
finalhp1 = roundOff(horsepower1, 2)
horsepower2 = horsepower1 * 1.3;
finalhp2 = roundOff(horsepower2, 2)
text = "<HEAD><TITLE>Horsepower Calculator</TITLE>";
text += "</HEAD><BODY BGCOLOR=#ffffff TEXT=#111111><link href='styles.css' rel='stylesheet' media='screen'>";
text += "<CENTER>";
text += "<div class=bodybox><h3>Horsepower Results</h3><p>";
text += "Your " +form.carModel.value;
text += " weighs about " +form.vehicleWeight.value+ " pounds ";
text += "and can complete a 1/4 mile in about ";
text += form.elapsedTime.value;
text += " seconds. That means that you've got about " +finalhp1;
text += " HP at the wheels, and about " + finalhp2;
text += " HP at the flywheel.";
text += "</p></div><center><form><input type=button onClick='self.close()'";
text += "value='Close Window' class=button></form></center></font>";
resultsWindow=window.open("", "displayWindow", "toolbar=no,menubar=no,scrollbar=auto,resizable=no,width=450,height=150")
resultsWindow.document.writeln(text);
resultsWindow.document.close();
}
function input1(form) {
Ctrl = form.carModel;
if (Ctrl.value == "") {
validatePrompt (Ctrl, "Please Input a Car Model.")
return (false);
} else
return (true);
}
function input2(form) {
Ctrl = form.vehicleWeight;
if (Ctrl.value == "") {
validatePrompt (Ctrl, "Please enter Your Vehicle Weight in Pounds.")
return (false);
} else
return (true);
}
function input3(form) {
Ctrl = form.elapsedTime;
if (Ctrl.value == "") {
validatePrompt (Ctrl, "Please enter Your 1/4 mile trapspeed. You can estimate...")
return (false);
} else
return (true);
}
function runSubmit (form, button)  {
if (!input1(form)) return;
if (!input2(form)) return;
if (!input3(form)) return;
create(form);       
return;
}
function validatePrompt (Ctrl, PromptStr) {
alert (PromptStr)
Ctrl.focus();
return;
}
function roundOff(value, precision) {
value = "" + value;
precision = parseInt(precision);
var whole = "" + Math.round(value * Math.pow(10, precision));
var decPoint = whole.length - precision;
if(decPoint != 0) {
result = whole.substring(0, decPoint);
result += ".";
result += whole.substring(decPoint, whole.length);
}
else {
result = whole;
}
return result;
}
