/*V7.9*/
// Francois Simard
// Sometime in Spring 2002
// RELOAD FOR NETSCAPE ON WINDOW RESIZE
function i492()
{
  if(innerWidth != o593 || innerHeight != o559)
    location.reload();
};

if(document.layers)
  {
    o593  = innerWidth;
    o559 = innerHeight;
  }
if(document.layers)
  onresize = i492;

function MainChange(selectID)
{
  var SelectedItem = eval('document.forms[0].mnuReportList'+selectID+'.options[document.forms[0].mnuReportList'+selectID+'.selectedIndex].value')

  if(eval('document.forms[0].mnuGroupList'+selectID))
    {
      if(SelectedItem.match(/\~GROUPED=TRUE/))
        eval('document.forms[0].mnuGroupList'+selectID+'.disabled = false');
      else
        eval('document.forms[0].mnuGroupList'+selectID+'.disabled = true');
    }
};

function DisplayReport(selectID)
{
  var itemUrl = eval('document.forms[0].mnuReportList'+selectID+'.options[document.forms[0].mnuReportList'+selectID+'.selectedIndex].value');
  if(itemUrl != "")
    {
      if(itemUrl.match(/\~GROUPED=TRUE/))
      {
        var newURL = itemUrl.replace(/\~GROUPED=TRUE/,"");
        HrefGroup(newURL, eval('document.forms[0].mnuGroupList'+selectID+'.options[document.forms[0].mnuGroupList'+selectID+'.selectedIndex].value'));
      }
      else
        {
          DMLoad(itemUrl);
        }
    }
};

function HrefGroup(currentPageUrl, groupID)
{
  DMLoad(currentPageUrl + "?GroupID="+groupID);
};

var dmLoadRunning = false;

// NOTE: if you pass the URL to this function, make sure you return false if it's on the on click
//       of a <A> tag. Otherwise, you'll get a surprise in IE and Netscape 6+
// This functions set the loading div to visible.
// It crashes Mac so we are going around this
var isMac = (navigator.userAgent.indexOf('Mac') != -1) ? true : false;
function DMLoad(hLink)
{
  // Stop any loops
  Stop = true;
  
  // close the loops  
  CloseOpenLoops();
  //alert(LoopCounter);
    
  //parent.top.BottomFrame.BottomRight.document.location = hLink
  //return;
  
  if(isMac)
    {
      if(hLink)
        {
          if(parent.top.BottomFrame.BottomRight)
            if(parent.top.BottomFrame.BottomRight.DMLoadDiv) // In case we got a problem
              parent.top.BottomFrame.BottomRight.document.location = hLink;
            else
              return true;
          else
            parent.top.BottomFrame.document.location = hLink;
        }
      
      return;
    }
  else
    {
      var Message  = "<table cellspacing=0 cellpadding=0 border=0 width=~W~ height=100% bgcolor=#FFFFFF>"+
                     " <tr valign=top>"+
                     "  <td align=center><br><br><br><br><br><font style=\"font-weight: bold;  font-size: 11px;  color: black;  font-family: Arial;\">One moment please...</font></td>"+
                     " </tr>"+
                     "</table>";
    
      if( document.all && (window.name == "BottomRight" || (window.name == 'BottomFrame' && !parent.top.BottomFrame.BottomRight)))
        {
          if(window.name == "BottomRight")
            Message = Message.replace(/~W~/, "690");
          else
            Message = Message.replace(/~W~/, "100%");

          // if IE, Hide all the applets and Forms and print a DIV with the loading message in it
          IEhideApplets('');
          IEhideForms('');
          var topPos = 0 + document.body.scrollTop;
          document.body.insertAdjacentHTML('beforeEnd', '<div id="dmLoadDiv" style="position:absolute;left:0;top:'+topPos+';width:100%;height:100%;z-index:999;">' + Message + '</div>');
          if(hLink)
            {
              window.location = hLink;
              return false;
            }
          return true;
        }
      else
        {
          if(document.all) // If IE, call the function from the bottom right frame
            {
              if(parent.top.BottomFrame.BottomRight)
                if(parent.top.BottomFrame.BottomRight.DMLoadDiv) // In case we got a problem
                  parent.top.BottomFrame.BottomRight.DMLoad(hLink);
                else
                  return true;
              else
                parent.top.BottomFrame.DMLoad(hLink);
            }
          else
            {
              // Get the top right frame to overwrite the bottom right html code and change it's location
              if(!dmLoadRunning)
                {
                  var frameCall = "";
                  dmLoadRunning = true;
                  if(window.name == "BottomRight")
                    {
                      parent.top.TopFrame.TopRight.DMLoad(hLink);
                      return;
                    }
                  else
                    {
                      if(parent.top.BottomFrame.BottomRight)
                        {
                          Message = Message.replace(/~W~/, "690");
                          parent.top.BottomFrame.BottomRight.document.write(Message);
                          if(hLink)
                            parent.top.BottomFrame.BottomRight.location = hLink;
                        }
                      else
                        {
                          Message = Message.replace(/~W~/, "100%");
                          parent.top.BottomFrame.document.write(Message);
                          if(hLink)
                            parent.top.BottomFrame.location = hLink;
                        }
                    }
    
                  dmLoadRunning = false;
                  return true;
                }
            }
        }
    }
};

