lbi_scratch = window.lbi_scratch || {};
lbi_scratch.cookie_monster = {
    create: function (c, d, e) {
        if (e) {
            var b = new Date();
            b.setTime(b.getTime() + (e * 24 * 60 * 60 * 1000));
            var a = "; expires=" + b.toGMTString()
        } else {
            var a = ""
        }
        document.cookie = c + "=" + d + a + "; path=/"
    },
    read: function (b) {
        var e = b + "=";
        var a = document.cookie.split(";");
        for (var d = 0; d < a.length; d++) {
            var f = a[d];
            while (f.charAt(0) == " ") {
                f = f.substring(1, f.length)
            }
            if (f.indexOf(e) == 0) {
                return f.substring(e.length, f.length)
            }
        }
        return null
    },
    erase: function (a) {
        lbi_scratch.cookie_monster.create(a, "", -1)
    }
};
$(function () {
    lbi_scratch.check_again = {
        $curr_number: $(".curr_number"),
        reset_text: "Start by checking your line",
        container_class: "productSupportPanelC",
        init: function () {
            lbi_scratch.check_again.$curr_number.each(function () {
                var c = $(this);
                var f = c.parents("." + lbi_scratch.check_again.container_class);
                var a = f.find("h2");
                var e = c.siblings(".new_number");
                var b = e.find(".link_text");
                var d = c.find(".num");
                e.hide();
                d.after('<a href="#" class="re_check">' + b.text() + "</a>");
                c.find(".re_check").click(function () {
                    c.hide();
                    e.show();
                    a.text(lbi_scratch.check_again.reset_text);
                    return false
                })
            })
        }
    };
    lbi_scratch.highlight_col = {
        $cols: $(".col"),
        init: function () {
            lbi_scratch.highlight_col.$cols.each(function () {
                var a = $(this);
                a.find(".radio input").click(function () {
                    lbi_scratch.highlight_col.highlight($(this))
                }).end().find(".radio label").click(function () {
                    lbi_scratch.highlight_col.highlight($(this))
                })
            })
        },
        highlight: function (a) {
            lbi_scratch.highlight_col.$cols.removeClass("selected");
            a.parents(".col").addClass("selected")
        }
    };
    lbi_scratch.lightboxLink = {
        $trigger: $(".hasLbLink"),
        init: function () {
            lbi_scratch.lightboxLink.$trigger.each(function () {
                var b = $(this);
                var a = b.siblings("#lb_content1");
                a.hide();
                b.append('<a class="thickbox price_info" href="#TB_inline?height=276&width=580&inlineId=lb_content1"> Pricing information</a>');
                tb_init("a.price_info")
            })
        }
    };
    lbi_scratch.toggle_price = {
        $inputs_container: $(".prices"),
        $price_containers: $(".costOrder"),
        display_class: "shown",
        init: function () {
            lbi_scratch.toggle_price.$inputs_container.each(function () {
                var a = $(this);
                a.find("input").click(function () {
                    lbi_scratch.toggle_price.display_price($(this).attr("id"))
                })
            })
        },
        display_price: function (a) {
            lbi_scratch.toggle_price.$price_containers.find("p").removeClass(lbi_scratch.toggle_price.display_class);
            lbi_scratch.toggle_price.$price_containers.find("." + a).addClass(lbi_scratch.toggle_price.display_class)
        }
    };
    lbi_scratch.mac_create_select = {
        $data_source: $("#mac_codes"),
        $container: $("#get_code"),
        $message: "fail",
        check_name: "selectIsp",
        order_url: "/secure/broadband/line-check/",
        linechecked_order_url: "/secure/broadband/config/",
        threeway_call_url: "/switch-broadband-to-bt/3waycall",
        init: function () {
            var a = "<label class='hidden' for='" + lbi_scratch.mac_create_select.check_name + "'>Select your current supplier</label>";
            a += "<select id='" + lbi_scratch.mac_create_select.check_name + "'><option>Select provider</option>";
            lbi_scratch.mac_create_select.$data_source.find("tbody tr").each(function () {
                var g = $(this);
                var e = g.find("th").text();
                var h = e.replace(/ /, "_").toLowerCase();
                var d = g.find("td:first").text();
                var c = h + "_tel";
                var b = g.find("td:last").html();
                var f = h + "_url";
                a += "<option value='" + h + "'>" + e + "</option>";
                lbi_scratch.mac_create_select.$container.data(c, d);
                lbi_scratch.mac_create_select.$container.data(f, b)
            });
            a += "</select>";
            lbi_scratch.mac_create_select.$data_source.hide();
            lbi_scratch.mac_create_select.$container.append(a);
            lbi_scratch.mac_create_select.assign_functionality()
        },
        assign_functionality: function () {
            var a = $("#" + lbi_scratch.mac_create_select.check_name);
            a.change(function () {
                var d = $(this);
                var e = d.val();
                var c = e + "_tel";
                data_tel_name = lbi_scratch.mac_create_select.$container.data(c);
                var b = e + "_url";
                data_url_name = lbi_scratch.mac_create_select.$container.data(b);
                lbi_scratch.mac_create_select.display_message(data_tel_name, data_url_name)
            })
        },
        display_message: function (c, b) {
            if (c != undefined) {
                $(".mac_message").show()
            } else {
                $(".mac_message").hide()
            }
            var a = "<strong>Call them on <span class='tel'></span></strong> or <span class='switch'></span> we'll talk to them with you on a <a href='/broadband-and-internet/internet-access/broadband/switch-broadband-to-bt/3waycall'>3 way call</a>";
            if (lbi_scratch.mac_create_select.$message === "fail") {
                lbi_scratch.mac_create_select.$container.after("<div class='mac_message'><p>" + a + "</p></div>");
                lbi_scratch.mac_create_select.$message = $(".mac_message p");
                if ($("body#broadband-switch-broadband-to-bt").length != 0) {
                    if (lbi_scratch.cookie_monster.read("linecheck_number")) {
                        lbi_scratch.mac_create_select.$message.after("")
                    } else {
                        lbi_scratch.mac_create_select.$message.after("")
                    }
                }
            } else {
                lbi_scratch.mac_create_select.$message.html(a)
            }
            $(".mac_message").find(".tel").text(c);
            if (b != "") {
                $(".mac_message").find(".switch").html(b + " or ")
            } else {
                $(".mac_message").find(".switch").html(b)
            }
        }
    };
    lbi_scratch.init_switcher_page = {
        init: function () {
            $("#broadband-switch-to-bt h4").each(function () {
                var b = $(this);
                var a = b.attr("class");
                b.before('<input type="radio" name="show_switch" class="radio" id=' + a + " />");
                b.wrap("<label for=" + a + "></label>");
                b.parent().parent().find(".radio").click(function () {
                    $(".switcher_display").removeClass("switcher_display");
                    $(this).parent().addClass("switcher_display")
                })
            })
        }
    };
    lbi_scratch.linecheck_form = {
        init: function () {
            $(".PE_cookie_linecheck #btnSubmit").click(function () {
                if (readCookie("linecheck_number")) {
                    eraseCookie("linecheck_number")
                }
                var a = $(".PE_cookie_linecheck #phone").val();
                createCookie("linecheck_number", a, 28)
            })
        }
    };
    lbi_scratch.check_again.init();
    lbi_scratch.highlight_col.init();
    lbi_scratch.lightboxLink.init();
    lbi_scratch.toggle_price.init();
    lbi_scratch.mac_create_select.init();
    lbi_scratch.init_switcher_page.init();
    lbi_scratch.linecheck_form.init()
});
