var GetPromo={init:function(){try{typeof $.fn.trimSpace!="undefined"&&$("#feedbackDealer input.w-full,#feedbackDealer textarea").trimSpace()}catch(n){console.error("Exception : GetPromo.init() => "+n)}},initPopup:function(){const i=this;let n="#frmGetPromo",t=!1;$("#subGetPromo",n).on("click",function(){$("#RegionId",n).val($("#cboSearchRegionIdPopup",n).val());$("#CityId",n).val($("#cboSearchCityIdPopup",n).val());$("#BrandId",n).val($("#cboSearchBrandIdPopup",n).val());$("#ModelId",n).val($("#cboSearchModelIdPopup",n).val());t=i.validateForm();t&&$("#subFormGetPromo",n).click()});$("#popup #btnContinueSubmitGetpromo").on("click",function(){t&&$("#subFormGetPromo",n).click()});$("#popupModel .head-collapse ").on("click",function(){$(this).parent().hasClass("open")?$(this).parent().removeClass("open"):$(this).parent().addClass("open")});i.checkRegionMatchPromo()},showPopupGetPromo:function(n,t,i,r,u){var e,f;const o=this;t!=1||u||(e=$(n).attr("data-page"),!isNaN(e)&&e>0&&(u=e));f="";i?(f+="?modelId="+i,!r||(f+="&variant="+r),!u||(f+="&PageTypeId="+u)):!u||(f+="?PageTypeId="+u);let s=parseInt($(n).attr("data-promo-id"));!s||(f+=f?"&PromoId="+s:"?PromoId="+s);$("#popup").html("");PostForm.LoadPopupFromUrl("/Subscribe/GetPromoMembership"+f,null,function(){window.cboBrandModelSearch=$("#cboBrandModelSearchPopup").CustomDropdown({targetInputId:"cboSearchBrandModelIdPopup",targetTextId:"cboBrandModelTextSearchPopup",boxId:"cstBrandModelDropdownSearchPopup",boxTitle:"Select a Brand/Model",optionValueProperty:"Id",optionTextProperty:"Name",defaultText:"Brand/Model",grouped:!0,groupedLink:!1,groupFetchType:"merged",groupsFetchUrl:"/Common/GetListBrandModel",groupValueProperty:"GroupId",groupTextProperty:"GroupName",groupLinkProperty:"GroupLink",optionsInGroupProperty:"ListItem",targetGroupInputId:"cboSearchBrandModelGroupIdPopup"});window.cboCitySearch=$("#cboCitySearchPopup").CustomDropdown({targetInputId:"cboSearchCityIdPopup",targetTextId:"cboCityTextPopup",boxId:"cstCityDropdownPopup",boxTitle:"Select a City/Region",optionValueProperty:"Id",optionTextProperty:"Name",defaultText:"City/Region",grouped:!0,groupFetchType:"merged",groupsFetchUrl:"/Common/GetListRegionCity",groupValueProperty:"GroupId",groupTextProperty:"GroupName",optionsInGroupProperty:"ListItem",onSelected:function(){GetPromo.checkRegionMatchPromo()}});$("#desFeedback").text("Fill in the form below to request information about get promo");$("#feedbackDealer .test-driver").addClass("hidden");$("#txtFeedbackType").val(t);$("#titFeedback").text("Get Promo");typeof Location!="undefined"&&Location.InitLocationEvent();$("#subGetPromo").length>0&&o.checkTermAndConditionPopup("#subGetPromo");$("#btnFeedback").length>0&&o.checkTermAndConditionPopup("#btnFeedback");o.initPopup();var n=$("#feedbackDealer #hddCallBackCityName").val();typeof n!="undefined"&&n!=""&&$("#feedbackDealer #cboCityTextPopup").empty().text(n);try{if(t==feedbackDealerTypeEnum.getQuote||t==feedbackDealerTypeEnum.availPromo){let t="Other";location.pathname.indexOf("-dpid")>-1?t="Detail":(location.pathname.indexOf("-promotions-in-the-philippines")>-1||location.pathname.indexOf("search-car-promos")>-1)&&(t="List");let i="",n=$("#cboBrandModelTextFormRequest").text();n||(n=$("#cboBrandModelTextSearchPopup").text());let u=$("#cboCityTextPopup").text();i||(i="");n||(n=$("#cboBrandModelTextSearchPopup").text());n||(n="");let r=$("#hddUserId").val();r||(r=0);let f={event:"actionNewCarPromo",action:"click",model:i+" "+n,city:u,pageType:t,userID:r};typeof GtmUtils!="undefined"&&GtmUtils.pushDataEvent(f);$("#feedbackDealer .close").on("click",function(){let f={event:"actionNewCarPromo",action:"close",model:i+" "+n,city:u,pageType:t,userID:r};typeof GtmUtils!="undefined"&&GtmUtils.pushDataEvent(f)})}}catch(i){console.error("Exception : Wap => GetPromo.showPopupGetPromo() => "+i)}})},checkTermAndConditionPopup:function(n){if(typeof n!="undefined"&&n!=""&&$("#popup").length>0)$("#popup").on("change","#termsAgreedPopup",function(){$(this).is(":checked")?$(n,"#popup").removeClass("readonly-btn"):$(n,"#popup").addClass("readonly-btn")})},validateForm:function(){var n="#frmGetPromo",r=$("#FullName",n),t=$("#Email",n),i=$("#Phone",n);if($("#lblMessage",n).empty(),r.val()&&r.val().trim())$("#lblMessage",n).empty().text("");else return $("#lblMessage",n).empty().text("Please enter your full name"),r.focus(),!1;if(t.val()&&t.val().trim())if(emailValidate.isValidEmail(t.val()))$("#lblMessage").empty().text("");else return $("#lblMessage").empty().text("Invalid email address format"),t.focus(),!1;else return $("#lblMessage",n).empty().text("Please enter email address"),t.focus(),!1;if(i.val()&&i.val().trim()){let t=i.val().replace(/\s+/g,"");if(t.length>9&&t.match(/^(09|08)\d{9}$/))$("#lblMessage",n).empty().text("");else return $("#lblMessage",n).empty().text("Phone Message: eg: 09012345678 | 08112345678"),i.focus(),!1}else return $("#lblMessage",n).empty().text("Please enter your phone number"),i.focus(),!1;return!0},checkRegionMatchPromo:function(){if($("#hddListRegionIds").val()!=0){const u=this,r="#frmGetPromo";let t=$("#hddListRegionIds").val().split(","),i=parseInt($("#cboSearchCityIdPopup",r).val()),n=0;$("#cboSearchCityIdPopup",r).val()==""||i==0||t.includes("0")?($("#checkMatchRegion").addClass("hidden"),$("#checkMatchRegion_Suitable").removeClass("hidden")):(isNaN(i)&&(i=0),$.ajax({type:"GET",cache:!1,url:"/Region/GetRegionByCityId/",data:{cityId:i},success:function(i){if(i!=null&&(n=i.Id,!!t&&t!=""&&!!n&&n>0)){var r=t.includes(n.toString());r==!0?($("#checkMatchRegion").addClass("hidden"),$("#checkMatchRegion_Suitable").addClass("hidden")):u.showWarningLocation(n,i.Name)}}}))}},showWarningLocation:function(n,t){let i={BrandId:0,ModelId:0,RegionId:n,CityId:0,DealershipId:0,PaymentType:0};$.ajax({type:"POST",cache:!1,url:"/DealerPromos/GetSearchLinkJson/",data:i,success:function(n){$("#regionTextSelected").text(t);$(".regionTextSelected").text(t);$("#urlRedirectToRegionSelected").attr("href",n);$("#checkMatchRegion").removeClass("hidden");$("#checkMatchRegion_Suitable").addClass("hidden")}})}}