function getWindowMaxSize(res)
  {
  // assumed maximum resolution
  res.maxWidth = 640;
  res.maxHeight = 480; 

  if (document.all) { res.maxWidth = screen.width; res.maxHeight = screen.height; }
  else if (document.layers) { res.maxWidth = window.outerWidth; res.maxHeight = window.outerHeight; }
  }

function getWindowByRatio(ratio)
  {
  res = new Object();

  //initialize it
  getWindowMaxSize(res)

  // new window size
  res.Width = Math.round(res.maxWidth * ratio);
  res.Height = Math.round(res.maxHeight * ratio);

  // screen offsets
  res.xOffset = Math.round((res.maxWidth - res.Width) / 2);
  if (res.xOffset < 0) res.xOffset = 0;
  res.yOffset = Math.round((res.maxHeight - res.Height) / 2 - 40);
  if (res.yOffset < 0) res.yOffset = 0;

  return(res);
  }

function getWindowByPixels(newWidth, newHeight)
  {
  res = new Object();

  //initialize it
  getWindowMaxSize(res)

  // new window size
  res.Width = newWidth;
  res.Height = newHeight;

  // screen offsets
  res.xOffset = Math.round((res.maxWidth - res.Width) / 2);
  if (res.xOffset < 0) res.xOffset = 0;
  res.yOffset = Math.round((res.maxHeight - res.Height) / 2 - 40);
  if (res.yOffset < 0) res.yOffset = 0;

  return(res);
  }

function openWindow(URL, windowName, res)
  {
  win1 = window.open(URL,windowName, 
                     'width='+res.Width+',height='+res.Height+',screenX='+res.xOffset+',screenY='+res.yOffset+',left='+res.xOffset+',top='+res.yOffset+','+
                     'resizable=yes,dependent=yes,menubar=yes,scrollbars=yes,personalbar=yes,status=yes,alwaysRaised=yes');
  if (win1.focus) win1.focus();

  return(win1);
  }

function getBase() 
  {
  baseTag = null;
  if (document.all) baseTag = document.all.tags('base');
  //MetaDatas = document.getElementsByTagName("base");

  // If there is a BASE tag, use it
  if (baseTag && baseTag.length) 
    baseLocation = baseTag[0].href;
  else 
    baseLocation = "";

  return(baseLocation);
  }

function getHost()
  {
  if ((location.protocol.toLowerCase() == "http:") || (location.protocol.toLowerCase() == "https:"))
    Host = location.protocol + '//' + location.hostname;
  else
    {
    Host = getBase();
    SOS = Host.indexOf('://');
    if (SOS >= 0) 
      {
      SOS = Host.indexOf('/', SOS + 3);
      if (SOS >= 0) Host = Host.substring(0, SOS);
      }
    }

  return(Host);
  } 

function getMetaValue(MetaName)
  {
  MetaValue = "";

  MetaDatas = null;
  if (document.all) MetaDatas = document.all.tags('meta');
  //MetaDatas = document.getElementsByTagName("meta");
  if (MetaDatas != null)
    for (i=0; i < MetaDatas.length; i++) 
      if (MetaDatas[i].name == MetaName) 
        {
        MetaValue = MetaDatas[i].content;
        break;
        }
  
  return MetaValue;
  }
  
function getPath()
  {
  PathName = unescape(getMetaValue("PagePath"));
  if (PathName == "") PathName = unescape(location.pathname);
  
  return (PathName);
  }

function emailcell(PathName)
  {
  if (!PathName) PathName = getPath();
  params = '';
  psep = '?';
  params = params + psep + 'FileName=' + escape(PathName); psep = '&'; 

  win1 = openWindow(getHost() + '/_common/pages/emailfile.php' + params,'emailfile', getWindowByPixels(500, 500)); 
  }


function printcell(PathName)
  {
  if (!PathName) PathName = getPath();
  params = '';
  psep = '?';
  params = params + psep + 'FileName=' + escape(PathName); psep = '&'; 
  params = params + psep + 'Print=true'; psep = '&';

  win1 = openWindow(getHost() + '/_common/pages/pf.php' + params, 'printfriendly', getWindowByRatio(0.75)); 
  }

function savecell(PathName)
  {
  if (!PathName) PathName = getPath();
  params = '';
  psep = '?';
  params = params + psep + 'FileName=' + escape(PathName); psep = '&'; 

  window.location = getHost() + '/_common/pages/savefile.php' + params;
  }

function savepdf(PathName)
  {
  if (!PathName) PathName = getPath();
  params = '';
  psep = '?';
  params = params + psep + 'FileName=' + escape(PathName); psep = '&'; 

  window.location = getHost() + '/_common/pages/savepdf.php' + params;
  }

function redirectindex(PathName)
  {
  if (!PathName) PathName = getPath();
  params = '';
  psep = '?';
  params = params + psep + 'FileName=' + escape(PathName); psep = '&'; 

  window.location = getHost() + '/_common/pages/redirectindex.php' + params; 
  }

