	// c3o.org JS debug helpers
	// version 2


	c3o_isSafari = navigator.userAgent.toLowerCase().indexOf('applewebkit/') > -1 ? true : false;

	function jsdebug() {
		if(!c3o_isSafari) {
			window.onerror = c3o_error;
			document.body.innerHTML+='<div id="c3o_debugconsole" style="visibility:hidden;position:fixed;_position:absolute;bottom:0;right:0;width:350px;height:1em;_height:350px;opacity:0.8;padding:5px;padding-top:4px;padding-bottom:3px;background-color:#666;color:white;font-family:Arial;font-size:0.8em;overflow:auto;_filter:alpha(opacity=80);"><div style="position:fixed;right:3px;bottom:3px;"><a href="#" style="color:#FFF !important" accesskey="z" onclick="return c3o_toggle();">TOGGLE</a>/<a href="#" onclick="return c3o_clear()" style="color:#FFF !important">CLEAR</a></div></div>';
		}
	}


	//////


	function c3o_clear() {
		var dbc = document.getElementById('c3o_debugconsole');
		var con = dbc.childNodes;
		for(var i=con.length-1;i>0;i--) {
			dbc.removeChild(dbc.childNodes[1])
		}
		return false;
	}
	function c3o_toggle() {
		var dbc = document.getElementById('c3o_debugconsole');
		dbc.style.height = (dbc.offsetHeight > 50) ? '1em' : '300px';
		dbc.scrollTop = dbc.scrollHeight;
		return false;
	}

	function c3o_error(msg, url, linenumber) {
		c3o_debug('ERROR (line '+linenumber+') '+msg);
		return true;
	}
	function c3o_errorAlert(msg, url, linenumber) {
		alert('ERROR (line '+linenumber+') '+msg);
		return true;
	}
	function c3o_debug(txt) {
		if(typeof(txt) == 'object') { txt = c3o_debugNodeinfo(txt) }
		if(c3o_isSafari) {
		/////	alert(txt);
		} else {
			var debugwin = document.getElementById('c3o_debugconsole');
			if(debugwin && debugwin.style.visibility != 'visible') { debugwin.style.visibility='visible'; } // c3o_toggle();
			if(debugwin) { debugwin.innerHTML+='<br />- '+txt; }
			debugwin.scrollTop = debugwin.scrollHeight;
		}
	}
	function c3o_debugToggleOutline(oid) {
		o = document.getElementById(oid);
		if(o) {
			if(document.all) {
				if(o.style.border != '') { 	o.style.border = ''; } else { o.style.border = '2px dotted orange'; }
			} else {
				if(o.style.MozOutline != '') { 	o.style.MozOutline = ''; } else { o.style.MozOutline = '2px dotted orange'; }
			}
		} else {
			c3o_debug('debugToggleOutline: no object with id='+oid+' exists (anymore?)');
		}
	}
	var c3o_tmp = 0;
	function c3o_debugNodeinfo(o, checkattr) {
		var nodeinfo='';
		if(!o) {
			nodeinfo='[not a node]';
		} else if(o.nodeType==1) {
			if(!o.id) { o.id = 'debugTmpId'+c3o_tmp; c3o_tmp++; }
			if(!c3o_isSafari) {
				if(o.id != '') { nodeinfo = '<a href="#" style="color:white;" onclick="c3o_debugToggleOutline(\''+o.id+'\');return false">'; }
			}
			nodeinfo += '['+o.nodeName;
			nodeinfo += ' id='+(o.id || 'null');
			if(o.nodeName == 'A') { nodeinfo += ' href=...'+o.href.substr(o.href.length-12,o.href.length); }
			if(o.nodeName == 'INPUT' || o.nodeName == 'SELECT' || o.nodeName == 'TEXTAREA') { nodeinfo += ' name='+o.getAttribute('name'); }
			if(checkattr != '' && checkattr != undefined && checkattr != 'undefined') { nodeinfo += ' '+checkattr+'='+o.getAttribute(checkattr); }
			nodeinfo += ']';
			if(!c3o_isSafari) {
				if(o.id != '') { nodeinfo += '</a> '; } else { nodeinfo += ' '; }
			}

		} else {
			nodeinfo =  o+' ';	//todo array list nicely etc.
		}	
		return nodeinfo;
	}