!function(n,t){var f=t.isDefined,r=t.isUndefined,e=t.isNumber,i=t.isObject,o=t.isArray,s=t.extend,u=t.toJson;t.module("LocalStorageModule",[]).provider("localStorageService",function(){this.prefix="ls";this.storageType="localStorage";this.cookie={expiry:30,path:"/"};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.setStorageCookie=function(n,t){return this.cookie.expiry=n,this.cookie.path=t,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",function(n,t,h,c){var a,v=this,l=v.prefix,b=v.cookie,d=v.notify,w=v.storageType;h?h[0]&&(h=h[0]):h=document;"."!==l.substr(-1)&&(l=l?l+".":"");var p=function(n){return l+n},y=function(){try{var i=w in t&&null!==t[w],r=p("__"+Math.round(1e7*Math.random()));return i&&(a=t[w],a.setItem(r,""),a.removeItem(r)),i}catch(u){return w="cookie",n.$broadcast("LocalStorageModule.notification.error",u.message),!1}}(),nt=function(t,i){if(i=r(i)?null:u(i),!y||"cookie"===v.storageType)return y||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),d.setItem&&n.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:i,storageType:"cookie"}),k(t,i);try{a&&a.setItem(p(t),i);d.setItem&&n.$broadcast("LocalStorageModule.notification.setitem",{key:t,newvalue:i,storageType:v.storageType})}catch(f){return n.$broadcast("LocalStorageModule.notification.error",f.message),k(t,i)}return!0},rt=function(t){if(!y||"cookie"===v.storageType)return y||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),ft(t);var i=a?a.getItem(p(t)):null;if(!i||"null"===i)return null;try{return JSON.parse(i)}catch(r){return i}},ut=function(){for(var t,i=0;i<arguments.length;i++)if(t=arguments[i],y&&"cookie"!==v.storageType)try{a.removeItem(p(t));d.removeItem&&n.$broadcast("LocalStorageModule.notification.removeitem",{key:t,storageType:v.storageType})}catch(r){n.$broadcast("LocalStorageModule.notification.error",r.message);g(t)}else y||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),d.removeItem&&n.$broadcast("LocalStorageModule.notification.removeitem",{key:t,storageType:"cookie"}),g(t)},et=function(){var t,i,r;if(!y)return n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),[];t=l.length;i=[];for(r in a)if(r.substr(0,t)===l)try{i.push(r.substr(t))}catch(u){return n.$broadcast("LocalStorageModule.notification.error",u.Description),[]}return i},ot=function(t){var u=l?new RegExp("^"+l):new RegExp,f=t?new RegExp(t):new RegExp,r,i;if(!y||"cookie"===v.storageType)return y||n.$broadcast("LocalStorageModule.notification.warning","LOCAL_STORAGE_NOT_SUPPORTED"),it();r=l.length;for(i in a)if(u.test(i)&&f.test(i.substr(r)))try{ut(i.substr(r))}catch(e){return n.$broadcast("LocalStorageModule.notification.error",e.message),it()}return!0},tt=function(){try{return t.navigator.cookieEnabled||"cookie"in h&&(h.cookie.length>0||(h.cookie="test").indexOf.call(h.cookie,"test")>-1)}catch(i){return n.$broadcast("LocalStorageModule.notification.error",i.message),!1}}(),k=function(t,f,s){var v;if(r(f))return!1;if((o(f)||i(f))&&(f=u(f)),!tt)return n.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;try{var l="",c=new Date,a="";(null===f?(c.setTime(c.getTime()+-864e5),l="; expires="+c.toGMTString(),f=""):e(s)&&0!==s?(c.setTime(c.getTime()+864e5*s),l="; expires="+c.toGMTString()):0!==b.expiry&&(c.setTime(c.getTime()+864e5*b.expiry),l="; expires="+c.toGMTString()),t)&&(v="; path="+b.path,b.domain&&(a="; domain="+b.domain),h.cookie=p(t)+"="+encodeURIComponent(f)+l+v+a)}catch(y){return n.$broadcast("LocalStorageModule.notification.error",y.message),!1}return!0},ft=function(t){var u,r,i,f;if(!tt)return n.$broadcast("LocalStorageModule.notification.error","COOKIES_NOT_SUPPORTED"),!1;for(u=h.cookie&&h.cookie.split(";")||[],r=0;r<u.length;r++){for(i=u[r];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(p(t)+"=")){f=decodeURIComponent(i.substring(l.length+t.length+1,i.length));try{return JSON.parse(f)}catch(e){return f}}}return null},g=function(n){k(n,null)},it=function(){for(var r,n=null,u=l.length,i=h.cookie.split(";"),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("="));g(r)}},st=function(){return w},ht=function(n,t,r,u){u=u||t;var e=rt(u);return null===e&&f(r)?e=r:i(e)&&i(r)&&(e=s(e,r)),c(t).assign(n,e),n.$watch(t,function(n){nt(u,n)},i(n[t]))},ct=function(){for(var i=0,r=t[w],n=0;n<r.length;n++)0===r.key(n).indexOf(l)&&i++;return i};return{isSupported:y,getStorageType:st,set:nt,add:nt,get:rt,keys:et,remove:ut,clearAll:ot,bind:ht,deriveKey:p,length:ct,cookie:{isSupported:tt,set:k,add:k,get:ft,remove:g,clearAll:it}}}]})}(window,window.angular)