// ############################################################################
// ##
// ##  CUSTOM WEBSITE FUNCTIONS
// ##  (i.e. not standard white site functions)
// ##
// ############################################################################

// ====================
// Function:    getObj
//
// Purpose:     Returns string for access to passed in object style attributes
//
// Input:       ID of object
//
// Output:      Returns string for access to passed in object style attributes
//
// Assumptions: -
//
// History:     SC 2006-05-15
function getObj(name) 
{
	if (document.getElementById) 
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} 
	else if (document.all) 
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} 
	else if (document.layers) 
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}


// ====================
// Function:    ReturnWindowHight
//
// Purpose:     Returns the height of the client window
//
// Input:       None
//
// Output:      Returns the height of the client window
//
// Assumptions: -
//
// History:     SC 2006-05-15
function ReturnWindowHeight(windowRef) 
{
	var intHeight = -1;
	if (!windowRef) {
		windowRef = window;
	}
	if (typeof(windowRef.innerWidth) == 'number') {
		intHeight = windowRef.innerHeight;
	}
	if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number') {
		intHeight = windowRef.document.body.clientHeight;
	}

	//if (height == 0) {
	//	intHeight = window.innerHeight;
	//}
	return intHeight;
}

// ====================
// Function:    GetObjectHeight
//
// Purpose:     Returns the height of any passed in block level object
//
// Input:       ID of item
//
// Output:      Returns the height of any passed in block level object
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function GetObjectHeight(objectRef)
{
	var intHeight = -1;

	if (document.getElementById)
	{
		if (document.getElementById(objectRef))
		{
			intHeight = eval(document.getElementById(objectRef).offsetHeight);
		}
	}
	else if (document.all)
	{
		if (document.all[objectRef])
		{
			intHeight = document.all[objectRef].scrollHeight;
		}
	}
	else if (document.layers)
	{
		if (document[objectRef])
		{
			intHeight = document[objectRef].clip.bottom;
		}
	}

	return intHeight;
}

// ====================
// Function:    SetUniformHeight
//
// Purpose:     Sets a number of page objects to a uniform height, being the
//              maximum height of any of the given objects.
//
// Input:       strPageObjects - Comma separated list of object IDs that should
//              be set to a uniform height.
//
// Output:      Updates the height of the given objects.
//
// Assumptions: GetObjectHeight()
//
// History:     20060823 RW Created
// ====================
function SetUniformHeight(strPageObjects) {
	
	intMaxHeight = 0;

	if (strPageObjects) {
		arrPageObjects = strPageObjects.split(",");
	}

	if (arrPageObjects) {
		// Find the height of the tallest object.
		for (i = 0; i < arrPageObjects.length; i++) {
			intThisHeight = GetObjectHeight(arrPageObjects[i]);
			if (intThisHeight > intMaxHeight) {
				intMaxHeight = intThisHeight;
			}
		}

		// Set all the objects to the same (maximum) height if a height larger
		// than 0 was found.
		if (intMaxHeight > 0 ) {
			for (i = 0; i < arrPageObjects.length; i++) {
				strMaxHeight = intMaxHeight + 'px';
				if(document.getElementById(arrPageObjects[i])) {
					document.getElementById(arrPageObjects[i]).style.height = strMaxHeight;
				}
			}
		}
	}
}

// Put custom functions for your website here.

function ClearUsernamePassword(strFormID)
{
	if (gblnDefaultUsernamePassword)
	{
		if (document.forms[strFormID]) 
		{
			document.forms[strFormID].username.value='';
		}
		if (document.forms[strFormID]) 
		{
			document.forms[strFormID].password.value='';
		}
		gblnDefaultUsernamePassword = false;
	}
}


//Form Submission Validation - 20051206 GR - added for DOE extranet form as standard validation method

