// charset=utf-8
// $Id: debug.js 1362 2007-04-11 15:44:27Z dierker $
// +----------------------------------------------------------------------+
// | mcm                                                                  |
// | version 5.0                                                          |
// | (c) 2002-2007 monsun media (http://www.monsun-media.com)             |
// +----------------------------------------------------------------------+


var mcmEnableDebugger = true;

/**
* print HTML to a debug-window
*
* @param	string	html
* @return	void
*/
function printDebug(html){
	if( window.opera ){
		return;
	};
	if( typeof mcmEnableDebugger == "undefined" || mcmEnableDebugger!=true ){
		return;
	};
	if( typeof mcmDebugWindow=="undefined" || mcmDebugWindow.closed == true){
		var left = 1152; var width = 400;
		left -= (width + 13);
		mcmDebugWindow = window.open('','mcmDebugWin','width='+width+',height=400,status=yes,resizable=yes,scrollbars=yes,left='+left+',top=0');
		mcmDebugWindow.document.open();
		mcmDebugWindow.document.writeln('<html>\n<title>Javascript-Debugger</title>\n<head>\n<style type="text/css">\nbody,th,td { font-family:Courier; font-size:11px;}\n</style>\n</head><body scroll="auto">');
		mcmDebugWindow.document.writeln('<div align="center" style="background-color:buttonface;"><button onclick="document.getElementById(\'debugOutput\').innerHTML=\'\';">clear page</button></div><div id="debugOutput"></div>');
		mcmDebugWindow.document.writeln('</body></html>');
		mcmDebugWindow.document.close();
	};
	mcmDebugWindow.document.getElementById("debugOutput").innerHTML += html;
	//mcmDebugWindow.focus();
};

/**
* print HTML (and add a <br>) to the debug-window
*
* @param	string	html
* @return	void
*/
function printDebugLn(html){
	printDebug(html+"<br>");
}


/**
* dump information about an object into the debug-window
*
* @param	obj			object 	object to inspect
* @param	bSortIt		bool	sort the object-properties?
* @return	void
*/
function printDebugObject(obj,bSortIt){
	if( typeof mcmEnableDebugger == "undefined" || mcmEnableDebugger!=true ){
		return;
	};
	if( typeof obj=="object" ){
		var i;
		var htmlBuffer = '';
		var bufferAry = new Array();
		var htmlStr = "";
		for( i in obj ){
			htmlStr  = '<tr><td valign="top"><b>'+i+'</b></td><td valign="top">';
			if( typeof obj[i] == "boolean" ){
				htmlStr += obj[i]==true ? 'true' : 'false';
			//}else if( typeof obj[i] == "object" ){
			//	htmlStr += '<a href="#" onclick="printDebugObject(obj[i]);">' + obj[i] + '</a>';
			}else{
				htmlStr += (obj[i]==''?'&nbsp;':obj[i])
			};
			htmlStr += '</td><td>['+(typeof obj[i])+']</td></tr>';
			bufferAry[bufferAry.length] = htmlStr;
		};
		if( bSortIt!=false ){
			bufferAry.sort();
		};
		htmlBuffer  = '<table border="1" cellpadding="2" cellspacing="0">';
		htmlBuffer += bufferAry.join("\n");
		htmlBuffer += '</table>';
		printDebug(htmlBuffer);
	};
}

// wrapper functions
function printObject(obj,bSortIt){
	if( typeof mcmEnableDebugger == "undefined" || mcmEnableDebugger!=true ){
		return;
	};
	printDebugObject(obj,bSortIt);
}

/**
* convert special HTML-characters into entities
*
* @param	string	text containg some html-code
* @return	string	text with html-entities replaced!
* @return	string
*/
function htmlentities(str){
	if( typeof str == "undefined" ){
		return;
	};
	var re1 = /</g;
	var re2 = />/g;
	var re3 = /&/g;
	var re4 = /\n/g;
	str = str.replace(re3,'&amp;');
	str = str.replace(re1,'&lt;');
	str = str.replace(re2,'&gt;');
	str = str.replace(re4,'<br>');
	return str;
};