function FarePanel(C,B,A){this.farePanelId=C;this.panelDataName=A;this.direction=B;this.currentPage=0;this.disableAll=false;this.inRollOver=false}FarePanel.prototype.AddRolloverListener=function(A){this.journeyPlanningData=A;this.availableFares=YAHOO.util.Dom.getElementsByClassName("AvailableFares",undefined,this.farePanelId)[0];var B=YAHOO.util.Event.addListener(this.availableFares,"mouseover",this.OnRollover,this,true);B=YAHOO.util.Event.addListener(this.availableFares,"mouseout",this.OnRolloverExit,this,true)};FarePanel.prototype.OnRollover=function(A){if(!this.inRollOver){this.inRollOver=true;this.journeyPlanningData.UpdateChooseFare(this.direction,this.inRollOver)}};FarePanel.prototype.OnRolloverExit=function(A){if(this.inRollOver){if(StillInsideElementOnMouseOut(this.availableFares,A)){return }this.inRollOver=false;this.journeyPlanningData.UpdateChooseFare(this.direction,this.inRollOver)}};FarePanel.prototype.AddEventListener=function(B,A){if(this.changedEvent==undefined){this.changedEvent=new YAHOO.util.CustomEvent("FareGroupSelected"+this.direction)}this.changedEvent.subscribe(A,B,true)};FarePanel.prototype.FireEvent=function(A,B){if(this.changedEvent!=undefined){this.changedEvent.fire(this.direction,A,B)}};FarePanel.prototype.OnShowCheaperFares=function(){this.currentPage--;this.UpdateDisplay()};FarePanel.prototype.OnShowMoreExpensiveFares=function(){this.currentPage++;this.UpdateDisplay()};FarePanel.prototype.DisableAllFares=function(B){if(this.disableAll!=B){this.disableAll=B;var A=this.GetFareControls();for(var C=0;C<A.length;C++){this.SetAppearance(A[C])}}};FarePanel.prototype.SetData=function(C,B,A){this.singleFareGroups=C;this.returnFareGroups=B;this.routes=A;this.CalculatePagesRequired();if(!this.isEnabled){this.EnablePanel()}};FarePanel.prototype.CalculatePagesRequired=function(){if(this.returnFareGroups.length==0){this.pagesRequired=Math.floor((this.singleFareGroups.length-1)/10+1)}else{this.pagesRequired=Math.floor(Math.max((this.returnFareGroups.length-1)/5+1,(this.singleFareGroups.length-1)/5+1))}if(this.pagesRequired==0){this.pagesRequired=1}if(this.currentPage>=this.pagesRequired){this.currentPage=this.pagesRequired-1}};FarePanel.prototype.UpdateDisplay=function(){this.fareKeys=new Array();var A=this.GetFareControls();for(var B=0;B<A.length;B++){A[B].fareGroup=undefined;this.ClearFare(A[B])}if(this.returnFareGroups.length==0){this.SetFares(A,this.singleFareGroups,0,10)}else{this.SetFares(A,this.singleFareGroups,0,5);this.SetFares(A,this.returnFareGroups,5,5)}for(B=0;B<A.length;B++){this.SetAppearance(A[B])}if(!this.btnMoreFares){this.btnMoreFares=YAHOO.util.Dom.getElementsByClassName("MoreFares",undefined,this.farePanelId)[0]}ShowElement(this.btnMoreFares,this.currentPage<this.pagesRequired-1);if(!this.btnCheaperFares){this.btnCheaperFares=YAHOO.util.Dom.getElementsByClassName("CheaperFares",undefined,this.farePanelId)[0]}ShowElement(this.btnCheaperFares,this.currentPage>0)};FarePanel.prototype.SetFares=function(C,G,E,D){var B=D*this.currentPage;var H=0;var I=E;for(var F in G){if(H>=B){if(I>=E+D){break}this.SetFare(C[I],G[F],F);var A=new Object();A.farePanel=this;A.fareControl=C[I];var J=YAHOO.util.Event.addListener(C[I],"mouseover",this.FareMouseOver,A);J=YAHOO.util.Event.addListener(C[I],"mouseout",this.FareMouseOut,A);J=YAHOO.util.Event.addListener(C[I],"click",this.FareMouseClick,A);I++}H++}};FarePanel.prototype.ClearFare=function(A){var D=YAHOO.util.Event.removeListener(A,"mouseover");D=YAHOO.util.Event.removeListener(A,"mouseout");D=YAHOO.util.Event.removeListener(A,"click");var C=YAHOO.util.Dom.getElementsByClassName("FarePriceText",undefined,A);C[0].innerHTML="";var B=YAHOO.util.Dom.getElementsByClassName("FareType",undefined,A);B[0].innerHTML="";if(A.webFare==undefined){A.webFare=YAHOO.util.Dom.getElementsByClassName("WebFare",undefined,A)[0];A.dummyWebFare=YAHOO.util.Dom.getElementsByClassName("DummyWebFare",undefined,A)[0]}this.ShowWebFareElement(A,false);if(A.loyaltyPoints==undefined){A.loyaltyPoints=YAHOO.util.Dom.getElementsByClassName("LoyaltyPointsIcon",undefined,A)[0]}this.ShowLoyaltyPointsElement(A,false);A.title=""};FarePanel.prototype.ShowWebFareElement=function(A,B){ShowElement(A.webFare,B);var C;if(B){C=A.fareGroup.minFare<10000&&A.fareGroup.minFare!=A.fareGroup.maxFare}else{C=A.fareGroup&&A.fareGroup.minFare==A.fareGroup.maxFare}ShowElement(A.dummyWebFare,C)};FarePanel.prototype.ShowLoyaltyPointsElement=function(A,B){ShowElement(A.loyaltyPoints,B)};FarePanel.prototype.SetFare=function(A,E){A.fareGroup=E;A.fareKey=E.fareGroupId;this.fareKeys[E.fareGroupId]=A;var D=YAHOO.util.Dom.getElementsByClassName("FarePriceText",undefined,A);if(E.minFare==E.maxFare){E.farePrice=FormatPrice(E.minFare);D[0].innerHTML=this.FormatPrice(E.minFare);D[0].style.display="block";D[0].style.clear="both";D[0].parentNode.style.paddingTop=""}else{E.farePrice=this.FormatPrice(E.minFare)+" "+mixingDeck.resourceStrings.to+" "+this.FormatPrice(E.maxFare);D[0].innerHTML=this.FormatPrice(E.minFare)+mixingDeck.resourceStrings.to+" "+this.FormatPrice(E.maxFare);D[0].style.display="";D[0].style.clear="";D[0].parentNode.style.paddingTop="4px";D[0].innerHTML=this.FormatPrice(E.minFare)+"<br/>"+mixingDeck.resourceStrings.to+this.FormatPrice(E.maxFare)}var C=YAHOO.util.Dom.getElementsByClassName("FareType",undefined,A);if(E.isCarnet){C[0].innerHTML=mixingDeck.resourceStrings.carnetTicket}else{if(E.isReturn){C[0].innerHTML=mixingDeck.resourceStrings.returnTicket}else{C[0].innerHTML=mixingDeck.resourceStrings.singleTicket}}this.ShowWebFareElement(A,E.isDiscounted);var B=mixingDeck.journeyPlanningData.GetLoyaltyPoints(E);this.ShowLoyaltyPointsElement(A,B!=null)};FarePanel.prototype.FareMouseOver=function(E,C){var A=C.fareControl;var D=C.farePanel;if(A.fareGroup==undefined){return }else{var B=mixingDeck.journeyPlanningData.GetLoyaltyPoints(A.fareGroup);if(B){D.ShowLoyaltyPopup(A,B)}}if(!A.hover){A.hover=true;C.farePanel.SetAppearance(A);if(!D.disableAll&&!C.farePanel.FareSelected()&&D.IsAvailable(A)){C.farePanel.FireEvent(A.fareGroup,false)}}};FarePanel.prototype.FareMouseOut=function(G,C){var F=C.fareControl;var D=C.farePanel;if(StillInsideElementOnMouseOut(F,G)){return }if(F.fareGroup==undefined){return }else{D.HideLoyaltyPopup()}F.hover=false;C.farePanel.SetAppearance(F);if((D.IsAvailable(F)||F.fareGroup.isDisabled)&&!D.disableAll&&!C.farePanel.FareSelected()){var E=G.relatedTarget||G.toElement;var H=(E==null||E==undefined);if(!H){var B=E;var A;var I;while(B!=undefined){if(HasClass(B,"FareLineEntry")){I=B}if(B.id==D.farePanelId){A=true;break}B=B.parentNode}H=(I==undefined||I.fareGroup==undefined||!D.IsAvailable(I)||!A)}if(H){C.farePanel.FireEvent(null,false)}}};FarePanel.prototype.SelectFare=function(D){var C;var B;var A;if(this.returnFareGroups.length==0){for(A=0;this.singleFareGroups[A]!=D;A++){if(!this.singleFareGroups[A]){return }}C=Math.floor(A/10);B=A%10}else{if(D.isReturn&&!D.isBidirectional){for(A=0;this.returnFareGroups[A]!=D;A++){if(this.returnFareGroups[A]==undefined){return }}B=A%5+5}else{for(A=0;this.singleFareGroups[A]!=D;A++){if(this.singleFareGroups[A]==undefined){return }}B=A%5}C=Math.floor(A/5)}this.currentPage=C;this.UpdateDisplay();this.SetAvailableFares(null)};FarePanel.prototype.FareMouseClick=function(D,B){var A=B.fareControl;var C=B.farePanel;if(!C.IsAvailable(A)||C.disableAll){return }var E=null;if(mixingDeck.journeyPlanningData._selectedFareGroup[outward].selected&&isOutwardUpgradeTaken&&C.direction==0){isOutwardUpgradeTaken=false}if(mixingDeck.journeyPlanningData._selectedFareGroup[inward].selected&&isReturnUpgradeTaken&&C.direction==1){isReturnUpgradeTaken=false}if(!C.IsSelected(A.fareGroup)){E=C.GetSelectedControl()}B.farePanel.FireEvent(A.fareGroup,!C.IsSelected(A.fareGroup));if(E){C.SetAppearance(E)}B.farePanel.SetAppearance(A)};FarePanel.prototype.GetSelectedControl=function(){var A=this.GetFareControls();for(var B=0;B<A.length;B++){if(A[B].fareGroup&&this.IsSelected(A[B].fareGroup)){return A[B]}}return null};FarePanel.prototype.ClearSelection=function(){var A=this.GetSelectedControl();if(A){this.FireEvent(null,false);this.SetAppearance(A)}};FarePanel.prototype.CentreFareText=function(A,C,B){if(B){C.style.display="";C.style.clear=""}else{C.style.display="block";C.style.clear="both"}};FarePanel.prototype.FormatPrice=function(A){if(A%100==0){return"&pound;"+(A/100)}else{return"&pound;"+(A/100).toFixed(2)}};FarePanel.prototype.SetAvailableFares=function(A,D){var C;var B=this.GetFareControls();for(C in B){this.SetAppearance(B[C])}};FarePanel.prototype.IsFareGroupInService=function(C,A){for(var B in A.serviceFares){if(A.serviceFares[B].fgId==C){return true}}return false};FarePanel.prototype.SetTooltip=function(A){if(A.fareGroup==undefined){A.title="";return }var B=A.fareGroup.tooltipDesc;if(!A.fareGroup.multiRoutes&&A.fareGroup.routeCode!="00000"){B+=mixingDeck.resourceStrings.validVia+this.routes[A.fareGroup.routeCode].routeDesc}if(A.fareGroup.railcardText!=undefined){B+=A.fareGroup.railcardText}if(this.IsAvailable(A)){A.title=B}else{if(A.fareGroup.isDisabled){A.title=B+A.fareGroup.toolTip}else{A.title=B+mixingDeck.resourceStrings.notAvailable}}};FarePanel.prototype.GetFareControls=function(){if(this.fareControls==undefined){this.fareControls=YAHOO.util.Dom.getElementsByClassName("FareLineEntry",undefined,this.farePanelId)}return this.fareControls};FarePanel.prototype.SetAppearance=function(B){var E=0;var I;var A="0px 0px";var D="0px 0px";var G=mixingDeck.journeyPlanningData.GetLoyaltyPoints(B.fareGroup);if(!G){this.SetTooltip(B)}if(B.fareGroup==undefined){I=6}else{switch(B.fareGroup.isReturn){case true:switch(B.fareGroup.fClass){case"S":E=2;break;case"1":E=3;break}break;case false:switch(B.fareGroup.fClass){case"S":E=0;break;case"1":E=1;break}break}if(B.fareGroup.isCarnet&&B.fareGroup.isSingleBidirectional){switch(B.fareGroup.fClass){case"S":E=0;break;case"1":E=1;break}}if(this.IsAvailable(B)==false||this.disableAll){if(B.hover){I=5}else{I=4}if(B.fareGroup.isDiscounted){A="0px -20px"}D="0px -20px"}else{if(this.IsSelected(B.fareGroup)){if(B.hover){I=3}else{I=2}}else{if(B.hover){I=1}else{I=0}}}}if(B.webFare.style.backgroundPosition!=A){B.webFare.style.backgroundPosition=A}if(B.loyaltyPoints.style.backgroundPosition!=D){B.loyaltyPoints.style.backgroundPosition=D}var C;switch(E){case 0:C="StandardSingle";break;case 1:C="FirstSingle";break;case 2:C="StandardReturn";break;case 3:C="FirstReturn";break;default:C="";break}switch(I){case 0:C+="";break;case 1:C+="Hover";break;case 2:C+="Selected";break;case 3:C+="SelectedHover";break;case 4:C+="Unavailable";break;case 5:C+="UnavailableHover";break;case 6:C+="Undefined";break}var F=B.className.split(" ");var H=[F[0]];if(F.length>1&&F[1]=="FareSpace"){H.push(F[1])}H.push(C);B.className=H.join(" ")};FarePanel.prototype.EnablePanel=function(){var A=document.getElementById(this.farePanelId);YAHOO.util.Dom.addClass(A,"PanelAvailable");this.isEnabled=true};FarePanel.prototype.IsAvailable=function(A){if(mixingDeck.firstclassrestrictedservices==1){return(!A.fareGroup.isDisabled&&A.fareGroup._available&&!(A.fareGroup._fClassAvailableOnAnyLeg=="noLegs"))}else{return(!A.fareGroup.isDisabled&&A.fareGroup._available)}};FarePanel.prototype.IsSelected=function(A){return mixingDeck.journeyPlanningData.IsSelected(this.direction,A)};FarePanel.prototype.FareSelected=function(){return mixingDeck.journeyPlanningData._selectedFareGroup[this.direction].selected};FarePanel.prototype.ShowLoyaltyPopup=function(C,D){var E="";if(C.fareGroup.fClass=="1"){E+=mixingDeck.resourceStrings["LoyaltyPointsFirstClass"]}else{E+=mixingDeck.resourceStrings["LoyaltyPointsStandardClass"]}var F=this.journeyPlanningData.data.fares[C.fareGroup.repFareId].numChildren;if(F==1){E+=mixingDeck.resourceStrings["LoyaltyPointsIncludesChild"]}else{if(F>1){E+=mixingDeck.resourceStrings["LoyaltyPointsIncludesChildren"]}}E+=D.Message;if(D.Warning){E+=D.Warning}if(!C.fareGroup.multiRoutes&&C.fareGroup.routeCode!="00000"){E+=mixingDeck.resourceStrings.validVia+this.routes[C.fareGroup.routeCode].routeDesc}var A=document.getElementById("ctl00_mainContentPlaceHolder_LoyaltyPointsInfoBubble");var B=YAHOO.util.Dom.getElementsByClassName("LoyaltyPointsText",undefined,A)[0];B.innerHTML=E;var G=YAHOO.util.Dom.getXY(C);A.style.left=(G[0]+75)+"px";A.style.top=(G[1]-22)+"px";ShowElement(A,true)};FarePanel.prototype.HideLoyaltyPopup=function(){ShowElement(document.getElementById("ctl00_mainContentPlaceHolder_LoyaltyPointsInfoBubble"),false)}
