function tebotOpen()
{
    iframe = document.getElementById('aime_fluent_chat');
    iframe.contentWindow.postMessage('_window_open_', '*');
    return false;
}
function tebotClose()
{
    iframe = document.getElementById('aime_fluent_chat');
    iframe.contentWindow.postMessage('_window_close_', '*');
    return false;
}
function myFunction() {

    if(false){
        parentUrl = window.location.href;
        if(parentUrl.includes('tebot.jp/portal/') || ! parentUrl.includes('tebot.jp/') ){
            return false;
        }
    }

    window.AIME_FLUENT_DEFAULT_OPEN = false;
    window.addEventListener("message",
        function (e) {
            if (!e) {
                return;
            }
            if (e.data === "_aime_chat_open_") {
                if(iframe$.classList.contains('pc')){
                    iframe$.style = "z-index:99999;  max-height: 570px;  height: 100%;  max-width: 100%;  width: 420px;  position: fixed;  right: 0;  bottom: 0;  border: none;  background: none;";
                }else{
                    iframe$.style = "z-index:99999;  max-height: 570px;  height: 100%;  max-width: 390px; width: 100%; position: fixed; right: 0;  bottom: 0;  border: none;  background: none;";
                }
                iframe$.classList.add('chat-open');
                iframe$.classList.remove('chat-close', 'chat-shutdown');
            } else if (e.data === "_aime_chat_close_") {
                if(iframe$.classList.contains('pc')){
                    iframe$.style = "z-index:99999;  max-height: 120px; height: 100%;  width: 300px;  position: fixed;  right: 20px;  bottom: 50px;  border: none;  background: none;  transition-delay:0.4s;";
                }else{
                    iframe$.style = "z-index:99999;  max-height: 120px; height: 100%;  width: 85px;  position: fixed;  right: 10px;  bottom: 80px;  border: none;  background: none;  transition-delay:0.4s;";
                }
                iframe$.classList.add('chat-close');
                iframe$.classList.remove('chat-open', 'chat-shutdown');
            } else if (e.data === "_aime_chat_shut_down_") {
                iframe$.style.maxHeight = "0px";
                iframe$.style.width = "0px";
                iframe$.classList.add('chat-shutdown');
                iframe$.classList.remove('chat-open', 'chat-close');
            } else if (e.data === "_aime_chat_ready_") {
                if (window.AIME_FLUENT_DEFAULT_OPEN) {
                    iframe$.contentWindow.postMessage("_expand_", "*");
                }
            } else if (e.data === "_aime_get_href_") {
                iframe$.contentWindow.postMessage('_href_' + window.location.href, '*');
                // e.originEvent.source.postMessage("_aime_return_href_", "*", window.location.href);
            } else if (e.data === "_aime_get_parent_width_") {
                // Send parent width back to iframe
                iframe$.contentWindow.postMessage({
                    type: 'parent_width',
                    width: window.innerWidth
                }, '*');
            }

        }, false);


    var div$ = document.createElement("div");
    div$.setAttribute("id", "JKChatView_place_holder");
    div$.setAttribute("style", "max-height: 95px;");
    var iframe$ = document.createElement("iframe");
    iframe$.setAttribute("id", "aime_fluent_chat");
    document.body.appendChild(div$);
    div$.appendChild(iframe$);
    if ("" == "1") {
        iframe$.src = "https://tebot.jp/bot/1127/render_bot_v9?lang=ja&bot_lang=ja&allow_input_text=&code=";
    } else if ('false' == 'true') {
        iframe$.src = "https://tebot.jp/bot/1127/render_bot_v9?lang=ja&bot_lang=ja&embed_page=true&code=";
    } else {
        iframe$.src = "https://tebot.jp/bot/1127/render_bot_v9?lang=ja&bot_lang=ja&code=";
    }

    if (window.matchMedia( "(max-width: 750px)" ).matches) {
        // for sp
        iframe$.style = "z-index:99999;  max-height: 120px; height: 100%;  width: 85px;  position: fixed;  right: 10px;  bottom: 80px;  border: none;  background: none;  transition-delay:0.4s;";
        iframe$.style.display = 'none';
        iframe$.classList.add('sp');
        iframe$.classList.remove('pc');
        iframe$.onload = function(){
            iframe$.contentWindow.postMessage('_set_sp_class_', '*');
            iframe$.style.display = 'block';
        };
    } else {
        // for pc
        iframe$.style = "z-index:99999;  max-height: 120px; height: 100%;  width: 300px;  position: fixed;  right: 20px;  bottom: 50px;  border: none;  background: none;  transition-delay:0.4s;";
        iframe$.classList.add('pc');
        iframe$.classList.remove('sp');
        iframe$.onload = function(){
            iframe$.contentWindow.postMessage('_set_pc_class_', '*');
        };
    }
    if ('false' == 'true') {
        window.addEventListener("scroll", (event) => {
            iframe = document.getElementById('aime_fluent_chat');
            iframe.contentWindow.postMessage('_parent_scroll_' + window.scrollY, '*');
        });
    }
};
myFunction();