/* ====================================================================================== * Copyright 2009 American Airlines, Inc. All rights reserved. * * Flexpricer for multi-city UI functions * Version 1.0 * ====================================================================================== */ function updateOrigin(targetSelectId, srcSelectId, destHFId, origHFId, origDFId, form) { // Create element refrences for form input fields var targetSel = document.getElementById(targetSelectId); // Next disabled select var srcSel = document.getElementById(srcSelectId); // Select that triggered event var destHf = document.getElementById(destHFId); // Hidden field related to src select var origHf = document.getElementById(origHFId); // Hidden field for the next orig var origDf = document.getElementById(origDFId); // Text field for next orig var formRef = document.getElementById(form); // Refrence to the calling form // Get the display text from the selected destination. This will be used to update // the value of the next origin text field in the form var origDisplayText = srcSel.options[srcSel.selectedIndex].text; // Get the value from the selected destination. This will be used to update // the value of the next hidden origin field in the form var origValue = srcSel.options[srcSel.selectedIndex].value; // Only update fields if an actual destination was chosen from the dropdown // If default value is selected E.G "Choose destination" no update should be made if(origValue != "") { // Update hidden field related to the select that trigered the event destHf.value = origValue; // Update hidden field for next origin in the form origHf.value = origValue; // Update text field value for next origin in the form origDf.value = origDisplayText; // Enable target dropdown targetSel.disabled = false; targetSel.style.backgroundColor = '#FFFFFF'; } else if(origValue == "" && srcSelectId == 'd_destination2') { // Update hidden field related to the select that trigered the event destHf.value = ""; // Update hidden field for next origin in the form origHf.value = ""; // Update text field value for next origin in the form origDf.value = ""; } else { formRef.reset(); } } function processForm(formId, lang, errorDivId) { var errorAlertIds = ['dest1Err', 'orig2Err', 'dest2Err', 'orig3Err', 'depDay1Err', 'depMonth1Err', 'depDay2Err', 'depMonth2Err', 'depDay3Err', 'depMonth3Err', 'adultsErr', 'childrenErr']; var formData = getFormData(formId); var validPaxNum = validatePaxNum(formData['adults'], formData['children'], 7); if(!validPaxNum) { formData['adults'] = 'FALSE'; formData['children'] = 'FALSE'; } var isValid = checkForErrors(formData, lang, errorDivId, errorAlertIds, 'Err'); if(isValid) { formattedArray = formatData(formData, 3); var paxType = updatePaxType(formattedArray['adults'], formattedArray['children']); updatefpMcForm('fpMcf', 3, formattedArray, paxType); submitForm('fpMcf'); } return false; } function submitForm(formId) { try { var targetForm = document.getElementById(formId); targetForm.submit(); } catch(err) { } } function updatefpMcForm(formId, slices, formData, paxData) { try { var targetForm = document.getElementById(formId); var postFix; targetForm.reset(); // Make sure we clear any old values for(i = 0; i < slices; i++) { postFix = i + 1; targetForm['B_LOCATION_' + postFix].value = formData['orig' + postFix]; targetForm['E_LOCATION_' + postFix].value = formData['dest' + postFix]; targetForm['B_DATE_' + postFix].value = formData['date' + postFix]; targetForm['B_ANY_TIME_' + postFix].value = formData['anytime' + postFix]; targetForm['DATE_RANGE_VALUE_' + postFix].value = formData['drv']; targetForm['DATE_RANGE_QUALIFIER_'+ postFix].value = formData['drc']; } var count = 1; for(prop in paxData) { targetForm['TRAVELLER_TYPE_'+ count].value = paxData[prop]; count++; } } catch(err) { } } function formatData(data, slices) { var postFix; for(i = 0; i < slices; i++) { postFix = i + 1; data['date'+postFix] = createAmadeusDate( data['depDay'+postFix], data['depMonth'+postFix], substitute(data['depTime'+postFix], 'ANY', '0000'), postFix ); data['anytime'+postFix] = anyTime('ANY', data['depTime'+postFix]); } return data; } function updatePaxType(adt, chd) { var adult; var paxTypeArr = new Array(); for(var i = 0; i < parseInt(adt, 10); i++) { adult = i+1; paxTypeArr['traveller'+adult] = "ADT"; } var children = parseInt(adt, 10) + 1; for(var i = 0; i < parseInt(chd, 10); i++) { paxTypeArr['traveller'+children] = "CHD"; children++; } return paxTypeArr; } function leapYear(theYear) { if(((theYear % 4 == 0) && (theYear % 100 != 0)) || (theYear % 400 == 0)) { return true; } else { return false; } } function checkMaxDay(form, monthId, dayId) { var f = document.getElementById(form); var day = f[dayId].options[f[dayId].selectedIndex].value; var month = f[monthId].options[f[monthId].selectedIndex].value; var max; if(day != '' && month != '') { max = maxDay(month, day); if(day > max) { f[dayId].options.selectedIndex = max; } } } function maxDay(month, day) { var max = null; switch(parseInt(month, 10)) { case 1: max = 31; break; case 2: max = 28; break; case 3: max = 31; break; case 4: max = 30; break; case 5: max = 31; break; case 6: max = 301; break; case 7: max = 31; break; case 8: max = 31; break; case 9: max = 30; break; case 10: max = 31; break; case 11: max = 30; break; case 12: max = 31; break; } var year = getYear(parseInt(month, 10), parseInt(day, 10)); var isLeap = leapYear(year); if(isLeap) { max++; } return max; } 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; } function formatNumStr(endRange, num) { var formattedStr = ''; if(parseInt(num, 10) < parseInt(endRange, 10)) { formattedStr = '0' + num; } else { formattedStr = num; } return formattedStr; } function substitute(origVal, designator, subVal) { if(origVal == designator) { origVal = subVal; } return origVal; } function createAmadeusDate(day, month, time, postFix) { var dateStr =''; var year = getYear(month, day); dateStr = '' + year + formatNumStr(10, month) + formatNumStr(10, day) + time; return dateStr; } function anyTime(designator, value) { if(value == designator) { return 'TRUE'; } else { return 'FALSE'; } } function getFormData(formId) { try { form = document.getElementById(formId); var formData = new Array(); formData['orig1'] = form.origin1.value; formData['dest1'] = validate(form.destination1.value); formData['orig2'] = validate(form.origin2.value); formData['dest2'] = validate(form.destination2.value); formData['orig3'] = validate(form.origin3.value); formData['dest3'] = form.destination3.value; formData['depDay1'] = validate(form.dayLeg1.options[form.dayLeg1.selectedIndex].value); formData['depMonth1'] = validate(form.monthLeg1.options[form.monthLeg1.selectedIndex].value); formData['depTime1'] = validate(form.timeLeg1.options[form.timeLeg1.selectedIndex].value); formData['depDay2'] = validate(form.dayLeg2.options[form.dayLeg2.selectedIndex].value); formData['depMonth2'] = validate(form.monthLeg2.options[form.monthLeg2.selectedIndex].value); formData['depTime2'] = validate(form.timeLeg2.options[form.timeLeg2.selectedIndex].value); formData['depDay3'] = validate(form.dayLeg3.options[form.dayLeg3.selectedIndex].value); formData['depMonth3'] = validate(form.monthLeg3.options[form.monthLeg3.selectedIndex].value); formData['depTime3'] = validate(form.timeLeg3.options[form.timeLeg3.selectedIndex].value); formData['adults'] = form.adultPassengerCount.options[form.adultPassengerCount.selectedIndex].value; formData['children'] = form.childPassengerCount.options[form.childPassengerCount.selectedIndex].value; formData['drv'] = 2; formData['drc'] = 'C'; } catch(err) { } return formData; } function validate(value) { if(value == "") { return 'FALSE'; } else { return value; } } function validatePaxNum(adt, chd, max) { if((parseInt(adt, 10) + parseInt(chd, 10)) > max) { return false; } else { return true; } } function checkForErrors(data, lang, id, errorAlertIds, postFix) { var isValid = true; var containerActive = false; clearErrors(id); clearAlerts(errorAlertIds); for(prop in data) { if(data[prop] == 'FALSE') { if(!containerActive) { activateErrorContainer(id, getErrorMessage('header', lang)); displayError(id, getErrorMessage(prop, lang)); displayAlert((prop+postFix)); containerActive = true; isValid = false; } else { displayError(id, getErrorMessage(prop, lang)); displayAlert((prop+postFix)); isValid = false; } } } return isValid; } function displayAlert(id) { document.getElementById(id).style.visibility = 'visible'; } function clearAlerts(alertIdList) { for(i = 0; i < alertIdList.length; i++) { var el = document.getElementById(alertIdList[i]); if(el != null) { el.style.visibility = 'hidden'; } } } function dynamicDivUpdate(id, htmlStr, overwrite) { var targetDiv = document.getElementById(id); if(overwrite) { targetDiv.innerHTML = htmlStr; } else { targetDiv.innerHTML += htmlStr; } } function activateErrorContainer(id, header) { var errorContainer = document.getElementById(id); var headerStr = '' + header + '
'; dynamicDivUpdate(id, headerStr, true); errorContainer.style.display = 'block'; } function displayError(id, error) { var errorStr = error + '
'; dynamicDivUpdate(id, errorStr, false); } function clearErrors(id) { dynamicDivUpdate(id, '', true); document.getElementById(id).style.display = 'none'; } function getErrorMessage(key, lang) { var errors = new Array(); // EN error messages errors['EN'] = { 'header': 'The following error(s) occured', 'dest1': 'Please choose as US destination city', 'orig2': 'Please choose a US departure city', 'dest2': 'Please choose a European destination city', 'orig3': 'Please choose a European departure city', 'depDay1': 'Please choose a departure date', 'depMonth1': 'Please choose a departure month', 'depDay2': 'Please choose a departure date', 'depMonth2': 'Please choose a departure month', 'depDay3': 'Please choose a departure date', 'depMonth3': 'Please choose a departure month', 'adults': 'The maximum total number of passengers you can book online is 7.' }, // JP error messages errors['JP'] = { 'header': '次のエラーが発生しました', 'dest1': '到着地(米国)を選択して下さい。', 'orig2': '出発地(米国)を選択して下さい。', 'dest2': '到着地(ヨーロッパ)を選択して下さい。', 'orig3': '出発地(ヨーロッパ)を選択して下さい。', 'depDay1': '出発日を選択して下さい。', 'depMonth1': '出発月を選択して下さい。', 'depDay2': '出発日を選択して下さい。', 'depMonth2': '出発月を選択して下さい。', 'depDay3': '出発日を選択して下さい。', 'depMonth3': '出発月を選択して下さい。', 'adults': '最大7名までの予約が可能です。', 'children': '' }; return errors[lang][key]; }