
if (typeof Prototype=='undefined')	{
      throw("errorlog.js requires the Prototype JavaScript framework");
}

/*
 * function:	handleError
 * description: Sends an http request to the server that passes 
 *				the javascript error message to the access log. 
 * parameters:	-
 * 
 * If you are in a position to configure your apache webserver, 
 * you might want to add the following to your (virtual) host 
 * configuration:
LogFormat "%h %l %u %t \"%{User-Agent}i\" \
\"%{X-JSError-URL}i,%{X-JSError-Line}i:%{X-JSError-Message}i\"" js

SetEnvIf    Request_URI "^/not_found/jserror" jslog
CustomLog   /var/log/apache/(your.server.name-)jserror.log   js  env=jslog
 *
 */

function handleError(sMsg, sURL, iLine)
{
	//	get the persistence data
	var oAjax = new Ajax.Request(
						'/not_found/jserror', 
						{	method: 'get', 
							//	This is needed to handle onSubmit errors
							asynchronous: false,
							parameters:   "msg="+encodeURIComponent(sMsg)
										+"&url="+encodeURIComponent(sURL)
										+"&line="+encodeURIComponent(iLine),
							requestHeaders:[
								'X-JSError-Message', sMsg,
								'X-JSError-URL', sURL,
								'X-JSError-Line', iLine
							]
						}
					);

	return false;
}

//	Set the error handler
window.onerror	= handleError;


