var NP = 15;
var probdat = new Object;
var adat = new Object;
var bdat = new Object;
var cdat = new Object;
var ddat = new Object;
var hints = new Object;
var tested = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var pm = new Array(1,2,3,4);
var mp = new Array(1,2,3,4);
var ans = new Array(5,11,11,2,13,9,3,5,4,7,1,3,6,5,10);
var hn = new Array(1,-2,3,4,5,3,6,7,8,9,10,11,12,13,12,14,15,16,17,18,19,20,21,22,23,24,24,23,25,26,27,28,29,30,31,32,33,34,35,33,36,37,38,39,25,40,41,42,43,44,45,44,46,47,48,49,-50,51,52,53);

hints[1] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"h/img1.gif\"> is continuous, so <IMG WIDTH=\"79\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img2.gif\">";
hints[2] = "<I>f</I> is decreasing on (2,3)";
hints[3] = "<I>f</I> is continuous, see The Extreme Value Theorem (&nbsp;p. 275&nbsp;)";
hints[4] = "Try <I>f</I>(<I>x</I>)=(<I>x</I>-5)<SUP>3</SUP>";
hints[5] = "See Concavity Test (&nbsp;p. 287&nbsp;)";
hints[6] = "Try <I>f</I>(<I>x</I>)=(<I>x</I>+4)<SUP>2</SUP>";
hints[7] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"h/img1.gif\"> is continuous, see The Intermediate Value Theorem (&nbsp;p. 127&nbsp;)";
hints[8] = "<I>f</I> is increasing, so it is one-to-one";
hints[9] = "The product of two increasing functions is an increasing function";
hints[10] = "Try <I>f</I>(<I>x</I>)=<I>x</I><SUP>3</SUP>-6<I>x</I><SUP>2</SUP>+13<I>x</I>";
hints[11] = "Obvious!";
hints[12] = "Try <I>f</I>(<I>x</I>)=<I>x</I><SUP>3</SUP>+<I>x</I>";
hints[13] = "<IMG WIDTH=\"83\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img3.gif\"> so 0 is a critical point of <IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"h/img1.gif\">";
hints[14] = "Try <I>f</I>(<I>x</I>)=<I>x</I><SUP>3</SUP>";
hints[15] = "<IMG WIDTH=\"178\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img4.gif\">";
hints[16] = "Try <P><BR><P></P><DIV ALIGN=\"CENTER\"><IMG WIDTH=\"274\" HEIGHT=\"53\" SRC=\"h/img5.gif\"></DIV><BR CLEAR=\"ALL\">";
hints[17] = "<IMG WIDTH=\"28\" HEIGHT=\"16\" ALIGN=\"BOTTOM\" SRC=\"h/img6.gif\"> is increasing on <IMG WIDTH=\"67\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img7.gif\">. The composition of two increasing functions is an increasing function";
hints[18] = "<IMG WIDTH=\"178\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img4.gif\">, <I>f</I> is increasing on (0,1), <IMG WIDTH=\"70\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img8.gif\"> is decreasing and <IMG WIDTH=\"46\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img9.gif\"> is decreasing, so <IMG WIDTH=\"19\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"h/img10.gif\"> is decreasing on (0,1)";
hints[19] = "<IMG WIDTH=\"151\" HEIGHT=\"59\" ALIGN=\"MIDDLE\" SRC=\"h/img11.gif\">, so <IMG WIDTH=\"81\" HEIGHT=\"45\" ALIGN=\"MIDDLE\" SRC=\"h/img12.gif\"> is increasing";
hints[20] = "If <IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img13.gif\"> then <IMG WIDTH=\"186\" HEIGHT=\"59\" ALIGN=\"MIDDLE\" SRC=\"h/img14.gif\">";
hints[21] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"h/img1.gif\"> exists, so <I>f</I> is continuous. See The Extreme Value Theorem (&nbsp;p. 275&nbsp;)";
hints[22] = "<IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img15.gif\">. See Theorem 6 p. 278";
hints[23] = "<IMG WIDTH=\"443\" HEIGHT=\"61\" ALIGN=\"MIDDLE\" SRC=\"h/img16.gif\">";
hints[24] = "<IMG WIDTH=\"443\" HEIGHT=\"61\" ALIGN=\"MIDDLE\" SRC=\"h/img16.gif\"><BR><IMG WIDTH=\"254\" HEIGHT=\"61\" ALIGN=\"MIDDLE\" SRC=\"h/img17.gif\"><P>";
hints[25] = "See The Mean Value Theorem (&nbsp;p. 283&nbsp;)";
hints[26] = "Try <I>f</I>(<I>x</I>)=(2<I>x</I>-3)<SUP>2</SUP>";
hints[27] = "<I>f</I> has a minimum on [1,2] (&nbsp;The Extremal Value Theorem&nbsp;) but does not have a minimum at <I>x</I>=1 and at <I>x</I>=2 (&nbsp;because <I>f</I>(<I>c</I>)&lt;<I>f</I>(1), <I>f</I>(<I>c</I>)&lt;<I>f</I>(2)&nbsp;)";
hints[28] = "Take <I>f</I>(<I>x</I>)=-(2<I>x</I>+3)<SUP>2</SUP>";
hints[29] = "Take <I>f</I>(<I>x</I>)=<I>x</I><SUP>3</SUP>";
hints[30] = "Take <I>f</I>(<I>x</I>)=<I>x</I><SUP>3</SUP>-9<I>x</I><SUP>2</SUP>+26<I>x</I>-24";
hints[31] = "See the second derivative test on p. 287";
hints[32] = "Try <I>f</I>(<I>x</I>)=(<I>x</I>-3)<SUP>2</SUP>";
hints[33] = "<IMG WIDTH=\"79\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img18.gif\"> (&nbsp;use the limit definition of derivative&nbsp;)";
hints[34] = "<BR><P></P><DIV ALIGN=\"CENTER\"><IMG WIDTH=\"487\" HEIGHT=\"53\" SRC=\"h/img19.gif\"></DIV><BR CLEAR=\"ALL\">";
hints[35] = "<BR><P></P><DIV ALIGN=\"CENTER\"><IMG WIDTH=\"231\" HEIGHT=\"53\" SRC=\"h/img20.gif\"></DIV><BR CLEAR=\"ALL\">";
hints[36] = "<IMG WIDTH=\"292\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img21.gif\">";
hints[37] = "Take <I>f</I>(<I>x</I>)=<I>x</I><SUP>2</SUP>, <I>g</I>(<I>x</I>)=2<I>x</I><SUP>2</SUP>"
hints[38] = "Try <I>f</I>(<I>x</I>)=(<I>x</I>-1)<SUP>2</SUP>, <I>g</I>(<I>x</I>)=<I>e</I><SUP>-<I>x</I></SUP>";
hints[39] = "Try <I>f</I>(<I>x</I>)=<I>x</I><SUP>2</SUP>, <I>g</I>(<I>x</I>)=<I>x</I><SUP>2</SUP>";
hints[40] = "<I>f</I> is increasing";
hints[41] = "Try <I>f</I>(<I>x</I>)=(<I>x</I>-1)<SUP>2</SUP>";
hints[42] = "If <I>f</I> is decreasing then <IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img22.gif\">";
hints[43] = "Try <I>f</I>(<I>x</I>)=<I>x</I>";
hints[44] = "<IMG WIDTH=\"200\" HEIGHT=\"38\" ALIGN=\"MIDDLE\" SRC=\"h/img23.gif\">";
hints[45] = "<IMG WIDTH=\"191\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img24.gif\"> if <I>f</I>(<I>x</I>)&lt;0";
hints[46] = "See the definition of an inflection point (&nbsp;p. 287&nbsp;)";
hints[47] = "Try <I>f</I>(<I>x</I>)=<I>x</I><SUP>3</SUP>-<I>x</I>";
hints[48] = "See the definition of concavity (&nbsp;p. 286&nbsp;)";
hints[49] = "Take <IMG WIDTH=\"132\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img25.gif\">";
hints[50] = "See the second derivative test (&nbsp;p. 287&nbsp;)";
hints[51] = "<I>f</I> is concave down";
hints[52] = "Try <I>f</I>(<I>x</I>)=-<I>x</I><SUP>2</SUP>";
hints[53] = "<IMG WIDTH=\"84\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"h/img26.gif\"> !";


