// ##################
// Browser Detection
// ##################

// Note: Browser detection may be outside this file if
// site is heavily JS driven and different JS files are
// loaded for each browser (e.g. separate DOM / NS / IE
// files)

var ua = navigator.userAgent.toLowerCase();
var av = navigator.appVersion.toLowerCase();

// Detect browsers
blnDOM = (document.getElementById) ? true : false;      // All DOM based browsers
blnIE = (document.all) ? true : false;                  // Any IE
blnIE = blnIE && (ua.indexOf("opera") == -1);           // Make sure Opera is not detected as IE
blnIE = blnIE && (ua.indexOf("webtv") == -1);           // Make sure WebTV is not detected as IE
blnIE4 = blnIE && !blnDOM;                              // IE 4 or earlier, not DOM based
blnIE5 = (blnIE && av.indexOf("msie 5.") != -1);        // Any IE 5.x series
blnIE55 = (av.indexOf("msie 5.5") != -1);               // IE 5.5 specifically
blnIE6 = (blnIE && av.indexOf("msie 6.") != -1);        // Any IE 6.x series
blnNS = blnDOM && !blnIE;                               // DOM based, not IE - e.g. Netscape 6.0 and after
blnNS4 = (document.layers) && (av.indexOf("4.") != -1); // Netscape 4 specifically
blnGecko = (ua.indexOf("gecko") != -1);                 // Gecko based browsers
blnOpera = (ua.indexOf("opera") != -1);                 // Opera
blnFirefox = (ua.indexOf("firefox") != -1);             // Firefox
blnSafari = (ua.indexOf("safari") != -1);               // Safari (Mac)
blnKonqueror = (ua.indexOf("konqueror") != -1);         // Konqueror

// Detect operating systems
blnMac = (av.indexOf("Mac") != -1);                     // Macintosh

// Detect other browser features
blnCanPrint = (window.print) ? 1 : 0;                   // Browsers that can print

// Detect the Mozilla HTML editing component (after Mozilla 1.3)
blnMozHTMLEditor = 0;
if (ua.indexOf("mozilla") != -1 && ua.indexOf("rv:") != -1)
	{
	intVerStart = ua.indexOf("rv:");
	intVerStart = intVerStart + 3;
	intVerEnd = intVerStart + 3;
	intMozillaRev = ua.substring(intVerStart,intVerEnd);
	if (intMozillaRev > 1.3)
		{
		blnMozHTMLEditor = 1;                           // This Mozilla browser has the HTML editing component (after 1.3)
		}
	}

// Detect the Internet Explorer HTML editing component (advanced version after IE5.5)
blnIEHTMLEditor = 0;
if (blnIE)
	{
	if (!blnIE4 && !blnIE5)
		{
		blnIEHTMLEditor = 1;                            // This version of IE supports both the IE specific cm3 editor and the Mozilla-based editor
		}
	if (blnIE55)
		{
		blnIEHTMLEditor = 1;                            // This version of IE supports both the IE specific cm3 editor and the Mozilla-based editor
		}
	}

// ##################
// Website-specific Elements
// ##################

// Pre-load images for mouseovers (global images only)
if (document.images)
	{
	//an_image_off = new Image();an_image_off.src = ''; //Put path to image in quotes
	//an_image_on = new Image();an_image_on.src = ''; //Put path to image in quotes
	}

// ##################
// Windows & Alerts
// ##################

// Helps set window attributes within PopupWindow. This way the call to
// PopupWindow is a bit less confusing, e.g. can pass boolean values instead
// of all that "yes" and "no" stuff.
function SetWindowAtttribute(strDefault,varValue)
	{
	// Default value is true
	if ((strDefault == "on") || (strDefault == "yes") || (strDefault == 1) || (strDefault == "true"))
		{
		// Passed value is false
		if ((varValue == 0) && (varValue == "no") && (varValue == "false") && (varValue == "off"))
			{
			return "no";
			}
		// Passed value is anything but false
		else
			{
			return "yes";
			}
		}
	// Default value is false (anything but true)
	else
		{
		// Passed value is true
		if ((varValue == 1) && (varValue == "yes") && (varValue == "true") && (varValue == "on"))
			{
			return "yes";
			}
		// Passed value is anything but true
		else
			{
			return "no";
			}
		}
	}

