

// Filename: /javascript/date_helpers.js
// Was: 7545, now: 3701, compression: 51%

Date.prototype.addDate=function(interval,value){value=parseInt(value,10);var newDate=new Date(this);switch(interval)
{case"d":{newDate.setDate(this.getDate()+value);break;}
case"m":{newDate.setMonth(this.getMonth()+value);break;}
case"y":{newDate.setFullYear(this.getFullYear()+value);break;}
case"h":{newDate.setHours(this.getHours()+value);break;}
case"n":{newDate.setMinutes(this.getMinutes()+value);break;}
case"s":{newDate.setSeconds(this.getSeconds()+value);break;}
default:{throw(new Error(".addDate: invalid interval"));break;}}
return newDate;};Date.prototype.toDateFormat=function(formatstring){var output=new String(formatstring);output=output.replace(/yyyy/gi,this.getFullYear());output=output.replace(/yy/gi,(this.getYear()<10?'0':'')+this.getYear());output=output.replace(/mm/g,((this.getMonth()+1)<10?'0':'')+(this.getMonth()+1));output=output.replace(/m/g,(this.getMonth()+1));output=output.replace(/dd/g,(this.getDate()<10?'0':'')+this.getDate());output=output.replace(/d/g,this.getDate());var hr=this.getHours();output=output.replace(/HH/g,(hr<10?'0':'')+hr);output=output.replace(/H/g,hr);if(hr>12)hr-=12;output=output.replace(/hh/g,(hr<10?'0':'')+hr);output=output.replace(/h/g,hr);output=output.replace(/nn/gi,(this.getMinutes()<10?'0':'')+this.getMinutes());output=output.replace(/n/gi,this.getMinutes());output=output.replace(/ss/gi,(this.getSeconds()<10?'0':'')+this.getSeconds());output=output.replace(/s/gi,this.getSeconds());output=output.replace(/ttt/gi,(this.getMilliseconds()<100?'0':'')+(this.getMilliseconds()<10?'0':'')+this.getMilliseconds());output=output.replace(/t/gi,this.getMilliseconds());output=output.replace(/MMMM/g,this.getMonthName());output=output.replace(/MMM/g,this.getMonthName(true));output=output.replace(/wwww/gi,this.getDayName(false));output=output.replace(/www/gi,this.getDayName(true));output=output.replace(/PP/g,(this.getHours()<12?'AM':'PM'));output=output.replace(/pp/g,(this.getHours()<12?'am':'pm'));output=output.replace(/DD/gi,(Math.floor((this.getDate()%100)/10)==1)?"th":["th","st","nd","rd","th","th","th","th","th","th"][this.getDate()%10]);return output;}
Date.prototype.getDayName=function(abbreviate,abb_length){var abb_length=abb_length?abb_length:3;var abbreviate=abbreviate?true:false;var index=this.getDay();if(abbreviate){return String(Date.dayNames[index]).substr(0,abb_length);}else{return Date.dayNames[index];}}
Date.prototype.getMonthName=function(abbreviate,abb_length){var abb_length=abb_length?abb_length:3;var abbreviate=abbreviate?true:false;var index=this.getMonth();if(abbreviate){return String(Date.monthNames[index]).substr(0,abb_length);}else{return Date.monthNames[index];}}
Date.dayNames=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];Date.monthNames=['January','February','March','April','May','June','July','August','September','October','November','December'];Date.daysBetween=function(start_date,end_date){return(Date.parse(start_date)-Date.parse(end_date))/(1000*60*60*24);}
Date.makeDate=function(date_string){return new Date(Date.parse(date_string));}
Date.prototype.addDays=function(days_to_add){return this.addDate("d",days_to_add);}
Date.prototype.toATOPDate=function(){return this.toDateFormat("d MMM yyyy");}
Date.prototype.ceilingDayOfMonth=function(){var date=this.addDate("m",1);date.setDate(0);return date;}
Date.prototype.getMaxDaysOfMonth=function(){return this.ceilingDayOfMonth().getDate();}
Date.prototype.toMidnight=function(){var newDate=new Date(this);newDate.setHours(0);newDate.setMinutes(0);newDate.setSeconds(0)
newDate.setMilliseconds(0);return newDate;}
Date.prototype.clone=function(){return new Date(this);}
function AssertJSLoadedOk(){return true;}

// Filename: /javascript/search/route_manager.js
// Was: 5575, now: 2700, compression: 52%

var RouteDay=new Class({day:0,durations:[],ret_arr_airport:"",one_way_flights_available:false,initialize:function(route_day){this.day=route_day[0];this.durations=route_day[1];this.ret_arr_airport=route_day[2]||"";this.one_way_flights_available=(this.durations[0]===0);}});var RouteManager=new Class({Implements:[Options],routes:new Hash(),ajaxRequest:null,options:{error_no_avail_message:"\nPlease select from the search options available.\n"},initialize:function(options){this.setOptions(options);},set:function(key,route){var hydrated_route=[];for(var i=0;i<route.length;i++){if(route[i]!=null){hydrated_route[i]=new RouteDay(route[i]);}}
hydrated_route.hydrated=true;this.routes.set(key,hydrated_route);},get:function(route_id){return this.routes.get(route_id)||[];},has:function(route_id){return this.routes.has(route_id);},loadRoute:function(route_id,user_callback){user_callback=user_callback||$empty;if(this.get(route_id)==0){this.cancelFetch();var domain_name="";var js_url=domain_name+"/javascript/availabilitydata/"+route_id+".js";this.ajaxRequest=new Ajax(js_url,{method:"get",evalResponse:true,onComplete:this.routeLoaded.pass([route_id,user_callback],this),noCache:true});this.ajaxRequest.request();}},createAccomOnlyRoute:function(route_id){var route=[];var durations=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28];var route_info=this.decodeRouteName(route_id)
var month_days=this.getRouteDate(route_id).getMaxDaysOfMonth();for(var i=1;i<=month_days;i++){route.push([i,durations,'']);}
this.set(route_id,route);},routeLoaded:function(route_id,callback){if(!this.has(route_id)){this.set(route_id,[]);}
callback();},cancelFetch:function(){if(this.ajaxRequest!=null){this.ajaxRequest.cancel();}
this.ajaxRequest=null;},getRouteName:function(from,to,when,search_type){var return_name="";if($chk(from)&&$chk(to)&&$chk(when)){return_name=from+"_to_"+to+"_on_"+when.toDateFormat("MMM_yyyy")+"_"+this.getSearchTypeKey(search_type);}
return return_name;},decodeRouteName:function(route_id){var route=null;var re=new RegExp("(.+)_to_(.+)_on_([A-Z]{3})_([0-9]{4})_([A-Z]+)","ig");if(route_id.match(re)){route={};route.from=RegExp.$1;route.to=RegExp.$2;route.month=RegExp.$3;route.year=RegExp.$4;route.search_type=RegExp.$5;}
return route;},getRouteDate:function(route_id){var route=this.decodeRouteName(route_id);return Date.makeDate("1 "+route.month+" "+route.year).toMidnight();},getSearchTypeKey:function(search_type){var type_key="";switch(search_type){case SearchTypes.Inclusive():{type_key="INC";break;}
case SearchTypes.AccomOnly():{type_key="AO";break;}
case SearchTypes.FlightOnly():{type_key="FO";break;}}
return type_key;}});var Routes=new RouteManager();