probdat[1] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> is continuous on [2,6] and <DIV ALIGN=\"CENTER\"><IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img2.gif\"> for <I>x</I>&lt;3<BR><IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img3.gif\"> for <I>x</I>&gt;3</DIV>";
adat[1] = "<I>f</I> has a critical point at <I>x</I>=3";
bdat[1] = "<I>f</I> is increasing on (2,3)";
cdat[1] = "<I>f</I> has a maximum on [2,6]";
ddat[1] = "<I>f</I> is concave upward on (2,6)";

probdat[2] = "<IMG WIDTH=\"84\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img4.gif\"> for all <IMG WIDTH=\"91\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img5.gif\">";
adat[2] = "<I>f</I> is concave upward on [-3,4]";
bdat[2] = "<I>f</I> has a minimum on [-3,4]";
cdat[2] = "<I>f</I> has a relative minimum on [-3,4]";
ddat[2] = "If <IMG WIDTH=\"124\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img6.gif\"> then <I>f</I> has a critical point on [-3,4]";

probdat[3] = "<IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img3.gif\"> for all <IMG WIDTH=\"76\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img7.gif\">";
adat[3] = "<I>f</I> is one-to-one";
bdat[3] = "<I>g</I>(<I>x</I>)=<I>x</I><SUP>2</SUP><I>f</I>(<I>x</I>) is increasing on [1,5]";
cdat[3] = "<I>f</I> has no inflection points";
ddat[3] = "<I>f</I> has a maximum at <I>x</I>=5";

