/*************************************************************************************************************************** * * Validation and helper functions for app modules. * ***************************************************************************************************************************/ /*************************************** BOOOKING MODULE CODE BEGINS HERE ************************************************/ function startInit() { erCon = new erc(); // Init e-retail connector object preloadImgs('/content/images/br/modules/common/error2.gif', 13, 15, '/content/images/br/modules/common/error3.gif', 15, 18, '/content/images/br/modules/common/progress.gif', 322, 13); } // Function checkIfLoaded checks to see if the defined element ID is available before executing the specified // function/script. This check is required for scripts that need to execute with event onload in an ajax loaded // panel. The function will continously poll the content from the time it is called until the specified // ID is available. At that point it will execute the required function and stop polling. function checkIfLoaded(id, load) { if (!load && document.getElementById(id)) { document.getElementById(id).id=''; return; } else if (load && document.getElementById(id)) { if (id == 'mod_1') { //initDate(document.ff_fs, document.ff_fs.departureMonth, document.ff_fs.departureDay); return; } } else if (load && !document.getElementById(id)) { setTimeout("checkIfLoaded('"+id+"', 'load')", 60); } } // Popup function for city lookup function jsPopUp(theUrl,theWidth,theHeight,getScrollVal) { var scrollVal = getScrollVal.toLowerCase(); // Open window and construct URL and toolbars win = window.open(theUrl,"myWin","width="+theWidth+",height="+theHeight+",resizable=0,menubar=1,scrollbars="+scrollVal+",left=100,top=20"); } // Hides or shows return flight input fields depending on if one-way or round-tript is selected function showHideReturnDate(bShow) { /*** * The following sets the time to any time for the return flight when one-way is selected. * Additionally it enables flexSearch if applicable. This check is required in case a user * selects a specific time on their return and then opts for a one-way flight instead. * Without this check the flexSearch option would remain disabled even if anytime was * selected on the departure flight ***/ if (bShow) { document.forms.ff_fs.returnTime.selectedIndex = 0; // Only enable if departure time value is set to ANY time if (document.forms.ff_fs.departureTime.options[document.forms.ff_fs.departureTime.selectedIndex].value == 'ANY') { disableEnable(document.forms.ff_fs.searchType[0], false); document.getElementById('fsOpt').style.color = ""; } } /* End of flexSearch check */ var returnCalendarId = "returnCalendar"; var returnMonthId = "returnMonth"; var returnDayId = "returnDay"; var returnTimeId = "returnTime"; var returnDateLabelId ="retDate"; var returnTimeErr = "rtimeErr"; showHide(returnTimeErr,bShow); showHide(returnDateLabelId,bShow); showHide(returnCalendarId,bShow); showHide(returnMonthId,bShow); showHide(returnTimeId,bShow); showHide(returnDayId,bShow); } // Function to disable or enable the flex search radio button function enableDisableFs(getAction) { if (getAction == 'ANY' && !document.forms.ff_fs.tripType[1].checked) { // Only enable if both field values are set to ANY time if (document.forms.ff_fs.departureTime.options[document.forms.ff_fs.departureTime.selectedIndex].value == 'ANY' && document.forms.ff_fs.returnTime.options[document.forms.ff_fs.returnTime.selectedIndex].value == 'ANY') { disableEnable(document.forms.ff_fs.searchType[0], false); document.getElementById('fsOpt').style.color = ""; } } else if (getAction == 'ANY' && document.forms.ff_fs.tripType[1].checked) { document.forms.ff_fs.returnTime.selectedIndex = 0; // Only enable if both field values are set to ANY time if (document.forms.ff_fs.departureTime.options[document.forms.ff_fs.departureTime.selectedIndex].value == 'ANY') { disableEnable(document.forms.ff_fs.searchType[0], false); document.getElementById('fsOpt').style.color = ""; } } else { document.getElementById('fsOpt').style.color = "#999999"; document.forms.ff_fs.searchType[1].checked = true; disableEnable(document.forms.ff_fs.searchType[0], true); } } // VALIDATE FORM AND CALL CONNECTOR function validateForm() { var errHeadSet = false; var isValid = true; var orig = document.forms["ff_fs"]["origin"]; var dest = document.forms["ff_fs"]["destination"]; var tripType = document.forms["ff_fs"]["tripType"]; var depMonth = document.forms["ff_fs"]["departureMonth"]; var depDay = document.forms["ff_fs"]["departureDay"]; var depTime = document.forms["ff_fs"]["departureTime"]; var retMonth = document.forms["ff_fs"]["returnMonth"]; var retDay = document.forms["ff_fs"]["returnDay"]; var retTime = document.forms["ff_fs"]["returnTime"]; var classOfService = document.forms["ff_fs"]["classOfServicePreference"]; var numAdt = document.forms["ff_fs"]["adultPassengerCount"]; var numChd = document.forms["ff_fs"]["childPassengerCount"]; var st = document.forms["ff_fs"]["searchType"]; var site = document.forms["ff_fs"]["SITE"]; var lang = document.forms["ff_fs"]["LANGUAGE"]; var tf = document.forms["ff_fs"]["TRIP_FLOW"]; var eid = document.forms["ff_fs"]["EXTERNAL_ID"]; var sds = document.forms["ff_fs"]["SEVEN_DAY_SEARCH"]; var et = document.forms["ff_fs"]["EMBEDDED_TRANSACTION"]; var so_avp = document.forms["ff_fs"]["SO_SITE_SPECIAL_REQUIREMENT2"]; // Allow value pricer var so_sppCfg = document.forms["ff_fs"]["SO_SITE_PASS_PROVIDER_CFG"]; var so_ofcId = document.forms["ff_fs"]["SO_SITE_OFFICE_ID"]; var so_amOfcId = document.forms["ff_fs"]["SO_SITE_AMADEUS_OFFICE_ID"]; var so_qOfcId = document.forms["ff_fs"]["SO_SITE_QUEUE_OFFICE_ID"]; var so_pos = document.forms["ff_fs"]["SO_SITE_POINT_OF_SALE"]; var pm = document.forms["ff_fs"]["proc_msg"]; var validatedOrig = validateStr(orig.value); var validatedDest = validateStr(dest.value); // Create vars for reg expression tests var num = /[0-9]+/; // Numeric content var ev = /^\s+$/; // Tab white space values // Calculate total passenger count var ttlPaxCount = parseInt(numAdt.options[numAdt.selectedIndex].value) + parseInt(numChd.options[numChd.selectedIndex].value); // Get checked radio button values var tripTypeVal; var stVal; if (tripType[0].checked) { tripTypeVal = tripType[0].value; } else if (tripType[1].checked) { tripTypeVal = tripType[1].value; } if (st[0].checked) { stVal = st[0].value; } else if (st[1].checked) { stVal = st[1].value; } // Clear any previous error messages before validating form fsError.clearError('error', 'span'); fsError.clearError('ffSf','label'); if (orig.value == "" || ev.test(orig.value) || num.test(orig.value)) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'Informe a cidade de origem e tente novamente.'); fsError.setAlert('from', '/content/images/br/modules/common/error2.gif'); isValid = false; } if (dest.value == "" || ev.test(dest.value) || num.test(dest.value)) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'Informe a cidade de retorno e tente novamente.'); fsError.setAlert('to', '/content/images/br/modules/common/error2.gif'); isValid = false; } if (ttlPaxCount > 7) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'O n\u00famero m\u00e1ximo de reservas de passageiros online \u00e9 sete.'); fsError.setAlert('adult', '/content/images/br/modules/common/error2.gif'); isValid = false; } // If trip type is not one-way check selected times if (!tripType[1].checked) { if (depMonth.options[depMonth.selectedIndex].value == retMonth.options[retMonth.selectedIndex].value && depDay.options[depDay.selectedIndex].value == retDay.options[retDay.selectedIndex].value) { if (retTime.options[retTime.selectedIndex].value != 'ANY' && depTime.options[depTime.selectedIndex].value !== 'ANY') { if (retTime.options[retTime.selectedIndex].value <= depTime.options[depTime.selectedIndex].value) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'Sua hora de retorno n\u00e3o pode ser a mesma ou antes da hora de partida.'); fsError.setAlert('dtime', '/content/images/br/modules/common/error2.gif'); fsError.setAlert('rtime', '/content/images/br/modules/common/error2.gif'); isValid = false; } } else if (st[1].checked) { if (depTime.options[depTime.selectedIndex].value == 'ANY' || retTime.options[retTime.selectedIndex].value == 'ANY') { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'Para v\u00f4os de volta na mesma data, especifique o hor\u00e1rio de seu v\u00f4o.'); fsError.setAlert('dtime', '/content/images/br/modules/common/error2.gif'); fsError.setAlert('rtime', '/content/images/br/modules/common/error2.gif'); isValid = false; } } } } // Check if outbound date is within permitted range of 331 days if (!checkDateRange(depMonth.options[depMonth.selectedIndex].value, depDay.options[depDay.selectedIndex].value, 0, 0, 0, 331, true)) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'S\u00f3 podemos mostrar v\u00f4os com partida em at\u00e9 331 dias, a contar de hoje.'); fsError.setAlert('depDate', '/content/images/br/modules/common/error2.gif'); if (!tripType[1].checked) { fsError.setMessage('error', 'S\u00f3 podemos mostrar v\u00f4os de retorno nos pr\u00f3ximos 331 dias.'); fsError.setAlert('retDateLbl', '/content/images/br/modules/common/error2.gif'); } isValid = false; // Ensure that a departure month and day has been selected } else if (depMonth.options[depMonth.selectedIndex].value == 0 || depDay.options[depDay.selectedIndex].value == 0) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'Por favor escolha o dia e m\u00eas de sa\u00edda.'); fsError.setAlert('depDate', '/content/images/br/modules/common/error2.gif'); isValid = false; } // If trip type selected is not one-way check if return date is within permitted range of 331 days & in chronological order if (checkDateRange(depMonth.options[depMonth.selectedIndex].value, depDay.options[depDay.selectedIndex].value, 0, 0, 0, 331, true)) { var obYear = getYear(depMonth.options[depMonth.selectedIndex].value, depDay.options[depDay.selectedIndex].value); if (!tripType[1].checked) { if (retMonth.options[retMonth.selectedIndex].value == 0 || retDay.options[retDay.selectedIndex].value == 0) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'Por favor, escolha o dia e m\u00eas de retorno.'); fsError.setAlert('retDateLbl', '/content/images/br/modules/common/error2.gif'); isValid = false; } else if (!checkDateRange(retMonth.options[retMonth.selectedIndex].value, retDay.options[retDay.selectedIndex].value, obYear, depMonth.options[depMonth.selectedIndex].value, depDay.options[depDay.selectedIndex].value, 331, false) && (retMonth.options[retMonth.selectedIndex].value != 0 || retDay.options[retDay.selectedIndex].value != 0)) { if (!errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); errHeadSet = true; } fsError.setMessage('error', 'S\u00f3 podemos mostrar v\u00f4os de retorno nos pr\u00f3ximos 331 dias.'); fsError.setAlert('retDateLbl', '/content/images/br/modules/common/error2.gif'); isValid = false; } } } if (isValid) { // Calls e-retail connector and constructs form for flexpricer requests erCon.flexPricerBuild(et.value, site.value, so_sppCfg.value, lang.value, tf.value, eid.value, so_ofcId.value, so_amOfcId.value, so_qOfcId.value, so_pos.value, validatedOrig, validatedDest, tripTypeVal, depMonth.options[depMonth.selectedIndex].value, depDay.options[depDay.selectedIndex].value, depTime.options[depTime.selectedIndex].value, retMonth.options[retMonth.selectedIndex].value, retDay.options[retDay.selectedIndex].value, retTime.options[retTime.selectedIndex].value, classOfService.options[classOfService.selectedIndex].value, sds.value, numAdt.options[numAdt.selectedIndex].value, numChd.options[numChd.selectedIndex].value, so_avp.value, pm.value, stVal); } } /*************************************** BOOKING MODULE CODE ENDS HERE ***************************************************/ /*************************************** RETRIEVE PNR MODULE CODE BEGINS HERE ********************************************/ function validateRPnrForm() { var pnr_errHeadSet = false; var pnr_isValid = true; var pnr = document.forms["retrievePnr"]["REC_LOC"]; var name = document.forms["retrievePnr"]["DIRECT_RETRIEVE_LASTNAME"]; // Create vars for reg expression tests var num = /[0-9]+/; // Numeric content var ev = /^\s+$/; // Tab white space values var sc = /[\!\@\#\$\%\"\'\(\)\&\§\-\_]+/; // Special characters // Clear any previous error messages before validating form fsError.clearError('error', 'span'); fsError.clearError('rPnr','label'); if (pnr.value == '' || ev.test(pnr.value) || num.test(pnr.value) || sc.test(pnr.value)) { if (!pnr_errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); pnr_errHeadSet = true; } fsError.setMessage('error', 'O n\u00famero do PNR \u00e9 obrigat\u00f3rio, informe-o.'); fsError.setAlert('recLoc', '/content/images/br/modules/common/error2.gif'); pnr_isValid = false; } if (name.value == '' || ev.test(name.value) || num.test(name.value) || sc.test(name.value)) { if (!pnr_errHeadSet) { fsError.setMessageHeader('error', 'O seguinte erro ocorreu', 'SFError', '/content/images/br/modules/common/error3.gif'); pnr_errHeadSet = true; } fsError.setMessage('error', 'Informe o \u00faltimo nome.'); fsError.setAlert('lName', '/content/images/br/modules/common/error2.gif'); pnr_isValid = false; } if (pnr_isValid) { var validatedName = validateStr(name.value); document.retrievePnr.DIRECT_RETRIEVE_LASTNAME.value = validatedName; document.retrievePnr.submit(); } } /*************************************** RETRIEVE PNR MODULE CODE ENDS HERE ********************************************/