
////site-uploads/1001460/frontjs/main_v1.js
/*handle phone numbers anchor href attr*/
$(document).ready(function () {
  var tel_1 = "tel:4186896283";
  $("body").find("a.tel-1").attr("href", tel_1);
  var tel_2 = "tel:";
  $("body").find("a.tel-2").attr("href", tel_2);
});

$(document).ready(function () {
  $("body").find("i").text("");
});

/* Menu */
$(document).ready(function () {
  $(".navbar-toggle").on("click", function () {
    $(this).toggleClass("active");
  });
});

/* Active State Menu */
$(document).ready(function () {
  var url = window.location.pathname;
  $('ul.nav a[href="' + url + '"]')
    .parent()
    .addClass("active");
  $("ul.nav a")
    .filter(function () {
      return this.href == url;
    })
    .parent()
    .addClass("active");
});

/* Sticky Menu on Scroll */
$(function () {
  $(window).on("scroll", function () {
    if ($(window).scrollTop() > 48) {
      $("#comp_1671645795095").addClass("sticky-nav");
    } else {
      $("#comp_1671645795095").removeClass("sticky-nav");
    }
  });
});

/* Slide to top */
$(document).ready(function () {
  $("a[href='#top']").on("click", function (e) {
    e.preventDefault();
    $("html, body").animate(
      {
        scrollTop: 0,
      },
      "slow"
    );
    return false;
  });
});

$(document).ready(function () {
  if ($("#normal_vdp").length) {
    if ($(".get-financed").length) {
      var el = $(".get-financed");
      var html = el.html();
      html = html.replace("Get Financed", "Financing");
      el.html(html);
    }
    if ($(".trade-btn").length) {
      var el = $(".trade-btn");
      var html = el.html();
      html = html.replace("Value a Trade", "Value your Trade");
      el.html(html);
    }

    if ($(".ecomm-btns .ecomm-btn").length) {
      var el = $(".ecomm-btns .ecomm-btn");
      var html = el.html();
      html = html.replace("Hold With Deposit", "Reserve");
      el.html(html);
    }

    if ($(".our-price-div .our-price").length) {
      var el = $(".our-price-div .our-price");
      var html = el.html();
      html = html.replace("Dealer Price", "Starting from:");
      el.html(html);
    }

    if ($(".our-price-div .primary").length) {
      var el = $(".our-price-div .primary");
      var html = el.html();
      html = html.replace("$", "");
      html = html.replace(" CAD", "$");
      el.html(html);
    }
  }
});

$(document).ready(function () {});

// var theLanguage = $('html').attr('lang');
// // Diferent language
// if (theLanguage == 'fr') {
//     $('.finacning-link').attr('href', '/fr/Finance-Request');

//     $('.finacning-link').attr('target', '_self');
// } else {
//     $('.finacning-link').attr('href', '/Finance-Request');

//     $('.finacning-link').attr('target', '_self');
// }

/* handle slider links in EN - FR */
$(document).ready(function () {
  if ($('[data-com-id="Slider"]').length) {
    $(".carousel-inner .item").each(function (idx, el) {
      var langPrefix = $("html").attr("lang");
      var element = $(el);
      var newHref =
        "/" +
        langPrefix +
        "/" +
        element.find(".sliderTitle").text().trim().replace(" ", "-");
      console.log("newHref => ", newHref);
      element.attr("href", newHref);
    });
  }
});

function changeSRPPriceLable() {
  if ($(".light2021").length) {
    if ($(".price.price.show-item .ttl").length) {
      $(".price.price.show-item .ttl").text("");
    }

    if ($(".price.price.show-item").length) {
      $(".price.price.show-item").each(function (i, obj) {
        //test
        // var el = $('.price.price.show-item');
        var html = obj.html();
        var html = html.replace("CAD", "");
        obj.html(html);
      });
    }

    if (
      $(".add-to-cart-product.deposit-to-cart.add-to-cart-btn.show-item").length
    ) {
      var el = $(
        ".add-to-cart-product.deposit-to-cart.add-to-cart-btn.show-item"
      );
      var html = el.html();
      var html = html.replace("Deposit", "Reserve");
      el.html(html);
    }
  }
}

$(document).ajaxComplete(function () {
  changeSRPPriceLable();
});

$(document).ready(function () {
  changeSRPPriceLable();
});

$(document).ready(function () {
  if ($("#normal_vdp").length) {
    var langPrefix = $("html").attr("lang");
    var element = $(".get-financed.finacning-link");
    var newHref = "/" + langPrefix + "/Finance";
    console.log("newHref => ", newHref);
    element.attr("href", newHref);
  }
});
////site-uploads/1001460/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/1001460/frontjs/Search_script.js
if (document.getElementById('searchbox')) {
  document
    .getElementById('searchbox')
    .addEventListener('keyup', function (event) {
      event.preventDefault();
      if (event.keyCode === 13) {
        document.getElementById('searchbtn')?.click();
      }
    });
}
function srch(e, page_name) {
  e.preventDefault();
  console.log(page_name);
  //var e = document.getElementById("pagedd");
  //var dest= e.options[e.selectedIndex].value;
  var valuee = document.getElementById('searchbox')?.value;
  if (valuee != '') {
    if (page_name == 'Inventory') {
      window.location = '/Search-Inventory/search/'.concat(valuee);
    } else {
      window.location = '/Search-parts/search/'.concat(valuee);
    }
  } else {
    document.getElementById('searchbox').placeholder = 'This field is required';
    var sheet = window.document.styleSheets[0];
    sheet.insertRule(
      'input#searchbox::-webkit-input-placeholder {color: red !important}',
      sheet.cssRules.length
    );
    sheet.insertRule(
      'input#searchbox::-moz-placeholder {color:#909; opacity:1;}',
      sheet.cssRules.length
    );
    sheet.insertRule(
      'input#searchbox:-moz-placeholder {color:#909; opacity:1;}',
      sheet.cssRules.length
    );
  }
}
