
////site-uploads/1001522/frontjs/sticky.js

$(function () {
    $(window).on("scroll", function () {
        if ($(window).scrollTop() > $(".header-div").outerHeight()) {
            $("#comp_1707125648635").addClass("sticky-header");
            var centerDivMargin = $('#comp_1707125648635').height();
            $('#CenterDiv').css({ "margin-top": centerDivMargin });
        } else {
            $("#comp_1707125648635").removeClass("sticky-header");
            $('#CenterDiv').css({ "margin-top": 0 });
        }
    });
});
////site-uploads/1001522/frontjs/breadcrumbs.js
jQuery(function ($) {
  /* Start for add custom breadcrumb Link */
  function returnPageSlug() {
    console.log('window.location.href => ', window.location.href);
    var allURL = window.location.href;
    var domainName = window.location.hostname;
    var currentPage = allURL.replace(domainName, '');
    var currentPage = currentPage.replace('https', '');
    var currentPage = currentPage.replace('http', '');
    var currentPage = currentPage.replace(/\//g, '');
    var currentPage = currentPage.replace(/:/g, '');
    if (currentPage.includes('?')) {
      var currentPage = currentPage.slice(0, currentPage.indexOf('?'));
    }
    console.log('currentPage => ', currentPage);
    return currentPage;
  }

  var pagesNeedCustomBreadcrumb = [
    // {
    //   target: {
    //     name: 'BOAT & PWC LIFTS',
    //     url: '/Boat-&-PWC-Lifts'
    //   },
    //   pages: [
    //     'Naylor-Dock-Products-'
    //   ]
    // }
  ];
  /* End It Here*/
  if ($('nav.breadcrumbParent').length) {
    var breadcrumbListItemsCount = $('ol.breadcrumb li').length;

    /*Related to add custom breadcrumb*/
    if (pagesNeedCustomBreadcrumb && pagesNeedCustomBreadcrumb.length !== 0) {
      var currentPageURL = returnPageSlug();
      for (let i = 0; i < pagesNeedCustomBreadcrumb.length; i++) {
        console.log(pagesNeedCustomBreadcrumb[i]);
        if (pagesNeedCustomBreadcrumb[i].pages.includes(currentPageURL)) {
          console.log('found');
          var el =
            '<li class="breadcrumb-item" style="text-transform: capitalize;"><a href="' +
            pagesNeedCustomBreadcrumb[i].target.url +
            '">' +
            pagesNeedCustomBreadcrumb[i].target.name +
            '</a></li>';
          $(el).insertBefore($('.breadcrumb-item.active'));
          breadcrumbListItemsCount++;
        }
      }
    }
    /* End It Here*/

    var modelTitle = '';
    if ($('.model-details-content.container .model-title').length) {
      $('.model-details-content.container .model-title').hide();
      modelTitle = $('.model-details-content.container .model-title').text();
    }

    var elementToHide = $('.breadcrumb-item.active');
    var new_title = elementToHide.text();
    console.log('new_title => ', new_title);
    elementToHide.hide();
    new_title = new_title
      .split('-')
      .filter(function (item) {
        item = item ? item.replace(/-/g, '') : item;
        return item;
      })
      .join(' ');

    new_title =
      modelTitle.length === 0 ? new_title.replace(/  +/g, ' - ') : modelTitle;
    /* handle get breadcrumb text from DOM Element */
    var customTitleExist = document.getElementById('_custome_breadcrumb_title');
    if (customTitleExist) {
      console.log(customTitleExist.innerText);
      customTitleExist.style.display = 'none';
      new_title = customTitleExist.innerText;
    }
    console.log('customTitleExist => ', customTitleExist);
    new_titleCharCount = new_title.length;
    if (new_titleCharCount > 25 || breadcrumbListItemsCount > 2 || 1 === 1) {
      var style =
        '<style>@media screen and (max-width: 620px){.breadcrumbParent {flex-direction: column;}.breadcrumbParent h2 {padding-top: 1.5vw;}}</style>';
      $('nav.breadcrumbParent').prepend(style);
    }
    ttlelement = '<h1>' + new_title + '</h1>';
    $('nav.breadcrumbParent').prepend(ttlelement);
    if ($('.col-sm-9.col-xs-12.model-ttl .model-title').length) {
      $('.col-sm-9.col-xs-12.model-ttl .model-title').hide();
    }

    /* start Capitalize other breadcrumb li elements */
    var oltherListItems = $('ol.breadcrumb li').not('.active');
    oltherListItems.each(function () {
      $(this).css({ 'text-transform': 'capitalize' });
    });
    /* End */
  }
});

function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

jQuery(function ($) {
  if (
    $(
      'div.col-lg-8.col-md-10.col-sm-10.col-xs-7.text-left.descColumnResponsive'
    ).length
  ) {
    $(
      'div.col-lg-8.col-md-10.col-sm-10.col-xs-7.text-left.descColumnResponsive'
    ).each(function () {
      console.log($(this).text());
      var text = $(this).text().replace(/\s/g, '');
      if (text === 'N/A') {
        $(this).parent().hide();
      }
    });
  }
});
////site-uploads/1001522/frontjs/Search_script1.js
setTimeout(function() {
    document.getElementById("searchbox2")?.addEventListener("keyup", function(event) {
        event.preventDefault();
        if (event.keyCode === 13) {
            document.getElementById("searchbtn2")?.click();
        }
    });
}, 2000);


function srch(srch_id) {
    //var e = document.getElementById("pagedd");
    //var dest= e.options[e.selectedIndex].value;
    var valuee = document.getElementById(srch_id)?.value;
    if (valuee != "") {
        window.location = "/Search-Inventory/search/".concat(valuee);
    } else {
        document.getElementById(srch_id).placeholder = "This field is required";
        var sheet = window.document.styleSheets[0];
        sheet.insertRule('input#'+srch_id+'::-webkit-input-placeholder {color: red !important}', sheet.cssRules.length);
        sheet.insertRule('input#'+srch_id+'::-moz-placeholder {color:#909; opacity:1;}', sheet.cssRules.length);
        sheet.insertRule('input#'+srch_id+':-moz-placeholder {color:#909; opacity:1;}', sheet.cssRules.length);
    }
	 
}

$(function(){
	
	/* Focus on input afrer modal open */
	$('#searchModal').on('shown.bs.modal', function () {
		$('#searchbox2').focus();
	}); 
});
////site-uploads/1001522/frontjs/slide-to-top.js
$(document).ready(function () {
  $('body').find('i').text('');
});

/* slide to top */
$(document).ready(function () {
    $("a[href='#top']").on('click', function (e) {
      e.preventDefault();
      $('html, body').animate({
          scrollTop: 0,
        },
        'slow'
      );
      return false;
    });
  });
  
  $('.goto-Agco-apply-link').on('click', function (e) {
    e.preventDefault();
    $('html,body').animate({
        scrollTop: $('#Agco-apply-link').offset().top - 200,
      },
      'slow'
    );
  });
////site-uploads/1001522/frontjs/frontjs_v8.js
let back_wrapper="<div class='back-wrapper'></div>";

/* ---------Make sure phone is clickable --------*/
$(function(){
	$(".set_phone_number_link").each(function(){
		$(this).attr("href", 'tel:'+window.website_settings.set_phone_number.replace(/[^0-9]/g,''))
	});
	$(".set_phone_number_link2").each(function(){
		$(this).attr("href", 'tel:'+window.website_settings.set_phone_number2.replace(/[^0-9]/g,''))
	});
	
	/*--------move teh featured ads arrows outside the wrapper div ---------*/
	var fix_actionp_arrows = setInterval(function ()
    {
        if ($('.featured-comp').length)
        {	
			$(".featured-comp").append($(".lSAction"));
            clearInterval(fix_actionp_arrows);
            // safe to execute your code here
        }
    }, 100);

$('body').append(back_wrapper); 
/* ADD Back buttin and stock number into gallery in VDP*/

$( "#imageGallery" ).on('DOMSubtreeModified', function() {
	  if($('#normal_vdp').size()>0){
				$(' #normal_vdp .gallery .panel-body').prepend($('.back-wrapper'));
				$(' #normal_vdp .back-wrapper').prepend($('.stock-num, div.back-btn')); 
		}
	});
	
	
	if (window.innerWidth <= 768) {    
		$('#oems_landing').lightSlider({
				item:3,
				loop:true,
				slideMove:2,
				easing: 'cubic-bezier(0.25, 0, 0.25, 1)',
				speed:600,

			}); 
			/*--------move teh featured ads arrows outside the wrapper div ---------*/
			var fix_actionp_arrows_oems = setInterval(function ()
			{
				if ($('.landing-oems').length)
				{	
					$(".landing-oems").append($(".lSAction"));
					clearInterval(fix_actionp_arrows_oems);
					// safe to execute your code here
				}
			}, 100);
		
		}
		

	
/*Modufy the VDP Right Form*/
$("#quote-form .formField").each(function(){ 
$("#quote-form .form-group").append($(this).children(".col-lg-12,.text-center").children("input,textarea,button"))
});
$("#quote-form #firstName").before("<span class='text-myn'>Hi, my name is</span>");
$("#quote-form #email").after($("#phone"));
$("#quote-form #email").before(`<span class='text-zip'>and I'm interested in this `+ttlelement.replace(/<\/?[^>]+(>|$)/g, "").trim()+`. I'm in the</span><input class="required adpage_formbox detailsFormPosatl1" id="PostalCode" name="PostalCode" placeholder="Zip Code*" type="text"><span class="text-ema">area and you can reach me at</span>`);
$("#quote-form #phone").before(`<span class='text-zip'>or on my phone at</span>`);
$("#quote-form #phone").after(`<span class='text-prefered'>What is your preferred method of contact?</span><select aria-invalid="false" class="valid" name="Preferred-method-of-contact" placeholder="Preferred Method of Contact"><option value="">Preferred Method of Contact</option><option>Phone</option><option>Text</option><option>Email</option></select>`);
$("#quote-form button").text(`Check availability`);





	
});


// When the user scrolls down 50px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};

let scroll_button = document.getElementById("to-up");
function scrollFunction() {
  if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 20) {
    $(scroll_button).addClass("active");
  } else {
    $(scroll_button).removeClass("active");
  }
}


