/* Js for , Version=1775291348 */
 v.lang = {"confirmDelete":"Do you want to delete it?","deleteing":"Deleting","doing":"Doing","loading":"Loading","updating":"Updating","timeout":"Timeout. Please try it again.","errorThrown":"Error : ","continueShopping":"Continue shopping","required":"Required","back":"Back","continue":"Continue","bindWechatTip":"Posting sets the limit for binding WeChat. Please bind WeChat user first.","importTip":"Old layout data will be replaced","fullImportTip":"Old article, product, layout data will be replaced and import test data"};; (function(c,l,a,r,i,t,y){
        c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
        t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
        y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "ob6lnnhebh");;v.pageID = 1592;;$(function()
{
    var clip;
    $('.copy').hover(function(e) {
        clip = new ClipboardJS(e.currentTarget);
    }, function(e) {
        clip.destroy();
    });
    $('.copy').click(function(e) {
        var copyElement = $(this);
        clip.on('success', function (e) {
          copyElement.find('.copy-tips').show();
          setTimeout(function() {
              copyElement.find('.copy-tips').hide();
          }, 2500);
        });
    });
    
    setTimeout(function(){$('a[href="/on-premises.html"]').parent().addClass('active');}, 100);
});

$(function()
{
    // $('.download-btn').attr('data-downloadActive', 'false');
    
    var typeMap = {
        'windows-setup': 'amd64-setup.exe',
        'windows': 'amd64-portable.exe',
        'linux': 'amd64.tar.gz',
        'source': '.zip',
        'gogs': ''
    }
    
    var linuxTypeMap = {
        'deb': '-1_all.deb',
        'rpm': '-1.noarch.rpm',
        'source': '.zip',
        'linux': 'amd64.tar.gz',
        'linuxarm': 'arm64.tar.gz'
    }
    
    var gogsLink = {
        'MacOS AMD64': 'darwin_amd64',
        'MacOS ARM64': 'darwin_arm64',
        'Linux ARM64': 'linux_arm64',
        'Linux AMD64': 'linux_amd64',
        'Windows AMD64': 'windows_amd64.exe'
    }
    
    var downloadVersionMap = {
        'open': '21.7',
        'biz': 'biz12.0',
        'max': 'max7.0',
        'ipd': 'ipd4.0'
    }
    
    var bookLinkMap = {
        'windows': 'https://www.zentao.net/book/zentaopms/811.html',
        'linux': 'https://www.zentao.net/book/zentaopms/458.html',
        'source': 'https://www.zentao.net/book/zentaopms/1165.html'
    }
    
    var modalIdMap = {
        'open': '#pms20',
        'biz': '#biz10',
        'max': '#max5',
        'ipd': '#ipd2'
    }
    
    var downloadVersion = downloadVersionMap['open'];
    var downloadType    = typeMap['windows-setup'];
    var split           = '-';
    var phpVersion      = '';
    // changeDownloadLink(downloadVersion, downloadType, phpVersion, split, '.download-item.open .download-btn',false);
    // changeDownloadLink(downloadVersionMap['biz'], downloadType, phpVersion, split, '.download-item.biz .download-btn',false);
    // changeDownloadLink(downloadVersionMap['max'], downloadType, phpVersion, split, '.download-item.max .download-btn',false);
    // changeDownloadLink(downloadVersionMap['ipd'], downloadType, phpVersion, split, '.download-item.ipd .download-btn',false);
    
    $('.download-picker .selected').click(function(e)
    {
      e.stopPropagation();
      $(this).next('.type-list').toggle();
      $('.dropdown').removeClass('open');
    });
    $('.download-picker .type-list li').click(function(e)
    {
        e.stopPropagation();
        $(this).parent().siblings('.selected').find('.system').html($(this).html());
        $(this).parent('.type-list').hide();
        
        var target = $(this).data('target');
        $(this).parents('.download-content').find(`.${target}`).removeClass('hidden').siblings('.dropdown-menu').addClass('hidden');
        var defaultShow = $(this).parents('.download-content').find(`.${target} li:first-child a`).html();
        $(this).parents('.download-content').find('.dropdown .select-version').html(defaultShow);
        
        downloadType = typeMap[target];
        if(target == 'source') phpVersion = defaultShow.replace(' ', '').toLocaleLowerCase();
        if(target != 'source') phpVersion = '';
        $('.download-btn').attr('data-downloadactive', 'false');
        const currentBtn = $(this).parents('.download-item').find('.download-btn');
        if(target == 'gogs')
        {
            // changeDownloadLink(gogsLink['MacOS AMD64'], 'gogs', '', '', currentBtn, true);
        }
        else if(target == 'docker' || target == 'z')
        {
            $(this).parents('.download-item').find(`.${target} a` ).click();
        }
        else {
            // changeDownloadLink(downloadVersionMap[$(this).parents('.download-item').data('type')], downloadType, phpVersion, split, currentBtn, true);
        }
        
        $(this).parents('.download-item').find('.link-book').attr('href', bookLinkMap[target]);
    });
    $(document).on('click', function()
    {
        $('.download-picker .type-list').hide();
    });
    $('.dropdown-menu > li').click(function()
    {
        if($(this).hasClass('dropdown-submenu')) return;
        var showHtml = $(this).find('a').html();
        if($(this).parents('li').hasClass('dropdown-submenu')) showHtml = $(this).parents('.dropdown-submenu').find('.linux-type').html() + ' ' + showHtml
        $(this).parents('.dropdown').find('button .select-version').html(showHtml);
        
        var target = $(this).find('a').data('target');
        if(!target.includes('windows'))
        {
            var downloadType = linuxTypeMap[target];
            $('.download-btn').attr('data-downloadActive', 'false');
            const currentBtn = $(this).parents('.download-item').find('.download-btn');
            if(downloadType)
            {
                if(['deb', 'rpm', 'source'].includes(target))
                {
                    split = '-';
                    phpVersion = $(this).find('a').html().replace(' ', '').toLocaleLowerCase();
                    if(target == 'deb') split = '_';
                    phpVersion = phpVersion.replace('-', '_');
                }
                if(!['deb', 'rpm', 'source'].includes(target)) phpVersion = '';
                // changeDownloadLink(downloadVersionMap[$(this).parents('.download-item').data('type')], downloadType, phpVersion, split, currentBtn, true);
            }
            else
            {
                var modalTarget = modalIdMap[$(this).parents('.download-item').data('type')];
                if(target == 'docker') var modalTarget = modalTarget + 'Docker';
                // changeDownloadLink(modalTarget, 'docker', '', '', currentBtn, true);
            }
        }
        else
        {
            $('.download-btn').attr('data-downloadActive', 'false');
            const currentBtn = $(this).parents('.download-item').find('.download-btn');
            // changeDownloadLink(downloadVersionMap[$(this).parents('.download-item').data('type')], typeMap[target], '', split, currentBtn, true);
        }
    });
    
    if($(window).width() < 768)
    {
        $('.dropdown-submenu').click(function(e)
        {
            e.stopPropagation();
        });
        $('.dropdown-submenu .dropdown-menu li').click(function(e)
        {
            $(this).parents('.dropdown').removeClass('open');
            $('.dropdown-backdrop').remove();
        });
    }
    
    function changeDownloadLink(version, type, phpVersion, split, ele, isActive = false)
    {
        var downloadLink = '';
        // var versionLib = version.replace('.beta', '');
        var match = /^(\d+\.\d+)(\.\d+)?$/.exec(version);
        var versionLib = match ? match[1] : version;
        if(type === 'gogs') downloadLink = `https://www.zentao.net/dl/gogs/0.12/gogs_${version}`;
        if(type !== 'gogs') downloadLink = `https://www.zentao.net/dl/zentao/${versionLib}/zentao${split}${version}-${phpVersion}${type}`;
        if(type === 'docker') downloadLink = version;
    
        $(ele).attr({
            'data-downloadLink': downloadLink,
            'data-downloadActive':  isActive ? 'true' : 'false'
        });
        $(ele).off('click.download').on('click.download', function(e) {
            $(ele).removeAttr('data-toggle data-target href');
            $('.download-btn').attr('data-downloadActive', 'false');
            $('.download-btn').attr('data-downloadType', '');
            $(this).attr('data-downloadActive', 'true');
            if(type === 'docker') $(this).attr('data-downloadType', 'docker')
            
            if(type === 'docker')
            {
                $(ele).attr('data-toggle', 'modal').attr('data-target', downloadLink)
            }
            else
            {
                window.location.href = downloadLink;               
            }
        });
    }
});

;v.pageLayout = "object";;$(function()
{
    if($('.siteNav .username').length > 0)
    {
        if($.cookie('siteNumber') && $.cookie('siteNumber') > 1)
        {
            $('.trial').attr('href', '/paas-choosesite.html');
            $('.trial').attr('target', '_blank');
        }
        else
        {
            if($.cookie('userDomain'))
            {
                $('.trial').attr('href', '/crosslogin-ajaxLoginSite-' + $.cookie('siteID'));
                $('.trial').attr('target', '_blank');
            }
        }
    }
});;$('.btn.reject').click(function(){localStorage.setItem('collectCookie', 'reject'); $('.collect-cookie').removeClass('active');});
$('.btn.accept').click(function(){localStorage.setItem('collectCookie', 'accept'); $('.collect-cookie').removeClass('active');});
$('.icon-close').click(function(){$('.collect-cookie').removeClass('active');});
if(!localStorage.getItem('collectCookie') || localStorage.getItem('collectCookie') == 'reject') $('.collect-cookie').addClass('active');;$(document).ready(function()
{
    $('.nav-page-' + v.pageID + ':first').addClass('active');
    $('#navbar li.active').parents('li').addClass('active');

    function basename(str)
    {
        var pos = str.lastIndexOf('/');
        return str.substring(pos + 1,str.length);
    }

    $('.article-content img').click(function(){
        var itemSrc  = $(this).attr('src');
        var itemName = basename(itemSrc).split('&')[0];
        if(typeof(itemName) == 'string')
        {
            $('.files-list .' + itemName).click();
        }
    });
});
$(document).ready(function()
{
    $('.footwrap').parent().insertBefore('#footer');
    
    if(typeof headerList != 'undefined') return false;
    headerList = true;
    
    $("#words").attr('placeholder','Search');
    
    $(".search-but").click(function(){
        // $(this).addClass('hidden');
        $(this).siblings().toggleClass('active');
    });
    
    $('#searchbar .icon-close').click(function()
    {
       $(this).parents('form').removeClass('active').siblings('.search-but').removeClass('hidden'); 
    });
    
    $("#reg #panel-pure #heading-title").text('Register');
    $("#login #login-region .panel-heading span").text('Login'); 
    $(".m-user-login .page-wrapper").before(`<div class="banner-wrap"><div class="banner"><h3>Welcome to login</h3></div></div>`);
    $(".m-user-register .page-wrapper").before(`<div class="banner-wrap"><div class="banner"><h3>Welcome to register</h3></div></div>`);
    $(".m-extension .page-wrapper").before(`<div class="banner-wrap"><div class="banner"><h3>Extension</h3></div></div>`);
    
    if(location.pathname.includes('download')) 
    {
        $('.article table a').click(function(e)
        {
            e.preventDefault();
            if($(this).attr('href').includes('dl'))
            {
                location.href = "/page/downloadComplete.html";
                sessionStorage.setItem('downloadUrl', $(this).attr('href'));
            }
        })
    }
    
    if(!location.href.includes('/page')) $('.navbar-nav li').removeClass('active');
});

// $(function(){
//     window.Intercom('boot', {
//       app_id: "buxeg11n",
//       bottom: 80,
//       right: 26,
//     });
// });

if(screen.width > 767){
    $("#navbar .dropdown").mouseover(function(e){
        $(this).addClass('open');
    });
    $("#navbar .dropdown").mouseout(function(e) {
        $(this).removeClass('open');
    });
};

function getCaptcha($ele)
{
    $.get(createLink('guarder', 'getCaptcha'), function(response)
    {
        if(response.result == 'success')
        {
            $ele.html(response.captchaContent);
        }
    })
}

$('#captchaBox').on('click', '.img-wrapper', function()
{
    getCaptcha($(this));
});

$('.signin').click(function()
{
    localStorage.setItem('signin', true);
});
;
$(document).ready(function()
{
    $('a[data-download=1]').each(function()
    {
        link = window.btoa(window.encodeURIComponent($(this).attr('href')));
        fileName = window.btoa(window.encodeURIComponent($(this).text()));
        $(this).attr('data-toggle', 'modal').attr('href', createLink('misc', 'download', 'link=' + link + '&fileName=' + fileName));
    });
})
;
    (function(d, w, c) {
        w.ChatraID = 'Cbq6Mh2awJjcBxaKu';
        var s = d.createElement('script');
        w[c] = w[c] || function() {
            (w[c].q = w[c].q || []).push(arguments);
        };
        s.async = true;
        s.src = 'https://call.chatra.io/chatra.js';
        if (d.head) d.head.appendChild(s);
    })(document, window, 'Chatra');
;
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-99909387-1');
;(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-W92V6QZ');;$('body').prepend(`<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W92V6QZ"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->`);;
function loadCartInfo(twinkle)
{
    $('#siteNav').load(createLink('misc', 'printTopBar'),
        function()
        {
            if(twinkle)
            {
                bootbox.dialog(
                {
                    message: v.addToCartSuccess,
                    buttons:
                    {
                        back:
                        {
                            label:     v.lang.continueShopping,
                            className: 'btn-primary',
                            callback:  function(){location.reload();}
                        },
                        cart:
                        {
                            label:     v.gotoCart,
                            className: 'btn-primary',
                            callback:  function(){location.href = createLink('cart', 'browse');}
                        }
                    }
                });
            }
        }
    );
}
;
var hash = window.location.hash.substring(1);
var browserLanguage = navigator.language || navigator.userLanguage;
var resolution      = screen.availWidth + ' X ' + screen.availHeight;
$.get(createLink('log', 'record', "hash=" + hash), {browserLanguage:browserLanguage, resolution:resolution});