function cm3ValidateForm(formname)
{
	// use "standard" cmFields field value to make JS cm3 form validation. It will show JS
	// popup with list of all errors found and returns true or false. One can use it on submit
	// button like <input type="submit" value="GO" onClick="return cm3ValidateForm('myform');">
	var validation_errors = "";
	var arrFields;
	if ( document.forms[formname].cmFields.length ) {
		arrFields = document.forms[formname].cmFields;
	} else {
		arrFields = document.forms[formname].cmFields.value.split(",");
	}
	//alert("formname="+formname+" length="+arrFields.length);
	for (var i = 0; i < arrFields.length; i++) {
		// just in case if cmFields definitions had "," inside:
		var arrFields1 = trim(arrFields[i].value).split(",");
		for (var j = 0; j < arrFields1.length; j++) {
			var arrFields2 = trim(arrFields1[j]).split(";");
			var fieldName = "";
			var fieldRequired = "0";
			var fieldLabel = "";
			var fieldType = "text";
			if ( arrFields2.length == 4 ) {
				fieldName = arrFields2[0];
				fieldRequired = arrFields2[1];
				fieldLabel = arrFields2[2];
				fieldType = arrFields2[3];
			} else if ( arrFields2.length == 1 ) {
				fieldName = arrFields2[0];
				fieldLabel = arrFields2[0];
			} else {
				// we should never be here
				alert("i="+i+" j="+j+" field="+trim(arrFields1[j])+" length="+arrFields2.length);
				fieldName = arrFields2[0];
				fieldLabel = arrFields2[0];
			}
			var error = cm3ValidateField(formname,fieldName,fieldRequired,fieldType);
			if ( error ) {
				validation_errors += fieldLabel + ": " + error + "\n";
			}
		}
	}
	if ( validation_errors ) {
		alert(validation_errors);
		return false;
	} else {
		//return false;
		return true;
	}
}

function cm3ValidateField(formname,fieldName,fieldRequired,fieldType)
{
	var error = "";
	if ( document.forms[formname].elements[fieldName] ) {
		if ( document.forms[formname].elements[fieldName].length  ) {
			// this is an array
			fieldValue = GetSelectedCheckboxValues(document.forms[formname].elements[fieldName]);
		} else {
			fieldValue = document.forms[formname].elements[fieldName].value;
		}
		if ( fieldValue ) {
			// add other specific validation types below
			if ( fieldType == "email" && !isEmail(fieldValue) ) {
				error = fieldValue + " is not valid email address";
			} else if ( fieldType == "number" && !isNumber(fieldValue) ) {
				error = fieldValue + " is not valid number";
			} else if ( (fieldType == "date" || fieldType == "cmdate" ) && !isDate(fieldValue) ) {
				error = fieldValue + " is not valid date in yyyy-mm-dd format";
			}
		} else if ( fieldRequired == "1" || fieldRequired == "3" ) {
			error = " is required field";
		}
	}
	return error;
}

function trim(str)
{
	if ( str ) {
		return str.replace(/^\s*|\s*$/g,"");
	} else {
		return "";
	}
}

// yyyy-mm-dd
function isDate(s) {
    if (!(/^\d{4,4}-\d{2,2}-\d{2,2}$/.test(s))) { return false; }
    var a = s.split("-");
    var d = new Date(a[0], Number(a[1])-1, a[2]);
    d = [d.getFullYear().toString(), (d.getMonth()+1).toString(), d.getDate().toString()];
    if (!d[0].length || !d[1].length || !d[2].length) { return false; }
    if (d[1].length == 1) { d[1] = "0"+d[1]; }
    if (d[2].length == 1) { d[2] = "0"+d[2]; }
    return a[0] == d[0] && a[1] == d[1] && a[2] == d[2];
}

// -0.01, 10, 10.45 	- ok
//  01, 00.1, .1, 0.0.0	- bad
function isNumber(s) {
    if (s.length && s.charAt(0) == "-") { return isNumber(s.substr(1)); }
    if (!(/^[\d.]+$/.test(s))) { return false; }
    if (s.indexOf(".") != -1 && (s.indexOf(".") != s.lastIndexOf("."))) { return false; }
    if (s.charAt(0) == ".") { return false; }
    if (s.length >= 2 && s.charAt(0) == "0" && s.charAt(1) != ".") { return false; }
    return !isNaN(s);
}

function isEmail(email)
{
	if ( ! email ) {
		return false;
	} else {
		if ( /^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$/.test(email) ) {
			return true;
		} else {
			return false;
		}
	}
}

function GetSelectedCheckbox(buttonGroup)
{
	// Go through all the check boxes. return an array of all the ones
	// that are selected (their position numbers). if no boxes were checked,
	// returned array will be empty (length will be zero)
	var retArr = new Array();
	var lastElement = 0;
	if (buttonGroup[0])
	{ // if the button group is an array (one check box is not an array)
		for (var i=0; i<buttonGroup.length; i++)
		{
			if (buttonGroup[i].checked)
			{
				retArr.length = lastElement;
				retArr[lastElement] = i;
				lastElement++;
			}
		}
	}
	else
	{ // There is only one check box (it's not an array)
		if (buttonGroup.checked)
		{ // if the one check box is checked
			retArr.length = lastElement;
			retArr[lastElement] = 0; // return zero as the only array value
		}
	}
	return retArr;
}

