var bodobj = null;
var shockObj;
var shockControl;
var is_ie4up = true;
var is_nav4up = false;




function shockScroll () {
  if (menuAutoHide) {
    if (shockObj && shockObj.style) {
      shockObj.style.visibility="hidden";
      shockObj.style.visibility="visible";
    }
  }
}

function beginPage() {
  preloadImages();
  startIt();
  setLowerBar();
  hideSearchBox();
}

function getThing(t, n) {
  if (document.all) {
    for (var i = 0; i < document.all.tags(t.toUpperCase()).length; i++) {
      if (document.all.tags(t.toUpperCase())[i].id == n) {
        return document.all.tags(t.toUpperCase())[i];
      }
    }
  }
}

function preloadImages () {
  for (var i = 0; i < preloadArr.length; i++) {
    var newImg = new Image();
    newImg.src = preloadArr[i];
  }
}

function checkNav() {
  var allDivs = document.all.tags("DIV");
  for (d in allDivs) {
    if (allDivs[d].className == "level1nav" || 
        allDivs[d].className == "level2nav") {
      getKiddies(allDivs[d]);
    }
  }
}

function timedCheckNav() {
  setTimeout('checkNav()', 200);
}

function setLowerBar(e) {
  if (is_ie4up) {
    var h = document.body.clientHeight;
    var w = document.body.clientWidth;

    document.all["searchbox"].style.pixelLeft = w - searchWidth - 15;
    document.all["searchbox"].style.pixelTop = h - bottomBarHeight - searchHeight;
    document.all["feedbackbox"].style.pixelLeft = w - feedbackWidth - 15;
    document.all["feedbackbox"].style.pixelTop = h - bottomBarHeight - feedbackHeight;
    document.all["footsect"].style.pixelLeft = 0;
    document.all["footsect"].style.pixelTop = h - bottomBarHeight;
    document.all["footsect"].style.visibility = "visible";

    if (h - bottomBarHeight - topBarHeight > 0) {
      document.all["bodysect"].style.height = h - bottomBarHeight - topBarHeight;
    }

    // Need to explicitly call this to resize without scroll areas
    if (document.all["navsect"]) {
      if (h - bottomBarHeight - topBarHeight > 0) {
        document.all["navsect"].style.height = h - bottomBarHeight - topBarHeight;
      }
      
    } else {
     
    }

    //document.all["headsect"].style.pixelHeight = topBarHeight;

    // check the hash value of the url.. this fixes a bug with SOME versions of IE
    // where the page doesn't scroll to an internal anchor.
    if (document.location.hash) {
      document.location.href = document.location.href; 
    }

    var allDivs = document.all.tags("DIV");
    var dlUp = document.location.href.toUpperCase();

    for (d in allDivs) {

      if (allDivs[d].id == "headsect") {
//        headObj = allDivs[d];
//        allAs = headObj.all.tags("A");
//        for (lnk in allAs) {
//          var aLnk = allAs[lnk];
//          var lnk = linkMap[aLnk.innerText];
//          if (lnk) {
//            lnk = lnk.toUpperCase();
//            if (aLnk.innerText && dlUp.indexOf(lnk) == 0) {
//              aLnk.style.color = "#ffca00";
//            }         
//          }
//        }
      } else if (allDivs[d].id == "navsect") {
        checkNav();

      } else if (allDivs[d].id == "bodysect") {
        bodobj = allDivs[d].id;
        if (menuAutoHide) {
          allDivs[d].onscroll = shockScroll;
          shockObj = getThing("DIV", menuAutoHide);
          shockControl = getThing("OBJECT", menuAutoHide + "obj");
        }
      }
    }

    // see if we should open any side menus
    if (document.openMenus) {
      var divCount = 0;
      var divMenus = new Array();
      var divSet = document.all.tags("DIV");
      for (d in divSet) {
        if (divSet[d].className == "level1nav") {
          divMenus[divMenus.length] = divSet[d];
        }
      }
      for (toOpen in document.openMenus) {
        toggleDiv(divMenus[toOpen].children.tags("DIV"));
      }
    }

    if (shockControl) {
      shockControl.style.visibility ="hidden";
      setTimeout('shockControl.style.visibility ="visible"', 500);

    }

   // **** ALL CODE BELOW HERE IS FOR NETSCAPE COMPATABILITY ***

  } else if (is_nav4) {
    window.document.onClick = hideAllBoxes;
    document.layers["bodysect"].onFocus = hideAllBoxes;
    if (e && e.type == "resize") {
      if (window.location.hash) {
        with (window.location) {
          tmp = protocol + host + port + pathname + search;
        }
        window.location.href = tmp;
      }
      window.location.href = window.location.href;
    }
    h = document.height;
    w = document.width;
    if (window.innerHeight > h) { h = window.innerHeight; }
    if(document.layers["footsect"]) {
      document.layers["footsect"].left = 0;
      document.layers["footsect"].top = h - bottomBarHeight - 1;
      document.layers["footsect"].visibility = "show";
    }
    document.layers["searchbox"].left = w - searchWidth - 15;
    document.layers["searchbox"].top = h - bottomBarHeight - searchHeight;
    document.layers["searchbox"].onMouseOut = hideSearchBox;
    document.layers["feedbackbox"].left = w - feedbackWidth - 15;
    document.layers["feedbackbox"].top = h - bottomBarHeight - feedbackHeight;
    document.layers["feedbackbox"].onMouseOut = hideFeedbackBox;
    event = null;
  }
}

