// script utility functions
// (c) 2005 PCAvionics
// LANGUAGE="JavaScript1.2"

var isIE = -1 != navigator.appName.indexOf("Microsoft Internet Explorer");
var isNS = -1 != navigator.appName.indexOf("Netscape");

// my object representing attributes of the browser
var Browser = new Object(); 

// my object representing attributes of the main window
var MainWindow = new Object();

function analyzeEnvironment()
{
  if ( !isIE )  
  {
    MainWindow.width = MainWindow.innerWidth;
    MainWindow.height = MainWindow.innerHeight;
  } 
  if ( isIE )
  {
    if (document.compatMode && document.compatMode != "BackCompat")
    {
      MainWindow.width = document.documentElement.clientWidth;
      MainWindow.height = document.documentElement.clientHeight;
    } else
    {
      MainWindow.width = document.body.clientWidth;
      MainWindow.height = document.body.clientHeight;
    }
  }
}

function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function lastMod(dateint, sfx)
{
//  alert( "lastMod got "+dateint );

	var x; // = new Date (document.lastModified);
	Modif = new Date(dateint);
//  return "modified: "+Modif;

	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
//  return "today: "+x+", modified: "+Modif;

	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730)
	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60)
	{
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14)
	{
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'Page last changed ';
	if (daysago == 0) towrite += 'today';
	else if (daysago == 1) towrite += 'yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite+sfx;
}

function onResize() {} // dummy function for replacement by the actual page

function _onResize()
{
  analyzeEnvironment();
  var vsize = (MainWindow.height-85-20-20);
  var obj = document.getElementById("BodyRow");
  //alert("vsize="+vsize+", obj="+obj);
  if ( isIE )
  {
    obj.style.height=vsize;
  } else
  {
    obj.innerHeight=vsize;
  }

  onResize();
}

function onLoad() {} // dummy function for replacement by the actual page

function _onLoad()
{
  analyzeEnvironment();
//if ( isIE ) 
//{ alert( "IE" ); }
//else if ( isNS ) { alert("NS"); }
//else { alert("Unknown browser type: "+Window.navigator.appName); }
  if ( onLoad ) onLoad();
  _onResize();
}

// function to emit an email address in a way that's not searchable by crawlers
function emitAddr(un)
{
 var ema = un;
 ema += "@";
 ema += "pcavionics";
 ema += ".com";
 document.write( "<A HREF=\"mailto:" + ema + "\">" + ema +"</A>" );
}

function getObj(name)
{
  var ths = new Object();
  if (document.getElementById)
  {
  	ths.obj = document.getElementById(name);
        if ( ths.obj.style )
          ths.style= ths.obj.style;
        else
	  ths.style = new Object();
  }
  else if (document.all)
  {
	ths.obj = document.all[name];
	ths.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	ths.obj = document.layers[name];
   	ths.style = document.layers[name];
  }
  return ths;
}

