//||===========================================================================
//|| jsDebug Methods and Variables
//||
//||===========================================================================

	//|This is a switch that allows disabling debug output. It
	//|provides a second level of insurance that debug output will
	//|not appear in production mode.
	var jsAllowDebugOutput = true;
	
	//|Boolean flag to simplify processing within the debug function
	var jsDebugIsVisible = false;

	//|array to hold any cached debug output from inline debug calls
  var	aCache = new Array();

//||==========================================================================
//||  METHOD: DebugWrite()
//||
//|| PURPOSE: controls and formats text for the js debug div
//||==========================================================================
function DebugWrite(pMod, pFunc, pMsg)
{
	var oDebug = document.getElementById("jsDebugOutput");
	var oDebugText = document.getElementById("jsDebugText");
	var sText;

	try
	{
		//|see if debug output is allowed
		if (jsAllowDebugOutput == true)
		{
			//|check to see if the html div element exists yet
			if ( ! oDebug)
			{
				//|if the debug div doesn't exist yet, format and cache the text
				sText = pMod + "." + pFunc + ": " + pMsg;
				aCache.splice(aCache.length + 1, 0, sText);
			}
			else
			{
				//|if the debug div exists but not visible, make it visible and add cached text
				if (jsDebugIsVisible == false)
				{
					//|make the debug div element visible
					//note: display = css1 / visibility = css2
					oDebug.style.visibility = "visible";
					oDebug.style.display = "block";
					jsDebugIsVisible = true;

					//add any accumulated text from the cache
					if (aCache.length > 0)
					{
						for (var iCt=0; iCt < aCache.length; iCt++)
						{
							sText = aCache[iCt];
							DebugWriteAddLine(oDebugText, sText);
						}
						aCache = new Array();
					}
				}

				//format and add the current text
				sText = pMod + "." + pFunc + ": " + pMsg;
				DebugWriteAddLine(oDebugText, sText);
			}
		}
	}
	catch(oErr)
	{
		alert("DebugWrite ERROR: " + oErr.description);
	}
}

//||==========================================================================
//||  METHOD: DebugWriteAddLine()
//||
//|| PURPOSE: controls and formats text for the js debug div
//||==========================================================================
function DebugWriteAddLine(pElement, pText)
{
	var oCrLf = document.createElement("BR");
	var oTextNode;

	try
	{
				//add a linefeed to the text if it's not the first line
				if (pElement.childNodes.length > 0)
				{
					pElement.appendChild(oCrLf);
				}

				//add the text to the div
				oTextNode = document.createTextNode(pText);
				pElement.appendChild(oTextNode);
	}
	catch(oErr)
	{
		alert("DebugWriteAddLine ERROR: " + oErr.description);
	}
}

//||==========================================================================
//||  METHOD: DebugWriteHTML()
//||
//|| PURPOSE: formats html for debug output
//||==========================================================================
function DebugWriteHTML(pMod, pFunc, pMsg)
{
	var sMsg;

	sMsg = HTMLEncode(pMsg);
	DebugWrite(pMod, pFunc, sMsg);
}

//||==========================================================================
//||  METHOD: HTMLEncode()
//||
//|| PURPOSE: does html encoding for javascript
//||==========================================================================
function HTMLEncode(pText)
{
	var sText = pText.toString();

	sText = sText.replace(/&/, "&amp;");
	sText = sText.replace(/"/, "&quot;");
	sText = sText.replace(/</, "&lt;");
	sText = sText.replace(/>/, "&gt;");
	return sText;
}
