// Example starter JavaScript for disabling form submissions if there are invalid fields
(() => {
  'use strict';

  // Fetch all the forms we want to apply custom Bootstrap validation styles to
  const forms = document.querySelectorAll('.needs-validation');

  // Loop over them and prevent submission
  Array.prototype.slice.call(forms).forEach((form) => {
    form.addEventListener('submit', (event) => {
      if (!form.checkValidity()) {
        event.preventDefault();
        event.stopPropagation();
      }
      form.classList.add('was-validated');
    }, false);
  });
})();

$(document).ready(function(){
    
	var current_fs, next_fs, previous_fs; //fieldsets
	var opacity;
	var current = 1;
	var steps = $("fieldset").length;

	//alert(steps);

	//setProgressBar(current);

	$(".next").click(function(){
	
	current_fs = $(this).parent().parent().parent().parent();
	next_fs = $(this).parent().parent().parent().parent().next();



	//Add Class Active
	$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

	//show the next fieldset
	next_fs.show();
	//hide the current fieldset with style
	current_fs.animate({opacity: 0}, {
	step: function(now) {
	// for making fielset appear animation
	opacity = 1 - now;

	current_fs.css({
	'display': 'none',
	'position': 'relative'
	});
	next_fs.css({'opacity': opacity});
	},
	duration: 500
	});
	if(current == 4){
		$('.progress').css('display','none');
	}
	//setProgressBar(++current);
	});

	$(".previous").click(function(){

	current_fs = $(this).parent().parent().parent().parent();
	previous_fs = $(this).parent().parent().parent().parent().prev();

	//Remove class active
	$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

	//show the previous fieldset
	previous_fs.show();

	//hide the current fieldset with style
	current_fs.animate({opacity: 0}, {
	step: function(now) {
	// for making fielset appear animation
	opacity = 1 - now;

	current_fs.css({
		'display': 'none',
		'position': 'relative'
	});
	previous_fs.css({'opacity': opacity});
	},
		duration: 500
	});
		//setProgressBar(--current);
	});

	/*function setProgressBar(curStep){
	var percent = parseFloat(100 / steps) * curStep;
	percent = percent.toFixed();
	$(".progress-bar")
		.css("width",percent+"%")
	}*/

	$(".submit").click(function(){
		return false;
	});
	/*document.querySelectorAll('.form-outline').forEach((formOutline) => {
	  new mdb.Input(formOutline).update();
	});*/
	
	 $("#progressbar li").click(function() {
		var gotoTarget = $(this).attr('dtarget');
		var gotoTarget_new = parseInt(gotoTarget);
		$("#progressbar li").each(function() {
		  $(this).removeClass('active');
		})

		for (var i = 0; i < (gotoTarget_new); i++) {
		  $("#progressbar li").eq(i).addClass('active');
		}
		$(this).closest('li').addClass('active');

		
		$("#msform > fieldset").each(function() {
		  $(this).hide();
		})
		$("#msform > fieldset").eq(gotoTarget_new).show();
	  })

});
$('.counter').counterUp({
  delay: 20,
  time: 5000
});


$(document).ready(function() {

   var owl = $('.main-owl-carousel').owlCarousel({
        nav: false,
        loop: true,
        //rewind: true, // rewind to first slide
        autoplay: true,
        autoplaySpeed: 4000,
        autoplayTimeout: 15000,
        dotsSpeed: 500,
	    autoplayHoverPause:true,
        items: 1,
        dotsContainer: '#custom-owl-dots'
    });
    
    $('.owl-dot a').click(function () {
		var index = $(this).parent().index();
        owl.trigger('to.owl.carousel', [index, 3000, true]);
    });

});