﻿
//initialize all the omniture variables
function OmnitureInit() {

    s.pageName = "";
    s.channel = "";
    s.prop1 = "";
    s.prop2 = "";
    s.prop3 = "";
    s.prop4 = "";
    s.prop5 = "";
    s.prop6 = "";
    s.prop7 = "";
    s.prop9 = "";
    s.prop19 = "";
    s.prop20 = "";
    s.prop21 = "";
    s.prop22 = "";
    s.prop23 = "";
    s.prop24 = "";

    /* Conversion Variables */
    s.events = "";
    s.products = "";
    s.eVar10 = "";
    s.eVar15 = "";
    s.eVar19 = "";
    s.eVar20 = "";
    s.eVar21 = "";
    s.eVar21 = "";
};

//Final call to output Omniture script
function OmnitureComplete() {

//    alert("OMNITURE DEBUG:\r\n\r\n pageName: '" + s.pageName + "'\n\r Channel: '" + s.channel + "'\n\r prop1: '" + s.prop1 + "'\n\r prop2: '" + s.prop2 +
//        "'\n\r prop3: '" + s.prop3 + "'\n\r prop22: '" + s.prop22 + "'\n\r prop23: '" + s.prop23 + "'\n\r prop24: '" + s.prop24 + "'\n\r prop25: '" +
//        s.prop25 + "'\n\r prop26: '" + s.prop26 + "'\r\n prop13: '" + s.prop13 + "'\n\r eVar7: '" + s.eVar7 + "'");

    if (s.t) {
        var s_code = s.t();

        if (s_code) 
        {
            document.write(s_code);
        }
    }
};

//shortened name overload
function AppendOmniVar(variable, value) 
{
    AppendOmnitureVariable(variable, value);
};

//will append the value to the current value for the specificed variable name
function AppendOmnitureVariable(variable, value) {
    // strip apostrophes
    value = value.replace("’", "");
    value = value.replace("'", "");
    
    //if (s[variable] == null || s[variable] == undefined) return;

    if (s[variable] == null || s[variable] == undefined || s[variable].length == 0) {
        s[variable] = value;
    }
    else {
        s[variable] += ":" + value;
    }
    
//    if (s[variable].length > 0) {
//        s[variable] += ":" + value;
//    }
//    else {
//        s[variable] = value;
//    }
};

//will overwrite what is currently set for the variable name with the given value
function SetOmnitureVariable(variable, value) {
    if (s[variable] == null || s[variable] == undefined) {
        return;
    }

    s[variable] = value;
};


//will append to pageName, prop1, prop2, prop3, prop22, prop23 and prop24
function AppendToDynamicOmnitureProperites(value) {
    AppendOmnitureVariable("pageName", value);
    AppendOmnitureVariable("prop3", value);
    AppendOmnitureVariable("prop22", value);
    AppendOmnitureVariable("prop23", value);
    AppendOmnitureVariable("prop24", value);
};
