function get(name) {
  let script = document.currentScript
    if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(script.src)) {
        return decodeURIComponent(name[1]);
    }
}

function guid() {
    const uuid = () => (
        (
            [1e7] + -1e3 + -4e3 + -8e3 + -1e11
        ).replace(/[018]/g, c => (
            c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4
        ).toString(16))
    ).replace(new RegExp('-', 'g'), '');

    return uuid();
}

function getCookie(name) {
    let matches = document.cookie.match(new RegExp(
        "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
    ));
    return matches ? decodeURIComponent(matches[1]) : undefined;
}

function setCookie(cname, cvalue, exdays) {
    let d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 30 * 12 * 6 ));
    let expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/; SameSite=None; Secure";
    window.mars = cvalue;
}

function gaid() {
    var cookie_ga_user_id;
    if (document.cookie && document.cookie.match(/_ga=(.+?);/)) {
        cookie_ga_user_id = document.cookie.match(/_ga=(.+?);/)[1].split('.').slice(-2).join(".")
    } else {
        try {
            cookie_ga_user_id = ga.getAll()[0].get('clientId');
        } catch (e) {
            cookie_ga_user_id = ""
        }
    }
    return cookie_ga_user_id
}


setTimeout(function () {

    if (getCookie('mars') != undefined){
        let gui = getCookie('mars');
        window.mars = gui;
        var s33 = document.createElement('script');
        var domain = window.location.href
        
            s33.src = `https://cdn3.caltat.com/fbfc504c-89b0-4a80-bef4-c8e39daeee6f/sslba.php?idClient=61&idCampaign=` + 92090 + `&sonar=true&ru=true&url=${encodeURIComponent(window.location.href || document.referrer)}&ref=${document.referrer}&status=old&gi=${gui}&spid=${gaid()}`
        
        document.getElementsByTagName('head')[0].appendChild(s33);


    } else if (window.mars != undefined) {
        let gui = window.mars;
        setCookie('mars', gui, 1826);
        var s33 = document.createElement('script');
        var domain = window.location.href
        
            s33.src = `https://cdn3.caltat.com/fbfc504c-89b0-4a80-bef4-c8e39daeee6f/sslba.php?idClient=61&idCampaign=` + 92090 + `&sonar=true&ru=true&url=${encodeURIComponent(window.location.href || document.referrer)}&ref=${document.referrer}&status=old&gi=${gui}&spid=${gaid()}`
        
        document.getElementsByTagName('head')[0].appendChild(s33);
    }
    else{
        let gui = guid();
        setCookie('mars', gui, 1826);
        var s33 = document.createElement('script');
        var domain = window.location.href
        
            s33.src = `https://cdn3.caltat.com/fbfc504c-89b0-4a80-bef4-c8e39daeee6f/sslba.php?idClient=61&idCampaign=` + 92090 + `&sonar=true&ru=true&url=${encodeURIComponent(window.location.href || document.referrer)}&ref=${document.referrer}&status=new&gi=${gui}&spid=${gaid()}`
        
        document.getElementsByTagName('head')[0].appendChild(s33);

    }

}, 300);