// Popup any window
function PopupWindow(strURL,intWidth,intHeight,strWindowID,blnScrollbars,blnResizable,blnToolbar,blnStatus,blnLocation)
	{

	intWidth = (intWidth) ? intWidth : 500;
	intHeight = (intHeight) ? intHeight : 400;
	strWindowID = (strWindowID) ? strWindowID : "PopupWindow";

	blnScrollbars = SetWindowAtttribute("yes",blnScrollbars);
	blnResizable = SetWindowAtttribute("yes",blnResizable);
	blnToolbar = SetWindowAtttribute("no",blnToolbar);
	blnStatus = SetWindowAtttribute("yes",blnStatus);
	blnLocation = SetWindowAtttribute("no",blnLocation);

	strAttributes = "";
	strAttributes += "width="+intWidth;
	strAttributes += ",height="+intHeight;
	strAttributes += ",scrollbars="+blnScrollbars;
	strAttributes += ",resizable="+blnResizable;
	strAttributes += ",toolbar="+blnToolbar;
	strAttributes += ",status="+blnStatus;
	strAttributes += ",location="+blnLocation;

	NewWindow = window.open(strURL,strWindowID,strAttributes);

	if (window.focus)
		{
		NewWindow.focus();
		}

	// Use isLoaded if you want to be careful about users clicking on
	// javascript links before pages are fully loaded. (Browsers will
	// stop loading the page when a javascript link is clicked.)
	//if (isLoaded == 0)
	//	{
	//	location.reload();
	//	}
	}

// Useful for links from popup windows that should load in the opener
function OpenerLink(strURL)
	{
	if (top.opener)
		{
		top.opener.location.href = strURL;
		if (window.focus)
			{
			top.opener.focus();
			}
		top.close();
		}
	else
		{
		alert("The link could not be followed. Sorry!\n(You may have close the window from which\nthis window was opened, or your browser\nmay not support the required link\nfunction.)\n");
		}
	}

// Get a user to confirm the navigation action, usually used for things like "Delete"
function ConfirmNavAction(strURL,strMessage)
	{
	if(confirm(strMessage))
		{
		location= strURL;
		}
	}

// ##################
// Image Manipulation
// ##################

// Swap any image to another
function imgSwap(id,name)
	{
	if (document.images)
		{
		document.images[id].src=eval(name+".src");
		}
	}

// Swap images with an optional fade effect
// - Requires fading style to be set.
// - Only works for IE5.5+ but falls back nicely
var transitionToggle = 0;
function imgSwapFX(id,name,transitionDisable)
	{
	if (transitionDisable || !document.images[id].filters || IE50)
		{
		if (document.images)
			{
			document.images[id].src=eval(name+".src");
			}
		}
	else
		{
		document.images[id].filters[0].Apply();
		// After setting Apply, changes to the object
		// are not displayed until Play is called.

		if (transitionToggle)
			{
			transitionToggle = 0;
			document.images[id].src=eval(name+".src");
			}
		else
			{
			transitionToggle = 1;
			document.images[id].src=eval(name+".src");
			}
		document.images[id].filters[0].Play();
		}
	}

// ##################
// Layer Manipulation
// ##################

// Turn any layer on and off
function LayerToggle(togglelayer,state)
	{
	if (blnNS4)
		{
		if (document.layers[togglelayer])
			{
			document.layers[togglelayer].visibility = state;
			}
		}
	else if (blnDOM)
		{
		if (document.getElementById(togglelayer))
			{
			document.getElementById(togglelayer).style.visibility = state;
			}
		}
	else if (blnIE)
		{
		if (document.all[togglelayer])
			{
			document.all[togglelayer].style.visibility = state;
			}
		}
	}

