

var g_d = null;

function sortObj(theObj)
{
  var sortable = [];
  for (var i in theObj) {
    sortable.push(i);
  }
  sortable.sort();

  var copy = new Object;
  for (var i in sortable) {
    var ind = sortable[i];
    copy[ind] = theObj[ind];
  }

  return copy;

}


function p_r(s, comment, level)
{
  var res = s;
  if (!g_d) return;
  var pre = new Array("","  " , "    ", "      ", "        ");
  if (comment) comment += " : ";
  if (arguments.length<2) comment='';
  if (arguments.length<3) level = 0;
  if (typeof(s) == 'object') {
    var copy = sortObj(s);
    comment += "\n";
    res = '[object]\n';
    if (level < 2) {
      for (var i in copy) {
        if (typeof(copy[i]) != "function")
          res += pre[level] + (i) + " : " + p_r(copy[i], '', level+1) +  " : " + typeof(copy[i]) + "\n";
      }
      res += pre[level] + "[/object]\n";
    }
  }
  else if (typeof(s) == 'function')
    res = 'function';
  else if (typeof(s) != 'string')
    res = '' + s;
  res = res.replace(/&/g, '&amp;');
  res = res.replace(/\x3C/g, '&lt;');
  res = res.replace(/>/g, '&gt;');
  if (level == 0) {
    g_d.innerHTML+= (comment + res + '\n');
  }
  return res;
}

if (get_value('d')) {
  document.write("<pre id='debug'></pre>\n");
  g_d = document.getElementById('debug');
}