function GetSelectedCheckboxValues(buttonGroup)
{
	// return a comma separated list of values for selected in the check box group.
	var retStr = "";
	var comma = "";
	var selectedItems = GetSelectedCheckbox(buttonGroup);
	if (selectedItems.length != 0)
	{ // if there was something selected
		for (var i=0; i<selectedItems.length; i++)
		{
			if (buttonGroup[selectedItems[i]])
			{ // Make sure it's an array
				retStr = retStr + comma + buttonGroup[selectedItems[i]].value;
				comma = ",";
			}
			else
			{ // It's not an array (there's just one check box and it's selected)
				retStr = buttonGroup.value;// return that value
			}
		}
	}
	return retStr;
}

// ############################################################################
// ##
// ##  STANDARD WHITE SITE FUNCTIONS
// ##
// ############################################################################

// ####################################
// Navigation
// ####################################

// ====================
// Function:    NavPullDown
//
// Purpose:     Go to a URL that is selected from a form a pull-down form field
//
// Input:       strFormName - The ID of the form being used to select naviation
//              strFieldName - The ID of the field with URL select options
//
// Output:      Navigates to selected URL.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function NavFormSelect(strFormName,strFieldName)
{
	intSelected = document[strFormName].elements[strFieldName].options.selectedIndex;
	strURL = document[strFormName].elements[strFieldName].options[intSelected].value;
	document[strFormName].elements[strFieldName].options.selectedIndex = 0;
	if (strURL != "")
	{
		location.href = strURL;
	}
}

// ====================
// Function:    InitNav
//              Note: InitNav must be called after menu list is created.
//
// Purpose:     Assigns classes to certain events for Internet Explorer 6.
//              (IE6 does not fully support CSS standards.)
//
// Input:       -
//
// Output:      -
//
// Assumptions: -
//
// History:     200512 Code from htmldog.com
//              200512 RW Turned into a function for nicer modularity
// ====================
function InitNav(strListID)
{
	sfHover = function()
	{
		var sfEls = document.getElementById(strListID).getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++)
		{
			sfEls[i].onmouseover=function()
			{
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function()
			{
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}

	// Only executes in IE
	if (window.attachEvent)
	{
		window.attachEvent("onload", sfHover);
	}
		
}

// ####################################
// Windows & Alerts
// ####################################

// ====================
// Function:    Popup
//
// Purpose:     Open a popup window with a series of option settings.
//
// Input:       strPage - The URL of the page to open in the popup window.
//              intWidth - The window width in pixels 
//              intHeight - The window height in pixels
//              strID - The ID of the popup window. (This is important if the
//                window may be called on by other functions or if there are
//                multiple popup windows in a site.)
//              strScrollbars - Switch visible scrollbars on/off ("yes"/"no")
//              strLocation - Switch visible location bar on/off ("yes"/"no")
//              strToolbar - Switch visible toolbar on/off ("yes"/"no")
//              strStatus - Switch visible status bar on/off ("yes"/"no")
//              strResizable - Window is resizable or not ("yes"/"no")
//
// Output:      Window opens containing the specified URL.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
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();
	}
	return false;
}

// ====================
// Function:    PopdownLink
//
// Purpose:     Open a link in a popup window in a specified main window and
//              close the popup window. If the specified link window does not
//              exist it is created. If no window is specified the link is
//              targeted to the original opener of the popup window.
//
// Input:       strURL - The URL of the page to open
//              strWindowID - The ID of the window in which to open the link
//
// Output:      Navigates to selected URL in selected window and closes current
//              window.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
//              2004 Multiple window targets added. (Previously could only
//                   target the opener.)
// ====================
function PopdownLink(strURL,strWindowID)
{
	if (!strWindowID)
{
		top.opener.location.href = strURL;
}
	else
{
		if (strWindowID.location)
	{
			strWindowID.location.href = strURL;
	}
		else
	{
			window.open(strURL,strWindowID);
	}
}
	top.close();
}

// ====================
// Function:    RequireKeywords
//
// Purpose:     Checks any search form to make sure keywords are entered before
//              the form can be submitted. 
//
// Input:       strFormName - The ID of the form with the keywords field in it
//              strFieldName - The ID of the keywords field within the form 
//
// Output:      Give an error if no keywords are presented.
//
// Assumptions: -
//
// History:     20040109 RW Created to replace local code in site templates.
// ====================
function RequireKeywords(strFormID,strFieldName)
{
	if (document.forms[strFormID].elements[strFieldName].value.length < 3)
	{
		alert("Please alter your requested keyword(s) in the search form.\nThe search phrase must be 3 characters or more in length.")
		return false;
	}
}