// read the links out of a given div
function getKiddies (div) {
  var aLinks = div.children.tags("A");
  for (var j in aLinks) {
    var lnk = aLinks[j].href;
    if (lnk && lnk != "") {
      var full = makeFullUrl(lnk);
      if (full == window.location.href || full == document.parentLink) {
        aLinks[j].className = "activeNavLink";
      } else {
        aLinks[j].className = "";
      }
      if (!aLinks[j].onclick) {
        aLinks[j].onclick = timedCheckNav;
      }
    }
  }
}


function makeFullUrl(lnk) {
  downLnk = lnk.toLowerCase();
  var p = window.location.protocol;
  var h = window.location.host;
  // if this is an absolute link, return it
  if (downLnk.indexOf("://") != -1 ||
      downLnk.indexOf("javascript:") == 0) {
    return lnk;
  }

  var brk = (p == "file" ? "\\" : "/");
  if (p && h) {
    if (lnk.indexOf(brk) == 0) {
      return p + "://" + h + lnk;
    } else {
      var path = window.location.pathname;
      path = path.substring(0, path.lastIndexOf(brk));
      return p + "://" + h + path + "/" + lnk;
    }
  }
  return lnk;
}

function openSearchBox(e,isClick) {
  hideFeedbackBox();
  if (is_ie4up) {
    if (e) { e.cancelBubble = true; }
    if (document.all["searchbox"].style.visibility == "visible" && isClick) {
      document.all["searchbox"].style.visibility = "hidden";
    } else {
      var h = document.body.clientHeight;
      var w = document.body.clientWidth;
      document.all["searchbox"].style.pixelLeft = w - searchWidth - 15;
      document.all["searchbox"].style.pixelTop = h - bottomBarHeight - searchHeight;
      document.all["searchbox"].style.visibility = "visible";
    }
  } else if (is_nav4) {
    if (document.layers["searchbox"].visibility == "show" && isClick) {
      document.layers["searchbox"].visibility = "hide";
    } else {
      var h = document.height;
      if (h == 0) { h = window.innerHeight; }
      var w = window.innerWidth;
      document.layers["searchbox"].left = w - searchWidth - 15;
      document.layers["searchbox"].top = h - bottomBarHeight - searchHeight - 15;
      document.layers["searchbox"].visibility = "show";
    }
  }
}