//Add default image to VDP when no images loaded
$(function(){
	if($("#imageGallery li:first-child").size() == 0 && $("#normal_vdp").size()>0){
		$("body").append(`<style>.lSSlideOuter {
			background-image: url(/site-uploads/1001522/Images/defaul_bg.jpg);
			min-height: 23rem;
			background-size: contain;
			background-repeat: no-repeat;
			background-position: center;
			margin: 1rem;
		}</style>`);
	}
	
	
	if($("#normal_vdp").size()>0){
		$("p").each(function(){
			if($(this).text().trim() == "_x000D_"){
				$(this).hide();
			}
		});
	}
	
	
	/*Add NEwsletter checkbox to all forms */
	if($('.formsParent').size()>0 && $(".Newsletter-signup").size()==0){
		$('.formsParent .SendCopyCheck').before('<div class="Newsletter-signup"><input type="checkbox" name="Newsletter" checked id="Newsletter-btn" value="1" title="Newsletter Sign up"><label>Sign Up for our Newsletter</label></div>');
	}
	
});




$( "body" ).on('DOMSubtreeModified', function() {
	  if($('.form-thank-you').size()>0){
				gtag('event', 'conversion', {
          'send_to': 'AW-1037984567/ct2KCMTgzp4ZELfG-e4D',
          'value': 1.0,
          'currency': 'CAD'
          });
		}
	});
	






function move_payments(){
	$(".item").each(function(){
	  $(this).find(".model-specs .stock-num").after($(this).find(".permonth.inst_rate"))
	});
}

$(function(){ move_payments(); });
$( document ).ajaxComplete(function( event, request, settings ) {
       move_payments();
});
