// Author: Alan Nanut

// This script may only be used for this website unless
// permission is granted by the author.


// browser dependent flags
// and initialization
var DHTML = 0;
var ns = 0;
var ie = 0;
var fx = 0;
var opera = 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 opnWindow = null;

var iFadeLow = 0;
var iFadeHigh = 100;


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



function setBrowser ()
{
  var agt = navigator.userAgent.toLowerCase ();
  
  if (iInit == 1)
    return;

  iInit = 1;

  // determine browser types and versions
  if (navigator.appName == "Microsoft Internet Explorer")
    ie = parseInt (navigator.appVersion);
  else if (navigator.appName == "Netscape")
    ns = parseInt (navigator.appVersion);
  if (agt.indexOf ("firefox") != -1)
    fx = parseInt (navigator.appVersion);
  if (agt.indexOf("opera") != -1)
    opera = parseInt (navigator.appVersion);

  // other browsers not checked, and so the Website may not be supported by them due to complex features
//  if (agt.indexOf("opera") != -1) return 'Opera';
//  if (agt.indexOf("staroffice") != -1) return 'Star Office';
//  if (agt.indexOf("beonex") != -1) return 'Beonex';
//  if (agt.indexOf("chimera") != -1) return 'Chimera';
//  if (agt.indexOf("netpositive") != -1) return 'NetPositive';
//  if (agt.indexOf("phoenix") != -1) return 'Phoenix';
//  if (agt.indexOf("firefox") != -1) return 'Firefox';
//  if (agt.indexOf("safari") != -1) return 'Safari';
//  if (agt.indexOf("skipstone") != -1) return 'SkipStone';
//  if (agt.indexOf("msie") != -1) return 'Internet Explorer';
//  if (agt.indexOf("netscape") != -1) return 'Netscape';
//  if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
//  if (agt.indexOf('\/') != -1)
//  {
//    if (agt.substr(0,agt.indexOf('\/')) != 'mozilla')
//	{
//      return navigator.userAgent.substr (0, agt.indexOf ('\/'));
//	}
//    else return 'Netscape';
//  }
//  else if (agt.indexOf(' ') != -1)
//    return navigator.userAgent.substr(0,agt.indexOf(' '));
//  else return navigator.userAgent;


  // 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 || opera)
  {
    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;
  // Firefox has a 2px narrower width
  if (fx)
    iClientWidth -= 2;
  else
    iClientWidth--;

  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 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 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 openWindow1 (sUrl, sTitle, iWndWidth, iWndHeight, iScroll)
{
  var iLeft = screen.width / 2 - iWndWidth / 2;
  var iTop = screen.height / 2 - iWndHeight / 2;

  opnWindow = window.open('','opnWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+iScroll+',resizable=no,width='+iWndWidth+',height='+iWndHeight+',left='+iLeft+',top='+iTop+'');
  opnWindow.document.open();
  opnWindow.document.write("<html><title>"+sTitle+"</title><body onBlur = 'close ();' marginwidth = '0' marginheight = '0' topmargin = '0' leftmargin = '0'><center><img src = '"+sUrl+"'></center></body></html>");
  opnWindow.document.close();
  opnWindow.focus();
}


function openWindow (sURL, iWndWidth, iWndHeight, iScroll)
{
  window.open(sURL,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars='+iScroll+',resizable=yes,width='+iWndWidth+',height='+iWndHeight+'');
}


function openWindow2 (sContent, iWndWidth, iWndHeight, iScroll)
{
  var iLeft = screen.width / 2 - iWndWidth / 2;
  var iTop = screen.height / 2 - iWndHeight / 2;

  opnWindow = window.open('','opnWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+iScroll+',resizable=yes,width='+iWndWidth+',height='+iWndHeight+',left='+iLeft+',top='+iTop+'');
  opnWindow.document.open();
  opnWindow.document.write("<html><body></body></html>");
  opnWindow.document.close();
  opnWindow.focus();
}



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;
}

