var katTimestart = new Date();

if(typeof(console) != 'undefined') {
  if(typeof(console.debug) != 'undefined') {
    debug = function(str) {
      var now = new Date();
      var strTime = '' + (now - katTimestart);
      console.debug('[' + strTime + ']' + str);
    };
    
  }

  if(typeof(console.log) != 'undefined') {
    debug = function(str) {
      var now = new Date();
      var strTime = '' + (now - katTimestart);
      console.log('[' + strTime + ']' + str);
    };
  }
}

if(typeof(debug) == 'undefined') {
    debug = function(str) {
    };
}

function debugObjToStr(obj, str, arrNullTest) {
  if(typeof(str) != 'string') {
    str = '';
  } else {
    str += '\n';
  }
  var okToContinue = true;
  for(var k in obj) {
    if(typeof(arrNullTest) != 'undefined') {
      for(var i=0;i<arrNullTest.length;i++) {
        if(arrNullTest[i] == k) {
          str += '  ' + k + ':' + ((obj[k] == null) ? '[null]' : '[not null]') + '\n';
          okToContinue = false;
          break;
        }
      }
    }
    if(!okToContinue) {
      continue;
    }
    debug('  member:' + k);
    var member = obj[k];
    var katType = typeof(member);
    if(member == null) katType='[null]';
    switch(katType) {
      case '[null]':
        str += '  ' + k + ':[null]\n';
      case 'function':
        break;
      case 'string':
      case 'number':
        str += '  ' + k + ':' + member + '\n';
        break;
      case 'object':
        str += '  ' + k + ':{\n' + debugObjToStr(member, '', arrNullTest) + '}';
        break;
      default:
        str += '  ' + k + ':' + member + '\n';
    }
  }
  return str;
}

function debugObj(obj, str, arrNullTest) {
  debug(debugObjToStr(obj, str, arrNullTest));
}