probdat[4] = "<I>f</I> is defined on [-1,1], <IMG WIDTH=\"24\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img8.gif\"> exists and <I>c</I>=0 is an inflection point of <I>f</I>";
adat[4] = "<I>f</I> has a critical point on [-1,1]";
bdat[4] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> has a critical point on [-1,1]";
cdat[4] = "<IMG WIDTH=\"24\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img8.gif\"> has a critical point on [-1,1]";
ddat[4] = "<I>c</I>=0 is not a critical point of <I>f</I>";

probdat[5] = "Let <I>f</I> be defined in <IMG WIDTH=\"19\" HEIGHT=\"17\" ALIGN=\"BOTTOM\" SRC=\"img9.gif\"> and let <IMG WIDTH=\"127\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img10.gif\">";
adat[5] = "if <IMG WIDTH=\"46\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img11.gif\"> exists, then <IMG WIDTH=\"44\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img12.gif\"> exists";
bdat[5] = "if <IMG WIDTH=\"44\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img12.gif\"> exists, then <IMG WIDTH=\"46\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img11.gif\"> exists";
cdat[5] = "if <I>f</I>(0)=0, <IMG WIDTH=\"95\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img13.gif\"> and <I>f</I> is increasing then <I>g</I> is increasing on (0,1)";
ddat[5] = "if <I>f</I>(0)=0, <IMG WIDTH=\"95\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img13.gif\"> and <I>f</I> is concave down and increasing on (0,1) then <I>g</I> is concave down on (0,1)";

probdat[6] = "<I>f</I> is defined on [1,2], one-to-one and <IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img14.gif\"> for all <IMG WIDTH=\"81\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img15.gif\">";
adat[6] = "if <I>f</I> is concave down then <I>f</I>&nbsp;<SUP>-1</SUP> is concave up";
bdat[6] = "if <I>f</I> is increasing then <I>f</I>&nbsp;<SUP>-1</SUP> is decreasing";
cdat[6] = "<I>f</I> does not have a maximum on [1,2]";
ddat[6] = "<I>f</I> does not have a local minimum on (1,2)";

probdat[7] = "<I>f</I> is an odd function and <IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\">, <IMG WIDTH=\"24\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img8.gif\"> exist";
adat[7] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> is an even function";
bdat[7] = "<IMG WIDTH=\"24\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img8.gif\"> is an odd function";
cdat[7] = "<IMG WIDTH=\"24\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img8.gif\"> can be an even nonzero function";
ddat[7] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> can be an odd nonzero function";

probdat[8] = "<I>f</I> is differentiable on [1,2] and <I>f</I>(1)=<I>f</I>(2)";
adat[8] = "<I>f</I> has a critical point on (1,2)";
bdat[8] = "<I>f</I> has a maximum on (1,2)";
cdat[8] = "if there exists <IMG WIDTH=\"78\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img16.gif\"> such that <I>f</I>(<I>c</I>)&lt;<I>f</I>(2) then <I>f</I> has a minimum on (1,2)";
ddat[8] = "<I>f</I> cannot have a maximum on (1,2)";

