(function(){"use strict";function n(n,t,i,r,u,f){function s(){r.log("agent login");signinAgent()}function h(){r.log("logOut");o();signoutAgent()}function o(){c(function(n){r.log("Cache Cleared : "+n)});t.currentUser={};t.accessToken={};n.defaults.headers.common.Authorization="Basic";clearAgentPortalClientStorage()}function c(n){f.post("ClearUserCache",n)}var e={};return e.clearCredentials=o,e.agentLogin=s,e.signOut=h,e}angular.module("ct.agentPortal").factory("authService",n);n.$inject=["$http","$rootScope","$cookies","$log","globalConstants","webApiRequest"]})(),function(){"use strict";function n(n,t,i,r){function e(i){n.get(t.WebApiUrl+"GetTitles").then(function(n){i(n.data)},function(n){i(ct.utls.buildErrorMessage(n.statusText))})}function o(i){n.get(t.WebApiUrl+"GetCustomClaims").then(function(n){i(n.data)},function(n){i(ct.utls.buildErrorMessage(n.statusText))})}function s(i){ct.utls.showLoading("pnlHeader");n.get(t.WebApiUrl+"GetCountries").then(function(n){ct.utls.hideLoading("pnlHeader");i(n.data)},function(n){ct.utls.hideLoading("pnlHeader");i(ct.utls.buildErrorMessage(n.statusText))})}function h(){var n=JSON.parse(ct.agent.clientStore.getItem(ct.utls.storageKeys.SignInResponse));return n?!0:!1}function f(){var i=JSON.parse(ct.agent.clientStore.getItem(ct.utls.storageKeys.SignInResponse)),r,u;return i?(r={userReference:i.profile.sub,userName:i.profile.username,email:i.profile.email,market:i.profile.agentmarketid,firstName:i.profile.firstname,familyName:i.profile.lastname,fullName:i.profile.firstname+" "+i.profile.lastname,middleName:i.profile.middlename,phoneNo:i.profile.phoneno,usertype:i.profile.usertype,agencyNo:i.profile.agencyno,staffId:i.profile.staffid,externalid:i.profile.externalid,schooxuserid:i.profile.schooxuserid,p2rMemberId:i.profile.p2rmemberid},t.currentUser=r,u=ct.agent.clientStore.getItem(ct.agent.storageKeys.ActiveAgencyNo),u&&u!=="undefined"?t.activeAgencyNo=JSON.parse(u):r.agencyNo&&(t.activeAgencyNo=JSON.parse(r.agencyNo),ct.agent.clientStore.setItem(ct.agent.storageKeys.ActiveAgencyNo,JSON.stringify(t.activeAgencyNo))),n.defaults.headers.common[ct.agent.headerKeys.ActiveAgencyNo]=t.activeAgencyNo,t.accessToken=i.access_token||{},n.defaults.headers.common[ct.utls.headerKeys.Authorization]="Bearer "+t.accessToken,ct.utls.isNullOrEmpty(t.currentUser.p2rMemberId)||(n.defaults.headers.common[ct.agent.headerKeys.SyncP2RMemberId]=t.currentUser.p2rMemberId),ct.utls.isNullOrEmpty(t.currentUser.externalid)||(n.defaults.headers.common[ct.agent.headerKeys.SyncExternalId]=t.currentUser.externalid),!0):(console.log("User not logged in"),!1)}function c(){var t=JSON.parse(ct.agent.clientStore.getItem(ct.utls.storageKeys.SignInResponse)),u=window.location.search.length>0,n,i,r;u&&(n=!1,i=ct.utls.getUrlParameterByName("firstName",window.location.href),i&&(t.profile.firstname=i,n=!0),r=ct.utls.getUrlParameterByName("familyName",window.location.href),r&&(t.profile.lastname=r,n=!0),n&&ct.agent.clientStore.setItem(ct.utls.storageKeys.SignInResponse,JSON.stringify(t)),window.location.replace(window.location.origin+window.location.pathname));f()}function l(n){r.get("agent/GetAgentBookings",n)}function a(n,t){r.get("agent/ClearCache",n,t)}function v(n){r.get("agent/GetMyAgencies",n)}function y(n){r.get("agent/CacheAgentBookings",n)}function p(i,r){n.post(t.WebHostUrl+"Updates/GetUpdates",{rootItemId:"{C91C74AB-A7D8-47EA-8913-74D85B3CB0E6}"}).success(function(n){r(n)})}function w(n){r.get("agent/GetVisitedUpdates",n)}var u={};return u.GetTitles=e,u.GetCountries=s,u.InitSigninResponse=f,u.IsUserLoggedIn=h,u.RefreshUser=c,u.GetCustomClaims=o,u.ClearCache=a,u.CacheBookings=y,u.GetBookingsOverview=l,u.GetMyAgencies=v,u.GetUpdates=p,u.GetVisitedUpdates=w,u}angular.module("ct.agentPortal").factory("headerService",n);n.$inject=["$http","$rootScope","globalConstants","webApiRequest"]}(),function(){"use strict";function n(n,t,i,r,u,f,e,o,s,h,c){function v(){ct.utls.isHomePage()||(window.location.search.indexOf("refreshUser")>=0&&u.RefreshUser(),!u.IsUserLoggedIn()&&window.location.pathname.indexOf("login")<0&&s.agentLogin(),n.currentUser.userName===undefined&&u.InitSigninResponse(),w(),ct.agent.clientStore.getItem(ct.utls.storageKeys.IsRedirectFromAgentLogin)&&(ct.agent.clientStore.removeItem(ct.utls.storageKeys.IsRedirectFromAgentLogin),u.CacheBookings(function(){console.log("bookings cached")})))}function l(){if($("#ddlAgencies").kendoDropDownList({dataTextField:"DisplayName",dataValueField:"Number",dataSource:n.myAgencies,change:p,height:100}),!ct.utls.isNullOrEmpty(n.activeAgencyNo)){var t=$("#ddlAgencies").data("kendoDropDownList");t&&t.select(function(t){return t.Number===n.activeAgencyNo})}}function y(){if(n.currentUser.staffId!=undefined){var t=JSON.parse(ct.agent.clientStore.getItem(ct.agent.storageKeys.MyAgencies));t&&t!=="undefined"&&t.length>0?(n.myAgencies=t,l()):u.GetMyAgencies(function(t){n.myAgencies=t.Data.Agencies;ct.agent.clientStore.setItem(ct.agent.storageKeys.MyAgencies,JSON.stringify(n.myAgencies));l()})}}function p(t){ct.agent.clientStore.removeItem(ct.agent.storageKeys.BookingsNavigationFilter);ct.agent.clientStore.removeItem(ct.agent.storageKeys.BdmInformation);var i=t.sender.dataItem().Number;b(i,n.activeAgencyNo)}function w(){if(n.currentUser.market!==undefined&&n.currentUser.market!==ct.utls.getMarketId()){var t=$("#hdnAgentPortalUrl_"+n.currentUser.market).val()+window.location.pathname;window.location.replace(t);ct.agent.clientStore.removeItem(ct.utls.storageKeys.SignInResponse);ct.agent.clientStore.removeItem(ct.agent.storageKeys.ActiveAgencyNo);ct.agent.clientStore.removeItem(ct.agent.storageKeys.MyAgencies)}}function b(i,r){i!=null&&i!==r&&ct.utls.confirmWindow(c,t,"Agency change confirmation","Do you want to change the agency?",function(){ct.utls.showLoading();n.activeAgencyNo=i;u.ClearCache(function(){ct.agent.clientStore.setItem(ct.agent.storageKeys.ActiveAgencyNo,JSON.stringify(n.activeAgencyNo));window.location.href="/account/dashboard"})},function(){t.$apply(function(){n.activeAgencyNo=r;var t=$("#ddlAgencies").data("kendoDropDownList");t.select(function(n){return n.Number===r})})})}function k(){n.currentUser.staffId!=undefined&&u.GetBookingsOverview(function(i){if(n.outstandingPayments=0,n.travellerDetails=0,n.pendingReservations=0,i.UserMessage.IsSuccess&&i.DataList.length>0){var r=[];_.forEach(i.DataList,function(t){t.RemainingDays>0&&(t.IsPaymentCompleted==!1||t.IsTravellersDetailsComplete==!1)&&t.BookingStatus!="Deleted"&&t.BookingStatus!="Cancelled"&&t.BookingStatus!="Departed"&&r.push(t);n.outstandingPayments+=t.IsPaymentCompleted===!1&&t.BookingStatus=="Booked"?1:0;n.travellerDetails+=t.IsTravellersDetailsComplete===!1&&t.BookingStatus=="Booked"?1:0;n.pendingReservations+=t.BookingStatus==="Undeposited"?1:0});t.bookings=r.length>0?r.slice(0,2):i.DataList.slice(0,2);n.totalBookingsCount=n.outstandingPayments+n.travellerDetails+n.pendingReservations}})}function d(){if(u.IsUserLoggedIn()){var t=JSON.parse(ct.agent.clientStore.getItem(ct.agent.storageKeys.UpdatesNotificationCount));t!==null&&t!==undefined?n.newUpdatesCount=t:u.GetUpdates("",function(t){t.Updates.length>0&&(n.updatesList=_.uniq(t.Updates,function(n){return n.ItemId}));u.GetVisitedUpdates(function(t){n.newUpdatesCount=0;_.each(n.updatesList,function(i){_.contains(t.DataList,i.ItemId)===!1&&(n.newUpdatesCount+=1)});ct.agent.clientStore.setItem(ct.agent.storageKeys.UpdatesNotificationCount,n.newUpdatesCount)},n.currentUser.staffId)})}}var a=this;a.signOut=s.signOut;t.globalScope=n;n.messageCount=0;n.alertCount=0,function(){console.log("init headerController");v();y();k();d()}();n.adjustLeftMenuHeight=function(){n.isAgentViewEnabled?$(".main").css("margin-top","175px"):$(".main").css("margin-top","130px")};t.showAgentViewInPage=function(){var i=JSON.parse(ct.agent.clientStore.getItem(ct.agent.storageKeys.IsAgentViewEnabled));(i=="undefined"||i==null)&&(i=!0);n.isAgentViewEnabled=i;t.agentViewChkBox=n.isAgentViewEnabled;n.adjustLeftMenuHeight()};t.disableAgentView=function(){n.isAgentViewEnabled=!1;t.agentViewChkBox=!1;n.adjustLeftMenuHeight();ct.agent.clientStore.setItem(ct.agent.storageKeys.IsAgentViewEnabled,n.isAgentViewEnabled)};t.setAgentViewMode=function(t){t?(n.isAgentViewEnabled=!0,n.adjustLeftMenuHeight()):(n.isAgentViewEnabled=!1,n.adjustLeftMenuHeight());ct.agent.clientStore.setItem(ct.agent.storageKeys.IsAgentViewEnabled,n.isAgentViewEnabled)};t.bookingDetails=function(n){var t={BookingNumber:n.BookingNumber,ComponentNumber:n.ComponentNumber,Season:n.Season};ct.agent.clientStore.setItem(ct.agent.storageKeys.BookingsNavigationFilter,JSON.stringify(t));location.href=ct.utls.url.webHostUrl()+"/account/bookings/yourbooking"};t.updateAgencyProfile=function(){window.location.href="/account/profile"}}angular.module("ct.agentPortal").controller("headerController",n);n.$inject=["$rootScope","$scope","$http","$location","headerService","$log","$state","$cookies","authService","globalConstants","$ngConfirm"]}(),function(){"use strict";function n(n,t,i,r,u,f,e,o,s){function h(){if(!u.IsUserLoggedIn()){t.showLogin=!0;return}}t.showLogin=!1;n.showRegistration=!1,function(){f.log("init mediateHeaderController");h()}();t.signOut=function(){s.signOut()};t.signIn=function(){s.agentLogin()};t.registration=function(){window.location.replace("/registration")}}angular.module("ct.agentPortal").controller("mediateHeaderController",n);n.$inject=["$rootScope","$scope","$http","$location","headerService","$log","$state","$cookies","authService"]}(),function(){"use strict";function n(n,t,i,r,u,f,e,o,s){(function(){u.log("init homeHeaderController")})();n.logInAgent=function(){s.agentLogin()}}angular.module("ct.agentPortal").controller("homeHeaderController",n);n.$inject=["$scope","$rootScope","$location","$state","$log","$http","$cookies","headerService","authService"]}()