jQuery(document).ready(function ($) {
  //fixed top-menu
  let lastYPos = jQuery(document).scrollTop();
  jQuery(document).on('scroll', function (event) {
    if (jQuery(document).scrollTop() > 0) {
      jQuery('.header-2024').parents('body').addClass('fixed-header');
    } else {
      jQuery('.header-2024').parents('body').removeClass('fixed-header');
    }
    lastYPos = jQuery(document).scrollTop();
  });

  //Meanmenu Setup
  /*jQuery('.header-2024 .meanmenu-content').meanmenu({
    meanMenuContainer: '.meanmenu-trigger',
    meanMenuOpen: '<div class="meanmenu-open-btn"><span></span><span></span><span></span><div class="btn-text">Menu</div></div>',
    meanMenuClose: '<div class="meanmenu-close-btn"><span></span><span></span></div>',
  });*/

  //Meanmenu Setup
  var currentUrl = window.location.pathname;


  if (jQuery('body').hasClass('home')) {
    jQuery('#header_section .navbarwrap').meanmenu();
  } else {
    jQuery('.header-2024 .meanmenu-content').meanmenu({
      meanMenuContainer: '.meanmenu-trigger',
      meanMenuOpen: '<div class="meanmenu-open-btn"><span></span><span></span><span></span></div>',
      meanMenuClose: '<div class="meanmenu-close-btn"><span></span><span></span></div>',
    });
  }

  //Slidemenu open-close
  jQuery('.slidemenu .slidemenu-btn-close, .main-header .btn-slidemenu').on('click', function () {
    jQuery('.slidemenu').toggleClass('slidemenu-opened');
  });

  //FAQ logic
  /*let faqWrap = jQuery('#rank-math-faq .rank-math-list');
  if (faqWrap.length > 0) {
    faqWrap.find('.rank-math-list-item').each(function (i, el) {
      let faq = jQuery(this);
      let faqTitle = faq.find('.rank-math-question');
      let faqContent = faq.find('.rank-math-answer');
      if (i === 0) {
        faqContent.slideDown();
        faqTitle.addClass('active');
      } else {
        faqContent.slideUp();
      }
      faq.click(function () {
        faqContent.slideDown(200);
        faqTitle.addClass('active');
        jQuery(this).siblings('.rank-math-list-item').find('.rank-math-answer').slideUp(200);
        jQuery(this).siblings('.rank-math-list-item').find('.rank-math-question').removeClass('active');
      });
      faq[0].click;
    });
  }*/
});








(function ($) {

  $(document).ready(myfunction_common);
  $(window).resize(myfunction_common);
  function myfunction_common() {
    $('#banner-home .table-wrap').css('height', $(window).height() + 'px');
    $('#banner-home .banner-img').css('height', $(window).height() + 'px');
    $('#banner_section').css('height', $(window).height() + 'px');
    /*$('#inner-main-banner .table-wrapper').height($(window).height());*/
    $('#banner_section .banner_holder').css('height', $(window).height() + 'px');
  }

})(jQuery);

