﻿(function(){var A=function(){var D=new SS.models.BrowseModel();var C=new SS.views.BrowseView(D);var B=new SS.controllers.BrowseController(D,C);C.init();B.init();D.init(C)};SS.mainContentReady.subscribe(A,this)}());
(function(){SS.controllers.BrowseController=function(B,A){this.model=B;this.view=A};SS.controllers.BrowseController.prototype.init=function(){if(this.view.directFlightList.rendered){this.view.directFlightList.changeSorting.subscribe(this.onDirectChangeSort,this,true);this.view.directFlightList.clickRow.subscribe(this.onDirectSelectRow,this,true);this.view.directFlightList.clickNext.subscribe(this.onDirectGoNext,this,true)}if(this.view.indirectFlightList.rendered){this.view.indirectFlightList.changeSorting.subscribe(this.onIndirectChangeSort,this,true);this.view.indirectFlightList.clickRow.subscribe(this.onIndirectSelectRow,this,true);this.view.indirectFlightList.clickNext.subscribe(this.onIndirectGoNext,this,true)}};SS.controllers.BrowseController.prototype.onDirectChangeSort=function(B,A){this.changeSort(this.model.directFlightModel,this.view.directFlightList,A[0])};SS.controllers.BrowseController.prototype.onIndirectChangeSort=function(B,A){this.changeSort(this.model.indirectFlightModel,this.view.indirectFlightList,A[0])};SS.controllers.BrowseController.prototype.onDirectSelectRow=function(B,A){this.selectRow(this.model.directFlightModel,this.view.directFlightList,A[0]);if(this.view.indirectFlightList){this.view.indirectFlightList.select(false,this.model.indirectFlightModel.selectedRow);this.view.indirectFlightList.enableNextButton(false)}};SS.controllers.BrowseController.prototype.onIndirectSelectRow=function(B,A){this.selectRow(this.model.indirectFlightModel,this.view.indirectFlightList,A[0]);if(this.view.directFlightList){this.view.directFlightList.select(false,this.model.directFlightModel.selectedRow);this.view.directFlightList.enableNextButton(false)}};SS.controllers.BrowseController.prototype.onDirectGoNext=function(){this.goNext(this.model.directFlightModel)};SS.controllers.BrowseController.prototype.onIndirectGoNext=function(){this.goNext(this.model.indirectFlightModel)};SS.controllers.BrowseController.prototype.changeSort=function(C,F,G){var B=SS.models.BrowseModel.SORT.ORDER;var E=C.sortBy;var A=C.sortOrder;if(G!=null){F.selectSort(E,null);if(E==G){if(A==B.ASC){A=B.DESC}else{A=B.ASC}}else{E=G;A=B.ASC}C.sortBy=E;C.sortOrder=A;F.selectSort(E,A);var D=C.sort();F.renderRows(D);F.select(true,C.selectedRow)}};SS.controllers.BrowseController.prototype.selectRow=function(C,E,B){var D=C.getRow(B);if(D!=null){E.select(false,C.selectedRow);C.selectedRow=D;E.select(true,C.selectedRow);var A=null;if(this.model.isOutbound()){A=SS.global.scView.oASCtrl1()}else{A=SS.global.scView.oASCtrl2()}A.textbox.value=D.data.pn;A.setCityID(D.data.ciid);A.setPlaceName(D.data.pn);A.setPlaceID(D.data.pid);E.enableNextButton(true)}};SS.controllers.BrowseController.prototype.goNext=function(D){if(D.getSelPlaceId()==null){var E=this.model.getTypeOfPlaces();var B=this.model.isOutbound();var C=null;if(E=="city"&&B==true){C="browse_oa"}if(E=="country"&&B==false){C="browse_icy"}if(E=="city"&&B==false){C="browse_i"}if(C){alert(SS.util.gettext(C))}}else{var A=D.getSelPlaceUrl();location.href=A}}}());
(function(){SS.models.BrowseModel=function(){};SS.models.BrowseModel.SORT={};SS.models.BrowseModel.SORT.BY={};SS.models.BrowseModel.SORT.ORDER={};SS.models.BrowseModel.SORT.BY.PLACE="place";SS.models.BrowseModel.SORT.BY.PRICE="price";SS.models.BrowseModel.SORT.ORDER.ASC="asc";SS.models.BrowseModel.SORT.ORDER.DESC="desc";SS.models.BrowseModel.prototype.init=function(B){this.params=SS.data.browse;if(!this.params){return }var C=this.params.currency;var A=C.roundingCoefficient/1000;this.currency=new SS.entities.Currency(C.id,C.symbol,C.thousandsSeparator,C.decimalSeparator,C.symbolOnLeft,C.spaceBetweenAmountAndSymbol,A);this.directFlightModel=new SS.models.BrowseViewFlightListModel(B.directFlightList,this.params.sort.by,this.params.sort.order);this.indirectFlightModel=new SS.models.BrowseViewFlightListModel(B.indirectFlightList,this.params.sort.by,this.params.sort.order)};SS.models.BrowseModel.prototype.getTypeOfPlaces=function(){if(this.params!=null){return this.params.type}else{return null}};SS.models.BrowseModel.prototype.isOutbound=function(){if(this.params){return this.params.outbound}else{return false}}}());
(function(){SS.models.BrowseViewFlightListModel=function(B,C,A){this.flightListView=B;this.sortBy=C;this.sortOrder=A;this.init()};SS.models.BrowseViewFlightListModel.prototype.init=function(){this.selectedRow=null;this.rows=new Array();var C=this.flightListView.getRows();if(C!=null){for(var A=0;A<C.length;A++){var B=this.flightListView.getRowData(A);this.rows[A]=B}}};SS.models.BrowseViewFlightListModel.prototype.getSelPlaceId=function(){if(this.selectedRow!=null){return this.selectedRow.data.pid}else{return null}};SS.models.BrowseViewFlightListModel.prototype.getSelPlaceUrl=function(){if(this.selectedRow!=null){return this.selectedRow.url}else{return null}};SS.models.BrowseViewFlightListModel.prototype.getRow=function(B){for(var A=0;A<this.rows.length;A++){var C=this.rows[A];if(C.rowIdx==B){return C}}return null};SS.models.BrowseViewFlightListModel.prototype.sort=function(){var B=this.rows;var A=this;B=this.rows.sort(function(D,C){return A.comparator(D,C)});return B};SS.models.BrowseViewFlightListModel.prototype.comparator=function(E,B){var G=SS.models.BrowseModel.SORT.BY;var D=SS.models.BrowseModel.SORT.ORDER;var A=this.sortBy;var C=this.sortOrder;if(A==G.PLACE){var F=E.data.no-B.data.no;return F*((C==D.ASC)?1:-1)}if(A==G.PRICE){var F=0;if(E.data.po<0||B.data.po<0){if(E.data.po<0&&B.data.po<0){return 0}if(E.data.po<0&&B.data.po>=0){return 1}if(E.data.po>=0&&B.data.po<0){return -1}}else{F=E.data.po-B.data.po}return F*((C==D.ASC)?1:-1)}return 0}}());
(function(){SS.views.BrowseView=function(A){this.model=A};SS.views.BrowseView.prototype.init=function(){this.itinerary=SS.factories.ItineraryFactory.getItinerary();this.directFlightList=new SS.views.BrowseViewFlightList("direct","sel_next_direct","sel_price_direct","sel_total_direct",this.model,this.itinerary);this.indirectFlightList=new SS.views.BrowseViewFlightList("indirect","sel_next_indirect","sel_price_indirect","sel_total_indirect",this.model,this.itinerary);if(this.directFlightList.rendered){var E=$D.getElementsByClassName("tooltip_source","span","selection_direct")[0];this.initPriceMessageTooltip(E,$D.get("prices_tooltip_direct"));this.initCheaperIndirectsTooltip()}if(this.indirectFlightList.rendered){var C=$D.getElementsByClassName("tooltip_source","span","selection_indirect")[0];this.initPriceMessageTooltip(C,$D.get("prices_tooltip_indirect"))}this.initSEOPanel();var A=$D.getElementsByClassName("bullet","p","browse"),B=0,D,F;for(;B<A.length;B++){D=A[B].innerHTML;F=D.indexOf("<");if(F>-1){D=D.substring(F);A[B].innerHTML=D}}};SS.views.BrowseView.prototype.initSEOPanel=function(){var C=$D.get("sm_content");var E=$D.getRegion(C);var D=E.bottom-E.top;var B=$D.get("sm_container");$D.setStyle(B,"paddingBottom",D+"px");this.enableShowMoreInfo();this.enableSmHighlighting();var A=$D.get("browse");A.style.zoom="0";A.style.zoom="1"};SS.views.BrowseView.prototype.initPriceMessageTooltip=function(D,C){var A=document.createElement("div");document.body.appendChild(A);A.innerHTML=C.innerHTML;A.style.width=C.style.width;A.className=C.className;A.id=C.id;C.parentNode.removeChild(C);var B=new SS.widgets.Tooltip(A,D,10,20)};SS.views.BrowseView.prototype.initCheaperIndirectsTooltip=function(){var C=$D.getElementsByClassName("cheaperindirect","th","direct");if(C.length==0){return }C=C[0];var A=document.createElement("div");A.id="cheaper_indirects_tooltip1";A.innerHTML=$D.get("cheaper_indirects_tooltip_text").getAttribute("value");$D.addClass(A,"standard_tooltip");document.body.appendChild(A);var B=new SS.widgets.Tooltip(A,C,10,24)};SS.views.BrowseView.prototype.enableSmHighlighting=function(){var A=new SS.views.SmTableView();A.enableHightlightingForAllTables()};SS.views.BrowseView.prototype.enableShowMoreInfo=function(){var A=new SS.views.BlurbView();A.init("sm_content");A.blurbExpanded.subscribe(function(E,C){var G=C[0];if(G!=null){var F=G.heightAfter-G.heightBefore;var B=$D.get("browse");if(B!=null){var D=$D.getStyle(B,"paddingBottom");D=D.replace("px","")|0;D+=F;$D.setStyle(B,"paddingBottom",D+"px")}}},this,true)}}());
(function(){SS.views.BrowseViewFlightList=function(D,F,E,B,C,A){this.panel=$D.get(D);this.rowPrefix=D;if(!this.panel){this.rendered=false;return }this.rendered=true;this.header=$D.getElementsByClassName("tb_hd","table",this.panel)[0];this.body=$D.getElementsByClassName("tb_bd","div",this.panel)[0];this.nextButton=$D.get(F);this.pricePanel=$D.get(E);this.totalPrice=$D.get(B);this.model=C;this.itinerary=A;this.itinerary.itineraryChanged.subscribe(SS.views.BrowseViewFlightList.prototype.onItineraryChanged,this,true);this.selectedPrice=null;this.changeSorting=new YAHOO.util.CustomEvent("changeSorting",this);this.clickNext=new YAHOO.util.CustomEvent("clickNext",this);this.clickRow=new YAHOO.util.CustomEvent("clickRow",this);this.init()};SS.views.BrowseViewFlightList.prototype.init=function(){this.initHeader();this.enableFlightsHighlight();this.enableFlightsSelect();this.enableNextButton(false);$E.addListener(this.nextButton,"click",function(){this.clickNext.fire()},this,true);this.fitPanelToContent();this.updateTotalPrice()};SS.views.BrowseViewFlightList.prototype.initHeader=function(){var A=SS.models.BrowseModel.SORT.BY,B=null,G=null,F,H,C,K,E,I,J,D=(YAHOO.env.ua.ie||0)>0;if(this.header!=null){B=$D.getElementsBy(function(){return true},"th",this.header);for(F=0;F<B.length;F++){H=$D.getElementsByClassName("sortable","",B[F]);if(H!=null&&H.length>0){skyscanner.$D.disableTextSelecting(H[0]);C=null;if($D.hasClass(B[F],"place")){C=A.PLACE}if($D.hasClass(B[F],"price")){C=A.PRICE}if(C!=null){$E.addListener(B[F],"click",function(M,L){this.changeSorting.fire(L)},C,this)}}}}K=this.getRows(true);if(K!=null){G=$D.getElementsBy(function(){return true},"td",K[0])}if(G!=null&&B!=null){for(F=0;F<G.length;F++){if(G[F+1]!=null){E=$D.getX(G[F+1]);I=$D.getX(G[F]);J=E-I;if(F==1&&D){J+=35}B[F].style.width=J+"px"}$D.setStyle(B[F],"visibility","visible")}}};SS.views.BrowseViewFlightList.prototype.enableFlightsHighlight=function(){var B=this.getRows(false);for(var A=0;A<B.length;A++){$E.addListener(B[A],"mouseover",function(D,C){if(!$D.hasClass(C,"hover")){$D.addClass(C,"hover")}},B[A]);$E.addListener(B[A],"mouseout",function(D,C){if($D.hasClass(C,"hover")){$D.removeClass(C,"hover")}},B[A])}};SS.views.BrowseViewFlightList.prototype.enableFlightsSelect=function(){var C=this.getRows(false),A=0,B;for(;A<C.length;A++){B=0;if(C[A].id!=null){B=C[A].id.replace(/.+_/i,"")||0}$E.addListener(C[A],"click",function(E,D){this.clickRow.fire(D)},B,this)}};SS.views.BrowseViewFlightList.prototype.enableNextButton=function(A){if(this.nextButton!=null){this.nextButton.disabled=!A;if(A){if($D.hasClass(this.nextButton,"disabled")){$D.removeClass(this.nextButton,"disabled")}}else{if(!$D.hasClass(this.nextButton,"disabled")){$D.addClass(this.nextButton,"disabled")}}}};SS.views.BrowseViewFlightList.prototype.fitPanelToContent=function(){var H=YAHOO.env.ua.ie||0;H=H<=6;if(H){var D=this.body;if(D!=null){var F=$D.getRegion(D),C=F.bottom-F.top,B=$D.getElementsBy(function(){return true},"table",D);if(B!=null&&B.length>0){B=B[0];var A=$D.getRegion(B),G=A.bottom-A.top,E=0;if(G<C&&G){if(G<E){G=E}D.style.height=G+"px"}}}}};SS.views.BrowseViewFlightList.prototype.selectSort=function(D,A){var B=$D.getElementsByClassName(D,"th",this.header);if(B!=null){B=B[0];var C=$D.getElementsByClassName("sortable","span",B);if(C!=null){C=C[0];if(A==SS.models.BrowseModel.SORT.ORDER.ASC){if(!$D.hasClass(C,"sort_asc")){$D.addClass(C,"sort_asc")}if($D.hasClass(C,"sort_desc")){$D.removeClass(C,"sort_desc")}}else{if(A==SS.models.BrowseModel.SORT.ORDER.DESC){if(!$D.hasClass(C,"sort_desc")){$D.addClass(C,"sort_desc")}if($D.hasClass(C,"sort_asc")){$D.removeClass(C,"sort_asc")}}else{if($D.hasClass(C,"sort_asc")){$D.removeClass(C,"sort_asc")}if($D.hasClass(C,"sort_desc")){$D.removeClass(C,"sort_desc")}}}}}};SS.views.BrowseViewFlightList.prototype.select=function(D,B){if(B!=null){var A=this.getRowDomElems(B.rowIdx);if(A!=null){if(D){if(!$D.hasClass(A.tr,"selected")){$D.addClass(A.tr,"selected")}A.radio.checked=true;var C=$D.getElementsByClassName("metadata","input",A.tr)[0];if(C){matches=C.value.match(/"po":(\d+(.\d+))/);if(matches){this.selectedPrice=matches[1]}else{this.selectedPrice=0}}}else{if($D.hasClass(A.tr,"selected")){$D.removeClass(A.tr,"selected")}this.selectedPrice=null}}}this.updateTotalPrice()};SS.views.BrowseViewFlightList.prototype.onItineraryChanged=function(B,A){this.updateTotalPrice()};SS.views.BrowseViewFlightList.prototype.getRows=function(A){if(A&&this._cachedRows!=null){return this._cachedRows}var C=this.body;if(C!=null){var B=$D.getElementsByClassName("row","tr",C);if(A){this._cachedRows=B}return B}return null};SS.views.BrowseViewFlightList.prototype.getRowDomElems=function(D){var A={radio:null,tr:null};var B=this.getRows(true);var C=$D.get(this.rowPrefix+"_"+D);if(C!=null){A.tr=C;A.radio=$D.getElementsBy(function(E){return E.type.toLowerCase()=="radio"},"input",C);if(A.radio!=null){A.radio=A.radio[0]}}return A};SS.views.BrowseViewFlightList.prototype.getRowData=function(F){var B={data:null,url:null,rowIdx:0,html:null};B.rowIdx=F;var D=this.getRows(true);var E=$D.get(this.rowPrefix+"_"+F);if(E!=null){B.html=E.innerHTML;var C=$D.getElementsBy(function(G){return G.type.toLowerCase()=="hidden"},"input",E);if(C!=null){C=C[0];B.data=YAHOO.lang.JSON.parse(C.value)}var A=$D.getElementsBy(function(G){return $D.hasClass(G.parentNode,"place")},"a",E);if(A){B.url=A[0].href}}return B};SS.views.BrowseViewFlightList.prototype.renderRows=function(A){var C=this.body;if(C!=null){tb=$D.getElementsBy(function(){return true},"table",C);if(tb!=null){tb=tb[0];var F=[],D=0,G,E,H,I,B;F.push("<table");if(tb.className!=""){F.push(' class="',tb.className,'"')}if(tb.id!=""){F.push(' id="',tb.id,'"')}F.push(">");for(;D<A.length;D++){F.push("<tr");B=A[D];I=this.getRowDomElems(B.rowIdx).tr;if(I.className!=""){G=I.className.split(" ");E=[];for(H=0;H<G.length;H++){if(G[H]!="row_even"){E.push(G[H])}}if(D%2!=0){E.push("row_even")}F.push(' class="',E.join(" "),'"')}if(I.id!=""){F.push(' id="',I.id,'"')}F.push(">",B.html,"</tr>")}F.push("</table>");while(C.firstChild){C.removeChild(C.firstChild)}C.innerHTML=F.join("");this.enableFlightsHighlight();this.enableFlightsSelect()}}};SS.views.BrowseViewFlightList.prototype.updateTotalPrice=function(){var B;if(this.selectedPrice===null){$D.setStyle(this.pricePanel,"display","none");return }if(this.selectedPrice>0){var A=this.selectedPrice*(this.itinerary.adults+this.itinerary.children);B=this.model.currency.formatPrice(Number(A),2,false)}else{B="&mdash;"}$D.setStyle(this.pricePanel,"display","block");this.totalPrice.innerHTML=B}}());
(function(){SS.views.BlurbView=function(){this.blurbExpanded=new YAHOO.util.CustomEvent("blurbExpanded",this)};SS.views.BlurbView.prototype.init=function(E){var C=this;var G=$D.getElementsByClassName("sm_show_more_less_info","a",E);if(G!=null&&G.length>0){for(var B=0;B<G.length;B++){var A=G[B];var F=$D.getElementsByClassName("sm_more_info","span",A.parentNode);if(F!=null&&F.length>0){var D={};D.moreInfoParagr=F[0];D.more=$D.hasClass(D.moreInfoParagr,"sm_more_info_expanded");D.anchor=A;this.showMoreLess=D;$E.addListener(A,"click",function(K,I){I.more=!I.more;var J=$D.getRegion(I.anchor.parentNode);I.heightBefore=J.bottom-J.top;if(I.more){$D.removeClass(I.moreInfoParagr,"sm_more_info_collapsed");$D.addClass(I.moreInfoParagr,"sm_more_info_expanded");var H=SS.util.gettext("sm_show_less_info");I.anchor.innerHTML=H}else{$D.removeClass(I.moreInfoParagr,"sm_more_info_expanded");$D.addClass(I.moreInfoParagr,"sm_more_info_collapsed");var H=SS.util.gettext("more2")+"+";I.anchor.innerHTML=H}var J=$D.getRegion(I.anchor.parentNode);I.heightAfter=J.bottom-J.top;C.blurbExpanded.fire(I);YAHOO.util.Event.preventDefault(K)},D,true)}}}}})();
(function(){SS.views.SmTableView=function(){};SS.views.SmTableView.prototype.enableHightlightingForAllTables=function(){var C=$D.getElementsByClassName("sm_table_hightlighted","table","sm_content");if(C!=null){for(var B=0;B<C.length;B++){var A=C[B];this.enableHightlightForTable(A)}}};SS.views.SmTableView.prototype.enableHightlightForTable=function(A){var B=$D.getChildren(A);if(B!=null){var D=$D.getChildren(B[0]);for(var C=0;C<D.length;C++){$E.addListener(D[C],"mouseover",function(){$D.addClass(this,"sm_table_row_hightlight")},D[C]);$E.addListener(D[C],"mouseout",function(){$D.removeClass(this,"sm_table_row_hightlight")},D[C])}}}})();
