var Engine;
var enOpera = 'Opera';
var enIE = 'IE';
var enGecko = 'Gecko';


function TestEngine()
{
  if (document.all) {
    if (window.opera) {
      Engine = enOpera;
    }
    else {
      Engine = enIE;
    }
  }
  else {
    Engine = enGecko;
  }
}


function CreateAnchor(aName)
{
  var anc;
  if (Engine == enIE)
  {
    anc = document.createElement('<a name="' + aName + '"></a>');
    anc.href = '';
  }//IE
  else
  {
    anc = document.createElement("a");
    anc.href = '';
    anc.name = aName;
  }//Mozilla, Opera
  return anc;
}


function CreateImage(gURL, gWidth, gHeight)
{
  var NewImg = document.createElement("img");
  NewImg.src = gURL;
  NewImg.width = gWidth;
  NewImg.height = gHeight;
  NewImg.border = 0;
  return NewImg;
}


function BuildTOC()
{
  var str = "";
  var coll = document.getElementsByTagName('span');
  var i;
  var theSpan;
  var InsertHere = document.getElementById("InsertHere");
  var firstBR = document.createElement("br");
  InsertHere.insertBefore(firstBR, InsertHere.lastChild);

  var theList = document.createElement("ul");
  theList.className = "casual";
//  theList.style.listStyleImage = "url('/images/question1.gif')";
  InsertHere.appendChild(theList);

  for (i=0;i<coll.length;++i)
  {
    theSpan = coll[i];
    if (theSpan.id == "Qx")
    {
      var anc = CreateAnchor('q' + i);
      var theHref = document.createElement("a");
      theHref.href = "#q" + i;
      theHref.innerHTML = theSpan.innerHTML;
      var theListItem = document.createElement("li");
      theList.appendChild(theListItem);
      theListItem.appendChild(theHref);
      theSpan.insertBefore(document.createElement("br"), theSpan.firstChild);
//      theSpan.insertBefore(CreateImage("/images/answer1.gif",544,23), theSpan.firstChild);
      theSpan.insertBefore(anc, theSpan.firstChild);
      theSpan.appendChild(document.createElement("br"));
//      theSpan.appendChild(CreateImage("/images/line2.gif",544,13));
    }//if question encountered
    if (theSpan.id == "Category")
    {
      var theCaption = document.createElement("h3");
      theCaption.innerHTML = theSpan.innerHTML;
//      theCaption.className = "x3";
      theList.appendChild(document.createElement("br"));
      theList.appendChild(theCaption);
      theList.appendChild(document.createElement("br"));
    }//if category encountered
/*    if (theSpan.className == "A")
    {
      var theDiv = document.createElement("div");
      theDiv.align = "right";
      theSpan.appendChild(theDiv);
      theDiv.appendChild(CreateImage("/images/line2.gif",544,13));
      theDiv.appendChild(document.createElement("br"));
      var theImage = CreateImage("/images/navbtn.gif",56,12);
      theImage.useMap = "#NavMap";
      theDiv.appendChild(theImage);
    }//if answer encountered*/
  }
  InsertHere.removeChild(firstBR);
}


TestEngine();
BuildTOC();
document.getElementById("PauseCover").style.visibility="hidden";
document.getElementById("Answers").style.visibility="visible";
