// Copyright 2014 Apple Inc.  All Rights Reserved.
(function(){function t(t,e){var r=e.kFlight,a=e.kFrom,n=e.kTo,i=e.kStops,s=e.kDuration,p=e.passengerInformation,o=t.getSpan().nextText(r).nextText(a).nextText(n).nextText(i).nextText(s);if(!o.exists())return CONTINUE;for(var g=[],l=o.parentTag("table3").tagContents().nextTag("tr3").firstTag("tr3");l.exists()&&l.nextText(p).exists();){var u=l.nextTag("td3").tagContents(),c=u.innerCapture(/([\d]+)/,1),x=u.innerCapture(/^([A-Z]+)/,1);c=(""+c).substring(0,4);var h=l.firstTag("tr3").tagContents(),T=h.firstTag("td3").tagContents(),f=T.nextTag("td3").tagContents(),m=T.innerCapture(/^(.+) (.+)\n/,1),d=f.innerCapture(/^(.+) (.+)\n/,1),v=T.innerCapture(/^(.+) (.+)\n/,2),C=f.innerCapture(/^(.+) (.+)\n/,2);if(v.exists()&&6==(""+v).length){if(v=(""+v).substring(1,4),!C.exists()||6!=(""+C).length)break;C=(""+C).substring(1,4);var b=(""+T).split("\n")[1],N=b.split("-"),A=N[0].split(" ")[1],S=N[1].split(" ")[0],k=N[1].split(" ")[1];b=A+" "+S+" "+k;var D=(""+T).split("\n")[2],y=t.getDetachedSpan(b+" "+D).innerDate(),F=(""+f).split("\n")[1],z=F.split("-"),I=z[0].split(" ")[1],R=z[1].split(" ")[0],E=z[1].split(" ")[1];F=I+" "+R+" "+E;var P=(""+f).split("\n")[2],L=t.getDetachedSpan(""+F+" "+P).innerDate();ASSERT(c,x,y,v,F,C)&&g.push({airlineName:"Air Canada",flightNumber:c,airlineCode:x,departureDate:y,departureAirport:m,departureAirportCode:v,arrivalDate:L,arrivalAirport:d,arrivalAirportCode:C}),l=l.nextTag("tr3").firstTag("tr3")}else l=l.nextTag("tr3").firstTag("tr3")}return l=null,g}function e(t,e){var r=e.bookingReference,a={};return a.reference=t.getSpan().nextText(r).nextTag("td5").tagContents(),a}function r(t,e){var r=e.passengerInformation,a=e.seatSelection,n=e.priceTotal,i=t.getSpan().nextText(n).nextTag("th3").tagContents(),s=t.getSpan().nextText(n).parentTag("th3").tagContents();if(s.exists()){var p=(""+s).split("-");2==p.length&&(s=p[1].trim())}passengers=[];for(var o,g=t.getSpan().nextText(r).nextTag("table2").firstTag("th2");g.exists();){var l=(""+g.tagContents()).split(":");if(4!=l.length)break;passengerName=l[1].trim(),o=l[3].trim();var u={};(""+g.nextText(a).firstTag("td2").tagContents()).split(",").forEach(function(t){seatDetail=t.trim().split(" "),seatDetail.length>1&&(u[seatDetail[0]]=seatDetail[1])}),passengers.push({name:passengerName,price:i,currency:s,ticketNumber:o,seats:u}),g=g.nextTag("th2")}return g=null,passengers}function a(t,e,r){for(var a=[],n=0;n<t.length;n++)for(var i=t[n],s=0;s<e.length;s++){var p=e[s],o={"@context":"http://schema.org","@type":"http://schema.org/FlightReservation",reservationFor:{"@type":"http://apple.com/FuzzyFlight",airlineName:i.airlineName,airlineCode:i.airlineCode,flightNumber:i.flightNumber,departureAirportFuzzy:i.departureAirport,departureAirportCode:i.departureAirportCode,departureTime:i.departureDate,arrivalAirportFuzzy:i.arrivalAirport,arrivalAirportCode:i.arrivalAirportCode,arrivalTime:i.arrivalDate},underName:{"@type":"http://schema.org/Person",name:p.name},reservationId:r.reference,reservationStatus:"http://schema.org/ReservationConfirmed",totalPrice:p.price,priceCurrency:p.currency,reservedTicket:{"@type":"http://schema.org/Ticket",ticketNumber:p.ticketNumber,ticketedSeat:{"@type":"http://schema.org/Seat",seatNumber:p.seats[i.airlineCode+i.flightNumber]}}};a.push(o)}return a}return function(n,i,s){var p=Scanner.fromMessage(n);p.setLocale(i);var o=t(p,s),g=r(p,s),l=e(p,s);return a(o,g,l)}}).call();