jQuery(document).ready(function ($) {
  $(document).on('click', '.next_btn', function () {
    // var lang = navigator.language;
    var lang = document.documentElement.lang;

    if (lang == 'ko-KR') {
      if (!$('#chk_kor').is(':checked')) {
        alert('개인정보 수집 동의해주셔야합니다.');
      }
    } else {
      if (!$('#chk_eng').is(':checked')) {
        alert('You have to agree privacy policy');
      }
    }
  });

  if ($(window).width() > 736) {
    AOS.init();
  }
  /////////////////////////////////////
  //  Wow js Active
  /////////////////////////////////////
  new WOW().init();
  /////////////////////////////////////
  //  SELECT CUSTOM
  /////////////////////////////////////
  $(document).on('click', '.chosen-container .chosen-single', function (e) {
    e.stopPropagation();
    if ($(this).parent().hasClass('active')) {
      if ($('.chosen-container').hasClass('active')) {
        $('.chosen-container').removeClass('active');
      }
      $(this).parent().removeClass('active');
    } else {
      if ($('.chosen-container').hasClass('active')) {
        $('.chosen-container').removeClass('active');
      }
      $(this).parent().addClass('active');
    }
    return false;
  });
  $(document).on('click', '.chosen-search input', function (e) {
    e.stopPropagation();
  });
  $(document).on('keyup', '.chosen-search input', function (e) {
    e.stopPropagation();
    let value = $(this).val().toLowerCase();
    $($(this).parent().next('ul').children('li')).filter(function () {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
    });
  });
  $(document).on('click', '.chosen-result li[data-index]', function () {
    let index = $(this).attr('data-index');
    let category = $(this).text();
    $(this).parent().children().removeClass('active');
    $(this).addClass('active');
    $(this).parents('.chosen-container').removeClass('active');
    //        $(this).parents('.chosen-container').find('.chosen-single .name').text(category);
    $(this)
      .parents('.chosen-container')
      .prev('select')
      .children('select option')
      .eq(parseInt(index))
      .prop('selected', true);
    let href = $(this).children().attr('href');
    if (href != '#') {
      $(this).children().trigger('click');
    }
    return false;
  });
  $(document).click(function (e) {
    if (e.target.className !== 'custom-select') {
      if ($('.chosen-container').hasClass('active')) {
        $('.chosen-container').removeClass('active');
      }
    }
    if (e.target.className !== 'has-sub') {
      $('.menu-map .has-sub ul').removeClass('visible');
    }
    if (e.target.className !== 'form-text') {
      if ($('.contact-page .form-contact .form-text textarea').val() == '') {
        $('.contact-page .form-contact .form-text').removeClass('active');
      }
    }
  });
  /////////////////////////////////////
  //  SHOW LANGUAGE
  /////////////////////////////////////
  $('.show-language').on('click', function () {
    // $(".wpml-ls-legacy-list-horizontal").slideToggle();
    return false;
  });
  /////////////////////////////////////
  //  SHOW MORE ABOUT BANNER TEXT
  /////////////////////////////////////
  $('.about-banner .show-more').on('click', function () {
    if ($(this).hasClass('active')) {
      $(this).removeClass('active');
      $('.more-dot').addClass('in');
      $('.more-content').removeClass('in');
    } else {
      $(this).addClass('active');
      $('.more-dot').removeClass('in');
      $('.more-content').addClass('in');
    }
    return false;
  });
  // console.log($("#period3 .list-year").innerHeight());
  setTimeout(function () {
    $('.history-box').each(function () {
      let id = $(this).attr('id');
      let history_height = $(this).find('.list-year').height();
      let last_history_height = $(this).find('.item').last().innerHeight();
      // console.log(history_height);
      let history_height_result = parseInt(
        history_height - last_history_height - 5
      );
      $('head').append(
        '<style> #' +
          id +
          ' .list-year:before{height:' +
          history_height_result +
          'px;}</style>'
      );
    });
  }, 100);
  /////////////////////////////////////
  //  HEADER FIXED
  /////////////////////////////////////
  $(window).bind('scroll', function (e) {
    var top = $(window).scrollTop();
    var admin_h = $('#wpadminbar').height();
    if (top > 120) {
      //Khoảng cách đã đo được
      $('header').addClass('fix-box');
      $('.breadcrumbs').addClass('fix-box');
      $('.sub-tab').addClass('fix-box');
      var header_h = $('header.fix-box').height();
      var breadcrum_h = $('.breadcrumbs.fix-box').height();
      $('main').css('padding-top', $('header').height());
      if ($('.sub-tab').length > 0) {
        $('.breadcrumbs').addClass('hide');
      }
      if ($(window).width() <= 600) {
        $('header').css('top', 0);
        $('.breadcrumbs').css('top', header_h);
        $('.sub-tab').css('top', header_h);
      } else {
        if (admin_h > 0) {
          $('header').css('top', admin_h);
          $('.breadcrumbs').css('top', header_h + admin_h);
          $('.sub-tab').css('top', header_h + breadcrum_h + admin_h);
          $('.sub-tab').css('top', header_h + admin_h);
        } else {
          $('header').css('top', 0);
          $('.breadcrumbs').css('top', header_h);
          $('.sub-tab').css('top', header_h);
        }
      }
    } else {
      $('main').removeAttr('style');
      $('header').removeClass('fix-box').removeAttr('style');
      $('.breadcrumbs').removeClass('fix-box').removeAttr('style');
      $('.sub-tab').removeClass('fix-box').removeAttr('style');
      if ($('.sub-tab').length > 0) {
        $('.breadcrumbs').removeClass('hide');
      }
    }
    let menu_h = 0;
    if (top > 108) {
      //Khoảng cách đã đo được
      if ($(window).width() <= 600) {
        $('.menu-mb').css('top', 0);
        menu_h = $(window).height();
      } else {
        if (admin_h > 0) {
          $('.menu-mb').css('top', admin_h);
          menu_h = $(window).height() - admin_h;
        } else {
          $('.menu-mb').css('top', 0);
          menu_h = $(window).height();
        }
      }
    } else {
      if (admin_h > 0) {
        $('.menu-mb').css('top', admin_h);
        menu_h = $(window).height() - admin_h;
      } else {
        $('.menu-mb').css('top', 0);
        menu_h = $(window).height();
      }
    }
    $('.menu-mb .scroll-wrapper').css('height', menu_h);
  });
  $('header .fa-bars').on('click', function (e) {
    e.preventDefault();
    $('.menu-mb').addClass('active');
    $('#overlay').fadeIn();
  });
  $('#overlay, .menu-mb .close').on('click', function () {
    $('.menu-mb').removeClass('active');
    $('#overlay').fadeOut();
  });
  $('.menu-mb')
    .find('.menu-item-has-children')
    .prepend('<i class="submenu-button fal fa-angle-down"></i>');
  $('.menu-mb')
    .find('.submenu-button')
    .on('click', function () {
      $(this).toggleClass('submenu-opened');
      if ($(this).parent().children('ul').hasClass('open')) {
        $(this).parent().children('ul').removeClass('open');
      } else {
        $(this).parent().children('ul').addClass('open');
      }
      $(this).parent().children('ul').slideToggle();
    });
  $('.scrollbar-inner').scrollbar();
  if ($('#wpadminbar').length > 0) {
    var header = $(window).height() - $('#wpadminbar').height();
  } else {
    var header = $(window).height();
  }
  $('.menu-mb .scroll-wrapper').css('height', header);
  if ($('#wpadminbar').length > 0) {
    $('.menu-mb').css('top', $('#wpadminbar').height());
  }
  /////////////////////////////////////
  //  SCROLL BAR
  /////////////////////////////////////
  var scollSize = $(document).height() - $(window).height() + 20;
  var delayBar;
  $(window).on('scroll', function () {
    $('.scrolling-bar').css({
      'z-index': '101',
      opacity: '1',
      width: ($(window).scrollTop() / scollSize) * 100 + '%',
    });
    clearTimeout(delayBar);
    delayBar = setTimeout(function () {
      $('.scrolling-bar').css({ opacity: '0', 'z-index': '0' }, 400);
    }, 400);
  });
  /////////////////////////////////////
  //  SIDE MENU IN HISTORY PAGE
  /////////////////////////////////////
  var lastId,
    topMenu = $('.history-period'),
    topMenuHeight = topMenu.outerHeight() / 16,
    // topMenuHeight = 80,
    // All list items
    menuItems = topMenu.find('a'),
    // Anchors corresponding to menu items
    scrollItems = menuItems.map(function () {
      var item = $($(this).attr('href'));
      if (item.length) {
        return item;
      }
    });

  // Bind click handler to menu items
  // so we can get a fancy scroll animation
  menuItems.click(function (e) {
    if ($('.history-content').length > 0) {
      var href = $(this).attr('href');
      // var class_name = href.split('#');
      $([document.documentElement, document.body]).animate(
        {
          scrollTop: $(href).offset().top - 120,
        },
        800,
        'swing',
        function () {
          $('html, body').removeClass('scrolling');
          $(e.target).removeClass('scrolling');
        }
      );
    }
    e.preventDefault();
  });
  if ($('.history-content').length > 0) {
    $('.history-nav li a').on('click', function (e) {
      var href = $(this).attr('href');
      // var class_name = href.split('#');
      if ($('header').hasClass('fix-box')) {
        var scroll_h = $(href).offset().top - 120;
      } else {
        var scroll_h = $(href).offset().top - 120 - $('header').height();
      }
      $([document.documentElement, document.body]).animate(
        {
          scrollTop: scroll_h,
        },
        800,
        'swing',
        function () {
          $('html, body').removeClass('scrolling');
          $(e.target).removeClass('scrolling');
        }
      );
      return false;
    });
    $('.list-history-mobi .item').on('click', function (e) {
      var href = $(this).attr('data-index');
      href = '#' + href;
      if ($('header').hasClass('fix-box')) {
        var scroll_h = $(href).offset().top - 120;
      } else {
        var scroll_h = $(href).offset().top - 120 - $('header').height();
      }
      $([document.documentElement, document.body]).animate(
        {
          scrollTop: scroll_h,
        },
        800,
        'swing',
        function () {
          $('html, body').removeClass('scrolling');
          $(e.target).removeClass('scrolling');
        }
      );
    });
  }
  // var height_window = $(window).scrollTop();
  var height_topHeader =
    $('header').outerHeight() + $('.history-banner').outerHeight();
  if ($(window).width() > 1500) {
    var left =
      $('.container').offset().left +
      $('.history-content .sec-body').outerWidth() +
      22;
  } else if ($(window).width() > 1400 && $(window).width() <= 1500) {
    var left =
      $('.container').offset().left +
      $('.history-content .sec-body').width() -
      44;
  } else if ($(window).width() > 1366 && $(window).width() <= 1400) {
    var left =
      $('.container').offset().left +
      $('.history-content .sec-body').width() -
      61;
  } else if ($(window).width() > 1280 && $(window).width() <= 1366) {
    var left =
      $('.container').offset().left +
      $('.history-content .sec-body').width() -
      81;
  } else {
    var left =
      $('.container').offset().left +
      $('.history-content .sec-body').width() -
      105;
  }

  $(window).scroll(function () {
    if ($('.history-box').length > 0) {
      let distance_wg = $('footer').offset().top - 800;
      // console.log(distance_wg);
      let height_window = $(window).scrollTop();
      let width_menu = $('.side-nav').outerWidth();
      let distance_sidebar = $('.history-content #period1 .period').offset()
        .top;
      let height_sidebar = $('.history-content #period1 .period').outerHeight();
      if (
        height_window >
          distance_sidebar + height_sidebar - height_topHeader + 200 &&
        height_window < distance_wg - height_topHeader + 200
      ) {
        $('.side-nav').addClass('fixed');
        $('.side-nav').css('left', left);
      } else {
        $('.side-nav').removeClass('fixed').removeAttr('style');
      }
      // Get container scroll position
      let fromTop = $(this).scrollTop() + topMenuHeight + 80;

      // Get id of current scroll item
      let cur = scrollItems.map(function () {
        if ($(this).offset().top - 120 < fromTop) return this;
      });
      // Get the id of the current element
      cur = cur[cur.length - 1];
      let id = cur && cur.length ? cur[0].id : '';

      if (lastId !== id) {
        lastId = id;
        // Set/remove active class
        menuItems
          .parent()
          .removeClass('active')
          .end()
          .filter("[href='#" + id + "']")
          .parent()
          .addClass('active');
      }
    }
  });
  $('.scroll-top').on('click', function () {
    $('html, body').animate({ scrollTop: 0 }, 800, 'swing');
  });
  $('.location-content .menu-map ul li').parents('li').addClass('has-sub');
  $('.location-content .menu-map ul li a').on('click', function () {
    $('.location-content .menu-map ul li').removeClass('selected');
    $(this).parent().addClass('selected');
    let href = $(this).attr('href');
    $(href).parent().children().removeClass('active');
    $(href).addClass('active');
    return false;
  });
  $('footer .wpml-ls-item-toggle').on('click', function () {
    if ($(this).hasClass('active')) {
      $(this).removeClass('active');
      $(this).siblings('ul').removeAttr('style');
    } else {
      $(this).addClass('active');
      $(this).siblings('ul').css('visibility', 'visible');
    }
    return false;
  });
  $('.register-button .link-regis').on('click', function () {
    let href = $(this).attr('href');
    console.log(href);
    //$("a[href='" + href + "']").trigger('click');
    $('#single-event-content .nav li').removeClass('active');
    setTimeout(function () {
      $('a[href="#single-registration"]').parent('li').addClass('active');
    }, 500);
  });

  $('.scroll-up').on('click', function () {
    $('html, body').animate(
      {
        scrollTop: 0,
      },
      700
    );
  });

  /////////////////////////////////////
  //  LOGIN / REGISTER
  /////////////////////////////////////
  $('header .btn-login, .head-login, .menu-mb .no-login .login').on(
    'click',
    function () {
      // $("#overlay").fadeIn();
      $('#login-op').fadeIn();
      $('#regiter-op').fadeOut();
      $('#lost-password').fadeOut();
      $('#reset-password').fadeOut();
      $('#login-op #login-op').css('display', 'block');
      return false;
    }
  );
  $('.head-register, .menu-mb .no-login .signup').on('click', function () {
    // $("#overlay").fadeIn();
    $('#login-op').fadeOut();
    $('#regiter-op').fadeIn();
    $('#regiter-op #regiter-op').css('display', 'block');
    return false;
  });
  /////////////////////////////////////
  //  CHECKED REMEMBER
  /////////////////////////////////////
  $('.vs-op-frm .custom-checkbox label').click(function () {
    $(this).parent().children('.remember').toggleClass('checked');
    if ($(this).parent().children('.remember').hasClass('checked')) {
      $(this).parent().children('.remember').val(1);
    } else {
      $(this).parent().children('.remember').val(0);
    }
  });
  /////////////////////////////////////
  //  VALIDATE EMAIL RETURN TRUE/FALSE
  /////////////////////////////////////
  function validateEmail($email) {
    let emailReg = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return emailReg.test($email);
  }
  /////////////////////////////////////
  //  CHECK LOGIN
  /////////////////////////////////////
  $('#login-op').on('click', '.btn-login', function () {
    let email, password;
    email = $('#login-op .email').val();
    password = $('#login-op .password').val();
    if (email == '' || password == '') {
      $('.form-group .txt').each(function () {
        if ($(this).val() === '') {
          if ($(this).attr('type') === 'email') {
            $(this).siblings('.error-empty').fadeIn();
            $(this).parents('.form-group').find('.error-reg').fadeOut();
          } else {
            $(this).siblings('.error-message').fadeIn();
          }
        } else {
          if ($(this).attr('type') === 'email') {
            if (validateEmail(email) === false) {
              $(this).siblings('.error-empty').fadeOut();
              $(this).parents('.form-group').find('.error-reg').fadeIn();
            } else {
              $(this).siblings('.error-message').fadeOut();
            }
          } else {
            $(this).siblings('.error-message').fadeOut();
          }
        }
      });
    } else {
      $('.form-group .txt').each(function () {
        $(this).parent().siblings('.error-message').fadeOut();
      });
      $('.vs-loading').show();
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        data: {
          action: 'checkLogin',
          username: email,
          password: password,
        },
        success: function (data) {
          $('.vs-loading').hide();
          if (data == '?register=true') {
            window.location.href = data;
          } else {
            $('#login-op .notify').fadeIn();
          }
        },
      });
    }
    return false;
  });
  /////////////////////////////////////
  //  CHECK REGISTER
  /////////////////////////////////////
  $('#regiter-op').on('click', '.btn-register', function (e) {
    e.preventDefault();
    let email, password, remember, post_id;
    email = $('#regiter-op .email').val();
    password = $('#regiter-op .password').val();
    re_password = $('#regiter-op .re-password').val();
    post_id = $('#regiter-op .post-id').val();
    if (
      email === '' ||
      password === '' ||
      re_password != password ||
      validateEmail(email) === false
    ) {
      $('.form-group .txt').each(function () {
        if ($(this).val() === '') {
          if ($(this).attr('type') === 'email') {
            $(this).siblings('.error-empty').fadeIn();
            $(this).parents('.form-group').find('.error-reg').fadeOut();
          } else {
            $(this).siblings('.error-message').fadeIn();
          }
        } else {
          if ($(this).attr('type') === 'email') {
            if (validateEmail(email) === false) {
              $(this).siblings('.error-empty').fadeOut();
              $(this).parents('.form-group').find('.error-reg').fadeIn();
            } else {
              $(this).siblings('.error-message').fadeOut();
            }
          } else {
            $(this).siblings('.error-message').fadeOut();
          }
        }
      });
      if (re_password != password) {
        $('#regiter-op .notify.psw').fadeIn();
      } else {
        $('#regiter-op .notify.psw').fadeOut();
      }
    } else {
      $('.form-group .txt').each(function () {
        $(this).parent().siblings('.error-message').fadeOut();
      });
      $('#regiter-op .notify.psw').fadeOut();
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        data: {
          action: 'checkRegister',
          email: email,
          password: password,
          post_id: post_id,
        },
        beforeSend: function () {
          $('#regiter-op .vs-loading').show();
        },
        success: function (data) {
          var result = jQuery.parseJSON(data);
          $('#regiter-op .vs-loading').hide();
          if (result.msg == '') {
            $('#regiter-op .notify.msg').fadeOut();
            console.log('a');
            console.log(result.link);
            window.location.href = result.link;
          } else {
            $('#regiter-op .notify.msg').html(result.msg).fadeIn();
          }
        },
      });
    }
  });
  /////////////////////////////////////
  //  EVENT FORM
  /////////////////////////////////////
  $('.register-event-form .your-birthday input').datepicker({
    dateFormat: 'yy/mm/dd',
    changeMonth: true,
    changeYear: true,
    yearRange: '-100:+0',
  });
  var currentTime = new Date();
  var current_year = currentTime.getFullYear();
  $(
    '.register-event-form .your-arrival-date input, .your-departure-date input, .your-check-in-date input, .your-check-out-date input'
  ).datepicker({
    dateFormat: 'mm/dd',
    changeYear: false,
    yearRange: '' + current_year + ':' + current_year + '',
    minDate: currentTime,
  });
  $('.your-arrival-time input, .your-departure-time input').timepicker({
    timeFormat: 'HH:mm',
    interval: 60,
    dynamic: false,
    dropdown: true,
    scrollbar: true,
    interval: 15,
  });
  $('.culture-content .menu-map > li').first().addClass('active');
  $('#culture-tabs .menu-tab > li:first-child').addClass('active');
  $('.culture-content .tab-content .tab-pane').first().addClass('in active');

  if ($(window).width() <= 736) {
    function hasTouch() {
      return (
        'ontouchstart' in document.documentElement ||
        navigator.maxTouchPoints > 0 ||
        navigator.msMaxTouchPoints > 0
      );
    }

    if (hasTouch()) {
      // remove all :hover stylesheets
      try {
        // prevent exception on browsers not supporting DOM styleSheets properly
        for (var si in document.styleSheets) {
          var styleSheet = document.styleSheets[si];
          if (!styleSheet.rules) continue;

          for (var ri = styleSheet.rules.length - 1; ri >= 0; ri--) {
            if (!styleSheet.rules[ri].selectorText) continue;

            if (styleSheet.rules[ri].selectorText.match(':hover')) {
              styleSheet.deleteRule(ri);
            }
          }
        }
      } catch (ex) {}
    }
  }
  /////////////////////////////////////
  //  BREADCRUMBS
  /////////////////////////////////////
  $('.breadcrumbs ul ul li').each(function () {
    // if($(this).children("a").attr("href") != '#' && $(this).children("a").attr("href") != undefined){
    //     if($(this).children("a").attr("href") === $(this).parent().parent().children("a").attr("href")){
    //         $(this).remove();
    //     }
    // }else{

    // console.log($(this).parent().parent().children("a").text().toUpperCase());
    if (
      $(this).children('a').text().toUpperCase() ===
      $(this).parent().parent().children('a').text().toUpperCase()
    ) {
      $(this).remove();
    }
    // }
  });
  // $(".breadcrumbs .fa-angle-down").each(function(){

  //     let this_text = $(this).parent().text().toUpperCase();
  //     $(this).parent().siblings("ul").children("li").each(function(){
  //         if($(this).children("a").attr("href") != '#' && $(this).children("a").attr("href") != undefined){
  //             if($(this).children("a").attr("href") === this_text){
  //                 $(this).remove();
  //             }
  //         }else{
  //             if($(this).children("a").text().toUpperCase() === this_text){
  //                 $(this).remove();
  //             }
  //         }
  //     });
  // });
  $('.breadcrumbs').on('click', '.fa-angle-down', function () {
    $(this).toggleClass('active');
    $(this).parent().siblings('ul').slideToggle();
    return false;
  });
  $('.breadcrumbs .fa-angle-down')
    .parent('a')
    .on('click', function () {
      $(this).children('i').toggleClass('active');
      $(this).siblings('ul').slideToggle();
      return false;
    });
  $('.breadcrumbs li').mouseleave(function () {
    $(this).children('ul').stop().slideUp();
  });
  $('.breadcrumbs .container > ul > li').mouseleave(function () {
    $(this).children().children('i').removeClass('active');
  });
  /////////////////////////////////////
  //  HOME BANNER VIDEO
  /////////////////////////////////////
  var slideWrapper = $('.video-wrap');
  var iframes = slideWrapper.find('iframe');
  function resizePlayer(iframes, ratio) {
    if (!iframes[0]) return;
    var win = slideWrapper,
      width = win.width(),
      playerWidth,
      height = win.height(),
      playerHeight,
      ratio = ratio || 16 / 9;

    iframes.each(function () {
      var current = $(this);
      if (width / ratio < height) {
        playerWidth = Math.ceil(height * ratio);
        current
          .width(playerWidth)
          .height(height)
          .css({
            left: (width - playerWidth) / 2,
            top: 0,
          });
      } else {
        playerHeight = Math.ceil(width / ratio);
        current
          .width(width)
          .height(playerHeight)
          .css({
            left: 0,
            top: (height - playerHeight) / 2,
          });
      }
    });
    // $(".home-banner").css({height: iframes.height() - 100});
  }
  // Resize event
  resizePlayer(iframes, 16 / 9);
  /////////////////////////////////////
  //  UPADTE PROFILE
  /////////////////////////////////////
  if ($('#update_profile').length > 0) {
    var iti = window.intlTelInput(input_phone, {
      utilsScript: directory + '/js/utils.js?1560794689211',
    });
    if (countryData != '') {
      iti.setCountry(countryData);
    } else {
      iti.setCountry('gb');
    }
    var errorMsg = document.querySelector('#error-msg'),
      validMsg = document.querySelector('#valid-msg');
    var reset = function () {
      input_phone.classList.remove('error');
      errorMsg.innerHTML = '';
      errorMsg.classList.add('hide');
      validMsg.classList.add('hide');
    };

    // on blur: validate
    input_phone.addEventListener('blur', function () {
      reset();
      if (input_phone.value.trim()) {
        if (iti.isValidNumber()) {
          validMsg.classList.remove('hide');
        } else {
          input_phone.classList.add('error');
          var errorCode = iti.getValidationError();
          errorMsg.innerHTML = errorMap[errorCode];
          errorMsg.classList.remove('hide');
        }
      }
    });

    // on keyup / change flag: reset
    input_phone.addEventListener('change', reset);
    input_phone.addEventListener('keyup', reset);
  }
  $('#update_profile').on('submit', function (e) {
    e.preventDefault();
    let name = $('input[name=user_name]').val();
    let email = $('input[name=user_email]').val();
    let sex = $('select[name=sex]').val();
    let date = $('input[name=user_date]').val();
    let address = $('input[name=address]').val();
    let phone = $('input[name=user_phone]').val();
    let countryData = iti.getSelectedCountryData().iso2;
    if ($('#valid-msg').hasClass('hide') == false) {
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        cache: false,
        data: {
          action: 'update_profile',
          name: name,
          email: email,
          sex: sex,
          date: date,
          address: address,
          phone: phone,
          countryData: countryData,
        },
        beforeSend: function () {
          $('#overlay').show();
          $('.loading').show();
        },
        success: function (data) {
          $('#overlay').hide();
          $('.loading').hide();

          $('.check-alert')
            .addClass('alert-success')
            .removeClass('alert-danger');
          $('.check-alert').addClass('alert');
          $('.check-alert').text(susscess_msg);
        },
      });
    } else {
      $('.check-alert').addClass('alert-danger').removeClass('alert-success');
      $('.check-alert').addClass('alert');
      $('.check-alert').text(phone_msg);
    }
    return false;
  });
  /////////////////////////////////////
  //  UPADTE PASS
  /////////////////////////////////////
  $('#update_pass').on('submit', function (e) {
    e.preventDefault();
    old_pass = $('input[name=old_pass]').val();
    new_pass = $('input[name=new_pass]').val();
    new_pass2 = $('input[name=new_pass2]').val();
    if (new_pass != new_pass2) {
      if (!$('.check-alert').hasClass('alert')) {
        $('.check-alert').addClass('alert');
      }
      if ($('.check-alert').hasClass('alert-success')) {
        $('.check-alert').removeClass('alert-success');
      }
      if (!$('.check-alert').hasClass('alert-danger')) {
        $('.notify-profile').html(
          '<div class="form-group check-alert alert alert-danger">' +
            pass_msg +
            '</div>'
        );
      }
    } else {
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        cache: false,
        data: {
          action: 'custom_change_pass',
          old_pass: old_pass,
          new_pass: new_pass,
          new_pass2: new_pass2,
        },
        beforeSend: function () {
          $('#overlay').show();
          $('.loading').show();
        },
        success: function (data) {
          $('#overlay').hide();
          $('.loading').hide();
          $('.notify-profile').html(data);
        },
      });
    }
  });

  /////////////////////////////////////
  //  UPLOAD AVATAR
  /////////////////////////////////////
  function readURL(input) {
    if (input.files && input.files[0]) {
      var reader = new FileReader();

      reader.onload = function (e) {
        $('#avatar_user .avatar').attr('src', e.target.result);
      };
      reader.readAsDataURL(input.files[0]);
    }
  }

  $('#file_profile').on('change', function () {
    readURL(this);
    $('#update_ava').trigger('submit');
  });
  $('#update_ava').on('submit', function (e) {
    e.preventDefault();
    var link = $('input[name=upload_img_link]').val();
    $.ajax({
      type: 'POST',
      url: link,
      cache: false,
      data: new FormData(this),
      mimeType: 'multipart/form-data',
      contentType: false,
      processData: false,
      success: function (data) {},
    });
  });
  $('.btn-avatar').on('click', function (e) {
    e.preventDefault();
    $('#file_profile').trigger('click');
  });
  $('.language-ipecs .wrap-user .avatar-user').on('click', function () {
    $(this).siblings('ul').toggleClass('active');
    $(this).siblings('ul').slideToggle();
    return false;
  });
  /////////////////////////////////////
  //  FINANCIAL SELECT
  /////////////////////////////////////
  $('.financial-statement .select-wrap select').on('change', function () {
    let data = $(this).val();
    $('#sel-' + data)
      .parents('.sec-content')
      .find('.img-wrap')
      .removeClass('in active');
    $('#sel-' + data).addClass('in active');
  });
  $('.form-contact form input').on('keydown', function (e) {
    let val_input = $('.form-contact form .form-append input').val();
    if (val_input == '') {
      e.preventDefault();
      if ($('.form-contact form .form-append .red-alert').length > 0) {
        $('.form-contact form .form-append .red-alert').text(
          data_text.notify_category
        );
      } else {
        $('.form-contact form .form-append').append(
          '<span class="red-alert">' + data_text.notify_category + '</span>'
        );
      }
    } else {
      $('.form-contact form .form-append .red-alert').remove();
    }
  });
  /////////////////////////////////////
  // LOAD MORE AJAX IN MOBILE
  /////////////////////////////////////
  $('#archive-event .loadmore').on('click', function () {
    let current = parseInt(
      $('#archive-event .load-btn input[name=current]').val()
    );
    let total = parseInt($('#archive-event .load-btn input[name=total]').val());
    let data = $('#archive-event .load-btn input[name=data]').val();
    console.log(current);
    if (current < total) {
      current = current + 1;
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        data: {
          action: 'dsmart_ajax_load_more_event',
          current: current,
          data: data,
        },
        success: function (data) {
          $('#archive-event .load-btn input[name=current]').val(current);
          if (current >= total) {
            $('#archive-event .load-btn').remove();
          }
          $('#archive-event table tbody').append(data);
        },
      });
    }
    return false;
  });
  $('.newsroom-page .loadmore').on('click', function () {
    let current = parseInt(
      $('.newsroom-page .load-btn input[name=current]').val()
    );
    let total = parseInt($('.newsroom-page .load-btn input[name=total]').val());
    let total_post = parseInt(
      $('.newsroom-page .load-btn input[name=total_post]').val()
    );
    let data = $('.newsroom-page .load-btn input[name=data]').val();
    if (current < total) {
      current = current + 1;
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        data: {
          action: 'dsmart_ajax_load_more_news',
          current: current,
          data: data,
          total_post: total_post,
        },
        success: function (data) {
          $('.newsroom-page .load-btn input[name=current]').val(current);
          if (current >= total) {
            $('.newsroom-page .load-btn').remove();
          }
          $('.newsroom-page .news-first').append(data);
        },
      });
    }
    return false;
  });
  $('.blog-page .loadmore').on('click', function () {
    let current = parseInt($('.blog-page .load-btn input[name=current]').val());
    let total = parseInt($('.blog-page .load-btn input[name=total]').val());
    let data = $('.blog-page .load-btn input[name=data]').val();
    if (current < total) {
      current = current + 1;
      $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        data: {
          action: 'dsmart_ajax_load_more_blog',
          current: current,
          data: data,
        },
        success: function (data) {
          $('.blog-page .load-btn input[name=current]').val(current);
          if (current >= total) {
            $('.nblog-page .load-btn').remove();
          }
          $('.blog-page .blog-post .row').append(data);
        },
      });
    }
    return false;
  });
  /////////////////////////////////////
  // SOCIAL STORY TAB
  /////////////////////////////////////
  if ($(window).width() > 992) {
    $('.social-sec').on('click', '.tab-pane .owl-nav button', function () {
      let index = $(this).attr('data-index');
      $(this)
        .parents('.social-sec')
        .find("a[href='#social-tab" + index + "']")
        .trigger('click');
      return false;
    });
  }
  if ($(window).width() <= 1024) {
    $('footer .wpml-ls-sidebars-language_switcher a span').each(function () {
      let text = $(this).text();
      let res = text.substring(0, 3);
      $(this).text(res);
    });
  }
  if ($(window).width() <= 1024) {
    $('*')
      .removeAttr('data-aos')
      .removeClass('aos-init')
      .removeClass('aos-animate');
    $('section').removeAttr('data-aos-duration');
    $('.location-content .menu-map .has-sub > a').on('click', function () {
      $(this).siblings('ul').toggleClass('visible');
      return false;
    });
    $('.location-content .menu-map > li > a').on('click', function () {
      $('.location-content .menu-map > li').removeClass('active');
      $('.location-content .tab-content>.tab-pane').removeClass('in active');
      $(this).parent().addClass('active');
      href = $(this).attr('href');
      $(href).addClass('in active');
      return false;
    });
  }
  $('body').on('click touchstart', 'a.html5lightbox', function () {
    return false;
  });
  $('#people-tab .button-desc').html(function () {
    var text = $(this).text().trim().split(' ');
    var first = text.shift();
    return (
      (text.length > 0 ? "<span class='red'>" + first + '</span> ' : first) +
      text.join(' ')
    );
  });
  var lang = $('html').attr('lang');
  var href_page = $("#archive-event .wp-pagenavi a[title='Page 1']").attr(
    'href'
  );
  if (lang == 'en-US') {
    href_page = href_page + '&tab=archive';
  } else {
    href_page = href_page + '?tab=archive';
  }
  $("#archive-event .wp-pagenavi a[title='Page 1']").attr('href', href_page);
  /////////////////////////////////////
  // CONTACT TEXTAREA
  /////////////////////////////////////
  $('.contact-page .form-contact .form-text textarea').on('keyup', function () {
    let val = $(this).val();
    if (val != '') {
      $(this).parents('.form-text').addClass('active');
    } else {
      $(this).parents('.form-text').removeClass('active');
    }
  });
  jQuery('.textarea-scrollbar').scrollbar();
  $(
    '.contact-page .form-contact .form-input.form-text label, .contact-page .form-contact .form-text textarea'
  ).on('click', function () {
    $(this).parents('.form-text').addClass('active');
    return false;
  });
  if ($('#culture-tabs').length > 0) {
    $($('#culture-tabs .menu-tab li')).each(function () {
      if ($(this).hasClass('current-menu-item')) {
        var check = ' selected';
      } else {
        var check = '';
      }
      if ($(this).parent('ul').hasClass('sub-menu')) {
        $('.select-culture').append(
          "<option value='" +
            $(this).children('a').attr('href') +
            "'" +
            check +
            '>- ' +
            $(this).children('a').text() +
            '</option>'
        );
      } else {
        $('.select-culture').append(
          "<option value='" +
            $(this).children('a').attr('href') +
            "'" +
            check +
            '>' +
            $(this).children('a').text() +
            '</option>'
        );
      }
    });
    $('.select-culture').on('change', function () {
      var val = $(this).val();
      window.location.href = val;
    });
  }
  if ($('#corp-tab').length > 0) {
    $($('#corp-tab .menu-tab li')).each(function () {
      if ($(this).hasClass('current-menu-item')) {
        var check = ' selected';
      } else {
        var check = '';
      }
      if ($(this).parent('ul').hasClass('sub-menu')) {
        $('#corp .select-pill').append(
          "<option value='" +
            $(this).children('a').attr('href') +
            "'" +
            check +
            '>- ' +
            $(this).children('a').text() +
            '</option>'
        );
      } else {
        $('#corp .select-pill').append(
          "<option value='" +
            $(this).children('a').attr('href') +
            "'" +
            check +
            '>' +
            $(this).children('a').text() +
            '</option>'
        );
      }
    });
    $('#corp .select-pill').on('change', function () {
      var val = $(this).val();
      window.location.href = val;
    });
  }
});