<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">function scrollToTop() {
    window.scrollTo({ top: 0, behavior: "smooth" });
}

function validateEmail(email) {
    var re = /\S+@\S+\.\S+/;
    return re.test(email);
}

function setCookie(key, value, hours) {
    var expires = new Date();
    if (hours) {
        expires.setTime(expires.getTime() + hours * 60 * 60 * 1000);
        document.cookie =
            key + "=" + value + ";expires=" + expires.toUTCString();
    } else {
        document.cookie =
            key + "=" + value + ";expires=Fri, 30 Dec 9999 23:59:59 GMT;";
    }
}

function getCookie(key) {
    var keyValue = document.cookie.match("(^|;) ?" + key + "=([^;]*)(;|$)");
    return keyValue ? keyValue[2] : null;
}

function crktag(page, category_id, type) {
    //views , click
    $.get( AdsUrl + "/home/tracking/page?category_id=" + category_id + "&amp;page=" + page + "&amp;type=" + type + "&amp;tag=KA");
}

$(function () {
    if (typeof BannerZ == "object" &amp;&amp; getCookie(bz_cookie) == null) {
        // #krungsri_cal_modal
        setTimeout(function () {
            $("#bannerZ").modal("show");
            setCookie(bz_cookie, 1, 1);
        }, 10000); // 10 sec
    }

    if (getCookie("consent") == null) {
        setTimeout(function () {
            $(".pdpa-popup").addClass("active");
            $(".pdpa-popup").css({ "z-index": "1000" });
        }, 600000); // 600 sec
    }

    if (typeof BannerZ2 == "object") {
        setTimeout(function () {
            $("#bannerZ").modal("hide");
            $("#bannerZ2").modal("show");
        }, 60000); //60 sec
    }

    // setTimeout(function(){
    //     fbq('consent', 'grant');
    // },3000);

    // $("#bannerz-btn").click(function (e) {
    //     e.preventDefault();
    //     $("#bannerZ").modal("hide");
    //     if (getCookie("consent") == null) {
    //         setTimeout(function () {
    //             $(".pdpa-popup").addClass("active");
    //             $(".pdpa-popup").css({ "z-index": "1000" });
    //         }, 10000);
    //     }
    // });

    $("#pdpa-popup-close").click(function (e) {
        e.preventDefault();
        $(".pdpa-popup").removeClass("active");
    });

    $("#pdpa-popup-accept-all").click(function (e) {
        e.preventDefault();
        setCookie("consent", true);
        $(".pdpa-popup").removeClass("active");
    });

    $(".pdpa-popup-settings").click(function (e) {
        e.preventDefault();
        $(".pdpa-popup-bg").addClass("active");
        $(".pdpa-popup-sidebar").addClass("active");
    });

    $("#pdpa-popup-settings-close").click(function (e) {
        e.preventDefault();
        $(".pdpa-popup-bg").removeClass("active");
        $(".pdpa-popup-sidebar").removeClass("active");
    });

    $("#pdpa_settings_save").click(function (e) {
        e.preventDefault();
        setCookie("consent", true);
        $(".pdpa-popup-bg").removeClass("active");
        $(".pdpa-popup-sidebar").removeClass("active");

        $(".pdpa-popup").removeClass("active");
    });

    $("#slidetop").find(".slidetop_menu &gt; *:first-child").addClass("active");
    $("#slidetop").find(".slidetop_dotted &gt; *:first-child").addClass("active");

    $('[data-toggle="slidetop"]').click(function (e) {
        e.preventDefault();
        $("[data-slidetop]").removeClass("active");
        $('[data-slidetop="' + $(this).data("slidetop") + '"]').addClass(
            "active"
        );
    });

    $(".slidetop_body-arrow").click(function () {
        if ($(this).hasClass("r")) {
            if ($("#slidetop .slidetop_menu &gt; .active").next().length &gt; 0) {
                $("#slidetop .slidetop_menu &gt; .active").next().click();
            } else {
                $("#slidetop .slidetop_menu &gt; :first-child").click();
            }
        } else {
            if ($("#slidetop .slidetop_menu &gt; .active").prev().length &gt; 0) {
                $("#slidetop .slidetop_menu &gt; .active").prev().click();
            } else {
                $("#slidetop .slidetop_menu &gt; :last-child").click();
            }
        }
    });

    $('.slidetop_menu [data-slidetop="0"]').click();

    // copy url
    $(".copylink").click(function () {
        $("#copytext").val($(this).data("link"));
        var $temp = $("&lt;input&gt;");
        $("body").append($temp);
        $temp.val($(this).data("link")).select();
        document.execCommand("copy");
        $temp.remove();
    });

    $("._article-detail-content :not(script)")
        .contents()
        .filter(function () {
            return this.nodeType === 3;
        })
        .replaceWith(function () {
            const linkTemplateRegex = /\{\d+,.+\}/;
            if (linkTemplateRegex.test(this.nodeValue)) {
                const rawLink = linkTemplateRegex.exec(this.nodeValue)[0];
                const parts = rawLink.slice(1, -1).split(",");
                const crkp_id = parts[0];
                const text = parts[1];
                return this.nodeValue.replace(
                    linkTemplateRegex,
                    `&lt;a href="/crkp_url/${crkp_id}" title="${text}" target="_blank" rel="noopener noreferrer"&gt;${text}&lt;/a&gt;`
                );
            }
            return this.nodeValue;
        });

    $("._guru-card-arrow").click(function () {
        var targetid = 0;
        if ($(this).hasClass("r")) {
            var target = $("._guru-card-item.active").next();
            $("._guru-card-item").removeClass("active");

            if (target.length != 0) {
                target.addClass("active");
                targetid = target.data("id");
            } else {
                $("._guru-card-item:first-child").addClass("active");
            }
        } else {
            var target = $("._guru-card-item.active").prev();
            $("._guru-card-item").removeClass("active");
            if (target.length != 0) {
                target.addClass("active");
                targetid = target.data("id");
            } else {
                $("._guru-card-item:last-child").addClass("active");
                targetid = $("._guru-card-item:last-child").data("id");
            }
        }
        $("._guru-card-dotted-item").removeClass("active");
        $('._guru-card-dotted-item[data-id="' + targetid + '"]').addClass(
            "active"
        );
    });

    $("._guru-card-dotted-item").click(function () {
        $("._guru-card-dotted-item").removeClass("active");
        $(this).addClass("active");
        $("._guru-card-item").removeClass("active");
        $('._guru-card-item[data-id="' + $(this).data("id") + '"]').addClass(
            "active"
        );
    });

    // $("#subscriber").submit(function (e) {
    //     e.preventDefault();
    //     $("#email_subscriber + span").removeClass("active");

    //     let email = $("#email_subscriber").val();
    //     if (validateEmail(email)) {
    //         $("#subscriber_modal").modal("show");
    //         $.get("/addsubscribe/" + email, function () {});
    //     } else {
    //         $("#email_subscriber + span").addClass("active");
    //     }
    // });
});

