function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = MM_findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }
  }
}
function moveLayerToMouseLoc(theLayer, offsetH, offsetV)
{
  var obj, left, top, width, height;
  var fudge = 15 // to account for any scrollbar
  var winW = window.innerWidth || window.clientWidth || document.body.clientWidth;
  var winH = window.innerHeight || window.clientHeight || document.body.clientHeight;
  if ((MM_findObj(theLayer))!=null)
  {
    if (document.layers)  //NS
    {
      document.onMouseMove = getMouseLoc;
      obj = document.layers[theLayer];
      width = obj.clip.width;
      height = obj.clip.height;
      left = mLoc.x + offsetH;
      top = mLoc.y + offsetV;
      
      if (left + width > winW) {
        left = winW - width - fudge;
      }
      
      if (top + height > winH) {
        top = winH - height - fudge
      }
      
      obj.left = left;
      obj.top  = top
    }
    else if (document.all)//IE
    {
      getMouseLoc();
      obj = document.all[theLayer].style;
      width = document.all[theLayer].clientWidth;
      height = document.all[theLayer].clientHeight;
      left = mLoc.x + offsetH;
      top = mLoc.y + offsetV;
      
      if (left + width > winW) {
        left = winW - width - fudge;
      }
      
      if (top + height > winH) {
        top = winH - height - fudge
      }
      
      obj.pixelLeft = left;
      obj.pixelTop  = top;
    }
    else {
       obj = document.getElementById(theLayer).style;
       width = document.getElementById(theLayer).offsetWidth;
       height = document.getElementById(theLayer).offsetHeight;
       left = mLoc.x + offsetH;
       top = mLoc.y + offsetV;
       
       if (left + width > winW) {
        left = winW - width - fudge;
      }
      
      if (top + height > winH) {
        top = winH - height - fudge
      }
       
       obj.left = left + "px";
       obj.top = top + "px";
    }
    showHideLayers(theLayer,'','show');
  }
}

// get mouse location
function Point(x,y) {  this.x = x; this.y = y; }
mLoc = new Point(-500,-500);

if (document.getElementById && !document.all && !document.layers) {
  document.onmousemove = function(e) {
    mLoc.x = e.pageX;
    mLoc.y = e.pageY;
  }
}

function getMouseLoc(e)
{
  if(!document.all)  //NS
  {
    mLoc.x = e.pageX;
    mLoc.y = e.pageY;
  }
  else               //IE
  {
    mLoc.x = event.x + document.body.scrollLeft;
    mLoc.y = event.y + document.body.scrollTop;
  }
  return true;
}

function printPage() {
    if (! window.print) {
        alert("This feature is not available for your browser. " +
              "To print this page, select Print from the File menu.");
        return;
    }
    window.print();
}

function getParam(p) {
    var qstring = location.search.substring(1);
    var re = new RegExp(p + "=([^&$]+)");
    re.test(qstring);
    return RegExp.$1;
}

function showSection() {
    var i, section;
    var s = getParam("section");
    for (i = 0; i <= s; i++) {
        section = document.getElementById("section" + i);
        section.style.display = "block";
    }
    if (i > 1) section.style.backgroundColor = "#F1CB8C";
}

function showAnswer(letter) {
    var selected, verity, explanation, button;
    
    selected = document.getElementById("selected" + letter.toUpperCase());
    explanation = document.getElementById("explanation" + letter.toUpperCase());
    
    if (letter == correctAnswer) {
        verity = document.getElementById("correct");
        button = document.getElementById("buttonCorrect");
    } else {
        verity = document.getElementById("incorrect");
        button = document.getElementById("buttonIncorrect");
    }

    selected.style.display = "inline";
    verity.style.display = "inline";
    explanation.style.display = "block";
    button.style.display = "inline";
}

function showDownloadHelp(isVisible) {
    if (isVisible) {
        moveLayerToMouseLoc("fileDownload", 10, 10);
    } else {
       showHideLayers("fileDownload", "", "hide");
    }
}

function validate(f) {
    var radios = f.elements['answer'];
    for (i = 0; i < radios.length; i++) {
        if (radios[i].checked) return true;
    }
    alert("Please choose an answer.");
    return false;
}

function resizeToImage() {
    var resource = document.getElementById("resource");
    var imageW = resource.clientWidth || resource.offsetWidth;
    var imageH = resource.clientHeight || resource.offsetHeight;
    var fudgeW = 10;
    var fudgeH = 30;
    var screenW = screen.width;
    var screenH = screen.height;
    var winW = imageW + fudgeW;
    var winH = imageH + fudgeH;
    window.resizeTo(winW, winH);
    window.moveTo(Math.max((0, screenW - winW) / 2), Math.max((0, screenH - winH) / 2));
}