// Filename: /javascript/search/comp_code.js
// Was: 7899, now: 3337, compression: 58%

var CompCode={defaultCode:function(search_type){var comp_code="G";switch(search_type){case SearchTypes.FlightOnly():{comp_code=this.convertInclusiveToFlightOnly(comp_code);break;}
case SearchTypes.AccomOnly():{comp_code=this.convertInclusiveToAccomOnly(comp_code);break;}};return comp_code;},forInclusive:function(airport_code,outDepDate){airport_code=airport_code.toUpperCase();var company_code=this.defaultCode();var codes;if(outDepDate!=null&&outDepDate>new Date(2012,4,1)){codes=new Hash({"C":["CYP","EY","LCA","PFO"],"G":["ATH","CFU","CH","CHQ","CRE","EFL","GRE","HER","JKH","JMK","JNX","JSI","JSY","JTR","KE","KGS","KLX","MJT","PVK","RHO","SKG","SKU","ZTH"],"L":["CAI","BJL","CMB","CUN","DEL","DXB","EG","EGY","GOI","HRG","LRM","LXR","MBA","MLE","MRU","ODY","OE","POP","PUJ","PUY","SSH","TCP","AGY","BOJ","RMF"],"U":["ACE","AGP","ALC","BA","BCN","CA","FAO","FU","FUE","GIB","IBZ","LEI","LPA","MAH","MJV","PMI","SP","TFS","TN"],"X":["ADB","AYT","BJV","BUL","CRO","DB","DLM","EC","ET","MIR","NBE","OT","PUL","TUN","TUR","VAR","SAW"],"S":["SMI"],"N":["DBV","BOJ","MLA"]});}else{codes=new Hash({"C":["CYP","EY","LCA","PFO"],"G":["ATH","CFU","CH","CHQ","CRE","EFL","GRE","HER","JKH","JMK","JNX","JSI","JSY","JTR","KE","KGS","KLX","MJT","PVK","RHO","SKG","SKU","ZTH"],"L":["CAI","BJL","CMB","CUN","DEL","DXB","EG","EGY","GOI","HRG","LRM","LXR","MBA","MLA","MLE","MRU","ODY","OE","POP","PUJ","PUY","SSH","TCP","AGY","BOJ","RMF"],"U":["ACE","AGP","ALC","BA","BCN","CA","FAO","FU","FUE","GIB","IBZ","LEI","LPA","MAH","MJV","PMI","SP","TFS","TN"],"X":["ADB","AYT","BJV","BOJ","BUL","CRO","DB","DBV","DLM","EC","ET","MLA","MIR","NBE","OT","PUL","TUN","TUR","VAR","SAW"],"S":["SMI"]});}
codes.each(function(val,key){if(val.contains(airport_code.toUpperCase())){company_code=codes.keyOf(val).toUpperCase();}});return company_code;},convertInclusiveToFlightOnly:function(inclusive_comp_code){inclusive_comp_code=inclusive_comp_code.toUpperCase();var company_code="";switch(inclusive_comp_code){case"C":{company_code="B";break;}
case"G":{company_code="F";break;}
case"L":{company_code="K";break;}
case"U":{company_code="T";break;}
case"X":{company_code="Y";break;}
case"N":{company_code="O";}};return company_code;},forFlightOnly:function(airport_code,outDepDate){return this.convertInclusiveToFlightOnly(this.forInclusive(airport_code,outDepDate));},convertInclusiveToAccomOnly:function(inclusive_comp_code){inclusive_comp_code=inclusive_comp_code.toUpperCase();var company_code="";switch(inclusive_comp_code){case"C":{company_code="E";break;}
case"G":{company_code="H";break;}
case"L":{company_code="M";break;}
case"U":{company_code="V";break;}
case"X":{company_code="Z";break;}
case"N":{company_code="P";break;}};return company_code;},forAccomOnly:function(airport_code,outDepDate){return this.convertInclusiveToAccomOnly(this.forInclusive(airport_code,outDepDate));},forAirport:function(airport_code,search_type,outDepDate){var company_code="";switch(search_type){case SearchTypes.Inclusive():{company_code=this.forInclusive(airport_code,outDepDate);break;}
case SearchTypes.FlightOnly():{company_code=this.forFlightOnly(airport_code,outDepDate);break;}
case SearchTypes.AccomOnly():{company_code=this.forAccomOnly(airport_code,outDepDate);break;}};return company_code;},branchCode:function(comp_code){return comp_code.toUpperCase()+"IN";}};

// Filename: /javascript/search/search_controller_base.js
// Was: 7823, now: 4591, compression: 41%

var SearchControllerBase=new Class({options:{lastArrAirport:"",lastLocationCode:"",lastResortCode:"",lastDepDate:new Date().toMidnight(),earliestBookableDate:new Date().toMidnight()},selectPaxValueFrom:function(optionsPax,cookiePax,lastPax){var paxAmount=(optionsPax!==null)?optionsPax:false||cookiePax||lastPax;return paxAmount;},createDestinationOptions:function(groups){var all_options=new Hash();var selectedDestinations=null;groups.each(function(group,country_name){var options=[];group.destinations.each(function(destination){var option=this.createDestinationOption(destination,country_name);options.push(option);selectedDestinations=this.setSelectedDestination(option,destination,selectedDestinations)},this);if(options.length>0){all_options.set(country_name,options);}},this);if(selectedDestinations){if(selectedDestinations.airport_location_resort_match){selectedDestinations.airport_location_resort_match.selected=true;}else if(selectedDestinations.airport_location_match){selectedDestinations.airport_location_match.selected=true;}else if(selectedDestinations.airport_match){selectedDestinations.airport_match.selected=true;}}
return all_options;},setSelectedDestination:function(option,destination,selectedDestinations){selectedDestinations=selectedDestinations||{airport_location_resort_match:null,airport_location_match:null,airport_match:null};if(selectedDestinations.airport_location_resort_match==null&&(this.options.lastArrAirport==destination.airportCode&&this.options.lastLocationCode==destination.locationCode&&this.options.lastResortCode==destination.resortCode)){selectedDestinations.airport_location_resort_match=option;}else if(selectedDestinations.airport_location_match==null&&(this.options.lastArrAirport==destination.airportCode&&this.options.lastLocationCode==destination.locationCode)){selectedDestinations.airport_location_match=option;}else if(selectedDestinations.airport_match==null&&this.options.lastArrAirport==destination.airportCode){selectedDestinations.airport_match=option;}
return selectedDestinations;},createDestinationOption:function(destination,country_name){return{value:destination.id,html:this.decorateAllResortsText(destination.name,country_name),selected:false};},createDepartureOptions:function(destination){var options=[];destination.departures.each(function(departure){var option=this.createDepartureOption(departure);options.push(option);},this);return options;},createDepartureOption:function(departure){return{value:departure.airportCode,html:AirportLookup[departure.airportCode]||departure.airportCode,selected:departure.airportCode==this.options.lastDepAirport};},createResortsOptions:function(destination){var options=[];var allResort=this.createResortOptionObject(destination.resortCode,"All Resorts",false);options.push(allResort);destination.resorts.each(function(resort){var option=this.createResortOption(resort);options.push(option);},this);return options;},createResortOption:function(resort){return this.createResortOptionObject(resort.resortCode,resort.resortName);},createResortOptionObject:function(resortCode,resortName){return{value:resortCode,html:resortName,selected:resortCode==this.options.lastResortCode};},createDurationOptions:function(durations,minDuration){var availableDurations=[];minDuration=minDuration?minDuration:0;durations.each(function(duration){if(duration>minDuration){availableDurations.push(duration);}},this);return availableDurations;},createDurationOption:function(duration,matches_last_selection){return{value:duration,html:duration,selected:matches_last_selection,defaultSelected:matches_last_selection};},createMonthYearOptions:function(dates){var options=new Hash();dates.each(function(datePair){var startDate=datePair[0].toMidnight();if(startDate<this.options.earliestBookableDate){startDate=this.options.earliestBookableDate;}
var endDate=datePair[1];var tempDate=startDate.clone();var num_entries=0;while(tempDate<endDate||num_entries>=24){var option=this.createMonthYearOption(tempDate);options.set(option.value,option);tempDate.setDate(1);tempDate=tempDate.addDate("m",1);num_entries++;}},this);return options.getValues();},createMonthYearOption:function(date){var text=date.toDateFormat("MMMM YYYY");return{value:text,html:text,selected:(text==this.options.lastDepDate.toDateFormat("MMMM YYYY"))};},createResortValue:function(resortElementValue,arrivalResortCode){return resortElementValue?resortElementValue:arrivalResortCode;},decorateAllResortsText:function(region_name,country_name){return region_name.toLowerCase()=="all resorts"?country_name+" - All Resorts":region_name;}});

