angular.module("checklist-model",[]).directive("checklistModel",["$parse","$compile",function(n,t){function i(n,t,i){if(angular.isArray(n))for(var r=n.length;r--;)if(i(n[r],t))return!0;return!1}function r(n,t,r){return n=angular.isArray(n)?n:[],i(n,t,r)||n.push(t),n}function u(n,t,i){if(angular.isArray(n))for(var r=n.length;r--;)if(i(n[r],t)){n.splice(r,1);break}return n}function f(f,e,o){function w(n,t){var i=a(f.$parent);angular.isFunction(v)&&(t===!0?v(f.$parent,r(i,n,s)):v(f.$parent,u(i,n,s)))}function b(n){if(c&&c(f)===!1){w(l,f[o.ngModel]);return}f[o.ngModel]=i(n,l,s)}var h=o.checklistModel,y;o.$set("checklistModel",null);t(e)(f);o.$set("checklistModel",h);var a=n(h),v=a.assign,p=n(o.checklistChange),c=n(o.checklistBeforeChange),l=o.checklistValue?n(o.checklistValue)(f.$parent):o.value,s=angular.equals;o.hasOwnProperty("checklistComparator")&&(o.checklistComparator[0]=="."?(y=o.checklistComparator.substring(1),s=function(n,t){return n[y]===t[y]}):s=n(o.checklistComparator)(f.$parent));f.$watch(o.ngModel,function(n,t){if(n!==t){if(c&&c(f)===!1){f[o.ngModel]=i(a(f.$parent),l,s);return}w(l,n);p&&p(f)}});angular.isFunction(f.$parent.$watchCollection)?f.$parent.$watchCollection(h,b):f.$parent.$watch(h,b,!0)}return{restrict:"A",priority:1e3,terminal:!0,scope:!0,compile:function(n,t){if((n[0].tagName!=="INPUT"||t.type!=="checkbox")&&n[0].tagName!=="MD-CHECKBOX"&&!t.btnCheckbox)throw'checklist-model should be applied to `input[type="checkbox"]` or `md-checkbox`.';if(!t.checklistValue&&!t.value)throw"You should provide `value` or `checklist-value`.";return t.ngModel||t.$set("ngModel","checked"),f}}}]),function(n,t){var f=t.isDefined,r=t.isUndefined,e=t.isNumber,i=t.isObject,o=t.isArray,s=t.isString,h=t.extend,u=t.toJson;t.module("LocalStorageModule",[]).provider("localStorageService",function(){this.prefix="ls";this.storageType="localStorage";this.cookie={expiry:30,path:"/",secure:!1};this.defaultToCookie=!0;this.notify={setItem:!0,removeItem:!1};this.setPrefix=function(n){return this.prefix=n,this};this.setStorageType=function(n){return this.storageType=n,this};this.setDefaultToCookie=function(n){return this.defaultToCookie=!!n,this};this.setStorageCookie=function(n,t,i){return this.cookie.expiry=n,this.cookie.path=t,this.cookie.secure=i,this};this.setStorageCookieDomain=function(n){return this.cookie.domain=n,this};this.setNotify=function(n,t){return this.notify={setItem:n,removeItem:t},this};this.$get=["$rootScope","$window","$document","$parse","$timeout",function(n,t,c,l,a){function ut(i){if(i||(i=t.event),tt.setItem&&s(i.key)&&pt(i.key)){var r=st(i.key);a(function(){n.$broadcast("LocalStorageModule.notification.changed",{key:r,newvalue:i.newValue,storageType:v.storageType})})}}var v=this,y=v.prefix,nt=v.cookie,tt=v.notify,k=v.storageType,b,vt,yt;c?c[0]&&(c=c[0]):c=document;y.substr(-1)!=="."&&(y=!y?"":y+".");var d=function(n){return y+n},st=function(n){return n.replace(new RegExp("^"+y,"g"),"")},pt=function(n){return n.indexOf(y)===0},ht=function(){try{var i=k in t&&t[k]!==null,r=d("__"+Math.round(Math.random()*1e7));return i&&(b=t[k],b.setItem(r,""),b.removeItem(r)),i}catch(u){return v.defaultToCookie&&(k="cookie"),n.$broadcast("LocalStorageModule.notification.error",u.message),!1}},p=ht(),ft=function(t,i,f){var e=g();try{if(w(f),i=r(i)?null:u(i),!p&&v.defaultToCookie||v.storageType==="cookie")return p||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),tt.setItem&&n.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:i,storageType:"cookie"}),it(t,i);try{b&&b.setItem(d(t),i);tt.setItem&&n.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:i,storageType:v.storageType})}catch(o){return n.$broadcast("LocalStorageModule.notification.error",o.message),it(t,i)}return!0}finally{w(e)}},ct=function(t,i){var u=g(),r;try{if(w(i),!p&&v.defaultToCookie||v.storageType==="cookie")return p||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),at(t);if(r=b?b.getItem(d(t)):null,!r||r==="null")return null;try{return JSON.parse(r)}catch(f){return r}}finally{w(u)}},lt=function(){var u=g(),r,i,t;try{for(r=0,arguments.length>=1&&(arguments[arguments.length-1]==="localStorage"||arguments[arguments.length-1]==="sessionStorage")&&(r=1,w(arguments[arguments.length-1])),i=0;i<arguments.length-r;i++)if(t=arguments[i],!p&&v.defaultToCookie||v.storageType==="cookie")p||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),tt.removeItem&&n.$broadcast("LocalStorageModule.notification.removeitem",{key:t,storageType:"cookie"}),rt(t);else try{b.removeItem(d(t));tt.removeItem&&n.$broadcast("LocalStorageModule.notification.removeitem",{key:t,storageType:v.storageType})}catch(f){n.$broadcast("LocalStorageModule.notification.error",f.message);rt(t)}}finally{w(u)}},wt=function(t){var f=g(),i,r,u;try{if(w(t),!p)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),[];i=y.length;r=[];for(u in b)if(u.substr(0,i)===y)try{r.push(u.substr(i))}catch(e){return n.$broadcast("LocalStorageModule.notification.error",e.Description),[]}return r}finally{w(f)}},bt=function(t,i){var o=g(),f,e,u,r;try{if(w(i),f=!y?new RegExp:new RegExp("^"+y),e=!t?new RegExp:new RegExp(t),!p&&v.defaultToCookie||v.storageType==="cookie")return p||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),ot();if(!p&&!v.defaultToCookie)return!1;u=y.length;for(r in b)if(f.test(r)&&e.test(r.substr(u)))try{lt(r.substr(u))}catch(s){return n.$broadcast("LocalStorageModule.notification.error",s.message),ot()}return!0}finally{w(o)}},et=function(){try{return t.navigator.cookieEnabled||"cookie"in c&&(c.cookie.length>0||(c.cookie="test").indexOf.call(c.cookie,"test")>-1)}catch(i){return n.$broadcast("LocalStorageModule.notification.error",i.message),!1}}(),it=function(t,f,s,h){var y;if(r(f))return!1;if((o(f)||i(f))&&(f=u(f)),!et)return n.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var a="",l=new Date,v="";f===null?(l.setTime(l.getTime()+-864e5),a="; expires="+l.toGMTString(),f=""):e(s)&&s!==0?(l.setTime(l.getTime()+s*864e5),a="; expires="+l.toGMTString()):nt.expiry!==0&&(l.setTime(l.getTime()+nt.expiry*864e5),a="; expires="+l.toGMTString());!t||(y="; path="+nt.path,nt.domain&&(v="; domain="+nt.domain),typeof h=="boolean"?h===!0&&(v+="; secure"):nt.secure===!0&&(v+="; secure"),c.cookie=d(t)+"="+encodeURIComponent(f)+a+y+v)}catch(p){return n.$broadcast("LocalStorageModule.notification.error",p.message),!1}return!0},at=function(t){var f,r,i,u,e;if(!et)return n.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(f=c.cookie&&c.cookie.split(";")||[],r=0;r<f.length;r++){for(i=f[r];i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(d(t)+"=")===0){u=decodeURIComponent(i.substring(y.length+t.length+1,i.length));try{return e=JSON.parse(u),typeof e=="number"?u:e}catch(o){return u}}}return null},rt=function(n){it(n,null)},ot=function(){for(var n=null,u=y.length,i=c.cookie.split(";"),r,t=0;t<i.length;t++){for(n=i[t];n.charAt(0)===" ";)n=n.substring(1,n.length);r=n.substring(u,n.indexOf("="));rt(r)}},g=function(){return k},w=function(n){return n&&k!==n&&(k=n,p=ht()),p},kt=function(n,t,r,u,e){u=u||t;var o=ct(u,e);return o===null&&f(r)?o=r:i(o)&&i(r)&&(o=h(o,r)),l(t).assign(n,o),n.$watch(t,function(n){ft(u,n,e)},i(n[t]))};return p&&(t.addEventListener?(t.addEventListener("storage",ut,!1),n.$on("$destroy",function(){t.removeEventListener("storage",ut)})):t.attachEvent&&(t.attachEvent("onstorage",ut),n.$on("$destroy",function(){t.detachEvent("onstorage",ut)}))),vt=function(n){var f=g(),r,u,i;try{for(w(n),r=0,u=t[k],i=0;i<u.length;i++)u.key(i).indexOf(y)===0&&r++;return r}finally{w(f)}},yt=function(n){y=n},{isSupported:p,getStorageType:g,setStorageType:w,setPrefix:yt,set:ft,add:ft,get:ct,keys:wt,remove:lt,clearAll:bt,bind:kt,deriveKey:d,underiveKey:st,length:vt,defaultToCookie:this.defaultToCookie,cookie:{isSupported:et,set:it,add:it,get:at,remove:rt,clearAll:ot}}}]})}(window,window.angular);var app=angular.module("eventSearchApp",["ui.bootstrap","medcast.services","checklist-model","LocalStorageModule"]);app.config(["$locationProvider","localStorageServiceProvider",function(n,t){n.html5Mode({enabled:!0,requireBase:!1});t.setStorageType("sessionStorage").setPrefix("eventSearchApp")}]);app.controller("eventSearchController",["$scope","$http","$window","medcastAPI","$q","$timeout","$location","localStorageService",function(n,t,i,r,u){n.loading=!0;n.data={type:null,types:[{label:"Events",value:1},{label:"Live Webinars",value:0}],month:null,months:[],searchTerm:null,location:null,locations:[],products:[],partnerId:null,partners:[],productTypes:{course:0,event:1,other:2}};n.appStart=function(){n.populateMonths();n.loadQueryStringData();n.search()};n.populateMonths=function(){for(var u=new Date,t=u.getMonth(),i=u.getFullYear(),f,r=0;r<12;r++)f=getFullMonthName(t),n.data.months.push({label:f+" "+i.toString(),value:t}),t===11?(t=0,i=i+1):t=t+1};n.search=function(){var i=[],t,f;n.data.products=[];n.loading=!0;n.data.locations.length===0&&i.push(r.getEventLocations(!1).then(function(t){t.status===200&&(n.data.locations=t.data)},function(){}));n.data.partners.length===0&&i.push(r.courseProviders().then(function(t){t.status===200&&(n.data.partners=t.data.filter(function(n){return n.name==="Medcast"||n.name==="Critical Care Education"||n.name==="Black Dog Institute"||n.name==="NB Medical Education + Medcast"}))},function(){}));t=n.data.partnerId?n.data.partnerId.toString():null;t===1&&(f=getArrayIndex(n.data.partners,"NB Medical Education + Medcast","name"),f&&(t=t+","+n.data.partners[f].id));i.push(r.getCourseCatalog({courseType:"live-webinar",searchTerm:"",startDate:(new Date).toISOString(),partnerIds:t}).then(function(t){t.status==200&&(n.data.products=n.data.products.concat(t.data))},function(){}));i.push(r.getEvents(null,n.data.location,t,new Date((new Date).setHours(0,0,0,0)).toISOString()).then(function(t){t.status===200&&(n.data.products=n.data.products.concat(t.data))},function(){}));u.all(i).then(function(){n.loading=!1})};n.openPage=function(n){i.open(n.relativeUrl,"_self")};n.loadQueryStringData=function(){for(var t=[],f=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),r,u,i=0;i<f.length;i++)r=f[i].split("="),u=r[0].toLowerCase(),t.push(u),t[u]=r[1];t.type&&(n.data.type=t.type);t.location&&(n.data.location=decodeURIComponent(t.location));t.month&&(n.data.month=(parseInt(t.month)-1).toString());t.partnerid&&(n.data.partnerId=t.partnerid)};n.appStart()}]);app.filter("filterByMonth",function(){return function(n,t){var r,i,u,f;if(!t)return n;for(r=[],i=0;i<n.length;i++)u=n[i],f=isoDateToJsDate(u.startDate),f.getMonth()==parseInt(t)&&r.push(u);return r}});app.filter("filterByType",function(){return function(n,t){var r,i;if(!t)return n;for(r=[],i=0;i<n.length;i++)n[i].productType==parseInt(t)&&r.push(n[i]);return r}})