function GotoPage(n){var t=n.attr("data-page");$.ajax({type:"GET",url:"/licensing/docs/Search/GetDocumentPage?pageNumber="+t,datatype:"json",contentType:"application/json",success:function(n){RebuildResultsView(n)},error:function(){toastr.error("Error paging documents")}})}function NextPages(){$.ajax({type:"GET",url:"/licensing/docs/Search/GetNextPages",datatype:"json",contentType:"application/json",success:function(n){RebuildResultsView(n)},error:function(){toastr.error("Error paging documents")}})}function PreviousPages(){$.ajax({type:"GET",url:"/licensing/docs/Search/GetPreviousPages",datatype:"json",contentType:"application/json",success:function(n){RebuildResultsView(n)},error:function(){toastr.error("Error paging documents")}})}function BindSortControls(){$(".view .sort-control").click(function(n){n.preventDefault();SetSort($(this))});$(".view #doc-page-size").change(function(){DoSearch()});$("div.featuredDocument").hide();$("div.webpageDocument").hide();$("div.licensingGuideDocument").hide();$("div.licensingBriefDocument").hide();$("div.whitepaperDocument").hide();$("div.faqDocument").hide();$("div.datasheetDocument").hide();$("div.otherDocument").hide();$("div.featuredDocument").slice(0,5).show();$("div.webpageDocument").slice(0,5).show();$("div.licensingGuideDocument").slice(0,5).show();$("div.licensingBriefDocument").slice(0,5).show();$("div.whitepaperDocument").slice(0,5).show();$("div.faqDocument").slice(0,5).show();$("div.datasheetDocument").slice(0,5).show();$("div.otherDocument").slice(0,5).show();$("#featuredTo").text(Math.min($(".view #featuredDocuments-page-size").val(),$("#featuredCount").val()));$("#webpagesTo").text(Math.min($(".view #webpages-page-size").val(),$("#webpagesCount").val()));$("#licensingGuidesTo").text(Math.min($(".view #licensingGuides-page-size").val(),$("#licensingGuidesCount").val()));$("#licensingBriefsTo").text(Math.min($(".view #licensingBriefs-page-size").val(),$("#licensingBriefsCount").val()));$("#whitepapersTo").text(Math.min($(".view #whitepapers-page-size").val(),$("#whitepapersCount").val()));$("#faqsTo").text(Math.min($(".view #faqs-page-size").val(),$("#faqsCount").val()));$("#datasheetsTo").text(Math.min($(".view #datasheets-page-size").val(),$("#datasheetsCount").val()));$("#othersTo").text(Math.min($(".view #others-page-size").val(),$("#othersCount").val()));$(".view #featuredDocuments-page-size").change(function(){$("div.featuredDocument").hide();$("div.featuredDocument").slice(0,$(this).val()).show();$("#featuredTo").text(Math.min($(this).val(),$("#featuredCount").val()))});$(".view #webpages-page-size").change(function(){$("div.webpageDocument").hide();$("div.webpageDocument").slice(0,$(this).val()).show();$("#webpagesTo").text(Math.min($(this).val(),$("#webpagesCount").val()))});$(".view #licensingGuides-page-size").change(function(){$("div.licensingGuideDocument").hide();$("div.licensingGuideDocument").slice(0,$(this).val()).show();$("#licensingGuidesTo").text(Math.min($(this).val(),$("#licensingGuidesCount").val()))});$(".view #licensingBriefs-page-size").change(function(){$("div.licensingBriefDocument").hide();$("div.licensingBriefDocument").slice(0,$(this).val()).show();$("#licensingBriefsTo").text(Math.min($(this).val(),$("#licensingBriefsCount").val()))});$(".view #whitepapers-page-size").change(function(){$("div.whitepaperDocument").hide();$("div.whitepaperDocument").slice(0,$(this).val()).show();$("#whitepapersTo").text(Math.min($(this).val(),$("#whitepapersCount").val()))});$(".view #faqs-page-size").change(function(){$("div.faqDocument").hide();$("div.faqDocument").slice(0,$(this).val()).show();$("#faqsTo").text(Math.min($(this).val(),$("#faqsCount").val()))});$(".view #datasheets-page-size").change(function(){$("div.datasheetDocument").hide();$("div.datasheetDocument").slice(0,$(this).val()).show();$("#datasheetsTo").text(Math.min($(this).val(),$("#datasheetsCount").val()))});$(".view #others-page-size").change(function(){$("div.otherDocument").hide();$("div.otherDocument").slice(0,$(this).val()).show();$("#othersTo").text(Math.min($(this).val(),$("#othersCount").val()))});$(".view .page-button").click(function(n){n.preventDefault();GotoPage($(this))});$(".view .previous-page-button").click(function(n){n.preventDefault();PreviousPages()});$(".view .next-page-button").click(function(n){n.preventDefault();NextPages()});var n=$('.view .sort-control [data-sort]:not([data-sort=""])').first(),t=n.attr("data-sort"),i="desc";(!t||t.endsWith("asc"))&&(i="asc");n.addClass(i)}function RebuildResultsView(n){$("#search-results").replaceWith(n);BindSortControls()}function SetSort(n){var t=n.find(".sort-title"),u=t.attr("data-sortname"),r=t.attr("data-sort"),i;$(".view .sort-control .sort-title").attr("data-sort","");$(".view .sort-control .sort-title").removeAttr("data-sort");i="asc";(!r||r.endsWith("asc"))&&(i="desc");t.attr("data-sort",u+"_"+i);DoSearch()}function loadSelectedFilters(){$("#selected-filters").empty();var n=$("ul.filter-list .checkbox-field input:checked").not("input.all-value").get();n.forEach(n=>{let t=$("<span/>").html(n.nextElementSibling.innerHTML).on("click",t=>{t.preventDefault(),$(".document-filters input:checkbox[value="+n.value+"]").not("input.all-value").attr("checked",!1),DoSearch()});$("#selected-filters").append(t)})}function DoSearch(){var n=[],t;$(".document-filters .years input:checkbox.all-value").first().prop("checked")||(n=$(".document-filters .years input:checked").map(function(){return this.value}).get());t={Years:n,Language:$(".document-filters #languages").val(),Status:$(".document-filters .statuses input:checked").map(function(){return this.value}).get(),Tags:$(".document-filters .tags input:checked").map(function(){return this.value}).get(),Sort:$('.view .sort-control [data-sort]:not([data-sort=""])').first().attr("data-sort"),PageSize:$(".view #doc-page-size").val(),CurrentPage:$(".page-button.active").first().attr("data-page"),FirstPage:$(".page-button").first().attr("data-page"),Term:$("#search-input").val()};$.ajax({type:"POST",url:"/licensing/docs/Search/GetDocuments",datatype:"json",data:JSON.stringify(t),contentType:"application/json",success:function(n){RebuildResultsView(n)},error:function(){toastr.error("Error retrieving documents.")}});loadSelectedFilters()}function toggleDocType(){$(".doc-url-field").toggle();$(".doc-doc-field").toggle()}function validateDoc(){var t,i,n,r,u;if($(".error-msg").text(""),t=$("#doctypes input:checked").val(),i=$("#doc-title").val(),i=="")return $("#doc-title").siblings(".error-msg").text("Document title is required."),{};if(t=="1"){if(n=$("#doc-filepath").val(),n=="")return $("#doc-filepath").siblings(".error-msg").text("Document file is required."),{}}else if(n=$("#doc-url").val(),n=="")return $("#doc-url").siblings(".error-msg").text("Document URL is required."),{};return(r=$("#doc-date").val(),r=="")?($("#doc-date").siblings(".error-msg").text("Document date is required."),{}):(u=$("#doc-tags input:checked").map(function(){return this.value}).get(),u.length==0)?($("#doc-tags .error-msg").text("Document requires at least 1 tag."),{}):{DocumentTypeID:t,DocumentID:$("#doc-id").val(),PublishDate:$("#doc-publishDate").val(),DocumentTitle:i,DocumentURL:n,DocumentDate:r,LanguageID:$("#doc-language option:selected").val(),Tags:u}}$(document).ready(function(){$("#search-form").on("submit",function(n){n.preventDefault();window.location.href=$("#searchPageUrl").val()+"?term="+$("#search-input").val()});$("#search-button").on("click",function(n){n.preventDefault();window.location.href=$("#searchPageUrl").val()+"?term="+$("#search-input").val()});$("#doc-date").datepicker();$("#doc-publishDate").datepicker();$(".publish-date-trigger").click(function(n){n.preventDefault();$("#doc-publishDate").datepicker("show")});$("#doctypes input:checked").val()!=="1"&&toggleDocType();$("#doctypes input").change(function(){toggleDocType()});Dropzone.options.dropzoneForm={timeout:18e4,maxFilesize:100,init:function(){thisDropzone=this;this.on("drop",function(){$("#doc-filepath").siblings(".error-msg").text("")});this.on("success",function(n,t){$("#doc-filepath").val(t.Result);$(".edit .uploaded-document").hide()});this.on("error",function(n,t){t&&t.Message&&t.Message&&t.Message.indexOf("File Already Exists")!==-1&&(this.removeFile(n),$("#doc-filepath").siblings(".error-msg").text("The uploaded file already exists"))})}};BindSortControls();$(".document-filters input:checkbox").change(function(n){var t=$(n.target),i=t.parents(".select-all").first();t.hasClass("all-value")?i.find("input:checkbox.valid-tag").prop("checked",!1):i.find("input:checkbox.all-value").prop("checked",!1);DoSearch()});$(".document-filters select").change(function(){DoSearch()});$(".document-filters .reset-filters-link").click(function(n){n.preventDefault();var t=$(".document-filters input:checkbox:checked");t.attr("checked",!1);t.length>0&&DoSearch()})})