/*	 * =======================================================	 * <HEADER>	 * NAME:	OpenLogFunctions script library	 * VERSION:	20070320a	 * AUTHOR(S):	Julian Robichaux ( http://www.nsftools.com )	 * ORIGINAL SOURCE:	The OpenLog database, available as an	 * open-source project at http://www.OpenNTF.org	 * HISTORY:	 * 20070320a:	initial version	 * 	 * DISCLAIMER:	 * This code is provided "as-is", and should be used at your own risk. 	 * The authors make no express or implied warranty about anything, 	 * and they will not be responsible or liable for any damage caused by 	 * the use or misuse of this code or its byproducts. No guarantees are 	 * made about anything.	 *	 * That being said, you can use, modify, and distribute this code in any	 * way you want, as long as you keep this header section intact and in	 * a prominent place in the code.	 * </HEADER>	 * =======================================================This library contains generic functions that can be used to log events and errorsto the OpenLog database. All you have to do is include the file on any web pageyou want to log errors from, and it will automatically register itself as a JavaScripterror handler for the page. If another JavaScript function has already been registered as an error handler,this will detect the other function and automatically run it after it logs an error.For best results, you should add this AFTER all the other JavaScript files, in caseyour other JavaScript files register an error handler that overrides this one.The master copy of this script library resides in the OpenLog database. All copies of this library in other databases should be set to inherit changes from that database.*/// modify the OpenLog database location appropriately//var openLogUrl = "http://www.example.com/OpenLog.nsf/JavascriptErrorReport?OpenAgent";//var openLogUrl = "http://diskusis7.diskus.com:81/customer/servomex/webv2/weblog.nsf/JavascriptErrorReport?OpenAgent";var openLogUrl = location.protocol + "//" + location.host + "/80257482003E769F/JavascriptErrorReport?OpenAgent";// if you set the user name variable later on (via JavaScript written// on the server-side, most likely), it will get picked up by the // openLogObject when the errors/events are reportedvar openLogUserName;// this is just used to record how long it was between when the page// loaded and when the error occurredvar openLogStartTime = new Date();// override anything that's already registered as a window.onerror handlervar openLogOldErrorHandler = window.onerror;window.onerror = openLogErrorHandler;function openLogErrorHandler (msg, url, line) {	var logObj = new openLogObject(msg, url, line);	logObj.logError();		if (typeof(oldErrorHandler) == "function") {		return oldErrorHandler(msg, url, line);	} else {		return true;	}	}// here's the openLogObject that does all the workfunction openLogObject (msg, url, line) {	this.msg = msg;	this.url = url;	this.line = line;	this.msgType = "Error";	this.postParamList = new Object();		// for some reason the window.onerror messages often end	// with a linefeed. Let's trim that off	this.msg = this.msg.replace(/^\s+|\s+$/g, "");			// toString is a built-in	this.toString = function() {		if (this.line)			return this.msgType + " on line " + this.line + ": " + this.msg;		else			return this.msgType + " message: " + this.msg;	}			/*******************************************	  *  LOGGING ERRORS	 *******************************************/	// create the beforeLogEvent and afterLogEvent  functions	// using prototype if you want specific things to happen	// just before or just after the event is POSTed	// 	//	openLogObject.prototype.beforeLogEvent = function() {}	//	openLogObject.prototype.afterLogEvent = function() {}	//		this.logError = function(doAlert, doStatusBar) {		if (typeof(this.beforeLogError) == "function") { this.beforeLogError(); }				var postMessage = this.createPostMessage();		this.doAjaxPost(openLogUrl, postMessage);				if (doAlert)			alert(this);		if (doStatusBar)			window.status = this;				if (typeof(this.afterLogError) == "function") { this.afterLogError(); }	}			/*******************************************	  *  LOGGING EVENTS	 *******************************************/	// create the beforeLogEvent and afterLogEvent  functions	// using prototype if you want specific things to happen	// just before or just after the event is POSTed	// 	//	openLogObject.prototype.beforeLogEvent = function() {}	//	openLogObject.prototype.afterLogEvent = function() {}	//		this.logEvent = function(doAlert, doStatusBar) {		this.msgType = "Event";		if (typeof(this.afterLogEvent) == "function") { this.afterLogEvent(); }				var postMessage = this.createPostMessage();		this.doAjaxPost(openLogUrl, postMessage);				if (doAlert)			alert(this);		if (doStatusBar)			window.status = this;				if (typeof(this.afterLogEvent) == "function") { this.afterLogEvent(); }	}			/*******************************************	  *  Generate the POST request that 	  *  gets sent to the server	 *******************************************/	this.createPostMessage = function() {		this.postParamList["msg"] = this.msg;		this.postParamList["url"] = this.url;		this.postParamList["line"] = line;		this.postParamList[ "thispage"] = location.href;		this.postParamList["referrer"] = document.referrer;		this.postParamList["eventType"] = this.msgType;		this.postParamList["userName"] = openLogUserName;		this.postParamList["browser"] = navigator.appName  + " " + navigator.appVersion;		this.postParamList["os"] = navigator.platform;		this.postParamList["userAgent"] = navigator.userAgent;		this.postParamList["lang"] = navigator.language;		this.postParamList["resolution"] = screen.width + " x " + screen.height;				var timeNow = new Date();		this.postParamList["browserTime"] = timeNow.toLocaleString();		this.postParamList["startTime"] = openLogStartTime.toUTCString();		this.postParamList["elapsed"] = ((timeNow.getTime() - openLogStartTime.getTime()) / 1000);				var cookieSupport = "yes";		document.cookie = "cookietest=test; path=/";		if (document.cookie.indexOf("cookietest=test") == -1)			cookieSupport = "no";		this.postParamList["cookiesAllowed"] = cookieSupport;				var sep = "";		var postString = "";		for (param in this.postParamList) {			postString += sep + escape(param) + "=" + escape(this.postParamList[param]);			sep = "&";		}				return postString;	}			/*******************************************	  *  Send the POST request using	  *  AJAX (or a user-defined method)	 *******************************************/	// create the alternateAjaxPost function using prototype 	// if you want to use your own Ajax library to sent the request	// in the background (a lot of them will be much more robust than	// the simple code we have below, and will deal with things	// like browser quirks and cross-domain issues). Make sure	// that the function returns true if it's successful.	// 	//	openLogObject.prototype.alternateAjaxPost = function(url, postMessage) {}	//		this.doAjaxPost = function(url, postMessage) {		if (typeof(alternateAjaxPost) == "function") { 			if (this.alternateAjaxPost(url, postMessage))				return true;		}				var xmlHttp = null;		try { xmlHttp = new XMLHttpRequest(); } catch(e) {			try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e2) {				try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e3) {					xmlHttp = null;				}			}		}				if (!xmlHttp) {			return this.doIFramePost(openLogUrl, postMessage);		}				try {			xmlHttp.open("POST", url, true);			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");			postMessage += "&uploadType=openLogXMLHttp";			xmlHttp.send(postMessage);		} catch(e) {			//return false;			// iFrames will still work if cross-domain requests will cause a problem			return this.doIFramePost(openLogUrl, postMessage);		}				return true;	}			// fall back to using an iFrame to do the POST, in case XMLHttp isn't permitted	// or something (for example, if users are still on IE6 and ActiveX isn't allowed)	this.doIFramePost = function(url, postMessage) {		var iFrameDivID = "openLogIFrameDiv";		var iFrameID = "openLogIFrame";				try {			if (!document.getElementById(iFrameDivID)) {				var newNode = document.createElement("div");				newNode.setAttribute("id", iFrameDivID);				newNode.setAttribute("name", iFrameDivID);				document.body.appendChild(newNode);								var iNode = document.createElement("iFrame");				iNode.setAttribute("id", iFrameID);				iNode.setAttribute("name", iFrameID);				iNode.setAttribute("src", "javascript:false;");				iNode.setAttribute("scrolling", "no");				iNode.setAttribute ("frameborder", "0");				iNode.style.position = "absolute";				iNode.style.width = "0";				iNode.style.height = "0";				iNode.style.top = "0";				iNode.style.left = "0";				iNode.style.visibility = "hidden";				iNode.style.display = "none";				newNode.appendChild(iNode);								// fix for IE problem where the iFrame name wasn't being set properly,				// so the response from the POST request ended up opening in a new				// window instead of the iFrame target				self.frames[iFrameID].name = iFrameID;			}		} catch(e) {}				var postdiv = document.getElementById(iFrameDivID);		if (!postdiv) {			return false;		}				var inputFields = "";		this.postParamList["uploadType"] = "openLogIFrame";		for (param in this.postParamList) {			inputFields += "<input type='hidden' name='" + escape(param) + "' id='" + iFrameID + escape(param) + "' >\n";		}				try {			var iform = document.createElement("form");			iform.setAttribute("action", url);			iform.action = url;			iform.setAttribute("target", iFrameID);			iform.target = iFrameID;			iform.setAttribute("method", "post");			iform.innerHTML = inputFields;			postdiv.appendChild(iform);						for (param in this.postParamList) {				var field = document.getElementById(iFrameID + escape(param));				var value = new String(this.postParamList[param]);				if (field) {					// a little madness to work around the fact that Domino wants to					// replace all the spaces with plus signs					field.value = value.replace(/ /g, "%20");				}			}						iform.submit();			postdiv.removeChild(iform);		} catch(e) {			return false;		}				return true;	}			// a well-behaved JavaScript object should always	// return true after it's been created...	return true;}/*********************************************************// here's an example of adding functionality to prompt the user for // information prior to sending the error to the OpenLog databaseopenLogObject.prototype.beforeLogError = function() {	// this adds some user-supplied text to the error message we got	var answer = prompt("The error \"" + this.msg + "\" just occurred.\nWhat were you doing?", "");	this.msg += "\n\nAt the time of the error, the user was doing this:\n" + answer;		// and this adds a new POST parameter to the packet that is sent to the	// server, which will in turn create a new field called "ExtraMessage" on	// the OpenLog document that is created	this.postParamList["ExtraMessage"] = answer;}********************************************************/