﻿Ajax.JSONRequest = Class.create(Ajax.Base, (function () { var id = 0, head = document.getElementsByTagName("head")[0]; return { initialize: function ($super, url, options) { $super(options); this.options.url = url; this.options.callbackParamName = this.options.callbackParamName || "callback"; this.options.timeout = this.options.timeout || 1; this.options.invokeImmediately = (!Object.isUndefined(this.options.invokeImmediately)) ? this.options.invokeImmediately : true; if (this.options.invokeImmediately) { this.request() } }, _cleanup: function () { if (this.timeout) { clearTimeout(this.timeout); this.timeout = null } if (this.transport && Object.isElement(this.transport)) { this.transport.remove() } }, request: function () { var response = new Ajax.JSONResponse(this); var key = this.options.callbackParamName, name = "_prototypeJSONPCallback_" + (id++), complete = function () { if (Object.isFunction(this.options.onComplete)) { this.options.onComplete.call(this, response) } } .bind(this); this.options.parameters[key] = name; var url = this.options.url + ((this.options.url.include("?") ? "&" : "?") + Object.toQueryString(this.options.parameters)); window[name] = function (json) { this._cleanup(); window[name] = undefined; if (Object.isFunction(this.options.onSuccess)) { response.status = 200; response.statusText = "OK"; response.setResponseContent(json); this.options.onSuccess.call(this, response) } complete() } .bind(this); this.transport = new Element("script", { type: "text/javascript", src: url }); if (Object.isFunction(this.options.onCreate)) { this.options.onCreate.call(this, response) } head.appendChild(this.transport); this.timeout = setTimeout(function () { this._cleanup(); window[name] = Prototype.emptyFunction; if (Object.isFunction(this.options.onFailure)) { response.status = 504; response.statusText = "Gateway Timeout"; this.options.onFailure.call(this, response) } complete() } .bind(this), this.options.timeout * 1000) }, toString: function () { return "[object Ajax.JSONRequest]" } } })()); Ajax.JSONResponse = Class.create({ initialize: function (request) { this.request = request }, request: undefined, status: 0, statusText: "", responseJSON: undefined, responseText: undefined, setResponseContent: function (json) { this.responseJSON = json; this.responseText = Object.toJSON(json) }, getTransport: function () { if (this.request) { return this.request.transport } }, toString: function () { return "[object Ajax.JSONResponse]" } }); var AddAnalyticsData = Class.create({ initialize: function () { this.RootURL = "http://www.avenue7.com:8080/AnalyticsService.asmx/"; this.transport = null }, AddActivity: function (EventID, PageVariables, UserGuid, SessionID) { var Query = window.location.pathname; var E = 0; var isFrameAvbl = false; if (PageVariables != "") { Query = PageVariables } try { if (blnIsPostBack != undefined && !blnIsPostBack) { E = this.getERMID() } else { E = 0 } } catch (e) { E = 0 } var A7Cookie = this.getCookie(); if (Prototype.Browser.IE) { window.onerror = function () { return true } } new Ajax.JSONRequest(this.RootURL + "AddAnalytics", { callbackParamName: "jsoncallback", parameters: { UserGuid: UserGuid, PageType: EventID, strQueryString: Query, SessionID: SessionID, strCookieID: A7Cookie, ECRMID: E} }) }, CreateA7Cookie: function (id) { var today = new Date(); var expires = 3600 * 24 * 365 * 1000; var cookie_str = "Avenue7=" + id; today.setTime(today.getTime() + expires); expires = "; expires=" + today.toGMTString(); document.cookie = cookie_str + expires }, UpdateAnalytics: function (UserGuid, ReferrerUrl) { var A7Cookie = this.getCookie(); var isFrameAvbl = false; var BrowserInfo = BrowserDetails(); var referrer = (document.referrer == undefined || document.referrer == null || document.referrer == "") ? escape(ReferrerUrl) : escape(document.referrer); var rUrl = referrer; if (A7Cookie != null && A7Cookie != "") { new Ajax.JSONRequest(this.RootURL + "AddAnalyticsCookie", { callbackParamName: "jsoncallback", parameters: { UserGuid: UserGuid, strCookieID: A7Cookie, strReferrerUrl: rUrl, strBrowserDetails: ""} }); new Ajax.JSONRequest(this.RootURL + "UpdateBrowserDetails1", { callbackParamName: "jsoncallback", parameters: { UserGuid: UserGuid, CookieID: A7Cookie, strBrowserDetails: BrowserInfo} }) } }, getCookie: function () { var cookies = document.cookie.match("Avenue7=(.*?)(;|$)"); if (cookies) { return (unescape(cookies[1])) } else { return null } }, getERMID: function () { var ECrmID = 0; try { var Url = document.URL; if (Url != undefined && Url != null && Url != "") { var temp = Url.split("#"); if (Url.indexOf("#") > -1 && temp.length > 1) { blnIsPostBack = true; if (!isNaN(temp[1])) { ECrmID = temp[1]; if (ECrmID > 100 || ECrmID == "") { ECrmID = 0 } } else { if (temp.length > 2 && !isNaN(temp[2])) { ECrmID = temp[2]; if (ECrmID > 100 || ECrmID == "") { ECrmID = 0 } } else { if (Url.toLowerCase().indexOf("#comments") > -1) { ECrmID = 52 } else { if (Url.toLowerCase().indexOf("#wall") > -1) { ECrmID = 51 } } } } } } } catch (e) { } return ECrmID } }); function DetectSilverlight() { var a = []; var b = false; var c = 0; a.IsSL = false; a.SLVersion = 0; try { var d = new ActiveXObject("AgControl.AgControl"); if (d.IsVersionSupported("3.0")) { a.SLVersion = 3 } else { if (d.IsVersionSupported("2.0")) { a.SLVersion = 2 } else { a.SLVersion = 1 } } d = null; b = true } catch (e) { var f = navigator.plugins["Silverlight Plug-In"]; if (f) { if (f.description === "1.0.30226.2") { a.SLVersion = 2 } else { a.SLVersion = parseInt(f.description[0]) } b = true } else { a.SLVersion = 0 } } if (b) { a.IsSL = true } return a } function DetectFlash() { var a = []; var b = false; a.IsFlash = false; a.FLVersion = 0; if (navigator.plugins && navigator.plugins.length) { for (x = 0; x < navigator.plugins.length; x++) { if (navigator.plugins[x].name.indexOf("Shockwave Flash") != -1) { var c = navigator.plugins["Shockwave Flash"].description.split(" "); for (var i = 0; i < c.length; ++i) { if (isNaN(parseInt(c[i]))) { continue } a.FLVersion = c[i] } b = true; break } } } else { var d = ControlVersion(); if (d != null && d != "-1") { b = true; a.FLVersion = d } } if (b) { a.IsFlash = true } return a } function BrowserVersion(a) { var b = 0; var c = a ? a.versionSearch || a.identity : ""; var d = navigator.userAgent.indexOf(c); if (d > -1) { b = parseFloat(navigator.userAgent.substring(d + c.length + 1)) } d = navigator.appVersion.indexOf(c); if (d > -1) { b = parseFloat(navigator.appVersion.substring(d + c.length + 1)) } return b } function BrowserDetails() { var a = []; var b = ""; var c = [{ string: navigator.userAgent, subString: "MSIE", identity: "IE", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Apple", identity: "Safari" }, { string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { prop: window.opera, identity: "Opera" }, { string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "iCab", identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror"}]; for (var i = 0; i < c.length; i++) { var d = c[i].string; var e = c[i].prop; if (d) { if (d.indexOf(c[i].subString) != -1) { a.Browser = c[i].identity; a.Version = this.BrowserVersion(c[i]); break } } else { if (e) { a.Browser = c[i].identity; a.Version = this.BrowserVersion(c[i]); break } } } if (a.Browser == "") { a.Browser = navigator.appName } if (a.Version == "") { a.Version = navigator.appVersion } var f = DetectSilverlight(); var g = DetectFlash(); b = a.Browser + "|" + a.Version + "|" + navigator.cookieEnabled + "|" + screen.width + "x" + screen.height + " |" + f.IsSL + " |" + f.SLVersion + " |" + g.IsFlash + " |" + g.FLVersion; return b } function ControlVersion() { var a; var b; var e; try { b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); a = b.GetVariable("$version") } catch (e) { } if (!a) { try { b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); a = "WIN 6,0,21,0"; b.AllowScriptAccess = "always"; a = b.GetVariable("$version") } catch (e) { } } if (!a) { try { b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); a = b.GetVariable("$version") } catch (e) { } } if (!a) { try { b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); a = "WIN 3,0,18,0" } catch (e) { } } if (!a) { try { b = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); a = "WIN 2,0,0,11" } catch (e) { a = -1 } } return a } var Analytics = new AddAnalyticsData(); function AddA7Cookie(UserGuid, cookieID, referrer) { try { var cookies = document.cookie.match("Avenue7=(.*?)(;|$)"); var A7Cookie = ""; if (cookies) { A7Cookie = unescape(cookies[1]) } else { Analytics.CreateA7Cookie(cookieID); cookies = document.cookie.match("Avenue7=(.*?)(;|$)"); if (cookies) { A7Cookie = unescape(cookies[1]) } else { A7Cookie = cookieID } } Analytics.UpdateAnalytics(UserGuid, referrer) } catch (e) { } };