﻿$(document).ready(function() {

    $("#header #HeaderMyBlackAndDecker #SignupLinks .notLoggedInWishList").click(
                    function() {
                        loginPrompt();
                    });

    //The following is the javascript for the navigation dropdowns
    $("#mainNavigation .topLevelDropdown").hover(
                function() {
                    $(this).children(".hasResults").show();

                },
                function() {
                    $(this).children(".hasResults").hide();
                }
                );

    //The following is the javascript for the footer Country Picker
    $(".CountryPicker").hover(
                function() {
                    $(".CountryPicker .CountryPickerList").show();
                },
                function() {
                    $(".CountryPicker .CountryPickerList").hide();
                }
                );

    //The following is the javascript to display the login form
    $("#headerLoginNavigationContainer").hover(
                function() {
                    $("#myBlackAndDeckerLoginForm").show();
                    $("#header #headerLoginNavigation").css("background-position", "-592px -36px");

                },
                function() {
                    $("#header #headerLoginNavigation").css("background-position", "-592px 0")
                }
     );


    //The following is to handle the text inputs in the login form in the header
    clearTextBoxesLabel("#myBlackAndDeckerLoginFormContainer #txtEmail");
    clearTextBoxesLabel("#myBlackAndDeckerLoginFormContainer #txtPassword");


    clearTextBoxesLabel("#FooterMyBlackAndDecker #txtEmailFooter");
    clearTextBoxesLabel("#FooterMyBlackAndDecker #txtPasswordFooter");

    //The following is the functionality for the "Forgot Password" Overlay
    createOverlay("#forgotPasswordOverlayContainer", 312, '.null', 200);
    $(".forgotPassword").click(function() {
        displayForgotPassword();
    });

    $(".paginatorLinks .paginatorDropDown").live('change', function() {
        if ($(this).val() != "") {
            var thisValue = $(this).val();
            eval(thisValue);
        }
    });

    $("#registerUserNameNameContainer .registerUserLabel").click(function() {
        var availableDisplayName = false;
        //        if ($("#registerUserNameNameContainer #registerNewUserName").val() != "") {
        //            $.ajax({
        //                type: "POST",
        //                url: "/WebServices/UserManagement.asmx/CheckUserDisplayName",
        //                data: { name: $("#registerUserNameNameContainer #registerNewUserName").val() },
        //                dataType: "xml",
        //                success: function(data) {
        //                    $(data).find("string").each(function() {
        //                        if ($(this).text().length == 0) {
        //                            availableDisplayName = true;
        //                        } else {
        //                            $("#registerUserNameNameContainer .error ").html("Display name not available.");
        //                        }
        //                    });
        //                }
        //            });
        //        }

        // if (availableDisplayName) {
        var recorededResponse;
        $.ajax({
            type: "POST",
            url: "/WebServices/UserManagement.asmx/UpdateDisplayName",
            data: { consumerTouchPointID: $("#newUserNameEmailConsumerTouchPointID").val(), displayName: $("#registerUserNameNameContainer #registerNewUserName").val() },
            dataType: "xml",
            success: function(response) {
                $(response).find("StatusCode").each(function() {
                    if ($(this).text() == "Success") {
                        $("#registerUserNameNameContainer .error ").html("");
                        //window.location.reload();
                        ajaxLogin($("#newUserNameEmailConsumerEmail").val(), $("#newUserNameEmailConsumerPW").val())
                    } else {
                        $("#registerUserNameNameContainer .error ").html("Display name is not available.");
                    }
                });
            },
            error: function(response) {
                // TODO --> HIDE ENTIRE CONTROL
                //recorededResponse = response;
                // alert("JSON Error Response:\r\n" + response.responseText);
            }
        });
        //     }
    });

});