probdat[9] = "<I>f</I> is defined on [2,4] and <IMG WIDTH=\"24\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img8.gif\"> is continuous";
adat[9] = "if <IMG WIDTH=\"83\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img17.gif\"> then <I>f</I> has a local minimum at <I>x</I>=3";
bdat[9] = "if <IMG WIDTH=\"83\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img18.gif\"> then <I>f</I> has a critical point at <I>x</I>=3";
cdat[9] = "if <IMG WIDTH=\"83\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img19.gif\"> then <I>f</I> cannot have a local minimum at <I>x</I>=3";
ddat[9] = "if <IMG WIDTH=\"79\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img20.gif\"> then <I>f</I> has an inflection point at <I>x</I>=3";

probdat[10] = "<IMG WIDTH=\"112\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img21.gif\">";
adat[10] = "<IMG WIDTH=\"44\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img22.gif\"> exists and 0 is a critical point of <I>f</I>";
bdat[10] = "<IMG WIDTH=\"48\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img23.gif\"> does not exist";
cdat[10] = "0 is an inflection point of <I>f</I>";
ddat[10] = "<IMG WIDTH=\"44\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img22.gif\"> does not exist";

probdat[11] = "<I>f</I>, <I>g</I> are defined on [-1,3] and <IMG WIDTH=\"84\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img4.gif\">, <IMG WIDTH=\"82\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img24.gif\"> for all <IMG WIDTH=\"91\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img25.gif\">";
adat[11] = "<I>f</I>+<I>g</I> is concave upward on (-1,3)";
bdat[11] = "<I>f</I>-<I>g</I> is concave upward on (-1,3)";
cdat[11] = "<I>fg</I> is concave upward on (-1,3)";
ddat[11] = "<I>fg</I> does not have a critical point on (-1,3)";

probdat[12] = "<I>f</I> is defined on [0,1] and <IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> exists on (0,1)";
adat[12] = "if <I>f</I>(0)=0 then <IMG WIDTH=\"104\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img26.gif\"> for some <IMG WIDTH=\"78\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img27.gif\">";
bdat[12] = "if <IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img3.gif\"> for all <IMG WIDTH=\"81\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img28.gif\"> then <I>f</I> has an absolute minimum at <I>x</I>=0";
cdat[12] = "if <IMG WIDTH=\"84\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img4.gif\"> for all <IMG WIDTH=\"81\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img28.gif\"> then <I>f</I> is increasing";
ddat[12] = "if <I>f</I> is decreasing on (0,1) then <IMG WIDTH=\"80\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img3.gif\"> on (0,1)";

probdat[13] = "<I>f</I> is increasing on [-3,3] and <IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> exists on (-3,3)";
adat[13] = "<I>g</I>(<I>x</I>)=<I>f</I><SUP>&nbsp;2</SUP>(<I>x</I>) is increasing on (-3,3)";
bdat[13] = "<I>h</I>(<I>x</I>)=<I>f</I><SUP>&nbsp;3</SUP>(<I>x</I>) is increasing on (-3,3)";
cdat[13] = "if <I>f</I>(<I>x</I>)&lt;0 for -3&lt;<I>x</I>&lt;0 then <I>g</I>(<I>x</I>)=<I>f</I><SUP>&nbsp;2</SUP></I>(<I>x</I>) is decreasing on (-3,0)";
ddat[13] = "if <I>f</I>(<I>x</I>)&lt;0 for 0&lt;<I>x</I>&lt;3 then <I>h</I>(<I>x</I>)=<I>f</i><SUP>&nbsp;3</SUP>(<I>x</I>) is decreasing on (0,3)";

probdat[14] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> is increasing on (-1,0) and decreasing on (0,1)";
adat[14] = "0 is an inflection point of <I>f</I>";
bdat[14] = "0 is a critical point of <I>f</I>";
cdat[14] = "<I>f</I> is concave up on (-1,0)";
ddat[14] = "<I>f</I> is decreasing on (0,1)";

probdat[15] = "<IMG WIDTH=\"84\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img29.gif\"> for all <IMG WIDTH=\"96\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img30.gif\">";
adat[15] = "if <IMG WIDTH=\"78\" HEIGHT=\"37\" ALIGN=\"MIDDLE\" SRC=\"img31.gif\"> for some -4&lt;<I>c</I>&lt;4 then <I>f</I> does not need to have a maximum at <I>c</I>";
bdat[15] = "<I>f</I> has no inflection points on (-4,4)";
cdat[15] = "<I>f</I> is increasing on (-4,4)";
ddat[15] = "<IMG WIDTH=\"21\" HEIGHT=\"36\" ALIGN=\"MIDDLE\" SRC=\"img1.gif\"> is decreasing on (-4,4)";