function setOptionModel(brand_id, crkp_id, catid, box_id) {
    let category = catid == 158 ? 'car' : 'motorcycle';

    let obj = $('#'+ box_id);

    $.get("/" + category + "/search?lookup=branditem&amp;_brand=" + brand_id + "&amp;_cat=" + catid + "&amp;method=api", function (res) {
        obj.find(".krungsrical-model").empty();
        obj.find(".krungsrical-model").append("&lt;option&gt;เลือกรุ่น&lt;/option&gt;");
        obj.find(".krungsrical-model").append(res);
        // for (i in res) {
        //     obj.find(".krungsrical-model").append(
        //         '&lt;option value="' + res[i][0] + '" data-price="' + res[i][2] + '" data-image="' + res[i][3] + '"&gt;' + res[i][1] + "&lt;/option&gt;"
        //     );
        // }

        obj.find(".krungsrical-brand").val(brand_id);
        obj.find(".krungsrical-model").val(crkp_id);

        // alert(disable);
        // if(disable == true){
        //     obj.find(".krungsrical-brand").prop("disabled", true);
        //     obj.find(".krungsrical-model").prop("disabled", true);
        // }


        let opt = obj.find('.krungsrical-model option[value="' + crkp_id + '"]');
        obj.find(".krungsrical-image img").attr("src", opt.attr("data-image"));
        obj.find(".krungsrical-price").text(opt.attr("data-price_text"));
        obj.find(".krungsrical-preview").removeClass("d-none");
    });
}

$(function () {
    $(".krungsri-calc-btn").each(function (i) {
        let krungsri_data = {
            rand: Math.random(),
            k: $(this).data("k"),
            category_id: $(this).data("category_id"),
            type: $(this).data("type"),
            brand: $(this).data("brand"),
            model: $(this).data("model"),
            sub_model: $(this).data("sub_model"),
            price: $(this).data("price"),
            cc: $(this).data("cc"),
            year: $(this).data("year"),
            page: window.location.href,
            promptstart_login: $(this).data("promptstart_login"),
        };
        let krungsri_id = $(this).data("id");
        $.get(AdsUrl +  "/krungsri/table/check/",krungsri_data,function (_result) {
            if (_result == "true") {
                $("#" + krungsri_id).removeClass("d-none");
                $("#" + krungsri_id).parent().removeClass("d-none");
            }
        });
    });
});

