var home={isLoadCombobox:!1,init:function(){var n,t,i,e,r,u,f;document.getElementById("cbNewCar").checked==!0&&($(".box-search-home .tab-new-car").removeClass("none-i"),$(".box-search-home .tab-used-car").addClass("none-i"));menu.active_menu(1);n=$("#cbCity").select2();t=$("#cbBrand").select2();$("#cbBudget").select2();i=$("#cbBrandNewCar").select2();$("#cbBudgetNewCar").select2();n.on("select2:opening",function(){home.load_combo(function(){n.select2("close");n.select2("open")})});t.on("select2:opening",function(){home.load_combo(function(){t.select2("close");t.select2("open")})});i.on("select2:opening",function(){home.load_combo(function(){i.select2("close");i.select2("open")})});$("#btnSearch").click(function(){var r=3,f=document.getElementById("cbUsedCar").checked,n="",t="",i="",u;f?(n=$("#cbBrand").val(),t=$("#cbBudget").val(),i=$("#cbCity").val()):(r=2,n=$("#cbBrandNewCar").val(),t=$("#cbBudgetNewCar").val(),i="0");searchModel={CityId:i,BrandIdStr:n,PriceId:t,Secondhand:r};u="/Home/GetSearchLink";ajax_feed.post_json_extention(u,searchModel,null,function(n){return location.href=n})});$("#cbBrandNewCar").change(function(){var n=$(this).val(),t,i;/-/g.test(n)&&(t="/Home/GetDetailNewCar",i={brand:n},ajax_feed.post_json_extention(t,i,null,function(n){n!=null&&n!=undefined&&n!=""&&(window.location.href=n)}))});$(".top-city-home").length>0&&(e=new Swiper(".top-city-home .swiper-container",{slidesPerView:"auto",spaceBetween:6,centeredSlides:!1,grabCursor:!1}));$("#top_brand_home").length>0&&(r=new Swiper("#top_brand_home.swiper-container",{slidesPerView:"auto",spaceBetween:6,centeredSlides:!1,grabCursor:!1}));$("#stories_home").length>0&&(r=new Swiper("#stories_home.swiper-container",{slidesPerView:"auto",spaceBetween:6,centeredSlides:!1,grabCursor:!1}));$("#cbUsedCar").click(function(){$(".box-search-home .tab-new-car").addClass("none-i");$(".box-search-home .tab-used-car").removeClass("none-i")});$("#cbNewCar").click(function(){$(".box-search-home .tab-new-car").removeClass("none-i");$(".box-search-home .tab-used-car").addClass("none-i")});$("#RecommendedUsedCar").length>0&&(u="/Home/RecommendedUsedCarBox",f={},ajax_feed.post_html_extention(u,f,null,function(n){$("#RecommendedUsedCar").html(n);setTimeout(function(){$("img.lazy").length>0&&new LazyLoad({elements_selector:".lazy"})},200)}));randomBanner.run()},load_combo:function(n){home.isLoadCombobox||setTimeout(function(){ajax_feed.post_json_extention("/Home/GetDataForComboSearch",null,null,function(t){var i,u,e,c,r,f;if(t!==null){home.isLoadCombobox=!0;var o="",s="",h="";if(t.ListBrand!==null)for(i=0;i<t.ListBrand.length;i++)if(t.ListBrand[i].Name!==null&&t.ListBrand[i].Name!==""&&(s+='<option value="'+t.ListBrand[i].BranchId+'" class="select-group-name">'+t.ListBrand[i].Name+"<\/option>",t.ListBrand[i].Models!==undefined&&t.ListBrand[i].Models.length>0))for(u=0;u<t.ListBrand[i].Models.length;u++)t.ListBrand[i].Models[u].ModelName!==null&&t.ListBrand[i].Models[u].ModelName!==""&&(s+='<option value="'+t.ListBrand[i].BranchId+"-"+t.ListBrand[i].Models[u].Id+'">'+t.ListBrand[i].Name+" "+t.ListBrand[i].Models[u].ModelName+"<\/option>");if(t.ListProvince!==null)for(e=0;e<t.ListProvince.length;e++)c=t.ListProvince[e].Id===t.CityId?"selected":"",h+="<option "+c+' value="'+t.ListProvince[e].Id+'" >'+t.ListProvince[e].Name+"<\/option>";if(t.ListBrandNewCar!==null)for(r=0;r<t.ListBrandNewCar.length;r++)if(t.ListBrand[r].Name!==null&&t.ListBrandNewCar[r].Name!==""&&(o+='<option value="'+t.ListBrandNewCar[r].BranchId+'" class="select-group-name">'+t.ListBrandNewCar[r].Name+"<\/option>",t.ListBrandNewCar[r].Models!==undefined&&t.ListBrandNewCar[r].Models.length>0))for(f=0;f<t.ListBrandNewCar[r].Models.length;f++)t.ListBrandNewCar[r].Models[f].ModelName!==null&&t.ListBrandNewCar[r].Models[f].ModelName!==""&&(o+='<option value="'+t.ListBrandNewCar[r].BranchId+"-"+t.ListBrandNewCar[r].Models[f].Id+'">'+t.ListBrandNewCar[r].Name+" "+t.ListBrandNewCar[r].Models[f].ModelName+"<\/option>");$("#cbCity").append(h);$("#cbBrandNewCar").append(o);$("#cbBrand").append(s);$("#cbCity").trigger("change.select2");$("#cbBrand").trigger("change.select2");$("#cbBrandNewCar").trigger("change.select2")}n!==null&&typeof n=="function"&&n()})},1)}};