﻿function OmnitureAccountID() {
    var omnitureAccountID = "brighthousesupport";
    var omnitureAccountIDdev = "brighthousesupportdev";
    if (location.host.lastIndexOf(".com") == location.host.lastIndexOf("."))
        return omnitureAccountID;
    else
        return omnitureAccountIDdev;
}

function LogLink($link) {
    if ($link != null) {
        var url = $link.attr("href");
        $.ajax({
            type: "POST",
            url: "/Log/Link/",
            data: "url=" + url,
            cache: false,
            async: false
        });
    }
}
function SelectNav(nav) {
    var index = 0;
    switch (nav.toLowerCase()) {
        case "account-and-billing":
            index = 0;
            break;
        case "television":
            index = 1;
            break;
        case "high-speed-internet":
            index = 2;
            break;
        case "home-phone":
            index = 3;
            break;
    }
    $subNavLiList = $("#sub-nav > ul > li");
    if ($subNavLiList.length > index) {
        $subNavLiList.eq(index).addClass("selected");
    }
    
}

$(document).ready(function() {

    //after localizing the user is returned to their current page
    $("input[name=desturl]").val(location.href);


    var defaultSearchText = "Search Support and Resources";
    var secondarySearchText = "SEARCH SUPPORT";
    $("#txtSearch").focus(function() {
        if ($(this).val() == defaultSearchText || $(this).val() == secondarySearchText)
            $(this).val("");
    });
    $("#btSearch").click(function() {
        var search = jQuery.trim($("#txtSearch").val());
        if (search != null && search != "" && search != defaultSearchText)
            top.location = "/Search/?s=" + $.URLEncode($("#txtSearch").val());
    });
    $("#txtSearch").keyup(function(e) {
        if (e.keyCode == 13)
            $("#btSearch").click();
    });

    $(".taxonomy-switch a").click(function() {
        $(this).hide();
        if ($(this).hasClass("blue-more")) {
            $(this).parent().find(".blue-less").show();
            $(this).parent().parent().find(".hidden").show();
        }
        else {
            $(this).parent().find(".blue-more").show();
            $(this).parent().parent().find(".hidden").hide();
        }
        return false;
    });

    $(".Print-Link").click(function() {
        print();
        return false;
    });

    $("#search_suggestion_link").click(function() {
        $("#search_feedback").show('slow');
        $(this).hide();
        return false;
    });

    $("#btSearchFeedback").click(function() {
        var form = $("#formFeedback");
        var action = form.attr("action");
        var formSerialized = form.serialize();
        $.post(action, formSerialized,
                function() {
                    $("#search_feedback").html("Thank you for your feedback.");
                }
            );
    });

    $("#category_suggestion_link").click(function() {
        $("#category_feedback").show('slow');
        $(this).hide();
        return false;
    });

    $("#btCategoryFeedback").click(function() {
        var form = $("#formFeedback");
        var action = form.attr("action");
        var formSerialized = form.serialize();
        $.post(action, formSerialized,
        function() {
            $("#category_feedback").html("Thank you for your feedback.");
        });
    });

    $(document).keydown(function(e) {
        if (e.which == 113) {
            Overlay.load("/Article/GetByID_AJAX/Seriously/", {
                cssclass: 'modal-alt transition',
                filter: '.modal-container',
                unloadOnHide: true,
                modal: true,
                title: ' ',
                closeText: ' ',
                afterShow: function() {
                    $("#txtID").select();
                    $("#btFindArticle").click(function() {
                        top.location = "/Article/GetByID/" + $("#txtID").val() + "/";
                    });
                    $("#txtID").keyup(function(e) {
                        if (e.keyCode == 13)
                            $("#btFindArticle").click();
                    });
                }
            });
        }
    });

    $(".rating_star").click(function() {
        var rating = $(this).attr("rating");
        $("#litRating").html(rating);
        $("#hfRating").val(rating);
        $("#hfRatingFeedback").val(rating);
        var form = $("#formRating");
        var action = form.attr("action");
        var formSerialized = form.serialize();
        $.post(action, formSerialized,
                function() {
                    if (rating <= 3) {
                        $("#article_rating").toggle('slow');
                        $("#article_feedback").toggle('slow');
                    }
                    else
                        $("#article_rating").html("Thank you for your feedback.");
                }
            );
    });

        
    $("#btFeedbackEmail").click(function() {
        var form = $("#formFeedbackEmail");
        var action = form.attr("action");
        var formSerialized = form.serialize();
        $.post(action, formSerialized,
                function() {
                    $("#article_feedback").show('slow');  
                    $("#article_feedback_email").hide('slow');                  
                    $("#article_feedback").html("Thank you for your feedback.");
                }
            );
    });
    $("#btFeedback").click(function() {
        var form = $("#formFeedback");
        var action = form.attr("action");
        var formSerialized = form.serialize();
        $.post(action, formSerialized,
                function() {
                    $("#article_feedback").hide('slow');
                    $("#article_feedback_email").show('slow');
                }
            );
    });    
    
    $("#star_container").hover(
        function() {
            $("#star_description").toggle();
            $("#star_description_hover").toggle();
        },
        function() {
            $("#star_description").toggle()
            $("#star_description_hover").toggle().text("");
        }
    );

    $(".rating_star").hover(
        function() {
            $(this).attr("src", "/Content/img/star.gif");
            var rating = $(this).attr("rating");
            $("#star_description_hover").text($(this).attr("alt"));
            for (i = 0; i < rating; i++) {
                $(".rating_star[rating='" + i + "']").attr("src", "/Content/img/star.gif");
            }
        },
        function() {
            $(".rating_star").attr("src", "/Content/img/empty_star.gif");
        }
    );

    $("#Answer-DVR-Yes").click(function() {
        $(".customize-question").hide();
        $("#DVR-List").show("slow");
        $.scrollTo($(".question-box"));
    });


    $("#Answer-DVR-No").click(function() {
        $(".customize-question").hide();
        $("#Converter-List").show("slow");
        $.scrollTo($(".question-box"));
    });
    $(".Answer-DVR-Back").click(function() {
        $("#Converter-Error").hide();
        $("#DVR-List").hide();
        $("#Converter-List").hide();
        $(".customize-question").show("slow");
        $.scrollTo($(".customize-question"));
        $("input[name=equipment]:checked").attr("checked", false);
    });

    $("#Equipment-Select").submit(function() {
        if ($("input[name=equipment]:checked").size() < 1) {
            $error = $("#Converter-Error");
            $error.show("slow");
            $.scrollTo($error);
            return false;
        }
        return true;
    });

    $(".back").click(function() {
        history.back();
        return false;
    });

    $("label > img").click(function() {
        var id = $(this).parent().attr("for");
        $("#" + id).select().attr("checked", "checked");
        $(this).parents("form").submit();
    });

    $('a.help').tooltip();

    $('a[href*=".jpg"],a[href*=".png"],a[href*=".gif"]').lightbox();
});
