 

/*============================= Back To Top Button Script ========================*/
var mybutton = document.getElementById("backTop");
window.onscroll = function () { scrollFunction() };
function scrollFunction() {
  if (document.body.scrollTop > 120 || document.documentElement.scrollTop > 120) {
    mybutton.style.display = "flex";
  } else {
    mybutton.style.display = "none";
  }
}
function topFunction() {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
}


window.addEventListener('scroll', function(){ 
  var menubar = document.querySelector("#mainNav"); 
  menubar.classList.toggle("fixed-top", window.scrollY > 100);
});

(function ($) {
  

  // Main Header Nav links Active Class Genaretor
  $("#mainNav .navbar-nav li a").each(function () {
    var linkUrl = this.href.replace(/\.php$/, ""); // Remove .php if present
    var currentUrl = location.href.replace(/\.php$/, "").replace(/#.*/, ""); // Remove .php and hash fragments

    if (linkUrl === currentUrl) {
      $(this).closest("li").addClass("active");
    }
  });
 

 
  $(".serviceCarousel").owlCarousel({
    autoplay: false, 
    autoplayHoverPause: true,
    smartSpeed: 550,
    responsiveClass: true,
    autoplayTimeout: 10000,
    autoplaySpeed: 3000,
    loop: false,
    margin: 15,
    items: 3,
    nav: false,
    dots: true,
    responsiveClass: true, 
    responsive: { 
        0: { items: 1, margin: 12 },
        576: { items: 2, margin: 12  },
        768: { items: 2, margin: 15,  },
        992: { items: 2, margin: 15,  }, 
        1200: { items: 3, margin: 15, }, 
        1400: { items: 3, }, 
    } 
  });

 
  $(".blogCarousel").owlCarousel({
    autoplay: false, 
    autoplayHoverPause: true,
    smartSpeed: 550,
    responsiveClass: true,
    autoplayTimeout: 10000,
    autoplaySpeed: 3000,
    loop: false,
    margin: 35,
    items: 3,
    nav: false,
    dots: true,
    responsiveClass: true, 
    responsive: { 
        0: { items: 1, margin: 15 },
        576: { items: 2, margin: 22  },
        768: { items: 2, margin: 25,  },
        992: { items: 2, margin: 25,  }, 
        1200: { items: 3, margin: 35, }, 
        1400: { items: 3, }, 
    } 
  });
  
  AOS.init({
    // Global settings:
    disable: false, // accepts following values: 'phone', 'tablet', 'mobile', boolean, expression or function
    startEvent: 'DOMContentLoaded', // name of the event dispatched on the document, that AOS should initialize on
    initClassName: 'aos-init', // class applied after initialization
    animatedClassName: 'aos-animate', // class applied on animation
    useClassNames: false, // if true, will add content of `data-aos` as classes on scroll
    disableMutationObserver: false, // disables automatic mutations' detections (advanced)
    debounceDelay: 50, // the delay on debounce used while resizing window (advanced)
    throttleDelay: 99, // the delay on throttle used while scrolling the page (advanced)
    
  
    // Settings that can be overridden on per-element basis, by `data-aos-*` attributes:
    offset: 100, // offset (in px) from the original trigger point
    delay: 100, // values from 0 to 3000, with step 50ms
    duration: 700, // values from 0 to 3000, with step 50ms
    easing: 'ease', // default easing for AOS animations
    once: true, // whether animation should happen only once - while scrolling down
    mirror: false, // whether elements should animate out while scrolling past them
    anchorPlacement: 'top-bottom', // defines which position of the element regarding to window should trigger the animation
  
  });


  $(document).ready(function() { 
   
    $("#contactForm").submit(function() {
        if (validateContactForm()) {
            return true;
        }
        else {
            return false;
        }
    }); 

    function validateContactForm() {
        var valid = true;	
        $(".form-control").css('border-color','');
        $(".error").html('');
        
        // User name validation
        if(!$("#name").val()) {
            $("#name_error").html("Name required");
            $("#name").css('border-color','#dc3545');
            valid = false;
        } else {
            $("#name_error").html("");
            $("#name").css('border-color','#099f1a');
        } 
        
        var phno = $.trim($('#phone').val());
        var che_phno = /^[0-9]{7,15}$/;
        if(!$("#phone").val()) {
            $("#phone_error").html("Phone number required");
            $("#phone").css('border-color','#dc3545');
            valid = false;
        } if (!che_phno.test(phno)) {
            $("#phone").css('border-color','#dc3545');
            $("#phone_error").html('Please enter valid phone no'); 
            valid = false;
        } else if (phno.length < 7 || phno.length > 15) {
            $("#phone").css('border-color','#dc3545');
            $("#phone_error").html('Phone no. must be greater than or equals to 7 and less than or equals to 15 digits!!'); 
            valid = false;
        } else {
            $("#phone_error").html("");
            $("#phone").css('border-color','#099f1a');
        } 
        //  
        if(!$("#email").val()) {
            $("#email_error").html("Email is required");
            $("#email").css('border-color','#dc3545');
            valid = false;
        } else if(!$("#email").val().match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/)) {
            $("#email_error").html("Invalid email");
            $("#email").css('border-color','#dc3545');
            valid = false;
        } else {
            $("#email_error").html("");
            $("#email").css('border-color','#099f1a');
        } 
        
        if(!$("#country").val()) {
            $("#country_error").html("Country required");
            $("#country").css('border-color','#dc3545');
            valid = false;
        } else {
            $("#country_error").html("");
            $("#country").css('border-color','#099f1a');
        } 
            
        return valid;
    } 
});
 
})(jQuery);

 
 