/* Js for , Version=1791281838 */
 if(typeof(v) != "object") v = {};v.theme = {"template":"default","theme":"wide","device":"desktop"};;v.lang = {"confirmDelete":"您确定要执行删除操作吗？","deleteing":"删除中","doing":"处理中","loading":"加载中","updating":"更新中...","timeout":"网络超时,请重试","errorThrown":"执行出错：","continueShopping":"继续购物","required":"必填","back":"返回","continue":"继续","bindWechatTip":"发帖功能设置了绑定微信的限制，请先绑定微信会员。","importTip":"只导入主题的风格和样式","fullImportTip":"将会导入测试数据以及替换站点文章、产品等数据"};;
$(function()
{
    var $link = $('#navbar').find('.js-try-for-free');
    if(!$link.length) return;

    var raw = $.cookie('siteContext');
    if(!raw) return;

    var siteContext = {};
    try
    {
        siteContext = JSON.parse(raw) || {};
    }
    catch(e)
    {
        return;
    }

    var siteNumber = parseInt(siteContext.siteNumber, 10);
    if(isNaN(siteNumber)) siteNumber = 0;

    var defaultTryUrl = $link.data('defaultTryUrl');
    var chooseSiteUrl = $link.data('chooseSiteUrl');
    var loginSiteTpl  = $link.data('loginSiteTpl');
    var siteID        = siteContext.siteID || '';
    var userSite      = siteContext.userSite || '';

    if(defaultTryUrl) $link.attr('href', defaultTryUrl);

    if(siteNumber > 1)
    {
        $link.attr('href', chooseSiteUrl);
        return;
    }

    if(siteNumber === 1 && userSite && siteID && loginSiteTpl)
    {
        $link.attr('href', loginSiteTpl.replace('__SITE_ID__', siteID));
    }
});
;v.path = [""];;v.objectType = "article";;v.objectID = 15;;v.categoryID = null;;v.categoryPath = [""];;const demoForm = document.getElementById("application-form");
const demoFormCard = document.getElementById("demo-form-card");

function validateDemoField(field) {
  const input = field.querySelector("input");
  const value = input.value.trim();
  let isValid = true;

  if (!value) {
    isValid = false;
  } else if (input.type === "email") {
    isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
  }

  field.classList.toggle("is-invalid", !isValid);
  return isValid;
}

demoForm.querySelectorAll(".field input").forEach(function (input) {
  input.addEventListener("input", function () {
    validateDemoField(input.closest(".field"));
  });
});

demoForm.addEventListener("submit", function (event) {
  event.preventDefault();

  const fields = Array.from(demoForm.querySelectorAll(".field"));
  const isFormValid = fields.every(validateDemoField);

  if (!isFormValid) {
    const firstInvalidField = demoForm.querySelector(".field.is-invalid input");
    if (firstInvalidField) {
      firstInvalidField.focus();
    }
    return;
  }
});

$.setAjaxForm('#application-form', function(response)
{
    if(response.result == 'success') location.href = '/cn/demo-request-success.html';
    if(response.result == 'fail') {
      $('#application-form .button-primary').popover({container:'body', trigger:'manual', content:response.message, placement: 'right', tipClass: 'popover-danger popover-ajaxform'}).popover('show');
    }
});
;v.pageLayout = "global";;$(document).ready(function()
{
    $('#copyBox').hide().find(':input').attr('disabled', true);
    $('#source').change(function()
    {
        $('#copyBox').hide().find(':input').attr('disabled', true);
        if($(this).val() != 'original') $('#copyBox').show().find(':input').attr('disabled', false);
    });

    /* Set current active topNav. */
    var hasActive = false;
    if(v.categoryID > 0 && $('.nav-article-' + v.categoryID).length >= 1)
    {
        hasActive = true;
        $('.nav-article-' + v.categoryID).addClass('active');
    }

    if(v.categoryPath && v.categoryPath.length)
    {
        $.each(v.categoryPath, function(index, category)
        {
            if(!hasActive)
            {
                if($('.nav-article-' + category).length >= 1) hasActive = true;
                $('.nav-article-' + category).addClass('active');
            }
        });
    }
    else if(v.path && v.path.length)
    {
        $.each(v.path, function(index, category)
        {
            if(!hasActive)
            {
                if($('.nav-article-' + category).length >= 1) hasActive = true;
                $('.nav-article-' + category).addClass('active');
            }
        });
        if(!hasActive) $('.nav-article-0').addClass('active');
    }

    if(v.categoryID !== 0) $('#category' + v.categoryID).parent().addClass('active');
    $('#navbar li.active').parents('li').addClass('active');
});
$(document).ready(function()
{
    function basename(str)
    {
        var pos = str.lastIndexOf('/');
        return str.substring(pos + 1,str.length);
    }

    $('body').tooltip(
    {
        html: true,
        selector: "[data-toggle=tooltip]",
        container: "body"
    }); 

    $('.article-content img').click(function(){
        var itemSrc  = $(this).attr('src');
        var itemName = basename(itemSrc).split('&')[0];
        if(typeof(itemName) == 'string')
        {
            $('.article-files .' + itemName).click();
        }
    });

    if($('.previous > a > span').width() > $('.previous > a').width())
    {
        previousSpanWidth = $('.previous > a').width() - $('.previous .icon-arrow-left').width() - 10;
        $('.previous > a > span').css('width', previousSpanWidth);
    }

    if($('.next > a > span').width() > $('.next > a').width())
    {
        nextSpanWidth = $('.next > a').width() - $('.next .icon-arrow-right').width() - 10;
        $('.next > a > span').css('width', nextSpanWidth);
    }
});
var lang = $.cookie('browseLang');
if (!lang) {
  lang = /^zh/i.test(navigator.language || '') ? 'zh-cn' : 'en';

  $.cookie('browseLang', lang, {
      expires: 365,
      path: '/',
      secure: true,
      sameSite: 'lax'
  });

  var url = new URL(location.href);
  var isCnPath =
      url.pathname === '/cn' ||
      url.pathname.indexOf('/cn/') === 0;

  if (lang === 'en' && isCnPath) {
      // /cn、/cn/XXX -> /、/XXX
      url.pathname = url.pathname.substring(3) || '/';
      location.replace(url.href);
  } else if (lang === 'zh-cn' && !isCnPath) {
      // /、/XXX -> /cn/、/cn/XXX
      url.pathname = '/cn' + url.pathname;
      location.replace(url.href);
  }
}
;
$(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));
    });
})
