//Properties
//***********************************************************************************************************************************************
    var dcsHTML = 0;;
    var dcsPOLL = 1;

    var dcsDomain = "ssdc.comcast.net";

    var dcsURI = "";
    var dcsTitle = "";
    var dcsHeadlines = "";
    var dcsModules = "";
    var dcsBanners = "";
    var dcsRef = "";

    //Images Array
    //***********************************************************************************************************************************************
    var gImages = new Array;
    var gIndex = 0;

    //Objects to hold the meta data
    //***********************************************************************************************************************************************
                                    //This is what they appear to hold
    var DCS = new Object();         //holds browser url information
    var WT = new Object();          //holds user information, screen size, date, browser type, etc...
    var COMCAST = new Object();     //all tags not included in the other groups
//Sets
//***********************************************************************************************************************************************
    function dcsClearValues() {
        dcsID = "";
        dcsURI = "";
        dcsTitle = "";
        dcsModules = "";
        dcsBanners = "";
        dcsRef = "";
        dcsSIP = window.location.hostname;
    }
    function setModule(name) {
        if (dcsModules.length == 0) {
            dcsModules = name
        } else {
            dcsModules += ";" + name;
        }
    }
    function setHeadlines(name) {
        if (dcsHeadlines.length == 0) {
            dcsHeadlines = name
        } else {
            dcsHeadlines += ";" + name;
        }
    }
    function setBanner(name) {
        if (dcsBanners.length == 0) {
            dcsBanners = name
        } else {
            dcsBanners += ";" + name;
        }
    }
    function addBanner(name) {
        setBanner(name);
    }
    function setTitle(title) {
        if (typeof title == "undefined" || title == null) {
            title = "";
        }
        dcsTitle = title;
    }
    function setURI(uri) {
        if (typeof uri == "undefined" || uri == null) {
            uri = "";
        }
        dcsURI = uri;
    }
    function setReferrer(ref) {
        if (typeof ref == "undefined" || ref == null) {
            ref = "";
        }
        dcsRef = ref;
    }
//Gets
//***********************************************************************************************************************************************
    function getID(type) {
        var id = "";
        switch (type) {
            case dcsPOLL:
                id = "dcs7bjhh110000oyioyaka1kl_7j9u";
                break;
            case dcsHTML:
                if (isProduction()) {
                    id = "dcs8ir0f010000oyioyaka1kl_8j7n";
                } else {
                    id = "dcscah7h110000oyioyaka1kl_7j8d";
                }
                break;
            default:
                if (isProduction()) {
                    id = "dcs8ir0f010000oyioyaka1kl_8j7n";
                } else {
                    id = "dcscah7h110000oyioyaka1kl_7j8d";
                }
                break;
        }
        if (typeof id == "undefined" || id == null || id.length == 0) {
            //if still nothing hard set to production value
            id = "dcs8ir0f010000oyioyaka1kl_8j7n";
        }
        return id;
    }
    function getModule() {
        return append("CM.mn", dcsModules);
    }
    function getHeadlines() {
        return append("CM.hl", dcsHeadlines);
    }
    function getBanner() {
        return append("WT.ad", dcsBanners);
    }
    function getTitle() {
        return append("WT.ti", dcsTitle);
    }
    function getURI() {
        return append("dcsurl", dcsURI);
    }
    function getSIP() {
        return append("dcssip", dcsSIP);
    }
    function getReferrer() {
        if (dcsRef.length > 0) {
            return append("dcsref", dcsRef);
        } else {
            if ((window.document.referrer != "") && (window.document.referrer != "-")) {
                return append("dcsref", new String(window.document.referrer));
            }
        }
        return "";
    }
