/*
'************************************************************************
'*      JavaScript Error Trapping and Logging (client side)             *
'************************************************************************
'*      Copyright (C) Anthony Serfes 2002,2003,2004 All rights reserved.*
'*      Written by Anthony Serfes (aserfes@optonline.net)               *
'*      Version 1.01 Written - April 10,2002                            *
'*      JSERRORLOG.JS                                                   *
'************************************************************************
*/

trapErrors = true;
logErrors = true;
showErrorAsStatusMessage = true;
logNumErrors = 10;
logScriptLoc = "/admin/js_err_log.asp";
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 = exception.description;  
        //msg = self.onerror;
        //line = 'MSIE';          
      } else {
		//msg = exception.message;
        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++;
    }
  }
    var sErrMsg = "Hey, there's an error! \n"
      + arguments[1] + "\nLine "
      + arguments[2] + "\n"
      + arguments[0];
    //window.alert(sErrMsg);
  return trapErrors;

}

function restoreWindowToPreviousState() {
  if (!MSIE) { window.onerror = originalErrorHandler; }
  window.defaultStatus = originalDefaultStatus;
}

window.onUnload = restoreWindowToPreviousState;
window.onerror = handleErrors;