var existWin2 = 0;
var num = 1;
var cp = 0;
var good = 0;

function DisplayProblem(problem)
{
  if ( existWin2==0 )
  {
    win2 = window.open("","Problem","location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=550,height=500");
  }
  win2.focus();
  if ( problem==0 )
  {
    cp++;
    with(Math)
    {
      num=floor(NP*random())+1;
      for ( i=0; i<5; i++ )
      {
        m1 = floor(4*random());
        m2 = floor(4*random());
        temp = pm[m1]; pm[m1] = pm[m2]; pm[m2] = temp;
      }
      for ( i=0; i<4; i++ )
      {
        mp[pm[i]-1]=i+1;
      }
    }
    if ( tested[num-1] )
    {
      for ( i=0; i<NP; i++ )
      {
        num = num+1;
        if ( num>NP ) { num=1; } 
        if ( !tested[num-1] ) { break; }
      }
      if ( i==NP )
      {
        DisplayFinalPage();
        return;
      }
    }
  }
  else
  {
    num = problem;
  }    
//  tested[num-1] = 1;
  win2.document.open();
  win2.document.writeln("<body bgcolor=FFFFCC>");
  win2.document.write("<P><B>Problem "+cp+".</B> ");
  win2.document.write(probdat[num]);
  win2.document.writeln("<P>Please select all statements that are <B>always</B> true.<P>");
  win2.document.writeln("<form name=\"testform\"><center><table><tr><td>");
  win2.document.write("<P>");
  win2.document.write("<input type=checkbox  name=\"test\" value=\"1\"> A. ");
  DisplayChoice(pm[0],num,0);
  win2.document.write("<input type=checkbox  name=\"test\" value=\"2\"> B. ");
  DisplayChoice(pm[1],num,0);
  win2.document.write("<input type=checkbox  name=\"test\" value=\"3\"> C. ");
  DisplayChoice(pm[2],num,0);
  win2.document.write("<input type=checkbox  name=\"test\" value=\"4\"> D. ");
  DisplayChoice(pm[3],num,0);
  win2.document.writeln("</td></tr></table><p>");
  win2.document.writeln("<input type=button name=\"but1\" value=\"Check Answers.\" onClick=\"opener.DisplaySolution(this.form)\"></center>");
  win2.document.close();
  existsWin2 = 1;
}

function DisplayChoice(i,num,chk)
{
  if ( i==1 )
  {
     win2.document.write(adat[num]);
  }
  else if ( i==2 )
  { 
     win2.document.write(bdat[num]);
  }
  else if ( i==3 )
  {
     win2.document.write(cdat[num]);
  }
  else
  {
     win2.document.write(ddat[num]);
  }   
  if ( chk==1 )
  {
     win2.document.write("<img src=\"checkmark.gif\" align=\"middle\">");
     good++;
  }
  else if ( chk==2 )
  {
     win2.document.write("<img src=\"wrong.gif\" align=\"middle\">");
  }
  win2.document.writeln("<BR><BR>");
}

function bit(x,k)
{
  return ( (x>>k) & 1 );
}

function DisplayHint(i1,n)
{
  var hind = hn[(n-1)*4+i1-1];
  win2.document.writeln("<FONT COLOR=\"RED\">");
  if ( bit(ans[n-1],i1-1)==1 )
  {
    win2.document.writeln("THIS IS TRUE!&nbsp;&nbsp; ");
  }
  else if ( hind>=0 )
  {
    win2.document.writeln("THIS IS NOT ALWAYS TRUE!&nbsp;&nbsp; ");
  } 
  else
  {
    win2.document.writeln("THIS IS NEVER TRUE!&nbsp;&nbsp; ");
    hind = -hind;
  }
  win2.document.writeln("</FONT>");
  win2.document.write(hints[hind]);
  win2.document.writeln(".<BR><BR>");
}

