const observer = lozad(); // lazy loads elements with default selector as '.lozad'
observer.observe();
//SERVICES
var csselects=[];
(function($) {
    $(function() {
        var jcarousel = $('.jcarousel');

        jcarousel
            .on('jcarousel:reload jcarousel:create', function () {
                var carousel = $(this),
                    width = carousel.innerWidth();
var xs=1;
var sm=2.1;
var md=3.2;
var lg=4.3;
if(jQuery(this).attr('id')=='inspection-type'){
xs=1;
sm=2.1;
md=2.1;
lg=3.2;
}
                if (width >=1100) {
                    width = width / lg;
                } else if (width >= 768) {
                    width = width / md;
                } else if (width >= 500) {
                    width = width / sm;
                } else if (width >= 350) {
                    width = width / xs;
                }

                carousel.jcarousel('items').css('width', Math.ceil(width) + 'px');
            })

            .jcarousel({
                wrap: 'circular'
            });
try{
        $('.jcarousel-control-prev')
            .jcarouselControl({
                target: '-=1'
            });

        $('.jcarousel-control-next')
            .jcarouselControl({
                target: '+=1'
            });

        $('.jcarousel-pagination')
            .on('jcarouselpagination:active', 'a', function() {
                $(this).addClass('active');
            })
            .on('jcarouselpagination:inactive', 'a', function() {
                $(this).removeClass('active');
            })
            .on('click', function(e) {
                e.preventDefault();
            })
            .jcarouselPagination({
                perPage: 1,
                item: function(page) {
                    return '<a href="#' + page + '">' + page + '</a>';
                }
            });
}catch(e){}
    });
})(jQuery);

(function() {
				[].slice.call( document.querySelectorAll( 'select.cs-select' ) ).forEach( function(el) {	
					csselects[el.id]=new SelectFx(el,{
            onChange: function() {
                var elid=el.id;
                if(elid==1){
                    var nelement=document.getElementById('3');
                    $.ajax({
                       type: "POST",
                        dataType: "application/json",
                        url: "/dresources/viewVetCourses",
                        data: "mode=json&pid="+document.getElementById('1').value+"&loc="+document.getElementById('2').value,
                        complete: function(data) {
                            var dates = $.parseJSON(data.responseText);
                            nelement.innerHTML='<option value="-1">Select Your Date</option>';
                            for (i = 0; i < dates.length; i++) { 
                                     nelement.innerHTML=nelement.innerHTML+'<option value="'+dates[i].id+'">'+dates[i].value+'</option>';
                            }
                        csselects[3]._ReinitEvents();
                        $("#content > div > div.container > div.row > div.col-xs-12 > div.md-down-padding-sides-20 > form > div > div:nth-child(3) > div.col-md-4.col-xs-12.search-form > div").rempveClass("search-input-indicator");

                       },  
                        beforeSend: function() {
                          $("#content > div > div.container > div.row > div.col-xs-12 > div.md-down-padding-sides-20 > form > div > div:nth-child(3) > div.col-md-4.col-xs-12.search-form > div").addClass("search-input-indicator");
                        }
                    });
                 }
                else  if(elid==2){
                    var nelement=document.getElementById('3');
                    var courseID=document.getElementById('1').value;
                    if(document.getElementById('2').value == 'Melbourne' && courseID=='4') courseID='17';
                    $.ajax({
                       type: "POST",
                        dataType: "application/json",
                        url: "/dresources/viewVetCourses",
                        data: "mode=json&pid="+courseID+"&loc="+document.getElementById('2').value,
                        complete: function(data) {
                            var dates = $.parseJSON(data.responseText);
                            nelement.innerHTML='<option value="-1">Select Your Date</option>';
                            for (i = 0; i < dates.length; i++) { 
                                     nelement.innerHTML=nelement.innerHTML+'<option value="'+dates[i].id+'">'+dates[i].value+'</option>';
                            }
                        csselects[3]._ReinitEvents();
                        $("#content > div > div.container > div.row > div.col-xs-12 > div.md-down-padding-sides-20 > form > div > div:nth-child(3) > div.col-md-4.col-xs-12.search-form > div").rempveClass("search-input-indicator");
                       },  
                        beforeSend: function() {
                          $("#content > div > div.container > div.row > div.col-xs-12 > div.md-down-padding-sides-20 > form > div > div:nth-child(3) > div.col-md-4.col-xs-12.search-form > div").addClass("search-input-indicator");
                        }
                    });
                  
                } else  if(elid==3){

                }
            }
        });
				} );
			})();

$(document).ready(function () {
try{
$( ".book-form-popoup" ).each(function( index ) {
$(this).fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic'
			});
});

}catch(e){console.log("Error", e.stack);}

try{
$("#date-of-birth").datetimepicker({
		timepicker:false,
	    format: 'd-m-Y'
		});
}catch(e){}
if(document.getElementById("wpac-google-review")){
var s=document.getElementById("wpac-google-review");
wpac_init = window.wpac_init || [];
wpac_init.push({widget: 'GoogleReview', id: 10033, place_id: 'ChIJTZjff2quEmsRsqBghTtgCLM', view_mode: 'badge'});
(function() {
    if ('WIDGETPACK_LOADED' in window) return;
    WIDGETPACK_LOADED = true;
    var mc = document.createElement('script');
    mc.type = 'text/javascript';
    mc.async = true;
    mc.src = 'https://embed.widgetpack.com/widget.js';
    s.parentNode.insertBefore(mc, s);
})();
}}());

/////////////////
function recaptchaCheck(form) {
    if(!form.accept.checked) {
      alert("Please indicate that you accept the Terms and Conditions");
      form.accept.focus();
      return false;
    }else{
grecaptcha.ready(function() {
      grecaptcha.execute('6LeUf6oUAAAAAI-P6Vlk2Z9uhyKfKjw4UQyteSr9', {action: 'course_booking'}).then(function(token) {
                // add token to form
               document.getElementById('recaptcha-v3').value = token;
                   });
  });
return true;
}
return false;
}


///
function validate() {
if(document.getElementById('visa').checked){
var crd=document.getElementById('cnumber').value;
var visaRegEx = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
   if(crd.match(visaRegEx)==null){
        document.getElementById('errModalText').innerText='Please enter a valid VisaCard number.';
        $('#errModal').modal('show');
        return;
    }
}else if(document.getElementById('mastercard').checked){
var crd=document.getElementById('cnumber').value;
var mastercardRegEx = /^(?:5[1-5][0-9]{14})$/;
   if(crd.match(mastercardRegEx)==null){
        document.getElementById('errModalText').innerText='Please enter a valid MasterCard number.';
        $('#errModal').modal('show');
        return false;
    }
}
if(document.getElementById('mastercard').checked || document.getElementById('visa').checked){
var sec=document.getElementById('sec').value;
var secRegEx = /^[0-9]{3,4}$/;
   if(sec.match(secRegEx)==null){
        document.getElementById('errModalText').innerText='Please enter a valid CVV security code.';
        $('#errModal').modal('show');
        return false;
    }
var cname=document.getElementById('cname').value;
var nameRegex=/^\s*$/;
  if(cname.length<5){
        document.getElementById('errModalText').innerText='Please enter the name on the card.';
        $('#errModal').modal('show');
        return false;
    }
}
return true;
}