var outward=0;var inward=1;function MixingDeck(){this.railDataProvider=new RailDataProvider();this.outwardFarePanel=new FarePanel("outwardJourney",outward,"outwardFareGroups");this.inwardFarePanel=new FarePanel("inwardJourney",inward,"inwardFareGroups");this.outwardServicePanel=new ServicePanel("outwardServicePanel",outward,"outwardServices");this.inwardServicePanel=new ServicePanel("inwardServicePanel",inward,"inwardServices");this.outwardChoicePanel=new ChoicePanel("outwardChoicePanel",outward);this.inwardChoicePanel=new ChoicePanel("inwardChoicePanel",inward);this.totalCostPanel=new TotalCostPanel("totalCostPanel");this.stoppingPointPanel=new StoppingPointPanel("ctl00_mainContentPlaceHolder_stoppingPointPanel");this.filterPanel=new FilterPanel("filterControl");this.lowestFareFinder=new LowestFareFinder("lowestFareFinder","lowestFareFinderMinimisedId");this.timeoutSet=false;this.outstandingEnquiry=new Object();this.startTime=0}MixingDeck.prototype.ProcessInitialData=function(B,C){if(B.complete){this.journeyPlanningData=new JourneyPlanningData(B);this.journeyPlanningData.SetPostbackControls(document.getElementById(this.hdnOutwardFareGroupId),document.getElementById(this.hdnInwardFareGroupId),document.getElementById(this.hdnOutwardServiceId),document.getElementById(this.hdnInwardServiceId));ShowElement(document.getElementById("pleaseWait"),false);this.journeyPlanningData.SetFarePanel(this.outwardFarePanel);if(B.isReturn&&B.returnDate){this.journeyPlanningData.SetFarePanel(this.inwardFarePanel)}this.journeyPlanningData.SetServicePanel(this.outwardServicePanel);if(B.isReturn&&B.returnDate){this.journeyPlanningData.SetServicePanel(this.inwardServicePanel)}this.journeyPlanningData.SetTotalCostPanel(this.totalCostPanel);this.journeyPlanningData.SetChoicePanel(this.outwardChoicePanel);this.journeyPlanningData.SetChoicePanel(this.inwardChoicePanel);this.journeyPlanningData.SetFitlerPanel(this.filterPanel);this.lowestFareFinder.SetData(this.journeyPlanningData);this.extensionState=0;this.HandleExtensions();this.filterPanel.SetVisibilityOfFlexibilityButtons(this.journeyPlanningData.data.outwardFareGroups,this.journeyPlanningData.data.inwardFareGroups);this.lowestFareFinder.ShowMinimised(true);DisableWTButton(document.getElementById(this.btnOutwardPrev),!this.enableOutwardPrev);DisableWTButton(document.getElementById(this.btnOutwardNext),!this.enableOutwardNext);document.getElementById("outwardJourneyDate").innerHTML=B.outwardDate;if(B.isReturn&&B.returnDate){DisableWTButton(document.getElementById(this.btnReturnPrev),!this.enableReturnPrev);DisableWTButton(document.getElementById(this.btnReturnNext),!this.enableReturnNext);document.getElementById("inwardJourneyDate").innerHTML=B.returnDate;helpPanels.DataLoaded(true)}else{helpPanels.DataLoaded(false)}this.UpdateFilter();this.journeyPlanningData.SetSelectedData(this.journeyPlanningData);if(B.nrsFailure){this.nrsFailure=true;this.DisplayMessage(mixingDeck.resourceStrings.nrsFailure)}if(!this.debug){this.disableErrorReporting=true}}else{switch(B.status){case"expired":this.DisplayMessage(mixingDeck.resourceStrings.requestExpired);break;case"error":this.DisplayError("error in ProcessInitialData");break;case"no fares":this.DisplayMessage(mixingDeck.resourceStrings.noFares);break;case"no direct services":this.noDirectServices=true;this.DisplayMessage(mixingDeck.resourceStrings.noDirectServices);break;case"no smartcard fares found":this.noSmartcardFares=true;this.DisplayMessage(mixingDeck.resourceStrings.noSmartCardFares);break;default:var A=new Date()-this.startTime;if(A/1000>this.pollTimeout){this.DisplayError("Timeout in ProcessInitialData")}else{timer.SetTimer(this.standardPollInterval,this,this.PollForInitialData)}break}}};MixingDeck.prototype.HandleExtensions=function(){switch(this.extensionState){case 0:this.extensionState=4;if(this.noAutoExtensions!="y"){this.StartFTAEnquiryExtension("O","E")}break;case 1:if(this.journeyPlanningData.data.isReturn&&this.journeyPlanningData.data.returnDate){this.extensionState=2}else{this.extensionState=4}this.StartFTAEnquiryExtension("O","L");break;case 2:this.extensionState=3;if(this.noAutoExtensions!="y"){this.StartFTAEnquiryExtension("R","E")}break;case 3:this.extensionState=4;this.StartFTAEnquiryExtension("R","L");break}};MixingDeck.prototype.MoveLowestFareFinder=function(){if(this.journeyPlanningData.data.isReturn&&this.journeyPlanningData.data.returnDate){this.lowestFareFinder.ShowMinimised(true)}};MixingDeck.prototype.PollForInitialData=function(){try{if(!this.bSubmitHooked){this.hookedOnSubmitFunction=document.forms[0].onsubmit;document.forms[0].onsubmit=OnSubmitMixingDeck;this.bSubmitHooked=true}this.railDataProvider.SetTimeout(this.pollTimeout*1000);this.railDataProvider.SetErrorFunction(this,"DisplayError");this.railDataProvider.GetInitialFareData(this.enquiryIds,this,this.ProcessInitialData)}catch(A){this.DisplayError("PollForInitialData",A)}};MixingDeck.prototype.ProcessStartEnquiryExtensionData=function(B,A){if(B.enquiryIds){A[2]=B.enquiryIds;A[3]=new Date();timer.SetTimer(this.standardPollInterval,this,this.PollForExtensionData,A)}else{if(this.debug){this.DisplayError("No returned enquiryIds in ProcessStartEnquiryExtensionData")}else{this.HandleReturnedError(A[0],A[1])}}};MixingDeck.prototype.StartFTAEnquiryExtension=function(C,B){if(this.journeyPlanningData.AllDataReceived(C,B)){this.HandleExtensions();return false}if(!this.outstandingEnquiry[C+B]){this.outstandingEnquiry[C+B]=true;try{this.railDataProvider.StartFTAEnquiryExtension(C,B,this,this.ProcessStartEnquiryExtensionData)}catch(A){if(this.debug){this.DisplayError("StartFTAEnquiryExtension",A)}return false}}return true};MixingDeck.prototype.HandleReturnedError=function(B,A){if(this.journeyPlanningData&&this.journeyPlanningData.servicePanel[B]){this.journeyPlanningData.servicePanel[B].ShowGettingServiceData(false)}if(this.journeyPlanningData.data.isReturn&&this.journeyPlanningData.data.returnDate){this.lowestFareFinder.ShowGettingLowestFareData(false)}this.outstandingEnquiry[(B==0?"O":"R")+A]=false};MixingDeck.prototype.ProcessExtensionData=function(C,B){if(C.complete){this.journeyPlanningData.AddFTAEnquiryExtensionData(C,B[0],B[1]);if(this.journeyPlanningData.data.isReturn&&this.journeyPlanningData.data.returnDate){this.lowestFareFinder.ShowGettingLowestFareData(false);this.lowestFareFinder.NewDataAdded()}this.filterPanel.SetVisibilityOfFlexibilityButtons(this.journeyPlanningData.data.outwardFareGroups,this.journeyPlanningData.data.inwardFareGroups);this.outstandingEnquiry[(B[0]==0?"O":"R")+B[1]]=false;this.HandleExtensions()}else{if(C.status=="error"){if(this.debug){this.DisplayError("error in ProcessExtensionData")}else{this.HandleReturnedError(B[0],B[1])}}else{var A=new Date()-B[3];if(A/1000>this.pollTimeout){this.DisplayError("timeout in ProcessExtensionData")}else{timer.SetTimer(this.standardPollInterval,this,this.PollForExtensionData,B)}}}};MixingDeck.prototype.DisplayError=function(A,C){var B;if(this.debug){if(C){B=A+" "+C.name+" "+C.message}else{B=A}}else{B=this.resourceStrings.errorMessage}this.DisplayMessage(B)};MixingDeck.prototype.DisplayMessage=function(B){if(this.disableErrorReporting){return }var C=document.getElementById(this.divDisableScreenId);if(B!=null){var A=YAHOO.util.Dom.getElementsByClassName("ErrorMessage",undefined,C)[0];A.innerHTML=B}ShowElement(document.getElementById("pleaseWait"),false);if(this.journeyPlanningData){if(this.journeyPlanningData.servicePanel[outward]){this.journeyPlanningData.servicePanel[outward].ShowGettingServiceData(false)}if(this.journeyPlanningData.servicePanel[inward]){this.journeyPlanningData.servicePanel[inward].ShowGettingServiceData(false)}}ticketSearchControl.ShowTicketSearchControl(false);YAHOO.util.Dom.removeClass(C,"Transparent");YAHOO.util.Dom.addClass(C,"ErrorOverlay");ShowElement(C,true)};MixingDeck.prototype.ShowTransparentDiv=function(A){var C=document.getElementById(this.divDisableScreenId);var B=document.getElementById("rightcolumnPH");disabledScreenShowing=A;if(A){YAHOO.util.Dom.addClass(C,"Transparent");YAHOO.util.Dom.removeClass(C,"ErrorOverlay");B.style.zIndex="50"}else{if(!showingSavedJourneys){B.style.zIndex="0"}}ShowElement(C,A)};MixingDeck.prototype.OnErrorContinue=function(){if(this.nrsFailure){this.ShowTransparentDiv(false)}else{this.ShowTransparentDiv(true);ticketSearchControl.DisableClose();if(this.noDirectServices){ticketSearchControl.SearchForNonDirectTrains()}else{if(this.noSmartcardFares){ticketSearchControl.SearchForNonSmartcardFares()}else{ticketSearchControl.ShowTicketSearchControl(true)}}}};MixingDeck.prototype.DisableErrorReporting=function(){this.disableErrorReporting=true};MixingDeck.prototype.PollForExtensionData=function(A){try{this.railDataProvider.CheckForFTAExtensionCompletion(A[2],this,this.ProcessExtensionData,A)}catch(B){if(this.debug){this.DisplayError("PollForExtensionData",B)}}};MixingDeck.prototype.SetFlexibility=function(A){this.showingFlexible=A;this.UpdateFilter()};MixingDeck.prototype.ShowStandard=function(A){this.showingStandard=A};MixingDeck.prototype.ShowFirst=function(A){this.showingFirst=A};MixingDeck.prototype.UpdateFilter=function(){if(this.journeyPlanningData){this.journeyPlanningData.SetFlexibility(this.showingFlexible,this.showingStandard,this.showingFirst,this.showingOnlySmartCardFares)}};MixingDeck.prototype.ToggleSlowerRoutes=function(){this.filterPanel.ToggleSlowerRoutes()};MixingDeck.prototype.OnUpdate=function(){this.filterPanel.OnUpdate()};MixingDeck.prototype.ProcessKeepAliveMessage=function(B,A){};MixingDeck.prototype.CheckKeepAliveTimeout=function(){var A=(new Date()-this.railDataProvider.lastCommunication)/1000;if(A>this.keepAliveInterval){try{this.railDataProvider.SendKeepAliveMessage(this,this.ProcessKeepAliveMessage)}catch(B){if(this.debug){this.DisplayError("CheckKeepAliveTimeout",B)}}}};MixingDeck.prototype.ProcessStoppingPoints=function(B,A){if(B.status=="error"){if(this.debug){this.DisplayError("Error in ProcessStoppingPoints")}else{this.stoppingPointPanel.HidePanel()}}else{this.journeyPlanningData.AddStoppingPoints(B);this.stoppingPointPanel.StoppingPointsReceived()}};MixingDeck.prototype.ShowServiceInformation=function(B,A,D){this.stoppingPointPanel.ShowPanel(B,A,D);if(B.stoppingPoints==undefined){try{this.railDataProvider.GetStoppingPoints(B,this,this.ProcessStoppingPoints)}catch(C){this.stoppingPointPanel.HidePanel();if(this.debug){this.DisplayError("ShowServiceInformation",C)}}}};MixingDeck.prototype.ShowOnlySmartCardFares=function(A){this.showingOnlySmartCardFares=A};MixingDeck.prototype.OnShowCheaperFares=function(A){this.journeyPlanningData.OnShowCheaperFares(A)};MixingDeck.prototype.OnShowMoreExpensiveFares=function(A){this.journeyPlanningData.OnShowMoreExpensiveFares(A)};MixingDeck.prototype.OnAddReturnJourney=function(A){this.ShowTransparentDiv(true);ticketSearchControl.ShowTicketSearchControl(true,true)};MixingDeck.prototype.GetServiceId=function(A){if(A!=undefined){return A.serviceId}else{return undefined}};MixingDeck.prototype.OnRouteClicked=function(A){this.filterPanel.OnRouteClicked(A)};MixingDeck.prototype.GetFareGroupId=function(A){if(A!=undefined){return A.fareGroupId}else{return undefined}};MixingDeck.prototype.HandleSaveResponse=function(A){};MixingDeck.prototype.OnSaveJourney=function(){};MixingDeck.prototype.ClearPendingSavedJourney=function(){try{this.railDataProvider.ClearPendingSavedJourney(this,this.HandleSaveResponse)}catch(A){if(this.debug){this.DisplayError("ClearPendingSavedJourney",A)}}};MixingDeck.prototype.DisplayImmediateErrorMessage=function(){this.DisplayMessage(this.errorMessageToDisplay)};var mixingDeck=new MixingDeck();function OnSubmitMixingDeck(A){mixingDeck.DisableErrorReporting();if(mixingDeck.hookedOnSubmitFunction){mixingDeck.hookedOnSubmitFunction(A)}}function InitialiseMixingDeck(){if(BrowserDetect.browser=="Explorer"){try{if(document.execCommand){document.execCommand("BackgroundImageCache",false,true)}}catch(A){}}mixingDeck.startTime=new Date();if(mixingDeck.mode=="Display"&&!mixingDeck.errorMessageToDisplay){ShowElement(document.getElementById("pleaseWait"),true);timer.SetTimer(mixingDeck.initialPollInterval,mixingDeck,mixingDeck.PollForInitialData);mixingDeck.filterPanel.Show(true);mixingDeck.totalCostPanel.SetVisibility(true,true);timer.SetTimer(3000,helpPanels,helpPanels.ShowFarePanel);LoadAllImages()}}