WebVisibleRequestManagerItem = function(url, id) {this._url = url;this._image = null;this._isError = false;this._isComplete = false;this._retries = 0;this._id = id;this._queueTimestamp = new Date();this._sendTimestamp = null;this._doneTimestamp = null;this._expiration = null;};WebVisibleRequestManagerItem.prototype = {isExpired : function() {if (this._expiration == null) {return false;}var dt = new Date();return (this._expiration.getTime() <= dt.getTime());},isIE : function() {var browser = navigator.appName;return (browser == "Microsoft Internet Explorer");},createRequestObject : function() {if (this.isIE() == true) {return new ActiveXObject("Microsoft.XMLHTTP");}return new XMLHttpRequest();},send : function() {var request = this;this._image = document.createElement("img");this._image.onload = function() {request._isComplete = true;request._isError = false;request._doneTimestamp = new Date();WebVisibleRequestManager.endRequest(request);};this._image.onerror = function() {request._isComplete = true;request._isError = true;request._doneTimestamp = new Date();WebVisibleRequestManager.endRequest(request);};WebVisibleRequestManager.fireStatusUpdate(this._id + ": sending");this._sendTimestamp = new Date();this._expiration = new Date(this._sendTimestamp.getTime() + (WebVisibleRequestManager.TIMEOUT * 1000));this._image.src = this._url;}};var WebVisibleRequestManager = function() {var oManager = {INTERVAL : 1000,MAX_RETRIES : 5,MAX_REQUESTS : 2,TIMEOUT : 10,_items : new Array(),_active : new Array(),_idCount : 0,_isProcessing : false,_onQueueCleared : null,executeOnEmpty : function(foo) {if (typeof(foo) == 'function') {this._onQueueCleared = foo;}},isEmpty : function() {return (this._items.length == 0 && this._active.length == 0 && this._isProcessing == false);},addRequest : function(url) {var id = this._idCount;this._idCount++;var request = new WebVisibleRequestManagerItem(url, id);WebVisibleRequestManager.fireStatusUpdate(request._id + ": queuing");this._items.push(request);this.processNext();},endRequest : function(request) {if(request._isError == false) {WebVisibleRequestManager.fireStatusUpdate(request._id + ": complete (width = " + request._image.width + ")");} else if(request._retries < WebVisibleRequestManager.MAX_RETRIES) {request._retries++;WebVisibleRequestManager.fireStatusUpdate(request._id + ": error; retry " + request._retries);this._items.push(request);} else {WebVisibleRequestManager.fireStatusUpdate(request._id + ": failed after " + request._retries + " retries");}this.processNext();if (this.isEmpty() == true) {if (typeof(this._onQueueCleared) == 'function') {this._onQueueCleared();}}},processNext : function() {if (this._isProcessing == false) {this._isProcessing = true;if (this._active.length > 0) {var newActive = new Array();for (var activeIndex = 0; activeIndex < this._active.length; activeIndex++) {var active = this._active[activeIndex];if(active._isComplete == false) {WebVisibleRequestManager.fireStatusUpdate(active._id + ": waiting");newActive.push(active);continue;}}this._active = newActive;}while (this._items.length > 0 && this._active.length < WebVisibleRequestManager.MAX_REQUESTS) {var nextRequest = this._items.shift();nextRequest.send();this._active.push(nextRequest);}if(this._items.length > 0 || this._active.length > 0) {var queuedItems = "";for (var queueIndex = 0; queueIndex < this._items.length; queueIndex++) {queuedItems = queuedItems + (queueIndex == 0 ? "" : ", ") + this._items[queueIndex]._id;}var activeItems = "";for (var activeIndex2 = 0; activeIndex2 < this._active.length; activeIndex2++) {activeItems = activeItems + (activeIndex2 == 0 ? "" : ", ")+ this._active[activeIndex2]._id+ (this._active[activeIndex2].isExpired() == true ? " (expired)" : "");}this.fireStatusUpdate("Queue = { " + queuedItems + " }; Active = { " + activeItems + " }");}this._isProcessing = false;}},onStatusUpdate : function(msg) { },fireStatusUpdate : function(msg) {if (typeof(this.onStatusUpdate) == "function") {this.onStatusUpdate(msg);}}}; setTimeout(function() {WebVisibleRequestManager.processNext(); setTimeout(arguments.callee, WebVisibleRequestManager.INTERVAL);}, oManager.INTERVAL);return oManager;}();
WebVisibleEventLogger = function() {this._partnerCode = null;this._url = null;this._debug = false;this._sessionId = null;this._source = null;};WebVisibleEventLogger.prototype = {logClick : function(url, linkId, linkClass) {this.submitEvent("click", {"url" : url,"link_id" : linkId,"link_class" : linkClass});},logVideoView : function() {this.submitEvent("video_view", {});},logPrint : function() {this.submitEvent("page_print", {});},logBookmark : function(url) {this.submitEvent("bookmark", {"url" : url});},logDirectionsTo : function(url) {this.submitEvent("directions_to", {"url" : url});},logDirectionsFrom : function(url) {this.submitEvent("directions_from", {"url" : url});},logEmailForm : function(to, from, subject, body) {this.submitEvent("email_form", {"to" : to,"from" : from,"subject" : subject,"body" : body});},logPageLoad : function(url, loadTime) {this.submitEvent("page_load", {"url" : url,"load_time": loadTime});},logFormSubmit : function(formVariables) {this.submitEvent("form_submit", formVariables);},submitEvent : function(eventName, details) {var query = "";if(details != null) {for(var key in details) {if(key.length < 2) {throw "Event detail names must be at least two characters in length.";}query += (query == "" ? "" : "&") + this.encodeUrl(key) + "=" + this.encodeUrl(details[key]);}}var dt = new Date();this.submit("e=" + this.encodeUrl(eventName)+ "&s=" + this.encodeUrl(this._sessionId)+ "&p=" + this.encodeUrl(this._partnerCode)+ "&r=" + this.encodeUrl(this._source)+ "&d=" + dt.getTime()+ (query != "" ? "&" + query : ""));},submit : function(query) {var fullURI = this._url + "?" + query;this.fireStatusUpdate("URI to be loaded:\n" + fullURI);WebVisibleRequestManager.addRequest(fullURI);},encodeUrl : function(s) {return encodeURIComponent(s);},prepareLink : function(uri) {var tmp = uri.split('#');if (tmp[0].indexOf('?') < 0) {tmp[0] = tmp[0] + '?wvsessionid=' + this.getSessionId();} else {var index = tmp[0].indexOf('?');var base = tmp[0].substring(0, index + 1);var qs = tmp[0].substring(index + 1);qs = qs.replace(/\+/g, ' ');var args = qs.split('&');for (var qsIndex = 0; qsIndex < args.length; qsIndex++) {var pair = args[qsIndex].split('=');if (decodeURIComponent(pair[0]).toLowerCase() != 'wvsessionid') {base += args[qsIndex] + '&';}}tmp[0] = base + 'wvsessionid=' + this.getSessionId();}return tmp.join('#');},getSessionIdFromQuery : function() {var qs = document.location.search.substring(1, document.location.search.length);qs = qs.replace(/\+/g, ' ');var args = qs.split('&');for (var qsIndex = 0; qsIndex < args.length; qsIndex++) {var pair = args[qsIndex].split('=');if (decodeURIComponent(pair[0]) == "wvsessionid") {var value = ((pair.length == 2) ? decodeURIComponent(pair[1]) : "");if (value != null && value != "") {this.setSessionId(value);return;}}}},htmlEncode : function(str) {var div = document.createElement('div');var text = document.createTextNode(str);div.appendChild(text);return (div.innerHTML);},parsePage : function() {if (this.isSessionCreated() == true) {this.fireStatusUpdate("Session ID = " + this.getSessionId());} else {this.fireStatusUpdate("No session found");}if (this.isSessionCreated() == true) {var lastHtml = "#%&(@#&%^#@";for (var linkIndex = 0; linkIndex < document.links.length; linkIndex++) {if (document.links[linkIndex].href.substring(0, 7).toLowerCase() != "mailto:"&& document.links[linkIndex].href.substring(0, 11).toLowerCase() != "javascript:") {if(lastHtml == document.links[linkIndex].innerHTML) {continue;}lastHtml = document.links[linkIndex].innerHTML;var childObjects = document.createElement('div');for (var i = document.links[linkIndex].childNodes.length - 1; i >= 0; i--) {var o = document.links[linkIndex].childNodes[i];childObjects.appendChild(o);}document.links[linkIndex].href = this.prepareLink(document.links[linkIndex].href);for (var i = childObjects.childNodes.length - 1; i >= 0; i--) {var child = childObjects.childNodes[i];document.links[linkIndex].appendChild(child);}}}for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {if(document.forms[formIndex].action != null && document.forms[formIndex].action != ""&& document.forms[formIndex].action.substring(0, 11).toLowerCase() != "javascript:") {document.forms[formIndex].action = this.prepareLink(document.forms[formIndex].action);}}}},getPartnerCode : function() {return this._partnerCode;},setPartnerCode : function(partnerCode) {this._partnerCode = partnerCode;},getSource : function() {return this._source;},setSource : function(source) {this._source = source;},getUrl : function() {return this._url;},setUrl : function(url) {this._url = url;},getDebug : function() {return this._debug;},setDebug : function(debug) {this._debug = debug;},getSessionId : function() {return this._sessionId;},setSessionId : function(value) {this._sessionId = value;this.parsePage();},isSessionCreated : function() {return (this._sessionId != null && this._sessionId != "");},onStatusUpdate : function(msg) { },fireStatusUpdate : function(msg) {if (typeof(this.onStatusUpdate) == "function") {this.onStatusUpdate(msg);}if(this.getDebug() == true) {alert(msg);}}};
function wvAddLoadEvent(func) {var oldonload = window.onload;if (typeof window.onload != 'function') {window.onload = func;} else {window.onload = function() {try {func();} catch (ex) {}if (oldonload) {try {oldonload();} catch (ex) {}}};}};function wvUpdateStatus(msg) {var o = document.getElementById("wvStatusWindow");if (o.innerHTML != "" && o.innerHTML != null) {o.innerHTML = o.innerHTML + "<br />";}o.innerHTML = o.innerHTML + msg;o.scrollTop = o.scrollHeight;}function wvCreateStatusWindow() {document.write('\n<div id=\"wvStatusWindow\"  style=\"background-color: orange; padding: 4px; height: 200px; overflow: auto; font-family: Courier; font-size: 8pt;\">test</div>');wvEventLogger.onStatusUpdate = wvUpdateStatus;WebVisibleRequestManager.onStatusUpdate = wvUpdateStatus;}var wvEventLogger = new WebVisibleEventLogger();wvAddLoadEvent(function() { wvEventLogger.getSessionIdFromQuery(); });
wvEventLogger.setPartnerCode("");
wvEventLogger.setSource("RP");
wvEventLogger.setUrl("http://track.webvisible.com/track/log.jpg");
