var ExactTarget = {
    params: {},
    xml : "",
    tag : "",
    jobId : "",
    memberId : "",
    email : "",
    list : "",
    originalLinkId: "",
    batchId : "",
    conversionLinkId : "2",
    linkAlias : "",
    displayOrder : "2",
    dataSet : "",

    init : function() {
        this.list           = this.getParam('l');
        this.email          = this.getParam('e');
        this.jobId          = this.getParam('j');
        this.batchId        = this.getParam('jb');
        this.memberId       = this.getParam('m');
        this.originalLinkId = this.getParam('u');
        this.linkAlias      = document.title;

        this.track();
    },

    track : function() {
        document.body.appendChild(this.getTag());
    },

    getParam : function(key) {
        if (this.params.length <= 0) {
            this.getParams();
        }

        return this.params[key] ? this.params[key] : '';
    },

    getParams : function() {
        var query = document.location.search;
        query = query.substring(1, query.length);
        var keyValues = query.split('&');
        for (var i = 0; i < keyValues.length; i++) {
            var keyValue = keyValues[i];
            var pos = keyValue.indexOf("=");
            if (pos > 0) {
                var key = keyValue.substring(0, pos);
                var value = keyValue.substring(pos + 1);
                this.params[key] = value;
            }
        }
    },

    getXml : function() {
        if (!this.xml) {
            this.xml = "<system><system_name>tracking</system_name><action>conversion</action>"
                     + "<member_id>" + this.memberId + "</member_id>"
                     + "<job_id>" + this.jobId + "</job_id>"
                     + "<email>" + this.email + "</email>"
                     + "<list>" + this.list + "</list>"
                     + "<original_link_id>" + this.originalLinkId + "</original_link_id>"
                     + "<BatchID>" + this.batchId + "</BatchID>"
                     + "<conversion_link_id>" + this.conversionLinkId + "</conversion_link_id>"
                     + "<link_alias>" + this.linkAlias + "</link_alias>"
                     + "<display_order>" + this.displayOrder + "</display_order>"
                     + "<data_set>" + this.dataSet + "</data_set>"
                     + "</system>";
        }

        return this.xml;
    },

    getTag : function() {
        if (!this.tag) {
            this.tag = document.createElement("img");
            this.tag.src = "http://click.exacttarget.com/conversion.aspx?xml=" + this.getXml();
            this.width = "1";
            this.height = "1";
        }

        return this.tag;
    }
}

var ExpireDays = 90;
//Do not change anything below this line
qstr = document.location.search;
qstr = qstr.substring(1, qstr.length)
function SetCookie(cookieName, cookieValue, nDays)
{
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString() + ";domain=sixflags.com; path=/;";
}

thevars = qstr.split("&");
for (i = 0; i < thevars.length; i++) {
    var aryVariable
    aryVariable = thevars[i].split('=');
    switch (aryVariable[0]) {
        case "e":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("EmailAddr", e, ExpireDays);
            break;
        case "j":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("JobID", j, ExpireDays);
            break;
        case "l":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("ListID", l, ExpireDays);
            break;
        case "u":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("UrlID", u, ExpireDays);
            break;
        case "mid":
            thevars[i] = thevars[i].replace("=", "='") + "'";
            eval(thevars[i]);
            SetCookie("MemberID", mid, ExpireDays);
            break;
        default:
            if (thevars[i] && thevars[i].indexOf('=') != -1) {
                thevars[i] = thevars[i].replace("=", "='") + "'";
                eval(thevars[i]);
            }
            break;
    }
}

