﻿  
////////////////////////////////////////////////////////////////////////////////////////////////////
// setup some globals
////////////////////////////////////////////////////////////////////////////////////////////////////
var zoomInt, wW, wH, wmet, hmet, buffer_launch;
// location of web services
var wsloc = '/shop/ClientService/Shell.svc/', wsctype = "application/json; charset=utf-8";
var abclick = 'onclick = "message.show(\'Existing services are billed as shown on your most previous statement. Visit <a href=https://my.cincinnatibell.com/ target=_blank>My Account</a> to view your most recent bill. Any changes you have made since your last billing cycle will not be reflected in My Account until your next statement.\'); return false;"';


// remove all filters 
//if ($.browser.msie) { document.all.inner.style.removeAttribute("filter", false);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// avoid firebug console errors
if (firebug) { if (console) { } else {console = { log: function() { } }; } }
else {console = { log: function() { } }; }
////////////////////////////////////////////////////////////////////////////////////////////////////
// page initialization (onload)

// put us in httpsland
if (is_prod) { if (location.protocol.toLowerCase() == 'http:') { var nu = location.href.replace('http:', 'https:'); nu = nu.replace('https://c', 'https://www.c');location.href = nu; } }

var p = null, bogus = '{"i":"i"}';

function init(in_u, callback) {
    if (!p) { load_p(in_u, callback); } // load up product object
    else {

        // if already logged in, setup the authinator
        if (in_u) {
            if (in_u.hp) {
                if (in_u.hp.auth) { if (!in_u.hp.acc) { in_u.hp.acc = ''; } u.hp = in_u.hp; }
            }
            if (in_u.w) {
                if (in_u.w.auth) { if (!in_u.w.acc) { in_u.w.acc = ''; } u.w = in_u.w; }
            }
            auth.get_addrs('u.load_addrs(' + callback + ')');
        }
        else {
            silo.load_js(['hp', 'w', 'i', 'tv', 'hs']);
            // setup resize for blanket, silo, inner and message
            var alladj = '';
            if (!$.browser.msie) { $(window).resize(function() { clearTimeout(alladj); silo.blanket.adjust(); setTimeout('silo.adjust(); message.adjust();', 1000); }); }
            if (callback) {eval(callback); }
            page.init();           
        }
    }
}

