// Copyright 2008 Cloud Engines

if(!CE)var CE={};CE.CEDBG=new function(){var that=this;var __enabled=false;var __msgdiv=null;function cerealize(obj,depth,md){var t=typeof(obj);if(depth>=md){return'['+t+'] '+obj;}
var s='';if(obj&&t=='function'){s+="'function "+obj.name+"'";}else if(obj&&t=='object'){if(obj.constructor==Array){s+='[ ';for(var each=0;each<obj.length;++each){var prop;try{prop=obj[each]}catch(e){prop='inaccessible';};s+=cerealize(prop,depth+1,md);if(each<(obj.length-1)){s+=', ';}}
s+=' ]';}else{var wasfirst=true;for(var each in obj){if(each===undefined){return''+obj;}
if(wasfirst){s+='{ ';}else{s+=', ';};wasfirst=false;s+=(each+': ');var prop;try{prop=obj[each];}catch(e){prop='inaccessible';};s+=cerealize(prop,depth+1,md);}
s+=' }';}}else{if(obj&&obj.constructor==String){s+="'"+obj+"'";}else{s+=obj;}}
return s;}
this.serialize=function(obj,maxdepth){if(!maxdepth)maxdepth=10;return cerealize(obj,0,maxdepth);};this.enable=function(on){var dbgdiv=document.getElementById('cedebug_div');__enabled=on;if(__enabled){if(dbgdiv==null){dbgdiv=document.createElement('div');dbgdiv.id='cedebug_div';dbgdiv.className='cemin';var hdrdiv=document.createElement('div');hdrdiv.id='cedebug_hdr';var hdrclose=document.createElement('a');hdrclose.className='cedebug_hdrbutton';hdrclose.href='#';hdrclose.onclick=function(){that.show(false);return false;}
hdrclose.innerHTML='x';hdrdiv.appendChild(hdrclose);hdrclose=null;var hdrclear=document.createElement('a');hdrclear.className='cedebug_hdrbutton';hdrclear.style.marginRight='4px';hdrclear.href='#';hdrclear.onclick=function(){that.clear();return false;}
hdrclear.innerHTML='clear';hdrdiv.appendChild(hdrclear);hdrclear=null;var hdropen=document.createElement('a');hdropen.className='cedebug_hdrbutton';hdropen.style.marginRight='4px';hdropen.href='#';hdropen.onclick=function(){that.toggleOpen();return false;}
hdropen.innerHTML='open/close';hdrdiv.appendChild(hdropen);hdropen=null;var hdrmsg=document.createElement('h3');hdrmsg.innerHTML='Cloud Engines Debug Console';hdrdiv.appendChild(hdrmsg);dbgdiv.appendChild(hdrdiv);hdrmsg=null;hdrdiv=null;__msgdiv=document.createElement('div');__msgdiv.id='cedebug_msg';dbgdiv.appendChild(__msgdiv);that.println('Cloud Engines Debug Enabled!');var root=document.getElementById('ceroot');if(root==null){root=document.body;}
root.appendChild(dbgdiv);}
that.show(true);}else{that.show(false);}}
this.show=function(on){var dbgdiv=document.getElementById('cedebug_div');if(dbgdiv){if(on){CE.rCN(dbgdiv,'hidden');}else{CE.aCN(dbgdiv,'hidden');}}}
this.clear=function(){if(__enabled){__msgdiv.innerHTML='';}}
this.toggleOpen=function(){if(CE.hCN('cedebug_div','cemin')){CE.rCN('cedebug_div','cemin');}else{CE.aCN('cedebug_div','cemin');}};this.println=function(msg){if(__enabled){__msgdiv.innerHTML+=msg+'<br>';}}
this.atn=function(msg){if(__enabled){__msgdiv.appendChild(CE.dctn(msg));__msgdiv.appendChild(CE.dce("br"));}}
this.print=function(msg){if(__enabled){__msgdiv.innerHTML+=msg;}}
this.isEnabled=function(){return __enabled;};}();