//require nuskin.util namespace
if (!window.nuskin || !window.nuskin.util) {
    alert("error: missing nuskin.util namespace");
}

var Base64 = {
    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
}

//don't override if present
if (!nuskin.account) {
    dojo.require("dojo.cookie");
    dojo.require('dojox.io.windowName');
    dojo.require('dojox.secure.capability');

    nuskin.account = {
        //event called when a page loads with an authentication cookie
        AUTHENTICATION_MESSAGE_TYPE: "nuskin-account-authentication",
        //event called when a user logs in
        LOGIN_MESSAGE_TYPE: "nuskin-account-login",
        //event called when a user logs out
        LOGOUT_MESSAGE_TYPE: "nuskin-account-logout",
        //event called when an error occurs during authentication
        INVALID_AUTHENTICATION_MESSAGE_TYPE: "nuskin-account-invalidAuthentication",
        //event called when account initialization is complete
        INITIALIZATION_COMPLETE: "nuskin-account-initializationComplete",
        //event called when account initialization is complete
        LOGIN_REQUESTED: "nuskin-account-loginRequested"
    };

    //AccountManager definition
    function AccountManager() {
        var thisAM = this;
        var cookieName = "nuskin.account.data";
        var afterLoginUrlCookieName = "nuskin.account.afterLoginUrl";
        var newWindowUrlCookieName = "nuskin.account.newWindowUrl";
        var sponsorIdCookieName = "nuskin.account.sponsorId";
        var campaignsVisitedCookieName = "nuskin.account.campaignsVisited";
        var initialized = false;
        var AUTHENTICATION_BRIDGE="/authenticationBridge";

        this.currentData = null;
        this.afterLogoutRedirect = null;
        
        this.isLoggedIn = function() {
            return dojo.cookie(cookieName);
        }

        //this should only be called during customer (or other) signup
        //where they have just accepted the PnP, so no need to check here
        var silentAuthReturnHandler = function(result) {
            dojox.secure.capability.validate(result, [], []);
            var resultObject = dojo.fromJson(result);
            if (nuskin.account.LOGIN_MESSAGE_TYPE == resultObject.messageType) {
                thisAM.currentData = resultObject.message;
                //set the cookie to initialize the "session"
                dojo.cookie(
                        cookieName,
                        dojo.toJson(resultObject.message),
                {path:'/'});
                //remove the sponsorId cookie if it is set
                dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});
            }
            dojo.publish(nuskin.account.AUTHENTICATION_MESSAGE_TYPE, [resultObject.message]);
        }

        var qualifiedCampaignsReturnHandler = function(result) {
            try {
                if (result != 'error') {
                    dojox.secure.capability.validate(result, [], []);
                    if (result && result.length > 0) {
                        var resultObject = dojo.fromJson(result);
                        var campaigns = resultObject.campaigns;
                        var campaignString = "";
                        for (var i=0; i < campaigns.length; i++) {
                            campaignString+=campaigns[i]+" ";
                        }
                        if (!campaignString) {
                            campaignString = 'NONE'; // will never be empty
                        }
                        CQ_Analytics.ProfileDataMgr.setProperty('qualifiedCampaigns', campaignString);

                    }
                }
            } catch (e) {}
            CQ_Analytics.ClickstreamcloudMgr.fireEvent("loadcampaigns");
        }

        function getQualifiedCampaigns(sapId) {
            var parameters = {};
            parameters.sapId = sapId;
            dojo.xhrGet({
                url:"/signupApp/service/qualifiedCampaigns/"+nuskin.util.countryCode+"/"+sapId,
                handleAs:"text",
                load: qualifiedCampaignsReturnHandler,
                error: function(result) {
                    $('#errorDiv').text("Error:"+result);
                }
            });
        }

        var authReturnHandler = function(result) {
            dojox.secure.capability.validate(result,[],[]);
            var resultObject = dojo.fromJson(result);
            if (nuskin.account.LOGIN_MESSAGE_TYPE == resultObject.messageType) {
                thisAM.currentData = resultObject.message;
                //set the cookie to initialize the "session"
                dojo.cookie(
                    cookieName,
                    dojo.toJson(resultObject.message),
                    {path:'/'});
                //remove the sponsorId cookie if it is set
                dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});


                //run the PNP check
                var returnUrl = window.location.protocol+"//"+window.location.host+window.location.pathname;
                var afterLoginUrl = thisAM.getAfterLoginUrl();
                if (afterLoginUrl) {
                    if(afterLoginUrl.newWindow) {
                        dojo.cookie(
                                newWindowUrlCookieName,
                                afterLoginUrl.url,
                                {path:'/'});
                    } else {
                        returnUrl = afterLoginUrl.url;
                    }
                    thisAM.setAfterLoginUrl(null);
                }

                if (!useCAS) {
                    returnUrl = escape(returnUrl);
                    var authUrl = nuskin.util.secureHost + "/signon/pnp/form.do?pnpSapId="+thisAM.currentData.id+"&pnpAcceptURL="+returnUrl+"&pnpRejectURL="+returnUrl+"&pnpErrorURL="+returnUrl;
                    window.location = authUrl;
                }
                return;
            }
            dojo.publish(resultObject.messageType, [resultObject.message]);
		}

        // cas
        this.CASpingReturnHandler = function(result) {
            dojox.secure.capability.validate(result, [], []);
            if (result && result.length > 0) {
                var resultObject = dojo.fromJson(result);
                if (!resultObject.eid) {
                    thisAM.logout();
                }
                if (thisAM.currentData) {
                    thisAM.currentData.eid = resultObject.eid;
                }
                if (!initialized) {
                    initialized = true;
                    dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                }
            } else {
                thisAM.logout();
            }

        }

        // non cas
        this.pingReturnHandler = function(result){
            if (useCAS) {
                this.CASpingReturnHandler(result);
            } else {
                dojox.secure.capability.validate(result,[],[]);
                var resultObject = dojo.fromJson(result);
                var campaigns = CQ_Analytics.ProfileDataMgr.getProperty('qualifiedCampaigns');
                if(!resultObject.eid) {
                    thisAM.logout();
                    return;
                }

                if(thisAM.currentData) {
                    thisAM.currentData.eid = resultObject.eid;
                }
                                
                if(!initialized) {
                    initialized = true;
                    dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                    
                    if (nuskin.util.useCampaigns && !campaigns) {                        
                        var id = nuskin.account.AccountManager.currentData.id;
                        getQualifiedCampaigns(id);
                    }
                }
            }
        }

        this.setAfterLoginUrl = function(url, newWindow) {
            if (url == null) {
                dojo.cookie(afterLoginUrlCookieName, null, {path:'/', expires: -1});
            } else {
                if (!newWindow) {
                    newWindow = false;
                }
                if (url.match("^http[s]*://") == null) {
                    url = window.location.protocol + '//' + window.location.host + (url.match("^/") == "/" ? "" : "/") + url;
                }
                var urlObject = {};
                urlObject.url = url;
                urlObject.newWindow = newWindow;
                dojo.cookie(
                        afterLoginUrlCookieName,
                        dojo.toJson(urlObject),
                {path:'/'});
            }
        }

        this.getAfterLoginUrl = function() {
            var cookieString = dojo.cookie(afterLoginUrlCookieName);
            if (cookieString) {
                dojox.secure.capability.validate(cookieString, [], []);
                return dojo.fromJson(cookieString);
            }
            return null;
        }

        this.authenticate = function(username, password) {
            if (thisAM.currentData) {
                dojo.cookie(cookieName, null, {path:'/', expires: -1});
                dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});
                thisAM.currentData = null;
                dojo.publish(nuskin.account.LOGOUT_MESSAGE_TYPE, [
                    {}
                ]);
            }
            var parameters = {};
            parameters.username = Base64.encode(username);
            parameters.password = Base64.encode(password);

            if (document.URL.indexOf("zh_TW") !=-1) {                
                var returnUrl = window.location.toString().replace(".loginError","");                
                var authenticateUrl = taiwanLoginUrl+'?furl='+returnUrl+'&username='+username+'&password='+password;
                window.location = authenticateUrl;
            } else {
                var deferred = dojox.io.windowName.send(
                        "POST",
                {url:nuskin.util.secureHost + "/apps/global/services/authenticate",
                    content:parameters});
                deferred.addCallback(authReturnHandler);
            }
        }

        this.authenticateWithEid = function(eid, silent) {
            if (thisAM.currentData) {
                // null out both cookies to that the cookie processing doesnt happen in the onload
                dojo.cookie(cookieName, null, {path:'/', expires: -1});
                dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});
                thisAM.currentData = null;
                dojo.publish(nuskin.account.LOGOUT_MESSAGE_TYPE, [
                    {}
                ]);
            }
            var parameters = {};
            parameters.eid = eid;

            var deferred = dojox.io.windowName.send(
                    "POST",
            {url:nuskin.util.secureHost + "/apps/global/services/authenticate",
                content:parameters});

            if (silent) {
                deferred.addCallback(silentAuthReturnHandler);
            } else {
                deferred.addCallback(authReturnHandler);
            }
        }

        this.setCampaignsVisited = function(value) {
            dojo.cookie(campaignsVisitedCookieName, value, {path:'/'});
        }

        this.getCampaignsVisited = function() {
            var rv = dojo.cookie(campaignsVisitedCookieName);
            if (!rv || rv == undefined ||  typeof(rv)  == "undefined") {
                rv = '';
            }
            return rv;
        }

        this.clearCampaignsVisited = function() {
            dojo.cookie(campaignsVisitedCookieName, null, {path:'/', expires: -1});
        }

        this.CASping = function() {
            if (thisAM.currentData) {
                var deferred = dojox.io.windowName.send(
                        "POST",
                {url:nuskin.util.authenticationHost + "/ping.jsp",handleAs:'text'});
                deferred.addCallback(function(result) {
                    // don't ask me why I have to do the whole '<!-- framPath...' check...
                    if (result && result != '<!--framePath //<!--frame1-->-->' && result.length > 0) {
                        if (thisAM.currentData) {
                            thisAM.currentData.eid = result;
                        }

                        if (!thisAM.initialized) {
                            thisAM.initialized = true;
                            dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                        }
                    } else {
                        thisAM.logout();
                    }
                });
                //dojo.io.script.attach("account-ping-"+(new Date().getTime()), nuskin.util.secureHost+"/apps/global/services/authenticate.ping?id="+thisAM.currentData.id+"&"+(new Date().getTime()));
            }
        }

          this.TaiwanPing = function() {
            if (thisAM.currentData) {
                var deferred = dojox.io.windowName.send(
                    "POST",
                    {url:taiwanPingUrl,handleAs:'text'});
                deferred.addCallback(function(result) {
                    // don't ask me why I have to do the whole '<!-- framPath...' check...
                if (result && result != '<!--framePath //<!--frame1-->-->' && result.length > 0) {
                        if (thisAM.currentData) {
                            thisAM.currentData.eid = result;
                        }

                        if (!thisAM.initialized) {
                            thisAM.initialized = true;
                            dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                        }
                    } else {
                        thisAM.logout();
                    }
                });
                //dojo.io.script.attach("account-ping-"+(new Date().getTime()), nuskin.util.secureHost+"/apps/global/services/authenticate.ping?id="+thisAM.currentData.id+"&"+(new Date().getTime()));
            }
        }

        this.ping = function() {
            if (document.URL.indexOf("zh_TW") !=-1) {
                 this.TaiwanPing();
            }
            if (useCAS) {
                this.CASping();
            } else {
                if(initialized && thisAM.currentData) {
                    dojo.io.script.attach("account-ping-"+(new Date().getTime()), nuskin.util.secureHost+"/apps/global/services/authenticate.ping?id="+thisAM.currentData.id+"&"+(new Date().getTime()));
                }
            }
        }

        this.CASlogout = function() {
            dojo.cookie(cookieName, null, {path:'/', expires: -1});
            var redirectUrl = "";
            if (thisAM.currentData) {
                //someone was actually logged in--need to take care of some things
                dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});
                thisAM.currentData = null;
                if (thisAM.afterLogoutRedirect) {
                    // just set the cookie for the bridging app
                    // lets not set the cookie here but pass the url on the request
                    var url = thisAM.afterLogoutRedirect;
                    redirectUrl = "?redirectUrl=" + window.location.protocol + '//' + window.location.host + (url.match("^/") == "/" ? "" : "/") + url;
                    //dojo.cookie("nuskin.account.afterLogoutRedirect", redirectUrl, {path:'/'});
                } else {
                    //publish the event
                    dojo.publish(nuskin.account.LOGOUT_MESSAGE_TYPE, [
                        {}
                    ]);
                }
            }
            window.location = nuskin.util.authenticationHost + "/logout.jsp" + redirectUrl;
        }

          this.TaiwanLogout = function() {
            dojo.cookie(cookieName, null, {path:'/', expires: -1});
            var redirectUrl = "";
            if (thisAM.currentData) {
                //someone was actually logged in--need to take care of some things
                dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});
                thisAM.currentData = null;
                if (thisAM.afterLogoutRedirect) {
                    // just set the cookie for the bridging app
                    // lets not set the cookie here but pass the url on the request
                    var url = thisAM.afterLogoutRedirect;
                    redirectUrl = "?redirectUrl=" + window.location.protocol + '//' + window.location.host + (url.match("^/") == "/" ? "" : "/") + url;
                    //dojo.cookie("nuskin.account.afterLogoutRedirect", redirectUrl, {path:'/'});
                } else {
                    //publish the event
                    dojo.publish(nuskin.account.LOGOUT_MESSAGE_TYPE, [
                        {}
                    ]);
                }
            }            
            window.location = taiwanLogoutUrl + '?furl='+window.location.toString();
        }

        this.logout = function() {
            if (document.URL.indexOf("zh_TW") !=-1) {
                 this.TaiwanLogout();
            } else if (useCAS) {
                this.CASlogout();
            } else {
                var deferred = dojox.io.windowName.send("GET", {url:nuskin.util.secureHost + "/apps/global/services/authenticate.logout",
                    content:{}});
                deferred.addCallback(new function() {
                    dojo.cookie(cookieName, null, {path:'/', expires: -1});
                    if (thisAM.currentData) {
                        CQ_Analytics.ProfileDataMgr.setProperty('qualifiedCampaigns', '');
                        nuskin.account.AccountManager.clearCampaignsVisited(); // clears the cookie

                        //someone was actually logged in--need to take care of some things
                        dojo.cookie(sponsorIdCookieName, null, {path:'/', expires: -1});
                        thisAM.currentData = null;
                        if (thisAM.afterLogoutRedirect) {
                            //redirect if a url is specified
                            window.location = thisAM.afterLogoutRedirect;
                        } else {
                            //publish the event
                            dojo.publish(nuskin.account.LOGOUT_MESSAGE_TYPE, [
                                {}
                            ]);
                        }
                    }
                });
            }

        }

        this.getCachedSponsorId = function() {
            return dojo.cookie(sponsorIdCookieName);
        }

        this.requestLogin = function() {
            dojo.publish(nuskin.account.LOGIN_REQUESTED);
        }

        this.taiwanPingReturn = function(result) {

            if (result) {
                var cookieString = dojo.cookie(cookieName);
                var user = result;

                if(!user.memberId || user.memberId == '') {
                    if (cookieString) {
                        thisAM.TaiwanLogout();
                    }
                } else {
                    user.firstName =  decodeURIComponent(user.partnerName.replace(/\+/g," "));
                    var memberType = user.memberType;
                    if (memberType == '1') {
                        memberType = '10';
                    }
                    if (memberType == '3') {
                        memberType = '30';
                    }
                    user.accountType = memberType;
                    user.lastName = '';
                    user.id = user.memberId;

                    dojo.cookie(cookieName, dojo.toJson(user), {path:'/'});
                    thisAM.currentData = user;
                    thisAM.currentData.eid = user.eid;
                    thisAM.initialized = true;
                    dojo.publish(nuskin.account.AUTHENTICATION_MESSAGE_TYPE, [user]);
                }

                if(!initialized) {
                   initialized = true;
                   dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                }
            } else {                 
                // shouldnt happen, but just in case
                if (cookieString) {
                    thisAM.TaiwanLogout();
                }
            }
        }

        var onLoad = function() {

            var queryString = window.location.search.substring(1);
            if (queryString) {
                var queryObject = dojo.queryToObject(queryString);

                if (!useCAS) {
                    //check for auto login parameter
                    if (queryObject.eid) {
                        thisAM.authenticateWithEid(queryObject.eid);
                    }
                }

                // check for sponsorId on query string and set it
                var sponsorId = null;

                if (queryObject.pwpId) {
                    sponsorId = queryObject.pwpId;
                } else if (queryObject.gwpId) {
                    sponsorId = queryObject.gwpId;
                }

                if (sponsorId) {
                    //set the sponsor id cookie
                    dojo.cookie(
                            sponsorIdCookieName,
                            sponsorId,
                    {path:'/'});
                }
            }

            var newWindowUrl = dojo.cookie(newWindowUrlCookieName);
            if (newWindowUrl) {
                dojo.cookie(newWindowUrlCookieName, null, {path:'/', expires: -1});
                window.open(newWindowUrl, '', '');
            }

            if (useCAS) {
                var cookieString = dojo.cookie(cookieName);
                if (cookieString) {
                    // here we need to do a ping if the user is logged in to log us out
                    dojox.secure.capability.validate(cookieString, [], ['id']);
                    var authentication = dojo.fromJson(cookieString);
                    thisAM.currentData = authentication;

                    //publish the event to the page.  if the ping shows the session
                    //is invalid the included js file will call the logout function
                    dojo.publish(nuskin.account.AUTHENTICATION_MESSAGE_TYPE, [authentication]);
                    thisAM.ping();
                } else {
                    // This call opens up an iframe makes a call and then extracts the return information via the windowName
                    // property. Used for cross-domain communications
                    // If no windowName property is returned, this call will time out. Specifically in the case of a cas application,
                    // the iframe will load a 'login' screen. This is then silently ignored.

                    var checkUrl = nuskin.util.authenticationHost + "/secure/loginCheck.jsp";

                    var deferred = dojox.io.windowName.send(
                            "POST",
                    {url:checkUrl,handleAs:'text'});
                    deferred.addCallback(function(result) {
                        dojox.secure.capability.validate(result, [], []);
                        if (result && result.length > 0) {
                            var user = dojo.fromJson(result);
                            var eid = user.eid;
                            delete user.eid;
                            dojo.cookie(cookieName, dojo.toJson(user), {path:'/'});
                            thisAM.currentData = user;
                            thisAM.currentData.eid = user.eid;
                            thisAM.initialized = true;
                            dojo.publish(nuskin.account.AUTHENTICATION_MESSAGE_TYPE, [user]);
                        }
                    });

                    dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                }
            } else {
                // if taiwan
                if (document.URL.indexOf("zh_TW") !=-1) {

                    var cookieString = dojo.cookie(cookieName);
                    var checkUrl = taiwanPingUrl;
                    var parameters = {};
                    var src = taiwanPingUrl+"?jsonp=nuskin.account.AccountManager.taiwanPingReturn&ts="+new Date().getTime();
                    if (cookieString) {
                        dojox.secure.capability.validate(cookieString,[],['id']);
                        var authentication = dojo.fromJson(cookieString);
                        thisAM.currentData = authentication;
                        // this script will log the user in and out.
                        // it doesnt matter if they are logged in yet or not
                        // todo update the taiwanPingUrl to the one below
                        src = src+"memberId="+thisAM.currentData.id;
                    }

                    var pingStr = "ping-"+(new Date().getTime());                    
                    dojo.io.script.attach(pingStr, src);
                } else if (document.URL.indexOf("ja_JP") !=-1) {
                    // no ping necessary
                } else {
                    // everyone else
                    var cookieString = dojo.cookie(cookieName);
                    if(cookieString) {
                        dojox.secure.capability.validate(cookieString,[],['id']);
                        var authentication = dojo.fromJson(cookieString);
                        thisAM.currentData = authentication;

                        //publish the event to the page.  if the ping shows the session
                        //is invalid the included js file will call the logout function
                        dojo.publish(nuskin.account.AUTHENTICATION_MESSAGE_TYPE, [authentication]);

                        //ping the server to verify the session is still active
                        dojo.io.script.attach("account-ping-"+(new Date().getTime()), nuskin.util.secureHost+"/apps/global/services/authenticate.ping?id="+thisAM.currentData.id+"&"+(new Date().getTime()));
                    } else {
                        dojo.publish(nuskin.account.INITIALIZATION_COMPLETE);
                        CQ_Analytics.ProfileDataMgr.setProperty('qualifiedCampaigns', ''); // resetting qualified campaigns
                    }
                }
            }

        }
        nuskin.util.Initializer.addOnLoad(onLoad);
    }

    nuskin.account.AccountManager = new AccountManager();
}