//Methods
//***********************************************************************************************************************************************
    function append(name, value) {
        //appends a name value pair to the querystring
        if (typeof value == "undefined" || value == null) {
            value = "";
        }
        if (value.length > 0) {
            return "&" + name + "=" + escape(value);
        } else {
            return "";
        }
    }
    function dcsComcast() {
        var query = "";
        for (name in COMCAST) {
            if (COMCAST[name]) {
                query += append(name, COMCAST[name]);
            }
        }
        return query;
    }
    function dcsDCS() {
        var query = "";
        for (name in DCS) {
            if (DCS[name]) {
                query += append(name, DCS[name]);
            }
        }
        return query;
    }
    function dcsWT() {
        var query = "";
        for (name in WT) {
            if (WT[name]) {
                query += append("WT." + name, WT[name]);
            }
        }
        return query;
    }
    function dcsTag() {
        var query = "";
        query += dcsComcast();
        query += dcsDCS();
        query += dcsWT();
        query += getModule() + getBanner() + getHeadlines();
        dcsTrack(query);
    }
    function dcsCreateImage(dcsSrc) {
        //final call to write the image
        //when image loads the page is tracked
        if (document.images) {
            gImages[gIndex] = new Image;
            gImages[gIndex].src = dcsSrc;
            gIndex++;
        } else{
            document.write("<img alt=\"\" border=\"0\" height=\"1\" name=\"DCSIMG\" src=\"" + dcsSrc + "\" width=\"1\">");
        }
    }
    function dcsTrack(query, type) {
        if (typeof type == "undefined") {
            type = dcsHTML;
        }
        var path = "http" + (window.location.protocol.indexOf('https:') == 0 ? "s" : "") + "://" + dcsDomain + "/" + getID(type) + "/dcs.gif?";
        if (query.indexOf("&") == 0) {
            query = query.substring(1);
        }
        path += query;
        if (path.length > 2040 && navigator.userAgent.indexOf('MSIE') >= 0) {
            path = path.substring(0, 2040) + "&WT.tu=1";
        }
        dcsCreateImage(path);
        dcsClearValues();   //clear all values when finished to prepare for other calls
    }
    //Fill Variables
    //***********************************************************************************************************************************************
    function dcsVar() {
        //creates the main objects with some generic information
        //stuff can be added here or removed
        var dCurrent = new Date();
        WT.tz = dCurrent.getTimezoneOffset() / 60 * -1;
        WT.bh = dCurrent.getHours();
        WT.ul = navigator.appName == "Netscape" ? navigator.language : navigator.userLanguage;
        if (typeof(screen) == "object") {
            WT.cd = screen.colorDepth;
            WT.sr = screen.width + "x" + screen.height;
        }
        if (typeof(navigator.javaEnabled()) == "boolean") {
            WT.jo = navigator.javaEnabled() ? "Yes" : "No";
        }
        WT.ti = document.title;
        WT.js = "Yes";
        if (typeof(gVersion) != "undefined") {
            WT.jv = gVersion;
        }
        DCS.dcsuri = window.location.pathname;
        DCS.dcsqry = window.location.search;
        if ((window.document.referrer != "") && (window.document.referrer != "-")) {
            if (!(navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) < 4)) {
                DCS.dcsref = window.document.referrer;
            }
        }
        DCS.dcssip = window.location.hostname;
        DCS.dcsdat = dCurrent.getTime();
    }
    function dcsMeta() {
        //loops through meta tags and records them in the objects
        var myDocumentElements;
        if (document.all) {
            myDocumentElements = document.all.tags("meta");
        } else if (document.documentElement) {
            myDocumentElements = document.getElementsByTagName("meta");
        }
        if (typeof(myDocumentElements) != "undefined") {
            for (var i = 0 ; i < myDocumentElements.length ; i++) {
                myMeta = myDocumentElements.item(i);
                if (myMeta.name) {
                    if (myMeta.name.indexOf("WT.") == 0) {
                        WT[myMeta.name.substring(3)] = myMeta.content;
                    } else if (myMeta.name.indexOf("DCS.") == 0) {
                        DCS[myMeta.name.substring(4)] = myMeta.content;
                    } else {
                        //added as a catch all for all meta tags to be tagged
                        COMCAST[myMeta.name] = myMeta.content;
                    }
                }
            }
        }
    }
//Util
//***********************************************************************************************************************************************
    function castString(param) {
        if (typeof param == "undefined" || param == null) {
            param = "";
        } else if (typeof param != "string") {
            param += "";
        }
        return param;
    }
    function displayArguments() {
        var message = "";
        for (var x = 0 ; x < arguments.length ; x++) {
            if (arguments[x].length > 0) {
                message += x + ": " + arguments[x] + "\n";
            }
        }
        if (message.length > 0) {
            alert(message);
        }
    }
//Tracking Items
//***********************************************************************************************************************************************
    //Call Tracking for a banner
    //***********************************************************************************************************************************************
    function trackBanners(uri, name, referrer, url) {
        uri = castString(uri);
        name = castString(name);
        referrer = castString(referrer);
        url = castString(url);
        if (uri.indexOf(".banner") == -1) {
            uri += ".banner";
        }
        if (name.length == 0) {
            name = "UnknownName";
        }
        DCS = new Object();
        DCS.dcsuri = uri;
        DCS.dcspro = window.location.protocol;
        DCS.dcssip = window.location.hostname;
        var dCurrent = new Date();
        DCS.dcsdat = dCurrent.getTime();
        if (referrer.length == 0) {
            referrer = window.location.href;
        }
        var query = append("WT.ac", name) + dcsDCS();
        dcsTrack(query);
        if (url.length > 0) {
            window.open(url, "tracking");
        }
    }

    //Call Tracking for an external link
    //***********************************************************************************************************************************************
    function linkTracking(name, redirect, windowName, params) {
        trackExternalLink(name, "Old Tracking", redirect);
    }
    function trackExternalLink(uri, title, referrer, url, extra) {
        uri = castString(uri);
        title = castString(title);
        referrer = castString(referrer);
        url = castString(url);
        extra = castString(extra);
        if (uri.indexOf(".exlink") == -1) {
            uri += ".exlink";
        }
        setTitle(title);
        DCS = new Object();
        DCS.dcsuri = uri;
        DCS.dcspro = window.location.protocol;
        DCS.dcssip = window.location.hostname;
        var dCurrent = new Date();
        DCS.dcsdat = dCurrent.getTime();
        if (referrer.length == 0) {
            referrer = window.location.href;
        }
        var query = getTitle() + dcsDCS() + extra;
        dcsTrack(query);
        if (url.length > 0) {
            window.open(url, "tracking");
        }
    }
    //Call Tracking for a Poll
    //***********************************************************************************************************************************************
    function trackPoll(uri, value) {
        uri = castString(uri);
        value = castString(value);
        setURI(uri);
        setTitle("Comcast Polls");
        var query = getURI() + getTitle() + "&" + value;
        dcsTrack(query, dcsPOLL);
    }
    //Call Tracking for flash
    //***********************************************************************************************************************************************
    function trackFlash(uri, title, referrer, extra) {
        uri = castString(uri);
        title = castString(title);
        referrer = castString(referrer);
        extra = castString(extra);
        setTitle(title);
        DCS = new Object();
        DCS.dcsuri = uri;
        DCS.dcspro = window.location.protocol;
        DCS.dcssip = window.location.hostname;
        var dCurrent = new Date();
        DCS.dcsdat = dCurrent.getTime();
        if (referrer.length == 0) {
            referrer = window.location.href;
        }
        DCS.dcsref = referrer;
        var query = getTitle() + dcsDCS() + extra;
        dcsTrack(query);
    }
