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("courseSearchApp",["ui.bootstrap","medcast.services","checklist-model","LocalStorageModule","medcast.directives"]);app.config(["$locationProvider","localStorageServiceProvider",function(n,t){n.html5Mode({enabled:!0,requireBase:!1});t.setStorageType("sessionStorage").setPrefix("courseSearchApp")}]);app.controller("courseSearchController",["$scope","$http","$window","medcastAPI","$q","$timeout","$location","localStorageService",function(n,t,i,r,u,f,e,o){n.loaded=!1;n.loading=!1;n.showFilter=!1;n.courses=[];n.productTypes={course:0,event:1,other:2};n.data={courseTypes:[],partners:[],areasOfInterest:[],dateOrderBy:[],professions:[],paymentTypes:[]};n.criteria={search:"",profession:null,dateOrder:"sort",courseTypes:null,partnerId:null,areasOfInterest:[],location:null,hasCPDPoints:null,paymentType:null};n.appStart=function(){n.loadQueryStringData();var t=[],i=o.get("criteria");i!=null?n.data=i:t.push(r.getCourseSearchDropdowns().then(function(t){t.status==200&&(n.data.courseTypes=t.data.courseTypes,n.data.partners=t.data.partners,n.data.areasOfInterest=t.data.areasOfInterest,n.data.dateOrderBy=t.data.dateOrderBy,n.data.professions=t.data.professions,n.data.paymentTypes=t.data.paymentTypes,o.set("criteria",n.data))},function(){}));t.push(r.getCourseCatalog(n.getSearchModel()).then(function(t){t.status==200&&(n.courses=t.data,n.showFilter&&scrollToElement($("#search-results")))},function(){}));u.all(t).then(function(){n.loaded=!0})};n.loadQueryStringData=function(){for(var t=[],f=window.location.href.slice(window.location.href.indexOf("?")+1).split("&"),r,u,e,i=0;i<f.length;i++)r=f[i].split("="),u=r[0].toLowerCase(),t.push(u),t[u]=r[1];t.searchterm&&(n.criteria.search=decodeURIComponent(t.searchterm),n.showFilter=!0);t.profession&&(n.criteria.profession=decodeURIComponent(t.profession),n.showFilter=!0);t.coursetype&&(n.criteria.courseTypes=decodeURIComponent(t.coursetype),n.showFilter=!0);t.coursetypes&&(n.criteria.courseTypes=decodeURIComponent(t.coursetypes),n.showFilter=!0);t.partnerid&&(n.criteria.partnerId=t.partnerid,n.showFilter=!0);t.dateorder&&(n.criteria.dateOrder=t.dateorder,n.showFilter=!0);t.location&&(n.criteria.location=decodeURIComponent(t.location),n.showFilter=!0);t.showfilter&&t.showfilter==="true"&&(n.showFilter=!0);t.paymenttype&&(n.criteria.paymentType=t.paymenttype,n.showFilter=!0);t.areasofinterest&&(e=decodeURIComponent(t.areasofinterest),n.criteria.areasOfInterest=e.split(","),n.showFilter=!0)};n.fetchCourses=function(){n.loading=!0;var t=n.getSearchModel();r.getCourseCatalog(t).then(function(t){t.status==200&&(n.courses=t.data);n.loading=!1;scrollToElement($("#search-results"))},function(){n.loading=!1})};n.getSearchModel=function(){return{searchTerm:n.criteria.search,courseTypes:n.criteria.courseTypes,partnerIds:n.criteria.partnerId,dateOrder:n.criteria.dateOrder,selectedInterests:n.criteria.areasOfInterest.join(","),professions:n.criteria.profession,hasCPDPoints:n.criteria.hasCPDPoints,paymentType:n.criteria.paymentType}};n.showStartDate=function(n){if(!n)return!1;var t=new Date,i=new Date(n);return i>t};n.clearFilter=function(){n.criteria={search:"",profession:null,dateOrder:"sort",courseTypes:null,partnerId:null,areasOfInterest:[],location:null};n.fetchCourses()};n.getProviderColour=GetProviderColour;n.getCourseTypeIcon=GetCourseTypeIcon;n.getCourseTypeName=GetCourseTypeName;n.getProductTypeName=GetProductTypeName;n.$on("loadImages",function(){loadDeferedImages()});n.appStart()}])