var Flight=function(n){this.query=n},FlightFactory;Flight.prototype.getId=function(){return"__"+CityMap.name2code[this.query.from]+"-"+CityMap.name2code[this.query.to]+"|"+this.query.date[0]+"-"+this.query.date[1]+"|"+this.query.extra[0]+"-"+this.query.extra[1]};Flight.prototype.getUrl=function(){if(this.url===undefined){var n=this.query.date[0],t=this.query.date[1];this.url="http://api.liebao.cn/flight-extension/qunar/?c=flight_tickets&from="+encodeURIComponent(this.query.from)+"&to="+encodeURIComponent(this.query.to)+"&start="+Util.date.format(n)+"&end="+Util.date.format(t)}return this.url};Flight.prototype.setData=function(n){return this.data=n,this};Flight.prototype.getData=function(n,t,i,r,u){var f={extra:[]},s,a=this.getUrl(),h=this,o,c,e;if(arguments[0]===undefined&&(n=0),n===!0&&(n=1),n||this.data===undefined)n||(n=1);else return this.data;if(arguments[1]===undefined&&(t=!1),o=function(n){if(h.simpleCheck(),n.price===undefined)throw{name:"QueryResultError",message:"没有找到此条航线"};return f.main=n,f.lowestPrice=parseInt(n.price,10),h.data=f,f},t)c=this.getUrl(),e=function(n){$.ajax({url:c,async:!0,error:function(){--n?e(n):(r&&r({name:"RequestError",message:"连接失败"}),u&&u())},success:function(t){try{var f=o(t);i&&i(f)}catch(s){--n?e(n):r&&r(s)}finally{u&&u()}}})},e(n);else while(n)try{return s=JSON.parse($.ajax({url:this.getUrl(),async:!1}).responseText),o(s)}catch(l){if(!--n)throw l;}};Flight.prototype.simpleCheck=function(){if(CityMap.name2code[this.query.from]===undefined)throw{name:"QueryFromError",message:"对不起，不支持该出发地"};if(CityMap.name2code[this.query.to]===undefined)throw{name:"QueryToError",message:"对不起，不支持该目的地"};if(this.query.date[1]<Util.date.floor())throw{name:"QueryDateError",message:"对不起，这张机票你已经错过了"};if(this.query.date[0]>this.query.date[1])throw{name:"QueryDateError",message:"起始日期应小于结束日期"};};FlightFactory={getFromKeeper:function(){var n=InputKeeper.getInfo(),t={from:n.from,to:n.to,date:[n.dateFrom,n.dateTo],extra:[]},r=Math.max(n.date-1728e5,Util.date.floor()),i;return n.dateTo-n.dateFrom<864e5*(config.monitor.extraLeast-1)?(t.extra[0]=Math.max(Util.date.floor(),Util.date.floor(n.dateFrom+(n.dateTo-n.dateFrom)/2-432e5*(config.monitor.extraLeast-1))),t.extra[1]=t.extra[0]+864e5*(config.monitor.extraLeast-1)):t.extra=t.date,i=new Flight(t),n.data!==undefined&&i.setData(JSON.parse(n.data)),i},getFromId:function(n){var t=n.substring(2).split("|"),i=t[0].split("-"),r=t[1].split("-"),u=t[2].split("-");return new Flight({from:CityMap.code2name[i[0]],to:CityMap.code2name[i[1]],date:[parseInt(r[0],10),parseInt(r[1],10)],extra:[parseInt(u[0],10),parseInt(u[1],10)]})},getFromShort:function(n){return new Flight({from:CityMap.code2name[n.shortFrom],to:CityMap.code2name[n.shortTo],date:n.date,extra:n.date})},getFromCtrip:function(n,t,i){var u=Util.date.parse(i),r=[];return r[0]=Math.min(u-1728e5,Util.date.floor()),r[1]=r[0]+3456e5,new Flight({from:CityMap.code2name[n],to:CityMap.code2name[t],date:[u,u],extra:r})}}