function setupValidation(n,t){country=$.trim(t.split(",")[0]),returnIata=$.trim(t.match(/\[(.*?)\]/)[1]),resort=$.trim(t.split(",")[2]),$('.destCountry_select[data-sid="'+n.attr("data-sid")+'"]').val(country),$('.destination_select[data-sid="'+n.attr("data-sid")+'"]').val(returnIata),$('.resort_select[data-sid="'+n.attr("data-sid")+'"]').val(resort),autoCompleteSelection["sid"+n.attr("data-sid")]=t}function toggleOneWayCheckBox(){oneWaySelector.is(":checked")?flightReturnSelector.animate({height:"0"},200,function(){$(this).css("display","none")}):flightReturnSelector.css({height:"0",display:"block"}).animate({height:animHeight},200)}function sb_validate(n){if(autoCompleteSelection["sid"+n]!=$('.autocomplete[data-sid="'+n+'"]').val())return $(".destCountry_select[data-sid= "+n+"]").parents("form").find(".sb_validation_error").slideDown(),!1}function magicalSearchBox(){$("input.DepDate").change(function(){DepDate(this)}),$(".howmany").change(function(){howmany(this)}),$(".DepPoint").change(function(){DepPoint(this)}),$(".btn-sb-more-options").click(function(){MoreOptions(this)})}function destination_select(n){$(n).parents("form").find("p.resort_depart").css("display")=="none"&&$(n).parents("form").find("p.resort_depart").css({height:"0",display:"block"}).animate({height:animHeight},200)}function DepDate(n){$(n).parents("form").find("p.flex_duration").css("display")=="none"&&$(n).parents("form").find("p.flex_duration").css({height:"0",display:"block"}).animate({height:animHeight},200)}function howmany(n){$(n).parents("form").find("p.numberofrooms, p.more_options").css("display")=="none"&&$(n).parents("form").find("p.numberofrooms, p.more_options").css({height:"0",display:"block"}).animate({height:animHeight},200)}function DepPoint(n){$(n).parents("form").find("p.numberofrooms, p.more_options").css("display")=="none"&&$(n).parents("form").find("p.numberofrooms, p.more_options").css({height:"0",display:"block"}).animate({height:animHeight},200),$(n).parents("form").find(".btn-sb-more-options").remove()}function flightsReturn(n){$(n).parents("form").find(".flights_returning").css("display")=="none"&&$(n).parents("form").find(".flights_returning").css({height:"0",display:"block"}).animate({height:animHeight},200)}function MoreOptions(n){destination_select(n),DepDate(n),oneWaySelector.is(":checked")||flightsReturn(n),howmany(n),DepPoint(n),$(n).remove()}var country,returnIata,resort,autoCompleteSelection={},sbTabInvalid={},animHeight,oneWaySelector,flightReturnSelector,autoComplete;$(document).ready(function(){var n=$("#search-box").attr("data-startdate"),t=$(".departing_when");animHeight=t.css("height")=="0px"?"28px":t.css("height"),$(".datepicker").datepicker({dateFormat:"DD, d M, yy",numberOfMonths:2,minDate:n,changeMonth:!0,changeYear:!0,showAnim:"fadeIn",beforeShow:function(){setTimeout(function(){$("#content").hasClass("sectional")?$(".ui-datepicker").addClass($("#content").attr("class").substring(10)).css("z-index",100):$(".ui-datepicker").addClass("holidays").css("z-index",100)},0)}}),$(".datepicker").focus(function(){$(this).blur()}),$("#flight_depDate").datepicker({dateFormat:"DD, d M, yy",numberOfMonths:2,minDate:n,changeMonth:!0,changeYear:!0,showAnim:"fadeIn",onClose:function(n){$("#RetDate").datepicker("option","minDate",n)},beforeShow:function(){setTimeout(function(){$("#content").hasClass("sectional")?$(".ui-datepicker").addClass($("#content").attr("class").substring(10)).css("z-index",100):$(".ui-datepicker").addClass("holidays").css("z-index",100)},0)}}),$("#flight_depDate").focus(function(){$(this).blur()}),$("#RetDate").datepicker({dateFormat:"DD, d M, yy",numberOfMonths:2,minDate:n,changeMonth:!0,changeYear:!0,showAnim:"fadeIn",onClose:function(n){$("#flight_depDate").datepicker("option","maxDate",n)},beforeShow:function(){setTimeout(function(){$("#content").hasClass("sectional")?$(".ui-datepicker").addClass($("#content").attr("class").substring(10)).css("z-index",100):$(".ui-datepicker").addClass("holidays").css("z-index",100)},0)}}),$("#RetDate").focus(function(){$(this).blur()}),oneWaySelector=$("#OneWay"),flightReturnSelector=$(".flights_returning"),oneWaySelector.click(toggleOneWayCheckBox),toggleOneWayCheckBox(),autoComplete=$(".autocomplete"),autoComplete.each(function(){var n=$(this).attr("data-sid");$(this).autocomplete({source:"/Search/Services/Destinations",change:function(n,t){$(".dd-arrow").hide(),$(this).removeClass("autocomplete-focus autocomplete-open"),t.item!=null&&setupValidation($(this),t.item.value),$(this).val().length>0?autoLabel.hide():autoLabel.show()},select:function(t,i){$(".dd-arrow").hide(),$(this).removeClass("autocomplete-focus autocomplete-open"),autoLabel.hide(),setupValidation($(this),i.item.value),destination_select(this,n),DepDate(this)},open:function(){$(this).addClass("autocomplete-open"),$(".dd-arrow").show()},minLength:3,delay:500}).click(function(){defaultSBValue=!1,autoLabel=$(this).prev(),autoLabel.fadeTo(100,.7),$(".sb_validation_error").length>0&&$(".sb_validation_error").hide(),$(this).val(""),$(this).addClass("autocomplete-focus autocomplete-open")}).keypress(function(){autoLabel.hide(),$(this).removeClass("autocomplete-focus")}).blur(function(){$(this).val().length==0&&(autoLabel.show(),autoLabel.fadeTo(100,1),$(this).removeClass("autocomplete-focus autocomplete-open"))})}),$(".auto-label").click(function(){$(this).next().focus().click()}),autoComplete.each(function(){$(this).val().length>0?(autoCompleteSelection["sid"+$(this).attr("data-sid")]=$(this).val(),destination_select(this)):$(this).prev().show()}),magicalSearchBox()}),$(document).ready(function(){$("#search-box .tabs li").click(function(){$(this).hasClass("active")||($("#search-box .tabs li").removeClass("active"),$(this).addClass("active"),$(".search-form form").stop(!0,!1).fadeTo(100,0,function(){$(this).stop(!0,!1).fadeTo(100,1)}))})}),$(document).ready(function(){function u(){$("#colorbox").length>0&&$.colorbox.resize()}function f(t){for($(".numChild").each(function(){if($(this).val()!=0){$(this).parents("form").find("fieldset.child-ages").slideDown(n);return}}),i=$(".rooms .room").length;i>t.val();)$(".rooms .room.num-"+i+"").slideUp(n),$(".child.num-"+i+"").slideUp(n),i--;t.val()>1?$(".rooms .room.num-1 .how-many-label span").text("room 1"):$(".rooms .room.num-1 .how-many-label span").text("how many");for(var i=0;i<=t.val();i++)$(".rooms .room.num-"+i).slideDown(n),$(".child-ages .child.num-"+i+" select").css("display")=="inline-block"|$(".child-ages .child.num-"+i+" select").css("display")=="inline"&&$(".child-ages .child.num-"+i+"").css("display","block");setTimeout(u,n)}var n=200,r,t;for($("fieldset.child select:last-child").addClass("last"),$(".child-ages .child").css("display","none"),$(".numRooms").change(function(){f($(this))}),numberOfRooms=$(".numRooms").val();numberOfRooms>1;)typeof r=="undefined"&&$(".rooms .room.num-1 .how-many-label span").text("room 1"),$(".room.num-"+numberOfRooms).show(),r=!0,numberOfRooms--;$(".numChild").change(function(){if(t=$(this).parents(".room").attr("class").substring(5),$(this).val()>0)for($(".child-ages .child."+t+" .child").css("display","none"),$(this).parents("form").find("fieldset.child-ages").slideDown(n),$(".child-ages .child."+t+"").slideDown(n),i=0;i<=$(this).val();i++)$(".child-ages .child."+t+" .child.age-"+i+"").css("display","inline");else $(".child-ages .child."+t+", .child-ages .child."+t+" .child").slideUp(n);setTimeout(u,n)}),$(".DepPoint.num-1 select").after('Add another departure'),$(".DepPoint.num-2 select, .DepPoint.num-3 select").after('minus departure'),$(".depart-plus").click(function(){$(".DepPoint.num-1").next().css("display")=="block"?$(".DepPoint.num-1").next().next().css("display","block"):$(".DepPoint.num-1").next().css("display","block"),$(".depart-minus").click(function(){$(this).parent().css("display","none")})})})