/**
* GF_Debug()
* 
* Groups the methods needed by the debug section of Framework.
*/
function GF_Debug() {};

/**
* Error reporting constants.
* @const GF_Debug.LEVEL_ALL int - Report all messages.
* @const GF_Debug.LEVEL_ERRORS_ONLY int - Report errors only.
* @const GF_Debug.LEVEL_NONE int - Verbose mode.
*/
GF_Debug.LEVEL_ALL = 0;
GF_Debug.LEVEL_ERRORS_ONLY = 1;
GF_Debug.LEVEL_NONE = 2;

/**
* @var GF_Debug.s_iLevel int - Current error reporting level. May be set
*  externally at any moment.
*/
GF_Debug.s_iLevel = GF_Debug.LEVEL_NONE;

/**
* @var GF_Debug.s_asMessages array - Vector of pending messages.
*/
GF_Debug.s_asMessages = [];

/**
* GF_Debug.Error(sMessage)
* 
* Signals that an error has occured. It processes the message and
* reports it to the user if the reporting level is adequate.
* It also raises an exception with the message specified.
* 
* @param sMessage string - The error description.
*/
GF_Debug.Error = function(sMessage) {
	GF_Debug.s_asMessages.push({
		level: 2,
		message: sMessage
	});
	if (GF_Debug.s_iLevel <= GF_Debug.LEVEL_ERRORS_ONLY) {
		GF_Debug.ShowMessage(sMessage);
	}
	throw new GF_Exception(sMessage);
};

/**
* GF_Debug.Warning(sMessage)
* 
* Signals that a warning has occured. It processes the message and
* reports it to the user if the reporting level is adequate.
* 
* @param sMessage string - The warning description.
*/
GF_Debug.Warning = function(sMessage) {
	GF_Debug.s_asMessages.push({
		level: 1,
		message: sMessage
	});
	if (GF_Debug.s_iLevel == GF_Debug.LEVEL_ALL) {
		GF_Debug.ShowMessage(sMessage);
	}
};

/**
* GF_Debug.ShowMessage(sMessage)
* 
* Reprots a message to the user. In it's simple form just shows
* an alert box on the screen.
* 
* It can be freely overriden with a custom function.
* 
* @param sMessage string - The message to display.
*/
GF_Debug.ShowMessage = function(sMessage) {
	alert(sMessage);
};

/**
* GF_Debug.HandleException(xException)
* 
* Handles an exception in an appropriate way.
* 
* @return void
* @param xException mixed - An exception.
*/
GF_Debug.HandleException = function(xException) {
	if (xException instanceof GF_Exception) {
		
	}
	else {
		if (GF_Debug.level <= GF_Debug.LEVEL_ERRORS_ONLY) {
			alert('Non-GF exception:\n' + xException);
		}
	}
	throw xException;
};

/**
* GF_Exception(sMessage)
* 
* General GexoFramework exception.
* 
* @param sMessage string - The exception's description.
*/
function GF_Exception(sMessage) {};
