var airportClone=null;var countryClone=null;var airlineClone=null;var countryClone2=null;
function initCovid19Travel(resourceUrlForAutoPopulate){initTravelDropdowns();initTravelAutocompletes();initTravelButtons();initTravelSegments();initScrollToTopButton();initAddTransferButton();window.history.replaceState(null,null,location.href.split("?")[0]);var disabled=handleTravelSubmitButton(true);if(!disabled&&$(".captcha-container").hasClass("hide")){$("#travelExpSubmit").attr("disabled",true);$("#travelExpSubmit").parent().addClass("hide travelExpSubmithide");processSuccessfulTravelInfoResponse($("#travelInfoExpResponse1"),
1,""==$("#txfAirport").val()?true:false)}setTimeout(function(){if(!disabled&&!$(".captcha-container").hasClass("hide"))$("#captchaDiv").addClass("focus");$("#airlineDropdown1SelectBoxItText").attr("tabindex",4);$("#airlineDropdown2SelectBoxItText").attr("tabindex",5)},500);if(""!=$("#airlineDropdown2").val()&&""==$("#transferAirport").val())setTimeout(function(){$("#transferAirport").focus()},500);$(window).on("resize",function(){$(".allTravelContent label").removeAttr("style");equalHeight($(".allTravelContent label"))})}
function initTravelDropdowns(){$(".airlineDropdown").on("change",function(){var id=$(this).attr("id");handleTravelSubmitButton(false);if(id=="airlineDropdown2"&&""==$("#transferAirport").val())setTimeout(function(){$("#transferAirport").focus()},500)})}
function initTravelAutocompletes(){var airportOptions=[];$("#airportDropdown option").each(function(){airportOptions.push($(this).text())});$("#covid19TravelExpForm .autopopulate-input").each(function(){var $this=$(this);$(this).autocomplete({source:function(request,response){$(this).parent("p").removeClass("error");$(this).removeClass("inputDataLoading1");var toSearch=request.term.toLowerCase();var options=[];$.each(airportOptions,function(index,value){if(value.toLowerCase().indexOf(toSearch)>=0)options.push(value)});
if(options.length>0)$(".autopopulate-input").each(function(){var val=$(this).val();if(val!=request.term){var index=options.indexOf(val);if(index>-1)options.splice(index,1)}});if(options.length==0){opt={label:$("#saAutoCompleteError").val(),value:null};options.push(opt)}response(options)},select:function(event,ui){event.preventDefault();var itineraryName=null;var label=ui.item.label;var value=ui.item.value;if(value==null)$(this).val("");else $(this).val(label);var match=label.match(/\[(.*?)\]/);if(null!=
match){var option=$("#airportDropdown").children("option[value^\x3d'"+match[1]+"_']");var info=option.attr("value").split("_");var countryCodes=info[1].split(",");$(this).siblings(".hiddenCountry").val(countryCodes[0]);$(this).siblings(".hiddenCountryA3").val(countryCodes[1]);$(this).siblings(".hiddenAirport").val(info[0])}handleTravelSubmitButton(false)},change:function(event,ui){if(ui.item==null){$(this).val(ui.item?ui.item.label:"");$(this).siblings(".hiddenCountry").val("");$(this).siblings(".hiddenCountryA3").val("");
$(this).siblings(".hiddenAirport").val("");handleTravelSubmitButton(false)}},minLength:2,selectFirst:true,appendTo:"#"+$(this).parent("p").attr("id"),autoFocus:false})})}
function initTravelButtons(){$(".travelInfoReset button:first").on("click",function(){$(".formExplainer").show();$(".formContainer").toggleClass("col-sm-8 col-sm-12");$(".addTransfer").show();$("#validationDest").parent().insertBefore($(".col-sm-3.segment.segment1.segment2"));$("#validationAirline2").parent().insertBefore($(".col-sm-3.segment.segment1.segment2"));$(".allTravelContent label").removeAttr("style");$("#travelExpSubmit").parent().removeClass("hide");$(".addthis_inline_share_toolbox").addClass("hide");
$(".segment").show();$(".autopopulate-input").attr("disabled",false);$("#airlineDropdown1").data("selectBox-selectBoxIt").enable();$("#airlineDropdown2").data("selectBox-selectBoxIt").enable();$("#travelExpSubmit").attr("data-segment","");$("#travelExpSubmit").attr("data-clear","true");$(".col-sm-3.segment").toggleClass("col-sm-6 col-sm-3");$(".page-dark-section").removeClass("scroll-fix").removeAttr("style").removeClass("dropShadow");$(".scroll-fix-shadow").remove();$("#phaseContainer,[id^\x3dtravelInfoExpResponse]").addClass("hide");
$(".scrollTop").hide();$(window).off("scroll",scrollToTopButtonHandler);scrollToFormTop($(".page-dark-section"))});$("#travelExpSubmit").on("click",function(){var clear=$(this).attr("data-clear");if("true"==clear){airportClone=null;countryClone=null;airlineClone=null;countryClone2=null;$(".scrollTop").hide();$(window).off("scroll",scrollToTopButtonHandler);$("#travelInfoExpResponse1, #travelInfoExpResponse2").children().remove();$("#phaseContainer p.animExplainer").addClass("hide");$("#phaseContainer").addClass("hide");
$("#phaseContainer .travelAnimation").removeClass("exLarge doubleLeg");$("#phaseContainer .travelAnimation li").removeClass("active hide")}var segment=$(this).attr("data-segment");var captchaContainer=$(".captcha-container").css("display");$(".validationError").hide();$(".validationError2").hide();var ori=$("#oriAirport").val();var airline1=$("#airlineDropdown1").val();var txf=$("#txfAirport").val();var airline2=$("#airlineDropdown2").val();var dest=$("#destAirport").val();var currentChose=ori+"#"+
airline1+"#"+txf+"#"+airline2+"#"+dest;if(""!=ori&&""!=dest){var captchaText=$("input[id$\x3d'captchaText']").val();if("none"!=captchaContainer&&(undefined==captchaText||captchaText=="")&&(typeof grecaptcha=="undefined"||grecaptcha.getResponse()=="")){$("#captchaDiv, .captchaError").addClass("error");$(".captchaError").children(".validationError").show()}else{var singlesegment=""==txf?true:false;$("#chosenAA").val(currentChose);if(""==segment)segment=1;$("#travelExpSubmit").attr("disabled",true);
$(".captcha-container").addClass("hide");$("#travelExpSubmit").parent().addClass("hide travelExpSubmithide");showPageLoader();getTravelResponse(parseInt(segment),true,singlesegment)}}})}
function handleTravelSubmitButton(setCurrentChose){var ori=$("#oriAirport").val();var airline1=$("#airlineDropdown1").val();var txf=$("#txfAirport").val();var airline2=$("#airlineDropdown2").val();var dest=$("#destAirport").val();var chosenAA=$("#chosenAA").val();var currentChose=ori+"#"+airline1+"#"+txf+"#"+airline2+"#"+dest;var disabled=false;if(currentChose.match(/^[a-zA-Z]{3}#.*#.*#.*#[a-zA-Z]{3}$/g)&&chosenAA!=currentChose)$("#travelExpSubmit").attr("disabled",false);else{disabled=true;$("#travelExpSubmit").attr("disabled",
true)}if(!disabled&&""!=airline2&&""==txf){$("#travelExpSubmit").attr("disabled",true);disabled=true}if(setCurrentChose)$("#chosenAA").val(currentChose);return disabled}
function getTravelResponse(segment,empty,singlesegment){if(!empty){$("#airlineDropdown1").data("selectBox-selectBoxIt").enable();$("#airlineDropdown2").data("selectBox-selectBoxIt").enable()}$.ajax({url:$("#covid19TravelExpForm").attr("action")+"\x26segment\x3d"+segment+"\x26single\x3d"+singlesegment+"\x26p_auth\x3d"+Liferay.authToken,method:"POST",data:$("#covid19TravelExpForm").serialize(),success:function(result,status,xhr){var captchaContainer=$(".captcha-container").css("display");$("#page-loader").hide();
if("none"!=captchaContainer){$("a[id$\x3d'refreshCaptcha']").trigger("click");grecaptcha.reset()}if(xhr.getResponseHeader("captchaError")=="true"){$("#captchaDiv, .captchaError").addClass("error");$(".captchaError").children(".validationError").show();$("#travelExpSubmit").attr("disabled",false);$("#travelExpSubmit").parent().addClass("travelExpSubmit").removeClass("hide travelExpSubmithide");$(".captcha-container").removeClass("hide")}else{var travelInfoResponse=$("#travelInfoExpResponse"+segment);
travelInfoResponse.html(result);processSuccessfulTravelInfoResponse(travelInfoResponse,segment,singlesegment)}},error:function(xhr,status,error){$("#page-loader").hide();$("a[id$\x3d'refreshCaptcha']").trigger("click");grecaptcha.reset()}})}
function processSuccessfulTravelInfoResponse(travelInfoResponse,segment,singlesegment){var ipError=$(".requestPerIpError").length;if(ipError==0){var ori=$("#oriAirport").val();var airline1=$("#airlineDropdown1").val();var txf=$("#txfAirport").val();var airline2=$("#airlineDropdown2").val();var dest=$("#destAirport").val();var oriCountry=$("#oriCountry").val();var destCountry=$("#destCountry").val();var txfCountry=$("#txfCountry").val();$(".scrollTop").show();$(window).on("scroll",scrollToTopButtonHandler);
travelInfoResponse.find(".h-card p").each(function(){var $this=$(this);var text=$this.contents().not($this.children(":not(a)")).text();if(""==text.trim())$this.remove()});if(travelInfoResponse.find("p.explainer").text().trim()=="")travelInfoResponse.find("p.explainer").remove();travelInfoResponse.find("div.detailedInfo").each(function(){var $this=$(this);var contentLen=$this.children(":not(strong)").length;if(contentLen==0)$this.remove()});if(!singlesegment){$("#phaseContainer .travelAnimation").addClass("doubleLeg").removeClass("exLarge");
$("#phaseContainer li:nth-child(2)").removeClass("hide")}else{$("#phaseContainer li:nth-child(2)").addClass("hide");$("#phaseContainer .travelAnimation").addClass("exLarge").removeClass("doubleLeg")}$(".formExplainer").hide();travelInfoResponse.siblings(".pageText").addClass("hide");$("#phaseContainer li:nth-child(1) span.airportCode").text(ori);$("#phaseContainer li:nth-child(2) span.airportCode").text(txf);$("#phaseContainer li:nth-child(3) span.airportCode").text(dest);$(".col-sm-6.segment").toggleClass("col-sm-3 col-sm-6");
$(".addTransfer").hide();if(1==segment){$(".formContainer").toggleClass("col-sm-12 col-sm-8");$("#phaseContainer").removeClass("hide");equalHeight($(".allTravelContent label"));var shareLink=$(".shareLink").attr("data-href");var currentURL=location.href.split("?")[0];currentURL+="?ori\x3d"+ori+"\x26dest\x3d"+dest+(""!=txf?"\x26txf\x3d"+txf:"")+(""!=airline1?"\x26airline1\x3d"+airline1:"")+(""!=airline2?"\x26airline2\x3d"+airline2:"");shareLink=shareLink.replace("$CURRENT$",encodeURIComponent(currentURL+
" "));$(".shareLink").attr("href",shareLink);$(".addthis_inline_share_toolbox").attr("data-url",currentURL);$("meta[property\x3d'og\\:url']").attr("content",currentURL);addthis_share.url=currentURL;$(".segment2.segment").not(".segment1").hide();$(".segment1.segment").not(".segment2").show();$("#phaseContainer li:nth-child(1)").addClass("active");if(singlesegment){$(".segment1.segment2.segment").hide();$(".segment2.segment").first().show();$("span.airportCode").addClass("active")}else{$("span.airportCode:last").removeClass("active");
$("span.airportCode").not(":last").addClass("active");$("#phaseContainer p.animExplainer").removeClass("hide");airportClone=$("#airport1").clone().prop("id","airport2").toggleClass("airportAndAirline2 airportAndAirline1");if(""!=airline1&&airline1==airline2)airlineClone=$("#airportAndAirline1").find("#airlineCovidInfo").clone();if(txfCountry!=oriCountry)countryClone=$("#destCountry1").clone().prop("id","oriCountry2").toggleClass("country2 country1");else countryClone=$("#oriCountry1").clone().prop("id",
"oriCountry2").toggleClass("country2 country1")}}else if(2==segment){$(".segment1.segment").not(".segment2").hide();$("#validationDest").parent().insertAfter($(".col-sm-3.segment.segment1.segment2"));$("#validationAirline2").parent().insertAfter($(".col-sm-3.segment.segment1.segment2"));$(".segment2.segment").not(".segment1").show();travelInfoResponse.prepend(airportClone);travelInfoResponse.prepend(countryClone);if(null!=countryClone2)travelInfoResponse.append(countryClone2);if(null!=airlineClone)$("#airportAndAirline2").find(".covidInfoPanel").prepend(airlineClone);
$(".segment1.segment").not(".segment2").hide()}if(travelInfoResponse.find(".covidInfoHeadCard").length>0)pushDataToAnalytics(segment,singlesegment,ori,airline1,txf,airline2,dest);if($(window).width()>=768)scrollToFormTop($(".page-dark-section"));processCountryResponse($("#lastUpdatedLabel").val(),segment);processTravelResponse(segment);var header=travelInfoResponse.find(".countryCovidInfo .covidInfoHeadCard");if(header.length>0)header.next().hide();$(".autopopulate-input").attr("disabled",true);$("#airlineDropdown1").selectBoxIt().data("selectBox-selectBoxIt").disable();
$("#airlineDropdown2").selectBoxIt().data("selectBox-selectBoxIt").disable();if(segment==1){$(".page-dark-section").addClass("scroll-fix");bindScrollFix()}$(".content.omImage").each(function(){var dataImg=$(this).attr("data-img");if(""!=dataImg)$(this).prev(".media.othermeasure").children("img").attr("src",dataImg)});appendMailShareToAddThis()}travelInfoResponse.removeClass("hide")}
function addThisShareHandler(evt){var ori=$("#oriAirport").val();var airline1=$("#airlineDropdown1").val();var txf=$("#txfAirport").val();var airline2=$("#airlineDropdown2").val();var dest=$("#destAirport").val();var label="";if(""!=ori)label+="origin:"+ori;if(""!=airline1)label+=",airline1:"+airline1;if(""!=txf)label+=",transfer:"+txf;if(""!=airline2)label+=",airline2:"+airline2;if(""!=dest)label+=",destination:"+dest;pushEventInDataLayer("Covid 19","Travel Hub Information",evt.data.service,label,
"")}
function appendMailShareToAddThis(){var aMS=setInterval(appendPolling,100);var counter=0;function appendPolling(){counter++;var addThisElements=$(".at-share-btn-elements");if(addThisElements.length>0){$(".shareLink").removeClass("hide");$(".shareLink").prependTo(addThisElements);$(".addthis_inline_share_toolbox").removeClass("hide");addthis.addEventListener("addthis.menu.share",addThisShareHandler);clearInterval(aMS)}else if(counter>50){$(".shareLink").removeClass("hide");clearInterval(aMS)}}}
function pushDataToAnalytics(segment,singlesegment,ori,airline1,txf,airline2,dest){var label="";if(""!=ori)label+="origin:"+ori;if(""!=airline1)label+=",airline1:"+airline1;if(""!=txf)label+=",transfer:"+txf;if(""!=airline2)label+=",airline2:"+airline2;if(""!=dest)label+=",destination:"+dest;if(1==segment)pushEventInDataLayer("Covid 19","Travel Hub Information",singlesegment?"Journey without Transfer":"Journey with Transfer",label,"");else pushEventInDataLayer("Covid 19","Travel Hub Information",
"Second Segment Seen",label,"")}
function initTravelSegments(){$(".travelAnimation li span.airportCode").click(function(event){event.stopPropagation()});$(".travelAnimation li:not(:last-child)").click(function(){var elem=$(this);if(elem.hasClass("active"))return;else{elem.siblings().removeClass("active");elem.addClass("active");var singlesegment=""==$("#txfAirport").val()?true:false;var segment=parseInt(elem.attr("data-segment"));var segment1Container=$("#travelInfoExpResponse1");var segment2Container=$("#travelInfoExpResponse2");
if(1==segment&&segment1Container.hasClass("hide")){segment1Container.siblings(".pageText").addClass("hide");segment1Container.removeClass("hide");$("#travelExpSubmit").attr("data-segment",1);$(".segment2.segment").not(".segment1").hide();$(".segment1.segment").not(".segment2").show();if(singlesegment){$(".segment1.segment2.segment").hide();$(".segment2.segment").first().show()}else{$("span.airportCode:last").removeClass("active");$("span.airportCode").not(":last").addClass("active")}}if(2==segment&&
segment2Container.hasClass("hide")){if(segment2Container.children().length==0){showPageLoader();getTravelResponse(segment,false,false)}else{segment2Container.siblings(".pageText").addClass("hide");segment2Container.removeClass("hide");$(".segment1.segment").not(".segment2").hide();$(".segment2.segment").not(".segment1").show()}$("span.airportCode:first").removeClass("active");$("span.airportCode").not(":first").addClass("active");$("#travelExpSubmit").attr("data-segment",2)}}})}
function processTravelResponse(segment){var covidInfoHead=$('div[class^\x3d"airportAndAirline"] .covidInfoHeadCard');var container=$(".airportAndAirline"+segment);var completeContainer=$("#travelInfoExpResponse"+segment);var lastUpdateDate=container.find(".lastUpdateDate");if(null!=segment){covidInfoHead=completeContainer.find("div[class^\x3d'airportAndAirline'] .covidInfoHeadCard");lastUpdateDate=container.find(".lastUpdateDate")}else segment="";if(covidInfoHead.length>1)covidInfoHead.click(function(e){$(this).toggleClass("expanded");
$(this).next().toggle()});lastUpdateDate.each(function(){var dateElement=$(this);var processed=dateElement.attr("data-processed");if("1"!=processed){var dateS=dateElement.attr("data-date");if(""!=dateS){var date=new Date(dateS);var text="";var time="";if(isNaN(date)==false){if(dateS.indexOf("T")>-1)time=dateS.split("T").pop();text=$.datepicker.formatDate(" M d, yy ",date)+time}else text=dateS;dateElement.children("p").append(text)}else dateElement.hide();dateElement.attr("data-processed","1")}})}
function processCountryResponse(lastUpdatedLabel,segment){var container=$(".country"+segment);var segmentHead=$(".statusInfo");var dateUpdtdFld=$(".dateUpdtdFld");if(null!=segment){segmentHead=container.find(".covidInfoHeadCard");dateUpdtdFld=container.find(".dateUpdtdFld")}segmentHead.click(function(e){$(this).toggleClass("expanded");$(this).next().toggle()});dateUpdtdFld.each(function(){var $this=$(this);var processed=$this.attr("data-processed");if("1"!=processed){var text=$this.text();if(""!=
text){var date=new Date(text);var time="";if(isNaN(date)==false){if(text.indexOf("T")>-1)time=text.split("T").pop().substr(0,5);text=$.datepicker.formatDate(" M d, yy ",date)+time}$(this).text(lastUpdatedLabel+text)}else $this.hide();$this.attr("data-processed","1")}})}var usabillaTry=0;
function initScrollToTopButton(){var scrollTopButton=$(".scrollTop");if($(".control-menu").length>0)controlMenuHeight=$(".control-menu").height();setTimeout(function(){setScrollToTopButtonPosition(scrollTopButton)},1E3);$(".scrollTop").on("click",function(){scrollToFormTop($(".allTravelContent"))})}
function setScrollToTopButtonPosition(scrollTopButton){var usabillaButton=$(".usabilla_live_button_container");if(usabillaButton.length>0){var height=$(".usabilla_live_button_container").css("height");if(height.indexOf("130")<0)scrollTopButton.addClass("rightPos")}else if(usabillaTry<4){usabillaTry++;setTimeout(function(){setScrollToTopButtonPosition(scrollTopButton)},250)}}
function scrollToTopButtonHandler(){var scrollPos=$(window).scrollTop();var targetDivPos=$("#phaseContainer").position().top;scrollPos>=targetDivPos?$(".scrollTop").show():$(".scrollTop").hide()}function initAddTransferButton(){$(".addTransfer").on("click",function(){$(".col-sm-6.segment.hide").removeClass("hide");$(".row.transfer").removeClass("transfer");$(".addthis_inline_share_toolbox.transfer").removeClass("transfer");$(this).remove()})}
function initCovid19FTB(){emptyFormFields($("#covid19TravelExpForm"));$("#cOriginCountry,#cDestinationCountry").on("change",function(){var val=$(this).val();var sibling=$($(this).attr("data-sibling"));sibling.children("option[disabled]").prop("disabled",false);if(""!=val)sibling.children("option[value\x3d'"+val+"']").prop("disabled",true);sibling.selectBoxIt().selectBoxIt("refresh");if(""!=$("#cOriginCountry").val())$("#travelExpSubmit").prop("disabled",false);else $("#travelExpSubmit").prop("disabled",
true)});var targetURL=$("#travelHubContainer").attr("data-url");if(undefined!==targetURL)$("#covid19TravelExpForm").attr("action",targetURL);$("#travelExpSubmit").on("click",function(){var cOrigin=$("#cOriginCountry").val();var cDestination=$("#cDestinationCountry").val();var label="";if(""!=cOrigin)label+="origin:"+cOrigin;if(""!=cDestination)label+=",destination:"+cDestination;pushEventInDataLayer("Covid 19","Travel Hub Information","Flight Tool Bar",label,"");$("#covid19TravelExpForm").submit()})}
;
