
/*
    Helper methods used for accordion and tool tips
*/

$(function () {
    // passenger info accordion
    $('#passengers').accordion({
        autoheight: false,
        alwaysOpen: false,
        header: 'h3'
    });
    // flight info tooltips
    $('.tooltip').tooltip();
    $('tr[id^=trigger]').tooltip({
        bodyHandler: function () {
            return $(this).next().html();
        }
    });

});

// Validate Destination Address if required
function customValidate() {

    var paxCount = document.getElementById("paxCount").innerHTML;
    var index = 0;
    var txtErrors = "";
    var staticControlPrefix = "ControlGroupPassengerChangeView_PassengerChangeInputView_";

    for (index = 0; index <= paxCount; index++) {

        var destinationAddressRequired = document.getElementById("destinationAddressRequired_" + index).innerHTML;

        if (destinationAddressRequired == 'True') {
            var arrivalStations = document.getElementById(staticControlPrefix + "DropDownListPassengerAddressArrivalStations_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Destination Airport is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "TextBoxPassengerAddressCompanyName_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Company Address is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "TextBoxPassengerAddressPhone_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Phone is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "TextBoxPassengerAddressLine1_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Address is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "DropDownListPassengerAddressProvinceState_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Province/State is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "TextBoxPassengerAddressPostalCode_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Postal Code is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "TextBoxPassengerAddressCity_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - City is required.\n"
            }
            var arrivalStations = document.getElementById(staticControlPrefix + "DropDownListPassengerAddressCountry_" + index + "_0").value;
            if (arrivalStations == "") {
                txtErrors = txtErrors + " - Country is required.\n"
            }
        }

        // Exit if errors found already
        if (txtErrors != "") {
            index = paxCount + 1;
        }

    }

    // Check error container
    if (txtErrors != "") {
        alert("Please correct the following:\n\n" + txtErrors);
        return false;
    }

    return true;

}

