// Author: Alan Nanut, ATS, York University
// Generalized routines



// browser dependent flags
// and initialization
var DHTML = 0;
var ns = 0;
var ie = 0;
var use_features = 0;
var useFade = 0;
var set_show;
var set_hide;
var iClientWidth;
var iClientHeight;
var iScreenWidth;
var iScreenHeight;
var iInit = 0;

var iFadeLow = 0;
var iFadeHigh = 100;


/************************* GENERAL ROUTINES */



function setBrowser ()
{
  if (iInit == 1)
    return;

  iInit = 1;

  // determine browser versions
  if (navigator.appName == "Microsoft Internet Explorer")
    ie = parseInt (navigator.appVersion);
  else if (navigator.appName == "Netscape")
    ns = parseInt (navigator.appVersion);

  // browser-specific visibility flags
  set_show = (ns) ? 'show' : 'visible';
  set_hide = (ns) ? 'hide' : 'hidden';

  if (ns >= 5)
  {
    set_show = 'visible';
    set_hide = 'hidden';
  }

  // determine applicable features
  if (ie >= 4 || ns >= 5)
  {
    use_features = 1;
    useFade = 1;
  }
  else if (ns >= 4)
    use_features = 2;
  else
    use_features = 0;


  iClientWidth = (ns) ? window.innerWidth - 14 : document.body.offsetWidth - 20;
  iClientHeight = (ns) ? window.innerHeight : document.body.offsetHeight;

  iScreenWidth = screen.width;
  iScreenHeight = screen.height;

  DHTML = (document.getElementById || document.all || document.layers);

  if (!DHTML)
  {
    alert ("This page requires a browser that supports dynamic html (DHTML).  Try disabling JavaScript within your browser in order to view this website.  This window will now close.");
    window.close ();
  }
}



function checkClientArea ()
{
  if (ns)
  {
    if ((window.innerWidth - 14 != iClientWidth) ||
        (window.innerHeight != iClientHeight))
    {
      iClientWidth = window.innerWidth - 14;
      iClientHeight = window.innerHeight;
      return 1;
    }
  }
  else if ((document.body.offsetWidth - 20 != iClientWidth) ||
           (document.body.offsetHeight != iClientHeight))
  {
    iClientWidth = document.body.offsetWidth - 20;
    iClientHeight = document.body.offsetHeight;
    return 1;
  }

  return 0;
}


function checkScreenArea ()
{
  if ((screen.width != iScreenWidth) ||
      (screen.height != iScreenHeight))
  {
    iScreenWidth = screen.width;
    iScreenHeight = screen.height;
    return 1;
  }

  return 0;
}

function screen_adjust ()
{
    document.location.reload ();
    return;
}

function hideBorder (obj)
{
  if (use_features == 1 && ie)
    obj.blur ();
}

function abs (iInt)
{
  if (iInt < 0)
    iInt = -iInt;

  return iInt;
}


function parseHref (sDelimiter)
{
  var iStart = location.href.indexOf (sDelimiter);
  var sParams = location.href.slice (iStart + sDelimiter.length);
  return sParams;
}

function nothing ()
{
  return;
}


function setOpacity (fadeObj, iField, iOpacity, iFadeObj, iFadeEnd)
{
  var iIndex;

  for (iIndex = iFadeObj; iIndex <= iFadeEnd; iIndex++)
  {
    if (fadeObj[iIndex][iField].filters)
      fadeObj[iIndex][iField].filters.alpha.opacity = iOpacity; 
    else if (fadeObj[iIndex][iField].style.MozOpacity)
      fadeObj[iIndex][iField].style.MozOpacity = iOpacity / 100; 
  }

  if (iOpacity >= iFadeHigh)
    return iFadeHigh;
  else if (iOpacity <= iFadeLow)
    return iFadeLow;

  return iOpacity;
}


