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


// Function to write code to display a randomly-selected photo for home page, using data from object myRandomPhoto
function myGetPhoto ( nOldImage )
{
if ( typeof(myRandomPhoto) != 'undefined' )
  {
	var o = getElement( myRandomPhoto.id );
	if ( o == null )
		return;
	if ( arguments.length < 1 )
		nOldImage = 0;
	var nImage;
	do { nImage = myRandomPhoto.stack.draw() }
		while (nImage == nOldImage);
	var sFile = myRandomPhoto.name(nImage);
	var sTitle = myRandomPhoto.aFile[nImage].text || ' ';
	var sClass = 'class="photo"';
	var ix = sFile.indexOf('=');
	if ( ix != -1 )
	  {
		sFile = sFile.substring(0,ix) + sFile.substring(ix+1);
		sClass = '';
	  }
	var sHTML = '<p class="tiny">';
	sHTML += '<img src="' + sFile + '" ' + sClass + ' onclick="myGetPhoto(' + nImage + ');" title="' + sTitle + '" alt="' + sTitle + '" />';
	sHTML += '</p>';
	o.innerHTML = sHTML;
  }
}


// Mark anchor specifified in hash
function myMarkAnchor ( )
{
var o;
if ( ((window.location.href.indexOf("archive.htm") != -1)
   )
  && (window.location.hash != '') )
  {
	var sHash = window.location.hash.substr(1);
	if ( (o = document.anchors[sHash]) != null )
	  {
		o.style.color = '#090';
	  }
	else if ( (o = getElement(sHash)) != null )
	  {
		o.style.color = '#090';
	  }
  }
}


//	Common OnLoad Function
function myCommonOnLoad( nTimeLimit )
{
if ( typeof(cPageStyle) != 'undefined' )
	oPageStyle.setActiveStylesheet();
if ( typeof(cBrowser) != 'undefined' )
	startList( "hormenu" );
if ( typeof(myFilmLibrary) != 'undefined' )
	myGallery();
myGetPhoto();
if ( typeof(kal) == 'object' )
  {
	if ( isMobileDevice() )
		calUpcomingListTournamentGames = true;
	var myCalendarType = 'grid';
	if ( typeof(myNewsAlert) != 'undefined' )
		myNewsAlert.addNews();
	if ( typeof(myPrintOnLoad) != 'undefined' )
		myCalendarType = myPrintOnLoad();
	if ( typeof(cal.toNewsHTML) != 'undefined' )
		cal.toNewsHTML();
	if ( typeof(cal.toCheckHTML) != 'undefined' )
		cal.toCheckHTML();
	if ( typeof(cal.toCalendarHTML) != 'undefined' )
		cal.toCalendarHTML( (isMobileDevice()?'list':'grid'), 'ins_calendar_dump', window.location.hash );
	if ( typeof(cal.toGamesHTML) != 'undefined' )
		cal.toGamesHTML();
	if ( typeof(cal.toTrophiesHTML) != 'undefined' )
		cal.toTrophiesHTML();
	if ( typeof(calendarTournament) != 'undefined' )
		cal.toGamesHTML( calendarTournamentID, 'T', calendarTournament );
  }
if ( typeof(mySponsorList) != 'undefined' )
	mySponsorList.insertHTML();
if ( typeof(myNewsAlertForm) != 'undefined' )
	myNewsAlertForm.initForm();
myMarkAnchor();
if ( typeof(myReportAnyBrowserUpdate) != 'undefined' )
	myReportAnyBrowserUpdate( '../../../BrowserNews/', getElement('ins_BrowserUpdate') );
aModule.alert();
}




// 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) != 'undefined') && (typeof(window.scrollTo) != 'undefined') )
	  {
		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 );
}

