var app=app||{};app.search=app.search||{},function(n,t,i){"use strict";function p(t,i){var s=n(t).find(".chkbox-item").not(".checkall").length,u=n(t).find(".chkbox-item").not(".checkall").filter(":checked").length,e=17,o,r;s===u?(o=n.grep(f,function(n){return n.DialogId===t}),n(t).find(".checkall").prop("checked",!0),n(i).val(o[0].defaultvalue)):u>1?n(i).val("Multiple"):u>0?(r=n(t).find(".chkbox-item").not(".checkall").filter(":checked").first().attr("data-value"),r.length>e&&(r=n.trim(r).substring(0,e)+"..."),n(i).val(r)):n(i).val("")}function w(){n.each([{dialog:"#programme-filter-dialog",txtbox:"#txtprogrammes"},{dialog:"#componenttype-filter-dialog",txtbox:"#txtcomponenttypes"},{dialog:"#status-filter-dialog",txtbox:"#txtstatuses"}],function(n,t){p(t.dialog,t.txtbox)})}function b(){var i=n("#search-filter-container"),r=i.is(":visible"),t=!1;return r?t=!0:n("#SearchText").val().length>1?t=!0:n("#chkEnroll").is(":checked")?t=!0:n("[name='chkstatus']:checked").length>0&&n("[name='chkstatus']:unchecked").length>0?t=!0:n("[name='chkcomponenttype']:checked").length>0&&n("[name='chkcomponenttype']:unchecked").length>0?t=!0:n("[name='chkprogramme']:checked").length>0&&n("[name='chkprogramme']:unchecked").length>0&&(t=!0),t}function s(t){var i=[];return n("[name="+t+"]:checked").each(function(n,t){i.push(t.value)}),i=i.join(",")}function k(){n(".loading").show();var t="",i="",r="",u="";return n("#adv_chkProgrammeAll").is(":checked")||(t=s("adv_chkprogramme")),n("#adv_chkComponentAll").is(":checked")||(r=s("adv_chkcomponenttype")),n("#adv_chkStatusAll").is(":checked")||(i=s("adv_chkstatus")),u=s("adv_chkSearchFields"),n("#Adv_ProgrammeIds").val(t),n("#Adv_ComponentTypeIds").val(r),n("#Adv_ActivityStatusIds").val(i),n("#Adv_SearchFieldIds").val(u),!0}function d(){n("#searchresultcontainer").length>0&&(n(".panel-content").show(),n(".toggable").bind("click",function(t){n(this).closest(".panel-header").next().toggle();n(this).find("img").toggle();t.preventDefault()}),n(".panel-content").last().find(".row").last().addClass("noborder"))}function g(t){if(t.which===27&&r!==null){var i=n(r).find(".btnclose").first();i.click();t.preventDefault()}}function l(){(typeof o=="undefined"||o==="")&&n.ajax({type:"POST",url:"/Search/FillQuickSearchFilters",data:{qModel:t.search.quickSearch},success:function(t){var i=t.d||t;typeof i.view!="undefined"&&(o=i.view,n(".main","#search-filter-container").append(o),w())},async:!1})}function nt(){h=!0}var a,f=[{DialogId:"#status-filter-dialog",txtboxId:"#txtstatuses",defaultvalue:"All statuses"},{DialogId:"#componenttype-filter-dialog",txtboxId:"#txtcomponenttypes",defaultvalue:"All components"},{DialogId:"#programme-filter-dialog",txtboxId:"#txtprogrammes",defaultvalue:"All resources"},{DialogId:"#adv_status-filter-dialog",txtboxId:"#adv_txtstatuses",defaultvalue:"All statuses"},{DialogId:"#adv_componenttype-filter-dialog",txtboxId:"#adv_txtcomponenttypes",defaultvalue:"All components"},{DialogId:"#adv_programme-filter-dialog",txtboxId:"#adv_txtprogrammes",defaultvalue:"All resources"}],r=null,u=null,e=!0,h=!0,o="",v=n("#advancedsearchform #startDate"),y=n("#advancedsearchform #endDate"),c;t.search.quickSearch=n.parseJSON(document.getElementById("qModel").value);c=n("body");c.on("submit","#formsearch",function(){var t;if(b()){if(n(".loading").show(),t=n("#status-filter-dialog, #componenttype-filter-dialog, programme-filter-dialog"),t.length===0)n('<input type="hidden" name="ActivityStatusesSelectAll" value="true" /><input type="hidden" name="ComponentTypesSelectAll" value="true" /><input type="hidden" name="ProgrammesSelectAll" value="true" />').appendTo(this);return!0}return alert("Please enter at least 2 characters in the search text box or drop down the filter selection and choose the filters required."),!1}).on("submit","#formadvancesearch",function(){return k()}).on("click","#btnsearch",function(){n("#formsearch").submit()}).on("click","#btnadvsearch",function(){n("#formadvancesearch").submit()}).on("click","#searchFilterIconLink,#btn-search-filter-close",function(i){var r=n("#search-filter-container");r.is(":hidden")&&l();n(".searchFilterIcon-img").toggle();r.toggle();t.search.quickSearchFilterEnabled=!t.search.quickSearchFilterEnabled;n("#QuickSearchFilterEnabled").val(t.search.quickSearchFilterEnabled);i.preventDefault()}).on("click",".checkall",function(){n(r).find(".chkbox-item").not(".checkall").prop("checked",this.checked)}).on("click",".chkbox-item",function(){if(!this.checked){var t=n(r).find(".checkall").first();t!==null&&n(t).prop("checked",!1)}}).on("click",".btnclose",function(t){h=!1;n(u).focus();n(r).modal("hide");t.preventDefault();setTimeout(nt,100)}).on("dp.change","#advancedsearchform #startDate,#advancedsearchform #ActivityFromDate",function(n){y.data("DateTimePicker").minDate(n.date)}).on("dp.change","#advancedsearchform #endDate, #advancedsearchform #ActivityToDate",function(n){v.data("DateTimePicker").maxDate(n.date)}).on("focus","#advancedsearchform #ActivityFromDate,#advancedsearchform #ActivityToDate",function(){n(this).closest(".input-group.date").data("DateTimePicker").show()}).on("click","#btnadvcancel",function(){n("#formadvancesearch").get(0).reset()}).on("click",".breadcrumbswitch",function(){n(this).parent().next().toggle();n(this).parent().find(".breadcrumbswitch").toggle()}).on("click",".breadcrumbswitchForPage",function(){e=!e;n(".breadcrumbtrail").toggle(e);n(".breadcrumbswitchForPage").toggle();e?(n(".breadcrumbswitchCol .expand").show(),n(".breadcrumbswitchCol .collapse").hide()):(n(".breadcrumbswitchCol .expand").hide(),n(".breadcrumbswitchCol .collapse").show())});n.each(f,function(t){var e=f[t].txtboxId,i=f[t].DialogId;c.on("focus click",e,function(){var f,o,s,c,l;!(n(i).data("bs.modal")||{}).isShown&&h&&(f=n(this).offset(),o=0,t>2&&(o=350),s=f.top+45-o+"px",c=f.left-10+"px",n(i).css({position:"absolute",top:s,left:c}),l={keyboard:!0,show:!0},n(i).modal("show"),r=i,u=e)}).on("hidden.bs.modal",i,function(){var s=n(r).attr("id"),c=n(i).find(".chkbox-item").not(".checkall").length,e=n(i).find(".chkbox-item").not(".checkall").filter(":checked").length,o=17,h,t;s.indexOf("adv")===0&&(o=35);c===e?(h=n.grep(f,function(n){return n.DialogId==="#"+s}),n(i).find(".checkall").prop("checked",!0),n(u).val(h[0].defaultvalue)):e>1?n(u).val("Multiple"):e>0?(t=n(i).find(".chkbox-item").not(".checkall").filter(":checked").first().attr("data-value"),t.length>o&&(t=n.trim(t).substring(0,o)+"..."),n(u).val(t)):n(u).val("");r=null})});n(document).ready(function(){n(".loading").hide();n.ajaxSetup({cache:!1});a={debug:0,TimeoutInMS:9e4,timeoutMessage:"A timeout occurred submitting your details, please try again."};n(document).keyup(function(n){g(n)});var r={format:"DD MMM YYYY",useCurrent:!0,maxDate:i(),showTodayButton:!0,locale:"en",widgetPositioning:{horizontal:"right",vertical:"auto"}};n("#advancedsearchform .input-group.date").datetimepicker(r);n("#adv_searchAllFields").change(function(){this.checked?n("input[name='adv_chkSearchFields']").each(function(){this.checked=!0}):n("input[name='adv_chkSearchFields']").each(function(){this.checked=!1})});n("input[name='adv_chkSearchFields']").on("click",function(){n("input[name='adv_chkSearchFields']:checked").length===n("input[name='adv_chkSearchFields']").length?n("#adv_searchAllFields").prop("checked",!0):n("#adv_searchAllFields").prop("checked",!1)});d();t.search.quickSearchFilterEnabled&&l();n(document).mouseup(function(t){var i=n(".modal-search:visible");i.is(t.target)||i.has(t.target).length!==0||i.modal("toggle")})})}(window.jQuery,app,moment)