// ##################
// 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)

DOM = (document.getElementById) ? true : false;
NS4 = (document.layers) ? true : false;						//Netscape 4 specifically
NS6 = (!document.all && document.getElementById) ? 1 : 0;	//Netscape 6 & 7
IE = (document.all) ? true : false;							//Any IE
IE4 = IE && !DOM;											//IE4 specifically
IE5 = (IE4 && navigator.appVersion.indexOf("5.") != -1);	//Any IE 5 series
IE50 = (navigator.appVersion.indexOf("MSIE 5.0") != -1);	//IE5.0 specifically
ver4 = (NS4 || IE4 || DOM);									//Version 4 or ABOVE
isMac = (navigator.appVersion.indexOf("Mac") != -1);		//Any Mac browser
isDynamic = (DOM || NS4 || NS6 || (IE4 && !isMac) || (IE5 && isMac));
															//Any browsing supporting dHTML (Apparently... This may need work!)
canPrint = (window.print) ? 1 : 0;

// ##################
// Browser detection (admin)
// ##################

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
	}

// ##################
// Navigation
// ##################

function GoThere(frmName,fdName)
	{
	intSelected = document[frmName].elements[fdName].options.selectedIndex;
	strURL = document[frmName].elements[fdName].options[intSelected].value;
	document[frmName].elements[fdName].options.selectedIndex = 0;
	if (strURL != "")
		{
		location.href = strURL;
		}
	}

// ##################
// Windows & Alerts
// ##################

function Popup(strPage,intWidth,intHeight,strID,strScrollbars,strLocation,strToolbar,strStatus,strResizable)
	{
	if (!strPage)
		{
		strPage = "/";
		}
	if (!intWidth)
		{
		intWidth = 500;
		}
	if (!intHeight)
		{
		intHeight = 320;
		}
	if (!strID)
		{
		strID = "PopupWindow";
		}
	if (!strScrollbars)
		{
		strScrollbars = "yes";
		}
	if (!strLocation)
		{
		strLocation = "no";
		}
	if (!strToolbar)
		{
		strToolbar = "no";
		}
	if (!strStatus)
		{
		strStatus = "no";
		}
	if (!strResizable)
		{
		strResizable = "yes";
		}
	//if (isLoaded == 0)
	//	{
	//	location.reload();
	//	}
	idPopup = window.open(strPage,strID,"width="+intWidth+",height="+intHeight+",scrollbars="+strScrollbars+",location="+strLocation+",toolbar="+strToolbar+",status="+strStatus+",resizable="+strResizable);
	if (window.focus)
		{
		idPopup.focus();
		}
	}

function PopupLink(URL)
	{
	top.opener.location.href = URL;
	top.close();
	}

function CS()
	{
	alert("That function is coming soon.");
	}

function checkSiteSearchForm()
	{
	if (fmSearch.keywords.value.length == 0)
		{
		alert("Please type keyword(s) into the search form before searching.")
		return false;
		}
	}

// ##################
// Image Manipulation
// ##################

// Swap any image to another
function ImageSwap(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 ImageSwapFX(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 (NS4)
		{
		if (document.layers[togglelayer])
			{
			document.layers[togglelayer].visibility = state;
			}
		}
	else
		{
		if (document.all[togglelayer])
			{
			document.all[togglelayer].style.visibility = state;
			}
		}
	}

// ##################
// Printing
// ##################

if (IE4 && !canPrint && !isMac) 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 (canPrint)
		{
		window.print();
		}
	else if (IE4 && !isMac)
		{
		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.")
		}
	}
	
// ##################
// HTML Manipulation
// ##################

