<!--Define JavaScript functions.-->

function sign(y){
 return ((y < 0) ? -1 : 1);
}  //End of function sign.

function f(par1, par2, par3, tm){
 var dummy = (1.0 + par2*tm*tm)/(1.0 + par2);
 dummy = Math.pow(dummy, par3);
 dummy -= 1;
 dummy /= tm*tm;
 return par1/Math.sqrt(1.0 - tm*tm) - dummy;
}//End of function f

function f2Zero(dataForm){
var b = parseFloat(dataForm.b.value);
var c = parseFloat(dataForm.c.value);
var k1 = parseFloat(dataForm.a1.value);
var k2 = parseFloat(dataForm.a2.value);
var k3 = parseFloat(dataForm.a3.value);
var z;
var negFlag = 0;

if (b == c){
 alert("b and c are the same. Please try again with a non-zero interval. No further action taken.");
 return;
}

if (k2 == -1){
 alert("a2 was entered as -1. The function is infinite for this input. Please try again, entering a value for a2 that is not -1. No further action taken.");
 return;
}

if ((k3 == 0) || (k2 == 0)) {
 if (k1 == 0){
  alert("You have entered a zero function. The entire function is zero. No further action taken.");
  return;
 }
 else { //k1 non-zero
  alert("There is no zero for the function as entered. No further action taken.");
  return;
 }
} //End if k3 or k2 are 0

if (b > c) { // Swap interval endpoints.
 z = b;
 b = c;
 c = z;
} //End if (b > c)

if (Math.abs(b) > Math.abs(c)) { //Most of interval negative.
 if (c >= 0) {
  c = -b;
  b = 0.0000000001;
  alert("The interval was truncated so that it does NOT include 0.");
 }
 else {
  z = -b;
  b = -c;
  c = z;
 }
} //End if (abs(b) > abs(c)
else { //else abs(b) <= abs(c)
 negFlag = 1;
 if (b <= 0) {
  b = 0.0000000001;
  alert("The interval was truncated so that it does NOT include 0."); 
 }
} //End else abs(b) <= abs(c)

if (k1 != 0){
 if (c >= 1) { // Truncate interval so that c < 1
 c = 0.999999999;
 alert("The interval was truncated to the range x < abs(1).");
 } //End if (c >= 1)
 if (b >= 1) { // Truncate interval so that b > 0
  b = 0.0000000001;
  alert("The interval was truncated to the range x < abs(1), and x non-zero.");
 } //End if (b >= 1)
} //End if k1 != 0)

z = (c + b)/2;
var fz = f(k1, k2, k3, z);

var fc = fz, t = b, kount = 2;
var fb = f(k1, k2, k3, b);

if (fb == 0){
 if (negFlag) dataForm.t.value = b;
 else dataForm.t.value = -b;
 dataForm.erCode.value = 2;
 dataForm.funcEval.value = kount;
 return;
}

if (fz == 0){
 if (negFlag) dataForm.t.value = z;
 else dataForm.t.value = -z;
 dataForm.erCode.value = 2;
 dataForm.funcEval.value = kount;
 return;
}

if (sign(fz) == sign(fb))
{t = c;
 fc = f(k1, k2, k3, c);
 kount = 3;

 if (fc == 0){
  if (negFlag) dataForm.t.value = c;
  else dataForm.t.value = -c;
  dataForm.erCode.value = 2;
  dataForm.funcEval.value = kount;
  return;
 }

 if (sign(fz) != sign(fc))
 {b = z;
  fb = fz;
 }  //End if sign(fz) != sign(fc).
 else {//Sign is the same on this interval as well; no zero on input interval
  alert("The function does not change sign over the input interval. Please select another interval. No further action         taken.");
  return;
 }//End else if sign(fc) == sign(fz)
}  //End if sign(fz) == sign(fb).
else c = z;

var a = c, fa = fc, acmb, ic = 0, tol, p, q, acbs = Math.abs(-b + c), MAXIT = 200, ae, cmb;

acmb = 1.0;
do {
  ae = acmb;
  acmb /= 2.0;
  cmb = 1.0 + acmb;
} while (cmb > 1.0);
// At this point, ae should equal the machine epsilon
dataForm.epmch.value = ae;

do {
 if (Math.abs(fc) < Math.abs(fb))  //Interchange if necessary.
 {a = b;
  fa = fb;
  b = c;
  fb = fc;
  c = a;
  fc = fa
 }  //End if abs(fc) < abs(fb)
 cmb = (-b + c)/2;
 acmb = Math.abs(cmb);
 tol = Math.abs(b);
 tol++;
 tol *= ae;

 if (acmb <= tol)
 {dataForm.erCode.value = 1;
  break;
 }  //End if acmb <= tol.

 if (fb == 0)
 {dataForm.erCode.value = 2;
  break;
 }  //End if fb == 0.

/* Calculate new iterate implicitly as b + p/q, where p is arranged to be >= 0. This implicit form is used to prevent overflow. */

 p = (-a + b)*fb;
 q = -fb + fa;
 if (p < 0)
 {p = -p;
  q = -q;
 }  //End if p < 0.

/* Update a and check for satisfactory reduction in the size of the bracketing interval. If not, perform bisection. */

 a = b;
 fa = fb;
 ic++;

 if ((ic >= 4) && (8*acmb >= acbs))
  b = (c + b)/2;  //Use bisection
 else
 {if (ic >= 4)
  {ic = 0;
   acbs = acmb;
  }  //End if ic >= 4
  if (p <= tol*Math.abs(q))  //Test for too small a change
   b += tol*sign(cmb);
  else    //Root between b and (b + c)/2
  {if (p < cmb*q)  //Use secant rule
    b += p/q;
   else            //Use bisection
    b = (c + b)/2;
  }  //End else
 }  //End else.

// Have now computed new iterate, b.

 fb = f(k1, k2, k3, b);
 kount++;

 if (fb == 0){
  if (negFlag) dataForm.t.value = b;
  else dataForm.t.value = -b;
  dataForm.erCode.value = 2;
  dataForm.funcEval.value = kount;
  return;
 }

//Decide if next step interpolation or extrapolation

 if (sign(fb) == sign(fc))
 {c = a;
  fc = fa;
 }  //End sign(fb) == sign(fc).

} while (kount < MAXIT); //End do-while loop
if (kount >= MAXIT) dataForm.erCode.value = 3;

if (negFlag) dataForm.t.value = b;
else dataForm.t.value = -b;
dataForm.funcEval.value = kount;

return;
}  //End of f2Zero

// end of JavaScript function definitions -->