/*************************************************************************************************************************** UTILITIES JS LIBRARY V2.0 IMP DATE: 13/11/2007 LAST MODIFIED: 08/11/2007 AUTHOR: OLIVER AMMANN (1.) CALENDAR AND DATE VALIDATION FUNCTIONS (2.) E-RETAIL CONNECTOR FUNCTIONS ***************************************************************************************************************************/ /********************* (1.) CALENDAR AND DATE VALIDATION FUNCTIONS *********************/ // Checks that selected dates do not exceed 329 days from today and that dates are in chronological order function checkDateRange(getMonth, getDay, getObYear, getObMonth, getObDay, maxRange, orIbCheck) { var isValid = true; // Selected date values var year = getYear(getMonth, getDay); var month = parseInt(getMonth); var day = parseInt(getDay); // Outbound date values var obYear = parseInt(getObYear); var obMonth = parseInt(getObMonth); var obDay = parseInt(getObDay); var legalRange = new Date(); if (!orIbCheck) { if (obYear > year) { year++; } if (obYear == year) { if (month < obMonth) { year++; } else if (month == obMonth && day < obDay) { year++; } } } legalRange.setDate(legalRange.getDate() + maxRange); var lrYear = legalRange.getUTCFullYear(); var lrMonth = legalRange.getUTCMonth()+1; var lrDay = legalRange.getUTCDate(); var lrDate = new Date(lrYear, lrMonth, lrDay); var selectedDate = new Date(year, month, day); if (selectedDate > lrDate) { isValid = false; } return isValid; } // Determines year depending on selected dates function getYear(getMonth, getDay) { var year; var month = parseInt(getMonth); var day = parseInt(getDay); var date = new Date(); if (month <= date.getUTCMonth()+1) { if (month == date.getUTCMonth()+1 && day < date.getUTCDate()) { year = date.getUTCFullYear() + 1; } else if (month < date.getUTCMonth()+1) { year = date.getUTCFullYear() + 1; } else { year = date.getUTCFullYear(); } } else { year = date.getUTCFullYear(); } return year; } // Launch language specific calendar popup (adapted from aa.com) function launchCalendar(calForm, formName,langVal){ var urlVer; if (langVal == 'll') { urlVer = '/intl/br/apps/common/calendar.jsp'; } else if (langVal == 'en') { urlVer = '/intl/br/apps/common/calendar.jsp'; } eval('document.'+formName+'.currentCalForm.value = calForm'); var calWin = window.open(urlVer,formName,'scrollbars=no,menu=no,width=300,height=165,top=125,left=325'); calWin.focus(); } // Date validation for selected dates (Adapted from aa.com) function leapYear(theYear) { if ( ((theYear % 4 == 0) && (theYear % 100 != 0)) || (theYear % 400 == 0) ) { return true; } else { return false; } } /* *** Set the return month and day to two days after the departure month and day. [chalsted] ER #9196 *** */ function updateReturnDate(formName) { var d = new Date(); var dYear = d.getFullYear(); var dDay = formName.departureDay.selectedIndex; var dMonth = formName.departureMonth.selectedIndex; var today = new Date(); var threeDaysInfuture = new Date(); threeDaysInfuture.setDate(today.getDate() + 3); /* Start of ER 12182 :ER - Return Date should not default to Outbound + 2 * if return date has been specified by user */ var rDy = formName.returnDay.selectedIndex; var rMon = formName.returnMonth.selectedIndex; //var changed = true; //if((rDy == threeDaysInfuture.getDate() - 1) && (rMon == threeDaysInfuture.getMonth())) //changed = false; /** * */ //if(changed == true && formName.changed == null) //new page - keep date changes // return; var rYr = d.getFullYear(); // for next year if (formName.returnMonth.selectedIndex < d.getMonth()){ rYr = rYr+1; } // for next year if (formName.departureMonth.selectedIndex < d.getMonth()){ dYear = dYear+1; } rDate = new Date(rYr, rMon, rDy); dDate = new Date(dYear, dMonth, dDay+2); // end of ER 12182 : var rYear = dYear; var rMonth = '1'; var rDay = '1'; // 30 Days: April-3 June-5 September-8 November-10 // 31 Days: January-0, March-2, May-4, July-6, August-7, October-9, December-11 // 28 Days: February-1 // For Months with 31 days if ( (dMonth == '1' || dMonth == '3' || dMonth == '5' || dMonth == '7' || dMonth == '8' || dMonth == '10' || dMonth == '12' )){ if (dDay == '30') { rDay = '1'; // If December, set month back to '0' for January if (dMonth == '12') { rMonth = '1'; } else { rMonth = dMonth + 1; } } else if (dDay == '31') { rDay = '2'; // If December, set month back to '0' for January if (dMonth == '12') { rMonth = '1'; } else { rMonth = dMonth + 1; } } else { rDay = dDay + 2; rMonth = dMonth; } // For Months with 30 days } else if ((dMonth == '4' || dMonth == '6' || dMonth == '9' || dMonth == '11' )) { /* test for invalid dates */ if (dDay == '31' || dDay == '32') { dDay = '30'; eval (formName.departureDay.selectedIndex = dDay); } if (dDay == '29') { rDay = '1'; rMonth = dMonth + 1; } else if (dDay == '30') { rDay = '2'; rMonth = dMonth + 1; } else { rDay = dDay + 2; rMonth = dMonth; } // For February, check for leapyear. } else if (dMonth == '2') { /*********************************************************** 13 Apr 07 - Updated validation to take account of leap year [O.Ammann] ***********************************************************/ // Check to see if Feb 29, 30, or 31 is selected for NON-leapyear. // If so, set departure date to Feb 28. if (!leapYear(rYear)) { if (dDay == '29' || dDay == '30' || dDay == '31') { dDay = '28'; eval (formName.departureDay.selectedIndex = dDay); } } else if (leapYear(rYear)) { if (dDay == '30' || dDay == '31') { dDay = '29'; eval (formName.departureDay.selectedIndex = dDay); } } if ((leapYear(rYear) && dDay == '28') || (!leapYear(rYear) && dDay == '27')) { rDay = '1'; rMonth = dMonth + 1; } else if ((leapYear(rYear) && dDay == '29') || (!leapYear(rYear) && dDay == '28')) { rDay = '1'; rMonth = dMonth + 1; } else { rDay = dDay + 2; rMonth = dMonth; } } //check to see if on different page if(formName.dateChanged != null && formName.dateChanged.value == 'true') return; if(formName.returnDay.changed == null && formName.changed == null){ eval (formName.returnDay.selectedIndex = rDay); } if( formName.returnMonth.changed == null && formName.changed == null){ eval (formName.returnMonth.selectedIndex = rMonth); } return; } function validateReturn(theForm) { var formName = eval('document.' + theForm); var dMonth = formName.returnMonth.selectedIndex; var dDay = formName.returnDay.selectedIndex; var dYear = getYear(dMonth, dDay); // For Months with 31 days if ( (dMonth == '0' || dMonth == '2' || dMonth == '4' || dMonth == '6' || dMonth == '7' || dMonth == '9' || dMonth == '11' )){ if (dDay == '30' || dDay == '31') { dDay = '29'; //eval (formName.returnDay.selectedIndex = dDay); } // For Months with 30 days } else if ((dMonth == '3' || dMonth == '5' || dMonth == '8' || dMonth == '10' )) { if (dDay == '30' || dDay == '31') { dDay = '29'; eval (formName.returnDay.selectedIndex = dDay); } /*********************************************************** 13 Apr 07 - Updated validation to take account of leap year [O.Ammann] ***********************************************************/ // For February, check for leapyear. } else if (dMonth == '1') { if (!leapYear(dYear)) { if (dDay == '28' || dDay == '29' || dDay == '30') { dDay = '27'; eval (formName.returnDay.selectedIndex = dDay); } } else if (leapYear(dYear)) { if (dDay == '29' || dDay == '30') { dDay = '28'; eval (formName.returnDay.selectedIndex = dDay); } } } } function updateChangedDate(selectObject){ selectObject.changed = true; if(selectObject.form.dateChanged) selectObject.form.dateChanged.value = true; } // Validates max day in month for month selected function doMaxDayCheck(getTargetElement, theMonth, theDay) { var theYear = getYear(theMonth, theDay); // 31 Days: January-1, March-3, May-5, July-7, August-8, October-10, December-12 // 30 Days: April-4 June-6 September-9 November-11 // 28 Days: February-2 // For Months with 30 days if ((parseInt(theMonth,10) == 4 || parseInt(theMonth,10) == 6 || parseInt(theMonth,10) == 9 || parseInt(theMonth,10) == 11)) { if (parseInt(theDay,10) > 30) { getTargetElement.selectedIndex = 30; } // For February, check for leapyear. } else if (parseInt(theMonth,10) == 2) { if (!leapYear(theYear) && parseInt(theDay,10) > 28) { getTargetElement.selectedIndex = 28; } else if (leapYear(theYear) && parseInt(theDay,10) > 29) { getTargetElement.selectedIndex = 29; } } } /********************* (2.) E-RETAIL CONNECTOR FUNCTIONS **********************/ /*** * formatdateStr function Added 07/05/07 * Converts month and day string from 1 digit to 2 digit value, which is required for the e-retail date string. * Fix was implemented as passing a 2 digit value directly from the day/month dropdown caused date * validation errors for numberic values below 10. */ function formatDateStr(getVal) { if (getVal < 10) { getVal = 0 + getVal; } return getVal; } // Convert Portuguese special characters to regular ASCII equivalent - Implemented (04/07/2007) // Fix to correct URL encoding bug when special characters are contained in origin/destination values // This was causing errors in e-retail function validateStr(getStr) { var strToLc = getStr.toLowerCase(); if (strToLc.indexOf('á') != -1) { strToLc = strToLc.replace(/á/,'a'); } if (strToLc.indexOf('à') != -1) { strToLc = strToLc.replace(/à/,'a'); } if (strToLc.indexOf('ã') != -1) { strToLc = strToLc.replace(/ã/,'a'); } if (strToLc.indexOf('â') != -1) { strToLc = strToLc.replace(/â/,'a'); } if (strToLc.indexOf('ç') != -1) { strToLc = strToLc.replace(/ç/,'c'); } if (strToLc.indexOf('é') != -1) { strToLc = strToLc.replace(/é/,'e'); } if (strToLc.indexOf('ê') != -1) { strToLc = strToLc.replace(/ê/,'e'); } if (strToLc.indexOf('ó') != -1) { strToLc = strToLc.replace(/ó/,'o'); } if (strToLc.indexOf('ô') != -1) { strToLc = strToLc.replace(/ô/,'o'); } if (strToLc.indexOf('õ') != -1) { strToLc = strToLc.replace(/õ/,'o'); } if (strToLc.indexOf('í') != -1) { strToLc = strToLc.replace(/í/,'i'); } if (strToLc.indexOf('ú') != -1) { strToLc = strToLc.replace(/ú/,'u'); } return strToLc; } // E-Retail connector Object function erc() { var ercObj = new Object(); /* BEGINS FLEXPRICER FUNCTION */ function flexPricerBuild(et, site, hostPCC, lang, tripFlow, eid, so_officeId, so_amOfficeId, so_qofficeId, so_pointOfSale, origin, destination, tripType, depMonth, depDay, depTime, retMonth, retDay, retTime, classOfService, sevenDaySearch, numAdt, numChd, vpAllowed, holdMsg, flexSearch) { // Determine outbound and inbound year for selected dates and create dep and ret dates var obYear = getYear(depMonth, depDay); var ibYear = getYear(retMonth, retDay); var depDate; var retDate; var obAnyTime; var ibAnyTime; if (depTime != "ANY") { depDate = obYear+formatDateStr(depMonth)+formatDateStr(depDay)+depTime; obAnyTime = false; } else { depDate = obYear+formatDateStr(depMonth)+formatDateStr(depDay)+"0000"; obAnyTime = true; } if (retTime != "ANY") { retDate = ibYear+formatDateStr(retMonth)+formatDateStr(retDay)+retTime; ibAnyTime = false; } else { retDate = ibYear+formatDateStr(retMonth)+formatDateStr(retDay)+"0000"; ibAnyTime = true; } var adtCount = parseInt(numAdt); var chdCount = parseInt(numChd); // Display processing request message document.writeln(''); document.writeln(''); document.writeln(''+holdMsg+''); document.writeln(''); document.writeln(''); document.writeln(''); /*** New transition splash page code (Not ready for implementation) document.writeln(''); document.writeln(''); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); ***/ // Transition page code document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'+holdMsg+'
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); document.writeln('
'); /*** * Build FlexPricer form */ document.writeln('
'); document.writeln('
'); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); // Determine which commercial fare family to use based on selected booking class and external id if (classOfService == 'P') { document.writeln(''); } else { document.writeln(''); } /* Determine if we should use calendar or upsell display (1 = Calendar display 2 = upsell panel display) */ // Condition 1 - user selects around these dates and time is set to any time for both dates if (flexSearch == 'flexSearch') { document.writeln(''); // Sets display to calendar display document.writeln(''); // Orders default display by number of stops } else { document.writeln(''); // Sets display to upsell panel document.writeln(''); // Orders default display by number of stops } document.writeln(''); // O = oneway display I = roundtrip matrix document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); // C = search around dates document.writeln(''); // Passenger type logic based on number of adults and children selected in the UI var adult; for (var i = 0; i < adtCount; i++) { adult = i+1; document.writeln(''); } var children = adtCount+1; for (var i = 0; i < chdCount; i++) { document.writeln(''); children++; } // Global list overide parameters document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln(''); document.writeln('
'); document.writeln('
'); document.writeln(''); // Web analytics ER - added 25/02/10 document.writeln(''+'<\/scr'+'ipt>'); document.writeln(''); document.writeln(''); } ercObj.flexPricerBuild = flexPricerBuild; return ercObj; } // Preload and cache module & splash screen images function preloadImgs(img1, w1, h1, img2, w2, h2, img3, w3, h3) { image1 = new Image(w1,h1); image1.src = img1; image2 = new Image(w2,h2); image2.src = img2; image3 = new Image(w3,h3); image3.src = img3; }