//	Common Javascript - Copyright (C) 2003-2008 Charles A Upsdell, All Rights Reserved; www.upsdell.com


//	Init

function cVersion ( version, separator, bSkipSpace )
{
if ( version === undefined )
	version = '0';
if ( separator === undefined )
	separator = '.';
if ( bSkipSpace === undefined )
	bSkipSpace = false;
if ( version instanceof cVersion )
  {
	this.separator = (arguments.length < 2) ? version.separator : separator;
	this.v = new Array();
	this.v = version.v;
  }
else
  {
	var s = ( typeof(version) == 'number' ) ? version.toString() : version;
	this.separator = separator;
	this.v = new Array();
	var vindex = 0;
	var sindex = 0;
	var c;
	this.v[vindex] = '';
	if ( bSkipSpace) for ( ; sindex < s.length; ++sindex )
	  {
		c = s.charAt(sindex);
		if ( c != ' ' )
			break;
	  }
	for ( ; sindex < s.length; ++sindex )
	  {
		c = s.charAt(sindex);
		if ( c == separator )
			this.v[++vindex] = '';
		else if ( (c >= '0') && (c <= '9') )
			this.v[vindex] += c.toString();
		else
			break;
	  }
  }
return;
}


cVersion.prototype.toString = function ( separator )
{
if ( separator === undefined )
	separator = this.separator;
var result = '';
for ( var i = 0; i < this.v.length; ++i )
  {
	if ( i == 0 )
		result += this.v[0];
	else
		result += separator + this.v[i];
  }
return( result );
}


cVersion.prototype.comp = function ( version2 )
{
var operand;
if ( version2 === undefined )
	version2 = '0';
if ( version2 instanceof cVersion )
	operand = version2;
else
	operand = new cVersion( version2 );
var nLoops = Math.max( this.v.length, operand.v.length );
var result = 0;
for ( var i = 0; i < nLoops; ++i )
  {
	var n1 = Number( (i < this.v.length) ? this.v[i] : 0 );
	var n2 = Number( (i < operand.v.length) ? operand.v[i] : 0 );
	if ( n1 == n2 )
		continue;
	else if ( n1 < n2 )
		{ result = -1; break; }
	else
		{ result = 1; break; }
  }
return( result );
}


function cBrowser ( ua, ua_version )
{
ua = ua || navigator.userAgent;
ua_version = ua_version || navigator.appVersion;
this.arg1 = ua;
this.arg2 = ua_version;
this.UA = ua.toLowerCase();
this.isK = (this.UA.indexOf("khtml") != -1);
this.isO = (this.UA.indexOf("opera") != -1);
this.isG = !this.isK && !this.isO && (this.UA.indexOf("gecko/") != -1);
this.isN = !this.isO && ((this.UA.indexOf('mozilla')!=-1) && ((this.UA.indexOf('spoofer')==-1)
	&& (this.UA.indexOf('compatible') == -1)));
this.isW = (this.UA.indexOf("webtv") != -1);
this.isIE = !this.isW && !this.isO && (this.UA.indexOf("msie") != -1);
this.v = new cVersion( this.arg2, '.', true );
if ( this.isN && (this.v.comp(5)>=0) )
	this.isG = true;
else if ( this.isIE )
	this.v = new cVersion(this.UA.substring(4+this.UA.indexOf("msie")),'.',true);
else if ( this.isO )
  {
	if ( this.UA.indexOf('version/') != -1 )
		this.v = new cVersion(this.UA.substring(8+this.UA.indexOf("version/")));
	else if ( this.UA.indexOf('opera/') == 0 )
		this.v = new cVersion(this.UA.substring(1+this.UA.indexOf("/")));
	else if ( this.UA.indexOf("opera/") != -1 )
		this.v = new cVersion(this.UA.substring(2+this.UA.indexOf(")")));
	else
		this.v = new cVersion(this.UA.substring(6+this.UA.indexOf("opera/")));
  }
return;
}


String.prototype.alert = function ( method, arglist )
{
var errmsg = this;
errmsg += (method == '') ? '()' : ('.' + method + '()');
errmsg += ' error: ' + arguments[1];
for ( var i = 2; i < arguments.length; ++i )
	errmsg += ((i == 2 ) ? ': ' : ', ' ) + arguments[i];
alert( errmsg );
}


// Function to write code to enable links to the Photos page
function myEnablePhotos ( id )
{
id = id || 'photos_menuitem';
var o = getElement( id );
if ( o == null )
	return;
o.style.display = 'block';
}


var myBrowser = new cBrowser();
if ( (typeof(myBrowser)=='object') && ((myBrowser.isIE && (myBrowser.v.comp('5')>=0)) || myBrowser.isG || myBrowser.isK || (myBrowser.isO && (myBrowser.v.comp('7')>=0))) )
	; // browser is modern
else if ( (typeof(myBrowser)!='object') || myBrowser.isIE || myBrowser.isN || myBrowser.isO )
	alert( 'Sorry, this site is not designed for ancient browsers' );

//	End init


function myInsertPhoto ( sPhoto, id )
{
$name = 'myInsertPhoto';
if ( sPhoto === undefined )
	$name.alert( '', 'photo name missing' );
id = id || 'ins_enlargement';
var o = getElement( id );
if ( o == null )
	return( true );
var sHTML = '<img src="' + sPhoto + '" />';
o.innerHTML = sHTML;
return( false );
}


function startList ( id_list )
{
if ( myBrowser.isIE && (myBrowser.v.comp('7')<0) )
  {
	for ( var i = 0; i < arguments.length; ++i )
	  {
		var id = arguments[i];
		navRoot = document.getElementById(id);
		if ( navRoot == null )
			continue;
		for ( var j = 0; j < navRoot.childNodes.length; ++j )
		  {
			node = navRoot.childNodes[j];
			if (node.nodeName=="LI")
			  {
				node.onmouseover=function() { this.className+=" over"; }
				node.onmouseout=function() { this.className=this.className.replace(" over", ""); }
			  }
		  }
	  }
  }
}


// getElement - get element associated with an ID, or null if not found
function getElement ( id )
{
var element = null;
if ( (arguments.length == 0) || (id == "") )
	return( null );
if ( document.getElementById )
	element = document.getElementById( id );
else if ( document.all )
	element = document.all[id];
return( element );
}


// Scroll to an anchor; return false
function myScrollToAnchor ( id )
{
id = id || window.location.hash;
if ( id.indexOf('#') == 0 )
	id = id.substring(1);
var o = getElement( id );
if ( o )
  {
	if ( (typeof(o.offsetTop) !== typeof(nosuchvalue)) && (typeof(window.scrollTo) !== typeof(noSuchFunction)) )
	  {
		var x = 0;
		var y = 0;
		while ( o )
		  {
			x += o.offsetLeft;
			y += o.offsetTop;
			o = o.offsetParent;
		  }
		window.scrollTo( x, y );
	  }
	else
		window.location.replace( '#' + id );
  }
return( false );
}


// Scroll to a position, defaulting to top of page; return false if done
function myScrollTo ( left, top )
{
left = left || 0;
top = top || 0;
var value = true;
if ( typeof(window.scrollTo) !== typeof(noSuchFunction) )
  {
 	window.scrollTo( left, top );
	value = false;
  }
return( value );
}