function DisplaySolution(form)
{
  if ( tested[num-1]!=0 )
  {
    DisplayProblem(0);
    return;
  } 
  tested[num-1] = 1;
  var num1=0;
  for ( i=3; i>=0; i-- )
  {
    num1 = num1*2;
    if ( form.test[mp[i]-1].checked ) { num1 = num1+1; }
  } 
  win2.document.open();
  win2.document.writeln("<body bgcolor=FFFFCC>");
  if ( num1==ans[num-1] )
  {
     win2.document.writeln("<P><H2> YOU ARE RIGHT!!!</H2>");
     win2.document.write("<P><B>Problem "+cp+".</B> ");
     win2.document.write(probdat[num]);
     win2.document.writeln("<P>Your answers:<P>");
     win2.document.writeln("<form name=\"ansform\"><center><table><tr><td>");
     win2.document.write("<P>");
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"1\"");
     if ( bit(num1,pm[0]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> A. ");
     DisplayChoice(pm[0],num,1);
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"2\"");
     if ( bit(num1,pm[1]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> B. ");      
     DisplayChoice(pm[1],num,1);
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"3\"");
     if ( bit(num1,pm[2]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> C. ");
     DisplayChoice(pm[2],num,1);
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"4\"");
     if ( bit(num1,pm[3]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> D. ");  
     DisplayChoice(pm[3],num,1);
     win2.document.writeln("<hr width=\"50%\"></FONT></td></tr></table></center></form><p>");
     win2.document.write("<div align=right>:");
     win2.document.write("<a href=\"javascript:opener.DisplayProblem(0)\">");
     win2.document.write("Click here to proceed.</a>");
     win2.document.writeln("<div align=left></FONT>");
  }
  else
  {
     win2.document.writeln("<P><H2> HERE IS WHAT YOU'VE GOT WRONG:</H2>");
     win2.document.write("<P><B>Problem "+cp+".</B> ");
     win2.document.write(probdat[num]);
     win2.document.writeln("<P>Your answers:<P>");
     win2.document.writeln("<form name=\"ansform\"><center><table><tr><td>");
     win2.document.write("<P>");
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"1\"");
     if ( bit(num1,pm[0]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> A. ");
     if ( bit(num1,pm[0]-1)==bit(ans[num-1],pm[0]-1) )
     {  
        DisplayChoice(pm[0],num,1);
     }
     else
     {
        DisplayChoice(pm[0],num,2);
        DisplayHint(pm[0],num);
     }
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"2\"");
     if ( bit(num1,pm[1]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> B. ");      
     if ( bit(num1,pm[1]-1)==bit(ans[num-1],pm[1]-1) )
     {  
        DisplayChoice(pm[1],num,1);
     }
     else
     {
        DisplayChoice(pm[1],num,2);
        DisplayHint(pm[1],num);
     } 
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"3\"");
     if ( bit(num1,pm[2]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> C. ");
     if ( bit(num1,pm[2]-1)==bit(ans[num-1],pm[2]-1) )
     {  
        DisplayChoice(pm[2],num,1);
     }
     else
     {
        DisplayChoice(pm[2],num,2);
        DisplayHint(pm[2],num);
     }
     win2.document.write("<hr width=\"50%\"><input type=checkbox  name=\"test\" value=\"4\"");
     if ( bit(num1,pm[3]-1)==1 )
     {
        win2.document.write(" checked");
     }  
     win2.document.write("> D. ");  
     if ( bit(num1,pm[3]-1)==bit(ans[num-1],pm[3]-1) )
     {  
        DisplayChoice(pm[3],num,1);
     }
     else
     {
        DisplayChoice(pm[3],num,2);
        DisplayHint(pm[3],num);
     }
     win2.document.writeln("<hr width=\"50%\"></td></tr></table></center></form><p>");
     win2.document.write("<div align=right>:");
     win2.document.write("<a href=\"javascript:opener.DisplayProblem(0)\">");
     win2.document.write("Click here to proceed.</a>");
     win2.document.writeln("<div align=left>");  
  }
  win2.document.close();
}

function closeWin() 
{
  onerror=null
  if ( existsWin2==1 ) {win2.close()}
}

function percentage(x,y)
{
  return Math.round(1000.0*(x/y))/10.0;
}

function DisplayFinalPage()
{
  for ( i=0; i<NP; i++ )
    tested[i] = 0;
  cp = 0;
  win2.document.open();
  win2.document.writeln("<body bgcolor=FFFFCC>");
  win2.document.write("<b> You have reached the end of this quiz.");
  win2.document.writeln(" Thank you!</b><p>");
  win2.document.writeln("You answered correctly "+good+" questions out of ");
  win2.document.writeln((NP*4)+" possible which makes about "+percentage(good,NP*4)+"%<p>");
  win2.document.write("<a href=\"javascript:opener.DisplayProblem(0)\">");
  win2.document.write("Click here to run the test again.</a><br><br><p>");
  win2.document.write("<a href=\"javascript:opener.closeWin()\">");
  win2.document.write("Click here to quit.</a>");
  win2.document.close();
}