// Turn any layer on and off
function ToggleLayer(togglelayer,state)
	{
	if (blnIE && document.all[togglelayer])
		{
		if (state)
			{
			document.all[togglelayer].style.visibility = state;
			}
		else if (document.all[togglelayer].style.visibility == "visible")
			{
			document.all[togglelayer].style.visibility = "hidden";
			}
		else if (document.all[togglelayer].style.visibility == "hidden")
			{
			document.all[togglelayer].style.visibility = "visible";
			}
		}
	else if (blnNS4 && document.layers[togglelayer])
		{
		if (state)
			{
			document.layers[togglelayer].visibility = state;
			}
		else if (document.layers[togglelayer].visibility == "show")
			{
			document.layers[togglelayer].visibility = "hide";
			}
		else if (document.layers[togglelayer].visibility == "hide")
			{
			document.layers[togglelayer].visibility = "show";
			}
		}
	else
		{
		alert('Your browser does not support this function. Sorry!');
		}
	}

// ##################
// Printing
// ##################

if (blnIE && !blnCanPrint && !blnMac) with (document)
	{
	writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	writeln('Sub window_onunload');
	writeln('    On Error Resume Next');
	writeln('    Set WB = nothing');
	writeln('End Sub');
	writeln('Sub vbPrintPage');
	writeln('    OLECMDID_PRINT = 6');
	writeln('    OLECMDEXECOPT_DONTPROMPTUSER = 2');
	writeln('    OLECMDEXECOPT_PROMPTUSER = 1');
	writeln('    On Error Resume Next');
	writeln('    WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
	writeln('End Sub');
	writeln('<' + '/SCRIPT>');
	}

function PrintPage()
	{
	if (blnCanPrint)
		{
		window.print();
		}
	else if (blnIE && !blnMac)
		{
		vbPrintPage();
		}
	else
		{
		alert("Your web browser does not appear to support the automatic\nPrint function. To print this page, please select the \"Print\"\noption from the \"File\" menu of your web browser.");
		}
	}

// ##################
// Navigation & URL Manipulation
// ##################

// Helpful for using form pull-down fields for navigation
function NavPullDown(strFormName,strFieldName,strFrameName)
	{
	intSelected = document[strFormName].elements[strFieldName].options.selectedIndex;
	strURL = document[strFormName].elements[strFieldName].options[intSelected].value;
	document[strFormName].elements[strFieldName].options.selectedIndex = 0;
	if (strURL != "")
		{
		if (strFrameName != "")
			{
			strFrameName.location.href = strURL;
			}
		else
			{
			top.location.href = strURL;
			}
		}
	}

// Gets the value part of a name/value pair in a URL querystring, i.e. just
// like request.querystring(strId) in ASP
function GetQueryStringValue(strId)
	{
	// Load the querystring

	strQuerystring = location.search;

	// Look for the ID plus an '=' sign
	strFindId = strId + "=";

	// Find the start location of the ID within the querystring
	intStart = strQuerystring.indexOf(strFindId) + strFindId.length;

	// If the start location is not larger than the length of the ID, the
	// ID was not found
	if (intStart > strFindId.length)
		{
		// Find the rest of the querystring from the start location onwards
		strRestOfQS = strQuerystring.substring(intStart,strQuerystring.length);

		// Find the beginning of the next querystring ID if there is one,
		// knowing that IDs are delimited by the '&' symbol
		intEnd = strRestOfQS.indexOf('&');

		// If there was no other querystring ID, the end of the value we
		// want is also the end of the entire querystring
		if (intEnd == -1)
			{
			intEnd = strQuerystring.length;
			}
		else
			{
			intEnd = intStart + intEnd;
			}

		// And finally get the value for the ID we found
		strValue = strQuerystring.substring(intStart,intEnd);
		}
	else
		{
		strValue = "notfound";
		}

	return strValue;
	}

// ##################
// Custom Stuff & Site Settings
// ##################

var blnNeedSpacer

// ##################
// Fun Stuff / Easter Eggs
// ##################

// No easter eggs currently present. :-)
