var gaCookies = {
    source: '',
    medium: '',
    term: '',
    content: '',
    campaign: '',
    campaignsegment: '',
    numvisits: 0,
    _uGC: function (l, n, s) {
        if (!l || l == "" || !n || n == "" || !s || s == "") return "-";
        var i, i2, i3, c = "-";
        i = l.indexOf(n);
        i3 = n.indexOf("=") + 1;
        if (i > -1) {
            i2 = l.indexOf(s, i);
            if (i2 < 0) {
                i2 = l.length;
            }
            c = l.substring((i + i3), i2);
        }
        return c;
    },
    populateGAFields: function (z) {
        this.source = this._uGC(z, 'utmcsr=', '|');
        this.medium = this._uGC(z, 'utmcmd=', '|');
        this.term = this._uGC(z, 'utmctr=', '|');
        this.content = this._uGC(z, 'utmcct=', '|');
        this.campaign = this._uGC(z, 'utmccn=', '|');
        var gclid = this._uGC(z, 'utmgclid=', '|');
        if (gclid != "-") {
            this.source = 'google';
            this.medium = 'cpc';
        }
        var csegment = this._uGC(document.cookie, '__utmv=', ';');
        if (csegment != '-') {
            var csegmentex = /[1-9]*?\.(.*)/;
            csegment = csegment.match(csegmentex);
            csegment = csegment[1];
        } else {
            csegment = '(not set)';
        }
        this.campaignsegment = csegment;
        var a = this._uGC(document.cookie, '__utma=', ';');
        var aParts = a.split(".");
        this.numvisits = aParts[5];
    }
};
var dispLeadsgenerator = 0;
var _kiq = _kiq || [];
gaCookies.populateGAFields(gaCookies._uGC(document.cookie, '__utmz=', ';'));
if (document.location.href.match(/order.aspx\?lang=SE/) || true) {
    dispLeadsgenerator = 1;
    _kiq.push(function () {
        var surveys = [33214];
        var ab=new $KI.Cookie('ab_tavling', surveys[Math.floor(Math.random()*surveys.length)]);
        if(ab) {
          KI.show_by_id('survey', ab.get());
          if ($('.ki_answer_li').length == 0) {
            $('#ki_buttons').hide();
          }
        }
    });
} /*else if (document.location.href.match(/\/se\//)
            || document.location.href.match(/hem.aspx/)
            || document.location.href.match(/leadsgenerator/)) {
    dispLeadsgenerator = 1;
    _kiq.push(function () {
        var surveys = [33211, 33212, 33213, 33567];
        KI.show_by_id('survey', surveys[Math.floor(Math.random() * surveys.length)]);
    });
}*/
if (dispLeadsgenerator === 1) {
    (function () {
        var lg = document.createElement('script');
        lg.type = 'text/javascript';
        lg.async = true;
        lg.src = "//s3.amazonaws.com/ki.js/9914/3XQ.js";
        var lgs = document.getElementsByTagName('script')[0];
        lgs.parentNode.insertBefore(lg, lgs);
    })();
}