function load_p(in_u, callback) {
    if (!p) {
        $.ajax({
            type: "GET",
            url: "/shop/js/p" + to_min + ".js" + (js_version.p ? '?v=' + js_version.p : ''),
            success: function() { init(in_u, callback); },
            dataType: "script",
            cache: (js_version.p ? true : false)
        });
    }
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////

var $_b = $("body"), opac_low = { border: 0 }, opac_med = { border: 0 }, opac_high = { border: 0 };

if (!$.browser.msie) { opac_low.opacity = '0.1'; opac_med.opacity = '0.3';  opac_high.opacity = '1.0'; }

//////////////////////////////////////////////////////////////////////////////////////////////////// 
// USER
////////////////////////////////////////////////////////////////////////////////////////////////////

var u = {

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // USER SILO DATA
    ////////////////////////////////////////////////////////////////////////////////////////////////////

    hp: {
        auth: false // bool for wireline
    }, // homephone
    w: {
        auth: false // true/false or zip code for wireless (based on typeOf - bool or number)
    }, // wireless
    i: {}, // internets
    tv: {}, // tv
    hs: {}, // home security

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // USER ACCOUNTS, ADDRESSES, TNS
    ////////////////////////////////////////////////////////////////////////////////////////////////////

    accs: { // object to stick account arrays in
        hp: {}, // array to stick accounts into
        w: {} // array to stick accounts into
    },

    // this guy loads up the addresses returned form the get address info call
    // for customers that are authed already
    load_addrs: function(callback, skip_init) {

        if (u.get_addrs) {

            for (acc = 0, ACC = u.get_addrs.accts.length; acc < ACC; acc++) {
                var theacc = u.get_addrs.accts[acc];
                if (theacc.id.length == 8) { theacc.type = 'w'; }
                if (theacc.id == '') { theacc.id = 'N'; }
                u.accs[theacc.type][theacc.id] = theacc;

                // zt qual
                if (theacc.type == 'hp') {
                    if (theacc.qual.toString() != -3) {
                        u.i.qual = theacc.qual.toString();
                    }
                }

                // lock account check
                auth.lockedto(theacc);
            }
            page.address();
            delete u.get_addrs;
            if (skip_init != true) { init('', callback); }
        }
    },


    // add product data to user
    add: function(ws, type, subtype, option, qty, uid) {
        if (type == "F") { if (p.hasRules[ws]) { eval('p.validate_rules(\'' + ws + '\',\'' + option + '\')'); } }

        var f;
        // if you're adding a hp package, then assign the value of what's checked to the u.hp.F
        if (type == 'P') {
            setExisting(ws, type, 'F', option);
        }

        if (uid) {
            // could be erroring out here 
            if (isArray(u.w.users[uid][type])) {
                for (j = 0, J = u.w.users[uid].t[type].length; j < J; j++) {
                    // if already in there
                    if (u.w.users[uid].t[type][j] == option) { f = true; break; }
                }
                if (!f) {
                    u.w.users[uid].t[type].push(option);
                }
            }
            else { u.w.users[uid].t[type] = option; }

            if (qty) { u.w.users[uid].t[type + option + 'q'] = qty; }
            if (u.w.users[uid].t.F) { $('#wassup').html('Features: ' + $.toJSON(u.w.users[uid].t.F)); }
        }
        else {
            if (isArray(u[ws][type])) {
                for (j = 0, J = u[ws][type].length; j < J; j++) {
                    // if already in there
                    if (u[ws][type][j] == option) { f = true; break; }
                }
                if (!f) {
                    u[ws][type].push(option);
                }
            }
            else { u[ws][type] = option; }
            if (qty) { u[ws][type + option + 'q'] = qty; }
            if (u[ws].F) { $('#wassup').html('Features: ' + $.toJSON(u[ws].F)); }
        }

    },
    // remote product data to user
    remove: function(ws, type, subtype, option, uid) {

        if (subtype) { a = a[subtype]; } // not currently passing subtypes
        if (uid) {
            if (isArray(u.w.users[uid].t[type])) {

                //console.log('-----------------------------------------');
                //console.log('ws: ' + ws + ' type: ' + type + ' subtype: ' + subtype + ' option: ' + option);
                //console.log('i\'ve got 1: ' + u.w.users[uid][type]);

                for (j = 0, J = u.w.users[uid].t[type].length; j < J; j++) {
                    if (u.w.users[uid].t[type][j] == option) {
                        //console.log('i\'ve got 2a: ' + u.w.users[uid][type]);
                        u.w.users[uid].t[type].splice(j, 1);
                        delete u.w.users[uid].t[type][type + option + 'q'];
                        //console.log('i\'ve got 2b: ' + u.w.users[uid][type]);
                    }
                }
            }
            else { u.w.users[uid].t[type] = ''; }
            if (type == 'F') { $('#wassup').html('Features: ' + $.toJSON(u.w.users[uid].t[type])); }

            if (type == "F") { if (p.hasRules[ws]) { message.validate('{"ws":"' + ws + '","type":"' + type + '"}'); } }


        }
        else {
            if (isArray(u[ws][type])) {
                for (j = 0, J = u[ws][type].length; j < J; j++) {
                    if (u[ws][type][j] == option) { u[ws][type].splice(j, 1); delete u[ws][type][type + option + 'q']; delete u[ws][type + option + 'q']; }
                }
            }
            else { u[ws][type] = ''; }
            if (type == 'F') { $('#wassup').html('Features: ' + $.toJSON(u[ws][type])); }

            if (type == "F") { if (p.hasRules[ws]) { message.validate('{"ws":"' + ws + '","type":"' + type + '"}'); } }
        }
    }



}


//////////////////////////////////////////////////////////////////////////////////////////////////// 
// SILO
////////////////////////////////////////////////////////////////////////////////////////////////////

var silo = {

    "hp": { "i": false },
    "w": { "i": false },
    "i": { "i": false },
    "tv": { "i": false },
    "hs": { "i": false },
    "message": { "i": false },

    headings: {
        "i": "High-Speed Internet",
        "hp": "Home Phone Service",
        "w": "Wireless Phone Service",
        "tv": "Digital TV",
        "hs": "Home Security"
    },
    self_size: 611,

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // load up the silo specific js file
    load_js: function(ws, callback) {
        var ts = silo[ws], tsi = undefined;
        if (ts) { tsi = silo[ws].i; }
        if (!tsi) {
            if (isArray(ws)) { for (l = 0, L = ws.length; l < L; l++) { this.load_js(ws[l]); } }
            else {
                $.ajax({
                    type: "GET",
                    url: "/shop/js/" + ws + to_min + ".js" + (js_version[ws] ? '?v=' + js_version[ws] : ''),
                    success: function() { if (silo[ws]) { silo[ws].i = true; } if (callback) { eval(callback); } },
                    dataType: "script",
                    cache: (js_version[ws] ? true : false)
                });
            }
        }

    },
    login: function(ws, auth_type) {
    if (pageTracker) { pageTracker._trackEvent('Consord', 'Link', 'ExistingCustomerButton'); }
        silo.zoom('auth', ws, auth_type);
    },
    auth: {
        start: function(ws, auth_type) {
            if (!ws) {
                auth.display_pick_auth();
            }
            else {
                auth.display_main(ws, auth_type);
            }
        }
    },
    // launch a silo
    launch: function(ws, ssp, uid) {
        clearTimeout(buffer_launch);
        if (page.apcp_ready) { silo._launch(ws, ssp, uid); }
        else { buffer_launch = setTimeout('silo.launch(\'' + ws + '\', \'' + ssp + '\', ' + uid + ')', 800); }
    },
    _launch: function(ws, ssp, uid) {
        // if the ws js didn't finish preloading, loader up and callback zoom
        if (!silo[ws].i) { silo.load_js(ws, 'silo.zoom(\'' + ws + '\', \'' + ssp + '\', \'' + uid + '\');'); }
        else { silo.zoom(ws, ssp, uid); }
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // empty contents of silo
    clear: function() {
        silo.$_inner.html('');
    },
    // close
    close: function(w) {

        var keep_open = false;
        // clean out tmp wireless users
        if (u.w) { if (u.w.users) { for (ur in u.w.users) { if (u.w.users[ur].tmp) { delete u.w.users[ur]; } } } }
        u.wcount();
        if (u.w.users.total > 0) { keep_open = true; }

        if (w && keep_open) {
            silo.w.get_users();
        }
        else {
            message.hide();
            silo.blanket.hide();
            silo.inner.hide();
            silo.$_inner.remove();
            silo.$_inner = $('#inner');
            silo.$_box.remove();
            silo.$_ex_box.remove();
            delete silo.$_ex_box;
            delete silo.$_box;
            silo.$_x.remove();
            delete silo.$_x;
            page.title('');
        }
    },

    fatal: function(m, c, meth, s, a) {
        silo.inner.hide();
        $('#inner').html('\<br/><br/>\
            <div id="fatal"><h1>An unexpected error has occurred</h1>\
            <p>An unexpected error has occurred in one of our systems and we cannot complete your order at this time.  To complete your order please call 513-565-2210 or try again in 20 minutes.</p>\
            <!-- <br/><p style="color: ##D0D0D0;">' + m + '</p> --></div>');
        silo.inner.show();
        if (typeof m == "string") {
            m = santatize(m);
            m = m.replace(/ /g, '-');
            page.log('', ['Failure', m, c, meth || 'unknown', s, a]);
            if (pageTracker) {
                //setTimeout("pageTracker._trackPageview('/shop/dynamic/fatal/" + escape(m.toLowerCase()) + "')", 900);
                pageTracker._trackEvent('Consord', 'Fatal', escape(m.toLowerCase()));
            } // track changes in GA
        }
    },

    timeOut: function(meth, s, a) {
        page.log('location.href="/shop/session.aspx"', ['Failure', 'session timeout', '', meth || 'unknown', s, a]);
    },

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // visual animation of silo enlarging
    // params 
    //       ws      (silo you wanna launch - required )
    //       ssp     (silo starting point - optional)
    zoom: function(ws, ssp, uid) {

        if (!($('#box').length > 0)) {
            $_b.append('<div id="ex_box"><div id="ex_box_t"></div><div id="ex_box_m"></div><div id="ex_box_b"></div></div><img src="images/modal.png" id="box">');
            silo.$_box = $('#box');
            silo.$_ex_box = $('#ex_box');
            silo.$_ex_box_m = $('#ex_box_m');
        }

        silo.inner.load();

        var wW = ((window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth)) / 2) - 29;
        var wH = (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight)) / 2;

        var toW = wW - (940 / 2), toH = wH - (611 / 2),
        stW = (wW - 3), stH = (wH - 3);
        if (toW < 20) { toW = 20; }
        if (toH < 20) { toH = 20; }

        silo.$_box.css({
            width: 3,
            height: 3,
            left: stW,
            top: stH
        }).animate({
            width: 940,
            height: 611,
            left: toW,
            top: toH
        }, 400,
	            function() {
	                silo.$_x.css({
	                    left: parseInt(silo.$_box.css('left')) + parseInt(silo.$_box.width()) - 36,
	                    top: parseInt(silo.$_box.css('top')) + 6,
	                    display: 'block'
	                });
	                silo.blanket.show();
	                silo[ws].start(ssp, uid);
	                $('#ex_box').css({
	                    width: 940,
	                    height: 611,
	                    left: toW,
	                    top: toH,
	                    display: 'block'
	                });
	                silo.$_box.css({ display: 'none' });
	            });
    },
    // change the height of the silo
    resize: function(h, callback) {
        if (!h) { h = 611; }
        if (silo.$_ex_box) {
            if (silo.$_ex_box.length > 0) {
                var lh = h - $('#ex_box_t').height() - $('#ex_box_b').height();
                if (lh < 0) { lh = 1; }
                silo.$_ex_box.css({ height: h });
                silo.$_inner.css({ height: (h - 45) });
                silo.$_ex_box_m.animate({ height: lh }, 700, function() { silo.blanket.adjust(); eval(callback) });
                silo.self_size = h;
            }
        }
    },


    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // silo wrapper
    ////////////////////////////////////////////////////////////////////////////////////////////////////

    display_container: function(ws, auth_type, params) {
        if (params == undefined) { params = {}; }

        if (!($('#s_body').length > 0)) {
            silo.inner.wait();
            var h = '<div id="s_statusbar">';

            if (auth_type == 'hp') {
                if (u.hp) {
                    // if we're working with an existing TN
                    if (u.hp.tn) {
                        h += '<label>Phone Number: ' + formatPhone(u.hp.tn) + ' <a href="#" onclick="auth.logout(\'' + auth_type + '\'); silo.close(); return false;">Logout</a></label>';
                    }
                    // if we're working with a new address
                    else if (u.accs.hp.N) {
                        h += '<label>Address: ' + shrinkAddress(u.accs.hp.N) + ' <a href="#" onclick="silo.resize(); auth.display_main(\'' + ws + '\', \'' + auth_type + '\'); return false;">Change Service Address</a></label>';
                    }
                }
            }
            else if (auth_type == 'w') {
                // existing account
                if (u.w.acc) {
                    h += '<label>Address: ' + shrinkAddress(u.accs.w[u.w.acc]) + ' <a href="#" onclick="auth.logout(\'' + auth_type + '\'); silo.close(); return false;">Logout</a></label>';
                }
                // if we're working with a new wireless account
                else if (u.w.zip) {
                    h += '<label>Zip Code: ' + u.w.zip + ' <a href="#" onclick="silo.resize(); auth.display_main(\'' + ws + '\', \'' + auth_type + '\'); return false;">Change Zip Code</a></label>';
                }
            }

            h += '<h2 id="main_h">' + this.headings[ws] + '</h2>\
            <div class="s_status" id="status_' + ws + '"' + ((!params.nobar) ? '' : ' style="display: none;"') + '><img src="/shop/images/dot.gif" id="statusimg"><div id="mapcontainer"></div></div>\
            </div>\
            <div id="s_body"></div>';

            silo.$_inner.html(h);
        }
        params.nobar ? $('#status_' + ws).css({ display: 'none' }) : $('status_' + ws).css({ display: '' });
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////   
    display_inner_container: function(ws) {

        if (!($('#s_right').length > 0)) {
            silo.body.wait();
            var h = '';
            if (ws != 'w') { h += '<img src="/shop/images/icon_' + ws + '_lrg.png" id="icon_' + ws + '_lrg">'; }
            h += '\
            <h3 id="h_step">Loading...</h3>\
                <div id="s_right"></div>\
                <div id="s_bot_buttons"></div>';
            $('#s_body').html(h);
        }
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////   
    adjust: function() {
        silo.$_box = $('#box');
        silo.$_ex_box = $('#ex_box');
        if (silo.$_box.length > 0) {
            var wW = ((window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth)) / 2) - 29;
            var wH = (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight)) / 2;

            var toW = wW - (940 / 2), toH = wH - (611 / 2);
            if (toW < 20) { toW = 20; }
            if (toH < 20) { toH = 20; }

            silo.$_x.css({ display: 'none' });
            if (silo.$_inner) { if (silo.$_inner.length > 0) { silo.inner.hide(); } }
            silo.$_box.animate({
                left: toW,
                top: toH
            }, function() {
                silo.$_x.css({
                    left: parseInt(silo.$_box.css('left')) + parseInt(silo.$_box.width()) - 36,
                    top: parseInt(silo.$_box.css('top')) + 6,
                    display: 'block'
                });
                silo.inner.adjust();
            });

        }
        if (silo.$_ex_box.length > 0) {
            silo.$_ex_box.animate({
                left: toW,
                top: toH
            });
        }
    },
    timers: {},
    clear_wait_msgs: function() {
        for (wmt in silo.timers) {
            clearTimeout(silo.timers[wmt]);
            delete silo.timers[wmt];
        }
    },
    wait_msg: function(wm) {
        silo.clear_wait_msgs();
        silo.timers[wm + '1'] = setTimeout('$(\'#' + wm + '\').html(\'Please Wait.\')', 2000);
        silo.timers[wm + '2'] = setTimeout('$(\'#' + wm + '\').html(\'Still Working.\')', 9000);
        silo.timers[wm + '3'] = setTimeout('$(\'#' + wm + '\').html(\'Almost There.\')', 18000);
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    inner: {
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        load: function() {
            var i = $('#inner');
            if (i.length <= 0) { $_b.append('<div id="inner"></div><a href="#" onclick="silo.close(); return false;"><img src="/shop/images/x.png" id="x" alt="close" /></a>'); }
            silo.$_x = $('#x');
            silo.$_inner = $('#inner');
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        show: function() {
            if (!silo.$_box) { silo.$_box = $('#box'); }
            var blop = { display: 'block',
                left: parseInt(silo.$_box.css('left')) + 23,
                top: parseInt(silo.$_box.css('top')) + 23
            }
            if (opac_low.opacity) { blop.opacity = opac_low.opacity; }
            silo.$_inner.css(blop).animate(opac_high, 500, function() { silo.$_inner.css('opacity', ''); });
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        hide: function() {
            if (silo.$_inner) { silo.$_inner.css({ display: 'none' }); }
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        wait: function() {
            //message.hide();
            this.hide();
            silo.$_inner.html('<div class="spinner"><img src="images/spinner.gif"><span id="inner_spinner_msg" class="spinner_msg"></span></div>');
            silo.wait_msg('inner_spinner_msg');
            this.show();
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        adjust: function() {
            if (silo.$_inner) {
                if (silo.$_inner.length > 0) {
                    silo.$_inner.css({ left: parseInt(silo.$_box.css('left')) + 23,
                        top: parseInt(silo.$_box.css('top')) + 23
                    });
                    silo.inner.show();
                }
            }
        }
    },
    // shortcut for resize and wait
    rw: function() {
        silo.resize();
        silo.inner.wait();
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    body: {
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        show: function() {
            var blop = {
                display: 'block'
            }

            if (opac_low.opacity) { blop.opacity = opac_low.opacity; }
            $('#s_body').css(blop).animate(opac_high, 500, function() { $('#s_body').css('opacity', ''); });
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        hide: function() {
            $('#s_body').css({ display: 'none' });
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        wait: function() {
            message.hide();
            this.hide();
            $('#s_body').html('<div class="spinner"><img src="images/spinner.gif"><span id="body_spinner_msg" class="spinner_msg"></span></div>');
            silo.wait_msg('body_spinner_msg');
            this.show();
        }
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    right: {
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        // st = scrolltopping : bool
        show: function(stin) {
            if (stin == undefined) { stin = true; }
            var blop = {
                display: 'block'
            }, st = { top: 0, left: 0 };
            if (opac_low.opacity) { blop.opacity = opac_low.opacity; }

            $('#s_right').css(blop).animate(opac_high, 500, function() {
                $('#s_right').css('opacity', '');
                // return the scroll position of a div overflowed auto to 0 unless there's a preselected phone
                if ($('#myphone').length > 0) { st = $('#myphone').offset(); } //document.getElementById('myphone').offsetTop; }
                else if ($('#myplan').length > 0) { st = $('#myplan').offset(); } //document.getElementById('myplan').offsetTop; }

                if (stin) {
                    var sroff_init = $('#s_right').offset();
                    if (sroff_init == undefined) { sroff_init = { top: 0, left: 0 }; }
                    if (sroff_init.top == undefined) { sroff_init.top = 0; }
                    var ost = st.top - sroff_init.top;
                    if (ost < 0) { ost = 0; }
                    $('#s_right').scrollTop(ost);
                }
            });

        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        hide: function() {
            $('#s_right').css({ display: 'none' });
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        empty: function() {
            this.top();
            $('#s_right').html('');
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        wait: function(wa) {
            message.hide();
            this.empty();
            $('#s_right').html('<div class="spinner"><img src="images/spinner.gif"><span id="right_spinner_msg" class="spinner_msg"></span></div>');
            silo.wait_msg('right_spinner_msg');
            this.show(false);
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        top: function() {
            $('#s_right').scrollTop(0);
        }
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    blanket: {
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        show: function() {
            page.roller.kill();
            if ($('#footer').length > 0) { $('#footer').hide(); } // footer flashes so hide it
            var b = $('#blanket');
            if (b.length <= 0) { $_b.append('<div id="blanket"></div>'); }
            silo.blanket.adjust();
            $('#blanket').css({ opacity: 0.1 }).animate({ opacity: 0.9 }, 200);
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////   
        hide: function() {
            if ($('#footer').length > 0) { $('#footer').show(); } // bring back the footer!
            var b = $('#blanket');
            if (b.length <= 0) { $_b.append('<div id="blanket"></div>'); }
            silo.blanket.adjust();
            $('#blanket').css({ opacity: 0.9 }).animate({ opacity: 0.0 }, 200, function() { $('#blanket').remove(); });
        },
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        adjust: function() {
            var b = $('#blanket');
            if (b.length > 0) {
                var h = $(document).height(),
                w = $(document).width();
                b.css({ width: w, height: h });
            }
        }
    }
}

var message = {
load: function(f, pt1, pt2, pt3) {
        $.ajax({
            type: "GET",
            url: "/shop/js/message"+to_min+".js" + (js_version.m ? '?v=' + js_version.m : ''),
            success: function() { eval(message[f](pt1, pt2, pt3)); },
            dataType: "script",
            cache: (js_version.m ? true : false)
        });
    },
    show: function(pt1, pt2, pt3) { this.load('show', pt1, pt2, pt3); },
    hide: function(pt1, pt2, pt3) { this.load('hide', pt1, pt2, pt3); },
    validate: function(pt1, pt2, pt3) { this.load('validate', pt1, pt2, pt3); },
    cue: function(pt1, pt2, pt3) { this.load('cue', pt1, pt2, pt3); },
    only_if_inactive: function(pt1, pt2, pt3) { this.load('only_if_inactive', pt1, pt2, pt3); },
    adjust: function(pt1, pt2, pt3) { this.load('adjust', pt1, pt2, pt3); }
}


var cart = {
    save: function() {
        var ready = true, hpreq = false, reqhp = []; //reqhp = ['i', 'tv', 'hs'];
        var incomplete = 0, ss = [], fs = [], afs = []; // how many incomplete silos, what are start setup, what are finish setup

        for (dsl = 0, DSL = page.ds.length; dsl < DSL; dsl++) {
            var s = page.ds[dsl];
            if ((u[s].status == 1) || (u[s].status == 5)) {
                // figure out what products they need
                // figure out how many they need to finish
                // figure out if it's finish or start setup
                incomplete++;
                if (u[s].status == 1) { fs.push(s); afs.push(s); }
                else if (u[s].status == 5) { ss.push(s); afs.push(s); }
                ready = false;
            }
        }



        if (ready) {
            // check to see if they've got the right stuff to go forward
            for (rh = 0, RH = reqhp.length; rh < RH; rh++) {

                if (u[reqhp[rh]].status != 3) {
                    // have internet, need hp at least
                    // statuses
                    // Complete = 0, 
                    // Unfinished = 1, 
                    // NotAllowed = 2,
                    // Unselected = 3,
                    // ExistingNoChange = 4
                    // startsetup = 5
                    // FailedAccountValidation = 6  
                    if (u.hp.status == 3) {
                        ready = false;
                        hpreq = true;
                        break;
                    }
                }

            }
        }

        if (ready) {
            page.wait();
            $.ajax({
                type: "POST",
                url: wsloc + "SaveToCart",
                data: bogus,
                contentType: wsctype,
                dataType: "json",
                cache: false,
                success:
                    function(r) {
                        if (r.rc == 0) {
                            location.href = 'cart/';
                        }
                        else if (r.rc == 911) { silo.timeOut('function cart.save', this.url); }
                        else { message.show('Please try again.'); page.log('', ['Failure', 'cart not ready acception: please try again message thrown', this.url, 'Event Notice']); }
                    },
                error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function cart.save', this.url); }
            });
        }
        else {
            if (hpreq) { message.show('The products you\'ve selected require home phone service. Please add home phone to your order.'); }
            else {



                var s_plur = 's';
                if (incomplete == 1) { s_plur = ''; }
                var ssfs = '';
                if (ss.length > 0) { ssfs += '<b>Start Setup</b>'; }
                if (fs.length > 0) { if (ssfs != '') { ssfs += ' or '; } ssfs += '<b>Finish Setup</b>'; }

                var mes = 'You\'re almost finished, but you have selected products that have not been completed yet.  To complete your order click ' + ssfs + ' for the following product' + s_plur + ': ';
                for (ss1 = 0, SS1 = afs.length; ss1 < SS1; ss1++) {
                    mes += (afs.length > 1 ? (ss1 == (SS1 - 1) ? 'and ' : '') : '') + silo.headings[afs[ss1]] + ', ';
                }
                mes = mes.replace(/, $/, '');
                mes = mes.replace(/, and/, ' and');
                mes += '.';
                message.show(mes);


            }
        }
    }

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// page object

var page = {
    apcp_ready: false,
    ds: ['w', 'hp', 'i', 'tv', 'hs'],
    init: function() {
        // check to see if cookies are enabled
        createCookie('t', true);
        if (!readCookie('t')) { message.show('You do not have cookies enabled in your browser. Please enable cookies and try again.'); }

        this.apcp();
    },
    title: function(t) {
        document.title = 'Build Your Bundle: ' + t;
        t = santatize(t);
        t = t.replace(/ /g, '-');
        if (pageTracker) {
            setTimeout("pageTracker._trackEvent('Consord', 'Pageview', '" + escape(t.toLowerCase()) + "')", 800);
            //setTimeout("pageTracker._trackPageview('/shop/dynamic/" + escape(t.toLowerCase()) + "')", 900);
        } // track changes in GA
    },
    address: function() {
        var addr = [], h = '';

        // if we're working with an existing TN
        if (u.hp.acc) { if (u.accs.hp[u.hp.acc]) { addr.push({ 'a': u.accs.hp[u.hp.acc], 'ws': 'hp', 'at': 'hp' }); } }
        else if (u.accs.hp.N) { addr.push({ 'a': u.accs.hp.N, 'ws': 'hp', 'at': 'hp' }); }
        if (u.w.acc) { if (u.accs.w[u.w.acc]) { addr.push({ 'a': u.accs.w[u.w.acc], 'ws': 'w', 'at': 'w' }); } }

        var addlogoutbutton = false;
        for (a = 0, A = addr.length; a < A; a++) {
            h += '<div class="m_waddr"><img src="/shop/images/your_' + (addr[a].a.id == 'N' ? 's' : '') + addr[a].at + '.png" class="your_account" alt="Your Account"/>' + formatAddress(addr[a].a) + '\
             <div class="address_left noborder"><a href="#" onclick="silo.login(\'' + addr[a].ws + '\', \'' + addr[a].at + '\'); return false;" class="apcp_change">Change</a>';
            if (addr[a].a.id) {
                if (addr[a].a.id != 'N') { addlogoutbutton = true; }
            }
            if (addlogoutbutton) { h += '<a href="#" onclick="auth.logout(); return false;" class="apcp_logout">Logout</a>'; }
            h += '</div></div>';
        }

        if (addr.length > 1) {
            $('#checkout_lower').css({ display: 'none' });
            $('#checkout_upper').css({ display: '' });
        }
        else {
            $('#checkout_lower').css({ display: '' });
            $('#checkout_upper').css({ display: 'none' });
        }

        if (h != '') { $("#m_addr").html(h); }
        else { $("#m_addr").html('<a href="#" onclick="silo.login(); return false;"><img src="/shop/images/b_existingcustomer.gif" id="b_excust" alt="existing customer" /></a>'); }
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    check: function(ws, ob, is_undo, callback) {
        if (!ob) {
            ob = document.form1['sel_' + ws];
            if (ob) {
                ob.checked = true;
            }
        }
        if (ob) {
            var rs = ws, ischecked = ob.checked;
            if (ischecked == undefined) { ischecked = false; }
            // statuses
            // Complete = 0, 
            // Unfinished = 1, 
            // NotAllowed = 2,
            // Unselected = 3,
            // ExistingNoChange = 4
            // startsetup = 5
            // FailedAccountValidation = 6  

            var prevhtml = $('#s_' + ws + ' .sel_buts').html();
            $('#s_' + ws + ' .sel_buts').html('<img src="/shop/images/spinner.gif" />');

            $.ajax({
                type: "POST",
                url: wsloc + "SetSelectedStatus",
                data: '{"silo": "' + rs + '", "isselected": "' + ischecked + '"}',
                contentType: wsctype,
                dataType: "json",
                cache: false,
                success:
                    function(r) {

                        if (r.rc == 911) { silo.timeOut('function page.check', this.url); }
                        else {
                            if (r.helpermsg) { setTimeout("message.show('" + r.helpermsg + "')", 750); }
                            if (!is_undo) {
                                if ((ob.checked == false) && (r[ws].status != 3)) { page.apcp(); }
                                else {
                                    page.silo_buttons(ws, ischecked, prevhtml);
                                }

                            }
                            else { page.silo_buttons(ws, true, ''); }
                            for (dsl = 0, DSL = page.ds.length; dsl < DSL; dsl++) {
                                var h = '', s = page.ds[dsl];
                                if (u[s]) { u[s].status = r[s].status; }
                                for (sum = 0, SUM = r[s].summary.length; sum < SUM; sum++) {
                                    h += '<li>' + r[s].summary[sum] + '</li>';
                                }
                                $('#sum_' + s).html(h);

                                var sumh;
                                switch (r[s].status) {
                                    case 0: sumh = 'Your Order'; break;
                                    case 4: sumh = 'Existing Services'; break;
                                    default: sumh = 'Featuring';
                                }
                                $('#sumh_' + s).html(sumh);
                                // update button state
                                $('#bfin_' + s).attr('class', '');
                                $('#bfin_' + s).attr('class', 'b_fin_comp st' + r[s].status);

                                // update pricing
                                $('#tr_' + s + ' .ovp').html('$' + parseFloat(r[s].monthly).toFixed(2));
                            }

                            // update main pricing
                            page.math(r);
                            if (callback) { eval(callback); }
                            page.sfmessage();

                        }

                    },
                error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function page.check', this.url); }
            });
        }
    },
    silo_buttons: function(ws, ischecked, prevhtml, animation) {
        if (ischecked) {
            $('#s_' + ws).addClass('active');
            $('#s_' + ws + ' .silo_abrevs').css({ display: 'none' }).slideDown('slow', function() {
                $('#s_' + ws + ' .sel_buts').html(prevhtml);
                $('#sel_' + ws).attr('checked', ischecked);
                $('#sl_' + ws).attr('onclick', 'return false');
                $('#sl_' + ws).unbind('click');
                $('#s_' + ws + ' .b_fin_comp').click(function(e) { silo.launch(ws); return false; });
                $('#s_' + ws + ' .silo_abrevs').click(function(e) { silo.launch(ws); return false; });

                $('#sl_' + ws).click(function(e) { silo.launch(ws); return false; });
                $('#tr_' + ws).css({ display: 'block' });
            });
        }
        else {
            $('#s_' + ws + ' .silo_abrevs').slideUp('slow', function() {
                $('#s_' + ws).removeClass('active'); $('#s_' + ws + ' .sel_buts').html(prevhtml);
                $('#sel_' + ws).attr('checked', ischecked);
                $('#sl_' + ws).unbind('click');
                $('#s_' + ws + ' .b_fin_comp').unbind('click');
                $('#s_' + ws + ' .silo_abrevs').unbind('click');

                $('#sl_' + ws).click(function() { $('#sel_' + ws).attr('checked', true); page.check(ws, document.form1['sel_' + ws]); return false; });
                $('#tr_' + ws).css({ display: 'none' });
            });
        }
        if ($.browser.msie && ($.browser.version < 7)) {
            // IE6 cant handle the height on the silos ajusting the height on the container their inside of, so we'll do it for it
            var tallest = 500;
            $('.silo').each(function(i) { var th = this.offsetHeight; if (th > tallest) { tallest = th; } });
            $("#apcp_silos").css({ height: tallest });
        }
    },
    apcp: function(callback) {
        page.wait();
        $.ajax({
            type: "POST",
            url: wsloc + "GetAPCPData",
            data: bogus,
            contentType: wsctype,
            dataType: "json",
            cache: false,
            success:
                    function(r) {
                        if (r.rc == 911) { silo.timeOut('function page.apcp', this.url); }
                        else { page.update(r); page.tallest(); if (r.helpermsg) { message.show(r.helpermsg); } if (r.showcheckoutmsg) { message.show('/shop/mktg/checkoutmsg.html', 'mktg', true); } }
                        if (typeof callback == 'function') { callback(); }
                    },
            error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function page.apcp', this.url); }
        });
    },
    update: function(r, animation) {
        page.wait();
        // show marketing message

        if (r.ad) { if (!(readCookie('ad' + r.adid))) { page.roller.update(r.ad); page.roller.show(r.adid); } }
        var h = '';
        var producttheyhave = '';
        var ftdash = '';
        for (dsl = 0, DSL = page.ds.length; dsl < DSL; dsl++) {
            var s = page.ds[dsl];

            if (u[s]) { u[s].status = r[s].status; }

            // type 0 for dont know and 2 for really dont know so make 2 = 0
            if (r[s].type == 2) { r[s].type = 0; }


            // track products they have already
            if (r[s].type == 1) {
                producttheyhave += ftdash + s;
                ftdash = '-';
            }


            switch (r[s].status) {
                case 0: sumh = 'Your Order'; break;
                case 4:
                    sumh = 'Existing Services';
                    break;
                default: sumh = 'Featuring';
            }

            if ((r[s].status != 3) && (r[s].status != 6)) { r[s].checked = true; }
            if (r[s].status != 2) {
                h += '\
                    <div class="silo ' + s + (dsl == (page.ds.length - 1) ? (' last') : ('')) + (r[s].checked ? (' active') : ('')) + '" id="s_' + s + '">\
                    <div class="center"><b class="icon_name ' + s + '">Wireless</b>\
                    <a href="#" id="sl_' + s + '"><img src="/shop/images/icon_' + s + '.png" class="icon" style="width: ' + (s == 'tv' ? ('107px;') : ('73px;')) + ' height: 107px;" /></a>\
                    <div id="bfin_' + s + '" class="b_fin_comp st' + r[s].status + '"></div>';

                // if they're ordering this silo new. they get a checkbox
                if ((!r[s].type) && (r[s].status != 6)) {
                    h += '<div class="sel_buts">\
                        <input type="checkbox" name="sel_' + s + '" id="sel_' + s + '" ' + (r[s].checked ? (' checked="true"') : ('')) + 'onclick="page.check(\'' + s + '\',this);" />\
                        <label for="sel_' + s + '">SELECT</label>\
                        </div>';
                }
                else {
                    if ((r[s].status != 4) && (r[s].status != 6)) {
                        h += '<div class="sel_buts">\
                    <a href="#" onclick="page.check(\'' + s + '\', {checked: false}, true); return false;">UNDO CHANGES</a>\
                    </div>';
                    }
                }


                h += '<div class="silo_abrevs">\
                    <b id="sumh_' + s + '">' + sumh + ':</b>\
                    <ul id="sum_' + s + '">';

                for (sum = 0, SUM = r[s].summary.length; sum < SUM; sum++) {
                    h += '<li>' + r[s].summary[sum] + '</li>';
                }
                h += '</ul>\
                        </div>';


                h += '</div>\
                        </div>\
                        <script type="text/javascript">\
                        var prevhtml = $(\'#s_' + s + ' .sel_buts\').html();\
                        $(\'#s_' + s + ' .sel_buts\').html(\'<img src="/shop/images/spinner.gif" />\');\
                        page.silo_buttons(\'' + s + '\', ' + r[s].checked + ',prevhtml,' + animation + ');\
                        </script>';
            }

            $('#tr_' + s + ' .ovp').html('$' + parseFloat(r[s].monthly).toFixed(2));

        }

        if (pageTracker) {
            pageTracker._setCustomVar(
                    1,             // This custom var is set to slot #1 
                    'Existing-Products',   // The name of the custom varaible
                    (producttheyhave != '' ? producttheyhave.replace(/\s/g, "") : 'none'),      // Sets the value of "User Type" to "Member" or "Visitor" depending on status 
                     2             // Sets the scope to session-level   
                    );
            pageTracker._trackPageview();
        }


        this.math(r);
        $('#apcp_silos').html(h);
        page.apcp_ready = true;
        page.sfmessage();
    },
    sfmessage: function() {
        var ssmess = '', fsmess = '', finmess = '';
        for (dsl = 0, DSL = page.ds.length; dsl < DSL; dsl++) {
            var s = page.ds[dsl];

            // statuses
            // Complete = 0, 
            // Unfinished = 1, 
            // NotAllowed = 2,
            // Unselected = 3,
            // ExistingNoChange = 4
            // startsetup = 5
            // FailedAccountValidation = 6  
            if (u[s].status == 5) {
                ssmess = '<b class="blue">start setup</b>';
            }
            else if (u[s].status == 1) {
                fsmess = '<b class="blue">finish setup</b>';
            }

            if (ssmess && fsmess) { finmess = ssmess + ' or ' + fsmess; }
            else { finmess = ssmess + fsmess; }
            if (finmess) { finmess = ' and click ' + finmess; }
            $('#startsetuptext').html(finmess);
        }
    },
    tallest: function() {
        var tallest = 0;
        // find the tallest user
        $('.silo_abrevs').each(function(i) {
            var hi = this.scrollHeight;
            if (hi > tallest) { tallest = hi; }
        });
        tallest = tallest + 200;
        $('.silo.active').each(function(i) {
            this.style.height = tallest + 'px';
        });
    },
    math: function(r) {
        var webonly = 0, total_services = 0;
        for (dsl = 0, DSL = page.ds.length; dsl < DSL; dsl++) {
            var s = page.ds[dsl];
            webonly = webonly + r[s].webonly;
            if (r[s].status == 0) { total_services++; }
        }

        $('#rev_price').html('$' + parseFloat(r.monthly).toFixed(2));
        $('#tr_monthly .ovp').html('$' + parseFloat(r.monthly).toFixed(2));

        if (parseFloat(Math.abs(r.bundledsavings)) <= 0) { $('#tr_bundle').css({ display: 'none' }); }
        else { $('#tr_bundle').css({ display: 'block' }); $('#tr_bundle .ovp').html('$' + parseFloat(r.bundledsavings).toFixed(2)); }

        if (parseFloat(webonly) <= 0) { $('#wo').css({ display: 'none' }); }
        else { $('#wo').css({ display: 'block' }); $('#wosavings').html('$' + parseFloat(webonly).toFixed(2)); }

        $('#total_services').html(total_services);
        total_services == 1 ? $('#singplur').html('') : $('#singplur').html('s');

    },
    roller: {
        to: null,
        update: function(m) {
            if ($('#recommended').length == 0) {
                $_b.append('<div id="recommended"><div id="rec-inner"><p></p><a href="#" onclick="page.roller.hide(); return false;"><img src="/shop/images/x.png" id="rx" alt="close" /></a></div></div>');
            }
            $('#recommended p').html(m);
        },
        show: function(adid) {
            //if (adid) { createCookie('ad' + adid, true, '90'); } // cookie the rolldown to only show 1 time
            clearTimeout(page.roller.to);

            if ($('#recommended').length == 0) {
                $_b.append('<div id="recommended"><div id="rec-inner"><p></p><a href="#" onclick="page.roller.hide(); return false;"><img src="/shop/images/x.png" id="rx" alt="close" /></a></div></div>');
            }

            if ($("#box").length == 0) {
                if ((!$.browser.msie) && (!($.browser.version.substr(0, 3) == "6"))) {
                    page.roller.to = setTimeout("$('#recommended').slideDown('slow')", 1500);
                }
                else {
                    $('#recommended').css({ display: 'block' });
                }
            }
        },
        kill: function() {
            $('#recommended').remove();
            clearTimeout(page.roller.to);
        },
        hide: function() {
            if ((!$.browser.msie) && (!($.browser.version.substr(0, 3) == "6"))) {
                $('#recommended').slideUp('slow');
            }
            else {
                $('#recommended').css({ display: 'none' });
            }
        },
        link: function(callback) {
            this.hide();
            if (callback) { eval(callback); }
        }
    },
    wait: function() {
        $('#apcp_silos').html('<div class="spinner"><img src="images/spinner.gif"><span id="page_spinner_msg" class="spinner_msg"></span></div>');
        silo.wait_msg('page_spinner_msg');
    },
    log: function(callback, e) {
        // e is an array containing the following
        var v = ['Status', 'ErrorDescription', 'Comments', 'Method', 'Source', 'AdditionalInfo', 'ErrorType'];
        var ex = {};
        for (vc = 0, VC = v.length; vc < VC; vc++) { ex[v[vc]] = e[vc]; }
        ex.Comments += ' Browser: ' + navigator.userAgent;
        $.ajax({
            type: "POST",
            url: wsloc + "LogException",
            data: '{"Exception":' + $.toJSON(ex) + '}',
            contentType: wsctype,
            dataType: "json",
            success: function(r) { eval(callback); },
            error: function(r) { eval(callback); }
        });
    },
    setExisting: function() {
        if (pageTracker) { pageTracker._setVar('Existing Customer'); }
    }
}


//////////////////////////////////////////////////////////////////////////////////////////////////// 
// AUTHENTICATION
////////////////////////////////////////////////////////////////////////////////////////////////////

// params
//      ws      (silo you wanna authenticate - hp, i, tv, hs, w)
//      auth_type (authentication type - hp or w)
//      ssp (silo starting point)
//      asp (authentication starting point)
//      r (response back - dunno if we need this might remove)
//      param_vals (if a form element isn't present then you pass the form vars via this guy

var auth = {

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // the names of the divs that contain the form fields for clearing out the orange active status
    ////////////////////////////////////////////////////////////////////////////////////////////////////     
    form_fields: {
        "address": ['a_d_snum', 'a_d_sname', 'a_d_addr2', 'a_d_zip'],
        "account_num": ['a_d_acc_number', 'a_d_bill_zip'],
        "my_account": ['a_d_email', 'a_d_password']
    },

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // pathing for wireline authentication
    hp: function(ws, ssp, asp) {
        if (!asp) { asp = 'main'; } // if no start is passed in, start at beginning
        if (u.hp.acc && u.accs.hp[u.hp.acc] && !u.hp.tn) { asp = 'multiple_tns'; } // display select a tn page
        if (!u.hp.acc) { asp = 'main'; } // if no account selected, show main
        if (u.accs.hp.length == 0) { asp = 'main'; } // if no account selected, show main

        // apcp load auth
        if (u.hp.auth == false) {
            if (u.hp.zip && u.hp.acc) {
                this.enticate(ws, 'hp', ssp, asp, 'account_num', { acct: u.hp.acc, zip: u.hp.zip });
            }
            else {
                auth['display_' + asp](ws, 'hp', ssp, asp);
            }
        }
        else {
            auth['display_' + asp](ws, 'hp', ssp, asp);
        }
    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // pathing for wireless authentication
    w: function(ws, ssp, asp, uid) {
        if (!asp) { asp = 'main'; } // if no start is passed in, start at beginning
        if (!u.w.acc) { asp = 'main'; } // if no account selected, show main

        // apcp load auth
        if (u.w.auth == false) {
            if (u.w.zip && u.w.acc) {
                this.enticate(ws, 'w', ssp, asp, 'account_num', { acct: u.w.acc, zip: u.w.zip });
            }
            else {
                auth['display_' + asp](ws, 'w', ssp);
            }
        }
        else {
            auth['display_' + asp](ws, 'w', ssp);
        }
    },

    logout: function(auth_type) {
        // pass in hp, w or nothing for all
        if (u[auth_type]) {
            if (u[auth_type].lockedto) {
                // loggem both out
                auth_type = '';
            }
        }
        $.ajax({
            type: "POST",
            url: wsloc + "Logout",
            data: '{ "type": "' + auth_type + '" }',
            contentType: wsctype,
            dataType: "json",
            success:
                    function(r) {
                        if (r.rc == 911) { silo.timeOut('function auth.logout', this.url); }
                        else {
                            if (auth_type == 'h') { u.accs.hp = {}; u.hp = {}; } else if (auth_type == 'w') { u.accs.w = {}; u.w = {}; } else { u.accs.w = {}; u.accs.hp = {}; u.hp = {}, u.w = {}; }
                            page.apcp();
                            page.address();
                        }
                    },
            error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function auth.logout', this.url); }
        });

    },
    lockedto: function(theacc) {
        // locked to type is opposite of addr type
        if (theacc.type) {
            u[theacc.type].locked = theacc.lockedto ? theacc.lockedto : theacc.combinedto;
            if (u[theacc.type].locked != '') {
                if (theacc.type == 'hp' && u[theacc.type].locked) {
                    if (u.w.acc != u[theacc.type].locked) {
                        //u.w.auth = false,
                        u.w.zip = theacc.zip,
                        u.w.acc = u[theacc.type].locked;
                    }
                }
                else if (theacc.type == 'w' && u[theacc.type].locked) {
                    if (u.hp.acc != u[theacc.type].locked) {
                        u.hp.auth = false,
                        u.hp.zip = theacc.zip,
                        u.hp.acc = u[theacc.type].locked;
                    }
                }
            }
        }
    },




    i: function(tn, callback) {
        if (tn) {
            $.ajax({
                type: "POST",
                url: wsloc + "GetQualifications",
                data: '{"tn":"' + tn + '"}',
                contentType: wsctype,
                cache: false,
                dataType: "json",
                success:
                    function(r) {
                        if (r.rc == 911) { silo.timeOut('function auth.i', this.url); }
                        else {
                            if (!u.i) { u.i = {}; }
                               u.i.qual = r.qual.toString();
                            if (r.rc == '-100') { u.i.qual = "-4"; }
                            if (callback) { callback.call(); }
                        }
                    },
                error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function auth.i', this.url); }
            });
        } else { silo.fatal('ZT qual didnt work because getcustomerinfo isnt returning a qual attribute.'); }
    },
    get_addrs: function(callback) {
        $.ajax({
            type: "POST",
            url: wsloc + "GetCustomerInfo",
            data: bogus,
            contentType: wsctype,
            cache: false,
            dataType: "json",
            success:
                    function(r) {
                        if (r.rc == 911) { silo.timeOut('function auth.get_addrs', this.url); }
                        else {
                            u.get_addrs = r;
                            if (callback) { eval(callback); }
                        }
                    },
            error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function auth.get_addrs', this.url); }
        });
    },
    w_init: function(callback) {
        $.ajax({
            type: "POST",
            url: "clientservice/wireless.svc/InitializeWirelessSilo",
            data: bogus,
            contentType: wsctype,
            cache: false,
            dataType: "json",
            success:
                    function(r) {
                        if (r.rc == 911) { silo.timeOut('function auth.w_init', this.url); }
                        else if (r.rc != 0) { silo.fatal(r.rc, r.rc, 'function auth.w_init', this.url); }
                        else if (callback) { eval(callback); }
                    },
            error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function auth.w_init', this.url); }
        });
    },


    display_pick_auth: function() {
        page.title('Select Your Product And Login');
        var h = '\
        <div id="exlogin"><h1 class="green">Select Your Product</h1>\
            <p>Click the product below that you would wish to manage.</p>\
<ul>\
<li><b class="icon_name w">Wireless</b>\
<a href="#" onclick="silo.auth.start(\'w\',\'w\'); return false;"><img src="/shop/images/icon_w.png" class="icon" style="width: 73px; height: 107px;"/></a>\
<li><b class="icon_name hp">Home Phone</b>\
<a href="#" onclick="silo.auth.start(\'hp\',\'hp\'); return false;"><img src="/shop/images/icon_hp.png" class="icon" style="width: 73px; height: 107px;"/></a></li>\
<li><b class="icon_name i">Internet</b>\
<a href="#" onclick="silo.auth.start(\'i\',\'hp\'); return false;"><img src="/shop/images/icon_i.png" class="icon" style="width: 73px; height: 107px;"/></a></li>\
<li><b class="icon_name tv">Digital TV</b>\
<a href="#" onclick="silo.auth.start(\'tv\',\'hp\'); return false;"><img src="/shop/images/icon_tv.png" class="icon" style="width: 107px; height: 107px;"/></a></li>\
<li><b class="icon_name hs">Home Security</b>\
<a href="#" onclick="silo.auth.start(\'hs\',\'hp\'); return false;"><img src="/shop/images/icon_hs.png" class="icon" style="width: 73px; height: 107px;"/></a></li>\
</ul>\
</div>';

        $('#inner').html(h);
        page.title('Select Your Product');
        $('#status_w').css({ backgroundPosition: '0 -180px', display: '' });
        silo.inner.show();

    },


    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // display the main authentication modal

    display_main: function(ws, auth_type, ssp, asp, r) {

        silo.inner.wait();

        // form for account / bzip auth
        h = '<div id="a_left"></div><div id="a_right"></div>';
        silo.$_inner.html(h);
        this.display_hp_address_login(ws, auth_type, ssp, asp, r);
        this.display_hp_existing_login(ws, auth_type, ssp, asp, r);
        silo.inner.show();

    },

    display_hp_address_login: function(ws, auth_type, ssp, asp, r) {
        var h = ' ';
        if (auth_type == 'hp') {
            page.title('Login to Your Home Phone Account');

            // form for home phone address authentication
            var addrauth = 'auth.enticate(\'' + ws + '\',\'' + auth_type + '\',\'' + ssp + '\',\'' + asp + '\', \'address\'); return false;';
            h += '\
<div class="center"><img src="images/dot.gif" id="a_hp"></div>\
<h2>New Customers</h2>\
<p>Please enter the address where you would like service to determine what products are available at your home.</p>\
<form name="a_street_form" id="a_street_form" onsubmit="' + addrauth + '">\
<div class="a_form">\
<div id="a_d_snum">\
<label>Street Number:</label>\
<input type="text" size="4" name="street_num" id="street_num">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<div id="a_d_sname">\
<label>Street Name:</label>\
<input type="text" name="street_name" size="25" id="street_name">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<div id="a_d_addr2">\
<label>Apt / Suite:</label>\
<input type="text" name="address2" size="3" id="address2">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<div id="a_d_zip">\
<label>Zip Code:</label>\
<input type="text" name="zip" size="5" id="zip">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<br/>\
<a href="#" onclick="' + addrauth + '"><img src="/shop/images/check_address.png" class="b_check_address float_right"></a>\
<input type="submit" value="" style="position: absolute; top: -1000000px;">\
</form>\
<a href="#" onclick="silo.close(); return false;" class="b_cancel">Cancel</a>\
</div>';
        }


        if (auth_type == 'w') {
            page.title('Login to Your Wireless Account');
            var zipauth = 'auth.enticate(\'' + ws + '\',\'' + auth_type + '\',\'' + ssp + '\',\'' + asp + '\', \'zip\'); return false;';
            h += '\
<div class="center"><img src="images/a_w.png" id="a_w"></div>\
<h2>New Wireless Customer</h2>\
<p>If you don’t have wireless phone service from Cincinnati Bell, enter your zip code below.</p>\
<form name="a_zip_form" id="a_zip_form" onsubmit="' + zipauth + '">\
<div class="a_form">\
<div id="a_d_wzip">\
<label>Zip Code:</label>\
<input type="text" size="18" name="wzip" id="wzip">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<br/>\
<a href="#" onclick="' + zipauth + '">\
<img src="/shop/images/continue.png" class="b_continue  float_right"></a>\
<input type="submit" value="" style="position: absolute; top: -1000000px;">\
</form>\
<a href="#" onclick="silo.close(); return false;" class="b_cancel">Cancel</a>\
</div>'

        }

        $('#a_left').html(h);
    },


    display_hp_existing_login: function(ws, auth_type, ssp, asp, r) {
        var accnumauth = 'auth.enticate(\'' + ws + '\',\'' + auth_type + '\',\'' + ssp + '\',\'' + asp + '\', \'account_num\'); return false;';
        var myauth = 'auth.enticate(\'' + ws + '\',\'' + auth_type + '\',\'' + ssp + '\',\'' + asp + '\', \'my_account\'); return false;';
        var h = '<div class="center"><img src="images/' + ((auth_type == 'w') ? 'a_w_others.png" id="a_w_others"' : 'a_others.png" id="a_others"') + '></div>\
<h2>' + ((auth_type == 'hp') ? 'Existing Customers' : 'Existing Wireless Customers') + '</h2>\
<p>If you already have ' + ((auth_type == 'hp') ? 'home phone or Internet' : 'wireless') + ' service with Cincinnati Bell, please login with your My Account information or your account number and billing zip code.</p>\
<div id="a_my_acc">\
<a href="#" id="a_my_link" onclick="$(\'#a_acc\').slideUp(\'normal\',function(){$(\'#a_my_acc\').removeClass(\'active\'); $(\'#a_my\').slideDown(\'normal\');}); return false;">Login with My Account</a>\
<a href="#" id="a_acc_link" onclick="$(\'#a_my\').slideUp(\'normal\',function(){$(\'#a_my_acc\').addClass(\'active\'); $(\'#a_acc\').slideDown(\'normal\');}); return false;">Login with Account Number</a>\
</div>\
<div id="a_acc" class="a_form">\
<form onsubmit="' + accnumauth + '">\
<div id="a_d_acc_number">\
<label>Account Number:</label>\
<input type="text" size="40" name="acc_number" id="acc_number" onchange="$(\'#a_d_acc_number\').removeClass(\'a_factive\');" style="margin-bottom: 0;" tabindex="1">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
<div style="margin:5px 0 20px 110px;">\
<a href="#" onclick="message.show(\'/shop/mktg/accountnumber.html\',\'mktg\',true); return false;" style="font-size: 7pt; font-weight:normal;" tabindex="4">Where can I find my account number?</a></div>\
</div>\
<div id="a_d_bill_zip">\
<label>Billing Zip Code:</label>\
<input type="text" size="15" name="bill_zip" id="bill_zip" onchange="$(\'#a_d_bill_zip\').removeClass(\'a_factive\');" tabindex="2">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
<br class="clear" style="border: 0;margin:0;padding:0;"/>\
<div style="position:relative;"><small style="position: absolute; left: 110px; top: -12px;">(The Zip Code where your bill is sent)</small></div><br class="clear"/>\
</div><br class="clear"/>\
<a href="#" onclick="' + accnumauth + '"><img src="/shop/images/login.png" class="b_login float_right" tabindex="3"></a>\
<a href="#" onclick="silo.close(); return false;" class="b_cancel">Cancel</a>\
<input type="submit" value="" style="position: absolute; top: -1000000px;">\
</form>\
</div>\
<div id="a_my" class="a_form">\
<form onsubmit="' + myauth + '">\
<div id="a_d_email">\
<label>Email Address:</label>\
<input type="text" size="40" name="email" id="email" value="' + (readCookie('myaccountrememberusernameonly') || '') + '">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<div id="a_d_password">\
<label>Password:</label>\
<input type="password" size="40" name="password" id="password">\
<img src="/shop/images/arrow_orange.gif" class="a_arrow">\
</div>\
<div style="margin:0 0 20px 110px;">\
<a href="#" onclick="makewindow(\'https://my.cincinnatibell.com/SelfCare/UI/Root/Unauthenticated/ForgotPassword.aspx\',\'forgotPassword\',\'330\',\'320\',\'0\'); return false;" style="font-size: 8pt; font-weight:normal;">Forgot your password?</a>\
</div>\
<a href="#" onclick="' + myauth + '"><img src="/shop/images/login.png" class="b_login float_right"></a>\
<a href="#" onclick="silo.close(); return false;" class="b_cancel">Cancel</a>\
<input type="submit" value="" style="position: absolute; top: -1000000px;">\
</form>\
</div>';
        $('#a_right').html(h);
    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // display select multiple accounts modal

    display_multiple_accounts: function(ws, auth_type, ssp, asp, r) {
        page.title('Select Your My Account');
        var a = r.accts, checked;
        var h = '<h2>Select An Account</h2>\
    <p>Your My Account has multiple accounts. Select the account you would like to make updates to.</p>\
    <div id="a_addr_list">\
    <input type="hidden" name="myacct" id="myacct">\
    <input type="hidden" name="myzip" id="myzip">\
            <ul>';

        for (acc = 0; acc < a.length; acc++) {
            if (a[acc].type == auth_type || auth_type == 'w') {
                h += '<li onclick="$(\'#myaccounts_' + acc + '\').attr({checked: true}); $(\'#myacct\').val(\'' + a[acc].btacct + '\'); $(\'#myzip\').val(\'' + a[acc].zip + '\');">\
            <input type="radio" name="myaccounts" id="myaccounts_' + acc + '" value="' + a[acc].btacct + '"';
                if (acc == 0) { h += ' checked'; checked = acc; }
                h += '>' + formatAddress(a[acc]) + '</li>';
            }
        }

        h += '</ul></div>\
    <a href="#" onclick="var ma = $(\'#myacct\').val(); var mz = $(\'#myzip\').val(); auth.enticate(\'' + ws + '\', \'' + auth_type + '\', \'' + ssp + '\', \'' + asp + '\', \'account_num\', {\'acct\': ma, \'zip\':mz}); return false;"><img src="/shop/images/continue.png" width="107" height="34" class="b_continue float_right"></a>\
    <a href="#" onclick="silo.close(); return false;" class="b_cancel">Cancel</a>';
        silo.$_inner.html('<div id="a_left"></div><div id="a_right"></div>');
        $('#a_right').html(h);
        silo.inner.show();
        this.show('right');
        this.display_authed_left(ws, auth_type, ssp, asp, r);
        $('#myacct').val(a[checked].btacct);
        $('#myzip').val(a[checked].zip);

    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // display select multiple TN modal

    display_multiple_tns: function(ws, auth_type, ssp, asp, r) {
        page.title('Select Your Phone Number To Update');
        if (!r) {
            r = {
                "acct": u.accs[auth_type][u[auth_type].acc]
            }
        }

        var a = r.acct, lh = [];
        var h = '<h2>Select A Phone Number</h2>\
    <p>Your account has multiple phone numbers. Select the one you would like to make updates to.</p>\
    <div class="center bold">' + formatAddress(a) + '</div><br clear="both"/><br/>\
    <div class="yellow_box center bold">\
    <select name="hp_tns" id="hp_tns">';


        for (var tn = 0; tn < a.hptns.length; tn++) {
            lh[lh.length] = '<option value="' + a.hptns[tn] + '">' + formatPhone(a.hptns[tn]) + '</option>';
        }


        h += lh.join('') + '</select>\
    </div><br/>\
    <a href="#" onclick="auth.enticate(\'' + ws + '\', \'' + auth_type + '\', \'' + ssp + '\', \'' + asp + '\', \'tn\'); return false;"><img src="/shop/images/continue.png" width="107" height="34" class="b_continue float_right"></a>\
    <a href="#" onclick="silo.close(); return false;" class="b_cancel">Cancel</a>';
        silo.$_inner.html('<div id="a_left"></div><div id="a_right"></div>');
        $('#a_right').html(h);
        silo.inner.show();
        this.show('right');
        this.display_authed_left(ws, auth_type, ssp, asp, r);

    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // display left my/acc authenticated 

    display_authed_left: function(ws, auth_type, ssp, asp, r) {
        var h = '<div class="center"><img src="images/' + ((auth_type == 'w') ? 'a_w_others.png" id="a_w_others_sm"' : 'a_others.png" id="a_others_sm"') + '></div>\
    <h2>' + ((auth_type == 'hp') ? 'Existing Home Phone Customer' : 'Existing Wireless Customer') + '</h2>\
        <p>You have logged in successfully.</p>';
        $('#a_left').html(h);
        this.show('left');
    },


    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // set the account / tn selection

    show: function(side) {
        var blop = {
            display: 'block'
        }
        if (opac_low.opacity) { blop.opacity = opac_low.opacity; }
        $('#a_' + side).css(blop).animate(opac_high, 700);
    },
    hide: function(side) {
        $('#a_' + side).css({ display: 'none' });
    },
    wait: function(side) {
        this.hide(side);
        $('#a_' + side).html('<div class="spinner"><img src="images/spinner.gif"><span id="main_spinner_msg" class="spinner_msg"></span></div>');
        silo.wait_msg('main_spinner_msg');
        this.show(side);
    },



    ////////////////////////////////////////////////////////////////////////////////////////////////////
    // does the actual authenitcation calls

    enticate: function(ws, auth_type, ssp, asp, auth_with, param_vals) {

        // clear all active form fields
        if (this.form_fields[auth_with]) {
            for (var f = 0; f < this.form_fields[auth_with].length; f++) {
                $('#' + this.form_fields[auth_with][f]).removeClass("a_factive");
            }
        }
        var request;

        if (auth_with == 'address') {

            var stnum = $('#street_num').val().replace(/([^0-9])/g, ""),
                strname = $('#street_name').val(),
                straddr2 = $('#address2').val(),
                stzip = $('#zip').val().replace(/([^0-9])/g, "");

            $('#street_num').val(stnum);
            $('#zip').val(stzip);



            if (stnum == '') { message.show('Please enter a street number.'); }
            else if (strname == '') { message.show('Please enter a street name.'); }
            //  else if (stzip == '') { message.show('Please enter a 5 digit zip code.'); } // if we wanna require zip code
            else {
                if (u[ws]) { for (cat = 0; cat < p.siloCategories[ws].length; cat++) { delete u[ws][p.siloCategories[ws][cat]]; } } // clear out user data for working silo
                request = {
                    "url": wsloc + "ValidateHomeAddress",
                    "params": {
                        "hnum": stnum,
                        "street": strname,
                        "locNbr": straddr2,
                        "zip": stzip
                    },
                    "side": 'right'
                }
                this.wait('right');
            }
        }
        else if (auth_with == 'account_num') {

            var stacc = (param_vals ? param_vals.acct : $("#acc_number").val()).replace(/([^0-9])/g, ""),
                stbzip = (param_vals ? param_vals.zip : $("#bill_zip").val()).replace(/([^0-9])/g, "");

            if ($("#acc_number").val()) { $("#acc_number").val(stacc); }
            if ($("#bill_zip").val()) { $("#bill_zip").val(stbzip); }


            if (stacc == '') { message.show('Please enter your account number.'); }
            else if (stbzip == '') { message.show('Please enter your billing zip code.'); }
            else {

                if (u[ws]) { for (cat = 0; cat < p.siloCategories[ws].length; cat++) { delete u[ws][p.siloCategories[ws][cat]]; } } // clear out user data for working silo
                request = {
                    "url": wsloc + "ValidateAccount",
                    "params": {
                        "acct": param_vals ? param_vals.acct : $("#acc_number").val(),
                        "zip": param_vals ? param_vals.zip : $("#bill_zip").val(),
                        "valtype": (ws == 'i' ? 'i' : auth_type)
                    },
                    "side": 'left'
                }

                silo.inner.wait();
            }
        }
        else if (auth_with == 'my_account') {

            var vemail = val_email($("#email").val()),
            vpass = $("#password").val();

            if (vemail == '') { message.show('Please enter a valid My Account Email Address.'); }
            else if (vpass == '') { message.show('Please enter your My Account Password.'); }
            else {
                request = {
                    "url": wsloc + "GetMyUserAccounts",
                    "params": {
                        "uid": vemail,
                        "pwd": vpass,
                        "valtype": auth_type
                    },
                    "side": 'left'
                }
                silo.inner.wait();
            }
        }
        else if (auth_with == 'tn') {
            request = {
                "url": wsloc + "SetHomePhoneLineNumber",
                "params": {
                    "ln": param_vals ? param_vals.tn : $("#hp_tns").val()
                },
                "side": 'left'
            };
            silo.inner.wait();
        }
        else if (auth_with == 'zip') {
            var lzip = param_vals ? param_vals.wzip : $("#wzip").val();
            request = {
                "url": wsloc + "CbwInTerritoryCheck",
                "params": {
                    "zip": lzip.replace(/[^\d]/g, '') // removeos nondigitos
                },
                "side": 'left'
            };

            if (request.params.zip.length < 5) { message.show('Please enter a 5 digit zip code'); $("#wzip").val(''); return; }
            silo.inner.wait();
        }
        if (request) {
            $.ajax({
                type: "POST",
                url: request.url,
                data: $.toJSON(request.params),
                contentType: wsctype,
                dataType: "json",
                success:
                    function(r) {
                        if (r.rc == 911) { silo.timeOut('function auth.enticate', this.url); }
                        else {
                            r.nrc = r.rc.toString();
                            if (auth['rc' + r.nrc]) { auth['rc' + r.nrc](ws, auth_type, ssp, asp, r); }
                            else { auth['rcall_' + auth_with](ws, auth_type, ssp, asp, r); }
                        }
                    },
                error: function(e, ts, et) { silo.fatal(e.responseText, e.status + ' ' + e.statusText, 'function auth.enticate', this.url); }
            });
        }
    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // RC Code Functions
    ////////////////////////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////////////////////     
    // the recycle button
    button_recycle: function(ws, auth_type, ssp, asp, r) {
        return '<div id="a_login_with_my"><img src="/shop/images/icon_recycle.gif" class="icon_recycle"><a href="#" onclick="auth.display_hp_existing_login(\'' + ws + '\', \'' + auth_type + '\', \'' + ssp + '\', \'' + asp + '\'); return false;">Login with My Account or Account Number</a></div>';
    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // 0 = success, there should be an "acct" to grab

    rc0: function(ws, auth_type, ssp, asp, r) {

        //if hp and already zt qual, del zt qual val
        if (auth_type == 'hp') { if (u.i.qual) { delete u.i.qual; } }


        if ((typeof r) == 'string') { r = $.parseJSON(r); }

        // multiple accounts were returned
        if (r.accts) {
            r.hpcount = 0, r.wcount = 0, r.hpids = [], r.wids = [], r.hpzips = [], r.wzips = [];
            for (var acc = 0, ACC = r.accts.length; acc < ACC; acc++) {
                r[r.accts[acc].type + 'count']++;
                r[r.accts[acc].type + 'ids'].push(r.accts[acc].btacct);
                r[r.accts[acc].type + 'zips'].push(r.accts[acc].zip);
            }
            // NO accounts returned matching that auth_type (hp or w)
            //if (r[auth_type + 'count'] == 0) { alert('this account has no ' + auth_type + ' accounts'); }
            // only ONE account returned matching that auth_type (hp or w) and is home phone
            if (r.accts.length == 1) {
                (ws == 'hp') ? auth.enticate(ws, auth_type, ssp, asp, 'account_num', { "acct": r.accts[0].btacct, "zip": r.accts[0].zip }) : this.display_multiple_accounts(ws, auth_type, ssp, asp, r);
            }
            // MULTIPLE accounts returned matching that auth_type (hp or w) so gotta pick one
            else {
                this.display_multiple_accounts(ws, auth_type, ssp, asp, r);
            }
        }

        else if (r.tn) {
            u[auth_type].auth = true;
            u[auth_type].tn = r.tn;
            u[auth_type].zip = r.zip;
            // if hp authing then qual internet
            if (auth_type == 'hp') { if (ws != 'i') { auth.i(u[auth_type].tn); } }
            //page.address(ws, auth_type);
            auth.get_addrs('u.load_addrs(\'\',true)');
            page.setExisting();
            page.apcp(function() { silo[ws].start(ssp); });
        }

        // authing via zip code
        else if (r.inTerritory) {
            u[auth_type].auth = true;
            u[auth_type].zip = r.zip;
            //page.address(ws, auth_type);
            auth.get_addrs('u.load_addrs(\'\',true)');
            page.apcp(function() { silo[ws].start(ssp); });
        }

        // 1 my account
        // happens for both w and hp
        else {

            u[auth_type].acc = r.acct.btacct;
            u[auth_type].tns = r.acct[auth_type + 'tns'];
            u[auth_type].zip = r.acct.zip;

            if (r.acct.isnew) { u.accs[auth_type]['N'] = r.acct; }
            else { u.accs[auth_type][r.acct.btacct] = r.acct; }


            // lock account check
            auth.lockedto(r.acct);

            if (r.acct.hptns == null) { r.acct.hptns = []; }

            if (r.acct.hptns.length > 1) {
                this.display_multiple_tns(ws, auth_type, ssp, asp, r);
            }
            // wireless
            else if (auth_type == 'w') {

                if (r.acct.wtns.length == 0) {
                    this.enticate(ws, auth_type, ssp, asp, 'zip', { "wzip": r.acct.zip });
                }
                else {
                    u[auth_type].auth = true;

                    u[auth_type].zip = r.acct.zip;
                    //page.address(ws, auth_type);
                    auth.get_addrs('u.load_addrs(\'\',true)');

                    page.setExisting();
                    page.apcp(function() { silo[ws].start(ssp); });


                }
            }
            // hp only
            else {
                if (r.acct.isnew) {
                    u[auth_type].auth = true;

                    if (r.qual.toString()) { if (r.qual.toString() != -3) { u.i.qual = r.qual.toString(); } }
                    // if hp authing then qual internet
                    // if (auth_type == 'hp') { if (ws != 'i') { auth.i(u[auth_type].tn); } }
                    //page.address(ws, auth_type);
                    auth.get_addrs('u.load_addrs(\'\',true)');
                    page.apcp(function() { silo[ws].start(ssp); });

                }
                else {
                    this.enticate(ws, auth_type, ssp, asp, 'tn', { "tn": r.acct.hptns[0] });
                }
            }
        }
    },


    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // 1500 = (Partial Street Match). show emsg_disp and list of "streets". user chooses and retry.
    // MAPLE, PINEBLUFF or WILDFLOWER as address

    rc1500: function(ws, auth_type, ssp, asp, r) {
        var h = '<h2>Address Results</h2>\
            <p>' + r.emsg_disp + '</p>\
            <div id="a_addr_list">\
            <ul>';

        for (s = 0; s < r.streets.length; s++) {
            h += '<li onclick="$(\'#street100_' + s + '\').attr({checked: true});\
                $(\'#street_name\').val(\'' + r.streets[s].street + '\'); $(\'#zip\').val(\'' + r.streets[s].zip + '\');">\
                <input type="radio" name="street100" id="street100_' + s + '"';
            if (s == 0) { h += ' checked'; $('#street_name').val(r.streets[s].street); $('#zip').val(r.streets[s].zip); }
            h += '><span class="a_addr_street">' + r.streets[s].street + '</span><br/><span class="a_addr_zip">' + r.streets[s].zip + '</span></li>';
        }
        h += '</ul></div><a href="#" onclick="auth.enticate(\'' + ws + '\',\'' + auth_type + '\',\'' + ssp + '\',\'' + asp + '\', \'address\'); return false;"><img src="/shop/images/select_add_cont.png" class="b_select_add_cont float_right"></a>';
        $('#a_right').html(h + this.button_recycle(ws, auth_type, ssp, asp, r));
        this.show('right');
    },
    rc1510: function(ws, auth_type, ssp, asp, r) { this.rc1520(ws, auth_type, ssp, asp, r); },


    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // 1520 = (All except house number match). show emsg_disp and set focus to house number field

    rc1520: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        $('#a_d_snum').addClass("a_factive");
        $('#a_right').html(this.button_recycle(ws, auth_type, ssp, asp, r));
        this.show('right');
    },

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // 1530 = (Multiple locations match). If apt/suite not entered, force them to and resubmit. If entered, 

    rc1530: function(ws, auth_type, ssp, asp, r) {
        var h = '<h2>Address Results</h2>\
            <p>' + r.emsg_disp + '</p>\
            <div id="a_addr_list">\
            <ul>';

        for (l = 0; l < r.locs.length; l++) {
            h += '<li onclick="$(\'#loc300_' + l + '\').attr({checked: true});\
                $(\'#address2\').val(\'' + r.locs[l].loctype + ' ' + r.locs[l].locnbr + '\');">\
                <input type="radio" name="loc300" id="loc300_' + l + '"';
            if (l == 0) { h += ' checked'; $('#address2').val(r.locs[l].loctype + ' ' + r.locs[l].locnbr); }
            h += '><span class="a_addr_street">' + r.locs[l].loctype + '</span><br/><span class="a_addr_zip">' + r.locs[l].locnbr + '</span></li>';
        }
        h += '</ul></div><a href="#" onclick="auth.enticate(\'' + ws + '\',\'' + auth_type + '\',\'' + ssp + '\',\'' + asp + '\', \'address\'); return false;"><img src="/shop/images/select_add_cont.png" class="b_select_add_cont float_right"></a>';
        $('#a_right').html(h + this.button_recycle(ws, auth_type, ssp, asp, r));
        this.show('right');


    },
    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    // 1540 = (Multiple locations match, no apt/suite number passed in).  Need to tell customer
    //       to enter an apt/suite number.
    rc1540: function(ws, auth_type, ssp, asp, r) {
        $('#a_d_addr2').addClass("a_factive");
        this.rc_generic(ws, auth_type, ssp, asp, r);
    },
    // 1550 = Found, but it's a business address. Can't do biz online.
    rc1550: function(ws, auth_type, ssp, asp, r) { this.rc_generic(ws, auth_type, ssp, asp, r); },
    // 1560 = Found, but it's a Dayton Address. Can't do Dayton online.
    rc1560: function(ws, auth_type, ssp, asp, r) { this.rc_generic(ws, auth_type, ssp, asp, r); },
    // 1570 = Found, but it's out of territory somewhere. Can't do it online.
    rc1570: function(ws, auth_type, ssp, asp, r) { this.rc_generic(ws, auth_type, ssp, asp, r); },
    // 1580 = Found, buit it's a Lebanon address. Can't do Leb here.
    rc1580: function(ws, auth_type, ssp, asp, r) { this.rc_generic(ws, auth_type, ssp, asp, r); },
    //
    rc_generic: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        $('#a_right').html(this.button_recycle(ws, auth_type, ssp, asp, r));
        this.show('right');
    },

    // 1590 = Found, but WIP.. there's working service at the address. Need to warn before continuing.
    rc1590: function(ws, auth_type, ssp, asp, r) {
        var a = r.acct;
        var h = '<h2>Address Results</h2>\
    <p>There is currently working service at this address.</p>\
    <div class="yellow_box center bold" style="overflow: auto; padding-bottom: 2px;">\
    ' + formatAddress(a) + '<br class="clear" />&nbsp;</div>\
    <p>' + r.emsg_disp + '</p>\
    <p>If this is your address and you would like to make changes to your account, <a href="#" onclick="auth.display_hp_existing_login(\'' + ws + '\', \'' + auth_type + '\', \'' + ssp + '\', \'' + asp + '\', \'' + r + '\'); return false;">click here to login to your account</a>.</p>\
    <p>To continue with this address click <b>Select Address &amp; Continue</b> below.</p><br>\
    <input type="hidden" name="rc0data" id="rc0data" value="">\
    <a href="#" onclick="var rc0data = $(\'#rc0data\').val(); auth.rc0(\'' + ws + '\', \'' + auth_type + '\', \'' + ssp + '\', \'' + asp + '\',rc0data); return false;"><img src="/shop/images/select_add_cont.png" class="b_select_add_cont float_right"></a>';
        $('#a_right').html(h + this.button_recycle(ws, auth_type, ssp, asp, r));
        $('#rc0data').val($.toJSON(r));
        this.show('right');
    },
    // 1600 = Found, but has order activity preventing them from ordering online.
    rc1600: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        var h = '<h2>Address Results</h2>\
        <p>' + r.emsg_disp + '</p>';
        $('#a_right').html(h + this.button_recycle(ws, auth_type, ssp, asp, r));
        this.show('right');
    },

    // 1610 = Address not found
    rc1610: function(ws, auth_type, ssp, asp, r) { this.rc_generic(ws, auth_type, ssp, asp, r); },

    // all else = something bad happened

    rcall_address: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        $('#a_right').html(this.display_hp_existing_login(ws, auth_type, ssp, asp, r));
        this.show('right');
    },

    rcall_tn: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        this.display_main(ws, auth_type, ssp, asp, r);
        silo.inner.show();
    },

    // all else = something bad happened
    rcall_account_num: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        this.display_main(ws, auth_type, ssp, asp, r);
        silo.inner.show();
        $('#a_acc').css({ display: 'block' });
        $('#a_my').css({ display: 'none' });
        $('#a_my_acc').addClass('active');
        $('#a_d_acc_number').addClass("a_factive");
        $('#a_d_bill_zip').addClass("a_factive");
    },

    // all else = something bad happened
    rcall_my_account: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        this.display_main(ws, auth_type, ssp, asp, r);
        silo.inner.show();
        $('#a_d_email').addClass("a_factive");
        $('#a_d_password').addClass("a_factive");
    },

    // all else = invalid zip for w auth
    rcall_zip: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        this.display_main(ws, auth_type, ssp, asp, r);
        silo.inner.show();
        $('#a_d_wzip').addClass("a_factive");
    },
    ////////////////////////////////////////////////////////////////////////////////////////////////////  
    //1235 - Invalid account and zip code combination. missing zippity doo
    rc1235: function(ws, auth_type, ssp, asp, r) {
        message.show(r.emsg_disp);
        this.display_main(ws, auth_type, ssp, asp, r);
        silo.inner.show();
        $('#a_acc').css({ display: 'block' });
        $('#a_my').css({ display: 'none' });
        $('#a_my_acc').addClass('active');
        $('#a_d_bill_zip').addClass("a_factive");

    }
}

window.onerror = function(msg, url, line) {
page.log('',['Failure', msg, url + ' line:' + line, 'global js error']);
};


