﻿hhReplaceEvent(window, function () { hhSetupEvents("pageTracker", null, null); }, null, 'load');
var hhSiteDomains = "www.billerud.com,www.carrierbag.nu";
var hhDownloadExtensions = "avi,doc,docx,dwg,dxf,eps,exe,gz,jpg,mov,mp3,mpg,pdf,pps,ppt,pptx,rar,rtf,tar,tif,txt,wav,wmv,xls,xlsx,xml,zip";

/*
 * Setup standard onclick events with optional hooks
 * Version 1.3
 */
function hhSetupEvents(t, h1, h2) {
    var a = document.getElementsByTagName("A");
    if ( a != null ) {
        var b, d, e;
        for (var i=0; i<a.length; i++) {
            if ( a[i].href == null )
                continue;
            d = e = null;
            if ( h1 != null && typeof(h1) == "function" ) {
                h1(a[i]);
            }
            if ( (b = /^https?:\/\/([^:\/]*)[^\/]*(.*)$/i.exec(a[i].href)) != null && b.length == 3 && b[1].length > 0 && ("," + hhSiteDomains + ",").indexOf("," + b[1].toLowerCase() + ",") < 0 ) {
                d = "Exit: " + b[1].toLowerCase() + b[2].replace(/^\/$/, "");
                e = b[0];
            } else if ( (b = /^mailto:(.*)$/i.exec(a[i].href)) != null && b.length == 2 && b[1].length > 0 ) {
                d = "Mail: " + b[1].toLowerCase();
                e = b[0].toLowerCase();
            } else if ( (b = /^https?:\/\/[^\/]*(\/.*)\.([^.]*)$/i.exec(a[i].href)) != null && b.length == 3 && b[1].length > 0 && ("," + hhDownloadExtensions + ",").indexOf("," + b[2].toLowerCase() + ",") >= 0 ) {
                d = "File: " + b[1] + "." + b[2];
                e = b[1] + "." + b[2];
            } else if ( (b = /^https?:\/\/[^\/]*(\/.*)([?&])([a-z][a-z]*)(=1.*)$/i.exec(a[i].href)) != null && b.length == 5 && b[3].length > 0 && ("," + hhDownloadExtensions + ",").indexOf("," + b[3].toLowerCase() + ",") >= 0 ) {
                d = "File: " + b[1] + b[2] + b[3] + b[4];
                e = b[1] + b[2] + b[3] + b[4];
            }
            if ( e != null && h2 != null && typeof(h2) == "function" ) {
                e = h2(e);
            }
            if ( d != null ) {
                hhOnClick(a[i], "var t = document.title; document.title = '" + d.replace(/([\'\\])/g, "\\$1") + "'; " + t + "._trackPageview('" + e.replace(/([\'\\])/g, "\\$1") + "'); document.title = t;");
            }
        }
    }
}

/*
 * Add or replace an onclick event to an element
 * Version 1.0
 */
function hhOnClick(e, g) {
    hhReplaceOnClick(e, g, null);
}
function hhReplaceOnClick(e, g, r) {
    hhReplaceEvent(e, g, r, "click");
}
function hhReplaceEvent(e, g, r, n) {
    if ( typeof(e) != "object" || n == null )
        return;
    var f = (typeof(g) == "function" ? g : hhGetEventHandler(g));
    var q = (typeof(r) == "function" ? r : hhGetEventHandler(r));
    if ( typeof(e.addEventListener) == "function" || typeof(e.addEventListener) == "object" ) {
        if ( q != null ) {
            e.removeEventListener(n, q, false);
        }
        if ( f != null ) {
            e.removeEventListener(n, f, false);
            e.addEventListener(n, f, false);
        }
    } else if ( typeof(e.attachEvent) == "function" || typeof(e.attachEvent) == "object" ) {
        if ( q != null ) {
            e.detachEvent('on' + n, q);
        }
        if ( f != null ) {
            e.detachEvent('on' + n, f);
            e.attachEvent('on' + n, f);
        }
    }
}

/*
 * Create or get an event handler from a code string
 * Version 1.0
 */
var hhLiteralEventHandlers = new Array();
function hhGetEventHandler(t) {
    var f;
    if ( t == null )
        return null;
    if ( (f = hhLiteralEventHandlers[t]) != null )
        return f;
    f = hhLiteralEventHandlers[t] = new Function(t);
    return f;
}
