var chatV2Wap={initEventOfBoxLoginBuyer:function(){const t=this,n=".chat-box";$("#btnStartChat",n).on("click",function(){let i=$("#txtChatPhoneNumber",n).val().trim();if(i)if(/^(09|08)\d{9}$/.test(i)){$("#txtChatPhoneNumber-error").text("").hide();let n=$("#hddDealerId").val();t.getLinkChatWithSeller(n,i)}else $("#txtChatPhoneNumber-error").text("eg: 09012345678 | 08112345678").show();else $("#txtChatPhoneNumber-error").text("Please enter your phone number").show()});$("#btnChatClear",n).on("click",function(){$("#txtChatPhoneNumber-error").hide()});$(".chat-box-control",n).on("click",function(){$(n).addClass("hidden");$("#btnChatClear",n).click();typeof CommonsEvent!="undefined"&&CommonsEvent.RemoveNoScroll()})},getLinkChatWithSeller:function(n,t){const i=this;n&&(t||(t=""),$.ajax({type:"POST",cache:!1,url:"/ChatV2/GetLinkChatWithSeller",data:{toSellerId:n,fromBuyerPhone:t},beforeSend:function(){CommonsEvent.Loading()},success:function(n){!n||n.Error?alert(n.Title):location.href=n},error:function(n,t,i){console.log(i)},complete:function(){CommonsEvent.Loaded()}}))},removeCookieForChat:function(){$.removeCookie("hddTypeOfLinkChat");$.removeCookie("hddBuyerPhoneEncryped");$.removeCookie("hddSellerIdEncryped");$.removeCookie("accessTokenApi");typeof Utility!="undefined"&&Utility.SetCookie("hddTypeOfLinkChat",0,1)}};$(document).ready(function(){let r=$("#hddUserId").val();const n=".starter-icon-container",t="#btnSkip";$(".box-fb-google").length==0&&$(n).removeClass("prevent-click");try{chatV2Wap.initEventOfBoxLoginBuyer();$(n).on("click",function(){let n=$("#hddUserId").val();n?$.ajax({type:"POST",cache:!1,url:"/ChatV2/GetLinkChatboxForLoginUser/",success:function(n){!n||n.Error||(location.href=n)},error:function(n,t,i){console.log(i)}}):location.href="/login?ReturnUrl=/chat/messages"});$(t).on("click",function(){let n=$(t).attr("data-href");!n||(console.log("remove accessTokenApi"),$.removeCookie("accessTokenApi"),setTimeout(function(){location.href=n+"&isSkip=true"},500))});$(".btn-chat-seller-v2").on("click",function(){let t=$(this).attr("data-seller-id"),i=$("#hddUserId").val();if(i){if(t==i){alert("You cannot chat with yourself");return}chatV2Wap.getLinkChatWithSeller(t)}else{$(n).addClass("hidden");$("#chat-ui .chat-box").removeClass("hidden");typeof CommonsEvent!="undefined"&&CommonsEvent.AddNoScroll();return}});$(".chat-with-seller-fb").on("click",function(){let n=$("#hddProductId").val();(typeof n=="undefined"||n=="")&&(n=0);let t=$("#hddUserId").val();(typeof t=="undefined"||t=="")&&(t=0);let i=$("#hddDealerId").val();(typeof i=="undefined"||i=="")&&(i=0);let r={event:"actionUsedcar",action:"FB messenger",pageType:"Detail",productID:n,sellerID:i,userID:t};typeof GtmUtils!="undefined"&&GtmUtils.pushDataEvent(r)})}catch(i){console.error(i)}})