/*
    SetAdvertMetaData()

    Sets HTML meta tag 'WT.ad' to include the specified AdvertId (separated by ';')
*/
function SetAdvertMetaData(AdvertId) {

    var advertMetaTag = $j("meta[name=WT.ad]");

    if (advertMetaTag.length > 0) {
        // Add the meta information to an existing tag.
        advertMetaTag.attr("content", advertMetaTag.attr("content") + ";" + AdvertId);
    } // End If
    else {
        // Create the meta tag and add the infotmation.
        $j("head").append("<meta name=\"WT.ad\" content=\"" + AdvertId + "\" />");
    } // End Else
} // SetAdvertMetaData()

/*
    SetAdvertEventListener()

    Sets an event for the specified advert to handle click tracking.
*/
function SetAdvertEventListener(AdvertId, eventListener) {

    //add the event listener
    //var event = (navigator.appVersion.indexOf("MSIE") != -1) ? "click" : "mousedown";
    var trackedlink = $j("#" + AdvertId);

    if (trackedlink.length > 0) {
        trackedlink.bind("click mousedown", function(event) { AdvertClick(event); });
    } // End If

} // SetAdvertEventListener()

/*
    AdvertClick()

    Event handler for click tracking, injects an image into the DOM to trigger
    a download that handles the tracking via URL parameters
*/
function AdvertClick(event) {
    // Tracking URL
    dcsURL = "http://sdc.rfu.com/dcs0kn0n338nrlsph0th1dc4b_7z8b/dcs.gif";

    // The ad image that triggered the click event.
    var esource = event.target || event.srcElement;

    // Find the anchor that contains the ad image click that triggered the event.
    while (esource.tagName && (esource.tagName != "A")) {
        esource = esource.parentElement || esource.parentNode;
    } // End While

    var adCurrent = new Date();
    var adcssip = window.location.hostname;
    var adcsuri = window.location.pathname;
    var ImgSrc = dcsURL + "?dcsdat=" + adCurrent.getTime() + "&dcssip=" + adcssip + "&dcsuri=" + adcsuri + "&WT.ac=" + esource.id;

    if (document.images) {
        pic = new Image;
        pic.src = ImgSrc;
    } // End If
    else {
        document.write('<IMG ALT="" BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="' + ImgSrc + '">');
    } // End Else
} // AdvertClick()
