// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,t){var r=Scanner.fromMessage(e);r.setLocale(t);var a,n,i,p,o,m,s,g,l,u,c,d,h,T,f,C,v,y,b=[],x={};a=r.getSpan().nextRegExp(/[Cc]onfirmation code:/).parentAnyTag("td").tagContents().innerCapture(/\b[Cc]onfirmation code:\s+(\w+)/,1),not(a)&&(a=r.getSpan().nextRegExp(/Confirmation code:/).nextAnyTag("td").tagContents()),p=r.getSpan().nextText("Passenger name").parentTag("table3").withStart(r.getSpan().nextText("Passenger name").getEnd()).allInnerTags("tr3"),l=r.getSpan().nextText("Total fare").nextTag("td3").tagContents().innerCapture(/([\d,.]+)/,1),not(l)&&(c=r.getSpan().nextText("Fare total").nextTag("td4").tagContents().innerCapture(/($<total>[\d,.]+)\s+($<currency>[\w]+)/),l=c?c.$total:null,u=c?c.$currency:null);for(var N=0,S=p.length;N<S;N++)d=p[N].allInnerTags("td3").map(function(e){return e.tagContents()}),i=""+d[0],x[i]={name:i,programName:"Frequent Flyer",membershipNumber:d[1],ticketNumber:d[2],seats:{},seatingType:{},totalPrice:l,priceCurrency:u};s=r.getSpan().nextText("Trip details").parentTag("table3").allInnerTags("tr3").map(function(e){return e.allInnerTags("td3").map(function(e){return e.tagContents()})}).filter(function(e){return e.length>0});for(var A,$=/^($<time>\d{1,2}:\d{2} [A|P]M)\s+($<code>[A-Z]{3})$/,F=/Flight # (\d+) : Arrives next day,/,k=0;k<s.length;k++)if(d=s[k],d[0].innerCapture(/^(?:Depart|Return)/))m=d[0].nextText("Date:").nextDate();else if(d[1]&&d[1].innerCapture($)){g=d[0],h=d[1].innerCapture($),T=r.getDetachedSpan(""+m+" "+h.$time).innerDate(),f=h.$code,C=d[2].innerCapture($),v=r.getDetachedSpan(""+m+" "+C.$time).innerDate(),y=C.$code;var D=d[d.length-2];o=d[d.length-1].split(" "),p=Object.keys(x);for(var N=0;N<Math.min(p.length,o.length);N++)x[p[N]].seats[g]=o[N].trim(),x[p[N]].seatingType[g]=D;ASSERT(g,T,f,v,y)&&b.push({airlineCode:"US",flightNumber:g,reservationId:a,departureCode:f,departureTime:T,arrivalCode:y,arrivalTime:v,passengers:x})}else if(d[0].innerCapture(F)){A=d[0].innerCapture(F,1);for(var P=b.length;P-- >0&&(b[P].arrivalTime=modifyDate(b[P].arrivalTime,1),""+b[P].flightNumber!=""+A);)b[P].departureTime=modifyDate(b[P].departureTime,1)}for(var z=[],k=0;k<b.length;k++)for(var I=b[k],R=Object.keys(I.passengers),M=0;M<R.length;M++){var E=I.passengers[R[M]],U={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineName:I.airlineName,airlineCode:I.airlineCode||"US",flightNumber:I.flightNumber,departureAirportFuzzy:I.departureAirport,departureAirportCode:I.departureCode,departureTime:I.departureTime,arrivalAirportFuzzy:I.arrivalAirport,arrivalAirportCode:I.arrivalCode,arrivalTime:I.arrivalTime},underName:{"@type":"http://schema.org/Person",name:E.name,email:E.email},checkinUrl:n,reservationId:a,reservationStatus:"http://schema.org/ReservationConfirmed",totalPrice:E.totalPrice,priceCurrency:E.priceCurrency,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:E.ticketNumber,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:E.seats[I.flightNumber],seatingType:E.seatingType[I.flightNumber]}}};valid(E.membershipNumber,E.programName)&&(U.programMembershipUsed={"@type":"http://schema.org/ProgramMembership",membershipNumber:E.membershipNumber,programName:E.programName}),z.push(U)}if(z.length)return z}}).call();