jQuery(document).ready(function ($) {
  /*new WOW().init();*/

  //Smooth Scrolling
  $('a.scroll-down').click(function () {
    let elementClick = '#' + $(this).attr('href').split('#')[1];
    let destination = $(elementClick).offset().top - 150;
    jQuery('html:not(:animated),body:not(:animated)').
      animate({ scrollTop: destination }, 1000);
    return false;
  });









  $blog_section_entry_title = $('.blog_section .et_pb_salvattore_content article .entry-title')
  $blog_section_entry_title.matchHeight(
    {
      byRow: true,
      property: 'height',
      // target: null,
      remove: false
    }
  );

  $blog_section_p = $('.blog_section .et_pb_salvattore_content article .post-content .post-content-inner p')
  $blog_section_p.matchHeight(
    {
      byRow: true,
      property: 'height',
      // target: null,
      remove: false
    }
  );

  if ($('.single-blog').length) {
    $single_blog_title = $('body .single-blog-post-title')
    $single_blog_title.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );

    $single_blog_p = $('body .single-blog-post-content p')
    $single_blog_p.matchHeight(
      {
        byRow: true,
        property: 'height',
        // target: null,
        remove: false
      }
    );
  }

  function checkWidth() {
    var windowSize = $(window).width();

    if (windowSize >= 768) {
      $(window).scroll(function () {
        var scroll = $(window).scrollTop();
        if (scroll >= 1) {
          $("#header_section").addClass('smaller');


        } else {
          $("#header_section").removeClass("smaller");


        }
      });
    } else {
      $(window).scroll(function () {
        var scroll = $(window).scrollTop();
        if (scroll >= 6000) {
          $("#header_section").addClass('smaller');


        } else {
          $("#header_section").removeClass("smaller");


        }
      });
    }
  }
  // Execute on load
  checkWidth();
  // Bind event listener
  $(window).resize(checkWidth);

  if ($('.slider-for').length && $('.slider-nav').length) {
    $('.slider-for').slick({
      slidesToShow: 1,
      slidesToScroll: 1,
      arrows: false,
      fade: true,
      asNavFor: '.slider-nav'
    });

    $('.slider-nav').slick({
      slidesToShow: 4,
      slidesToScroll: 1,
      asNavFor: '.slider-for',
      dots: true,
      centerMode: false,
      focusOnSelect: true,
      responsive: [
        {
          breakpoint: 1000,
          settings: {
            arrows: true,
            slidesToShow: 2
          }
        },
        {
          breakpoint: 768,
          settings: {
            arrows: true,
            slidesToShow: 1
          }
        },
        {
          breakpoint: 767,
          settings: {
            arrows: true,
            slidesToShow: 1
          }
        },
        {
          breakpoint: 440,
          settings: {
            arrows: true,
            slidesToShow: 1
          }
        }
      ]
    });
  }

  // Rank Math Faq Accordion
  let faqWrap = jQuery('#rank-math-rich-snippet-wrapper #rank-math-faq .rank-math-list');

  if (faqWrap.length > 0) {
    faqWrap.find('.rank-math-list-item').each(function (i, el) {
      let faq = jQuery(this);
      let faqTitle = faq.find('.rank-math-question');
      let faqContent = faq.find('.rank-math-answer');
      if (i === 0) {
        faqContent.slideDown();
        faqTitle.addClass('active');
      } else {
        faqContent.slideUp();
        faqTitle.removeClass('active');
      }
      faq.click(function () {
        faqContent.slideDown(200);
        faqTitle.addClass('active');
        jQuery(this).siblings('.rank-math-list-item').find('.rank-math-answer').slideUp(200);
        jQuery(this).siblings('.rank-math-list-item').find('.rank-math-question').removeClass('active');
      });
    });
  }
  // End Rank Math Faq Accordion

  // Wrap the iframe with a center tag
  jQuery('#main-body-sub.single-page-standart-2023 .single-content-right-col iframe').each(function () {
    /*if (jQuery(this).parent('p')) {*/
    /*jQuery(this).wrap('<center></center>');*/
    let $iframe = $(this);
    if (!$iframe.parent().is("center")) {
      $iframe.wrap("<center></center>");
    }
    /*}*/
  });
  // End Wrap the iframe with a center tag

  // Ol li more than 15
  let singleOl = jQuery('#main-body-sub.single-page-standart-2023 .single-content-right-col ol');
  if (singleOl.length > 0) {
    singleOl.each(function (i, el) {
      let maxOl = jQuery(this);
      if (maxOl.children('li').length > 15) {
        maxOl.css('column-count', '2');
      }
    })
  }
  // End Ol li more than 15

  //Social Share
  if ($('a.share-btn, a.share').length) {
    $('a.share-btn, a.share').on('click', function (e) {
      e.preventDefault();
      $(this).toggleClass('active');
      //$(this).next(div.heateor_sss_sharing_container).toggleClass('active');
    })
  }
  //End Social Share

  if ($('.slider-benefit2').length && $('.slider-benefit').length) {
    $('.slider-benefit2').slick({
      slidesToShow: 1,
      slidesToScroll: 1,
      arrows: false,
      fade: true,
      asNavFor: '.slider-benefit'
    });

    $('.slider-benefit').slick({
      slidesToShow: 1,
      slidesToScroll: 1,
      asNavFor: '.slider-benefit2',
      dots: true,
      arrows: false,
      speed: 500,
      fade: true,
      focusOnSelect: true
    });
  }

  if ($('.carousel-wrapper').length) {
    $('.carousel-wrapper').slick({
      dots: true,
      infinite: true,
      speed: 2000,
      fade: true,
      autoplay: true,
      autoplaySpeed: 6000,
      cssEase: 'linear'
    });
  }

  $blog_body = $('#education_container .blog_wrapper .blog_block .blog_body')
  $blog_body.matchHeight(
    {
      byRow: true,
      property: 'height',
      // target: null,
      remove: false
    }
  );

  $title_wrap = $('#education_container .blog_wrapper .blog_block .blog_body h3')
  $title_wrap.matchHeight(
    {
      byRow: true,
      property: 'height',
      // target: null,
      remove: false
    }
  );

  if (!!document.querySelector('.single .inner-text .author-box')) {
    let firstH2 = document.querySelector('.inner-text h2:first-child'),
      firstH3 = document.querySelector('.inner-text h3:first-child'),
      authorInfo = document.querySelector('.inner-text .author-box'),
      anyFirst = document.querySelector('.inner-text *:first-child');

    if (!!firstH2) {
      firstH2.after(authorInfo);
    } else if (!!firstH3) {
      firstH3.after(authorInfo);
    } else {
      anyFirst.before(authorInfo);
      document.querySelector('.inner-text p:first-of-type').style.paddingTop = '10px';
    }
  }
});

