/*===============================================*\
|| ############################################# ||
|| # JAKWEB.CH / Version 5.1.2                 # ||
|| # ----------------------------------------- # ||
|| # Copyright 2024 JAKWEB All Rights Reserved # ||
|| ############################################# ||
\*===============================================*/

var lcjakwidgetid = 1;
var lcj_container = document.getElementById('jaklcp-chat-container');

function lcjak_chatWidget(id, data, origdomain) {
    if (data.widgethtml) {
        lcj_container.setAttribute("style", "position:fixed;right:0;bottom:0;width:0px;height:0px;");
        lcj_container.innerHTML = data.widgethtml;
        var lcj_resize = function (e) {
            if (lcjak_extractDomain(e.origin) !== origdomain) {
                return false
            }
            if (lcj_container) {
                message = e.data.split("::");
                if (message[0] == "redirecturl") {
                    window.location = message[1]
                } else if (message[0] == "knockknock") {
                    alert(message[1])
                } else if (message[0] == "customerdata") {
                    if (!localStorage.getItem('lcjak_customer')) localStorage.setItem('lcjak_customer', message[1])
                } else if (message[0] == "chatstatus") {
                    localStorage.setItem('lcjak_chatstatus', message[1])
                } else if (message[0] == "removedata") {
                    if (localStorage.getItem('lcjak_customer')) localStorage.removeItem('lcjak_customer')
                } else {
                    if (message[0] == "iframe_size") {
                        lcj_container.setAttribute("style", message[1])
                    }
                    lcjak_pageloaded(id, data.url, "customvars::" + data.customvars);
                    lcjak_pageloaded(id, data.url, "lcjak_session::" + data.rlbid)
                }
            }
        };
        if (window.addEventListener) {
            window.addEventListener("message", lcj_resize, false)
        } else if (window.attachEvent) {
            window.attachEvent("onmessage", lcj_resize)
        }
    }
    return true
}

function lcjak_pageloaded(id, origurl, message) {
    var iframeW = document.getElementById("livesupportchat" + id).contentWindow;
    if (iframeW.postMessage) iframeW.postMessage(message, origurl)
}

function lcjak_loadchat(w) {
    lcjakwidgetid = w.id;
    if (w?.lcjUrl)
        chatloc = JSON.parse(JSON.stringify(w.lcjUrl));
    if (!localStorage.getItem('lcjak_chatstatus')) localStorage.setItem('lcjak_chatstatus', "closed");
    var lcjak_chatstatus = localStorage.getItem('lcjak_chatstatus');
    var lcjak_session = "0";
    if (localStorage.getItem('lcjak_session')) lcjak_session = localStorage.getItem('lcjak_session');
    var lcjak_firstvisit = "0";
    if (localStorage.getItem('lcjak_firstvisit')) lcjak_firstvisit = localStorage.getItem('lcjak_firstvisit');
    var lcjak_geodata = "0";
    if (localStorage.getItem('lcjak_geodata')) lcjak_geodata = localStorage.getItem('lcjak_geodata');
    var lcjak_customer = "0";
    if (localStorage.getItem('lcjak_customer')) lcjak_customer = localStorage.getItem('lcjak_customer');
    if (lcjak_extractDomain(w.lcjUrl) == window.location.hostname) {
        var request = new XMLHttpRequest();
        request.open('POST', chatloc + 'include/loadiframe.php?id=' + lcjakwidgetid + '&currenturl=' + encodeURI(window.location), true);
        request.timeout = 3000;
        request.onload = function () {
            if (request.status >= 200 && request.status < 400) {
                var data = JSON.parse(request.responseText);
                if (data.status) {
                    if (data.customvars) {
                        localStorage.setItem('lcjak_customvars', data.customvars)
                    } else {
                        localStorage.removeItem('lcjak_customvars')
                    }
                    localStorage.setItem('lcjak_clientos', data.clientos);
                    if (data.firstvisit != 0) localStorage.setItem('lcjak_firstvisit', data.firstvisit);
                    if (data.geodata) localStorage.setItem('lcjak_geodata', data.geodata);
                    localStorage.setItem('lcjak_session', data.rlbid);
                    localStorage.setItem('lcjak_lastvisit', data.lastvisit);
                    lcjak_chatWidget(lcjakwidgetid, data, lcjak_extractDomain(w.lcjUrl));
                    return true
                } else {
                    console.log(data.error)
                }
            } else { }
        };
        request.onerror = function () { };
        request.ontimeout = function (e) { };
        var formData = new FormData();
        formData.append("lang", w.lang);
        formData.append("name", w.cName);
        formData.append("email", w.cEmail);
        formData.append("msg", w.cMessage);
        formData.append("cstatus", lcjak_chatstatus);
        formData.append("rlbid", lcjak_session);
        formData.append("firstvisit", lcjak_firstvisit);
        formData.append("customer", lcjak_customer);
        formData.append("geo", lcjak_geodata);
        request.send(formData)
    } else {
        var url = chatloc + 'include/loadiframe_cross.php?id=' + lcjakwidgetid + '&crossurl=' + encodeURI(window.location) + '&callback=LiveChatJAK';
        var request = lcjak_createCORSRequest('POST', url);
        if (!request) {
            console.log('CORS not supported');
            return
        }
        request.onload = function () {
            var data = JSON.parse(request.responseText);
            if (data.status) {
                if (data.customvars) {
                    localStorage.setItem('lcjak_customvars', data.customvars)
                } else {
                    localStorage.removeItem('lcjak_customvars')
                }
                localStorage.setItem('lcjak_clientos', data.clientos);
                if (data.firstvisit != 0) localStorage.setItem('lcjak_firstvisit', data.firstvisit);
                if (data.geodata) localStorage.setItem('lcjak_geodata', data.geodata);
                localStorage.setItem('lcjak_session', data.rlbid);
                localStorage.setItem('lcjak_lastvisit', data.lastvisit);
                lcjak_chatWidget(lcjakwidgetid, data, lcjak_extractDomain(w.lcjUrl));
                return true
            } else {
                console.log(data.error)
            }
        };
        request.onerror = function () {
            console.log('Woops, there was an error making the request.')
        };
        var formData = new FormData();
        formData.append("lang", w.lang);
        formData.append("name", w.cName);
        formData.append("email", w.cEmail);
        formData.append("msg", w.cMessage);
        formData.append("cstatus", lcjak_chatstatus);
        formData.append("rlbid", lcjak_session);
        formData.append("firstvisit", lcjak_firstvisit);
        formData.append("customer", lcjak_customer);
        formData.append("geo", lcjak_geodata);
        request.send(formData)
    }
}

function lcjak_extractDomain(url) {
    var domain;
    if (url.indexOf("://") > -1) {
        domain = url.split('/')[2]
    } else {
        domain = url.split('/')[0]
    }
    domain = domain.split(':')[0];
    return domain
}

function lcjak_createCORSRequest(method, url) {
    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;
    if ("withCredentials" in xhr) {
        xhr.open(method, url, true)
    } else if (typeof XDomainRequest != "undefined") {
        xhr = new XDomainRequest();
        xhr.open(method, url)
    } else {
        xhr = null
    }
    return xhr
} (function (w) {
    lcjak_loadchat(w)
}(window));