function openFeedbackBox(e,isClick) {
  hideSearchBox();
  if (is_ie4up) {
    if (e) { e.cancelBubble = true; }
    if (document.all["feedbackbox"].style.visibility == "visible" && isClick) {
      document.all["feedbackbox"].style.visibility = "hidden";
      if (menuAutoHide) {
        autohideDiv(menuAutoHide , 1);
      }
    } else {
      var h = document.body.clientHeight;
      var w = document.body.clientWidth;
      document.all["feedbackbox"].style.pixelLeft = w - feedbackWidth - 15;
      document.all["feedbackbox"].style.pixelTop = h - bottomBarHeight - feedbackHeight;
      document.all["feedbackbox"].style.visibility = "visible";
      if (menuAutoHide) {
        autohideDiv(menuAutoHide , 0);
      }
    }
  } else if (is_nav4) {
    if (document.layers["feedbackbox"].visibility == "show" && isClick) {
      document.layers["feedbackbox"].visibility = "hide";
    } else {
      var h = document.height;
      if (h == 0) { h = window.innerHeight; }
      var w = window.innerWidth;
      document.layers["feedbackbox"].left = w - feedbackWidth - 15;
      document.layers["feedbackbox"].top = h - bottomBarHeight - feedbackHeight;
      document.layers["feedbackbox"].visibility = "show";
    }
  }
}

function hideSearchBox(e) {
  if (is_ie4up) {
    if (e) { e.cancelBubble = true; }
    document.all["searchbox"].style.visibility = "hidden";
    document.all["bodysect"].focus();
  } else if (is_nav4up) {
    document.layers["searchbox"].visibility = "hide";
  }
}

function hideFeedbackBox(e) {
  if (is_ie4up) {
    if (e) { e.cancelBubble = true; }
    document.all["feedbackbox"].style.visibility = "hidden";
    document.all["bodysect"].focus();
  } else if (is_nav4up) {
    document.layers["feedbackbox"].visibility = "hide";
  }
  if (menuAutoHide) {
    autohideDiv(menuAutoHide , 1);
  }
}

function hideAllBoxes() {
  hideFeedbackBox();
  hideSearchBox();
  document.all["bodysect"].focus();
}

function toggleBit (e) {
  if (is_ie4up) {

    var clicked = e.srcElement;
    var doImg = false;

    
    var rightExp = document.fields.anchortoggleexpandicon.value;
    var downExp = document.fields.anchortoggleexpandedicon.value;
    
    //alert(rightExp);
    //alert(downExp);
     

    if (clicked.tagName == "IMG") {
      var dad = clicked.parentElement.parentElement.children.tags("DIV");
      doImg = true;

    } else {
      var dad = clicked.parentElement.children.tags("DIV");
    }

    var child = dad(0).sourceIndex;

    if (document.all[child] &&
        document.all[child].className == "level2nav") {

      if (document.all[child].style.display == "none" || 
          !document.all[child].style.display) {

        document.all[child].style.display = "block";

        if (doImg) { clicked.src = downExp; clicked.src = downExp; }

      } else {

        document.all[child].style.display = "none";
	
        if (doImg) { clicked.src = rightExp; clicked.src = rightExp; }
      
      
      }
    }
  }
}

function toggleDiv (dad) {
  if (is_ie4up) {
    doImg = 1;
    var leftImg = dad(0).parentElement.children.tags("A")(0).children.tags("IMG")(0);
    var child = dad(0).sourceIndex;
    if (document.all[child] &&
        document.all[child].className == "level2nav") {
      if (document.all[child].style.display == "none" || 
          !document.all[child].style.display) {
        document.all[child].style.display = "block";
        if (doImg) { leftImg.src = downExp;leftImg.src = downExp; }
      } else {
        document.all[child].style.display = "none";
        if (doImg) { leftImg.src = rightExp; leftImg.src = rightExp;}
      }
    }
  }
}