jQuery(document).ready(function ($) {
  var navigation_fixed = $('#scroll-activator').scrollTop();

  $(window).scroll(function () {

    if ($(window).scrollTop() > navigation_fixed) {
      $("#main-header").addClass('scroll');
    } else {
      $("#main-header").removeClass("scroll");
    }
  });

  // Remove all non-numeric characters from the beginning of the string
  function removeNonNumericPrefix(inputString) {

    let numericString = inputString.replace(/^\D+/g, '');

    return numericString;
  }

  // Set Value Input Formstack New Standart
  function setValueFormstackInpup( idForm, idInput, value ) {
    const form = window.fsApi().getForm( removeNonNumericPrefix(idForm) );
    const dataField = form.getField( removeNonNumericPrefix(idInput) );

    if(form && dataField){
      dataField.setValue( value );
    }
  }
  // END Set Value Input Formstack New Standart

  //Random 1-50
  function getRandomNumberWithout(excludedNumber) {
    let randomNumber = Math.floor(Math.random() * 50) + 1;

    while (randomNumber === excludedNumber) {
      randomNumber = Math.floor(Math.random() * 50) + 1;
    }

    return randomNumber;
  }

  //Page URL in Forms
  function pageURLInForm(formID ,idElementURL, idCaptchaElement, captchaElementValue, idButton) {

    let currentUrl = window.location.href;
    let urlField = document.getElementById(idElementURL);

    /*currentUrl = 'https://www.orionnetworks.net/?keyword_session_id=vt~adwords%7Ckt~cyber%20security%20companies%7Cmt~b%7Cta~674763502484&_vsrefdom=wordstream&gclid=EAIaIQobChMIlta_iMS3ggMViu7ICh28HQ6lEAAYASAAEgL_xvD_BwE';*/

    if (currentUrl.includes("?") || currentUrl.includes("%") || currentUrl.includes("~") || currentUrl.includes("&")) {

      if (idButton) {
        const button = document.getElementById(idButton);

        if (button) {
          button.disabled = true;
        }
      }

      if (idCaptchaElement && captchaElementValue) {
        const captchaElement = document.getElementById(idCaptchaElement);

        if (captchaElement) {
          captchaElementValue = captchaElementValue + getRandomNumberWithout(captchaElementValue);
          //captchaElement.value = captchaElementValue;

          setValueFormstackInpup( formID, idCaptchaElement, captchaElementValue );
        }
      }
    }

    if (urlField) {
      /*urlField.value = currentUrl;*/

      setValueFormstackInpup( formID, idElementURL, currentUrl );
    }
  }

  /* Popup Consultation Form, Contact Us Form */
  pageURLInForm('fsForm5540187' ,'field155325502', 'field155324656', 22, 'fsSubmitButton5540187');


  /*pageURLInForm('field155333335', 'field155333334', 22, 'fsSubmitButton5540493');*/
  //End Page URL in Forms

  //Fix enter forms
  form_enter_odd();

  function form_enter_odd() {
    $('.fsForm input, .fsForm select').keypress(function (e) {

      let thisForm = $(this).closest('.fsForm');
      let thisSubmit = thisForm.find('.fsSubmitButton');

      if (e.which == 13) {
        thisSubmit.click();
        return false;
      }
    });
  }
});

