// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,t,r){function a(){return{reservationId:null,reservationStatus:null,totalPrice:null,priceCurrency:null}}function n(){return{checkinUrl:null,airlineCode:null,airlineName:null,flightNumber:null,departureAirportFuzzy:null,departureAirportCode:null,departureTime:null,arrivalAirportFuzzy:null,arrivalAirportCode:null,arrivalTime:null,seatingType:null}}function i(){return{name:null,email:null,telephone:null,membershipNumber:null,programName:null,ticketNumber:null}}function l(){return{seatNumber:null,seatingType:null}}function u(e){return e.tagContents().innerCapture(/.*, .* \((.*)\),[\s]?.*/,1)}function p(e){return e.tagContents().innerCapture(/(.*) \(.*\),[\s]?.*/,1).trim()}var o=a(),g=[],m=[],s=[],T=Scanner.fromMessage(e),d=[];T.setLocale(t);for(var x=T.getSpan().nextText(r.travelTableTitle).nextTag("table4").nextText(r.flightTableTitle).parentTag("td5"),c=x.nextText(r.paymentTableTitle),v=c.nextText(r.passengerTableTitle).nextTag("table5"),b=v.nextTag("td6");b!==T.getNullSpan()&&v.contains(b);){var h=i();h.name=b.tagContents(),b=b.nextTag("td6").nextTag("td6");var C=b.innerCapture(RegExp(r.membershipLabel+"\\s*([A-Za-z ]*)\\s+([0-9]*)"));C&&null!==C[2]&&(h.membershipNumber=C[2].tagContents()),C&&null!==C[1]&&(h.programName=C[1].tagContents()),h.ticketNumber=b.innerCapture(regExpFormatted(/\s*\:\s*([\d|\s]+)/,r.ticketNumberLabel),1).trim(),m.push(h),r.extraPassengerSpacing&&(b=b.nextTag("table6").nextTag("table6").nextTag("table6").nextTag("table6").nextTag("td6").nextTag("td6").nextTag("td6")),b=b.nextTag("td6")}var N=v.nextText(r.preferencesTableTitle).nextTag("table5");o.totalPrice=T.getSpan().nextTag("table4").nextText(r.ticketPriceLabel).nextTag("td6").tagContents(),o.priceCurrency=o.totalPrice.nextTag("td6").tagContents(),o.reservationId=T.getSpan().nextText(r.reservationIdLabel).parentTag("td5").innerCapture(RegExp(r.reservationIdLabel+"\\s*([A-Za-z0-9]*)"),1).tagContents(),o.reservationStatus="http://schema.org/ReservationConfirmed";var y,f,z,A,S;for(y=x.nextTag("table6");y!==T.getNullSpan()&&x.contains(y);){var F=n();S=y.previousDate(),f=y.nextTag("td6"),A=f.tagContents().innerCapture(/($<airlineCode>.{2})($<flightNumber>.*)\s+-\s+($<seatingType>.*)/),A&&(F.airlineCode=A.$airlineCode,F.flightNumber=A.$flightNumber,F.seatingType=A.$seatingType);var k=f.nextTag("td6").nextDate();F.departureTime=getFuzzyDate(T.getDetachedSpan(""+S+" "+k));var D=k.nextTag("td6");F.departureAirportCode=u(D),F.departureAirportFuzzy=p(D);var P=D.nextTag("td6").nextTag("td6").nextTag("td6").nextTag("td6").nextTag("td6").nextDate();F.arrivalTime=getFuzzyDate(T.getDetachedSpan(""+S+" "+P)),unSpanDate_(F.departureTime)>unSpanDate_(F.arrivalTime)&&(F.arrivalTime=modifyDate(F.arrivalTime,1));var I=P.nextTag("td6");F.arrivalAirportCode=u(I),F.arrivalAirportFuzzy=p(I),ASSERT(F.airlineCode,F.flightNumber,F.arrivalTime,F.arrivalAirportCode,F.departureTime,F.departureAirportCode)&&g.push(F),y=y.nextTag("table6").nextTag("table6")}var L,R,$=N;for(R=0;R<m.length;R++){$=$.nextTag("tr6");var E=[];for(L=0;L<g.length;L++){var U=l();$=$.nextTag("tr6");var M=$.nextTag("td6").nextTag("td6").nextTag("td6").nextTag("td6").tagContents();""+M!="-"&&(U.seatNumber=M),E.push(U)}s.push(E),$=$.nextTag("tr6").nextTag("tr6")}for(L=0;L<g.length;L++){var F=g[L];for(R=0;R<m.length;R++){var O=m[R],z={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineCode:F.airlineCode,airlineName:F.airlineName,flightNumber:F.flightNumber,departureAirportFuzzy:F.departureAirportFuzzy,departureAirportCode:F.departureAirportCode,departureTime:F.departureTime,arrivalAirportFuzzy:F.arrivalAirportFuzzy,arrivalAirportCode:F.arrivalAirportCode,arrivalTime:F.arrivalTime},underName:{"@type":"http://schema.org/Person",name:O.name},checkinUrl:"",reservationId:o.reservationId,reservationStatus:o.reservationStatus,totalPrice:o.totalPrice,priceCurrency:o.priceCurrency,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:O.ticketNumber,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:s[R][L].seatNumber,seatingType:F.seatingType}}};valid(OR(O.membershipNumber,O.programName))&&(z.programMembershipUsed={"@type":"http://schema.org/ProgramMembership",membershipNumber:O.membershipNumber,programName:O.programName}),d.push(z)}}return d.length?d:CONTINUE}}).call();