/***********************************************************************************
 * Frontline Logic, Inc. Confidential and Proprietary
 *
 * This file and its related files contain valuable, confidential, and proprietary
 * information.  Disclosure, use, or reproduction without the written 
 * authorization of Frontline Logic, Inc. is prohibited.  This work by Frontline
 * Logic, Inc. is protected by laws of the United States and other
 * countries.  If publication of this file and its related files should occur, the
 * following notice shall apply:
 *
 * Copyright (c) 2007 Frontline Logic, Inc.  All rights reserved.
 ***********************************************************************************/

/**
* Add debug message to be displayed in JavaScript popup
* @param jsFile name of JavaScript file (e.g. cg_js_main.js)
* @param functionName name of JavaScript function that caused debug message (e.g. addDebugMessage)
* @param message text to display
* @return void
*/
var g_debugMessages = new Array();

function addDebugMessage(jsFile, functionName, message)
{
	try
	{
		var title = createMessageTitle(jsFile, functionName) + " DEBUG\n\n";
		g_debugMessages.push(title + message);
	}
	catch (e)
	{
		alert("CG_JS_MAIN.JS(ADDDEBUGMESSAGE)\n\n", message);
	}
}

/**
* Displays JavaScript popup of compiled debug messages separated by dashed line
* @return void
*/
function showDebugMessages()
{
	try
	{
		if (g_debugLevel > 0)
		{
			alert(g_debugMessages.length + " debug messages recorded\n\n" + g_debugMessages.join("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"));
		}
	}
	catch (e)
	{
		alert("CG_JS_MAIN.JS(SHOWDEBUGMESSAGES)\n\n", message);
	}
}

/**
* Display error message in JavaScript popup
* @param jsFile name of JavaScript file (e.g. cg_js_main.js)
* @param functionName name of JavaScript function that caused error message (e.g. showErrorMessage)
* @param message text to display
* @return void
*/
function showErrorMessage(jsFile, functionName, message)
{
	try
	{
		var title = createMessageTitle(jsFile, functionName) + "EXCEPTION\n\n";
		alert(title + message);
	}
	catch (e)
	{
		alert("CG_JS_MAIN.JS(SHOWERRORMESSAGE)\n\n", message);
	}
}

/**
* Create title in common format for debug and error messages.  Format is JSFILEUPPERCASE(FUNCTIONNAMEUPPERCASE)
* @param jsFile name of JavaScript file (e.g. cg_js_main.js)
* @param functionName name of JavaScript function that caused debug message (e.g. createMessageTitle)
* @return string
*/
function createMessageTitle(jsFile, functionName)
{
	try
	{
		return jsFile.toUpperCase() + "(" + functionName.toUpperCase() + ")";
	}
	catch (e)
	{
		alert("CG_JS_MAIN.JS(CREATEMESSAGETITLE)\n\n", e);
	}
}