var clearFocus=true;var IsBanIP=false;var isValidFlightSearch;var isValidDateForAirfare;var oFrm=new Object();oFrm.pWin=null;oFrm.DD1="#txtDepartureDate11";oFrm.DD2="#txtDepartureDate21";oFrm.RD2="#txtReturnDate21";oFrm.DF1="#txtDepartureFrom11";oFrm.DF2="#txtDepartureFrom21";oFrm.TT1="#txtTravelingTo11";oFrm.TT2="#txtTravelingTo21";oFrm.hs_ClickID="";oFrm.CTextVal="";oFrm.IsSelect=false;oFrm.ValidateID="";oFrm.VHandle=null;oFrm.eMsg=[];oFrm.eMsg.E0010="Please enter a valid city or 3 letter airport code where you are departing from. Do not enter a state or country";oFrm.eMsg.E0011="Please enter a valid city or 3 letter airport code where you are traveling to. Do not enter a state or country";oFrm.eMsg.E0020="Departure and destination airport must not be the same airport code";oFrm.LoadingImg=$("<img>").attr("src",oCFS.RootPath+"images/ajax_load.gif").attr("class","imgWait");oFrm.nextDay=1;function ShowErrorMsg(){$("#bLogo").block({message:$("#errors_div"),css:{width:"450px",cursor:"auto"},overlayCSS:{backgroundColor:"#FFF",opacity:0.4},centerY:true})}function HideErrorMsg(){$("#bLogo").unblock()}function AddErrorMsg(b){var a=$(document.createElement("li")).addClass("item").html(b);$("#errors_div ul li.text").before(a)}function ClearError(){$("#errors_div ul li.item").remove()}$(document).ready(function(){if(jQuery.blockUI){if(oCFS.IsError){ShowErrorMsg()}}var b=new Date();var c=new Date(b.getTime()+oFrm.nextDay*24*60*60*1000);var g=new Date(b.getTime()+(oFrm.nextDay+6)*24*60*60*1000);var e=c.getMonth()+1;var a=c.getDate();var f=$(oFrm.DD1).val();if(f==oCFS.DFDate){f=(e<10?"0"+e:e)+"/"+(a<10?"0"+a:a)+"/"+c.getFullYear()}e=g.getMonth()+1;a=g.getDate();var d=$(oFrm.RD2).val();if(d==oCFS.DFDate){d=(e<10?"0"+e:e)+"/"+(a<10?"0"+a:a)+"/"+g.getFullYear()}$(oFrm.DD1).datepicker({minDate:"0",hideIfNoPrevNext:true,duration:"fast",onSelect:function(h){HideErrorMsg()},changeMonth:true}).val(f);$(oFrm.DD2).datepicker({minDate:"0",onSelect:function(h){HideErrorMsg();DateSelect(oFrm.DD2,oFrm.RD2,h)},hideIfNoPrevNext:true,duration:"fast",changeMonth:true}).val(f);$(oFrm.RD2).datepicker({minDate:"+2",hideIfNoPrevNext:true,duration:"fast",onSelect:function(h){HideErrorMsg()},changeMonth:true}).val(d);$("input[name='triptype']").click(function(){ShowTripType()});SetAutoCompleteTextAir(oFrm.DF1);SetAutoCompleteTextAir(oFrm.DF2);SetAutoCompleteTextAir(oFrm.TT1);SetAutoCompleteTextAir(oFrm.TT2);SetFocusText(oFrm.DF1);SetFocusText(oFrm.DF2);SetFocusText(oFrm.TT1);SetFocusText(oFrm.TT2);$("#chkCreditLoc").attr("checked",$.cookie("uCredit")=="1"||$.cookie("uCredit")==null?true:false);$("#chkTile").attr("checked",$.cookie("uTile")=="1"||$.cookie("uTile")==null?true:false);if(!$("#chkCreditLoc").attr("checked")){$("#btnSearchAlt").hide()}CheckUser();$("#btnFlight,#btnSearchAlt").click(function(){ClearError();window.clearTimeout(oFrm.VHandle);$("div.sResultTop").html(oFrm.LoadingImg).append("Searching Flights..");var h=$("[name=triptype]:checked").val();if(ValidateFlight(h)){HideErrorMsg();$("#frmFlightSearch,#sResultCmd,#wGetMore,#wSpace").hide();$("#sResult").show();var i=getParamToValidate(h);DoSearch(h);$.ajax({type:"GET",url:oCFS.RootPath+"Widgets/Service/ValidateLocation.ashx",contentType:"application/json; charset=utf-8",data:i,dataType:"json",success:function(l){if(l.VALID){SearchManager(h)}else{if(oFrm.pWin!=null){oFrm.pWin.close()}var k=l.Errors;var j=k.split(",");$.each(j,function(m,n){AddErrorMsg(oFrm.eMsg[n])});ShowErrorMsg();isValidFlightSearch=false;BackToForm();FillForm(l)}},error:function(l,j,k){DoSearch()}});return false}else{ShowErrorMsg();isValidFlightSearch=false;return false}});$("#chkCreditLoc,#chkTile").click(function(){var h=$("#chkCreditLoc").attr("checked");var i=$("#chkTile").attr("checked");if(h){$("#btnSearchAlt").show()}else{$("#btnSearchAlt").hide()}$.cookie("uCredit",h?1:0);$.cookie("uTile",i?1:0)})});function DoSearch(c){isValidFlightSearch=true;var b;if(c=="2"){b=$(oFrm.DD2).val()}else{b=$(oFrm.DD1).val()}var e=b.substring(6,10);var f=b.substring(0,2);var d=b.substring(3,5);var g=new Date(e,f-1,d);var a=new Date();a.setDate(a.getDate()+oFrm.nextDay-1);isValidDateForAirfare=(g>=a);Pops()}function BackToForm(){$("#sResult,#sResultCmd").hide();$("#frmFlightSearch").show();if(!IsBanIP){$("#wGetMore").show()}$("#sResult div.sResultTop,#sResult div.sResultMiddle").html("")}function FillForm(b){var d=$("#frmFlightSearch");var a=$('input[value="'+b.TI+'"]',d);var c=$('input[value="'+b.FI+'"]',d);$(a).val(b.TR);$(c).val(b.FR);if(b.FR==""){$(c)[0].focus()}else{if(b.TR==""){$(a)[0].focus()}}}function DateSelect(b,a,e){$(b).removeClass("noDate");if(a!=""){$(a).removeClass("noDate")}var c=new Date($(b).datepicker("getDate"));var d=new Date($(b).datepicker("getDate"));c.setDate(c.getDate()+1);$(a).datepicker("option","minDate",c);d.setDate(d.getDate()+6);$(a).datepicker("setDate",d)}function ShowTripType(){if($("[name=triptype]:checked").val()=="2"){$("#ss2").show();$("#ss1").hide()}else{if($("[name=triptype]:checked").val()=="1"){$("#ss1").show();$("#ss2").hide()}}}function SetFocusText(a){$(a).focus(function(){window.clearTimeout(oFrm.VHandle);oFrm.CTextVal=$(this).val();if(clearFocus&&!oFrm.IsSelect){$(this).val("")}clearFocus=true}).blur(function(){if($(this).val()==""){$(this).val(oFrm.CTextVal)}else{if($(this).val()!=oFrm.CTextVal&&!oFrm.IsSelect){oFrm.ValidateID=$(this);oFrm.VHandle=window.setTimeout("ValidateOne();",100)}else{HideErrorMsg()}}})}function ValidateOne(){var a=$(oFrm.ValidateID).val();var b="#"+$(oFrm.ValidateID).attr("ID");$.ajax({type:"GET",url:oCFS.RootPath+"Widgets/Service/ValidateLocation.ashx",contentType:"application/json; charset=utf-8",data:{cn:a},dataType:"json",success:function(d){ClearError();if(d.VALID){HideErrorMsg();$(b).val(d.RS)}else{var c=$(b).attr("ID");if(c.startsWith("txtDeparture")){AddErrorMsg(oFrm.eMsg.E0010)}else{AddErrorMsg(oFrm.eMsg.E0011)}$(b).val("").focus();ShowErrorMsg()}},error:function(e,c,d){}})}function SetAutoCompleteTextAir(id){var termTemplate="<span class='ui-autocomplete-term'>%s</span>";$(id).autocomplete({minLength:3,source:function(request,response){$.ajax({url:"/Widgets/Travel/MultiSearch/SearchAirports.ashx",dataType:"application/json",data:{limit:30,q:request.term,Country:"",State:"",City:""},success:function(data){data=eval(data);response($.map(data,function(item){var ShowText=item.City;if(item.State!=""){ShowText=ShowText+", "+item.State}if(item.Country!=""){ShowText=ShowText+", "+item.Country}ShowText=ShowText+" - ("+item.AirportCode+") "+item.AirportName;return{label:ShowText,value:ShowText}}))},error:function(XMLHttpRequest,textStatus,errorThrown){if(oCFS.IsDebug){alert(textStatus)}}})},open:function(e,ui){var acData=$(this).data("autocomplete");var styledTerm=termTemplate.replace("%s",acData.term);acData.menu.element.find("li").each(function(index,value){var me=$("a",this);me.html(me.text().replace(acData.term,styledTerm));if((index%2)==1){$(this).addClass("alt")}})},select:function(event,ui){var ShowText=ui.item.value;$(id).val(ShowText);clearFocus=false;oFrm.IsSelect=true;oFrm.CTextVal=ShowText;window.setTimeout("oFrm.IsSelect = false;",100)}}).data("autocomplete")._renderItem=function(ul,item){return $("<li></li>").data("item.autocomplete",item).append("<a>"+item.label+"</a>").appendTo(ul)}}function ValidateFlight(b){if(b=="2"){if(!checkLegValueFrom(oFrm.DF2,"")){return false}if(!checkLegValueTo(oFrm.TT2,"")){return false}if($(oFrm.DF2).val()==$(oFrm.TT2).val()){AddErrorMsg("Departure and destination airport must not be the same airport code");$(oFrm.TT2).focus();return false}if(!validateDate($(oFrm.DD2).get(0))){return false}if(!validateDate($(oFrm.RD2).get(0))){return false}if(!DataCompare($(oFrm.DD2).val(),$(oFrm.RD2).val())){AddErrorMsg("Your return date must be after your departure date.");return false}}else{if(!checkLegValueFrom(oFrm.DF1,"")){return false}if(!checkLegValueTo(oFrm.TT1,"")){return false}if($(oFrm.DF1).val()==$(oFrm.TT1).val()){AddErrorMsg("Departure and destination airport must not be the same airport code");$(oFrm.TT1).focus();return false}if(!validateDate($(oFrm.DD1).get(0))){return false}}if($("#slInfant").length>0){var d=parseInt($("#slInfant").val());var c=parseInt($("#slFlightAdult").val());var a=parseInt($("#slFlightChild").val());if(d>c){AddErrorMsg("Number of infant can't more than number of adult.");return false}else{if(c+a+d>9){AddErrorMsg("The number of passenger can't more than 9 persons.");return false}}}return true}function checkLegValueFrom(c,b){var a=jQuery.trim($(c).val());if((a=="")||(a==oCFS.TextDefault)||a.length<3){AddErrorMsg(b+"Please enter a valid city or 3 letter airport code where you are departing from. Do not enter a state or country");$(c).focus();$(c).select();return false}return true}function checkLegValueTo(c,b){var a=jQuery.trim($(c).val());if((a=="")||(a==oCFS.TextDefault)){AddErrorMsg(b+"Please enter a valid city or 3 letter airport code where you are traveling from. Do not enter a state or country");$(c).focus();$(c).select();return false}return true}function Pops(){if(!IsBanIP&&isValidFlightSearch&&isValidDateForAirfare&&$("#chkTile").attr("checked")&&$("#chkCreditLoc").attr("checked")){oFrm.pWin=window.open(oCFS.TilePopupURL+"?"+GetParamFlightTile($("[input[name=triptype]:checked").val())+"&back=0","pop","height=700,width=1050,resizable=yes,toolbar=yes,location=yes,menubar=yes,scrollbars=yes,left=50,top=50");try{oFrm.pWin.blur();var b=navigator.userAgent.toLowerCase();if(b.indexOf("chrome")!=-1){setTimeout(oFrm.pWin.blur,0)}}catch(a){}window.focus()}}function GetAirportCode(b){var a="";if(b.length>=3){posb=b.indexOf("(");pose=b.indexOf(")");if((posb>-1)&&(pose>-1)){a=b.substring(posb+1,pose)}else{a=b}}return a}function GetParamFlightTile(a){var c={Show:"1",cmd:"air",t:a,na:$("#slFlightAdult").val(),nc:$("#slFlightChild").val(),ni:$("#slInfant").val()};if(a=="2"){c.fn=GetAirportCode($(oFrm.DF2).val());c.tn=GetAirportCode($(oFrm.TT2).val());c.dd=$(oFrm.DD2).val();c.rd=$(oFrm.RD2).val()}else{if(a=="1"){c.fn=GetAirportCode($(oFrm.DF1).val());c.tn=GetAirportCode($(oFrm.TT1).val());c.dd=$(oFrm.DD1).val()}}var b=jQuery.param(c);return b}function getParamToValidate(a){var b={};if(a=="2"){b.fn=$(oFrm.DF2).val();b.tn=$(oFrm.TT2).val()}else{if(a=="1"){b.fn=$(oFrm.DF1).val();b.tn=$(oFrm.TT1).val()}}return b}function SetValueToHiddenField(){$("#hdAdult").val($("#slFlightAdult").val());$("#hdChild").val($("#slFlightChild").val());$("#hdInfant").val($("#slInfant").val());$("#hdClass").val($("#slClass").val());$("#hdCreditCard").val($("#chkCreditLoc").attr("checked")?"Y":"N");$("#hdTripType").val($("[name=triptype]:checked").val());if($("[name=triptype]:checked").val()=="3"){}else{if($("[name=triptype]:checked").val()=="2"){$("#hdDeparting").val($(oFrm.DD2).val());$("#hdReturning").val($(oFrm.RD2).val());$("#hdDepTime").val($("#sdt21").val());$("#hdRetTime").val($("#srt21").val())}else{if($("[name=triptype]:checked").val()=="1"){$("#hdDeparting").val($(oFrm.DD1).val());$("#hdDepTime").val($("#sdt11").val())}}}}function SearchManager(a){var b=oCFS.TilePopURL+"?"+GetParamFlightTile($("[input[name=triptype]:checked").val());if(typeof(callServiceSync)!="undefined"){callServiceSync(packServiceWithMic("100046","100047","100048"),null);if($("#chkCreditLoc").attr("checked")){callServiceSync(packServiceWithMic("100010","100011","100012"),null)}if($("#chkTile").attr("checked")){callServiceSync(packServiceWithMic("100016","100017","100018"),null)}else{callServiceSync(packServiceWithMic("100013","100014","100015"),null)}}if(IsBanIP||!(isValidDateForAirfare)){window.location=b;return}if(CheckAirfare()){if($("#chkCreditLoc").attr("checked")==true){SetValueToHiddenField();$("#frmFlightSearch").trigger("submit");return}}window.location=b;return}function CheckAirfare(){var a=false;var c="";var b="";var d="";if($("[input[name=triptype]:checked").val()=="2"){c=$(oFrm.DF2).val();b=$(oFrm.TT2).val();d=$(oFrm.DD2).val()}else{c=$(oFrm.DF1).val();d=$(oFrm.DD1).val()}var e="on="+c+"&dn="+b+"&fd="+d;$.ajax({type:"GET",url:oCFS.RootPath+"Widgets/AIRFlightsBooking/AirfareSearch/CheckSearchInfo.ashx",contentType:"application/json; charset=utf-8",data:e,dataType:"json",async:false,success:function(f){if(f.IsAccept||oCFS.IsDebug){a=true}}});return a}function CheckUser(){$.ajax({type:"GET",url:oCFS.RootPath+"Widgets/AIRFlightsBooking/AirfareSearch/CheckSearchInfo.ashx",contentType:"application/json; charset=utf-8",data:"",dataType:"json",async:true,success:function(obj){if(obj.IsAccept||oCFS.IsDebug){if(typeof(callServiceAsync)!="undefined"&&!oCFS.IsPost){callServiceAsync(packServiceWithMic("100007","100008","100009"),null)}$("#wSpace").hide();$("#wGetMore").show();IsBanIP=false}else{if(typeof(callServiceAsync)!="undefined"&&!oCFS.IsPost){callServiceAsync(packServiceWithMic("100001","100002","100003"),null);callServiceAsync(packServiceWithMic("100004","100005","100006"),null)}IsBanIP=true}if(typeof(E_ValidateUserCompleted)!="undefined"){eval(E_ValidateUserCompleted)}}})}function CheckFocus(a){var b="";a=a.substring(0,9);if(a=="REQ_P1011"){b=oFrm.DF1}else{if(a=="REQ_P1012"){b=oFrm.TT1}else{if(a=="REQ_P1021"){b=oFrm.DF2}else{if(a=="REQ_P1022"){b=oFrm.TT2}else{if((a=="REQ_P1013")||(a=="REQ_P1151")||(a=="REQ_P1161")){b=oFrm.DD1}else{if((a=="REQ_P1023")||(a=="REQ_P1152")||(a=="REQ_P1162")){b=oFrm.DD2}else{if((a=="REQ_P1024")||(a=="REQ_P1153")||(a=="REQ_P1163")||(a=="REQ_P1143")){b=oFrm.RD2}}}}}}}$(b).focus()}function DataCompare(e,d){var h=(e.indexOf("/")!=-1)?"/":"-";var c=e.indexOf(h);var b=e.lastIndexOf(h);var g=parseInt(e.substring(b+1),10);var a=parseInt(e.substring(0,c),10);var f=parseInt(e.substring(c+1,b),10);var j=new Date(g,a-1,f);h=(d.indexOf("/")!=-1)?"/":"-";c=d.indexOf(h);b=d.lastIndexOf(h);g=parseInt(d.substring(b+1),10);a=parseInt(d.substring(0,c),10);f=parseInt(d.substring(c+1,b),10);var i=new Date(g,a-1,f);return j<i}function fnDateSelected(f,c){var i=(f.indexOf("/")!=-1)?"/":"-";var d=f.indexOf(i);var b=f.lastIndexOf(i);var h=parseInt(f.substring(b+1),10);var a=parseInt(f.substring(0,d),10);var g=parseInt(f.substring(d+1,b),10);var e=new Date(h,a-1,g);e.setDate(e.getDate()+1);$("#dTo,#dFrom").removeClass("noDate");$("#dTo").datepicker("option","minDate",e)}function checkDate(b){var a,f,j;var i=b.value;var k=/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;if(k.test(i)){var h=(i.indexOf("/")!=-1)?"/":"-";var d=i.indexOf(h);var c=i.lastIndexOf(h);a=parseInt(i.substring(0,d),10);f=parseInt(i.substring(d+1,c),10);j=parseInt(i.substring(c+1),10);var g=new Date(j,a-1,f);if(g.getDate()==f){if(g.getMonth()+1==a){if(g.getFullYear()==j){var e=new Date();e.setDate(e.getDate()-1);if(g<e){AddErrorMsg("The date must be greater than or equal today.");return false}return true}else{AddErrorMsg("There is a problem with the year entry.")}}else{AddErrorMsg("There is a problem with the month entry.")}}else{AddErrorMsg("There is a problem with the date entry.")}}else{AddErrorMsg("Incorrect date format. Enter as mm/dd/yyyy.")}$(b).addClass("noDate");return false}function validateDate(a){if(!checkDate(a)){a.focus();a.select();return false}return true}jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};String.prototype.startsWith=function(a){return(this.indexOf(a)===0)};