// Filename: /javascript/search/search_controller.js
// Was: 50263, now: 30475, compression: 39%

var SearchTypes={Inclusive:$lambda("Inclusive"),AccomOnly:$lambda("AccomOnly"),FlightOnly:$lambda("FlightOnly")};var FlightOnlyRouteTypes={Return:$lambda("return"),Out:$lambda("out"),Round:$lambda("round")};var SearchController=new Class({Implements:[Options,SearchControllerBase],search_data:null,data_is_good:false,routeManager:null,cookies:{lastSearchType:$lambda("SearchForm.lastSearchType"),lastArrAirport:$lambda("SearchForm.lastArrAirport"),lastDepDate:$lambda("SearchForm.lastDepDate"),lastDuration:$lambda("SearchForm.lastDuration"),lastRouteType:$lambda("SearchForm.lastFlightOnlyRouteType"),lastDepAirport:$lambda("SearchForm.lastDepAirport"),lastResortCode:$lambda("SearchForm.lastResortCode"),lastLocationCode:$lambda("SearchForm.lastLocationCode"),lastAdultPax:$lambda("SearchForm.lastAdultPax"),lastChildPax:$lambda("SearchForm.lastChildPax"),lastInfantPax:$lambda("SearchForm.lastInfantPax"),lastAccomClasses:$lambda("SearchForm.lastAccomClasses"),lastFeaturesAllInclusive:$lambda("SearchForm.lastFeatures.AllInclusive"),lastFeaturesSelfCatering:$lambda("SearchForm.lastFeatures.SelfCatering"),lastFeaturesFamily:$lambda("SearchForm.lastFeatures.Family"),lastFeaturesAdult:$lambda("SearchForm.lastFeatures.Adult"),lastFeaturesVillas:$lambda("SearchForm.lastFeatures.Villas"),lastFeaturesLuxury:$lambda("SearchForm.lastFeatures.Luxury")},errors:{noAvailabilty:$lambda("Sorry, no flight data available.\nPlease try reloading page."),tooManyPax:$lambda("Sorry, a maximum of 9 passengers are allowed."),noFlightData:$lambda("Sorry, no flight data available.\nPlease try reloading page."),tooManyInfants:$lambda("Sorry, you need one adult per infant")},elems:{arrival:null,arrLabel:null,adultPax:null,accomClassesLabel:null,accomClasses:null,branchCode:null,company:null,componentSearchType:null,childPax:null,departure:null,depLabel:null,duration:null,day:null,errorBox:null,flightOnlyRouteType:null,flightOnlyRouteTypeLabel:null,infantPax:null,monthYear:null,outArrAir:null,outDepAir:null,outDepDate:null,retDepDate:null,retDepAir:null,resort:null,resortOptions:null,resortWrapper:null,retArrAir:null,searchSelectorForInclusive:null,searchSelectorForFlightOnly:null,searchSelectorForAccomOnly:null,submitButton:null,spinner:null,template:null,returnDateLabel:null,form:null,luxury:null,allInclusive:null,selfCatering:null,families:null,adultFriendly:null,villas:null,searchTypes:null,MainAccom:null},options:{serverTime:null,currentSearchType:null,forceSearchType:null,lastArrAirport:"CYP",lastDepAirport:"LGW",lastDepDate:null,lastDuration:7,lastResortCode:null,lastLocationCode:null,errorBoxDefaultText:"Unknown error",errorBoxDefaultClass:"Unknown-class",earliestBookableDate:null,minimumDaysToDeparture:0,minDuration:0,showPleaseWaitEffect:$empty,hidePleaseWaitEffect:$empty,isAgent:false,lastAccomClasses:null,lastAdultPax:null,lastChildPax:null,lastInfantPax:null,accomClasses:null,adultPax:null,childPax:null,infantPax:null,cookie_options:{duration:400,path:"/"}},initialize:function(options){this.setOptions(options);this.options.earliestBookableDate=(this.options.serverTime||new Date()).addDays(this.options.isAgent?0:this.options.minimumDaysToDeparture).toMidnight();this.options.lastDepDate=this.options.earliestBookableDate.clone();this.hidePleaseWait();this.showSpinner();this.routeManager=this.options["routeManager"]||window.Routes;this.elems.arrival=$("Arr");this.elems.departure=$("Dep");this.elems.monthYear=$("Month");this.elems.componentSearchType=$("ComponentSearchType");this.elems.template=$("Template");this.elems.accomClasses=$("AccomClasses");this.elems.accomClassesLabel=$("AccomClassesLabel");this.elems.searchSelectorForInclusive=$("SearchSelector_Inclusive");this.elems.searchSelectorForFlightOnly=$("SearchSelector_FlightOnly");this.elems.searchSelectorForAccomOnly=$("SearchSelector_AccomOnly");this.elems.flightOnlyRouteType=$("RouteType");this.elems.flightOnlyRouteTypeLabel=$("RouteTypeLabel");this.elems.resort=$("Resort");this.elems.resortOptions=$("ResortOptions");this.elems.resortWrapper=$("searchToResort");this.elems.company=$("Company");this.elems.branchCode=$("BranchCode");this.elems.altCompany=$("AltComp");this.elems.arrLabel=$("ArrLabel");this.elems.depLabel=$("DepLabel");this.elems.duration=$("Duration");this.elems.outDepAir=$("OutDepAir");this.elems.outArrAir=$("OutArrAir");this.elems.retDepAir=$("RetDepAir");this.elems.retArrAir=$("RetArrAir");this.elems.outDepDate=$("OutDepDate");this.elems.retDepDate=$("RetDepDate");this.elems.adultPax=$("AdultPax");this.elems.childPax=$("ChildPax");this.elems.infantPax=$("InfantPax");this.elems.errorBox=$("searchformerror");this.elems.monthYear=$("Month");this.elems.day=$("Day");this.elems.submitButton=$('submitbutton');this.elems.spinner=$("Spinner");this.elems.returnDateLabel=$("returnDateLabel");this.elems.form=$("CriteriaForm");this.elems.departureWrapper=$("searchFrom");this.elems.luxury=$("featureLuxury");this.elems.allInclusive=$("featureAllInclusive");this.elems.selfCatering=$("featureSelfCatering");this.elems.families=$("featureFamily");this.elems.adultFriendly=$("featureAdult");this.elems.villas=$("featureVillas");this.elems.searchTypes=$("holidaySearchType");this.elems.MainAccom=$("MainAccom");this.setDefaults();this.switchSearchType(this.options.currentSearchType,true);this.elems.departure.addEvent("change",this.buildMonthYearDropDown.bind(this));this.elems.monthYear.addEvent("change",this.loadDayData.bind(this));this.elems.day.addEvent("change",this.buildDurationDropDown.bind(this));this.elems.adultPax.addEvent("change",this.validatePax.bind(this));this.elems.childPax.addEvent("change",this.validatePax.bind(this));this.elems.infantPax.addEvent("change",this.validatePax.bind(this));if(this.elems.resortOptions&&this.elems.resortOptions.options){this.elems.resortOptions.addEvent("change",this.buildMonthYearDropDown.bind(this));}
if(this.elems.searchSelectorForInclusive){this.elems.searchSelectorForInclusive.addEvent("click",this.switchSearchType.pass(SearchTypes.Inclusive(),this));this.elems.searchSelectorForInclusive.set("disabled","");}
if(this.elems.searchSelectorForFlightOnly){this.elems.searchSelectorForFlightOnly.addEvent("click",this.switchSearchType.pass(SearchTypes.FlightOnly(),this));this.elems.searchSelectorForFlightOnly.set("disabled","");this.elems.flightOnlyRouteType.addEvent("change",this.buildDeparturesDropDown.bind(this));}
if(this.elems.searchSelectorForAccomOnly){this.elems.searchSelectorForAccomOnly.addEvent("click",this.switchSearchType.pass(SearchTypes.AccomOnly(),this));this.elems.searchSelectorForAccomOnly.set("disabled","");}
if(this.elems.arrival){this.elems.arrival.addEvent("change",this.buildDeparturesDropDown.bind(this));}
if(this.elems.returnDateLabel){this.elems.monthYear.addEvent("change",this.updateReturnDate.bind(this));this.elems.day.addEvent("change",this.updateReturnDate.bind(this));this.elems.duration.addEvent("change",this.updateReturnDate.bind(this));}},getCookieKey:function(cookie_key){switch(cookie_key){case this.cookies.lastArrAirport:case this.cookies.lastDepAirport:case this.cookies.lastDepDate:case this.cookies.lastDuration:case this.cookies.lastResortCode:case this.cookies.lastLocationCode:cookie_key+="."+this.options.currentSearchType;break;}
return cookie_key;},saveSelection:function(cookieName,value,options){options=options||this.options.cookie_options;cookieKey=this.getCookieKey(cookieName);Cookie.write(cookieKey,value,options);},readSelection:function(key){var cookieKey=this.getCookieKey(key);var val=Cookie.read(cookieKey);return val;},showError:function(msg){this.modElementVisibility(this.elems.submitButton,false);this.elems.duration.disabled=true;this.hideSpinner();if(this.elems.errorBox){this.elems.errorBox.innerHTML=String(msg).replace(/\n/g,"<br>");this.elems.errorBox.className="searchformerror";}else{alert(msg);}},hideError:function(){this.modElementVisibility(this.elems.submitButton,true);if(this.elems.errorBox){this.elems.errorBox.innerHTML=this.options.errorBoxDefaultText;this.elems.errorBox.className=this.options.errorBoxDefaultClass;}},showSpinner:function(){this.modElementVisibility(this.elems.submitButton,false);this.modElementVisibility(this.elems.spinner,true);},hideSpinner:function(){this.modElementVisibility(this.elems.submitButton,true);this.modElementVisibility(this.elems.spinner,false);},cancelSearch:function(){this.hidePleaseWait();this.hideSpinner();},displayPleaseWait:function(){this.options.showPleaseWaitEffect();this.modFormFieldsToHide(true);this.showSpinner();},hidePleaseWait:function(){this.options.hidePleaseWaitEffect();this.modFormFieldsToHide(false);this.hideSpinner();},modElementVisibility:function(eleName,isVisible){var ele=$(eleName);if(ele){isVisible?ele.setStyle("display","inline"):ele.setStyle("display","none");}},modFormFieldsToHide:function(disabled){var fieldsToNotSend=["searchSelectorForInclusive","searchSelectorForFlightOnly","searchSelectorForAccomOnly","arrival","departure","monthYear","day","duration","submitButton","flightOnlyRouteType"];fieldsToNotSend.each(function(field){var elem=this.elems[field];if(elem){elem.disabled=disabled;}},this);if(this.elems.accomClasses&&this.elems.accomClasses.value==""){this.elems.accomClasses.disabled=disabled;}
if(this.elems.debug){this.elems.debug.disabled=this.elems.debug.value.toLowerCase()!="true";}},setDefaults:function(){this.search_data=window.InclusiveData;this.modFormFieldsToHide(false);this.options.currentSearchType=this.options.forceSearchType||this.readSelection(this.cookies.lastSearchType())||SearchTypes.Inclusive();this.options.lastLocationCode=this.options.lastLocationCode||this.readSelection(this.cookies.lastLocationCode())||"";this.options.lastResortCode=this.options.lastResortCode||this.readSelection(this.cookies.lastResortCode())||"";this.options.lastAccomClasses=this.options.accomClasses||this.readSelection(this.cookies.lastAccomClasses())||this.options.lastAccomClasses||"";this.options.lastAdultPax=this.selectPaxValueFrom(this.options.adultPax,this.readSelection(this.cookies.lastAdultPax()),this.options.lastAdultPax);this.options.lastChildPax=this.selectPaxValueFrom(this.options.childPax,this.readSelection(this.cookies.lastChildPax()),this.options.lastChildPax);this.options.lastInfantPax=this.selectPaxValueFrom(this.options.infantPax,this.readSelection(this.cookies.lastInfantPax()),this.options.lastInfantPax);var isSpecificSearch=true;var OutArrAir=this.elems.outArrAir;var OutDepAir=this.elems.outDepAir;var RouteType=this.elems.flightOnlyRouteType;var RetDepDate=this.elems.retDepDate;var OutDepDate=this.elems.outDepDate;var AdultPax=this.elems.adultPax;var ChildPax=this.elems.childPax;var InfantPax=this.elems.infantPax;var resort=this.elems.resortOptions;if(this.options.lastArrAirport==null){if(this.readSelection(this.cookies.lastArrAirport())!=null){this.options.lastArrAirport=this.readSelection(this.cookies.lastArrAirport());}else if(OutArrAir&&OutArrAir.getValue()!=""){this.options.lastArrAirport=OutArrAir.getValue();}}
if(OutDepAir&&OutDepAir.getValue()!=""){this.options.lastDepAirport=OutDepAir.getValue();}
else{if(this.readSelection(this.cookies.lastDepAirport())){this.options.lastDepAirport=this.readSelection(this.cookies.lastDepAirport());}}
if(this.elems.accomClasses){this.elems.accomClasses.setValue(this.options.lastAccomClasses);}
if(AdultPax.selectedIndex==-1){AdultPax.setValue(this.options.lastAdultPax);}
if(ChildPax.selectedIndex==-1){ChildPax.setValue(this.options.lastChildPax);}
if(InfantPax.selectedIndex==-1){InfantPax.setValue(this.options.lastInfantPax);}
var cookieDateString=this.readSelection(this.cookies.lastDepDate());if(OutDepDate&&OutDepDate.getValue()!=""){this.options.lastDepDate=Date.makeDate(OutDepDate.getValue());}
else if(cookieDateString!=""){var cookieDate=Date.makeDate(cookieDateString);if(cookieDate>=this.options.lastDepDate){this.options.lastDepDate=cookieDate;}}
if(OutDepDate&&OutDepDate.getValue()!=""&&RetDepDate&&RetDepDate.getValue()!=""){this.options.lastDuration=Date.daysBetween(RetDepDate.getValue(),OutDepDate.getValue());}else{var cookieDuration=this.readSelection(this.cookies.lastDuration());if(cookieDuration!=null&&cookieDuration!="undefined"){this.options.lastDuration=cookieDuration;}}
if(RouteType){switch(this.readSelection(this.cookies.lastRouteType())){case"out":{RouteType.selectedIndex=1;break;}
case"return":{RouteType.selectedIndex=2;break;}}}
var errorBox=this.elems.errorBox;if(errorBox){this.options.errorBoxDefaultText=errorBox.get("html");this.options.errorBoxDefaultClass=errorBox.get("class");}
if(!window.AccomOnlyData&&!window.FightOnlyData&&!window.InclusiveData){this.showError(this.errors.noFlightData());this.data_is_good=true;}
if(this.elems.luxury){this.elems.luxury.checked=(this.readSelection(this.cookies.lastFeaturesLuxury())=='true');this.elems.allInclusive.checked=(this.readSelection(this.cookies.lastFeaturesAllInclusive())=='true');this.elems.selfCatering.checked=(this.readSelection(this.cookies.lastFeaturesSelfCatering())=='true');this.elems.families.checked=(this.readSelection(this.cookies.lastFeaturesFamily())=='true');this.elems.adultFriendly.checked=(this.readSelection(this.cookies.lastFeaturesAdult())=='true');this.elems.villas.checked=(this.readSelection(this.cookies.lastFeaturesVillas())=='true');}},buildDestinationsDropDown:function(){if(this.elems.arrival.options){this.elems.arrival.empty();this.createDestinationOptions(this.search_data.groups).each(function(options,country){if(options.length>0){var countryOptionGroup=new Element('OPTGROUP',{label:country});options.each(function(option){var option_elem=new Element("option",option);countryOptionGroup.adopt(option_elem);},this);this.elems.arrival.adopt(countryOptionGroup);}},this);}
this.buildDeparturesDropDown();},buildDeparturesDropDown:function(){var arrival_id=this.elems.arrival.getValue();if(arrival_id!=""){var arrival_ids=this.search_data.decodeArrivalId(arrival_id);this.options.lastArrAirport=arrival_ids.airportCode;this.options.lastLocationCode=arrival_ids.locationCode;}
var destination=this.search_data.findDestinationById(this.search_data.checkArrivalId(arrival_id));if(destination==null){}else{this.elems.departure.empty();this.createDepartureOptions(destination).each(function(option){var option_elem=new Element("option",option);this.elems.departure.adopt(option_elem);},this);this.buildResortsDropDown();}},buildResortsDropDown:function(){if(this.elems.resortOptions&&this.elems.resortOptions.options){var arrival_id=this.elems.arrival.getValue();if(arrival_id!=""){var arrival_ids=this.search_data.decodeArrivalId(arrival_id);this.options.lastArrAirport=arrival_ids.airportCode;this.options.lastLocationCode=arrival_ids.locationCode;}
var destination=this.search_data.findDestinationById(this.search_data.checkArrivalId(arrival_id));this.elems.resortOptions.empty();var arrivalId=this.search_data.decodeArrivalId(this.elems.arrival.getValue());var resortOptions=this.createResortsOptions(destination,arrivalId);if(resortOptions.length==1){this.modElementVisibility(this.elems.resortWrapper,false);}
else{resortOptions.each(function(option){var option_elem=new Element("option",option);this.elems.resortOptions.adopt(option_elem);},this);this.modElementVisibility(this.elems.resortWrapper,true);}}
this.buildMonthYearDropDown();},buildMonthYearDropDown:function(){var lastSelectedDeparture=this.elems.departure.getValue();if(lastSelectedDeparture!=""){this.options.lastDepAirport=lastSelectedDeparture;}
var lastDepDate=this.options.lastDepDate.toDateFormat("MMM YYYY");var resort=this.elems.resortOptions!=null?this.elems.resortOptions.getValue():this.elems.resort.getValue();var arrival_id=this.elems.arrival.getValue();var destination_id=this.search_data.checkArrivalId(arrival_id);var destination=this.search_data.findDestinationById(destination_id);var departure=destination.findDepartureByAirportCode(this.options.lastDepAirport);var resortObj=destination.getResortByCode(resort);var dates;if((resortObj==null)||(resortObj.dates.length==0)){dates=departure.dates;}
else{dates=resortObj.dates;}
this.elems.monthYear.empty();this.createMonthYearOptions(dates).each(function(option){var option_elem=new Element("option",option);this.elems.monthYear.adopt(option_elem);},this);this.loadDayData();},is_one_way_flight_search:function(){return(this.options.currentSearchType==SearchTypes.FlightOnly()&&this.elems.flightOnlyRouteType&&this.elems.flightOnlyRouteType.getValue()!=FlightOnlyRouteTypes.Round());},routeNameFromForm:function(){var from_ap=(this.elems.departure||this.elems.outDepAir).getValue();var to_ap=this.search_data.decodeArrivalId((this.elems.arrival||this.elems.outArrAir).getValue()).airportCode;if(this.is_one_way_flight_search()&&this.elems.flightOnlyRouteType.getValue()==FlightOnlyRouteTypes.Return()){var temp_ap=from_ap;from_ap=to_ap;to_ap=temp_ap;}
var when=Date.makeDate("1 "+this.elems.monthYear.getValue());return this.routeManager.getRouteName(from_ap,to_ap,when,this.options.currentSearchType);},getSelectedDate:function(){var selected_date=this.options.earliestBookableDate.clone();if(this.elems.day.getValue()!=""){selected_date=Date.makeDate(this.elems.day.getValue()+" "+this.elems.monthYear.getValue());if(selected_date<=this.options.earliestBookableDate){selected_date=this.options.earliestBookableDate.clone()}}
return selected_date.toMidnight();},loadDayData:function(){var route_id=this.routeNameFromForm();if(!this.routeManager.has(route_id)){if(this.options.currentSearchType==SearchTypes.AccomOnly()){this.routeManager.createAccomOnlyRoute(route_id);this.buildDayDropDown();}
else{this.routeManager.loadRoute(route_id,this.buildDayDropDown.bind(this));}}
else{this.buildDayDropDown();}},buildDayDropDown:function(){this.showSpinner();this.elems.day.disabled=true;var route_id=this.routeNameFromForm();var route=this.routeManager.get(route_id);var route_date=this.routeManager.getRouteDate(route_id);if(route.length==0){this.showError(this.errors.noAvailabilty());this.modElementVisibility(this.elems.submitButton,false);return;}
this.hideError();if(this.elems.monthYear.options&&this.elems.monthYear.options.length>0&&this.elems.monthYear.getValue()!=""&&this.elems.day.options&&this.elems.day.options.length>0&&this.elems.day.getValue()!=""){this.options.lastDepDate=this.getSelectedDate();}
if(route_date<=this.options.earliestBookableDate){route_date=this.options.earliestBookableDate.clone();}
this.elems.day.empty();route.each(function(route_day){var renderOption=false;route_date=new Date(route_date.setDate(route_day.day));if(route_date>this.options.earliestBookableDate){if(this.is_one_way_flight_search()){if(route_day.one_way_flights_available){renderOption=true;}}else{renderOption=true;}
if(renderOption==true){var is_selected=(route_day.day==this.options.lastDepDate.getDate());var temp_date=Date.makeDate(route_day.day+" "+this.elems.monthYear.getValue());var today_text=temp_date.toDateFormat("www dDD");var option_elem=new Element("option",{"value":temp_date.getDate(),"html":today_text,"selected":is_selected,"defaultSelected":is_selected});this.elems.day.adopt(option_elem);}}},this);if(this.elems.day.options.length>0){this.elems.day.disabled=false;}
this.buildDurationDropDown();},buildDurationDropDown:function(){this.elems.duration.disabled=true;var lastDuration=this.elems.duration.getValue();this.elems.duration.empty();if(this.is_one_way_flight_search()){var option_elem=new Element("option",{"value":"","html":"N/A","selected":true,"defaultSelected":true});this.elems.duration.adopt(option_elem);this.hideSpinner();}
else{var route_name=this.routeNameFromForm();var which_day=this.elems.day.getValue();var route=this.routeManager.get(route_name);if(route.length==0){this.hideSpinner();}
else{for(var i=0;i<route.length;i++){var route_day=route[i];if(route_day.day==which_day){var minDuration=this.options.currentSearchType==SearchTypes.AccomOnly()?this.options.minAccomOnlyDuration:this.options.minDuration;var durations=this.createDurationOptions(route_day.durations,this.options.minDuration)
durations.each(function(dur){var matches_last_selection=dur==this.options.lastDuration;var option_elem=new Element("option",this.createDurationOption(dur,matches_last_selection));this.elems.duration.adopt(option_elem);},this);break;}}}
if(this.elems.duration.options.length>0){this.elems.duration.disabled=false;this.modElementVisibility(this.elems.submitButton,true);}}
this.updateReturnDate();this.hideSpinner();},switchSearchType:function(search_type,force_switch){if(!force_switch){this.saveSelection(this.cookies.lastSearchType(),search_type);if(search_type==this.options.currentSearchType){return;}}
this.elems.departure.disabled=false;this.modElementVisibility(this.elems.flightOnlyRouteType,false);this.modElementVisibility(this.elems.flightOnlyRouteTypeLabel,false);this.modElementVisibility(this.elems.searchTypes,true);this.modElementVisibility(this.elems.accomClasses,true);this.modElementVisibility(this.elems.accomClassesLabel,true);this.modElementVisibility(this.elems.departureWrapper,true);switch(search_type){case SearchTypes.Inclusive():{this.elems.submitButton.value="Search for my holiday";this.modElementVisibility(this.elems.resortWrapper,true);this.search_data=window.InclusiveData;if(this.elems.searchSelectorForInclusive){this.elems.searchSelectorForInclusive.checked=true;}
this.modElementVisibility(this.elems.searchTypes,true);break;}
case SearchTypes.FlightOnly():{this.search_data=window.FlightOnlyData;if(this.elems.searchSelectorForFlightOnly){this.elems.searchSelectorForFlightOnly.checked=true;}
this.elems.submitButton.value="Search for my flight";this.modElementVisibility(this.elems.resortWrapper,false);this.modElementVisibility(this.elems.accomClasses,false);this.modElementVisibility(this.elems.accomClassesLabel,false);this.modElementVisibility(this.elems.searchTypes,false);this.modElementVisibility(this.elems.flightOnlyRouteType,true);this.modElementVisibility(this.elems.flightOnlyRouteTypeLabel,true);break;}
case SearchTypes.AccomOnly():{this.elems.submitButton.value="Search for my holiday";this.modElementVisibility(this.elems.resortWrapper,true);this.search_data=window.AccomOnlyData;this.modElementVisibility(this.elems.searchTypes,true);this.elems.departureWrapper.hide();this.modElementVisibility(this.elems.departureWrapper,false);if(this.elems.searchSelectorForAccomOnly){this.elems.searchSelectorForAccomOnly.checked=true;}
break;}};this.options.currentSearchType=search_type;this.elems.componentSearchType.set("value",search_type);this.buildDestinationsDropDown();},updateReturnDate:function(){if(this.elems.returnDateLabel){var retText="-";if(this.elems.duration.getValue()!=""){if(!this.is_one_way_flight_search()){var retDate=this.getSelectedDate().addDate("d",this.elems.duration.getValue());retText=retDate.toDateFormat("www, dDD MMMM yyyy");}}
this.elems.returnDateLabel.set("html",retText);}},validatePax:function(){var foundError;if((this.elems.adultPax.getValue().toInt()+this.elems.childPax.getValue().toInt()+this.elems.infantPax.getValue().toInt())>9){foundError=this.errors.tooManyPax();}
if(this.elems.adultPax.getValue().toInt()<this.elems.infantPax.getValue().toInt()){foundError=this.errors.tooManyInfants();}
if(foundError){this.showError(foundError);this.modElementVisibility(this.elems.submitButton,false);}else{this.hideError();}},submitForm:function(){this.modElementVisibility('submitButton',false);var search_form=$H(this.createSearchData());this.displayPleaseWait();search_form.each(function(value,key){if(this.elems[key]!=null&&this.elems[key].set){this.elems[key].set("value",value);}},this);var arrAir=search_form.outArrAir;var depAir=search_form.outDepAir;if(search_form.isOneWayToUK){arrAir=search_form.outDepAir;depAir=search_form.outArrAir;}
this.saveSelection(this.cookies.lastArrAirport(),arrAir);this.saveSelection(this.cookies.lastDepAirport(),depAir);this.saveSelection(this.cookies.lastDepDate(),search_form.outDepDate);this.saveSelection(this.cookies.lastResortCode(),search_form.resort);this.saveSelection(this.cookies.lastDuration(),search_form.duration);this.saveSelection(this.cookies.lastLocationCode(),this.options.lastLocationCode);this.saveSelection(this.cookies.lastAdultPax(),search_form.adultPax);this.saveSelection(this.cookies.lastChildPax(),search_form.childPax);this.saveSelection(this.cookies.lastInfantPax(),search_form.infantPax);this.saveSelection(this.cookies.lastSearchType(),this.options.currentSearchType);if(this.elems.luxury){if(!this.elems.luxury.checked){this.saveSelection(this.cookies.lastAccomClasses(),search_form.accomClasses);}
else{if(this.elems.accomClasses){this.elems.accomClasses.setValue(5);}}
this.saveSelection(this.cookies.lastFeaturesLuxury(),this.elems.luxury.checked);this.saveSelection(this.cookies.lastFeaturesAllInclusive(),this.elems.allInclusive.checked);this.saveSelection(this.cookies.lastFeaturesSelfCatering(),this.elems.selfCatering.checked);this.saveSelection(this.cookies.lastFeaturesFamily(),this.elems.families.checked);this.saveSelection(this.cookies.lastFeaturesAdult(),this.elems.adultFriendly.checked);this.saveSelection(this.cookies.lastFeaturesVillas(),this.elems.villas.checked);}
if(this.options.currentSearchType==SearchTypes.FlightOnly()){this.saveSelection(this.cookies.lastRouteType(),this.elems.flightOnlyRouteType.getValue());}
if(pageTracker!=undefined){var Category=this.options.currentSearchType;if(this.elems.MainAccom==null||this.elems.MainAccom.value==""){Category="SiteWideSearch."+Category;}else{Category="SpecificSearch."+Category;this.sendEventToGoogle(Category,'Hotel',this.elems.MainAccom.value);var hotelNameSpan=$$('.hotelName');if(hotelNameSpan!=null){var hotelNameLink=hotelNameSpan.getFirst()[0];if(hotelNameLink!=null){var hotelName=hotelNameLink.getText();this.sendEventToGoogle(Category,'Hotel',hotelName);}}}
this.sendEventToGoogle(Category,search_form.outDepAir+" to "+search_form.outArrAir+" on "+search_form.rawDate.toDateFormat("MMMM yyyy"),search_form.duration+" nights");this.sendEventToGoogle(Category,'Resort',search_form.resort);this.sendEventToGoogle(Category,'Duration',search_form.duration);this.sendEventToGoogle(Category,'PAX','Adults',search_form.adultPax);this.sendEventToGoogle(Category,'PAX','Children',search_form.childPax);this.sendEventToGoogle(Category,'PAX','Infants',search_form.infantPax);if(this.options.currentSearchType!=SearchTypes.FlightOnly()){if(this.elems.allInclusive!=null&&this.elems.allInclusive.checked==true)
{this.sendEventToGoogle(Category,'FeatureFilter','All Inclusive');}
if(this.elems.selfCatering!=null&&this.elems.selfCatering.checked==true)
{this.sendEventToGoogle(Category,'FeatureFilter','Self Catering');}
if(this.elems.families!=null&&this.elems.families.checked==true)
{this.sendEventToGoogle(Category,'FeatureFilter','Families');}
if(this.elems.adultFriendly!=null&&this.elems.adultFriendly.checked==true)
{this.sendEventToGoogle(Category,'FeatureFilter','Adult Friendly');}
if(this.elems.villas!=null&&this.elems.villas.checked==true)
{this.sendEventToGoogle(Category,'FeatureFilter','Villas');}
if(this.elems.luxury!=null&&this.elems.luxury.checked==true)
{this.sendEventToGoogle(Category,'FeatureFilter','Luxury');this.sendEventToGoogle(Category,'Rating',5);}else{this.sendEventToGoogle(Category,'Rating',search_form.accomClasses);}}}
var send_search=this.dumpDebugInfo(search_form);if(!send_search){this.hidePleaseWait();}
return send_search;},sendEventToGoogle:function(category,action,label,value){if(label!=""){if(value==undefined){pageTracker._trackEvent(category,action,label,null,false);}else{pageTracker._trackEvent(category,action,label,parseInt(value),false);}}},dumpDebugInfo:function(formData){var ok_to_submit_form=false;if(location.search.length==0||location.search.indexOf("debug=")==-1){ok_to_submit_form=true;}
else{if(this.elems.debug){this.elems.debug.set("value","true");}
var eleArray=new Array();formData.each(function(value,key){eleArray.push(key+": \t"+value);});ok_to_submit_form=confirm("Debug information for form:\n\n - "+eleArray.join("\n - ")+"\n\nContinue submitting form?");}
return ok_to_submit_form;},createFormSelections:function(){var arr_values=this.search_data.decodeArrivalId(this.elems.arrival?this.elems.arrival.getValue():this.elems.outArrAir.getValue());return{arr:arr_values.airportCode,dep:this.elems.departure.getValue()=="N/A"?"":this.elems.departure.getValue(),resort:this.elems.resortOptions?this.createResortValue(this.elems.resortOptions.getValue(),arr_values.resortCode):this.elems.resort.getValue(),routeType:(this.elems.flightOnlyRouteType?this.elems.flightOnlyRouteType.getValue():""),outDepDate:this.getSelectedDate(),duration:this.elems.duration.getValue(),adultPax:this.elems.adultPax.getValue(),childPax:this.elems.childPax.getValue(),infantPax:this.elems.infantPax.getValue(),accomClasses:(this.elems.accomClasses?this.elems.accomClasses.getValue():"")};},createSearchData:function(selection){selection=selection||this.createFormSelections();var search_form={adultPax:selection.adultPax,branchCode:"",childPax:selection.childPax,company:CompCode.forAirport(selection.arr,this.options.currentSearchType,selection.outDepDate),infantPax:selection.infantPax,outDepDate:selection.outDepDate.toATOPDate(),outArrAir:selection.arr,outDepAir:selection.dep,retDepAir:selection.arr,resort:selection.resort,retArrAir:selection.dep,retDepDate:selection.outDepDate.addDate("d",selection.duration).toATOPDate(),template:"Summary",isOneWayToUK:false,duration:selection.duration,accomClasses:selection.accomClasses,rawDate:selection.outDepDate};switch(this.options.currentSearchType){case SearchTypes.FlightOnly():{var arr_comp_code=search_form.company;search_form.template="FlightSearch";if(selection.routeType!=FlightOnlyRouteTypes.Round()){if(selection.routeType==FlightOnlyRouteTypes.Return()){search_form.outArrAir=search_form.retArrAir;search_form.outDepAir=search_form.retDepAir;search_form.isOneWayToUK=true;}
search_form.retArrAir="";search_form.retDepDate="";search_form.retDepAir="";}
var dep_comp_code=CompCode.forAirport(selection.dep,this.options.currentSearchType,selection.outDepDate);if(dep_comp_code!=CompCode.defaultCode(this.options.currentSearchType)){arr_comp_code=dep_comp_code;}
search_form.company=arr_comp_code;break;}
case SearchTypes.AccomOnly():{search_form.template="Summary";}
case SearchTypes.Inclusive():{}}
search_form.branchCode=CompCode.branchCode(search_form.company);return search_form;}});

