if (!Framework.Debugging)
{
	Framework.Debugging = {};
}

Framework.Debugging.Environment = {
	
	isDebugMode: function()
	{
		return true;
	},
	
	getStackTrace: function()
	{
		var callstack = [];
		var isCallstackPopulated = false;
		try 
		{
			me.dont.exist += 0; // doesn't exist- that's the point
		} 
		catch (e) 
		{
			if (e.stack) 
			{ 
				//Firefox
				return e.stack;
			} 
			else if (window.opera && e.message) 
			{ 
				//Opera
				var lines = e.message.split("\n");
				for ( var i = 0, len = lines.length; i < len; i++) 
				{
					if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) 
					{
						var entry = lines[i];
						// Append next line also since it has the file info
						if (lines[i + 1]) 
						{
							entry += " at " + lines[i + 1];
							i++;
						}
						callstack.push(entry);
					}
				}
				//Remove call to printStackTrace()
				callstack.shift();
				isCallstackPopulated = true;
			}
		}
		if (!isCallstackPopulated) 
		{ 
			//IE and Safari
			var currentFunction = arguments.callee.caller;
			while (currentFunction) 
			{
				var fn = currentFunction.toString();
				var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous";
				callstack.push(f.name);

				currentFunction = currentFunction.caller;
			}
		}
		return callstack.join(' ');
	},
	
	postError: function(message, url, lno)
	{
		if (!Framework.Configuration.get('debugging_errorpost_url'))
		{
			Framework.Debugging.Console.log("No debugging_errorpost_url set!");
			return false;
		}
		
		return; // disabled for now
		
		var pars = "";
		if (typeof(message) == "string") 
		{
			pars += "&message=" + encodeURIComponent(message);
		}
		else 
		{
			if (message.msg) 
			{
				pars += "&message=" + encodeURIComponent(message.msg);
			}
			if (message.url) 
			{
				pars += "&script_url=" + encodeURIComponent(message.url);
			}
			if (message.lno)
			{
				pars += "&lno=" + message.lno;
			}
		}
		
		if (url) 
		{
			pars += "&script_url=" + encodeURIComponent(url);
		}
		if (lno) 
		{
			pars += "&lno=" + lno;
		}
		
		pars += "&url=" + encodeURIComponent(window.location);
		
		var stackTrace = this.getStackTrace();
		pars += "&trace=" + encodeURIComponent(stackTrace);
		
		var ajax = new Ajax.Request(
			Framework.Configuration.get('__base') + Framework.Configuration.get('debugging_errorpost_url'),
			{ 
				method: 'post',
				parameters: pars,
				onSuccess: function (request, json) 
				{ 
					Framework.Debugging.Console.log("error posted successfully"); 
				},
				onFailure: function (t) 
				{ 
					Framework.Debugging.Console.log("failure posting js error"); 
				}
			}
		);
	},
	
	_eoo: true
};