$(document).ready(function() { var afBannerHeaderPosition="r"; var afLoadSmall=false; var bannerLocation=""; var url=window.location.href; var popupPopulated=false; var pageCount=getCookie("utcount"); if (pageCount=='') { pageCount=0; } if (url.indexOf("search") > 1) { // SRP var pos=url.lastIndexOf("search")+7; var param=url.slice(pos); var paramKeyPos=param.lastIndexOf("+")+1; var paramKey=param.slice(paramKeyPos); var params=param.split("+"); var srpType=""; var year=""; var make=""; var model=""; var trim=""; for (var i = 0, len = paramKey.length; i < len; i++) { switch (paramKey[i]) { case "t": document.cookie="uttype="+params[i]+"; path=/"; srpType=params[i]; break; case "y": year=params[i]; document.cookie="utye="+params[i]+"; path=/"; break; case "m": make=params[i]; document.cookie="utma="+params[i]+"; path=/"; break; case "M": model=params[i]; document.cookie="utmo="+params[i]+"; path=/"; break; case "T": trim=params[i]; document.cookie="uttr="+params[i]+"; path=/"; break; default: break; } } document.cookie="utin="+param+"; path=/"; document.cookie="utty=srp; path=/"; if (model!='') { loadPopup("/carresearch/PopupSplash/confid_rivertowntoyota-responsive"); popupPopulated=true; } $(document).on("click","input:radio[name=make]", function() { var make=$(this).val(); document.cookie="uttr=; path=/"; document.cookie="utmo=; path=/"; document.cookie="utye=; path=/"; document.cookie="utma="+make+"; path=/"; }); $(document).on("click","input:radio[name=model]", function() { var model=$(this).val(); document.cookie="uttr=; path=/"; document.cookie="utye=; path=/"; model=encodeURI(model); document.cookie="utmo="+model+"; path=/"; }); $(document).on("click","input:radio[name=yearbody]", function() { var yearbody=$(this).val().split(" "); var year=yearbody[0]; document.cookie="uttr=; path=/"; document.cookie="utye="+year+"; path=/"; }); $(document).on("click","input:checkbox:checked[name^=trim]", function() { var trims=$(this).val(); document.cookie="uttr="+trims+"; path=/"; }); if (srpType=="New") { } else if (srpType=="Used") { } else if (srpType=="CPO") { } } else if (url.indexOf("details") > 1) { // VDP var pos=url.lastIndexOf("/")+1; var param=url.slice(pos); var initParams=param.split("#"); var params=initParams[0].split("="); var vin=params[1]; document.cookie="utin="+vin+"; path=/"; document.cookie="utty=vdp; path=/"; loadPopup("/carresearch/PopupSplash/confid_rivertowntoyota-responsive"); } else if (url.indexOf("service") > 1) { // Service document.cookie="utin=; path=/"; document.cookie="utty=service; path=/"; } else if (url.indexOf("parts") > 1) { // Parts document.cookie="utin=; path=/"; document.cookie="utty=parts; path=/"; } if (bannerLocation=='') { var pageType=getCookie("utty"); var pageInput=getCookie("utin"); if (pageType=='srp') { var carType=getCookie("uttype"); var year=getCookie("utye"); var make=getCookie("utma"); var model=getCookie("utmo"); var trim=getCookie("uttr"); if (year=="") { year=new Date().getFullYear(); } trim=encodeURI(trim); if (carType=="New") { } else if (carType=="Used") { } else if (carType=="CPO") { } } else if (pageType=='vdp') { } else if (pageType=='service') { } else if (pageType=='parts') { } } if (window.location.href.indexOf("thank_you") > -1) { document.cookie = "showdiv=no; path=/"; } // Banner Code if (bannerLocation!='') { var bannerLocations=bannerLocation.split(","); var bannerBig=bannerLocations[0]; var bannerSmall=""; if (bannerLocations.length==2) { bannerSmall=bannerLocations[1]; } $("#af-main-header").css({"position":"relative"}); $("#af-nav-mobile").css({"position":"relative"}); $("main").css({"top":"0"}); $("#af-mobile-content-wrapper").css({"top":"0"}); pageCount++; document.cookie="utcount="+pageCount+"; path=/"; if (bannerSmall=='') { if (pageCount=="1") { $(document).ready(function() { $("#af-banner").load(bannerBig, function() { if ($("af-banner").length) { window.addEventListener('scroll', function(e){ var distanceY = window.pageYOffset || document.documentElement.scrollTop; var distanceShrink=$("af-banner").height()/2; if (distanceY > distanceShrink) { $("af-banner").addClass("af-banner-small"); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); } }); $("#af-mobile-content-wrapper").scroll(function() { $("af-banner").addClass("af-banner-small"); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); } var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); }); } else { $(document).ready(function() { $("#af-banner").load(bannerBig, function() { if ($("af-banner").length) { $("af-banner").addClass("af-banner-small"); window.addEventListener('scroll', function(e){ var distanceY = window.pageYOffset || document.documentElement.scrollTop; var distanceShrink=$("af-banner").height()/2; if (distanceY > distanceShrink) { $("af-banner").addClass("af-banner-small"); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); } }); $("#af-mobile-content-wrapper").scroll(function() { $("af-banner").addClass("af-banner-small"); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); } var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); }); } } else { if (pageCount==1) { $(document).ready(function() { $("#af-banner").load(bannerBig); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); } else { $(document).ready(function() { $("#af-banner").load(bannerSmall); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); } } $(document).scroll(function() { var position=$("#af-banner")[0].getBoundingClientRect().top; var height=$("#af-banner").height(); position=-1*position; if (position > height) { if (! afLoadSmall) { if (bannerSmall!='') { $(document).ready(function() { $("#af-banner").load(bannerSmall); }); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); } afLoadSmall=true; } if (afBannerHeaderPosition=="r") { $("#af-main-header").css({"position":"fixed"}); $("#af-nav-mobile").css({"position":"fixed"}); afBannerHeaderPosition="f"; } } else if (afBannerHeaderPosition=="f") { $("#af-main-header").css({"position":"relative"}); $("#af-nav-mobile").css({"position":"relative"}); afBannerHeaderPosition="r"; } }); $("#af-mobile-content-wrapper").scroll(function() { if (! afLoadSmall) { if (bannerSmall!='') { $(document).ready(function() { $("#af-banner").load(bannerSmall); var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); } afLoadSmall=true; } }); $("#af-nav-mobile .dropdown").click(function() { var dropdownmenuAdjustment=$("#af-nav").height()+$("#af-banner").height(); $("#af-nav-mobile .dropdown-menu").css({"top":dropdownmenuAdjustment}); }); } // ignore link clicking and form submission for beforeunload event var normalevent=true; if (window.innerWidth <= 768) { normalevent=false; } $("a").mousedown(function() { var classname=$(this).attr("class"); if (classname!='dropdown-toggle') { // Ignore top menu clicks, other non-navigation clicks also need to be ignored normalevent = false; } }); // mm3 link needs to be overwritten. Code below doesn't work yet. $('.af-search-match-box').on('mouseup', function(e) { normalevent = false; }); $("form").submit(function() { normalevent = false; }); $(window).on('beforeunload', function(e){ // popupPopulated=updatePopupContent(); if (! popupPopulated) { normalevent = false; } // Popup has no content if (normalevent) { var showdiv = getCookie('showdiv'); // already closed hidden div previously. skip if (showdiv == 'no') { return; } e.preventDefault(); var confirmationMessage = ""; var pageType=getCookie("utty"); $('.af-popup').show(); document.cookie = "showdiv=no; path=/"; $("body").css({"overflow":"hidden"}); if (pageType=='srp') { confirmationMessage=""; } else if (pageType=='vdp') { confirmationMessage=""; } else if (pageType=='service') { confirmationMessage=""; } else if (pageType=='parts') { confirmationMessage=""; } return confirmationMessage; } }); // This should be adjust to however we close our hidden div $('a.af-popup-close').click(function(){ // close hidden div $('.af-popup').hide(); $("body").css({"overflow":"auto"}); }); }); function openOffer() { $('af-banner').removeClass('af-banner-small'); } var popupAjaxURL=''; function loadPopup(url) { if (url!=popupAjaxURL) { $(document).ready(function() { popupAjaxURL=url; $("#af-popup-ajaxcontent").load(url); }); } } function updatePopupContent() { var populated=false; var pageType=getCookie("utty"); var pageInput=getCookie("utin"); if (pageType=='srp') { var carType=getCookie("uttype"); var year=getCookie("utye"); var make=getCookie("utma"); var model=getCookie("utmo"); var trim=getCookie("uttr"); if (year=="") { year=new Date().getFullYear(); } trim=encodeURI(trim); if (carType=="New" && model!='') { var urlParams=""; if (year!='') { urlParams+="year_"+year+"/"; } if (make!='') { urlParams+="make_"+make+"/"; } if (model!='') { urlParams+="model_"+model+"/"; } var popupURL="/carresearch/PopupTrim/confid_rivertowntoyota-responsive/confid_rivertowntoyota-responsive/"+urlParams; if (make!='' && model!='' ) { loadPopup(popupURL); populated=true; } } else if (carType=="Used") { } else if (carType=="CPO") { } } // } else if (pageType=='vdp') { // // } else if (pageType=='service') { // // } else if (pageType=='parts') { // // } // if (populated) { alert("true"); } else { alert("false"); } return populated; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i