/*
  Copyright (c) 2003 Jan-Klaas Kollhof
 
  This is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
 
  This software is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
 
  You should have received a copy of the GNU General Public License
  along with this software; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
*/


debug = function(){
    var obj2Str = function(o){
        var s="";
        for(var n in o){
            s+=n+" : " + o[n] + "\n";
        }
        return s;
    }

    var debugMsg = function(s){
        var maxHeight=50;
        
        var a=s.split("\n")

        var tx = document.getElementById("dbgMsg");
        var insChild = tx.firstChild;
        
        var tsp = document.createElement("tspan");
        tsp.setAttribute("dy","1em");
        tsp.setAttribute("x","0");
        tsp.appendChild(document.createTextNode(" "));    

        if(tx.hasChildNodes()){
            tx.insertBefore(tsp, tx.firstChild);
            if (tx.childNodes.length>maxHeight){
                tx.removeChild(tx.lastChild);
            }
        }else{
            tx.appendChild(tsp);
        }
        
        for(var i=0;i<a.length;i++){
            var tsp = document.createElement("tspan");
            tsp.setAttribute("dy","1em");
            tsp.setAttribute("x","0");
            tsp.appendChild(document.createTextNode(a[i]));
            tx.insertBefore(tsp, insChild);
            
            if (tx.childNodes.length>maxHeight){
                tx.removeChild(tx.lastChild);
            }
        }
                
    }

    
    var printObj = function(o){
        debugMsg(obj2Str(o));
    }
    
    return {obj2Str:obj2Str, debugMsg:debugMsg, printObj:printObj};
}();
