﻿/* Copyright Channel Intelligence, Inc. 2002-2010");
*/
function TourViewer(headerId, footerId, topBannerId, bottomBannerId) {
    this.ScaleWindow = function(tourHeight, tourWidth) {
        var header = document.getElementById(headerId);
        var footer = document.getElementById(footerId);
        var topBanner = document.getElementById(topBannerId);
        var bottomBanner = document.getElementById(bottomBannerId);

        var headerHeight = header != null ? header.clientHeight : 0;
        var footerHeight = footer != null ? footer.clientHeight : 0;
        var topBannerHeight = topBanner != null ? topBanner.clientHeight : 0;
        var bottomBannerHeight = bottomBanner != null ? bottomBanner.clientHeight : 0;

        var totalHeight = headerHeight + footerHeight + topBannerHeight + bottomBannerHeight + tourHeight;
        try {
            top.resizeTo(tourWidth, totalHeight);
        }
        catch (e) {
            for (var i = 0; i < parent.frames.length; i++) {
                var iframe = parent.frames[i];
                if (iframe.location.href.match("TourViewer.aspx") != null) {
                    totalHeight = iframe.contentWindow.document.body.scrollHeight + headerHeight + footerHeight + topBannerHeight + bottomBannerHeight;
                    iframe.height = totalHeight;
                    iframe.width = tourWidth;
                }
            }
        }
    }
}

function TrackTab(tabGuid) {
    if (window[tabGuid]) {
        window[tabGuid].Track();
    }
}

function TrueTagLog(trueTagDomainName, documentReferrer, eventCode, content, tab, publisher, host, product, sref) {
    var tracked = false;
    this.Track = function() {
        if (tracked == false) {
            var fullQuery = location.search.replace('?', '');
            //Content={0}&Tab={1}&Publisher={2}&Host={3}&Product={4}&sref={5}&FullQueryString={6}
            var ciiBse = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
            var ciiDte = new Date();
            var ciiRnd = Math.floor((ciiDte.getTime() - 946875600000) / 604800000);
            var ciiRV = ciiBse.charAt((ciiDte.getYear() < 2000 ? ciiDte.getFullYear() : ciiDte.getYear()) - 2000) + ciiBse.charAt(ciiDte.getMonth() + 1) + ciiBse.charAt(ciiDte.getDate()) + ciiBse.charAt(ciiDte.getHours()) + ciiBse.charAt(ciiDte.getMinutes()) + ciiBse.charAt(ciiDte.getSeconds()) + ciiBse.charAt((ciiRnd - (ciiRnd % 16)) / 16) + ciiBse.charAt(ciiRnd % 16);

            if (typeof (ciiLog) == 'undefined') {
                ciiLog = {};
            }

            ciiLog[ciiRV] = document.createElement("img");
            ciiLog[ciiRV].src = location.protocol + '//'+ trueTagDomainName +'?eid=' + eventCode + '&sReferrer=' + encodeURI(documentReferrer) + '&sRnd=' + ciiRV + 'Content=' + content + '&Tab=' + tab + '&Publisher=' + publisher + '&Host=' + host + '&Product=' + product + '&sref=' + sref + '&FullQueryString=' + encodeURI(fullQuery);
            tracked = true;
        }
    }
}

function OnClientTabSelected(sender, eventArgs) {
    var tab = eventArgs.get_tab();
    if (tab != null) {
        SwitchTabs(tab.get_tabStrip());
    }
}

function OnTabstripLoad(sender) {
    SwitchTabs(sender);
}

function SwitchTabs(tabstrip) {
    if (tabstrip != null) {
        var tabs = tabstrip.get_tabs();
        var tabCount = tabs.get_count();
        for (var i = 0; i < tabCount; i++) {
            var tab = tabs.getTab(i);
            if (tab != null) {
                var isSelected = tab.get_selected();
                var img_text = isSelected == true ? "current tab" : "tab " + (i + 1) + " of " + tabCount;
                var img = tab.get_imageElement();
                if (img != null) {
                    img.alt = img_text;
                    img.title = img_text;
                }
                var link = tab.get_linkElement();
                var frameTitle = "Tab Content";
                var frameIndex = isSelected == true ? -1 : (tabCount + 1) * 10
                if (link != null) {
                    link.tabIndex = (i + 1) * 10;
                    frameTitle = link.title;
                }
                var frames = document.getElementsByName("tabContent");
                for (var f = 0; f < frames.length; f++) {
                    frames[f].title = frameTitle;
                }
                if (isSelected == true) {
                    TrackTab(tab.get_value());
                }
            }
        }
    }
}
function mailThisUrl() {

    var u = encodeURIComponent(window.location.href);
    var m = "I thought this might interest you...";
    var bodyEncoded = encodeURIComponent(document.title + " ") + u;

    var emailLink = "mailto:?subject=" + encodeURIComponent(m) +
        "&body=" + bodyEncoded;
    window.location = emailLink;
}