// ====================
// Function:    CS
//
// Purpose:     Display a "coming soon" message for sections of a website that
//              have not been created yet. This function is sometimes used in
//              development to make links active before a site is finished.
//
//              Note: This is an evil funciton, it should not be used! It
//              encourages bad development habits.
//
// Input:       -
//
// Output:      Show a "coming soon" message.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function CS()
{
	alert("That function is coming soon.");
}

// ####################################
// Image Manipulation
// ####################################

// ====================
// Function:    ImageSwap
//
// Purpose:     Swap any image to another.
//
// Input:       strImageID - ID of the image being swapped
//              strNewImageSrc - Source of the new image being loaded
//
// Output:      Swaps images.
//
// Assumptions: Images with all specified IDs exist and are pre-loaded.
//
// History:     DDSN created back in the Distant Past
// ====================
function ImageSwap(strImageID,strNewImageSrc)
{
	if (document.images)
	{
		document.images[strImageID].src = eval(strNewImageSrc+".src");
	}
}

// ====================
// Function:    ImageSwapFX
//
// Purpose:     Swap any image to another using an optional fade effect. Can
//              also be called with the transition effect disabled, i.e. just
//              swap the images.
//
// Input:       strImageID - ID of the image being swapped
//              strNewImageSrc - Source of the new image being loaded
//              blnDisableTrans - Switch the transition off or on (1/0)
//
// Output:      Swaps images with optional fade effect.
//
// Assumptions: - Images with all specified IDs exist and are pre-loaded.
//              - Requires fading transition style to be set first on image tag
//              - Only works for IE5.5+ but falls back nicely
//              - Javascript Globals: blnToggleTrans
//
// History:     2003 DDSN Created
//              2004 Updated with more standard naming structures
// ====================
function ImageSwapFX(strImageID,strNewImageSrc,blnDisableTrans)
{
	if (blnDisableTrans || !document.images[strImageID].filters || blnIE50)
	{
		if (document.images)
		{
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
	}
	else
	{
		// After setting Apply, changes to the object are not displayed
		// until Play is called.
		document.images[strImageID].filters[0].Apply();

		if (blnToggleTrans)
		{
			blnToggleTrans = 0;
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
		else
		{
			blnToggleTrans = 1;
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
		document.images[strImageID].filters[0].Play();
	}
}

// ####################################
// Layer Manipulation
// ####################################

// ====================
// Function:    LayerVisibility
//
// Purpose:     Turn visibility of any layer on or off.
//
// Input:       strLayerID - ID of the layer being altered
//              strState = "visible" or "hidden"
//
// Output:      Turns specified layer on or off.
//
// Assumptions: Specified layer exists in document hierarchy.
//
// History:     DDSN created back in the Distant Past
// ====================
function LayerVisibility(strLayerID,strState)
{
	if (blnNS4)
	{
		if (document.layers[strLayerID])
		{
			document.layers[strLayerID].visibility = strState;
		}
	}
	else if (blnDOM)
	{
		if (document.getElementById(strLayerID))
		{
			document.getElementById(strLayerID).style.visibility = strState;
		}
	}
	else if (blnIE)
	{
		if (document.all[strLayerID])
		{
			document.all[strLayerID].style.visibility = strState;
		}
	}
}

// ####################################
// Printing
// ####################################

// ====================
// Function:    LoadVBPrinter
//
// Purpose:     Load Visual Basic printing commands for VB enabled browsers.
//
// Input:       -
//
// Output:      Loads (writes out) visual basic printing functions.
//
// Assumptions: Javascript Globals: blnIE, blnCanPrint, blnMac
//
// History:     DDSN created back in the Distant Past
// ====================
//function LoadVBPrinter()
//{
	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
//
// Purpose:     Opens the print dialog window or shows a fallback message for
//              unsupported browsers
//
// Input:       -
//
// Output:      Opens the print dialog window or shows a fallback message for
//              unsupported browsers.
//
// Assumptions: Javascript Globals: blnCanPrint, blnIE, blnMac
//
// History:     DDSN created back in the Distant Past
// ====================
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.");
	}
}

// ##################
// 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;
	}

// Load Visual Basic printing commands for VB enabled browsers
//LoadVBPrinter()

// ####################################
// ActiveC "first click" fix for IE
// ####################################

function fixActivexClick() {
	objectTags = document.getElementsByTagName("object");
	for (var i = 0; i < objectTags.length; i++) {
			objectTags[i].outerHTML = objectTags[i].outerHTML;
	}
}

// Note: Move to individual templates if there are other onload functions in the site
window.onload = function() {
	fixActivexClick();
}

// ####################################
// Fun Stuff / Easter Eggs
// ####################################

// No easter eggs currently present. :-)