$(document).on("click", ".krungsri-calc-btn", function () {
    let catid = $(this).data("category_id");
    brand_id = $(this).data("brand_id");
    crkp_id = $(this).data("crkp_id");
    _url = AdsUrl +  "/krungsri/table/calc/";
    $.get(_url,{
            rand: Math.random(),
            k: $(this).data("k"),
            category_id: $(this).data("category_id"),
            type: $(this).data("type"),
            cc: $(this).data("cc"),
            price: $(this).data("price"),
            down_percent: $(this).data("down_percent"),
            down_price: $(this).data("down_price"),
            logo: $(this).data("logo"),
            brand: $(this).data("brand"),
            model: $(this).data("model"),
            sub_model: $(this).data("sub_model"),
            year: $(this).data("year"),
            name: $(this).data("name"),
            page: window.location.href,
            withform: true,
            withcompact: true,
            withcompare: false,
            promptstart_login: $(this).data("promptstart_login"),
        },
        function (_data) {
            if (_data) {
                $("#krungsri_cal_modal .krungsri-calc-box").html(_data);
            } else {
                $("#krungsri_cal_modal .krungsri-calc-box").remove();
            }
        }
    );

    _stat_url = AdsUrl + '/krungsri/stat/update/';
    $.post(_stat_url,
    {
        'rand' : Math.random(),
        k: $(this).data("k"),
        category_id: $(this).data("category_id"),
        type: $(this).data("type"),
        cc: $(this).data("cc"),
        price: $(this).data("price"),
        down_percent: $(this).data("down_percent"),
        down_price: $(this).data("down_price"),
        logo: $(this).data("logo"),
        brand: $(this).data("brand"),
        model: $(this).data("model"),
        sub_model: $(this).data("sub_model"),
        year: $(this).data("year"),
        name: $(this).data("name"),
        page: window.location.href,
        action : 'button',
        button: true
    });

    setOptionModel(brand_id, crkp_id, catid, 'krungsri_cal_modal', true);
});


$('#lead-form').validate({
    errorPlacement: function(error, element) {
        $(element)
            .closest("form")
            .find("label[for='" + element.attr("name") + "']")
            .html(error);
    },
    errorElement: "label",

    submitHandler: function() {

        var $form = $('#lead-form'),
            url = $form.attr("action");
        var form_data = $form.serialize();

        $.ajax({
            url: url,
            type: 'post',
            data: form_data,
            timeout: 60000
        }).done(function(response) {
            $('#leadpopup').modal('hide');
        });
    }
});

//lead form product detail page
$('#lead-form-detail').validate({
    errorPlacement: function(error, element) {
        $(element)
            .closest("form")
            .find("label[for='" + element.attr("name") + "']")
            .html(error);
    },
    errorElement: "label",

    submitHandler: function() {
        var $form = $('#lead-form-detail'),
            url = $form.attr("action");
        var form_data = $form.serialize();

        $.ajax({
            url: url,
            type: 'post',
            data: form_data,
            timeout: 60000
        }).done(function(response) {
            console.log("response :",response);
            alert('ส่งข้อมูลสำเร็จ!');
        });
    }
});

$('#dealer-submit-btn').click(function(){
    utm_code = $('#lead_utm_code').val();
    brand_id = $('#lead_brand_id').val();
    $('#leadpopup').modal();
})

$('.btn-lead').on('click',function(e)
{
    brand_id = $(this).data('brand_id');
    $('#lead_brand_id').val(brand_id);
    if(brand_id == 153){
        $('.lead_logo').attr('src', '/images/lead/isuzu.png');
    }else if(brand_id == 155){
        $('.lead_logo').attr('src', '/images/lead/kia.png');
    }else{
        $('.lead_logo').attr('src', '/images/lead/gwm.png');
    }

    $.get('/car/search?lookup=brand&amp;_cat=158&amp;_brand=' + brand_id, function (res) {
        $("#lead_model_id").empty();
        for (i in res) {
            $("#lead_model_id").append(
                '&lt;option value="' + res[i][0] + '"&gt;' + res[i][1] + "&lt;/option&gt;"
            );
        }
    });
    $('#leadpopup').modal('show');
})
</pre></body></html>