var ManagePrivacy = true;
setTimeout(initContentManagement, 1000);
function SetCustomSearchBoxEventsIndex() {
    if ($('#dw-custom-searchbox').length > 0) {
        $('#dw-custom-searchbox').autoComplete({
            minChars: 2,
            cache: false,
            delay: 1,
            menuClass: 'vehSearchResults',
            source: function (term, response) {
                $.getJSON('/PredictiveTyper.aspx', { type: '1', param: term, dealerID: DWDealerID, extra: '' }, function (data) {
                    response(data);
                });
            }
        });
        $('#dw-custom-searchbox').keypress(function (event) {
            var keycode = (event.keyCode ? event.keyCode : event.which);
            if (keycode == '13') {
                CustomSearchDWInventoryIndex();
            }
        });
    }
}
function CustomSearchDWInventoryIndex() {
    var getSearchValue = $('#dw-custom-searchbox').val();
    getSearchValue = getSearchValue.replace(/  +/g, ' ');
    logInventorySearchPhrase(getSearchValue);
    if (trim(getSearchValue).length > 0) {
        var myLocation = DealerSiteUrl + "/inventory.aspx?S=" + getSearchValue;
        window.location = myLocation;
    }
    else {
        AlertModel("Please enter Search value");
    }
}
//menu
$(document).ready(function () {
    $("#menuToggleBtn").on("click", function () {
        buildFullMenu();
        $("#dwc-mainmenu-overlay").addClass("active");
        $("body").addClass("dwc-menu-open");
    });
    $(document).on("click", ".dwc-mainmenu-close", function () {
        $("#dwc-mainmenu-overlay").removeClass("active");
        $("body").removeClass("dwc-menu-open");
    });
    function buildFullMenu() {
        var sections = [];
        $("#main_menu > li").each(function () {
            var $mainLink = $(this).children("a").first();
            var title = $mainLink.text().trim();
            var subMenu = $(this).find(".sub_menu").first();
            var hasSub = subMenu.length > 0;
            var clonedMainLink = $("<div>").append($mainLink.clone()).html();

            var sectionHTML =
                '<div class="dwc-mainmenu-section">' +
                '<div class="dwc-mainmenu-title">' +
                clonedMainLink +
                (hasSub ? '<span class="dwc-mainmenu-arrow"><i class="fa fa-caret-down"></i></span>' : '') +
                '</div>';

            if (hasSub) {
                sectionHTML += '<ul class="dwc-mainmenu-list">';
                subMenu.children("li").each(function () {
                    var $link = $(this).find("a").first();
                    if ($link.length) {
                        var clonedLink = $("<div>").append($link.clone()).html();
                        sectionHTML += '<li>' + clonedLink + '</li>';
                    }
                });
                sectionHTML += '</ul>';
            }
            sectionHTML += '</div>';
            sections.push(sectionHTML);
        });
        var finalHTML =
            '<div class="dwc-mainmenu-header">' +
            '<div class="dwc-mainmenu-close">X</div>' +
            '</div>' +
            '<div class="dwc-mainmenu-content">' +
            sections.join('') +
            '</div>';
        $("#dwc-mainmenu-overlay").html(finalHTML);
    }
    $(document).on("click", ".dwc-mainmenu-arrow", function (e) {
        e.preventDefault();
        e.stopPropagation();
        if ($(window).width() <= 1000) {
            var parent = $(this).closest(".dwc-mainmenu-section");
            var submenu = parent.find(".dwc-mainmenu-list");
            submenu.slideToggle(200);
            $(this).toggleClass("active");
        }
    });
});
//endmenu