// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,r,t){var a=Scanner.fromMessage(e);a.setLocale(r);var i,n,p,o,s,l,m,u,d,g,c,h,v,C,N,$,b,T,f,y,S,E,A,x=[],I={},F=/BOOKING REF : .*?: \w{6}, AIRLINE: ($<airline>\w{2})\/($<reservationId>\w{6})/,D={};for(m=a.getSpan();m.nextRegExp(F).exists();)A=m.innerCapture(F),D[""+A.$airline]=A.$reservationId,m=m.withStart(A[0].getEnd());i=a.getSpan().innerCapture(/TICKET NUMBER\s+: ETKT ([\d ]+)/,1),l=a.getSpan().innerCapture(/TOTAL\s+: ($<priceCurrency>[A-Z]{3})\s+($<totalPrice>[\d,.]+)/);var w=l?l.$priceCurrency:null,R=l?l.$totalPrice:null;if(o=a.getSpan().innerCapture(t.name,1),not(o))return CONTINUE;for(I[""+o]={name:o,seats:{},seatingType:{},ticketNumber:i,totalPrice:R,priceCurrency:w},S=a.getSpan().allInnerCapture(t.arrival,1),f=0;f<S.length;f++)1===S.length&&(y=/(\w{3})\s(\w{3})\s+-/.exec(e.subject),c=y[1],C=y[2]),N=S[f].withStart(S[f].previous(t.contentRegex).getEnd()).withEnd(S[f].previous(/.*/).next(t.flightSectionEnd).getEnd()),E=N.innerCapture(t.flightInfo),d=a.getDetachedSpan(""+E.$departureDate+" "+E.$departureHour+":"+E.$departureMinute).innerDate(),E.$arrivalDate.exists()||(E.$arrivalDate=E.$departureDate),h=a.getDetachedSpan(""+E.$arrivalDate+" "+E.$arrivalHour+":"+E.$arrivalMinute).innerDate(),u=E.$airlineCode,s=E.$flightNumber,g=E.$departureAirport,b=(""+g.next(/.*\n(.*)/,1)).replace(regExpFormatted(/\1.*/,t.terminal),"").trim(),g=(""+g+" "+b).trim(),v=E.$arrivalAirport,T=(""+v.next(/.*\n(.*)/,1)).replace(regExpFormatted(/\1.*/,t.terminal),"").trim(),v=(""+v+" "+T).trim(),$=a.getSpan().innerCapture(regExpFormatted(/\1\s+(.*)/,t.price),1),R=$.innerCapture(/([\d,.]+)/,1),w=$.innerCapture(/([^\d,.]+)/,1).trim(),n=D[""+u],valid(E.$seat)&&(I[""+o].seats[""+s]=E.$seat),ASSERT(u,s,g,d,v,h)&&x.push({reservationId:n,airlineCode:u,flightNumber:s,departureAirport:g,departureCode:c,departureTime:d,arrivalAirport:v,arrivalCode:C,arrivalTime:h,passengers:I});var k=[];for(f=0;f<x.length;f++)for(var P=x[f],z=Object.keys(P.passengers),M=0;M<z.length;M++){var O=P.passengers[z[M]],U={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineName:P.airlineName,airlineCode:P.airlineCode,flightNumber:P.flightNumber,departureAirportFuzzy:P.departureAirport,departureAirportCode:P.departureCode,departureTime:P.departureTime,arrivalAirportFuzzy:P.arrivalAirport,arrivalAirportCode:P.arrivalCode,arrivalTime:P.arrivalTime},underName:{"@type":"http://schema.org/Person",name:O.name},checkinUrl:p,reservationId:P.reservationId,reservationStatus:"http://schema.org/ReservationConfirmed",totalPrice:O.totalPrice,priceCurrency:O.priceCurrency,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:i,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:O.seats[P.flightNumber],seatingType:O.seatingType[P.flightNumber]}}};valid(O.membershipNumber,O.programName)&&(U.programMembershipUsed={"@type":"http://schema.org/ProgramMembership",membershipNumber:O.membershipNumber,programName:O.programName}),k.push(U)}return k.length?k:void 0}}).call();