// Title:   Page Support Routines
// Version: 01.00.000 - 15/04/2006
// 000-060415- Initial creation - AS

//***** Functions Present:
// displayPage()                       - Reformats the current page from plain CSS to DHTML.
// getCookie(name)                     - Returns the value of the specified cookie.
// getHeight(id)                       - Returns the specified object height attribute current setting.
// getLeft(id)                         - Returns the specified object left attribute current setting.
// getObj(name)                        - Returns the specifiec page object in the correct format for the current browser.
// getTop(id)                          - Returns the specified object top attribute current setting.
// getWidth(id)                        - Returns the specified object width attribute current setting.
// lastMod()                           - Returns how long ago the current page was modified.
// setLeft(id, pos)                    - Sets the specified object left attribute.
// setPosition(id, pos)                - Sets the specified object position attribute: absolute, releative, etc.
// setTop(id, pos)                     - Sets the specified object top attribute.
// setZOrder(is, order)                - Sets the specified object ZIndex attributute.


//*****************************************************************************
//***** Function to redisplay the main screen.
//*****************************************************************************

function displayPage(evnt)
{

	// Calculate the left position for everything.
	var LeftEdge = 0; // Default is leave alone!!
	if ( document.all ) { // IE.
		if ( window.document.body.clientWidth < 863 ) {
			LeftEdge = 0;
		} else {
			LeftEdge = window.document.body.clientWidth - 863;
			LeftEdge = LeftEdge / 2;
		}
	} else {
		if ( document.innerWidth < 863 ) {
			LeftEdge = 0;
		} else {
			LeftEdge = document.width - 863;
			LeftEdge = LeftEdge / 2;
		}
	}
	LeftEdge = LeftEdge;

	// Position up the MastHead.
	setPosition( 'masthead', 'Absolute' );
	setLeft( 'masthead', LeftEdge );	
	setTop( 'masthead', 0 );
	
	// Position up the Navigation Bar.
	setPosition( 'navbar', 'Absolute' );
	setLeft( 'navbar', LeftEdge );
	setTop( 'navbar', 40 );
	
	// Position up the Navigation Bark Marker.
	setPosition( 'navbr2', 'Absolute' );
	setLeft( 'navbr2', LeftEdge );
	setTop( 'navbr2', 55 );
	
	// Position up the Menu Box.
	setPosition( 'menubox', 'Absolute' );
	setLeft( 'menubox', LeftEdge );
	setTop( 'menubox', 59 );
	
	// Position up the Main Text.
	setPosition( 'text', 'Absolute' );
	setLeft( 'text', LeftEdge );
	setTop( 'text', 59 );
	
	// Position up the Footer.
	setPosition( 'footer', 'Absolute' );
	setLeft( 'footer', LeftEdge );
	setTop( 'footer', Math.max( parseInt(getHeight( 'menubox' )) + parseInt(getTop( 'menubox' )), parseInt(getHeight( 'text' )) + parseInt(getTop( 'text' ))));	
	
	// Position up the Section title.
	setPosition( 'section', 'Absolute' );
	setZOrder( 'section', 110 );
	setLeft( 'section', LeftEdge + getWidth( 'menubar' ));
	setTop( 'section', -65 );

}

//*****************************************************************************
//***** Function to get the value of the specified cookie.
//*****************************************************************************

function getCookie(name) 
{
	// Split cookies into an array.
	var cookies = document.cookie.split('; ');
	for ( var i = 0; i < cookies.length; i++ )
	{
		var c = cookies[i];                            // One cookie.
		var pos = c.indexOf('=');                      // Find = sign.
		var n = c.substring( 0, pos );                 // Get cookie name.
		if ( n == name )                               // If it matches,
			return c.substring( pos + 1 );             // Return value.
	}
	return null;                                       // Can't find the named cookie.
}

//*****************************************************************************
//***** Gets the specified object depending on browser type.
//*****************************************************************************

var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

//*****************************************************************************
//***** Sets the left of an object.
//*****************************************************************************

function setLeft( id, amount )
{
	if (!DHTML) return;
	var x = new getObj( id );
	x.style.left = amount + 'px';
}

//*****************************************************************************
//***** Sets the top of an object.
//*****************************************************************************

function setTop( id, amount )
{
	if (!DHTML) return;
	var x = new getObj( id );
	x.style.top = amount + 'px';
}

//*****************************************************************************
//***** Sets the positional type of an object.
//*****************************************************************************

function setPosition( id, typ )
{
	if (!DHTML) return;
	var x = new getObj( id );
	x.style.position = typ;
}

//*****************************************************************************
//***** Sets the positional z axis of an object.
//*****************************************************************************

function setZOrder( id, ord )
{
	if (!DHTML) return;
	var x = new getObj( id );
	x.style.zIndex = ord;
}

//*****************************************************************************
//***** Gets the positional top of an object.
//*****************************************************************************

function getTop( id )
{
	if (!DHTML) return;
	var x = new getObj( id );
	return( x.obj.offsetTop );
}

//*****************************************************************************
//***** Gets the height of an object.
//*****************************************************************************

function getHeight( id )
{
	if (!DHTML) return;
	var x = new getObj( id );
	
	return( x.obj.offsetHeight );	
}

//*****************************************************************************
//***** Gets the width of an object.
//*****************************************************************************

function getWidth( id )
{
	if (!DHTML) return;
	var x = new getObj( id );

	return( x.obj.offsetWidth );
}

//*****************************************************************************
//***** Gets the positional left of an object.
//*****************************************************************************

function getLeft( id )
{
	if (!DHTML) return;
	var x = new getObj( id );

	return( x.obj.offsetLeft );
}

//*****************************************************************************
//***** Returns Last modifion of current page.
//*****************************************************************************

function lastMod()
{
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	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());
	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 = '';
	if (daysago == 0) towrite += 'Today';
	else if (daysago == 1) towrite += 'Yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite;
}

//*****************************************************************************
//***** Returns the year part of a date.
//*****************************************************************************

function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

