/*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();

  hLink = RemoveParam( hLink, "UsingWidth" );
  //window.onresize=function(){ResizeEvent();}
  iFrameWidth = document.documentElement.offsetWidth - 51; // - 160;
  
  if ( iFrameWidth < 613 )
    iFrameWidth = 613;
    
  if(hLink && iFrameWidth>0)
  {
    if((ret = hLink.indexOf("?"))<0)
 	  hLink = hLink + "?UsingWidth=" + iFrameWidth;
    else 
  	  hLink = hLink + "&UsingWidth=" + iFrameWidth;
  }
  else
  {
  }
  if(!dmLoadRunning)
  {
      dmLoadRunning = true;
      IEhideApplets( "parent.top.ContentFrame." );
      parent.top.ShowOneMoment();
      parent.top.ContentFrame.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 IEshowApplets(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 = ''");
    }
}


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);
};

function RemoveParam( URL, Param )
{
    var rgx = eval("/" + Param + "\=[^\?\&]*/g");
    URL = URL.replace(rgx, '');
    URL = URL.replace(/\&\&/g, '&');
    URL = URL.replace(/\?\&/g, '?');
    
    return URL;
}