﻿/*******************************************************************************************************************************************
Comment: This on click function for Omniture will work for any link i.e. anchor tag where the following is added in the class attribute 
class="omniinfo {&quot;linkName&quot;:&quot;[[LinkName]]&quot;, &quot;eventNum&quot;:&quot;[[Event]]&quot;, &quot;linkType&quot;:&quot;[[linkType]]&quot;}" 

e.g.
<a target="_blank" href="http://www.goldbook.ca" class="omniinfo {&quot;linkName&quot;:&quot;Client Site Link&quot;, &quot;eventNum&quot;:&quot;event2&quot;, &quot;linkType&quot;:&quot;e&quot;}" 
title="Visit Website" id="dnn_ctr426_MainInfo_lnkWebsite">
                    <img alt="Visit Website" src="/DesktopModules/MLFx.DNNModule.Goldbook.BusinessInfo/Images/icon_globe.png">
                </a>
***********************************************************************************************************************************************/

$(document).ready(function () {
    $("a").each(function () {
        if ($(this).hasClass("omniinfo")) {
            getOmniLinks($(this));
        }
    });

});

function getOmniLinks(current) {
    var classValue = current.attr("class");
    var jsonString = classValue.substring(classValue.indexOf("{"), classValue.lastIndexOf("}") + 1);
    if (jsonString != "") {
        var json = jQuery.parseJSON(jsonString);
        if (json !== null) {
            var p = null;
            if ('params' in json) {
                p = json.params[0];
            }

            current.bind("click", function () {
                omniLinkTrack(this, json.linkName, json.eventNum, json.linkType, p);
            });
        }
    }
}
/**
* linkType : 'e' for exit link, 'd' for file download, 'o' for generic custom link
**/
function omniLinkTrack(obj, linkName, eventNum, linkType, params) {
    var s = s_gi('torontowheels');
    if (linkType == "o") {
        s.linkTrackVars = 'events,eVar4,eVar12,prop10,prop25,prop29';

        if (sanitize(eventNum) != '') {
            s.linkTrackEvents = eventNum;
            s.events = eventNum;
        }

        if (params != null) {
            for (key in params) {
                s[key] = params[key];
            }
        }

        s.tl(obj, 'o', linkName);
    } else {
        s.linkTrackVars = "None";
        s.linkTrackEvents = "None";
        var lt = obj.href != null ? s.lt(obj.href) : "";
        if (lt == "") {
            s.tl(obj, linkType, linkName); 
        }
    }
}

function sanitize(o) {
    return o === undefined ? '' : o
}



