//	script.js - Common Javascript
//
//	Copyright (C) 1998-2010 Charles A Upsdell, All Rights Reserved; www.upsdell.com


//	Initialization

// Break out of frame
if (top.location != self.location)
	top.location = self.location;


function cVersion ( version, separator, bSkipSpace )
{
if ( arguments.length < 1 )
	version = '0';
if ( arguments.length < 2 )
	separator = '.';
if ( arguments.length < 3 )
	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 ( arguments.length < 1 )
	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 ( arguments.length < 1 )
	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 );
}


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


// Add my extra menu items
function myAddMenuItems ( arglist )
{
if ( (arguments.length == 0) || (String(window.location).indexOf('file:') != 0) )
	return;
if ( arguments.length == 1 )
  {
	var o = getElement( arguments[0] );
	if ( o )
	  {
		o.style.display = 'inline';
		o.style.color = 'green';
	  }
  }
else
  {
	for ( var i = 0; i < arguments.length; ++i )
		myAddMenuItems( arguments[i] );
  }
}


// At find.htm etc. mark anchor specifified in hash
function myMarkAnchor ( )
{
var obj;
if ( ((window.location.href.indexOf("find.htm") != -1)
  || (window.location.href.indexOf("find_other.htm") != -1)
  || (window.location.href.indexOf("store_sw.htm") != -1)
   )
  && (window.location.hash != '') )
  {
	var sHash = window.location.hash.substr(1);
	if ( (obj = document.anchors[sHash]) != null )
	  {
		obj.firstChild.style.display = 'block';
	  }
	else if ( (obj = getElement(sHash)) != null )
	  {
		obj.firstChild.style.display = 'block';
	  }
  }
}


//	Function to run after page loads
function myOnLoad ()
{
myDateModified( 'ins_DateModified', '<p class="small dim centert"><br />Page updated ', '</p>\n' );

myAddMenuItems( 'ins_ResMobile' );

if ( typeof(myBookAds) != 'undefined' )
	myBookAds();
if ( typeof(myUpcomingBookAds) != 'undefined' )
	myUpcomingBookAds();
if ( typeof(myGetQuote) != 'undefined' )
	myGetQuote();
if ( typeof(myGetQuotes) != 'undefined' )
	myGetQuotes();
if ( typeof(myItemAd) != 'undefined' )
	myItemAd();
if ( typeof(ISBN) != 'undefined' )
	ISBN.ListISBNs( 'ins_ListISBNs' );
if ( typeof(ISBN_1) != 'undefined' )
	ISBN_1.ListISBNs();
if ( typeof(ISBN_2) != 'undefined' )
	ISBN_2.ListISBNs();
if ( typeof(ISBN_2a) != 'undefined' )
	ISBN_2a.ListISBNs();
if ( typeof(ISBN_2b) != 'undefined' )
	ISBN_2b.ListISBNs();
if ( typeof(ISBN_3) != 'undefined' )
	ISBN_3.ListISBNs();
myMarkAnchor();
if ( typeof(ISBN) != 'undefined' )
	ISBN.RandomISBN( 'ins_RandomISBN' );
if ( typeof(myBrowserDetected) != 'undefined' )
	myBrowserDetected();
if ( typeof(myReportAnyBrowserUpdate) != 'undefined' )
	myReportAnyBrowserUpdate( '', getElement('ins_BrowserUpdate') );
if ( typeof(mySoftwareAds) != 'undefined' )
	mySoftwareAds();
if ( typeof(myTestAds) != 'undefined' )
	myTestAds();
if ( typeof(myTestFacts) != 'undefined' )
	myTestFacts();
if ( typeof(myJavaScriptEnabled) != 'undefined' )
	myJavaScriptEnabled();
if ( typeof(myResBrowserPage) != 'undefined' )
	myResBrowserPage();
}


// Scroll to a position, defaulting to top of page; return false if done
function myScrollTo ( left, top )
{
if ( arguments.length < 1 )
	left = 0;
if ( arguments.length < 2 )
	top = 0;
var value = true;
if ( typeof(window.scrollTo) != 'undefined' )
  {
 	window.scrollTo( left, top );
	value = false;
  }
return( value );
}


//	Insert date when file was last modified
function myDateModified ( id, prefix, suffix )
{
if ( arguments.length < 1 )
	alert( 'myDateModified() error: no arguments' );
if ( arguments.length < 2 )
	prefix = '';
if ( arguments.length < 3 )
	suffix = '';
var o = getElement( id );
if ( o )
  {
	var sHTML = '';
	if ( document.lastModified == '' )
		return;
	var theDateMs = Date.parse( document.lastModified );
	var theDate = new Date( theDateMs );
	if ( theDateMs != 0 )
	  {
		var strDate;
		if ( typeof(theDate.toLocaleDateString) != 'undefined' )
			strDate = theDate.toLocaleDateString();
		else
			strDate = theDate.toString();
		sHTML += prefix + strDate + suffix;
	  }
	o.innerHTML = sHTML;
  }
}