// CREATED BY CHRIS HARRIS 23/01/2001
function rollover(e) {

     e.cancelBubble = true;
    var i = e.srcElement;

    // Get urls for images from document
    var searchbuttonoff = document.fields.searchbuttonoff.value;
    var searchbuttonon = document.fields.searchbuttonon.value;
    var feedbackbuttonoff = document.fields.feedbackbuttonoff.value;
    var feedbackbuttonon = document.fields.feedbackbuttonon.value;
    var gobuttonoff = document.fields.gobuttonoff.value;
    var gobuttonon = document.fields.gobuttonon.value;
    var printbuttonoff = document.fields.printbuttonoff.value;
    var printbuttonon = document.fields.printbuttonon.value;


  if (i.tagName == "IMG") {

     // Check if Search
     if(i.src.indexOf("search")!= -1) {

       if(e.type == "mouseover") {

         i.src = searchbuttonon;

           } else {
             i.src = searchbuttonoff;
       }
     }

     // Check if Feedback
     if(i.src.indexOf("feedback")!= -1) {

       if(e.type == "mouseover") {

         i.src = feedbackbuttonon;

           } else {
             i.src = feedbackbuttonoff;
       }
     }

     // Check if Print
     if(i.src.indexOf("print")!= -1) {

       if(e.type == "mouseover") {

         i.src = printbuttonon;

           } else {
             i.src = printbuttonoff;
       }
     }

     // Check if Go
     if(i.src.indexOf("go")!= -1) {

       if(e.type == "mouseover") {

         i.src = gobuttonon;

           } else {
             i.src = gobuttonoff;
       }
     }

  }
}






function rollEvent(e) {
  if (is_ie4up) {
    e.cancelBubble = true;
    var i = e.srcElement;
    if (i.tagName == "IMG") {
      if (e.type == "mouseover" && i.src.indexOf("off.gif") != -1) {
        i.src = i.src.substring(0, i.src.indexOf('off.gif')) + "on.gif";
      } else if (e.type == "mouseout" && i.src.indexOf("on.gif") != -1) {
        i.src = i.src.substring(0, i.src.indexOf('on.gif')) + "off.gif";
      }
    }
  }
}

function openPrintBox() {
  if (is_ie4up) {
    if (!pWin) {
      pWin = window.open("about:blank", "printWindow", "height=480,width=640,location=no,menubar=yes,status=no,toolbar=no,resizable=yes,scrollbars=yes");
    }
    var d = pWin.document;

    var t = document.fields.PageTitle.value;

//    if (document.all["PageTitle"]) {
//      t = document.all.PageTitle.value;
//    }

//    if (document.all(1).tagName == "HTML") {
//      var title = document.all(1).children.tags("HEAD")(0).children.tags("TITLE");
//      t = title(0).text;
//    }


    d.open("text/html");
    d.writeln("<html><head><title>" + t + "</title></head>\n");
    d.writeln("<body bgcolor=\"white\" text=\"black\" onload=\"javascript:window.print()\" onunload=\"if (window.opener && window.opener.pWin) {window.opener.pWin=null}\">");
    d.writeln(document.all["bodysect"].innerHTML);
    d.writeln("</body></html>\n");
    d.close();
  }
}

function autohideDiv(n, turnOn) {
  if (document.all && document.all.tags) {
    if (shockControl && shockControl.style) {
      if (turnOn) {
        shockControl.style.visibility = "visible";
      } else {
        shockControl.style.visibility = "hidden";
      }
    } else {
      for (var s in document.all.tags("OBJECT")) {
        var dElem = document.all.tags("OBJECT")[s];
        if (dElem.id == n + "obj") { 
          if (turnOn) {
            dElem.style.visibility = "visible";
          } else {
            dElem.style.visibility = "hidden";
          }
        }
      }
    }
  }
}



