
// if(performance.navigation.type == 2){
//     location.reload(true);
//  }

$(document).ready(function () {


    //$("img").bind("error",function(){
    // // Replacing image source
    // console.log("no_img");
    // $(this).attr("src","images/noimage.png");
    //});

    // var paddingleftfilter = $('.max_scr').offset.left() - $('body').offset.left();
    // console.log(paddingleftfilter);
    if ($("body").hasClass("post-template-default")) {
        $("#comments").hide();
        $(".post__title").prependTo(".post--single");
        // $(".post__date").prependTo(".post--single");
    }

    if ($("body").hasClass("page-template-default")) {


    } else {
        $(".filter").hide();
    }
    setInterval(function curfil() {
        var currentfil = $("#ajaxsearchprobsettings2_1 > form > fieldset:nth-child(7) > div > div > div > a > span").text();
        $(".current_tab").text(currentfil);
        // $(".chosen-drop").css("position","absolute");
    }, 1000);



    if (screen.width > 960) {
        if ($("body").hasClass("hp-template--listing-view-page")) {
            console.log("get+");


            async function f() {

                let promise = new Promise((resolve, reject) => {
                    $(".descr").prependTo(".hp-listing__description");
                    $('<div id="newcard_di"></div>').prependTo('.site-main');
                    $('<div class="card__wrapperin"></div>').prependTo('#newcard_di');
                    $('<div class="left__content_c"></div>').prependTo('.card__wrapperin');
                    $('<div class="right__content_c"></div>').appendTo('.card__wrapperin');
                    $('<div class="right__content_title"></div>').prependTo('.right__content_c');
                    $('<div class="right__content_title_left"></div>').prependTo('.right__content_title');
                    $('<div class="right__content_title_right"></div>').appendTo('.right__content_title');
                    $('<div class="right__content_title_right__add"></div>').appendTo('.right__content_title_right');
                    $('<div class="footer__content_ft"></div>').appendTo('#newcard_di');
                    $('<div class="footer__comment_ft"></div>').appendTo('#newcard_di');

                    setTimeout(() => resolve("готово!"), 1000)
                });

                let result = await promise; // будет ждать, пока промис не выполнится (*)

                $('.hp-listing__images').prependTo('.left__content_c');
                $('.title_bar').prependTo('.right__content_title_left');
                $(".region_title").prependTo('.right__content_title_right');
                $("#listingTimeBlock").appendTo(".right__content_title_right__add");
                $(".hp-listing__description").appendTo(".right__content_c");
                $(".cardButtonBlock").appendTo(".footer__content_ft");
                $("#comments").appendTo(".footer__comment_ft");
                $(".inner-wrapper-sticky").appendTo(".footer__comment_ft");
                //  $(".hp-listing__images").hide().show(2000);



                console.log(result); // "готово!"




            }

            f();

        }


    }
    $("#comment").focus(function () {
        $(".mobile_bootom_navbar").addClass("hider__bar");
        $(".mobile_bootom_navbar").fadeOut();
    });
    $("#comment").focusout(function () {
        $(".mobile_bootom_navbar").removeClass("hider__bar");
        $(".mobile_bootom_navbar").fadeIn();
    });

    $("#comment").each(function () {
        this.setAttribute("style", "height:" + "1rem" + "px;overflow-y:hidden;");
        // this.setAttribute("style", "height:" + (this.scrollHeight) + "px;overflow-y:hidden;");
    }).on("input", function () {

        this.style.height = "auto";
        this.style.height = (this.scrollHeight) + "px";
    });
    $("#comment").attr("rows", "1");
    $(window).on("load", function () {
        setTimeout(function () {
            $(".mobile_app").hide(300);
        }, 3000);

        $(".hp-form--message-send div button").removeClass().addClass("newbtnnew");
    });
    $('.sub_wrapper_inner').click(function () {
        $(".select2-results__option").each(function () {
            var regall = $(this).find("div").text();
            if (regall == 'Все регионы') {
                $(this).hide();
            }



        });
    });

    if (screen.width < 1100) {

        $(".asp_main_container").on("asp_search_end", function () {
            console.log("end");
            $("#loader").hide();
            $(".result div").removeClass("mainblock");
            $(".result").show();
            function showpanel() {
                $(".asp_content").each(function () {
                    var href = $(this).find("a").attr('href');
                    $(this).find("a").removeAttr("href");
                    // //  $( ".hp-listing--view-block" ).wrap( "<a class='popup-modal tiles' rel='20137' href='#test-modal'></a>" );
                    $(this).wrap(function () {
                        return "<a class='popup-modal tilesm' rel='" + href + "' href='#test-modal'></a>";
                    });
                    console.log(href);
                });
                console.log("end 1000");
            }
            setTimeout(showpanel, 100)



        });




    }


    $(".asp_main_container").on("asp_search_end", function () {
        console.log('DRRE');

    })




    $("body").css("background-image", "none");
    $(".wp-block-group__inner-container .row .col-6").addClass("mainblockfors");
    function show_confirm(obj) {
        var r = confirm("Вы действительно хотите удалить объявление?");
        if (r == true)
            window.location = obj.attr('href');
    }
    $('.wrapdel a').click(function (event) {
        event.preventDefault();
        show_confirm($(this));

    });
    if ($("body").hasClass("hp-template--listing-submit-details-page")) {
        lscache.flushExpired();
        var getoevl = $(".hp-form--listing-submit").attr("data-id");

        if (lscache.get(getoevl) === null) {
            // Swal.fire('Объявление поднято!');
            lscache.set(getoevl, 'sub', 1440)
        } else {
            console.log(getoevl);
            // window.location = 'https://kupi-business.kz/submit-listing/complete/';

        }
    }
    $('button').each(function () {
        if ($(this).attr('data-url') == "https://kupi-business.kz/account/") { // ссылка из а
            $(this).attr("data-url", "https://kupi-business.kz/acc/");
            console.log("match");
            // добавляем класс не переводить

        }

    })
    $('a').each(
        function () {
            if ($(this).attr('href') == "https://kupi-business.kz/account/") { // ссылка из а
                $(this).attr("href", "https://kupi-business.kz/acc/");
                console.log("match");
                // добавляем класс не переводить

            }
            if ($(this).attr('href') == "https://kupi-business.kz/account/listings/") { // ссылка из а
                $(this).attr("href", "https://kupi-business.kz/acc/");
                console.log("match");
                // добавляем класс не переводить

            }
        });


    $(".custom-logo-link").click(function () {
        $("#loader").show();
    });
    if (screen.width > 1100) {
        $(".hp-listing--view-block").each(function () {
            var href = $(this).find("a").attr('href');
            $(this).find("a").removeAttr("href");
            // //  $( ".hp-listing--view-block" ).wrap( "<a class='popup-modal tiles' rel='20137' href='#test-modal'></a>" );
            $(this).wrap(function () {
                return "<a class='popup-modal tiles' rel='" + href + "' href='#test-modal'></a>";
            });






        });
    }




    if (screen.width < 960) {
        // $(".hp-listing--view-block").click(function(){
        //             $("#loader").show();
        //       $(this).each(function(){

        //          var href = $(this).find("a").attr('href');
        //           console.log(href);

        //            window.location.href = href;
        //         });
        //          });


        $(".tilesm").click(function () {
            $('body').css("overflow", "hidden");

            $('.header-navbar').addClass('overxhead');
        });
        $(".hp-listing--view-block").each(function () {
            var href = $(this).find("a").attr('href');
            $(this).find("a").removeAttr("href");
            // //  $( ".hp-listing--view-block" ).wrap( "<a class='popup-modal tiles' rel='20137' href='#test-modal'></a>" );
            $(this).wrap(function () {
                return "<a class='popup-modal tilesm' rel='" + href + "' href='#test-modal'></a>";
            });



            console.log(href);


        });

    }
    //      $(".hp-listing--view-block").click(function(){
    //         $("#loader").show();
    //    $(this).each(function(){

    //      var href = $(this).find("a").attr('href');
    //       console.log(href);

    //         window.location.href = href;
    //     });
    //      });

    $(".hp-field--file").attr("accept", "image/*");
    $(window).on("load", function () {
        if ($("body").hasClass("hp-template--listing-edit-page")) {
            $('.select2-selection__rendered').each(function () {
                var valuea = $(this).attr('title');
                console.log(valuea);
                console.log("sd22")
                $(this).html(valuea);
            });

        }


    });
    // $("#select2-bedrooms-3k-container").attr('title');

    // console.log( $("#select2-bedrooms-3k-container").attr('title'); );
    $('.hp-page__title').each(function () {
        var text = $(this).text();
        $(this).text(text.replace('Заполните детали', 'Заполните поля'));
    });
    $(".hp-form__label span:contains('Рассмотрю варианты')").parent().find("label").hide();
    $(".hp-form__label span:contains('Рассмотрю варианты')").hide();
    $("input[name=first_name]").attr("placeholder", "Имя");
    $("input[name=first_name]").parent().find("label").hide();
    $("input[name=last_name]").attr("placeholder", "Фамилия");
    $("input[name=last_name]").parent().find("label").hide();
    $("input[name=email]").parent().find("label").hide();
    $("input[name=password]").parent().find("label").hide();
    $("input[name=password]").attr("placeholder", "Новый пароль");
    $("input[name=current_password]").parent().find("label").hide();
    $("input[name=current_password]").attr("placeholder", "Текущий пароль");
    $("input[name=email]").attr("placeholder", "Email");
    if ($("body").hasClass("hp-template--user-login-page")) {
        $("input[name=password]").parent().find("label").show();

        $("input[name=password]").attr("placeholder", "Пароль");
    };

    if ($("body").hasClass("hp-template--user-edit-settings-page")) {
        $(".header__search_wrapper").hide();
        $("#content").css("margin-top", "75px");

    }

    if ($("body").hasClass("hp-template--listing-edit-page")) {
        $(".header__search_wrapper").hide();
        $("#content").css("margin-top", "75px");

    }

    if ($("body").hasClass("hp-template--listing-submit-category-page")) {
        $(".header__search_wrapper").hide();
        $("#content").css("margin-top", "75px");

    }

    if ($("body").hasClass("hp-template--listing-submit-details-page")) {
        $(".header__search_wrapper").hide();
        $("#content").css("margin-top", "75px");

    }
    // $("textarea[name=description]").attr("placeholder","описание профиля");
    // $("textarea[name=description]").parent().find("label").hide();
    // if(("standalone" in window.navigator) && window.navigator.standalone){
    //     alert("get");
    //     location.reload();
    // }

    // $('.your_class_to_update_d').on('click', function() {
    //     alert('Для поднятия объявления необходимо авторизоваться на сайте');


    // });
    // Standard alert
    $("#sellerBtn").click(function () {
        $('#sellerBtn').each(function () {
            var value = $(this).text();
            $(this).html('<a href="tel:' + value + '">' + value + '</a>');
        });

    });


    $("body").show();
    if (top.location.pathname === '/') {
        $(".backback").hide();
        // $(".mobile_app").delay(5000).show();
    } else {
        $(".backback").click(function (event) {
            event.preventDefault();
            history.back(-1);
        });
        $(".homeback").hide();

        // $(".mobile_app").delay(5000).show();
    }





    console.log("ready!");

    // First we get the viewport height and we multiple it by 1% to get a value for a vh unit
    let vh = window.innerHeight * 0.01;
    // Then we set the value in the --vh custom property to the root of the document

    // Первый этап
    //nav


    $(".hp-page__content form").find("div").removeClass().addClass('listinginner');
    $(".hp-page__content form").find("button").removeClass().addClass('listinginnerbtn');
    $(".hp-form--user-register .hp-form__footer").removeClass().addClass('reform');;
    $(".hp-form--user-login .hp-form__footer").removeClass().addClass('reform');
    $(".reform button").removeClass("hp-form__button");

    if ($("body").hasClass("home")) {
        $(".cat").appendTo(".filter_content");

    }
    if ($("body").hasClass("hp-template--listings-edit-page")) {

        $('.hp-page__title').each(function () {
            var text = $(this).text();
            $(this).text(text.replace('Объявления', 'Мои объявления'));
        });

    }

    if ($("body").hasClass("home")) {
        $("#wpdreams_asp_results_1").css("display", "none");

    }
    if ($("body").hasClass("hp-template--user-login-page")) {
        $("#wpdreams_asp_results_1").css("display", "none");

    }


    if ($("body").hasClass("single-hp_listing")) {
        //   $(" .header-navbar__end").css("margin-left","240px");
        $("#wpdreams_asp_results_1").css("display", "none");
        $(window).on("load", function () {


            console.log("single");
            $(".probox .proclose").click();
        });

        $(".cat").appendTo(".filter_content");
    }
    if ($("body").hasClass("hp-template--user-edit-settings-page")) {
        $(".hp-page__sidebar").css("display", "block");
        $(".hp-row").css("display", "flex");
        $(".hp-row").css("flex-direction", "column");

    }
    if ($("body").hasClass("hp-template--listings-edit-page")) {
        $(".hp-page__sidebar").css("display", "block");
        $(".hp-row").css("display", "flex");
        $(".hp-row").css("flex-direction", "column");

    }

    if ($("body").hasClass("hp-template--listing-submit-category-page")) {
        console.log("1131232");
        $('a').each(
            function () {
                if ($(this).attr('href') == "https://kupi-business.kz/submit-listing/category/167/") {

                    $(this).addClass("disable").closest("article").addClass("disable");
                    // добавляем класс не переводить

                }
            });
        $(".hp-page__content").find(".hp-listing-categories").removeClass().addClass("cat_wrapper");
        $(".hp-page__content").find(".hp-row").removeClass().addClass("cat_wrapper_inner");
        $(".hp-page__content").find(".hp-grid__item").removeClass().addClass("cat_wrapper_card");

    }
    if ($("body").hasClass("hp-template--listing-submit-details-page")) {
        console.log("1131232");
        $('input').each(
            function () {

                if ($(this).hasClass('hp-field--url')) {


                    $(this).addClass("disable").closest("div").addClass("disable");
                    $(this).parent().find("div").addClass("disable");

                    // добавляем класс не переводить

                }
            });



        $("form .listinginner").removeClass().addClass("sub_wrapper");
        $("form div div").removeClass().addClass("sub_wrapper_inner");


    }

    $(".hp-widget--listing-filter").appendTo(".filter_content");
    $(".filter_en").click(function () {
        $(".filter_content").toggle();
    });
    $(".hp-field--number").attr({
        "max": 100000000,        // substitute your own
        "min": 0          // values (or variables) here
    });
    if (screen.width > 1440) {
        if ($("body").hasClass("home")) {
            $(".hp-listings").removeClass().addClass("main_card_wrapper");
            $(".hp-row").removeClass().addClass("main_card_wrapper_inner");
            $(".hp-row .hp-grid__item").removeClass().addClass("main_card");
        }

    }
    if (screen.width < 960) {
        // $( window ).on( "load", function() {
        //     $("#ajaxsearchprosettings1_1").appendTo(".header__search_wrapper");
        //     $("#ajaxsearchprores1_1").appendTo(".header__search_wrapper");



        // });
        $("input:radio").on("change", function () {
            if ($(this).is(':checked')) {
                $(this).addClass("plus");
                $(this).closest("label").addClass("chpl");
                // append goes here
            } else {
                console.log("deleted");
                $(this).removeClass("plus");
                $(this).closest("label").removeClass("chpl");
            }
        });

        $("#b1").click(function () {
            $(".asp_label:contains('VIP')").click();

        });
        $("#b2").click(function () {
            $(".asp_label:contains('Деловые предложения')").click();

        });
        $("#b3").click(function () {
            $(".asp_label:contains('Инвестиции')").click();

        });
        $("#b4").click(function () {
            $(".asp_label:contains('Кредиты для бизнеса')").click();

        });
        $("#b5").click(function () {
            $(".asp_label:contains('Недвижимость для бизнеса')").click();

        });
        $("#b6").click(function () {
            $(".asp_label:contains('Обмен бизнеса на авто')").click();

        });
        $("#b7").click(function () {
            $(".asp_label:contains('Проверенные объявления')").click();

        });
        $("#b8").click(function () {
            $(".asp_label:contains('Продажа бизнеса')").click();

        });
        $("#b9").click(function () {
            $(".asp_label:contains('Стартапы')").click();

        });
        $("#b10").click(function () {
            $(".asp_label:contains('Товары для бизнеса')").click();

        });
        $("#b11").click(function () {
            $(".asp_label:contains('Услуги для бизнеса')").click();

        });
        $("#b12").click(function () {
            $(".asp_label:contains('Франшизы')").click();

        });
        $(".nav__button_wr button").click(function () {
            $(".asp_spacer").remove();
            $(".nav__button_wr button").removeClass("testhover");
            $(this).addClass("testhover");
            $(".show_res_mob").click();
        });
        $("legend:contains('Категории')").closest("fieldset").hide();
        $(".filtre__enable").click(function () {
            $(this).hide();
            $("#wpdreams_asp_settings_1").show();

        });
        $(".hide_filter").click(function () {
            $("#wpdreams_asp_settings_1").hide();
            $(".filtre__enable").fadeIn(300);

        });
        $(".promagnifier").click(function () {
            $(".show_res_mob").click();

        });

        $(".show_res_mob").click(function () {
            $("#wpdreams_asp_settings_1").hide();
            $(".filtre__enable").fadeIn(300);
            $("#wpdreams_asp_results_1").css("display", "block");

            //     console.log("sdsddsd");
            //   $('#ajaxsearchprobsettings1_1').hide(100);
            //   $('#ajaxsearchprobsettings1_1').css("visibility","hidden");
            //   $('#ajaxsearchprobsettings1_1').css("opacity","0");
            //   $( '.prosettings' ).click ();

            //   $('#ajaxsearchprobsettings1_1').removeClass("asp_an_fadeIn").addClass("asp_an_fadeOut");
        });
        $(window).on("load", function () {

            $(".asp_spacer").remove();

            setInterval(function findrm() {


                $(".destext").each(function () {
                    $(".asp_spacer").remove();
                    var text = $(this).text();
                    //  console.log(text);
                    // var beforear = text.replace(/\;/g, ',');
                    //      console.log("r" + beforear);
                    //  var numbersArray = new Array(beforear);
                    //  var numbersString = numbersArray.join(',');
                    //  $.each(numbersArray, function(index, value) { 
                    //      console.log(index + ': ' + value);
                    //   });
                    //  console.log(numbersString); 
                    //alerts 1,2,3,4,5,6

                    var term = "Регион";

                    if (text.indexOf(term) != -1) {
                        //  console.log(term);
                    }

                    var cleartext = text.replace(/\s+/g, '');
                    var remreg = cleartext.replace(/Регион:/g, '');

                    var newtext = remreg.split(";")[1];
                    $(this).text(newtext);



                    //  $(".destext:contains('Продавец')").hide();

                    // function fnslear() {
                    setInterval(function fnslear() {
                        $(".destext:contains('Продавец')").hide();

                    }, 100);
                    //     // console.log("callback");

                    // }

                });


            }, 1000);



        });




        $(".description_price").wrap("<div class='mb__descr'></div>");
        $(".statCounter").appendTo(".mb__descr");
        // $(".hp-listing--view-block").each(function() {
        //    var fxs = $(this).find(".hp-listing__attribute--bedrooms");
        //    $(fxs).prependTo(".hp-listing__details--primary");
        // });
        //    $(".hp-listing--view-block .hp-listing__content .hp-listing__attribute--bedrooms").prependTo(".hp-listing__details--primary");



        // $('input:radio').change(
        //     function(){
        //         if ($(this).is(':checked') ) {
        //             $(this).addClass("plus");
        //             $(this).closest("label").addClass("chpl");
        //             // append goes here
        //         }else if($(this).is(":not(:checked)")){
        //             console.log("deleted");
        //             $(this).removeClass("plus");
        //             $(this).closest("label").removeClass("chpl");
        //         }
        //     });


        // if($("input:radio").is(":checked")){
        //     console.log("kjhaskjdfhwekjfh222222222222");
        //     this.addClass("plus");
        //      }else{
        //         this.removeClass("plus");
        //         // NOTHING IS CHECKED
        //      }

        $(".b2blinl").addClass("mb2blinl");

        $(".hp-form--listing-filter .hp-form__footer").removeClass().addClass("flbtnmob");
        $(".flbtnmob button").removeClass().addClass("flbtnmob_to_go");
        $(".filter_btn").find(".hp-form__field--select").removeClass().addClass("regselect");

        $(".share-buttons").appendTo(".cardButtonBlock");

        if ($("body").hasClass("single-hp_listing")) {

            $("#messageBtn").appendTo(".chat");
            $(".repl").hide();
            $("#messageBtn").html("Написать");
            if (screen.width < 960) {
                $(".hp-listing__description").appendTo(".mob_wrapper_text");
            }
            $(".hp-listing__description").addClass('sidebar-box');
            // $(".read-more").appendTo('.hp-listing__description');

            $(function () {

                var $el, $ps, $up, totalHeight;

                $(".sidebar-box .button").click(function () {

                    // IE 7 doesn't even get this far. I didn't feel like dicking with it.

                    totalHeight = 0

                    $el = $(this);
                    $p = $el.parent();
                    $up = $p.parent();
                    $ps = $up.find("p:not('.read-more')");

                    // measure how tall inside should be by adding together heights of all inside paragraphs (except read-more paragraph)
                    $ps.each(function () {
                        totalHeight += $(this).outerHeight();
                        // FAIL totalHeight += $(this).css("margin-bottom");
                    });

                    $up
                        .css({
                            // Set height to prevent instant jumpdown when max height is removed
                            "height": $up.height(),
                            "max-height": 9999
                        })
                        .animate({
                            "height": totalHeight
                        });

                    // fade out read-more
                    $p.fadeOut(6000);

                    // prevent jump-down
                    return false;

                });

            });

        }
        $("#listingTime").appendTo(".region_title");
        $(".hp-page__sidebar").appendTo("#addmore");
        $(".hp-page__sidebar").unwrap().removeClass().addClass('promote');;



        // $(".wp-block-group__inner-container .row div").removeClass().addClass('wrapper_mobile_listing');
        $("div.hp-form__fields  select").appendTo(".moredata");
        $(".hp-form__field--search").append("<div id='moredata'></div>").addClass("advanced");

        var coll = document.getElementsByClassName("collapsible");
        var i;

        for (i = 0; i < coll.length; i++) {
            coll[i].addEventListener("click", function () {
                this.classList.toggle("active");
                var content = this.nextElementSibling;
                if (content.style.display === "block") {
                    content.style.display = "none";
                } else {
                    content.style.display = "block";
                }
            });
        }
        $('#bs-example-navbar-collapse-1').on('show.bs.collapse', function () {
            $('.navbar').addClass('mobile-opened');
            $('.second_row').hide();
            $('.navbar-brand').addClass('mobile-opened');
        });

        $('#bs-example-navbar-collapse-1').on('hide.bs.collapse', function () {
            $('.navbar').removeClass('mobile-opened');
            $('.second_row').show();
            $('.navbar-brand').removeClass('mobile-opened');
        });

        //nav
        $("body").css("overflow", "scroll");
        $(".hp-field").attr("autocomplete", "off");
        $(".hp-page__header").appendTo(".header-navbar__end");
        $(".hp-form--wide").appendTo(".header-navbar__end");
        //  $("#sendMyListing").appendTo(".second_row");


        // //  sendMyListing
        // //  second_row
        // // wp-block-group

        $(".hp-field.hp-field--search").removeClass("background");

    }
    else {
        $(".hp-listing__description").css("font-size", "16px");
        $(".hp-listing__description").css("font-weight-size", "400");
        $(".hp-listing__description").css("font-color", "#222222");

        if ($("body").hasClass("single-hp_listing")) {
            $(" .header-navbar__end").css("margin-left", "240px");
        }

        $(".hp-page__sidebar").appendTo("#addmore");
        $(".hp-page__sidebar").unwrap().removeClass().addClass('promote');;
        var coll = document.getElementsByClassName("collapsible");
        var i;

        for (i = 0; i < coll.length; i++) {
            coll[i].addEventListener("click", function () {
                this.classList.toggle("active");
                var content = this.nextElementSibling;
                if (content.style.display === "block") {
                    content.style.display = "none";
                } else {
                    content.style.display = "block";
                }
            });
        }
        window.onscroll = function () { scrollFunction() };
        $(".header-navbar").css("height", "80px");
        // $(".header-navbar__start").fadeOut(500);
        // $(".header-navbar__end").fadeOut(500);
        $(".second_row").fadeOut(200);
        $(".filter_btn").hide();
        $(".hp-form--wide").addClass("slim_se");
        $(".hp-form--wide").find(".hp-form__footer button").addClass("slim_se_btn");

        $(".hp-form--wide").find(".hp-form__field--search").addClass("slim_se_btn_input");
        $(".hp-form--wide").find(".fa-map-marker-alt").addClass("slim_se_icon");
        $(".hp-form--wide").find(".select2-selection__rendered").addClass("slim_se_ul");
        $(".header-logo").find("img").addClass("logo_min");
        // $("#sendMyListing").appendTo(".header-navbar__end").addClass("row_btn");
        $("#sendMyListing").appendTo(".after_s").addClass("row_btn");;
        $(".header-navbar__end").addClass("slim_end");
        $(".hp-menu__item--user-account").addClass("myacc_head");

        function scrollFunction() {
            if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 50) {
                $(".header-navbar").css("height", "80px");
                // $(".header-navbar__start").fadeOut(500);
                // $(".header-navbar__end").fadeOut(500);
                $(".second_row").fadeOut(200);
                $(".filter_btn").hide();
                $(".hp-form--wide").addClass("slim_se");
                $(".hp-form--wide").find(".hp-form__footer button").addClass("slim_se_btn");

                $(".hp-form--wide").find(".hp-form__field--search").addClass("slim_se_btn_input");
                $(".hp-form--wide").find(".fa-map-marker-alt").addClass("slim_se_icon");
                $(".hp-form--wide").find(".select2-selection__rendered").addClass("slim_se_ul");
                $(".header-logo").find("img").addClass("logo_min");
                // $("#sendMyListing").appendTo(".header-navbar__end").addClass("row_btn");
                $("#sendMyListing").appendTo(".after_s").addClass("row_btn");;
                $(".header-navbar__end").addClass("slim_end");
                $(".hp-menu__item--user-account").addClass("myacc_head");




                // $(".hp-form--wide").clone().appendTo(".s_box_small");
                // $(".head_small").show();
                // $(".s_box_small form").addClass("search-box");
                //  $(".search-box").unwrap();

                $('.header').on('click', '.search-toggle', function (e) {
                    var selector = $(this).data('selector');

                    $(selector).toggleClass('show').find('.search-input').focus();
                    $(this).toggleClass('active');

                    e.preventDefault();
                });

                // document.getElementById("logo").style.fontSize = "25px";
            } else {
                // $(".filter_btn").show();
                // $(".hp-menu__item--user-account").removeClass("myacc_head");
                // $(".header-navbar__end").removeClass("slim_end");
                // // $("#sendMyListing").appendTo(".second_row").removeClass("row_btn");;
                // $("#sendMyListing").appendTo(".after_s").removeClass("row_btn");;
                // $(".header-logo").find("img").removeClass("logo_min");
                // $(".hp-form--wide").find(".hp-form__footer button").removeClass("slim_se_btn");
                // $(".head_small").hide();
                // //  $(".hp-form--wide").appendTo(".header-navbar__start");
                // // $(".header-navbar__end").fadeIn(500);
                // // $(".header-navbar__start").fadeIn(600);
                // $(".header-navbar").css("height","113px");
                // $(".second_row").fadeIn(700);
                // // $(".hp-form--wide").removeClass("slim_se");

            }
        }
        $("#content").addClass("wrap_desktop");

        $(".hp-page__header").appendTo(".header-navbar__start");
        $(".hp-form--wide").appendTo(".header-navbar__start");
        //   $("#sendMyListing").appendTo(".second_row");
        // //  sendMyListing
        // //  second_row
        // // wp-block-group

        $(".hp-field.hp-field--search").removeClass("background");
    }


    $(".hp-menu__item--user-account").addClass("notranslate");
    $("#sendMyListing").addClass("notranslate");
    $('a').each(
        function () {
            if ($(this).attr('href') == "/listing-category/startapy/") { // ссылка из а

                $(this).addClass("notranslate");
                // добавляем класс не переводить

            }

            if ($(this).attr('href') == "http://wa.me/+77056869069") { // ссылка из а

                $(this).addClass("notranslate");
                $(this).find('img').css("display", "none");
                // добавляем класс не переводить

            }


            if ($(this).attr('href') == "/listing-category/franshizy/") {
                $(this).addClass("notranslate");
            }

            if ($(this).attr('href') == "/listing-category/proverennye/") {
                $(this).addClass("notranslate");
            }
            if ($(this).attr('href') == "/listing-category/services/") { // ссылка из а

                $(this).addClass("notranslate");
                // добавляем класс не переводить

            }
            if ($(this).attr('href') == "/listing-category/tovary-dlya-biznesa/") { // ссылка из а

                $(this).addClass("notranslate");
                // добавляем класс не переводить

            }
            if ($(this).attr('href') == "/listing-category/kredity-dlya-biznesa/") { // ссылка из а

                $(this).addClass("notranslate");
                // добавляем класс не переводить

            }
        });

});
// select the target node
var target = document.getElementsByTagName("html");
// create an observer instance, safari via webkit
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
// create the observer
var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
        var pagelangchange = mutation.target.getAttribute("lang");
        // var htext = document.getElementsByClassName("pageheadmain")[0];

        if (pagelangchange == 'kk') {
            $("a.second-tag").css("display", "none");
            $("a.ab-item.first-tag").css("display", "none");
            // $(".first").find('img').attr("src","/assets/f_banner.png");
            $(".second").find('img').attr("src", "/assets/s_banner.png");

            $(".gttr a:first-child").css("color", "white");
            $(".gttr a:nth-child(2)").css("color", "gray");
            $('a[href="/listing-category/startapy"]').css("display", "none");
            $("#sendMyListing").find('span').text("Хабарландыру беру");
            $('a').each(
                function () {
                    if ($(this).attr('href') == "/listing-category/startapy/") {
                        $(this).find('.mobile-section-text').text("Стартаптар");
                        $(this).find('.section-text').text("Стартаптар");


                    } if ($(this).attr('href') == "https://kupi-business.kz/account/") {
                        $(this).find('span').text("Менің аккаунтым");



                    }
                    if ($(this).attr('href') == "/listing-category/franshizy/") {
                        $(this).find('.mobile-section-text').text("Франшизалар");
                        $(this).find('.section-text').text("Франшизалар");


                    }

                    if ($(this).attr('href') == "https://advertisement.kupi-business.kz/") {
                        $(this).find('img').attr("src", "/assets/inv_kz.png");



                    }
                    if ($(this).attr('href') == "/listing-category/proverennye/") {
                        $(this).find('.mobile-section-text').text("Тексерілген бизнес");
                        $(this).find('.section-text').text("Тексерілген бизнес");
                    }
                    if ($(this).attr('href') == "/listing-category/services/") {
                        $(this).find('.mobile-section-text').text("Бизнесті қызметтер");
                        $(this).find('.section-text').text("Бизнесті қызметтер");
                    }
                    if ($(this).attr('href') == "/listing-category/tovary-dlya-biznesa/") {
                        $(this).find('.mobile-section-text').text("Бизнеске арналған тауарлары");
                        $(this).find('.section-text').text("Бизнеске арналған тауарлары");
                    }
                    if ($(this).attr('href') == "/listing-category/kredity-dlya-biznesa/") {
                        $(this).find('.mobile-section-text').text("Бизнеске арналған кредиттер");
                        $(this).find('.section-text').text("Бизнеске арналған кредиттер");
                    }
                });
            console.log("kk");
            // htext.style.marginTop = "0px";

        } else {
            $("a.second-tag").css("display", "block");
            $("a.ab-item.first-tag").css("display", "block");
            // $(".first").find('img').attr("src","https://imagizer.imageshack.com/img922/8856/l5tFBi.png");
            $(".second").find('img').attr("src", "https://imagizer.imageshack.com/img923/1672/Lbz2f6.png");
            $(".gttr a:first-child").css("color", "gray");
            $(".gttr a:nth-child(2)").css("color", "white");
            $("#sendMyListing").find('span').text("Подать объявление");
            $('a').each(
                function () {
                    if ($(this).attr('href') == "/listing-category/startapy/") {
                        $(this).find('.mobile-section-text').text("Стартапы");
                        $(this).find('.section-text').text("Стартапы");


                    }
                    if ($(this).attr('href') == "https://advertisement.kupi-business.kz/") {
                        $(this).find('img').attr("src", "https://imageshack.com/i/pmJjM9bjp");



                    }



                    if ($(this).attr('href') == "/listing-category/franshizy/") {
                        $(this).find('.mobile-section-text').text("Франшизы");
                        $(this).find('.section-text').text("Франшизы");


                    }
                    if ($(this).attr('href') == "/listing-category/proverennye/") {
                        $(this).find('.mobile-section-text').text("Проверенный бизнес");
                        $(this).find('.section-text').text("Проверенный бизнес");
                    }
                    if ($(this).attr('href') == "/listing-category/services/") {
                        $(this).find('.mobile-section-text').text("Услуги для бизнеса");
                        $(this).find('.section-text').text("Услуги для бизнеса");
                    }
                    if ($(this).attr('href') == "/listing-category/tovary-dlya-biznesa/") {
                        $(this).find('.mobile-section-text').text("Товары для бизнеса");
                        $(this).find('.section-text').text("Товары для бизнеса");
                    }
                    if ($(this).attr('href') == "/listing-category/kredity-dlya-biznesa/") {
                        $(this).find('.mobile-section-text').text("Кредиты для бизнеса");
                        $(this).find('.section-text').text("Кредиты для бизнеса");
                    } if ($(this).attr('href') == "https://kupi-business.kz/account/") {
                        $(this).find('span').text("Мой аккаунт");



                    }
                });
            console.log("ru");
            // htext.style.marginTop = "59px";
        }
    });
});
// configuration of the observer:
// only really need attributes
var config = {
    attributeFilter: ['lang'],
    attributeOldValue: false,
    subtree: true
};
// pass in the target node, as well as the observer options
observer.observe($(target)[0], config);

$(window).on("load", function () {

    console.log('jQuery test');
    var html = document.getElementsByTagName("html")[0].getAttribute("lang");
    if (html === "ru-RU") {
        console.log("RURU");
        $(".gttr a:first-child").css("color", "gray");
        $(".gttr a:nth-child(2)").css("color", "white");
        // $('a[href="/listing-category/startapy"]').find(".mobile-section-text").text("It Worked!");

    }
});