/** cached 2010-01-26 10:05:48 maxemail.emailcenteruk.com **/

Mxm = (function() {
    var isReady = false, t, d = document, fnList = []; var onChange = function(e) { if (e && (e.type == 'DOMContentLoaded' || e.type == 'load')) { domReady(); } else if (d.readyState) { if (/^(loaded|complete)$/.test(d.readyState)) { domReady(); } } else if (!!d.documentElement.doScroll) { try { d.documentElement.doScroll('left'); domReady(); } catch (err) { } } }; var domReady = function() {
        if (isReady) return; isReady = true; clearInterval(t); if (d.removeEventListener) { d.removeEventListener('DOMContentLoaded', onChange, false); }
        d.onreadystatechange = null; window.onload = null; for (var i = 0; i < fnList.length; i++) { fnList[i](); } 
    }; return { onReady: function(fn) {
        if (isReady) { fn(); } else if (fnList.push(fn) == 1) {
            if (d.addEventListener) { d.addEventListener('DOMContentLoaded', onChange, false); }
            d.onreadystatechange = onChange; t = setInterval(onChange, 5); if (typeof window.onload == 'function') { fnList.push(window.onload); }
            window.onload = onChange;
        } 
    }, parseUrl: function(url) {
        var regUrl = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; var regQuery = /(?:^|&)([^&=]*)=?([^&]*)/g; var keys = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"]; var uri = {}; var i = keys.length; var parsed = regUrl.exec(url); while (i--) { uri[keys[i]] = parsed[i] || ""; }
        uri.request = {}; uri[keys[12]].replace(regQuery, function($0, $1, $2) { if ($1) { uri.request[$1] = $2; } }); return uri;
    }, createDelegate: function(callback, scope, args) { return function() { return callback.apply(scope || window, args || []); }; }, addEvent: function(element, type, callback, scope) { if (element.addEventListener) { element.addEventListener(type, this.normaliseEvent(callback, scope), false); } else if (element.attachEvent) { element.attachEvent('on' + type, this.normaliseEvent(callback, scope)); } }, removeEvent: function(element, type, callback, scope) { if (element.removeEventListener) { element.removeEventListener(type, this.normaliseEvent(callback, scope), false); } else if (element.detachEvent) { element.detachEvent('on' + type, this.normaliseEvent(callback, scope)); } }, normaliseEvent: function(callback, scope) {
        return function(e) {
            e = e || window.event; var event = { target: e.target || e.srcElement }; var result = callback.call(scope, event); if (result === false) { e.returnValue = false; e.cancelBubble = true; if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } }
            return result;
        };
    } 
    };
})(); Mxm.Cookie = (function() {
    return { create: function(name, value, days) {
        var expires = ''; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = '; expires=' + date.toGMTString(); }
        document.cookie = [name, '=', value, expires, '; path=/'].join('');
    }, read: function(name) {
        var nameEQ = name + '='; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); }
        return null;
    }, erase: function(name) { this.create(name, '', -1); } 
    };
})(); Mxm.Tracker = (function() {
    return { trackingServer: 'maxemail.emailcenteruk.com', cookieName: 'mxmroi', queryKey: 'mxmroi', expiryDays: 45, autoTrack: true, revenue: null, revenueEl: 'cart_total', autoLink: false, autoLinkDomains: [], roiDetails: [], init: function() { this.updateCookie(); Mxm.onReady(Mxm.createDelegate(this.onLoad, this)); }, updateCookie: function() {
        var parseUrl = Mxm.parseUrl(window.location); if (parseUrl.request[this.queryKey]) { Mxm.Cookie.create(this.cookieName, parseUrl.request[this.queryKey], this.expiryDays); }
        var cookieVal = Mxm.Cookie.read(this.cookieName); if (cookieVal) { this.roiDetails = cookieVal.split('-'); } 
    }, setExpiryDays: function(days) { this.expiryDays = days; this.updateCookie(); }, onLoad: function() {
        if (this.autoTrack !== false) { this.track(); }
        if (this.autoLink !== false) {
            Mxm.addEvent(document, 'click', function(e) {
                if (this.autoLink !== false && e.target.tagName.toLowerCase() === 'a') { return this.onLink(e.target); }
                return;
            }, this); var forms = document.getElementsByTagName('form'); for (var i = 0; i < forms.length; i++) {
                var form = forms[i]; Mxm.addEvent(form, 'submit', function(e) {
                    if (this.autoLink !== false) { return this.onSubmit(e.target); }
                    return;
                }, this);
            } 
        } 
    }, getCustomerId: function() { return this.roiDetails[0]; }, getRecipientId: function() { return this.roiDetails[1]; }, getLinkId: function() { return this.roiDetails[2]; }, getQueryKey: function() { return this.queryKey; }, getRoiCode: function() { return this.roiDetails.join('-'); }, setAutoTrack: function(enabled) { this.autoTrack = !!enabled; return this; }, appendImageRequest: function(type, vars) {
        if (!this.getCustomerId() > 0) { return; }
        var path = [this.trackingServer]; path.push('trak', type); path.push('customer', this.getCustomerId()); path.push('recipient', this.getRecipientId()); path.push('link', this.getLinkId()); if (vars instanceof Array) { for (var i = 0; i < vars.length; i++) { path.push(vars[i]); } }
        var url = '//' + path.join('/') + '?dcp=' + (new Date().getTime()); var img = document.createElement('img'); img.setAttribute('src', url); img.setAttribute('height', 1); img.setAttribute('width', 1); img.setAttribute('style', 'position:absolute;left:-2000px;'); img.setAttribute('class', 'mxmroi-tracking'); document.getElementsByTagName('body')[0].appendChild(img);
    }, track: function() {
        var vars = [], rev = this.getRevenue(); if (rev !== null) { vars.push('revenue', rev); }
        this.appendImageRequest('track', vars);
    }, complete: function() {
        this.setAutoTrack(false); var vars = [], rev = this.getRevenue(); if (rev !== null) { vars.push('revenue', rev); }
        this.appendImageRequest('complete', vars);
    }, completeGoal: function(goal, rev) {
        var vars = ['name', goal]; if (rev != undefined) { vars.push('revenue', rev); }
        this.appendImageRequest('goal', vars);
    }, setRevenue: function(val) { this.revenue = (val === null) ? null : parseInt(val, 10); return this; }, setRevenueEl: function(el) { this.revenueEl = el; return this; }, getRevenue: function() {
        var revenue = this.revenue; if (revenue === null) {
            if (typeof this.revenueEl == 'string') { this.revenueEl = document.getElementById(this.revenueEl); }
            if (this.revenueEl !== null && this.revenueEl.innerHTML) { revenue = this.revenueEl.innerHTML.match(/[0-9\.,]+/); if (revenue) { revenue = parseInt(revenue[0].replace(/[\.,]/g, ''), 10); } } 
        }
        return revenue;
    }, setAutoLink: function(enabled) { this.autoLink = !!enabled; return this; }, setAutoLinkDomains: function(domains) {
        if (domains instanceof Array) { this.autoLinkDomains = domains; } else { throw 'Mxm.Tracker.setAutoLinkDomains: argument domains needs to be of type Array'; }
        return this;
    }, checkLinkDomain: function(domain) {
        if (domain != window.location.hostname) { for (var i = 0; i < this.autoLinkDomains.length; i++) { var linkDomain = this.autoLinkDomains[i]; if (linkDomain == domain) { return true; } } }
        return false;
    }, createLinkDomain: function(urlComponents) {
        var url = urlComponents.source.match(/[^#\?]+/); var query = ''; if (urlComponents.query != '') { query = urlComponents.query; }
        if (!(urlComponents.request && urlComponents.request[this.getQueryKey()])) {
            if (query != '') { query += '&'; }
            query += this.getQueryKey() + '=' + this.getRoiCode();
        }
        var hash = ''; if (urlComponents.anchor != '') { hash = '#' + urlComponents.anchor; }
        return url + '?' + query + hash;
    }, onLink: function(el) {
        if (el.href) { var urlComponents = Mxm.parseUrl(el.href); if (this.checkLinkDomain(urlComponents.host)) { el.href = this.createLinkDomain(urlComponents); } }
        return;
    }, addLink: function(el) {
        if (el.tagName.toLowerCase() === 'a') { Mxm.addEvent(el, 'click', Mxm.createDelegate(this.onLink, this, [el])); } else { throw 'Mxm.Tracker.addLink: argument el needs to be of type A'; }
        return this;
    }, onSubmit: function(el) {
        if (el.action) { var urlComponents = Mxm.parseUrl(el.action); if (this.checkLinkDomain(urlComponents.host)) { if (el.method.toLowerCase() == 'post') { el.action = this.createLinkDomain(urlComponents); } else if (el.method.toLowerCase() == 'get') { if (el[this.getQueryKey()] == undefined) { var input = document.createElement('input'); input.setAttribute('type', 'hidden'); input.setAttribute('name', this.queryKey); input.setAttribute('value', this.getRoiCode()); el.appendChild(input); } } } }
        return;
    }, addForm: function(el) {
        if (el.tagName.toLowerCase() === 'form') { Mxm.addEvent(el, 'click', Mxm.createDelegate(this.onSubmit, this, [el])); } else { throw 'Mxm.Tracker.addForm: argument el needs to be of type FORM'; }
        return this;
    } 
    };
})(); Mxm.Tracker.init();