// Take a HTML string and lay it out nicely. This is not intended to be an
// advanced function, but it does make unreadable HTML code created by
// various HTML editors much easier to use.
function MakePrettyHTML(objHTML)
	{

	//allHTML = tbContentElement.DOM.body.innerHTML;
	allHTML = objHTML;

	allHTML = allHTML.replace(/<img/gi,"||<img");
	allHTML = allHTML.replace(/<br>/gi,"||<br>");
	allHTML = allHTML.replace(/<\/a>/gi,"||</a>");
	allHTML = allHTML.replace(/<em>/gi,"||<em>");
	allHTML = allHTML.replace(/<strong>/gi,"||<strong>");
	allHTML = allHTML.replace(/<b>/gi,"||<b>");
	allHTML = allHTML.replace(/<i>/gi,"||<i>");
	allHTML = allHTML.replace(/<\/td>/gi,"||</td>");
	allHTML = allHTML.replace(/<\/li>/gi,"||</li>");

	allHTML = allHTML.replace(/></gi,">\n<");

	allHTML = allHTML.replace(/\|\|<img/gi,"<img");
	allHTML = allHTML.replace(/\|\|<br>/gi,"<br>");
	allHTML = allHTML.replace(/\|\|<\/a>/gi,"</a>");
	allHTML = allHTML.replace(/\|\|<em>/gi,"<em>");
	allHTML = allHTML.replace(/\|\|<strong>/gi,"<strong>");
	allHTML = allHTML.replace(/\|\|<b>/gi,"<b>");
	allHTML = allHTML.replace(/\|\|<i>/gi,"<i>");
	allHTML = allHTML.replace(/\|\|<\/td>/gi,"</td>");
	allHTML = allHTML.replace(/\|\|<\/li>/gi,"</li>");

	allHTML = allHTML.replace(/<p/gi,"<p");
	allHTML = allHTML.replace(/<\/p>/gi,"</p>");
	allHTML = allHTML.replace(/ <\/p>/gi,"</p>");
	allHTML = allHTML.replace(/<h1/gi,"<h1");
	allHTML = allHTML.replace(/<h2/gi,"<h2");
	allHTML = allHTML.replace(/<h3/gi,"<h3");
	allHTML = allHTML.replace(/<h4/gi,"<h4");
	allHTML = allHTML.replace(/<h5/gi,"<h5");
	allHTML = allHTML.replace(/<h6/gi,"<h6");
	allHTML = allHTML.replace(/<ul/gi,"<ul");
	allHTML = allHTML.replace(/<ol/gi,"<ol");
	allHTML = allHTML.replace(/<blockquote/gi,"<blockquote");
	allHTML = allHTML.replace(/<img/gi,"<img");
	allHTML = allHTML.replace(/<font/gi,"<font");
	allHTML = allHTML.replace(/<\/font>/gi,"</font>");
	allHTML = allHTML.replace(/<a /gi,"<a ");
	allHTML = allHTML.replace(/<strong/gi,"<b");
	allHTML = allHTML.replace(/<\/strong>/gi,"</b>");
	allHTML = allHTML.replace(/<b/gi,"<b");
	allHTML = allHTML.replace(/<\/b>/gi,"</b>");
	allHTML = allHTML.replace(/<i/gi,"<i");
	allHTML = allHTML.replace(/<\/i>/gi,"</i>");
	allHTML = allHTML.replace(/<em/gi,"<em");
	allHTML = allHTML.replace(/<\/em>/gi,"</em>");
	allHTML = allHTML.replace(/<br>/gi,"<br>\n");
	allHTML = allHTML.replace(/<\/h1>/gi,"</h1>\n");
	allHTML = allHTML.replace(/<\/h2>/gi,"</h2>\n");
	allHTML = allHTML.replace(/<\/h3>/gi,"</h3>\n");
	allHTML = allHTML.replace(/<\/h4>/gi,"</h4>\n");
	allHTML = allHTML.replace(/<\/h5>/gi,"</h5>\n");
	allHTML = allHTML.replace(/<\/h6>/gi,"</h6>\n");
	allHTML = allHTML.replace(/<\/p>/gi,"</p>\n");
	allHTML = allHTML.replace(/<table(.*)>/gi,"<table$1>");
	allHTML = allHTML.replace(/<tbody/gi,"  <tbody");
	allHTML = allHTML.replace(/<tr/gi,"  <tr");
	allHTML = allHTML.replace(/<td/gi,"    <td");
	allHTML = allHTML.replace(/<\/tr>/gi,"  </tr>");
	allHTML = allHTML.replace(/<\/table>/gi,"</table>");
	allHTML = allHTML.replace(/<\/tbody>/gi,"  </tbody>");
	allHTML = allHTML.replace(/<li>/gi,"  <li> ");
	allHTML = allHTML.replace(/<\/li>/gi,"</li>\n");
	allHTML = allHTML.replace(/<\/ul>/gi,"</ul>\n");
	allHTML = allHTML.replace(/<\/ol>/gi,"</ol>\n");
	allHTML = allHTML.replace(/<\/blockquote>/gi,"</blockquote>\n");

	//allHTML = allHTML.replace(/<p><table/gi,"<table");
	//allHTML = allHTML.replace(/<\/table><\/p>/gi,"</table>\n");

	if (blnMozHTMLEditor)
		{
		// What a hack! There is a better way to do this...
		allHTML = allHTML.replace(/\n\n/gi,"\n");
		allHTML = allHTML.replace(/\n\n/gi,"\n");
		allHTML = allHTML.replace(/  /gi," ");
		}

	return allHTML;
	}
	
// ##################
// Fun Stuff / Easter Eggs
// ##################

// No easter eggs currently present. :-)
