(new Gallery).addStage("flightSetting",{header:{prevStage:"root",backWhole:!0,title:"抢飞机票"},init:function(){$(":text[name=flightFrom]").blur(function(){InputKeeper.keep("from",$(this).val())});$(":text[name=flightTo]").blur(function(){InputKeeper.keep("to",$.trim($(this).val()))});$("#datepickerFrom").datepicker({minDate:0,maxDate:"+60d",dateFormat:"yy-mm-dd",onSelect:function(n){var t=Util.date.parse(n);InputKeeper.keep("dateFrom",t);Statistics.trigger(10,n,0);t>Util.date.parse($("#datepickerTo").val())&&(setTimeout(function(){$("#datepickerTo").datepicker("setDate",Util.date.format(t+3456e5))},500),InputKeeper.keep("dateTo",t+3456e5));setTimeout(function(){$("#datepickerTo").datepicker("option","minDate",n)},500)}});$("#datepickerTo").datepicker({minDate:0,maxDate:"+60d",dateFormat:"yy-mm-dd",onSelect:function(n){InputKeeper.keep("dateTo",Util.date.parse(n));Statistics.trigger(10,n,1)}});initCityInput($("#flightFrom"),"From");initCityInput($("#flightTo"),"To");$(".main[_stage=flightSetting],.header").click(function(n){$("#cityListFrom:visible, #cityListTo:visible").each(function(t,i){var r=$(i).offset();(n.pageX<r.left||n.pageX>r.left+$(i).width()||n.pageY<r.top||n.pageY>r.top+$(i).height())&&$(i).hide()})});var n=this._errorHandler;$("#queryFlightBtn").click(function(){var t,i=function(n){for(var t=JSON.parse(Storage.getWithDefault("inputHistory","[]")),i=t.length-1;i>=0;i--)t[i]===n&&t.splice(i,1);t.unshift(n);Storage.set("inputHistory",t.slice(0,Math.min(t.length,config.history.length)))};$("#mainErrorInfo").hide();try{if(t=FlightFactory.getFromKeeper(),(new FlightMonitorBox).get(t.getId())!==undefined){n({name:"DuplicateFlight",message:"您已经关注这条航线, 请修改"});return}t.simpleCheck();i(t.query.from);i(t.query.to);(new Gallery).goTo("waitForData",!1,t)}catch(r){n(r)}})},prepare:function(n){var t,u;Statistics.trigger(2,1);t=InputKeeper.getInfo();u=Util.date.floor();$("#mainErrorInfo").hide();n!==undefined&&this._errorHandler(n);(t.dateFrom===undefined||t.dateFrom<u)&&(t.dateFrom=u+864e5,InputKeeper.keep("dateFrom",t.dateFrom));$("#datepickerFrom").datepicker("option","defaultDate",t.dateFrom);$("#datepickerFrom").val(Util.date.format(t.dateFrom));(t.dateTo===undefined||t.dateTo<t.dateFrom)&&(t.dateTo=t.dateFrom+3456e5,InputKeeper.keep("dateTo",t.dateTo));$("#datepickerTo").datepicker("option","defaultDate",t.dateTo);$("#datepickerTo").val(Util.date.format(t.dateTo));$("#datepickerTo").datepicker("option","minDate",$("#datepickerFrom").val());$("#flightFrom").val(t.from);$("#flightTo").val(t.to);t.from||(t.from=Storage.get("location"),$("#flightFrom").val(t.from),InputKeeper.keep("from",t.from));$("#flightFrom").val()&&$("#flightFrom ~ .text-prompt").addClass("text-hide-prompt");$("#flightTo").val()&&$("#flightTo ~ .text-prompt").addClass("text-hide-prompt");var r=JSON.parse(Storage.getWithDefault("inputHistory","[]")),e=$("ul.cityHistory"),f=6,i;for(r.length==0?$(".cityTitleName").text("热门城市"):$(".cityTitleName").text("历史"),e.empty(),i=0;i<r.length;i++){if(f+=r[i].length*12,f>config.history.width)break;$("<li>").text(r[i]).appendTo(e);f+=10}},_errorHandler:function(n){var t=function(){$(this).removeClass("errorInput").unbind("focus",t).val("")};switch(n.name){case"QueryFromError":$("#flightFrom ~ .text-prompt").addClass("text-hide-prompt");$("#flightFrom").val(n.message).addClass("errorInput").focus(t);break;case"QueryToError":$("#flightTo ~ .text-prompt").addClass("text-hide-prompt");$("#flightTo").val(n.message).addClass("errorInput").focus(t);break;case"QuerySoldOutError":n.message="对不起, 没有特价机票了";case"QueryDateError":case"QueryResultError":case"DuplicateFlight":case"RequestError":$("#mainErrorInfo").text(n.message).show()}}})