// PCA JS FLIGHT BOOKING COMPONENTS
// 8/19/2010

var arrErrors=[],arrMessages={eMsg1:'Invalid Datetime format: ',eMsg2:'Please make a selection for Departure Airport',eMsg3:'Please make a selection for Arrival Airport',eMsg4:'Departure Airport must be different from Arrival Airport',eMsg5:'Please enter a valid date for Departure Date',eMsg6:'Please enter a valid date for Return Date',eMsg7:'You have selected a departure date that has passed',eMsg8:'You have selected a return date that is before the departure date',eMsg9:'Please enter Number of Adults',eMsg10:'Please enter only numeric values for Number of Adults',eMsg11:'Please enter only positive numeric values for Number of Adults',eMsg12:'Please enter Number of Children',eMsg13:'Please enter only numeric values for Number of Children',eMsg14:'Please enter only positive numeric values for Number of Children'};function openWindow(a,b){var c={width:800,height:600,screenx:0,screeny:0,left:0,top:0,dependent:'no',directories:'no',fullscreen:'no',location:'no',menubar:'no',resizable:'no',scrollbars:'yes',status:'no',toolbar:'no'};for(var d in b){if(b.hasOwnProperty(d)){var e=b[d];d=d.toLowerCase();if(/^width|height|screenx|screeny|left|top$/.test(d)){e=parseFloat(e)}if(c.hasOwnProperty(d)){c[d]=e}}}c.screenx=c.left=((screen.availWidth/2)-(c.width/2));c.screeny=c.top=((screen.availHeight/2)-(c.height/2));var f='';for(var g in c){if(c.hasOwnProperty(g)){f+=g+'='+c[g]+','}}f=f.substring(0,f.length-1);var h=window.open(a,"popwindow",f);if(window.focus){h.focus()}return h}function str2dt4(a){var b=/^(\d+)\/(\d+)\/(\d+)$/;if(!b.exec(a)){arrErrors.push(arrMessages.eMsg1+a);return false}return(new Date(RegExp.$1,RegExp.$2-1,RegExp.$3))}function CSValidation(){var a="";var b=[];var c=null;var d=new RegExp("[0-9]+");var e=document.getElementById("radRndTripOn").checked;var f=document.Flight.lstOrigAP.value;if(f=='0'){arrErrors.push(arrMessages.eMsg2)}var g=document.Flight.lstDestAP.value;if(g=='0'){arrErrors.push(arrMessages.eMsg3)}if(f!='0'&&g!='0'&&f==g){arrErrors.push(arrMessages.eMsg4)}a=document.getElementById("depart-date").value;b=a.split("/");a=b[2]+"/"+b[0]+"/"+b[1];document.Flight.dlstDepDate_Day.value=b[1];document.Flight.dlstDepDate_Month.value=b[2]+"/"+b[0];c=new Date(str2dt4(b[2]+"/"+b[0]+"/"+"01")).getMonth();var h=new Date(str2dt4(a));if(c!=h.getMonth()){arrErrors.push(arrMessages.eMsg5)}a="";b=[];c=null;a=document.getElementById("return-date").value;b=a.split("/");a=b[2]+"/"+b[0]+"/"+b[1];document.Flight.dlstRetDate_Day.value=b[1];document.Flight.dlstRetDate_Month.value=b[2]+"/"+b[0];c=new Date(str2dt4(b[2]+"/"+b[0]+"/"+"01")).getMonth();var j=new Date(str2dt4(a));if(c!=j.getMonth()){arrErrors.push(arrMessages.eMsg6)}a="";b=[];c=null;var k=new Date();var l=new Date(k.getFullYear()+","+(k.getMonth()+1)+","+k.getDate());if(h<l){arrErrors.push(arrMessages.eMsg7)}if(e&&j<h){arrErrors.push(arrMessages.eMsg8)}if(!document.Flight.txtNumAdults.value){arrErrors.push(arrMessages.eMsg9)}else if(isNaN(document.Flight.txtNumAdults.value)){arrErrors.push(arrMessages.eMsg10)}else if(document.Flight.txtNumAdults.value<=0){arrErrors.push(arrMessages.eMsg11)}else{if(document.Flight.txtNumAdults.value!==''){if(!document.Flight.txtNumAdults.value.match(d)){arrErrors.push(arrMessages.eMsg10)}}}if(!document.Flight.txtNumChildren.value){arrErrors.push(arrMessages.eMsg12)}else if(isNaN(document.Flight.txtNumChildren.value)){arrErrors.push(arrMessages.eMsg13)}else if(document.Flight.txtNumChildren.value<0){arrErrors.push(arrMessages.eMsg14)}else{if(document.Flight.txtNumChildren.value!==''){if(!document.Flight.txtNumChildren.value.match(d)){arrErrors.push(arrMessages.eMsg13)}}}var m=arrErrors.length;if(m>0){var n="";for(i=0;i<m;i++){n+=(i+1)+". "+arrErrors[i]+"\n"}arrErrors=[];alert(n);return false}else{return true}}function SubmitForm(){if(CSValidation()){var a=$("#Flight").serialize();var b=document.Flight.action;openWindow(b+"?"+a);return false}else{return false}}function manageRndTrip(a){$('#dlstRetDate_Month').attr('disabled',a);$('#dlstRetDate_Day').attr('disabled',a);$('#chkRoundTrip').attr('disabled',a);$('#return-date').attr('disabled',a)}var date=new Date(),day=date.getDate(),month=date.getMonth()+1,year=date.getFullYear();if(day<10){day="0"+day}if(month<10){month="0"+month}$(document).ready(function(){$("#Flight")[0].reset();$("[name='groupRndTrip']","#Flight").click(function(){switch(this.id){case"radRndTripOn":manageRndTrip(false);break;case"radRndTripOff":manageRndTrip(true);break}}).filter("#radRndTripOn").trigger("click");$('#depart-date').datepicker({dateFormat:'mm/dd/yy',showAnim:null,minDate:+0,onSelect:function(a,b){$('#return-date').datepicker("option","minDate",new Date(b.selectedYear,b.selectedMonth,b.selectedDay))}}).val(month+"/"+day+"/"+year);$('#return-date').datepicker({dateFormat:'mm/dd/yy',showAnim:null,minDate:+0}).val(month+"/"+day+"/"+year);$('#dialog_link, ul#icons li').hover(function(){$(this).addClass('ui-state-hover')},function(){$(this).removeClass('ui-state-hover')});$(".btn_search_flight","#Flight").click(function(){$("form#Flight input#blnFares").val(false);return SubmitForm()});$(".btn_search_fare","#Flight").click(function(){$("form#Flight input#blnFares").val(true);return SubmitForm()});$(".btn_modify_booking","#Flight").click(function(){openWindow("https://ameliaweb.intelisys.ca/Pasco/AmeliaRequest.aspx");return false})});
