function SuperGridWatchlistButtonClick(n,t,i,r,u){n.preventDefault?n.preventDefault():n.returnValue=!1,n.stopPropagation?n.stopPropagation():n.cancelBubble=!0;var e=$(t).attr("id"),f="/Browse/AddToWatchlist.aspx?id="+i+"&type="+r+"&cat="+u+"&emailReminder=2&jsValidationToken="+encodeURIComponent(getJsValidationTokenFromMetaTag()),o="/API/Ajax/Watchlist.aspx?useSavedReminderValues=true&id="+i+"&type="+r+"&linkId="+e+"&cid="+u+"&initalUrl="+encodeURIComponent(f)+"&fromSearchCard=true&noJobsWatchlistPopup=true";return $savedLinks[e]?!1:($(t).addClass("adding"),requestSentTime=new Date,SuperGridUpdateCornerToSaved(i,!0),jQuery.ajax({type:"GET",url:o,success:function(n){SuperGridWatchlistSaveHandler(n,f)},error:function(){location.href=f},dataType:"json"}),!1)}function SuperGridUndoWatchlistCornerClick(n,t,i){n.preventDefault?n.preventDefault():n.returnValue=!1,n.stopPropagation?n.stopPropagation():n.cancelBubble=!0;var r="/API/Ajax/WatchlistUnwatch.aspx?id="+i;return SuperGridUpdateCornerToSaved(i,!1),jQuery.ajax({type:"GET",url:r,success:function(n){n.type==="Success"&&typeof WatchlistRetargetHandler==typeof Function&&WatchlistRetargetHandler("del",n)},error:function(){},dataType:"json"}),!1}function SuperGridSwallowUnwatchClick(n){return n.stopPropagation(),!1}function SuperGridWatchlistSaveHandler(n,t){switch(n.type){case"LoginWithUrl":LogIn(n.data);break;case"WatchlistSaveInvalidAttempt":location.href=t;break;case"Failed":location.href=n.Data;break;case"SuccessWithId":SuperGridSearchWatchlistSaveSuccess(n.linkId,n.pixelUrl),SuperGridUpdateButtonToSaved(n.linkId),PushWatchlistToDataLayer(n.gtm),typeof WatchlistRetargetHandler==typeof Function&&WatchlistRetargetHandler("add",n);break;default:location.href=n.Data}}function SuperGridSearchWatchlistSaveSuccess(n,t){$savedLinks[n]=n,TradeMe.ads.getWatchlistPixel(t);return}function SuperGridUpdateButtonToSaved(n){var t=$('[id="'+n+'"]');t.removeClass("adding"),t.addClass("watched"),t.onclick=function(){},t.attr("onclick",""),$("#"+n.replace("watchlist","iswatched")).val("True")}function SuperGridUpdateCornerToSaved(n,t){var i=$('[id="watchlisted'+n+'"]'),u="watchlist"+n,f=$('[id="'+u+'"]'),o="watchlistedIcon"+n,r=$('[id="'+o+'"]'),e;t?(i.removeClass("unwatched-corner"),i.addClass("watched-corner"),r.removeClass("watchlist-tick-icon-off"),r.addClass("watchlist-tick-icon-on")):(i.removeClass("watched-corner"),i.addClass("unwatched-corner"),r.removeClass("watchlist-tick-icon-on"),r.addClass("watchlist-tick-icon-off"),f.removeClass("watched"),f.removeClass("adding"),$savedLinks=$savedLinks.filter(function(){return this!==u})),e="return SuperGridUndoWatchlistCornerClick(event, this, "+n+");",i.attr("onclick",e)}function LogIn(n){location.href="/Members/Login.aspx?url="+escape(n)}function PushWatchlistToDataLayer(n){dataLayer.push({event:n.event,listingId:n.watchlistListingId,title:n.watchlistTitle,categoryLevel1:n.watchlistCategoryLevel1,categoryLevel2:n.watchlistCategoryLevel2,categoryLevel3:n.watchlistCategoryLevel3,categoryLevel4:n.watchlistCategoryLevel4,categoryLevel5:n.watchlistCategoryLevel5,mcat:n.watchlistMcat,newOrUsed:n.watchlistNewOrUsed,auctionOrClassified:n.watchlistAuctionOrClassified,store:n.watchlistStoreName,subtitle:n.watchlistSubtitle,sellerId:n.watchlistSellerId,sellerInTrade:n.watchlistSellerInTrade,isBuyNow:n.watchlistIsBuyNow,isPayNow:n.watchlistIsPayNow,isFeatured:n.watchlistIsFeatured,isSuperFeatured:n.watchlistIsSuperFeatured,mustPickUp:n.watchlistMustPickUp,sellerRegion:n.watchlistSellerRegion,sellerDistrict:n.watchlistSellerDistrict,freeShipping:n.watchlistFreeShipping,motorsKilometers:n.watchlistMotorsKilometers,motorsMake:n.watchlistMotorsMake,motorsType:n.watchlistMotorsType,motorsDealerId:n.watchlistMotorsDealerId,motorsAutobaseVehicleId:n.watchlistMotorsAutobaseVehicleId,propertyType:n.watchlistPropertyType,propertyUse:n.watchlistPropertyUse,propertyPriceType:n.watchlistPropertyPriceType,propertyRegion:n.watchlistPropertyRegion,propertyDistrict:n.watchlistPropertyDistrict,propertySuburb:n.watchlistPropertySuburb,jobsRegion:n.watchlistJobsRegion,jobsDistrict:n.watchlistJobsDistrict,jobsSuburb:n.watchlistJobsSuburb,jobsType:n.watchlistJobsType,jobsCompany:n.watchlistJobsCompany,businessLine:n.watchlistBusinessLine,band:n.watchlistBand})}function WatchlistRetargetHandler(n,t){var u,e,f,r,o,i;if(n&&t&&(u=t.gtm,e=t.listingId,e&&u.watchlistMotorsDealerId&&u.watchlistCategoryLevel2==="cars")){if(f=u.watchlistMotorsDealerId.toString(),r=$('input[id$="WatchlistRetargetDealers"]:first').val(),r=typeof r=="undefined"?"":r.replace(/\s/g,""),r!=="*"&&(","+r+",").indexOf(","+f+",")<0)return;if(o=e.toString(),i=window.localStorage,i)try{switch(n){case"add":i.setItem("dealerid",f),i.setItem("watchlistid",o);break;case"del":f===i.getItem("dealerid")&&o===i.getItem("watchlistid")&&(i.removeItem("dealerid"),i.removeItem("watchlistid"))}}catch(s){}}}var requestSentTime=null,$savedLinks=Array();$(document).ready(function(){var t,n,i;for($("div.watchlist").removeClass("adding"),$("#Main.fashion-landing").find(".supergrid-listing.bottom.small").addClass("fashion"),$("#Main").not(".fashion-landing").find(".supergrid-listing.bottom.small").addClass("normal"),$('[id="watched-corner-btn"]').hover(function(){$(this).find(".has-bid").css("cursor","default").find("span").removeClass("tmicon-function-tick").addClass("tmicon-lock-closed")},function(){$(this).find(".has-bid").find("span").removeClass("tmicon-lock-closed").addClass("tmicon-function-tick")}),t=document.querySelectorAll(".onloadwlfix"),n=0;n<t.length;n++)t[n].value=="True"&&(i=$(t[n]).attr("id").replace("iswatched","watchlist"),$("#"+i).hasClass("watched")||SuperGridUpdateButtonToSaved(i))})