// ---------------------------------------------------------- // TRACE CODE // ---------------------------------------------------------- var winDebug; var debug = false; if (debug) { winDebug = window.open('javascript/debug.htm','debug','width=700,height=700,left=0,top=100,screenX=0,screenY=100'); } // ---------------------------------------------------------- // This function outputs a string to the debug window. // The string is concatenated to existing window output // and a date stamp is added. // ---------------------------------------------------------- function printTrace() { if (debug) { sDebug = funcName(arguments.caller.callee); if (sDebug.length < 16) sDebug += "\t"; if (sDebug.length < 24) sDebug += "\t"; if (sDebug.length < 32) sDebug += "\t"; var d = new Date(); var t = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ":" + d.getMilliseconds(); winDebug.document.all['txtDebug'].value = winDebug.document.all['txtDebug'].value + sDebug + "\t" + t + "\n"; } } // ------------------------------------------------------------- // This function returns the name of a given function // It does this by converting the function to a string, // then using a regular expression to extract the function // name from the resulting code. // ------------------------------------------------------------- function funcName(f) { var s = f.toString().match(/function (\w*)/)[1]; if ((s == null) || (s.length == 0)) return "anonymous"; return s; } // ------------------------------------------------------------- // This function returns a string that contains a stack trace // ------------------------------------------------------------- function stackTrace() { var s = ""; // Loop through the stack of functions, using the caller // property of one arguments object to refer to the next // arguments object on the stack for (var a = arguments.caller; a != null; a = a.caller) { // Add the name of the current function to the // return value s += funcName(a.callee) + "\n"; } return s; } // -------------------------------------------------------------