// $Id:$
var _io_request = new IORequest();
var _io_config = undefined;
var _io_zone = undefined;
var _io_state = new IOState();
if (typeof console === "undefined" || typeof console.log === "undefined" || typeof console.group === "undefined") {
    var console = { log: function() {
    }, warn: function() {
    }, error: function() {
    }, dir: function() {
    }, group: function() {
    }, groupEnd: function() {
    } 
    };
}
function cm_ted_io(_1) {
    _io_state.cm_ted_io(_1);
};
function _cm_io_rec(_2) {
    if (_io_request !== undefined) {
        _io_request.cm_io_rec(_2);
    }
};
function _cm_io_cfg(_3) {
    if (_io_request !== undefined) {
        _io_request.cm_io_cfg(_3, 1);
    }
};
function cmRecRequest(_4, _5, _6, _7) {
    IORequest.rec_request(_4, _5, _6, _7);
};
function cmDisplayRecs() {
    IORequest.display_recs();
};
function IORequest(_8) {
    var _9 = "io_config.js";
    var _a = "V4";
    this.h_timer = undefined;
    this.h_script = undefined;
    this.xmlHttp = undefined;
    this.i_timeout = 0;
    this.request_type = "";
    this.action_callback = function(_b) {
        return;
    };
    this.display_status = function(_c, _d) {
        return;
    };
    this.display_product_table = function(_e) {
        return;
    };
    this.display_product_images = function(_f) {
        return;
    };
    this.display_config = function(_10) {
        return;
    };
    this.cm_alert = function(_11) {
        if (!IORequest.production) {
            alert(_11);
        }
    };
    IOStopWatch = function() {
        this.start = function() {
            this.elapsed_time = 0;
            this.t_start = new Date().getTime();
        };
        this.stop = function() {
            this.elapsed_time = new Date().getTime() - this.t_start;
            return (this.elapsed_time);
        };
    };
    this.stop_watch = new IOStopWatch("stop_watch");
    this.ajax_timeout = function(_12) {
        if (_io_request.xmlHttp !== undefined) {
            try {
                if (_io_request.xmlHttp.abort !== undefined) {
                    if (typeof _io_request.xmlHttp.abort == "function") {
                        _io_request.xmlHttp.abort();
                    }
                }
            }
            catch (e) {
                _io_request.display_status("IE - no abort property of the xmlHttp request object");
            }
        }
        IORequest.b_timeout = true;
        if (_12) {
            _io_request.action_callback("config_timeout");
            IORequest.i_zone = 0;
            setTimeout("IORequest.config_download_failure(\"ajax timeout\");", 0);
        } else {
            _io_request.display_status("Ajax timeout downloading product (" + _io_request.stop_watch.elapsed_time + "ms)", "red");
            IORequest.log(IORequest.log_warn, "Ajax timeout downloading product", _io_request.stop_watch.elapsed_time + " ms");
            _io_request.download_product();
        }
    };
    function _13() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else {
            if (window.ActiveXObject) {
            } else {
                return null;
            }
        }
    };
    this.javascript_timeout = function(_14) {
        if (IORequest.h_script !== undefined) {
            var h = document.getElementsByTagName("head").item(0);
            if (h) {
                h.removeChild(IORequest.h_script);
                IORequest.h_script = undefined;
            }
        }
        _io_request.stop_watch.stop();
        IORequest.timeout_product[IORequest.request_crc] = 1;
        if (_14) {
            _io_request.action_callback("config_timeout");
            IORequest.i_zone = 0;
            setTimeout("IORequest.config_download_failure(\"javascript timeout\");", 0);
        } else {
            _io_request.display_status("JavaScript timeout downloading product (" + _io_request.stop_watch.elapsed_time + "ms)", "red");
            IORequest.log(IORequest.log_warn, "JavaScript timeout downloading product", _io_request.stop_watch.elapsed_time + " ms");
            if ((_io_config.file_not_found_pc !== undefined) && (_io_config.file_not_found_pc > Math.floor(Math.random() * 100))) {
                var id = IORequest.offer_type + IORequest.offer_id + "|" + IORequest.request_crc + "|" + (IORequest.offer_type == "P" ? IORequest.plain_text_product_id : IORequest.plain_text_cat_id);
                cmCreatePageElementTag(id, _io_config.file_not_found_id);
                IORequest.log(IORequest.log_trace, "page element tag for file not found", id);
            }
            _io_request.download_product();
        }
    };
    this.stateChanged = function() {
        if (_io_request.xmlHttp.readyState == 4) {
            clearTimeout(_io_request.h_timer);
            _io_request.h_timer = undefined;
            if (_io_request.xmlHttp.status == 200) {
                var txt = _io_request.xmlHttp.responseText;
                eval(txt);
            } else {
                if (_io_request.xmlHttp.status == 404) {
                    _io_request.display_status("Ajax - Requested File not found on server - " + _io_request.xmlHttp.status + ". Next step in recommendation plan attempted", "blue");
                    IORequest.log(IORequest.log_warn, "Ajax - Requested File not found on server - " + _io_request.xmlHttp.status, "next step in recommendation plan attempted");
                    IORequest.b_404 = true;
                    if (_io_request.request_type == "config") {
                        setTimeout("IORequest.config_download_failure(\"ajax 404\");", 0);
                    } else {
                        if (_io_request.request_type == "product") {
                            _io_request.download_product();
                        }
                    }
                } else {
                    _io_request.display_status("Ajax - Unexpected status from stateChanged: " + _io_request.xmlHttp.status + ".", "red");
                    IORequest.log(IORequest.log_error, "Ajax - Unexpected status from stateChanged", _io_request.xmlHttp.status);
                    IORequest.b_404 = true;
                    if (_io_request.request_type == "config") {
                        setTimeout("IORequest.config_download_failure(\"ajax 404\");", 0);
                    } else {
                        if (_io_request.request_type == "product") {
                            _io_request.download_product();
                        }
                    }
                }
            }
        } else {
        }
    };
    this.get_target_from_plan = function(_15, _16) {
        if (IORequest.current_step >= _15.rec_steps.length) {
            return ("_SE_");
        }
        var _17 = _15.rec_steps[IORequest.current_step];
        IORequest.log(IORequest.log_trace, "step: " + IORequest.current_step + " offer_id: " + _17.offer_id + " type: " + _17.offer_type + " target", _17.target_id);
        if (_17.target_id == "_NR_") {
            return ("_NR_");
        }
        if (_17.target_id == "_DPF_") {
            return ("_DPF_");
        }
        if (_16 && _17.offer_type == "P") {
            IORequest.current_step++;
            this.display_status("Looking for Category - found Product: " + _17.target_id + ". Next step", "green");
            IORequest.log(IORequest.log_trace, "Looking for Category - found Product: " + _17.target_id, "next step");
            return (this.get_target_from_plan(_15, 1));
        }
        if (_17.target_id == "_SP_") {
            return (IORequest.primary_id || "_NR_");
        }
        if (_17.target_id == "_SC_") {
            return (IORequest.fallback_id || "_NR_");
        }
        if (_17.target_id == "_RVP_" || _17.target_id == "_RVC_" || _17.target_id == "_LCP_" || _17.target_id == "_RPP_" || _17.target_id == "_MPC_") {
            var rc = _io_state.cm_get_product_from_cookie(_17.target_id);
            if (rc === 0) {
                IORequest.current_step++;
                this.display_status("No " + _17.target_id + "available. Next step", "green");
                IORequest.log(IORequest.log_trace, "No " + _17.target_id + " available", "next step");
                return (this.get_target_from_plan(_15));
            } else {
                return (rc);
            }
        }
        this.display_status("unrecognized target id: " + _17.target_id + ".", "red");
        IORequest.log(IORequest.log_error, "unrecognized target id", _17.target_id);
        return ("_NR_");
    };
    this.issue_page_element_tag = function(_18) {
        if (IORequest.perm_cookie_not_supported === false) {
            var _19 = IORequest.find_cookie(IORequest.ses_cookie);
            if (_19 === undefined) {
                var _1a = new Date().getTime().toString();
                _19 = IORequest.set_and_check_cookie(IORequest.ses_cookie, "S" + _1a + "|", true);
                if (!_19) {
                    return;
                }
            }
            if (_19.indexOf("|" + _18[0] + "|") == -1) {
                IORequest.log(IORequest.log_trace, "issued page element tag" + this.io_zone.ab_test_id.split(":")[1], this.io_zone.ab_test_id.split(":")[0]);
                IORequest.log(IORequest.log_trace, "session cookie", _19);
                IORequest.set_and_check_cookie(IORequest.ses_cookie, _19 + _18[0] + "|", true);
                cmCreatePageElementTag(_18[1], _18[0]);
            }
        }
    };
    this.download_product = function() {
        IORequest.current_step++;
        this.io_zone = _io_config.zones[IORequest.zone_id];
        if (this.io_zone.ab_test_id != "no ab test") {
            this.issue_page_element_tag(this.io_zone.ab_test_id.split(":"));
        }
        IORequest.log(IORequest.log_trace, "ab test id", this.io_zone.ab_test_id);
        if (!this.io_zone.rec_plan) {
            this.cm_alert("rec_plan not defined - zone_id: " + IORequest.zone_id);
        }
        var rc = this.get_target_from_plan(this.io_zone.rec_plan, IORequest.b_timeout || IORequest.b_404);
        this.action_callback("recommendation_plan");
        if (rc == "_DPF_" && (IORequest.default_product_file !== undefined)) {
            _io_request.cm_io_rec(IORequest.default_product_file);
            return (0);
        }
        if (rc == "_SE_" || rc == "_NR_" || rc == "_DPF_") {
            var _1b = "";
            if (rc == "_SE_") {
                this.display_status("steps exhausted. Calling zone population function " + this.io_zone.zpf + " without recommendations.", "blue");
                IORequest.log(IORequest.log_trace, "steps exhausted - calling zone population function without recommendations", this.io_zone.zpf);
                _1b = "Steps exhausted.  No recommendations found";
            } else {
                this.display_status("calling zone population function " + this.io_zone.zpf + " without recommendations (_NR_)", "blue");
                IORequest.log(IORequest.log_trace, "calling zone population function without recommendations", this.io_zone.zpf);
                _1b = "No recommendations found";
            }
            if (this.io_zone.zpf !== undefined) {
                var _1c = "[],'" + this.io_zone.name + "','_NR_','','',[],[],'" + _1b + "'";
                var zpf = this.io_zone.zpf + "(" + _1c + ")";
                setTimeout(zpf, 0);
            }
            setTimeout("IORequest.stack_manager(\"rc: " + rc + "\");", 0);
            return (0);
        }
        var _1d = rc;
        this.offer_id = this.io_zone.rec_plan.rec_steps[IORequest.current_step].offer_id;
        this.cgi_version = this.io_zone.rec_plan.rec_steps[IORequest.current_step].offer_version;
        this.offer_type = this.io_zone.rec_plan.rec_steps[IORequest.current_step].offer_type;
        if (((this.offer_type == "C") && IORequest.encrypt_cats) || ((this.offer_type == "E") && IORequest.encrypt_cats) || ((this.offer_type == "P") && IORequest.encrypt_prds)) {
            this.prod_id_crc = _1d;
        } else {
            this.prod_id_crc = IORequest.hex32(IORequest.crc32_str(_1d));
        }
        IORequest.request_crc = this.prod_id_crc;
        IORequest.offer_type = this.offer_type;
        IORequest.offer_id = this.offer_id;
        this.group = this.prod_id_crc.substr(0, 2);
        this.url = IORequest.url_prefix[IORequest.access_method] + IORequest.client_id + "/" + _a + "/" + this.offer_type + this.offer_id + "/" + this.offer_type + this.group + "/" + this.prod_id_crc + ".js?V=" + this.cgi_version;
        this.display_status("retrieving IO file product ID: " + _1d + " url: " + this.url, "green");
        IORequest.log(IORequest.log_trace, "retrieving IO file product " + _1d + " - url", this.url);
        this.action_callback("product_request");
        if ((IORequest.access_method == "ajax local") || (IORequest.access_method == "ajax remote")) {
            this.xmlHttp = _13();
            if (this.xmlHttp === null) {
                this.cm_alert("Your browser really does not support Ajax!");
                return;
            }
            this.h_timer = setTimeout("_io_request.ajax_timeout(0)", IORequest.timeout[this.i_timeout]);
            this.i_timeout = 1;
            this.request_type = "product";
            this.xmlHttp.onreadystatechange = this.stateChanged;
            this.stop_watch.start();
            try {
                this.xmlHttp.open("GET", this.url, true);
            }
            catch (e) {
                clearTimeout(this.h_timer);
                this.display_status("Ajax Error: Cross Domain request attempted.  Ajax not supported.  Try json x-domain.", "red");
                IORequest.rec_request_abort();
            }
            try {
                this.xmlHttp.send(null);
            }
            catch (e1) {
                clearTimeout(this.h_timer);
                this.display_status("Ajax Error: Host not found.  Ajax not supported.  Try json x-domain.", "red");
                IORequest.rec_request_abort();
            }
        } else {
            this.h_timer = setTimeout("_io_request.javascript_timeout(0)", IORequest.timeout[this.i_timeout]);
            this.i_timeout = 1;
            this.stop_watch.start();
            try {
                var h = document.getElementsByTagName("head").item(0);
                IORequest.h_script = document.createElement("script");
                IORequest.h_script.setAttribute("language", "javascript");
                IORequest.h_script.setAttribute("type", "text/javascript");
                IORequest.h_script.setAttribute("src", this.url);
                h.appendChild(IORequest.h_script);
            }
            catch (e2) {
                IORequest.rec_request_abort();
            }
        }
    };
    this.download_config = function() {
        this.url = IORequest.url_prefix[IORequest.access_method] + IORequest.client_id + "/" + _9 + "?ts=" + (((new Date().getTime()) / 600000) | 0);
        this.display_status("retrieving IO Config file: " + _9 + " url: " + this.url, "green");
        IORequest.log(IORequest.log_trace, "retrieving IO config file " + _9, this.url);
        this.action_callback("config_request");
        if ((IORequest.access_method == "ajax local") || (IORequest.access_method == "ajax remote")) {
            this.xmlHttp = _13();
            if (this.xmlHttp === null) {
                this.cm_alert("Your browser really does not support Ajax!");
                return;
            }
            this.h_timer = setTimeout("_io_request.ajax_timeout(1)", IORequest.timeout[this.i_timeout]);
            this.i_timeout = 1;
            this.request_type = "config";
            this.xmlHttp.onreadystatechange = this.stateChanged;
            this.stop_watch.start();
            try {
                this.xmlHttp.open("GET", this.url, true);
            }
            catch (e) {
                clearTimeout(this.h_timer);
                this.display_status("Ajax Error: Cross Domain request attempted.  Ajax not supported.  Try json x-domain.", "red");
                IORequest.rec_request_abort();
            }
            try {
                this.xmlHttp.send(null);
            }
            catch (e1) {
                clearTimeout(this.h_timer);
                this.display_status("Ajax Error: Host not found.  Ajax not supported.  Try json x-domain.", "red");
                IORequest.rec_request_abort();
            }
        } else {
            this.h_timer = setTimeout("_io_request.javascript_timeout(1)", IORequest.timeout[this.i_timeout]);
            this.i_timeout = 1;
            this.stop_watch.start();
            try {
                var h = document.getElementsByTagName("head").item(0);
                var js = document.createElement("script");
                js.setAttribute("language", "javascript");
                js.setAttribute("type", "text/javascript");
                js.setAttribute("src", this.url);
                h.appendChild(js);
            }
            catch (e2) {
                IORequest.rec_request_abort();
            }
        }
    };
    this.cm_io_rec = function(_1e) {
        this.stop_watch.stop();
        if (this.h_timer !== undefined) {
            clearTimeout(this.h_timer);
            this.h_timer = undefined;
        }
        if (this.io_zone.zpf !== undefined) {
            if (_1e !== undefined) {
                var _1f = _1e.pd[0][0];
                var _20 = _1e.hd[6];
                var _21 = _1e.hd[2];
                if ((_20 !== undefined) && (_20.length == 8) && (IORequest.timeout_product[_20])) {
                    IORequest.log(IORequest.log_trace, "Product download attempt following timeout for same file.  Requested file CRC", IORequest.request_crc);
                    IORequest.timeout_product[_20] = 0;
                    return;
                }
                this.display_status("Successful download of IO Recommendations for product: " + _1f + " <font color=\"black\">(" + this.stop_watch.elapsed_time + " ms)</font>.", "green");
                IORequest.log(IORequest.log_trace, "successful retrieval of IO Recommendations for product " + _1f, this.stop_watch.elapsed_time + " ms");
                IORequest.log(IORequest.log_iuo, "requested version: " + this.cgi_version + " returned version", _1e.hd[9]);
                IORequest.log(IORequest.log_product_file, "product file", _1e);
                var _22 = [];
                var _23 = [];
                var _24 = [];
                var _25 = [];
                var mpc = _io_state.cm_get_product_from_cookie("_MPC_");
                for (var _26 = 1; _26 < _1e.pd.length; _26++) {
                    _25[_26 - 1] = [];
                    _25[_26 - 1][0] = _26;
                    if ((IORequest.optional_parm == "R") && (_21 != "P")) {
                        _25[_26 - 1][1] = Math.floor(Math.random() * 1000);
                    } else {
                        _25[_26 - 1][1] = _1e.pd[_26][1] * ((_1e.pd[_26][2] == mpc) ? _io_config.cp : 1);
                    }
                }
                _25.sort(function(a, b) {
                    return (b[1] - a[1]);
                });
                if ((_io_config.brand_multiplier !== undefined) && (_io_config.brand_multiplier > 1)) {
                    var mpb = _io_state.cm_get_product_from_cookie("_MPB_");
                    if (mpb !== 0) {
                        for (var _27 = 1; _27 < _1e.pd.length; _27++) {
                            _25[_27 - 1] = [];
                            _25[_27 - 1][0] = _27;
                            var _28 = _1e.pd[_27][_io_config.brand_index + 3];
                            var _29 = IORequest.hex32(IORequest.crc32_str(_28));
                            _25[_27 - 1][1] = _1e.pd[_27][1] * ((_29 == mpb) ? _io_config.brand_multiplier : 1);
                        }
                        _25.sort(function(a, b) {
                            return (b[1] - a[1]);
                        });
                    }
                }
                if (_io_config.brand_index !== undefined) {
                    _io_state.cm_ted_io({ i_offer: "brand", brn: _1e.pd[0][_io_config.brand_index + 3] });
                }
                l_attribute_array = _1e.pd[0].length;
                for (var _2a = 3; _2a < l_attribute_array; _2a++) {
                    var _2b = ((_1e.ap !== undefined && _1e.ap[_2a - 3] !== undefined) ? _1e.ap[_2a - 3] : "");
                    _24.push((_1e.pd[0][_2a] === undefined) ? undefined : _2b + _1e.pd[0][_2a].replace(/"/g, "\\\""));
                }
                var _2c = [];
                var _2d = [];
                if (this.io_zone.filter_cp) {
                    var acp = _io_state.cm_get_product_from_cookie("_ACP_");
                    for (var _2e = 0; _2e < acp.length; _2e++) {
                        if (IORequest.encrypt_prds) {
                            _2c[acp[_2e]] = 1;
                        } else {
                            _2d[acp[_2e]] = 1;
                        }
                    }
                }
                if (this.io_zone.filter_pp) {
                    var app = _io_state.cm_get_product_from_cookie("_APP_");
                    for (var _2f = 0; _2f < app.length; _2f++) {
                        if (IORequest.encrypt_prds) {
                            _2c[app[_2f]] = 1;
                        } else {
                            _2d[app[_2f]] = 1;
                        }
                    }
                }
                for (var _30 = 0; _30 < _io_config.bad_list.length; _30++) {
                    _2c[_io_config.bad_list[_30]] = 1;
                }
                if ((IORequest.use_site_category === false) && (_1e.pd[0][2])) {
                    _io_state.cm_ted_io({ i_offer: "epr_category", cg: _1e.pd[0][2] });
                }
                IORequest.reason = [];
                for (var ii = 0; ((_22.length < this.io_zone.rec_plan.n_recs) && (ii < _25.length)); ii++) {
                    var _31 = _25[ii][0];
                    var _32 = _1e.pd[_31][0];
                    var _33 = IORequest.hex32(IORequest.crc32_str(_32));
                    IORequest.reason[_32] = 6;
                    var _34 = _32.replace(/"/g, "\\\"");
                    var _35 = true;
                    if ((IORequest.filtered_out_products[_32] === undefined) && (_2d[_32] === undefined) && (_2c[_33] === undefined) && (IOState.h_productview_product[_32] === undefined)) {
                        var _36 = [];
                        for (var _37 = 3; ((_37 < _1e.pd[_31].length) && (_35 === true)); _37++) {
                            if (IORequest.required_attributes[_37 - 3] && !(_1e.pd[_31][_37])) {
                                _35 = false;
                            } else {
                                var _38 = ((_1e.ap !== undefined && _1e.ap[_37 - 3] !== undefined) ? _1e.ap[_37 - 3] : "");
                                _36.push((_1e.pd[_31][_37] === undefined) ? undefined : _38 + _1e.pd[_31][_37].replace(/"/g, "\\\""));
                            }
                        }
                        if (_35) {
                            _22.push(_34);
                            if (IORequest.conflict_resolution === true) {
                                IORequest.filtered_out_products[_32] = 1;
                            }
                            _23.push("[\"" + _36.join("\",\"") + "\"]");
                        } else {
                            IORequest.log(IORequest.log_trace, _34 + " required attribute not present", "not sent to zpf");
                            IORequest.reason[_32] = 1;
                        }
                    } else {
                        if ((_2d[_32] !== undefined) || (_2c[_33] !== undefined)) {
                            IORequest.log(IORequest.log_trace, _34 + " recently carted, purchased, or in bad product list", "not sent to zpf");
                            IORequest.reason[_32] = 2;
                        } else {
                            if (IORequest.filtered_out_products[_32] !== undefined) {
                                IORequest.log(IORequest.log_trace, _34 + " appears in previous zone", "not sent to zpf");
                                IORequest.reason[_32] = 3;
                            } else {
                                if (IOState.h_productview_product[_32] !== undefined) {
                                    IORequest.log(IORequest.log_trace, _34 + " appears in the recommendation list but is also a product for which a product view tag was issued for this page", "not sent to zpf");
                                    IORequest.reason[_32] = 5;
                                }
                            }
                        }
                    }
                }
                this.display_product_table(_1e, _22);
                this.display_product_images(_1e, _22);
                var _39 = [];
                _39._SP_ = "Recommendations from a product you recently viewed";
                _39._SC_ = "Recommendations from a category you recently viewed";
                _39._NR_ = "No Recs";
                _39._RVP_ = "Recommendations from a product you recently viewed";
                _39._LCP_ = "Recommendations from a product you recently added to your cart";
                _39._RPP_ = "Recommendations from a Product you recently purchased";
                _39._RVC_ = "Recommendations from a category you recently viewed";
                _39._MPC_ = "Recommendations from your favorite category";
                _39._DPF_ = "Recommendations from your favorite retail store";
                var _3a = [];
                var _3b = _22.length ? true : false;
                var _3c = _3b ? this.io_zone.rec_plan.rec_steps[IORequest.current_step].target_id : "_NR_";
                if (!_3b) {
                    IORequest.log(IORequest.log_trace, "No recommendations made it through the filters", "changing target symbolic from " + this.io_zone.rec_plan.rec_steps[IORequest.current_step].target_id + " to _NR_.");
                }
                var _3d = this.io_zone.rec_plan.rec_steps[IORequest.current_step].heading || _39[_3c];
                _3a.push(_3b ? "[\"" + _22.join("\",\"") + "\"]" : "[]");
                _3a.push("\"" + this.io_zone.name + "\"");
                _3a.push("\"" + _3c + "\"");
                _3a.push("\"" + _1f + "\"");
                _3a.push("\"" + _1e.pd[0][2] + "\"");
                _3a.push("[" + _23.join() + "]");
                _3a.push("[\"" + _24.join("\",\"") + "\"]");
                _3a.push("\"" + _3d + "\"");
                var _3e = this.io_zone.zpf + "(" + _3a.join() + ")";
                if (this.io_zone.zpf !== undefined) {
                    setTimeout(_3e, 0);
                }
            }
            setTimeout("IORequest.stack_manager(\"sucessful product retrieval\");", 0);
        }
    };
    this.cm_io_cfg = function(_3f, _40) {
        this.stop_watch.stop();
        clearTimeout(_io_request.h_timer);
        _io_request.h_timer = undefined;
        if (_io_config === undefined) {
            if (_3f !== undefined) {
                this.action_callback(_40 ? "server_cfg" : "default_cfg");
                IORequest.log(IORequest.log_trace, "successful retrieval of config file", this.stop_watch.elapsed_time + " ms");
                IORequest.log(IORequest.log_config_file, "config file", _3f);
                if (_3f.zp !== undefined) {
                    _io_config = new IOConfig(_3f);
                    this.action_callback("config_return");
                } else {
                    setTimeout("IORequest.config_download_failure(\"corrupt config file\");", 0);
                }
                if (_40) {
                    IORequest.i_zone = 0;
                    setTimeout("IORequest.config_downloaded(\"successful config download\");", 0);
                }
            }
        } else {
            IORequest.log(IORequest.log_warn, "config request where _io_config already defined", "aborting request");
        }
    };
};
IORequest.crc32_tab = [0, 1996959894, 3993919788, 2567524794, 124634137, 1886057615, 3915621685, 2657392035, 249268274, 2044508324, 3772115230, 2547177864, 162941995, 2125561021, 3887607047, 2428444049, 498536548, 1789927666, 4089016648, 2227061214, 450548861, 1843258603, 4107580753, 2211677639, 325883990, 1684777152, 4251122042, 2321926636, 335633487, 1661365465, 4195302755, 2366115317, 997073096, 1281953886, 3579855332, 2724688242, 1006888145, 1258607687, 3524101629, 2768942443, 901097722, 1119000684, 3686517206, 2898065728, 853044451, 1172266101, 3705015759, 2882616665, 651767980, 1373503546, 3369554304, 3218104598, 565507253, 1454621731, 3485111705, 3099436303, 671266974, 1594198024, 3322730930, 2970347812, 795835527, 1483230225, 3244367275, 3060149565, 1994146192, 31158534, 2563907772, 4023717930, 1907459465, 112637215, 2680153253, 3904427059, 2013776290, 251722036, 2517215374, 3775830040, 2137656763, 141376813, 2439277719, 3865271297, 1802195444, 476864866, 2238001368, 4066508878, 1812370925, 453092731, 2181625025, 4111451223, 1706088902, 314042704, 2344532202, 4240017532, 1658658271, 366619977, 2362670323, 4224994405, 1303535960, 984961486, 2747007092, 3569037538, 1256170817, 1037604311, 2765210733, 3554079995, 1131014506, 879679996, 2909243462, 3663771856, 1141124467, 855842277, 2852801631, 3708648649, 1342533948, 654459306, 3188396048, 3373015174, 1466479909, 544179635, 3110523913, 3462522015, 1591671054, 702138776, 2966460450, 3352799412, 1504918807, 783551873, 3082640443, 3233442989, 3988292384, 2596254646, 62317068, 1957810842, 3939845945, 2647816111, 81470997, 1943803523, 3814918930, 2489596804, 225274430, 2053790376, 3826175755, 2466906013, 167816743, 2097651377, 4027552580, 2265490386, 503444072, 1762050814, 4150417245, 2154129355, 426522225, 1852507879, 4275313526, 2312317920, 282753626, 1742555852, 4189708143, 2394877945, 397917763, 1622183637, 3604390888, 2714866558, 953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859, 3624741850, 2936675148, 906185462, 1090812512, 3747672003, 2825379669, 829329135, 1181335161, 3412177804, 3160834842, 628085408, 1382605366, 3423369109, 3138078467, 570562233, 1426400815, 3317316542, 2998733608, 733239954, 1555261956, 3268935591, 3050360625, 752459403, 1541320221, 2607071920, 3965973030, 1969922972, 40735498, 2617837225, 3943577151, 1913087877, 83908371, 2512341634, 3803740692, 2075208622, 213261112, 2463272603, 3855990285, 2094854071, 198958881, 2262029012, 4057260610, 1759359992, 534414190, 2176718541, 4139329115, 1873836001, 414664567, 2282248934, 4279200368, 1711684554, 285281116, 2405801727, 4167216745, 1634467795, 376229701, 2685067896, 3608007406, 1308918612, 956543938, 2808555105, 3495958263, 1231636301, 1047427035, 2932959818, 3654703836, 1088359270, 936918000, 2847714899, 3736837829, 1202900863, 817233897, 3183342108, 3401237130, 1404277552, 615818150, 3134207493, 3453421203, 1423857449, 601450431, 3009837614, 3294710456, 1567103746, 711928724, 3020668471, 3272380065, 1510334235, 755167117];
IORequest.crc32_add = function(crc, c) {
    return IORequest.crc32_tab[(crc ^ c) & 255] ^ ((crc >> 8) & 16777215);
};
IORequest.crc32_str = function(str) {
    var n;
    var len = str.length;
    var crc;
    crc = 4294967295;
    for (n = 0; n < len; n++) {
        crc = IORequest.crc32_add(crc, str.charCodeAt(n));
    }
    return crc ^ 4294967295;
};
IORequest.hex32 = function(val) {
    var n;
    var _41;
    var _42;
    n = val & 65535;
    _41 = n.toString(16).toUpperCase();
    while (_41.length < 4) {
        _41 = "0" + _41;
    }
    n = (val >>> 16) & 65535;
    _42 = n.toString(16).toUpperCase();
    while (_42.length < 4) {
        _42 = "0" + _42;
    }
    return _42 + _41;
};
IORequest.cookie_info = function(_43, _44) {
    var c = document.cookie;
    var l = c.length;
    var n = c.split(";").length;
    IORequest.log(IORequest.log_trace, "cookie_length: " + l + " number of cookies", IORequest.cookie_count(_43));
    IORequest.log(IORequest.log_trace, "cookie", c);
    alert("n: " + n + " l: " + l + " cookie: " + c);
    if (_44) {
        var _45 = _44 - l - 3 - _43.length;
        var _46 = "";
        for (var i = 0; i < _45; i++) {
            _46 += "" + i % 10;
        }
        IORequest.set_and_check_cookie(_43, _46);
        IORequest.cookie_info(_43);
    }
};
IORequest.cookie_count = function(_47) {
    var c = document.cookie;
    var n = 0;
    if (c) {
        n = c.split(";").length;
    }
    return n;
};
IORequest.find_cookie = function(_48) {
    var _49 = document.cookie.split("; ");
    var _4a = _48.length;
    for (var _4b = 0; _4b < _49.length; _4b++) {
        if ((_48 + "=") == _49[_4b].substring(0, _4a + 1)) {
            return (_49[_4b].substring(_4a + 1));
        }
    }
    return (undefined);
};
IORequest.rm_cookie = function(_4c) {
    document.cookie = _4c + "=;path=/;expires=" + new Date(1998, 0).toGMTString() + ";;";
};
IORequest.set_and_check_cookie = function(_4d, _4e, _4f, _50) {
    document.cookie = _4d + "=" + _4e + ";path=/" + (_4f ? "" : ";expires=" + new Date(2020, 0).toGMTString()) + (_50 ? ";domain=" + _50 : "");
    _4e = IORequest.find_cookie(_4d);
    if (_4e === undefined) {
        if (!_4f) {
            IORequest.perm_cookie_not_supported = true;
        }
    }
    return (_4e);
};
IORequest.build_array_from_cookie = function(_51) {
    var _52 = IORequest.find_state_cookie();
    return ((_52 === undefined) ? undefined : (_52.split(IORequest.cookie_separator))[_51]);
};
IORequest.find_state_cookie = function() {
    var _53 = IORequest.find_cookie(IORequest.state_cookie);
    if (_53 === undefined) {
        var _54 = ((IORequest.ie_version() !== null) && (IORequest.ie_version() < 7)) ? 20 : 30;
        if (IORequest.cookie_count() >= _54) {
            _53 = undefined;
        } else {
            var rn = Math.floor(Math.random() * 100);
            _53 = [rn].join() + IORequest.cookie_separator + IORequest.cookie_separator + IORequest.cookie_separator + IORequest.cookie_array_separator + IORequest.cookie_array_separator + IORequest.cookie_array_separator + IORequest.cookie_array_separator + IORequest.cookie_array_separator + IORequest.cookie_array_separator;
            var _55 = _53;
            _53 = IORequest.set_and_check_cookie(IORequest.state_cookie, _55);
        }
    }
    return (_53);
};
IORequest.ab_group_number = function() {
    var cfg = IORequest.build_array_from_cookie(0);
    return ((cfg === undefined) ? undefined : cfg.split(",")[0]);
};
IORequest.default_json = { "zp": [{ "id": "Default_Zone", "rp": [["001", 0, 99, 3]]}], "rp": { "001": [["101", "_DPF_", "0", "You might be interested in"]] }, "oa": { "101": ["4", "P"]} };
IORequest.i_zone = 1;
IORequest.i_msg = 0;
IORequest.rec_stack = [];
IORequest.filtered_out_products = [];
IORequest.b_timeout = false;
IORequest.b_404 = false;
IORequest.zone_id = 0;
IORequest.primary_id = 0;
IORequest.fallback_id = 0;
IORequest.current_step = -1;
IORequest.timeout_product = [];
IORequest.cookie_separator = "~|~";
IORequest.cookie_array_separator = "|";
IORequest.ses_cookie = "CoreM_Ses";
IORequest.state_cookie = "CoreM_State";
IORequest.recently_viewed_product = undefined;
IORequest.recently_viewed_category = undefined;
IORequest.perm_cookie_not_supported = false;
IORequest.access_method = "json local";
IORequest.log_cookie_write = 2 << 1;
IORequest.log_config_file = 2 << 2;
IORequest.log_product_file = 2 << 3;
IORequest.log_trace = 2 << 4;
IORequest.log_warn = 2 << 5;
IORequest.log_error = 2 << 6;
IORequest.log_iuo = 2 << 7;
IORequest.production = false;
IORequest.log_mask = IORequest.production ? IORequest.log_error : (2 << 16) - 1;
IORequest.log_mask = IORequest.log_mask & ~IORequest.log_iuo;
IORequest.log = function(bit, _56, _57) {
    if (bit == IORequest.log_product_file || bit == IORequest.log_config_file) {
        console.group();
        console.dir(_57);
        console.groupEnd();
    } else {
        if (bit == IORequest.log_warn) {
            console.warn(_56 + ": ", _57);
        } else {
            if (bit == IORequest.log_error) {
                console.error(_56 + ": ", _57);
            } else {
                if (IORequest.log_mask & bit) {
                    console.log(_56 + ": ", _57);
                }
            }
        }
    }
};
IORequest.ie_version = function() {
    return (/MSIE (\d+\.\d+);/.test(navigator.userAgent) ? RegExp.$1 : null);
};
IORequest.url_prefix = [];
IORequest.url_prefix["ajax local"] = "";
IORequest.url_prefix["ajax remote"] = "/limelight/";
IORequest.url_prefix["json local"] = "";
IORequest.url_prefix["json remote"] = "http://coremetric.vo.llnwd.net/o33/";
IORequest.rec_request = function(_58, _59, _5a, _5b) {
    IORequest.plain_text_product_id = _59;
    IORequest.plain_text_cat_id = _5a;
    IORequest.log(IORequest.log_trace, "cmRecRequest", _58 + "," + _59 + "," + _5a + "," + _5b);
    IORequest.rec_stack.push([_58, (IORequest.encrypt_prds ? IORequest.hex32(IORequest.crc32_str(_59)) : _59), (IORequest.encrypt_cats ? IORequest.hex32(IORequest.crc32_str(_5a)) : _5a), _5b]);
};
IORequest.rec_request_abort = function() {
    IORequest.rec_stack = [];
    IORequest.filtered_out_products = [];
    IORequest.log(IORequest.log_trace, "Aborted request", "communication exception");
};
IORequest.display_recs = function() {
    IORequest.i_msg = 0;
    IORequest.i_zone = 1;
    IORequest.filtered_out_products = [];
    _io_config = undefined;
    if (IORequest.chris_dot_html_config) {
        _io_config = new IOConfig(IORequest.chris_dot_html_config);
        IORequest.log(IORequest.log_config_file, "config file", IORequest.chris_dot_html_config);
        IORequest.i_zone = 0;
        IORequest.stack_manager("chris.html");
    } else {
        _io_request.download_config();
    }
};
IORequest.config_downloaded = function(_5c) {
    IORequest.stack_manager(_5c);
};
IORequest.config_download_failure = function(_5d) {
    _io_config = new IOConfig(IORequest.default_json);
    for (var _5e = 0; _5e < IORequest.rec_stack.length; _5e++) {
        _io_config.add_zone(IORequest.rec_stack[_5e][0]);
    }
    IORequest.stack_manager(_5d);
};
IORequest.stack_manager = function(_5f) {
    if (IORequest.rec_stack.length) {
        var _60 = IORequest.rec_stack.shift();
        IORequest.i_zone++;
        IORequest.i_msg = 0;
        IORequest.zone_id = _60[0];
        IORequest.primary_id = _60[1];
        IORequest.fallback_id = _60[2];
        IORequest.optional_parm = _60[3];
        IORequest.current_step = -1;
        IORequest.b_timeout = false;
        IORequest.b_404 = false;
        if (_io_config.zones[IORequest.zone_id] === undefined) {
            IORequest.log(IORequest.log_error, "cmRecRequest: zone " + IORequest.zone_id + " is not defined in the configuration file", "no action taken");
            IORequest.stack_manager("zone: " + IORequest.zone_id + " is not defined in the configuration file");
        } else {
            _io_request.display_status("stack_manager called - " + _5f + " - parms: " + _60.join(", "), "green");
            IORequest.log(IORequest.log_trace, "stack_manager called - " + _5f + " - parms", _60.join(", "));
            _io_request.download_product();
        }
    } else {
        if (IORequest.i_zone == 3) {
            IORequest.i_zone = 2;
        }
        _io_request.display_status("All cmRecRequests completed", "green");
        IORequest.log(IORequest.log_trace, "All cmRecRequests completed for zone", IORequest.zone_id);
        IORequest.i_zone = 1;
        IORequest.i_msg = 0;
    }
};
IORequest.inspect_json = function(obj, _61, _62) {
    var str = "", _63, msg;
    if (_62 === null || _62 === undefined) {
        _62 = 0;
    }
    if (_61 === null || _61 === undefined) {
        _61 = 1;
    }
    if (_61 < 1) {
        return "<font color=\"red\">Error: Levels number must be > 0</font>";
    }
    if (obj === null || obj === undefined) {
        return "<font color=\"red\">Error: Object <b>NULL</b></font>";
    }
    str += "<ul>";
    var _64;
    for (_64 in obj) {
        if (true) {
            try {
                _63 = typeof (obj[_64]);
                str += "<li>(" + _63 + ") " + _64 + ((obj[_64] === null) ? (": <b>null</b>") : (":  <font color=\"red\">" + obj[_64] + "</font>")) + "</li>";
                if ((_63 == "object") && (obj[_64] !== null) && (_62 + 1 < _61)) {
                    str += IORequest.inspect_json(obj[_64], _61, _62 + 1);
                }
            }
            catch (err) {
                if (typeof (err) == "string") {
                    msg = err;
                } else {
                    if (err.message) {
                        msg = err.message;
                    } else {
                        if (err.description) {
                            msg = err.description;
                        } else {
                            msg = "Unknown";
                        }
                    }
                }
                str += "<li><font color=\"red\">(Error) " + _64 + ": " + msg + "</font></li>";
            }
        }
    }
    str += "</ul>";
    return str;
};
function IOConfig(_65) {
    this.io = _65;
    this.cp = this.io.cp || 1.1;
    if (this.io.fnf !== undefined) {
        this.file_not_found_id = this.io.fnf[0];
        this.file_not_found_pc = this.io.fnf[1];
    }
    this.bad_list = this.io.bl || [];
    this.ps = this.io.ps === undefined ? 1 : this.io.ps;
    if (this.io.bp !== undefined) {
        this.brand_index = this.io.bp[0];
        this.brand_multiplier = this.io.bp[1];
    }
    this.zones = [];
    this.n_zones = this.io.zp.length;
    this.rec_plan = [];
    for (var ii = 0; ii < this.n_zones; ii++) {
        this.zones[this.io.zp[ii].id] = new IOZone(this.io.zp[ii], this.rec_plan, this.io.rp, this.io.oa);
    }
    this.add_zone = function(_66) {
        var _67 = { "id": _66, "rp": [["001", 0, 99, 3]] };
        this.zones[_66] = new IOZone(_67, this.rec_plan, this.io.rp, this.io.oa);
    };
};
function IOZone(_68, _69, _6a, _6b) {
    var _6c = undefined;
    this.name = _68.id;
    var _6d = this.name + "_zp";
    if ((window[_6d] !== undefined) && (typeof window[_6d] == "function")) {
        this.zpf = _6d;
    } else {
        if ((window.io_rec_zp !== undefined) && (typeof window.io_rec_zp == "function")) {
            this.zpf = "io_rec_zp";
        } else {
            this.zpf = undefined;
        }
    }
    this.filter_pp = (((_68.fp !== undefined) && (_68.fp === 0)) ? 0 : 1);
    this.filter_cp = (((_68.fc !== undefined) && (_68.fc === 0)) ? 0 : 1);
    if (_68.rp.length == 1) {
        if (_69[_68.rp[0][0]] === undefined) {
            _69[_68.rp[0][0]] = new IORecPlan(_68.rp[0][0], _6a, _6b, _68.rp[0][3]);
        }
        this.rec_plan = _69[_68.rp[0][0]];
        this.ab_test_id = "no ab test";
    } else {
        var rn = IORequest.ab_group_number();
        this.rn = (rn === undefined) ? 0 : rn;
        for (var _6e = 0; ((_6e < _68.rp.length) && (this.rec_plan === undefined)); _6e++) {
            if (this.rn >= _68.rp[_6e][1] && this.rn <= _68.rp[_6e][2]) {
                if (_69[_68.rp[_6e][0]] === undefined) {
                    _69[_68.rp[_6e][0]] = new IORecPlan(_68.rp[_6e][0], _6a, _6b, _68.rp[_6e][3]);
                }
                this.rec_plan = _69[_68.rp[_6e][0]];
                this.ab_test_id = ((_68.rp[_6e][4] !== undefined) ? _68.rp[_6e][4] : "no ab test");
            }
        }
    }
};
function IORecStep(_6f, _70) {
    this.offer_id = _6f[0];
    this.target_id = _6f[1];
    this.offer_type = this.offer_id ? _70[this.offer_id][1] : "N";
    this.offer_version = this.offer_id ? _70[this.offer_id][0] : 0;
    this.heading = (_6f[3] !== undefined) ? _6f[3] : "";
    this.to_string = function() {
        return ("offer_id: " + this.offer_id + " target_id: " + this.target_id + " offer_type: " + this.offer_type + " offer_version: " + this.offer_version);
    };
};
function IORecPlan(_71, _72, _73, _74) {
    this.rec_steps = [];
    this.id = _71;
    this.n_recs = _74;
    for (var _75 = 0; _75 < _72[_71].length; _75++) {
        this.rec_steps.push(new IORecStep(_72[_71][_75], _73));
    }
};
IOState.h_productview_product = [];
IOState.productview_product = "";
IOState.productview_category = "";
function IOState() {
    var _76 = document;
    var _77 = "undefined";
    var _78 = (IORequest.production ? "~" : "~");
    var _79 = ":";
    var _7a = [];
    var _7b = [];
    var _7c = [];
    var _7d = [];
    var _7e = [];
    var _7f = [];
    var _80 = [];
    var _81 = [];
    var _82 = [];
    var _83 = -1;
    var _84 = ["p_viewed", "p_carted", "p_purchased", "c_viewed", "c_n_views", "b_viewed", "b_n_views"];
    var _85 = ["pv", "pc", "pp", "cv", "cn", "bv", "bn"];
    var _86 = _84;
    var _87 = false;
    var _88 = [];
    if (IORequest.basket_pages !== undefined) {
        for (var _89 = 0; _89 < IORequest.basket_pages.length; _89++) {
            _88[IORequest.basket_pages[_89]] = 1;
        }
    }
    this.cm_get_product_from_cookie = function(_8a) {
        if (_7a.length !== 0 || (cm_build_all_recent_arrays() === true)) {
            if (_8a == "_RVP_") {
                return (IORequest.recently_viewed_product);
            }
            if (_8a == "_RVC_") {
                return (IORequest.recently_viewed_category);
            }
            if (_8a == "_LCP_") {
                return (_7f[0] || 0);
            }
            if (_8a == "_RPP_") {
                return (_80[0] || 0);
            }
            if (_8a == "_MPC_") {
                var _8b = 0;
                for (var _8c = 1; _8c < _81.length; _8c++) {
                    if (parseInt(_7c[_81[_8c]].n_viewed, 10) > parseInt(_7c[_81[_8b]].n_viewed, 10)) {
                        _8b = _8c;
                    }
                }
                return (_81[_8b] || 0);
            }
            if (_8a == "_MPB_") {
                var _8d = 0;
                for (var _8e = 1; _8e < _82.length; _8e++) {
                    if (parseInt(_7d[_82[_8e]].n_viewed, 10) > parseInt(_7d[_82[_8d]].n_viewed, 10)) {
                        _8d = _8e;
                    }
                }
                return (_82[_8d] || 0);
            }
            if (_8a == "_DFTP_") {
                return (IORequest.default_prd);
            }
            if (_8a == "_DFTC_") {
                return (IORequest.default_cat);
            }
            if (_8a == "_APP_") {
                return (_80);
            }
            if (_8a == "_ACP_") {
                return (_7f);
            }
        }
        return (0);
    };
    cm_initialize_id = function(p_h, id) {
        p_h[id] = [];
        p_h[id].index = -1;
        p_h[id].n_bought = 0;
        p_h[id].n_viewed = 0;
        p_h[id].n_carted = 0;
    };
    cm_build_hash_from_array = function(p_a) {
        var h = [];
        h.max_index = 0;
        for (var ii = 0; ii < p_a.length; ii++) {
            cm_initialize_id(h, p_a[ii]);
        }
        return h;
    };
    cm_id_array_from_index_array = function(_8f, _90, _91, _92, _93, _94) {
        var _95 = [];
        _95.max_length = _90;
        if (_8f) {
            var _96 = _8f.split(",");
            for (var ii = 0; ii < _96.length; ii++) {
                var _97 = _91[_96[ii]];
                _95.push(_97);
                if (_93 !== undefined) {
                    var _98 = _93.split(",");
                    if ((!(_92 === undefined)) && (_98.length > 0)) {
                        _92[_97][_94] = _98[ii];
                    }
                }
            }
            if (_95.length > _95.max_length) {
                _95.length = _95.max_length;
            }
        }
        return _95;
    };
    cm_create_integer_array_from_id_array = function(_99, p_h, _9a) {
        var _9b = [];
        for (var ii = 0; ii < _99.length; ii++) {
            var id = _99[ii];
            if (p_h[id].index == -1) {
                p_h[id].index = p_h.max_index++;
            }
            _9b.push(p_h[id][_9a]);
        }
        return _9b;
    };
    cm_create_id_array_from_hash = function(p_h) {
        var _9c = [];
        for (var id in p_h) {
            if (typeof id != "function") {
                _9c[p_h[id].index] = id;
            }
        }
        return _9c;
    };
    cm_add_action = function(_9d, p_h, _9e, _9f, _a0) {
        var _a1;
        var _a2 = _9d;
        if (_9e) {
            _a2 = IORequest.hex32(IORequest.crc32_str(_9d));
            IORequest.log(IORequest.log_trace, "crc of " + _9d, _a2);
        }
        if (_a2 !== undefined) {
            _a1 = [_a2];
            _a1.max_length = _9f.max_length;
            if (p_h[_a2] === undefined) {
                cm_initialize_id(p_h, _a2);
            }
            if (_a0 !== undefined) {
                p_h[_a2][_a0]++;
            }
            for (var ii = 0; ii < _9f.length; ii++) {
                if (_9f[ii] != _a2) {
                    _a1.push(_9f[ii]);
                }
            }
            if (_a1.length > _a1.max_length) {
                _a1.length = _a1.max_length;
            }
        } else {
            _a1 = _9f;
        }
        return (_a1);
    };
    cm_remove_element_from_array = function(p_a, _a3, _a4) {
        var _a5 = [];
        if (_a4) {
            _a3 = IORequest.hex32(IORequest.crc32_str(_a3));
        }
        for (var ii = 0; ii < p_a.length; ii++) {
            if (!(_a3 == p_a[ii])) {
                _a5.push(p_a[ii]);
            }
        }
        return _a5;
    };
    cm_build_all_recent_arrays = function() {
        var _a6 = [];
        var _a7 = [];
        var _a8 = [];
        var _a9 = IORequest.find_state_cookie(IORequest.state_cookie);
        if (_a9 !== undefined) {
            var _aa = (_a9 === undefined) ? 4 : (_a9.split(IORequest.cookie_separator).length - 1);
            _7a = IORequest.build_array_from_cookie(0).split(",");
            _a6 = IORequest.build_array_from_cookie(1).split(_78);
            _7b = cm_build_hash_from_array(_a6);
            _a7 = IORequest.build_array_from_cookie(2).split(_78);
            _7c = cm_build_hash_from_array(_a7);
            if (_aa > 3) {
                _a8 = IORequest.build_array_from_cookie(3).split(_78);
                _7d = cm_build_hash_from_array(_a8);
            }
            var _ab = IORequest.build_array_from_cookie(_aa).split(IORequest.cookie_array_separator);
            if (_87 && (g_b_a_arrays[0].substring(0, 2) == _86[0].substring(0, 2))) {
                for (var ii = 0; ii < _ab.length; ii++) {
                    _ab[ii] = _ab[ii].substring(_86[ii].length + 1);
                }
            }
            _7e = cm_id_array_from_index_array(_ab[0], IORequest.a_max_elements[0], _a6);
            _7f = cm_id_array_from_index_array(_ab[1], IORequest.a_max_elements[1], _a6);
            _80 = cm_id_array_from_index_array(_ab[2], IORequest.a_max_elements[2], _a6);
            _81 = cm_id_array_from_index_array(_ab[3], IORequest.a_max_elements[3], _a7, _7c, _ab[4], "n_viewed");
            if (_aa > 3) {
                _82 = cm_id_array_from_index_array(_ab[5], IORequest.a_max_elements[5], _a8, _7d, _ab[6], "n_viewed");
            }
            if (IORequest.recently_viewed_product === undefined) {
                IORequest.recently_viewed_product = (_7e.length === 0 ? 0 : _7e[0]);
            }
            if (IORequest.recently_viewed_category === undefined) {
                IORequest.recently_viewed_category = (_81.length === 0 ? 0 : _81[0]);
            }
            return (true);
        } else {
            return (false);
        }
    };
    cm_build_html_table_from_array = function(_ac, _ad, p_h, _ae) {
        var _af = (_ae ? 2 : 1);
        var _b0 = _ad.length;
        var _b1 = "";
        var _b2 = (_af == 1 ? "<TD COLSPAN=2>" : "<TD>");
        if (_b0 > 0 && (_ad[0] !== undefined)) {
            _b1 = "<TR><TH ROWSPAN=" + _b0 + ">" + _ac + "</TH>" + _b2 + (_af == 2 ? p_h[_ad[0]][_ae] + "</TD><TD>" : "") + _ad[0] + "</TD></TR>";
            for (var ii = 1; ii < _b0; ii++) {
                _b1 += "<TR>" + _b2 + (_af == 2 ? p_h[_ad[ii]][_ae] + "</TD><TD>" : "") + _ad[ii] + "</TD></TR>";
            }
        } else {
            _b1 = "<TR><TH ROWSPAN=1>" + _ac + "</TH>" + "<TD COLSPAN=2>" + "No " + _ac + "</TD></TR>";
        }
        return (_b1);
    };
    cm_get_products_in_cart = function() {
        if (cm_build_all_recent_arrays() === true) {
            return (_7f);
        } else {
            return ([]);
        }
    };
    this.cm_format_cookie_arrays = function(_b3) {
        if (cm_build_all_recent_arrays() === true) {
            var _b4 = "<TABLE BORDER=2 CELLPADDING=2>";
            _b4 += "<TR> <TH COLSPAN=3>Recent " + (_b3 == "products" ? "Products" : "Categories") + "</TH> </TR>";
            if (_b3 == "products" || _b3 === undefined) {
                _b4 += cm_build_html_table_from_array("Viewed Products", _7e, _7b);
                _b4 += cm_build_html_table_from_array("Carted Products", _7f, _7b);
                _b4 += cm_build_html_table_from_array("Purchased Products", _80, _7b);
            }
            if (_b3 == "categories" || _b3 === undefined) {
                _b4 += cm_build_html_table_from_array("Category Views", _81, _7c, "n_viewed");
            }
            return (_b4 + "</TABLE>");
        } else {
            return ("<H3>Can't create table.  Cookies disabled</H3>");
        }
    };
    this.cm_ted_io = function(_b5) {
        var _b6 = false;
        if (cm_build_all_recent_arrays() === true) {
            if (_b5.i_offer !== undefined) {
                if (_b5.i_offer == "epr_category") {
                    if (_b5.cg.length <= IORequest.max_cat_length) {
                        _81 = cm_add_action(_b5.cg, _7c, IORequest.encrypt_cats, _81, "n_viewed");
                        _b6 = true;
                    }
                }
                if (_b5.i_offer == "brand") {
                    IORequest.log(IORequest.log_trace, "adding " + _b5.brn, "g_a_brn_viewed array");
                    _82 = cm_add_action(_b5.brn, _7d, 1, _82, "n_viewed");
                    _b6 = true;
                }
            } else {
                if (_b5.tid == 1 || _b5.tid == 6 || _b5.tid == 5) {
                    IORequest.log(IORequest.log_cookie_write, "initial " + IORequest.state_cookie, IORequest.find_state_cookie());
                }
                if (5 == _b5.tid) {
                    var _b7 = "" + _b5.pr;
                    var _b8 = "" + _b5.cg;
                    if (_b7.length <= IORequest.max_prd_length) {
                        _7e = cm_add_action(_b7, _7b, IORequest.encrypt_prds, _7e);
                        _b6 = true;
                    }
                    if ((IORequest.use_site_category === true) && (_b8.length <= IORequest.max_cat_length)) {
                        _81 = cm_add_action(_b8, _7c, IORequest.encrypt_cats, _81, "n_viewed");
                        _b6 = true;
                    }
                    IOState.b_product_view = true;
                    IOState.h_productview_product[_b7] = 1;
                    IOState.productview_product = _b7;
                    IOState.productview_category = _b8;
                }
                if ((4 == _b5.tid) && (5 == _b5.at) && (_b5.pr.length <= IORequest.max_prd_length)) {
                    _7f = cm_add_action(_b5.pr, _7b, IORequest.encrypt_prds, _7f);
                    _b6 = true;
                }
                if (4 == _b5.tid && 9 == _b5.at) {
                    if (_b5.pr.length <= IORequest.max_prd_length) {
                        _80 = cm_add_action(_b5.pr, _7b, IORequest.encrypt_prds, _80);
                        _b6 = true;
                    }
                }
            }
            if (_b6) {
                var _b9 = [cm_create_integer_array_from_id_array(_7e, _7b, "index").join(","), cm_create_integer_array_from_id_array(_7f, _7b, "index").join(","), cm_create_integer_array_from_id_array(_80, _7b, "index").join(","), cm_create_integer_array_from_id_array(_81, _7c, "index").join(","), cm_create_integer_array_from_id_array(_81, _7c, "n_viewed").join(","), cm_create_integer_array_from_id_array(_82, _7d, "index").join(","), cm_create_integer_array_from_id_array(_82, _7d, "n_viewed").join(",")];
                if (_87) {
                    for (var jj = 0; jj < _86.length; jj++) {
                        _b9[jj] = _86[jj] + _79 + _b9[jj];
                    }
                }
                var cfg = _7a.join();
                var prd = cm_create_id_array_from_hash(_7b).join(_78);
                var cat = cm_create_id_array_from_hash(_7c).join(_78);
                var brn = cm_create_id_array_from_hash(_7d).join(_78);
                var cnt = _b9.join(IORequest.cookie_array_separator);
                var _ba = [cfg, prd, cat, brn, cnt].join(IORequest.cookie_separator);
                IORequest.set_and_check_cookie(IORequest.state_cookie, _ba);
                IORequest.log(IORequest.log_cookie_write, "write " + IORequest.state_cookie, _ba);
            }
        }
    };
};

