////
//// Dreamweaver functions and other miscellaneous utilities
////

// Dreamweaver functions
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_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_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 MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_jumpMenu(targ,selObj,restore){ //v3.0 mod by rjw
  if (selObj.options[selObj.selectedIndex].value != "#") {
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
  }
}
function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

// functions to swap and restore Go button
// replace ".gif" with "_hi.gif" and vice versa
function swapGo(buttonobj) {
  var i = buttonobj.src.lastIndexOf("_hi.gif");
  if (i < 0) {
    i = buttonobj.src.lastIndexOf(".gif");
    if (i >= 0) {
      buttonobj.src = buttonobj.src.substring(0,i)+"_hi.gif";
    }
  }
}
function swapGoRestore(buttonobj) {
  var i = buttonobj.src.lastIndexOf("_hi.gif");
  if (i >= 0) {
    buttonobj.src = buttonobj.src.substring(0,i)+".gif";
  }
}

// for use with search input box that contains "Search..."
// function sets value of control to "" and sets flag so
// it doesn't happen again
// call by setting input's onfocus="searchStart(this)"
//
var searchstarted = false;
function searchStart(ctrl) {
  if (!searchstarted) {
    ctrl.value = "";
    searchstarted = true;
  }
}

// function checks if PNGs need to be fixed, and if so,
// calls correctPNG()
// (see pngfix.js)
function fixpng() {
  if (typeof needtofixpng != 'undefined' && needtofixpng)
    correctPNG();
}


////
//// open the history page
////
function openhistory() {
  newWin = window.open("history.html", "history", "width=550,height=600,scrollbars=yes,resizable=yes,left=400,top=100");
  newWin.focus();
}
////
//// open a directory popup from the reporting list
////  call from onclick of <a> tag, i.e. onclick="return popup()"
////
function popup() {
  newWin = window.open(this.href, "directory", "width=720,height=450,scrollbars=yes,resizable=yes,menubar=yes,left=450,top=100");
  newWin.focus();
	return true;
}


//// code to open/close popup boxes on org charts

// how it works:
//  When the mouse passes over one of the small boxes, it calls
//   startpopup() to open the corresponding popup and close any others
//   that might be open.
//  When the mouse leaves the box, it calls endpopup() to start a delayed
//   close of the pop-up via start_delayed_hide_popup(). The closing is delayed
//   because the mouse might be entering the popup layer. If not, then the popup
//   will either be closed by the delayed call to do_delayed_hide_popup(), or by
//   entering a different box that triggers a new popup.
//  When the mouse enters a popup, it cancels the delayed close of that
//   popup by again calling startpopup().
//  When the mouse leaves a popup, it starts the delayed close by calling endpopup().
//
//

//// globals

// variable records which popup is currently open
var open_popup = "";    // name of open popup (the layer id is derived from this)
// popups enabled flag
var popups_enabled = false;  // set to true when page loaded

// timer for delayed hide
var timerid = null;

//// functions

// enable popups
//
function enablepopups() {
  popups_enabled = false;
}

// show popup layer, hiding any previously open
//
function startpopup(popname) {
  if (popups_enabled) {
    if (timerid != null) {        // cancel any delayed hides
      clearTimeout (timerid);
      timerid = null;
    }

    if (open_popup == popname)  // return if this popup already open
      return;

    if (open_popup != "") {     // hide the old popup
      var oldpopid = "div"+open_popup+"_pop";
      MM_showHideLayers(oldpopid,'','hide');
    }

    if (popname != "") {     // show the new popup
      var newpopid = "div"+popname+"_pop";
      MM_showHideLayers(newpopid,'','show');
    }

    // record the open popup
    open_popup = popname;
  }
}

// start delayed main nav image restoration and pop-up menu hiding
//
function endpopup() {
  if (popups_enabled) {
    timerid = setTimeout("do_delayed_hide_popup()", 250); // last arg is delay in milliseconds
  }
}

// perform delayed popup hiding
//
function do_delayed_hide_popup() {
  startpopup("");
}

