var emptyFieldFound; var emptyCheckboxFound; /** * Highlights obligatory fields that have been left empty * Uses array that is defined in the parent page (index.php) */ function testEmptyFields() { // ---------------------------------------------------------------------------- emptyFieldFound = false; emptyCheckboxFound = false; with (document.booking_container) { for (var i = 0; i < elements.length; i++) { testOneEmptyField(elements[i], obligatoryFieldsBasic); re = /^people\[(\d+)\]\[/; matchArray = re.exec(elements[i].name); if (matchArray) { passengerNumber = matchArray[1]; if ( (typeof otherNationChecked[passengerNumber] != 'undefined') && (otherNationChecked[passengerNumber]) ) testOneEmptyField(elements[i], obligatoryFieldsI94['passenger_' + passengerNumber]); var email = document.getElementsByName('people['+passengerNumber+'][email]').item(0); var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (!filter.test(email.value)) { alert('Please verify your e-mail address. It appears to be invalid.'); return false; } } } } if (emptyCheckboxFound) { alert('You have to agree to the terms and conditions in order to be able to proceed.'); return false; } if (emptyFieldFound) { alert('Please review fields that are marked with thick border. These are obligatory.'); return false; } else { return true; } } function testOneEmptyField(element, obligatoryFields) { // ---------------------------------------------------------------------------- for (field in obligatoryFields) { /* * if the element is disabled it means we`ll get its value from elsewhere */ if ( (element.name == field) && (element.disabled == false) ) { markField(false, element); switch (obligatoryFields[field]) { case "radio": /* too awkward to check and mark unselected radio buttons sets */ break; case "checkbox": if (element.checked == false) { emptyCheckboxFound = true; return false; } break; case "select": if (element.selectedIndex == -1) { markField(true, element, false); return false; } break; case "textarea": case "text": if ( (element.value == '') || (element.value == 'yyyy-mm-dd') ) { markField(true, element, false); return false; } break; } } } } /** * Optional setBackground is for checkboxes that don`t have border */ function markField(state, element, setBackground) { // ---------------------------------------------------------------------------- if (state) { element.style.borderWidth = "3"; /* pixels are understood */ emptyFieldFound = true; } else { element.style.borderWidth = "1"; } } var copyAttributes = new Array( "address","city","province","postal_code","phone","cell_phone","email","flight_airline_one","flight_number_one","flight_time_one","flight_airline_two","flight_number_two","flight_time_two"); function copyFirst(state, passengerId) { // ---------------------------------------------------------------------------- traverseElements(state, passengerId, copyAttributes); } function traverseElements(state, passengerId, arrayAttributes) { // ---------------------------------------------------------------------------- with (document.booking_container) { for (var i = 0; i < elements.length; i++) { firstSplit = elements[i].name.indexOf('['); secondSplit = elements[i].name.indexOf(']['); if (secondSplit) { // people[1][address] => address elementName = elements[i].name.substr( secondSplit + 2, elements[i].name.length - secondSplit - 3); // people[1][address] => 1 elementPassengerId = elements[i].name.substr( firstSplit + 1, secondSplit - firstSplit - 1); if (passengerId == elementPassengerId) { for (var j = 0; j < arrayAttributes.length; j++) { if (elementName == arrayAttributes[j]) { /* * disable the element */ elements[i].disabled = state; /* * change background to indicate write protection */ if (state) elements[i].style.backgroundColor = "white"; else elements[i].style.backgroundColor = ""; /* * perform action on this element */ switch (action) { case 'save': break; case 'copy': break; } } } } } } } } var userDataAttributes = new Array( "ticket_type", "first_name", "last_name", "address", "city", "province", "postal_code", "phone", "cell_phone", "email", "identification", "identification_type", "citizenship", "i94_citizenship", "i94_number", "i94_validity"); /* * If customer wants to use previously saved data we need to disable input fields that are not needed */ function disablePassengerFields(select, passengerId) { // ---------------------------------------------------------------------------- state = (select.selectedIndex != 0); traverseElements(state, passengerId, userDataAttributes); } function enableSubmitButton(enable) { // ---------------------------------------------------------------------------- if (enable) state = false; else state = true; var submitButtonElement = document.getElementById('submitButton'); submitButtonElement.disabled = state; } var otherNationChecked = new Array(); /** * When customer changes selection for Citizenship this function hides or shows I94 input fields * that are relevant only to non US and non CA citizens */ function toggleCitizenship(passengerNumber) { // ---------------------------------------------------------------------------- element = getSelectedRadio('people['+passengerNumber+'][citizenship]'); /* * Other Nation */ if (element.value == 2) { visibility = ''; otherNationChecked[passengerNumber] = true; } else { visibility = 'none'; otherNationChecked[passengerNumber] = false; } otherNationAttributes = new Array('i94','i94_citizenship','i94_number','i94_validity'); for (var i = 0; i < otherNationAttributes.length; i++) { toggleElement = document.getElementById(passengerNumber + '_' + otherNationAttributes[i]); toggleElement.style.display = visibility; } } function getSelectedRadio(groupName) { // ---------------------------------------------------------------------------- groupElements = document.getElementsByName(groupName); if (groupElements[0]) { for (var i=0; i