// ----------------------------------------------------------------------
// Generic code and functions for use by the top level index pages
// Norwich-Pool_Index.htm and Leasure-Link_Index.htm pages.
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// In-line code. This always runs when the page including this script is
// refreshed.
// ----------------------------------------------------------------------

// -----------------
// Global variables
// -----------------

var g_strBrowser = GetBrowserVersion();

// This global variables is used as a reference to the window that is used to display forms.
var g_objFormWindow;

// This global variables is used as a reference to the window that is used to display a printer
// friendly page. This variable is updated by code in script PrintPageCode.js when the window is
// opened.
var g_objPrintWindow;

// This global variables is used as a reference to the window that is used to display the singles
// league page. This variable is updated by code in script ??? when the window is opened.
var g_objSinglesLeagueWindow;

// Redirect to an error page if NetScape or Firefox is being used.
//
if(parseInt(navigator.appVersion) >= 4)
{
	if(navigator.appName == "Netscape")
	{
		var blnFireFox = (navigator.userAgent.indexOf("Firefox") != -1);
		
		if(blnFireFox == true)
		{
			document.location = "Generic_Pages/Firefox.htm";
		}
		else
		{
			document.location = "Generic_Pages/Netscape.htm";
		};
	};
};

// Assign the OnHelp function to the onhelp event of the document.
// This has the effect of causing this function to be call whenever
// F1 is pressed. This allows us to replaces the Internet Explorer
// help with our own help page.
document.onhelp = OnHelp;

// Always initially maximize the browser window.
MaximizeWindow();

// -------------------------------
// Generic Functions
// -------------------------------

//function DisplayWaitCursor()
//{
//	document.all.item("PageContents").style.cursor = "wait";
//}
//
//function DisplayNormalCursor()
//{
//	document.all.item("PageContents").style.cursor = "auto";
//}

// Maximizes the browser window to full screen.
//
function MaximizeWindow()
{
	window.moveTo(0,0);
	window.resizeTo(screen.availWidth, screen.availHeight);
}

// This function is called when F1 is pressed.
//
function OnHelp()
{
	DisplayWebPage("Generic_Pages/HelpPage.htm");
	return false;
}

// This function is called by the menu script when a menu is clicked on.
//
function DisplayWebPage(strPageName)
{
	closeallmenus();
	document.all.item("PageContents").src = strPageName;
}

// This function is called by the menu script when a menu is clicked on.
//
function DisplayWebPageInNewWindow(strPageName)
{
	closeallmenus();
	
	// Display the contents of this page in a new window.
	// These window dimension display the window full screen.

	var strWindowDimensions = ",left=0,top=0,width=" + String(screen.availWidth - 12) + ",height=" + String(screen.availHeight - 30);
	var strFeatures			= "toolbar=yes,menubar=no,scrollbars=yes,resizable=yes" + strWindowDimensions;

	// Open the new window and set a reference to it in global variable g_objPrintWindow of the 
	// main parent page. This variable is defined in script GenericFunctions.js
	window.parent.g_objSinglesLeagueWindow = window.open(strPageName, "NorwichPoolSinglesLeague", strFeatures);
	
	// Set focus to the window. Required when the window is already open.
	window.parent.g_objSinglesLeagueWindow.focus();
}

function CloseChildWindows()
{
	// Close the window that is used to display forms.
	if(typeof(g_objFormWindow) == "object")
	{
		g_objFormWindow.close();
	};
	
	// Close the window that is used to display the print pages.
	if(typeof(g_objPrintWindow) == "object")
	{
		g_objPrintWindow.close();
	};
	
	// Close the window that is used to display the singles league pages.
	if(typeof(g_objSinglesLeagueWindow) == "object")
	{
		g_objSinglesLeagueWindow.close();
	};
	
}

// Returns the browser version.
//
function GetBrowserVersion()
{
	return navigator.appName;
}

// Returns the site name (Norwich-Pool or Leisure-Link).
//
function GetSiteName()
{
	return g_SiteName;
}

// Dislay a status message in left hand side of the web site footer
//
function DisplayStatusMessage(strMsg) 
{
	// Display a message in status bar.
	document.all.item("txtStatus").innerHTML = strMsg;
}

function SetStartUpPage(strPageName)
{
	SetCookieItem(GetSiteName(), "StartUpPage", strPageName);
}

function ResetStartUpPage()
{
	DeleteCookieItem(GetSiteName(), "StartUpPage");
}

function SetTempStartUpPage(strPageName)
{
	SetCookieItem("Temp", "StartUpPage", strPageName);
}

function DisplayStartUpPage()
{
	var strWebPage = GetCookieItem("Temp", "StartUpPage");

	if(strWebPage == "")
	{
		strWebPage = GetCookieItem(GetSiteName(), "StartUpPage");
	};

	if(strWebPage != "")
	{

		DisplayWebPage(strWebPage);
			
		DeleteCookieItem("Temp", "StartUpPage");
	};
}

// Scroll the page so that the specified HTML object is visible
// on the page.
//
function ScrollIntoView(strName)
{
	var blnRC	= false;
	var objHTML = document.all.item(strName);
		
	if( (objHTML != null) && (typeof(objHTML) == "object"))
	{
		if(typeof(objHTML.scrollIntoView) == "object")
		{
			objHTML.scrollIntoView();
			blnRC = true;
		};
	};
	
	return blnRC;
}

// Returns information about the client browser and PC.
//
function GetClientDebugInformation()
{
	return "Application Name:    " + navigator.appName + "\n" +
		   "Application Version: " + navigator.appVersion + "\n" +
           "Application Code Name: " + navigator.appCodeName + "\n" +
           "Java Enabled: " + navigator.javaEnabled() + "\n" +
           "Cookie Enabled: " + navigator.cookieEnabled + "\n" +
           "Operating System: " + navigator.platform + "\n" +
           "CPU Class: " + navigator.cpuClass + "\n" +
           "System Language: " + navigator.systemLanguage + "\n" +
           "User Language: " + navigator.userLanguage + "\n" +
           "Screen Resolution: " + screen.width + " by " + screen.height + "\n" +
           "Screen Resolution (Available): " + screen.availWidth + " by " + screen.availHeight + "\n" +
           "Screen Colour Depth: " + screen.colorDepth + "\n" +
           "Screen Font Smoothing Enabled: " + screen.fontSmoothingenabled + "\n" +
           "Window Screen Left: " + window.screenLeft + "\n" +
           "Window Screen Top: " + window.screenTop + "\n";
}

function AddToFavourites()
{
	//window.external.AddFavorite('http://www.f1dreamteam.com','&pound;50,000 Formula 1 Dream Team XXX')
	
	window.external.AddFavorite("http://www.norwich-pool.co.uk","Norwich-Pool");
}

