/*
JavaScript Error Trapping and Logging
This library module enables suppression of
JavaScript errors in a way that allows errors
to be hidden from view, logged to a server
log file for further review, and optionally
displayed in the window.status area if desired.
Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Patrick Corcoran
Author email: patrick@taylor.org
*/
trapErrors = true;
logErrors = false;
showErrorAsStatusMessage = false;
logNumErrors = 3;
logScriptLoc = "path to your cgi script goes here";
scriptName = "JS Err Log";
logComment = "Testing";
MSIE = (navigator.userAgent.indexOf('MSIE') > -1) ? ( true ) : ( false );
if (!MSIE) { originalErrorHandler = window.onerror; }
originalDefaultStatus = window.defaultStatus;
numErrorEvents = 0;
function handleErrors(msg, errUrl, line) {
  if (logErrors || showErrorAsStatusMessage) {
    if (numErrorEvents < logNumErrors) {
      errImage = new Array(logNumErrors);
      d = new Date();
      sn = (scriptName) ? ('&scr=' + escape(scriptName)) : ('');
      lc = (logComment) ? ('&comm=' + escape(logComment)) : ('');
      if (MSIE) {
        errUrl = this.location;    
        msg = 'Unspecified JS Error';  
        line = 'MSIE';          
      } else {
        line = 'line ' + line;
      }
      if (logErrors) {
        errLogEntry = logScriptLoc + '?url=' + escape(errUrl) + '&msg=' + escape(msg) + '&line=' + escape(line) + sn + lc + '&d=' + escape(d);
        errImage[numErrorEvents] = new Image();  
        errImage[numErrorEvents].src = errLogEntry;
      }
      if (showErrorAsStatusMessage) { window.defaultStatus = 'JavaScript Error: ' + msg + ' in ' + line; }
      numErrorEvents++;
    }
  }
  return trapErrors;
}
function restoreWindowToPreviousState() {
  if (!MSIE) { window.onerror = originalErrorHandler; }
  window.defaultStatus = originalDefaultStatus;
}
window.onUnload = restoreWindowToPreviousState;
window.onerror = handleErrors;
