/* Plugin Config */

s.usePlugins=true;

var hhAlreadyRun = false;
function s_doPlugins(s) {
    // Run the following code only once
    if ( hhAlreadyRun )
        return;
    hhAlreadyRun = true;
    // Path variables
    if ( document.URL.match(/[^:]\/\/*standalone\/./i) )
        s.pageName = s.pageName.replace(/(\\ekonomifakta.se\\[^\\]*)$/i, "\\[Standalone]$1");
    var hhElements = s.pageName.split("\\");
    var hhI;
    if ( hhElements != null && hhElements.length > 1 ) {
        for (hhI=0; hhI<hhElements.length; hhI++) {
            hhElements[hhI] = hhCleanText(hhElements[hhI]);
        }
        var hhL = 5;
        if ( hhElements[hhElements.length-1].length > 0 && hhElements[hhElements.length-2].length > 0 ) {
            s.prop3 = s.hier1 = "";
            for (hhI=hhElements.length-1; hhI>=0; hhI--) {
                if ( hhI == hhElements.length-2 )
                    continue;
                s.hier1 += hhElements[hhI] + "/";
                // Split available length for remaining levels
                s.prop3 = hhByteCut(hhElements[hhI], Math.ceil((99 - hhLength(s.prop3)) / (hhL > 1 ? hhL : hhI + 1))) + (s.prop3 == "" ? "" : "\\" + s.prop3);
                hhL--;
            }
            s.pageName = s.prop3;
            s.hier1 += "[Main]";
            s.channel = s.hier1.replace(/^([^\/]*\/[^\/]*).*$/, "$1");
            s.prop1 = s.hier1.replace(/^([^\/]*\/[^\/]*\/[^\/]*).*$/, "$1");
            s.prop2 = "";
            for (hhI=0; hhI<hhElements.length; hhI++) {
                s.prop2 += (hhI == 0 ? "" : "\\") + hhCut(hhElements[hhI], 22 + hhI - hhElements.length);
            }
        }
    }
    // Page URL
    if ( document.URL != null )
        s.prop9 = document.URL.replace(/^[^\/]*\/\/[^\/]*[\/]/, "");
    // Internal search string
    var hhE = document.getElementById("ctl00_MidRegion_SearchBox");
    if ( hhE != null && hhE.value != null ) {
        s.prop7 = s.eVar7 = hhLowerCase(hhCleanTextAsterisk(hhE.value));
    }
    // Campaign codes
    s.prop10 = s.pageName;
    var csref = s.getQueryParam("csref");
    if ( csref != null && csref != "" ) {
        csref = s.prop5 = s.campaign = hhLowerCase(hhCleanText(csref));
        s.c_w("csref", csref, 0);
    } else {
        csref = s.c_r("csref");
    }
    if ( csref != null && csref != "" ) {
        s.prop10 = csref + "|" + s.pageName.substring(0, 99-csref.length);
    }
    // Compare statistics
    var hhCompState = { v0 : null, v1 : null, t : null };
    function hhCompLogger() {
        hhCompState.t = null;
        var i, e;
        var c = [ document.getElementById("serie1"), document.getElementById("serie2") ];
        var v = [ null, null ];
        var n = 0;
        s.events = s.products = "";
        try {
            for (i=0; i<2; i++) {
                if ( (v[i] = c[i].options[c[i].selectedIndex].value) != null && v[i] != "" && (v[i] = c[i].options[c[i].selectedIndex].text) != null && (v[i] = hhCleanText(v[i])) != "" ) {
                    s.products += (s.products == "" ? "" : ",") + ";" + v[i] + ";1;1";
                    n++;
                }
                hhReplaceEvent(c[i], hhCompChange, null, "change");
            }
            if ( n == 1 )
                s.events = "scView";
            if ( n == 2 )
                s.events = "scCheckout";
            if ( n == 1 || n == 2 )
                s.sa(s_account + ",halvarsson-searchc-ekonomifakta");
            if ( hhCompState.v0 != null && (n == 1 || n == 2) && (v[0] != hhCompState.v0 || v[1] != hhCompState.v1) ) {
                s.linkTrackEvents = s.events;
                s.linkTrackVars = "events,products";
                s.tl(true, "o", "Compare statistics");
                s.linkTrackEvents = s.linkTrackVars = "None";
            }
            hhCompState.v0 = v[0];
            hhCompState.v1 = v[1];
        } catch (e) {}
    }
    function hhCompChange() {
        if ( hhCompState.t != null )
            clearTimeout(t);
        hhCompState.t = setTimeout(hhCompLogger, 7000);
        hhReplaceEvent(window, "clearTimeout(" + hhCompState.t + ")", null, "unload");
    }
    hhCompLogger();
    // Landing page
    hhLandingPage(s, 2);
    // Time on site
    hhLogInteractionTime(s, 1);
    // Area for last click
    if ( (hhE = s.c_r("hhclickarea")) != null && hhE != "" ) {
        s.prop4 = s.eVar4 = hhE;
    }
    // Log clicks
    hhAttachClickLoggers();
    // Reattach click loggers when elements have been loaded
    if ( typeof(Sys) == "object" && typeof(Sys.WebForms) == "object" && typeof(Sys.WebForms.PageRequestManager) == "function" && typeof(Sys.WebForms.PageRequestManager.getInstance) == "function" && typeof(Sys.WebForms.PageRequestManager.getInstance()) == "object" && typeof(Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded) == "function" ) {
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(hhAttachClickLoggers);
    } else if ( typeof(window.addEventListener) == "function" ) {
        window.addEventListener("load", hhAttachClickLoggers, false);
    } else if ( typeof(window.attachEvent) == "function" ) {
        window.attachEvent("onload", hhAttachClickLoggers);
    }
}

s.doPlugins=s_doPlugins;

/********************** CLICK-LOGGING SECTION ***********************/
/* Site-specific DOM event handlers and attachers are defined here  */

function hhAttachClickLoggers() {
    // Definitions
    if ( (hhElements = document.getElementsByTagName("SPAN")) != null && hhElements.length > 0 ) {
        for (hhI=0; hhI<hhElements.length; hhI++)
            if ( hhElements[hhI].className == "tooltip" )
                hhOnClick(hhElements[hhI], "hhDefinitionView('" + hhCleanText(hhElements[hhI].innerHTML.replace(/<[^>]*>/g, "")).replace(/\\/g, "\\\\").replace(/\'/g, "\\'") + "'); return true;");
    }
    // Tag functions
    if ( (hhE = hhFindByClassName(document.getElementById("right-col"), "div.tagBox ul.smallBoxLinks")) != null && (hhElements = hhE.getElementsByTagName("A")) != null && hhElements.length > 0 ) {
        for (hhI=0; hhI<hhElements.length; hhI++)
            hhOnClick(hhElements[hhI], "hhTagFunction('" + hhCleanText(hhElements[hhI].innerHTML.replace(/<[^>]*>/g, "")).replace(/\\/g, "\\\\").replace(/\'/g, "\\'") + "');");
    }
    // Click-area tagging
    hhClickArea([
    { a : "Main menu", i : "top-menu" },
    { a : "Ekonomifakta logo", i : "company-logo" },
    { a : "Top search toolbox", i : "top-search" },
    { a : "Right-column toolbox", i : "right-toolbox" },
    { a : "Left menu", i : "body", c : "leftNav" },
    { a : "Breadcrumbs", i : "body", c : "breadcrumbs" },
    { a : "Main content", i : "content" },
    { a : "Main wide content", i : "widecontent" },
    { a : "Right column", i : "right-col" },
    { a : "Upper footer", i : "footer-navigation" },
    { a : "Lower footer", i : "footer-credits" }
    ]);
}

/*
 * Function for logging definition views (answers)
 */
var hhLoggedDefinitions = "|";
function hhDefinitionView(h) {
    var n = hhCleanText(h);
    if ( n != "" && hhLoggedDefinitions.indexOf("|" + n + "|") < 0 ) {
        hhLoggedDefinitions += n + "|";
        s.linkTrackVars = "prop11,eVar1";
        s.prop11 = s.eVar1 = hhByteCut(n, 75) + hhByteCut(s.pageName.replace(/^([^\\]*).*$/, " ($1)"), 25);
        setTimeout('s.tl(true, "o", "Definition (" + s.pageName + ")"); s.linkTrackVars = "None";', 0);
    }
    return true;
}

/*
 * Function for logging tag functions
 */
function hhTagFunction(h) {
    var n = hhCleanText(h);
    if ( n != "" ) {
        setTimeout('s.tl(true, "o", "Tag function: ' + h.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"") + '")', 0);
    }
    return true;
}

/*
 * Function for adding click-area handlers
 */
function hhClickArea(a) {
    var t = "var d = new Date(); d.setTime(d.getTime() + 20000); s.c_w('hhclickarea', '###', d);";
    var d = hhGetEventHandler(t.replace(/###/g, "[Untracked link area]"));
    var f = document.getElementsByTagName("A");
    var e, g, i, j, k, o;
    if ( f != null )
        for (i=0; i<f.length; i++)
            hhOnClick(f[i], d);
    for (j=0; j<a.length; j++) {
        if ( typeof(a[j] == "object" ) && (e = document.getElementById(a[j].i)) != null ) {
            o = hhGetEventHandler(t.replace(/###/g, a[j].a.replace(/\\/g, "\\\\").replace(/\'/g, "\\'")));
            if ( a[j].c == null && (f = e.getElementsByTagName("A")) != null && f.length > 0 ) {
                for (i=0; i<f.length; i++)
                    hhReplaceOnClick(f[i], o, d);
            } else if ( a[j].c == null && e.nodeName == "A" ) {
                hhReplaceOnClick(e, o, d);
            } else if ( a[j].c == null && e.parentNode.nodeName == "A" ) {
                hhReplaceOnClick(e.parentNode, o, d);
            } else if ( a[j].c != null && (g = e.getElementsByTagName("DIV")) != null && g.length > 0 ) {
                for (k=0; k<g.length; k++) {
                    if ( g[k].className == a[j].c ) {
                        if ( (f = g[k].getElementsByTagName("A")) != null && f.length > 0 )
                            for (i=0; i<f.length; i++)
                                hhReplaceOnClick(f[i], o, d);
                        break;
                    }
                }
            }
        }
    }
}

/************************** PLUGINS SECTION *************************/
/* You may insert any plugins you wish to use here.                 */
/*
 * Plugin: hhLowerCase
 */
function hhLowerCase(s) {
    if ( s == null )
        return null;
    return s.replace(/(^  *|  *$)/g, "").toLowerCase();
}

/*
 * Log the time since the last interaction in the session
 * Specify the s object and the event number (numeric, no subrelations)
 */
function hhLogInteractionTime(s, v) {
    var lastTime = s.c_r("hhinteractiontime");
    var currentTime = (new Date()).getTime();
    if ( lastTime != null && lastTime != "" && lastTime != 0 && lastTime <= currentTime && currentTime - lastTime < 1800000 ) {
        if ( currentTime - lastTime < 1000 )
            return;
        var eventName = "event" + v;
        if ( s.events == null || s.events == "" ) {
            s.events = eventName;
        } else {
            s.events += "," + eventName;
        }
        var eventIncrementor = eventName + "=" + (Math.round((currentTime - lastTime) / 600) / 100);
        if ( s.products == null || s.products == "" ) {
            s.products = ";;;;" + eventIncrementor;
        } else {
            s.products = s.products.replace(/^([^;,]*);?([^;,]*);?([^;,]*);?([^;,]*);?([^;,]*)/, "$1;$2;$3;$4;$5|" + eventIncrementor).replace(/^([^;]*;[^;]*;[^;]*;[^;]*;)\|/, "$1");
        }
    }
    s.c_w("hhinteractiontime", currentTime, 0);
}

/*
 * Log the landing page to an eVar
 */
function hhLandingPage(s, n) {
    var p = s.c_r("hhlandingpage");
    if ( p != null && p != "" )
        return;
    s["eVar" + n] = s.pageName;
    s.c_w("hhlandingpage", s.pageName, 0);
}

/*
 * Find an element recursively by class name
 */
function hhFindByClassName(e, c) {
    if ( e == null || c == null || c == "" )
        return e;
    var a = /^ *([^ ][^ ]*)\.([^ ][^ ]*) *(.*)$/.exec(c);
    var b, i, f;
    if ( a != null && (b = e.getElementsByTagName(a[1].toUpperCase())) != null )
        for (i=0; i<b.length; i++)
            if ( b[i].className == a[2] && (f = hhFindByClassName(b[i], a[3])) != null )
                return f;
    return null;
}

/*
 * Write a line of debug info if supported
 */
function tryDump(s) {
    if ( typeof(dump) == "function" )
        dump(s + "\r\n");
}

/*
 * Plugin: hhShortenText
 */
function hhShortenText(s) {
    return s.replace(/(https?|file):\/*[^\/]*/i, "").replace(/200([0-9])/g, "0$1").replace(/\.html/i, "").replace(/([a-zA-Z][a-zA-Z])[a-zA-Z]/g, "$1");
}

/*
 * Plugin: getQueryParam 2.1 - return query string parameter(s)
 */
s.getQueryParam=new Function("p","d","u",""
+"var s=this,v='',i,t;d=d?d:'';u=u?u:(s.pageURL?s.pageURL:s.wd.locati"
+"on);if(u=='f')u=s.gtfs().location;while(p){i=p.indexOf(',');i=i<0?p"
+".length:i;t=s.p_gpv(p.substring(0,i),u+'');if(t)v+=v?d+t:t;p=p.subs"
+"tring(i==p.length?i:i+1)}return v");
s.p_gpv=new Function("k","u",""
+"var s=this,v='',i=u.indexOf('?'),q;if(k&&i>-1){q=u.substring(i+1);v"
+"=s.pt(q,'&','p_gvf',k)}return v");
s.p_gvf=new Function("t","k",""
+"if(t){var s=this,i=t.indexOf('='),p=i<0?t:t.substring(0,i),v=i<0?'T"
+"rue':t.substring(i+1);if(p.toLowerCase()==k.toLowerCase())return s."
+"epa(v)}return ''");

/*
 * Plugin: getValOnce 0.2 - get a value once per session or number of days
 */
s.getValOnce=new Function("v","c","e",""
+"var s=this,k=s.c_r(c),a=new Date;e=e?e:0;if(v){a.setTime(a.getTime("
+")+e*86400000);s.c_w(c,v,e?a:0);}return v==k?'':v");
 
/*
 * Function - read combined cookies v 0.2
 */
s.c_rr=s.c_r;
s.c_r=new Function("k",""
+"var s=this,d=new Date,v=s.c_rr(k),c=s.c_rr('s_pers'),i,m,e;if(v)ret"
+"urn v;k=s.ape(k);i=c.indexOf(' '+k+'=');c=i<0?s.c_rr('s_sess'):c;i="
+"c.indexOf(' '+k+'=');m=i<0?i:c.indexOf('|',i);e=i<0?i:c.indexOf(';'"
+",i);m=m>0?m:e;v=i<0?'':s.epa(c.substring(i+2+k.length,m<0?c.length:"
+"m));if(m>0&&m!=e)if(parseInt(c.substring(m+1,e<0?c.length:e))<d.get"
+"Time()){d.setTime(d.getTime()-60000);s.c_w(s.epa(k),'',d);v='';}ret"
+"urn v;");

/*
 * Function - write combined cookies v 0.2
 */
s.c_wr=s.c_w;
s.c_w=new Function("k","v","e",""
+"var s=this,d=new Date,ht=0,pn='s_pers',sn='s_sess',pc=0,sc=0,pv,sv,"
+"c,i,t;d.setTime(d.getTime()-60000);if(s.c_rr(k)) s.c_wr(k,'',d);k=s"
+".ape(k);pv=s.c_rr(pn);i=pv.indexOf(' '+k+'=');if(i>-1){pv=pv.substr"
+"ing(0,i)+pv.substring(pv.indexOf(';',i)+1);pc=1;}sv=s.c_rr(sn);i=sv"
+".indexOf(' '+k+'=');if(i>-1){sv=sv.substring(0,i)+sv.substring(sv.i"
+"ndexOf(';',i)+1);sc=1;}d=new Date;if(e){if(e.getTime()>d.getTime())"
+"{pv+=' '+k+'='+s.ape(v)+'|'+e.getTime()+';';pc=1;}}else{sv+=' '+k+'"
+"='+s.ape(v)+';';sc=1;}if(sc) s.c_wr(sn,sv,0);if(pc){t=pv;while(t&&t"
+".indexOf(';')!=-1){var t1=parseInt(t.substring(t.indexOf('|')+1,t.i"
+"ndexOf(';')));t=t.substring(t.indexOf(';')+1);ht=ht<t1?t1:ht;}d.set"
+"Time(ht);s.c_wr(pn,pv,d);}return v==s.c_r(s.epa(k));");

