// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){return function(e,r,t){function a(){return(""+d).indexOf("AMERICAN AIRLINES")>=0?"AA":(""+d).indexOf("US AIRWAYS")>=0?"US":""}var n=Scanner.fromMessage(e);n.setLocale(r);var i,o,p,s,g,m,l,u,h,c,d,v,f,T,y,b,A=[],C={};if(c=n.getSpan().nextText(t.travelerInformation).nextTag("table2").allInnerTags("tr2"),u={},c.length)for(var N=1;N<c.length;N++)l=c[N].allInnerTags("td2").map(function(e){return e.tagContents()}),3===l.length&&(s=""+l[0],u[s]||(u[s]={seat:[],seatingType:[]}),u[s].seat.push(l[2]),u[s].seatingType.push(l[1]));if(m=n.getSpan().nextText(t.yourItinerary).nextTag("table1").allInnerTags("tr1"),m.length>2)for(var N=2;N<m.length;N++)if(h=m[N].allInnerTags("td1").map(function(e){return e.tagContents()}),8===h.length){d=h[0];var S=h[1];if(T=h[2].innerCapture(/^([A-Z]{3})/,1),f=getFuzzyDate(h[3]),b=h[4].innerCapture(/^([A-Z]{3})/,1),y=getFuzzyDate(h[5]),ASSERT(d,S,T,f,b,y)){g=Object.keys(u),C={};for(var I=0;I<g.length;I++)C[g[I]]={name:g[I],seat:u[g[I]].seat[A.length],seatingType:u[g[I]].seatingType[A.length]};v=a(d),i=n.getSpan().innerCapture(regExpFormatted(/\1 \2:\s+(\w{6})/,v,t.recordLocator),1),not(i)&&(i=n.getSpan().innerCapture(regExpFormatted(/\b\1:\s+(\w{6})/,t.recordLocator),1)),A.push({airlineName:d,airlineCode:v,flightNumber:S,reservationId:i,departureCode:T,departureTime:f,arrivalCode:b,arrivalTime:y,passengers:C})}}for(var x=[],N=0;N<A.length;N++)for(var z=A[N],F=Object.keys(z.passengers),I=0;I<F.length;I++){var k=z.passengers[F[I]],R={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineName:z.airlineName,airlineCode:z.airlineCode||"AA",flightNumber:z.flightNumber,departureAirportFuzzy:z.departureAirport,departureAirportCode:z.departureCode,departureTime:z.departureTime,arrivalAirportFuzzy:z.arrivalAirport,arrivalAirportCode:z.arrivalCode,arrivalTime:z.arrivalTime},underName:{"@type":"http://schema.org/Person",name:k.name},checkinUrl:o,reservationId:z.reservationId,reservationStatus:"http://schema.org/ReservationConfirmed",totalPrice:k.totalPrice,priceCurrency:p,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:k.ticketNumber,ticketedSeat:{"@type":"http://schema.org/Seat",seatingType:k.seatingType,seatNumber:k.seat}}};valid(k.membershipNumber)&&(R.programMembershipUsed={"@type":"http://schema.org/ProgramMembership",membershipNumber:k.membershipNumber,programName:k.programName}),x.push(R)}if(x.length)return x}}).call();