function IEhideApplets(frameCall)
{
  if(document.all)
    {
      var arrLen = eval(frameCall+"document.applets.length");
      for(var i=0;i<arrLen;i++)
        eval(frameCall+"document.applets["+i+"].style.visibility = 'hidden'");
    }
}

function IEhideForms(frameCall)
{
  if(document.all)
    {
      var arrLen = eval(frameCall+"document.forms.length");
      for(var i=0;i<arrLen;i++)
        eval(frameCall+"document.forms["+i+"].style.visibility = 'hidden'");
    }
}

// This image should not change on mouseover because it is the active one
/*var activeImage = '';
var activeId; */

// Mouse over function for report Headers
function moHeader(iName, ind, mo)
{
  var iState = '';
  if(mo)
    iState = 'MO';
  eval("document." + iName + ind + ".src = "+ iName + "Img" + iState + ".src");
};

// Called when going to another page
// Show the loading div before going somewhere else
function aClick()
{
  if(document.layers)
    { document.layers['loading'].visibility = 'visible'; }
  else
    {
      if(document.all)
        document.all.loading.style.visibility = 'visible';
      else
        document.getElementById('loading').style.visibility = 'visible';
    }
};

// Used by the DMui.MouseOver class
function dmMO(iName, ind, mo, lay)
{
  if( iName != activeImage)
    {
      var netCode = '';
      if(mo)
        ind++;

      if(document.layers)
        {
          if(lay)
            netCode = "document.layers['" + lay + "'].";
          eval(netCode + "document.images['" + iName + "'].src = '" + dmMOArr[ind].src + "'");
        } 
      else
        {
          eval("document." + iName + ".src = '" + dmMOArr[ind].src + "'");
        }
    }
};

// Set the image active and keep it from changing on mouseover
function SetActive(iName, ind, lay)
{
  if(activeImage != iName)
    {
      if(document.layers)
        {
          var netCode = '';
          if(lay)
            netCode = "document.layers['" + lay + "'].";
          eval(netCode + "document.images['" + iName + "'].src = '" + SelImages[iName].src + "'");
          
          netCode = "document.layers['" + activeLayer + "'].";
          if(activeImage != '')
            eval(netCode + "document.images['" + activeImage + "'].src = '" + dmMOArr[activeId].src + "'");
        }
      else
        {
          if(document.all)
            eval("document.all." + iName + ".src = '" + SelImages[iName].src + "'");
          else
            eval("document." + iName + ".src = '" + SelImages[iName].src + "'");
          if(activeImage != '')
            eval("document." + activeImage + ".src = '" + dmMOArr[activeId].src + "'");
        }


      activeImage = iName;
      activeId    = ind;
      activeLayer = lay;
    }
  this.parent.focus();
};

/* Resizing Stuff: */

var macIe = (navigator.userAgent.indexOf('Mac') != -1 && navigator.appVersion.indexOf('MSIE 5') != -1) ? true : false;
var macIe5 = (macIe && navigator.appVersion.indexOf('MSIE 5') != -1) ? true : false;

// Get the image left value IE ONLY
function getRealLeft(zName)
{
	xPos   = eval('document.'+zName+'.offsetLeft');
	(macIe && !macIe5) ? tempEl = eval('document.'+zName+'.parentElement') : tempEl = eval('document.'+zName+'.offsetParent');
  	while (tempEl != null) 
    	{
    		xPos  += tempEl.offsetLeft;
    	  (macIe && macIe5) ? tempEl = tempEl.parentElement : tempEl = tempEl.offsetParent;
    	}
   return xPos;
};

// Get the image top value IE ONLY
function getRealTop(zName)
{
  yPos   = eval('document.'+zName+'.offsetTop');
	(macIe && !macIe5) ? tempEl = eval('document.'+zName+'.parentElement') : tempEl = eval('document.'+zName+'.offsetParent');
	while (tempEl != null)
	  {
  		yPos  += tempEl.offsetTop;
  		(macIe && !macIe5) ? tempEl = tempEl.parentElement : tempEl = tempEl.offsetParent;
  	}
  if(macIe && !macIe5)
    yPos-=20;
	return yPos;
};

// When called on the onload, it resize the window so that it gets as small as it can without having to scroll.
// An image called formImage must be place at the very bottom right side of the screen.
// If the window has a toolbar, set the parameter to true. Otherwise, set it to false
function ResizeThisWin(gotToolbar)
{
  // Don't make the window too big
  var maxHeight = 500;
  var maxWidth  = 500;

  //Get the image position
  var leftPos = (document.layers) ? document.images['formImage'].x : getRealLeft('formImage');
  var topPos  = (document.layers) ? document.images['formImage'].y : getRealTop('formImage');

  if(leftPos > maxWidth)
    leftPos = maxWidth;

  if(topPos > maxHeight)
    topPos = maxHeight;

  if(gotToolbar)
    window.resizeBy(leftPos-GSW(), topPos-GSH()); //ResizeBy add the value you pass to the window's current size
  else
    window.resizeTo(leftPos, topPos);
};