// Filename: /javascript/search/search_group.js
// Was: 16795, now: 8448, compression: 50%

var SearchGroupCollection=new Class({groups:null,generated_on:new Date(),search_type:"unknown",dateLookup:[],initialize:function(data){this.groups=new Hash();this.generated_on=data.generated_on;this.search_type=data.search_type;this.dateLookup=this.hydrateDateLookup(data.dateLookup);if(this.search_type=="AccomOnlyData"){var x=1;}
$H(data.groups).each(function(group_data,country_name){var group=new SearchGroup(country_name,group_data,this.dateLookup);if(group.isValid()){this.groups.set(group.name,group);}},this);},hydrateDate:function(datePair){var startDate=new Date();var endDate=new Date();var month_year=this.cleanMonthYearString(datePair[0]);startDate.setDate(1);startDate.setYear(month_year.year);startDate.setMonth(month_year.month-1);startDate.setHours(0);startDate.setMinutes(0);startDate.setSeconds(0);startDate.setMilliseconds(0);month_year=this.cleanMonthYearString(datePair[1]);endDate.setDate(1);endDate.setYear(month_year.year);endDate.setMonth(month_year.month);endDate.setDate(0);endDate.setHours(23);endDate.setMinutes(59);endDate.setSeconds(59);endDate.setMilliseconds(999);return[startDate,endDate];},cleanMonthYearString:function(dateStr){var month_year=dateStr.trim().split(" ");month_year.map(function(date){return parseInt(date.trim(),10);});month_year.erase("");return{month:month_year[0],year:month_year[1]};},hydrateDateLookup:function(dates){var datesRtn=[];var datePairIndex=0;if(!dates)
{return;}
for(datePairIndex=0;datePairIndex<=dates.length-1;datePairIndex++){var datePair=dates[datePairIndex];if(datePair.length==2){datePair=this.hydrateDate(datePair);if(datePair[1]<new Date()){datePair=null;}
else
{if(datePair[0]<new Date()){datePair[0]=new Date().toMidnight();}}
datesRtn.push(datePair);}}
return datesRtn;},length:function(){return this.groups.getLength();},isValid:function(){return this.length()>0;},checkArrivalId:function(id){if(id.indexOf(":")==-1){id=this.createArrivalId(id);}
return id;},getDateFromLookup:function(index){return this.dateLookup[index];},createArrivalId:function(airport_code,resort_code,location_code){airport_code=(airport_code?airport_code:"").toUpperCase();resort_code=(resort_code?resort_code:"").toUpperCase();location_code=(location_code?location_code:"").toUpperCase();var id=airport_code+":"+location_code+":"+resort_code;return id;},decodeArrivalId:function(id){var parts=id.split(":");return{airportCode:parts[0]?parts[0].toUpperCase():"",locationCode:parts[1]?parts[1].toUpperCase():"",resortCode:parts[2]?parts[2].toUpperCase():""};},findCountryByName:function(country_name){return this.groups.get(country_name);},findCountriesByAirportCode:function(airport_code){airport_code=airport_code.toUpperCase();var country_names=this.groups.getKeys();var matching_countries=[];var group=null;for(var i=0;i<country_names.length;i++){country=this.findCountryByName(country_names[i]);if(country.findDestinationByAirportCode(airport_code)){matching_countries.push(country);}}
return matching_countries;},findDestinationById:function(id){var arrival=this.decodeArrivalId(id);var matching_destination=null;var countries=this.findCountriesByAirportCode(arrival.airportCode);countries.each(function(country){var dest=country.findDestinationById(id);if(dest){matching_destination=dest;}});if(matching_destination==null){countries.each(function(country){var dest=country.findDestinationByAirportCode(arrival.airportCode);if(dest){matching_destination=dest;}});}
return matching_destination;}});var SearchGroup=new Class({name:"",destinations:[],destinationByNameCache:null,destinationByAirportCodeCache:null,destinationByIdCache:null,initialize:function(country_name,data,lookup){this.destinations=[];this.destinationByNameCache=new Hash(),this.destinationByAirportCodeCache=new Hash(),this.destinationByIdCache=new Hash(),data=$H(data);this.name=country_name;data.each(function(destination,name){var search_destination=new SearchDestination(name,destination,lookup);if(search_destination.isValid()){this.destinations.push(search_destination);}
else{}},this);},findDestinationByIndex:function(index){return this.destinations[index];},findDestinationByName:function(name){var destination=this.destinationByNameCache.get(name);if(destination==null){for(var i=0;i<this.destinations.length;i++){if(this.destinations[i].name==name){destination=this.destinations[i];this.destinationByNameCache.set(name,destination);break;}}}
return destination;},findDestinationByAirportCode:function(airport_code){airport_code=airport_code.toUpperCase();var destination=this.destinationByAirportCodeCache.get(airport_code);if(destination==null){for(var i=0;i<this.destinations.length;i++){if(this.destinations[i].airportCode==airport_code){destination=this.destinations[i];this.destinationByAirportCodeCache.set(airport_code,destination);break;}}}
return destination;},findDestinationById:function(id){var destination=this.destinationByIdCache.get(id);if(destination==null){for(var i=0;i<this.destinations.length;i++){if(this.destinations[i].id==id){destination=this.destinations[i];this.destinationByIdCache.set(id,destination);}}}
return destination;},isValid:function(){return this.destinations.length>0;}});var SearchDestination=new Class({name:"",airportCode:"",departures:[],resortCode:"",locationCode:"",id:"",resorts:[],initialize:function(name,data,lookup){this.name=name;this.resorts=[];this.departures=[];this.airportCode=(data.airportCode||data.ac||"").toUpperCase();this.hydrateDepartures(data.deps,lookup);this.hydrateResorts(data.resorts,lookup);this.resortCode=(data.resortCode||data.rc||"").toUpperCase();this.locationCode=(data.locationCode||data.lc||"").toUpperCase();this.id=this.airportCode+":"+this.locationCode+":"+this.resortCode;},isValid:function(){return this.departures.length>0;},findDepartureByIndex:function(index){return this.departures[index];},getResortByCode:function(code){var resort=null;for(var i=0;i<this.resorts.length;i++){if(this.resorts[i].resortCode==code){resort=this.resorts[i];break;}}
return resort;},findDepartureByAirportCode:function(airport_code){airport_code=airport_code.toUpperCase();var departure=null;for(var i=0;i<this.departures.length;i++){if(this.departures[i].airportCode==airport_code){departure=this.departures[i];break;}}
return departure;},hydrateDepartures:function(departures,lookup){departures=$A(departures);departures.each(function(dep){var departure=new SearchDeparture(dep,lookup);if(departure.isValid()){this.departures.push(departure);}
else{}},this);},hydrateResorts:function(resorts,lookup){resorts=$H(resorts);resorts.each(function(res,name){var resort=new SearchResort(res,name,lookup);this.resorts.push(resort);},this);}});var SearchHydration=new Class({hydrateDate:function(datePair){var startDate=new Date();var endDate=new Date();var month_year=this.cleanMonthYearString(datePair[0]);startDate.setDate(1);startDate.setYear(month_year.year);startDate.setMonth(month_year.month-1);startDate.setHours(0);startDate.setMinutes(0);startDate.setSeconds(0);startDate.setMilliseconds(0);month_year=this.cleanMonthYearString(datePair[1]);endDate.setDate(1);endDate.setYear(month_year.year);endDate.setMonth(month_year.month);endDate.setDate(0);endDate.setHours(23);endDate.setMinutes(59);endDate.setSeconds(59);endDate.setMilliseconds(999);return[startDate,endDate];},cleanMonthYearString:function(dateStr){var month_year=dateStr.trim().split(" ");month_year.map(function(date){return parseInt(date.trim(),10);});month_year.erase("");return{month:month_year[0],year:month_year[1]};},hydrateDates:function(dates,lookup){var rtnVal=[];if(dates!=null)
{var datesRtn=[];var dateIndex=0;for(dateIndex=0;dateIndex<=dates.length-1;dateIndex++)
{var datePair=lookup[dates[dateIndex]];rtnVal.push(datePair);}}
return rtnVal;}});var SearchDeparture=new Class({Implements:[SearchHydration],airportCode:"",dates:[],initialize:function(data,lookup){this.dates=[];if($chk(data)){data.dates=data.d||data.dates;this.airportCode=(data.airportCode||data.ac).toUpperCase();this.dates=this.hydrateDates(data.dates,lookup).clean();}},isValid:function(){return this.dates.length>0;}});var SearchResort=new Class({Implements:[SearchHydration],resortName:"",resortCode:null,dates:[],initialize:function(data,name,lookup){this.dates=[];if($chk(data)){data.dates=data.d||data.dates;this.resortName=name;this.resortCode=(data.resortCode||data.rc);this.dates=this.hydrateDates(data.dates,lookup).clean();}},hasDates:function(){return this.dates.length>0;}});
