// global variables (or at least some of them....)
var canMixCabins = true;
var isRedemption = false;
var isFlexbile = false;

//Unavailable routes that should be removed from default routes
var unavailableRoutes = new Array();
//adding existing unavailable routes
unavailableRoutes = unavailableRoutes.concat(['CPTJNB', 'JNBCPT']);
//Singapore
unavailableRoutes = unavailableRoutes.concat(['SINADL', 'SINBNE', 'SINMEL', 'SINPER', 'SINSYD', 'ADLSIN', 'BNESIN', 'MELSIN', 'PERSIN', 'SYDSIN']);
//Virgin Blue
unavailableRoutes = unavailableRoutes.concat(['SYDADL', 'SYDBNE', 'SYDCBR', 'SYDMEL', 'SYDOOL', 'ADLSYD', 'BNESYD', 'CBRSYD', 'MELSYD', 'OOLSYD']);
//British Midland
unavailableRoutes = unavailableRoutes.concat(['LONAMS', 'LONLHRAMS', 'LONDUB', 'LONLHRDUB', 'LONBRU', 'LONLHRBRU','LONPMI', 'LONLHRPMI', 'LONNAP', 'LONLHRNAP', 'LONVCE', 'LONLHRVCE', 'LONHAJ', 'LONLHRHAJ', 'AMSLON', 'AMSLONLHR', 'DUBLON', 'DUBLONLHR', 'BRULON', 'BRULONLHR', 'PMILON', 'PMILONLHR', 'NAPLON', 'NAPLONLHR', 'VCELON', 'VCELONLHR','HAJLON', 'HAJLONLHR']);
/*
 * Removes the unavailable routes from default routes.
 */
function removeUnavailableRoutes() {
    for (var i = 0; i < unavailableRoutes.length; i++) {
        var unavailableRoute = unavailableRoutes[i];
        for (var j = 0; j < ourRoutes.length; j++) {
            var route = ourRoutes[j];
            if (route.departCity + route.arriveCity == unavailableRoute) {
                //remove the current route
                ourRoutes.splice(j, 1);
                break;
            }
        }
    }
}

// this is the Main function called on entry to the page
function setUp(obDepartCity, obArriveCity, obCabin, ibDepartCity, ibArriveCity, ibCabin)
{
    removeUnavailableRoutes();
    //check whether the Outbound and Inbound departure cities are in the dropdown list or not
    //if one of them are not available, set default departure cities as Gateway City and LON
    if (checkDepartCities(obDepartCity, ibDepartCity) || !isDepartCity(obDepartCity)) {
        obDepartCity = gatewayCityCode;
        defaultArrivalCity = 'LON';
        if (gatewayCityCode == 'LON') {//if Gateway Country is UK, set arrival city as NYC
            defaultArrivalCity = 'NYC';
        }
        obArriveCity = defaultArrivalCity;
        ibDepartCity = defaultArrivalCity;
        ibArriveCity = gatewayCityCode;
    }
    //If gateway city is not in the list, set defult to LON and NYC
    if (checkDepartCities(obDepartCity, ibDepartCity)) {
        obDepartCity = 'LON';
        obArriveCity = 'NYC';
        ibDepartCity = 'NYC';
        ibArriveCity = 'LON';
    }

    checkRedemption();
    //checkFlexible();

    // do the outbound stuff
    doOutboundDeparture(obDepartCity);
    var obCabinList = doOutboundArrival(obDepartCity, obArriveCity);
    doOutboundCabin(obCabin);

    // do the inbound stuff
    if (detailedBookingPage)
    {
        doInboundDeparture(ibDepartCity);
        doInboundArrival(ibDepartCity, ibArriveCity);

        doInboundCabin(ibCabin);

        // check that the cabins tally - i.e. if the inbound options are 'neither'
        // filter the outbound cabins so that they only have 'lowest' options
        checkOutboundCabins();
    }
}

// checks whether this is a redemption booking
function checkRedemption()
{
    if (detailedBookingPage)
    {
        // check for the redemption field first as the flexible field won't appear for
        // redemption bookings
        if (document.main.redemption.value == 'yes')
        {
            canMixCabins = false;
            isRedemption = true;
        }
    }
}

// checks the type of booking, whether it is must travel or flexible
function checkFlexible()
{
    if (!isRedemption && !nonBookingPage)
    {
        // first set the global variables
        if (document.main.flexible[0].checked)
        {
            checkedIndex = 0;
        }
        else
        {
            checkedIndex = 1;
        }
        if (document.main.flexible[checkedIndex].value == 'no')
        {
            canMixCabins = true;
            isFlexbile = false;
        }
        else
        {
            canMixCabins = false;
            isFlexbile = true;
        }
    }
}

// Populates the outbound departure city drop down
// Loops through all the cities, just removing the canDepart() = false ones
function doOutboundDeparture(departCity)
{

    var selected = 0;
    var optionIndex = 0;

    document.main.departure.options.length = 0;
    for (var i = 0; i < cityNames.length; i++)
    {
        var city = cityNames[i];

        if (city.canDepart) {
            document.main.departure.options.length++;
            document.main.departure.options[optionIndex++] = new Option(city.name, city.code);
        }

        if (city.code == departCity) selected = optionIndex - 1;
    }
    // set the selected one
    document.main.departure.options[selected].selected = true;


}

// Populates the outbound arrival city drop down
function doOutboundArrival(departCity, arrivalCity)
{
    // clear down the select box

    clearOptions(document.main.arrival);

    var optionIndex = 0;
    var cabinList = 0;
    var selected = 0;
    for (var i = 0; i < ourRoutes.length; i++)
    {
        var route = ourRoutes[i];
        // if this route departs from our departcity then add it
        if (route.departCity == departCity)
        {
            var cityName = getCityName(route.arriveCity)
            document.main.arrival.options[optionIndex++] = new Option(cityName, route.arriveCity);
            // check for the default and then get the cabin list from here
            if (route.arriveCity == arrivalCity)
            {
                selected = optionIndex - 1;
            }
        }
    }
    // set the selected one
    document.main.arrival.options[selected].selected = true;

    if (detailedBookingPage)
    {
        // check whether this is multi-sector or not and set the canMixCabins variable accordingly
        if (!isRedemption) checkRoutesForMultiSector();
    }
}

// populates the outbound cabin drop down
function doOutboundCabin(cabinId)
{

    var cabinList = getCabinList(true);
    // clear down the select box

    clearOptions(document.main.classType);

    var selected = 0;
    // get the array of cabins
    var cabins = cabinGroups[cabinList];
    // loop through these populating the class drop down
    for (var i = 0; i < cabins.length; i++)
    {
        var cabin = cabins[i];
        document.main.classType.options[i] = new Option(cabin.myFriendlyName, cabin.myId);
        if (cabin.myId == cabinId) selected = i;
    }
    // now set the default
    document.main.classType.options[selected].selected = true;

    // check that they tally with the inbound
    if (detailedBookingPage) checkOutboundCabins();
}

// populates the inbound departure city drop down
function doInboundDeparture(departCity)
{
    // clear the box down

    clearOptions(document.main.departureReturn);
    // add all cities except the one selected in the outbound departure drop down
    var selected = 0;
    var optionIndex = 0;

    // get outbound departure city
    var outboundDepartureCity = document.main.departure.options[document.main.departure.selectedIndex].value;

    for (var i = 0; i < cityNames.length; i++)
    {
        var city = cityNames[i];

        if (!isSameCity(city.code, outboundDepartureCity)) {
            document.main.departureReturn.options[optionIndex++] = new Option(city.name, city.code);

            if (city.code == departCity) {
                selected = optionIndex - 1;
            }
        }

    }
    // set the selected one
    document.main.departureReturn.options[selected].selected = true;
}


// populates the inbound arrival city drop down
function doInboundArrival(departCity, arrivalCity)
{
    // clear down the select box

    clearOptions(document.main.arrivalReturn);

    var optionIndex = 0;
    var cabinList = 0;
    var selected = 0;
    for (var i = 0; i < ourRoutes.length; i++)
    {
        var route = ourRoutes[i];

        // if this route departs from our departcity then add it
        if (route.departCity == departCity)
        {
            var cityName = getCityName(route.arriveCity)
            document.main.arrivalReturn.options[optionIndex++] = new Option(cityName, route.arriveCity);
            // check for the default and then get the cabin list from here
            if (route.arriveCity == arrivalCity)
            {
                selected = optionIndex - 1;
            }
        }
    }
    // set the selected one
    document.main.arrivalReturn.options[selected].selected = true;

    // check whether this is multi-sector or not and set the canMixCabins variable accordingly
    if (!isRedemption && !isFlexbile) checkRoutesForMultiSector();
}

// checks whether 2 citycodes with airport are in the same city or not
function isSameCity(cityCode, outBoundDeparture) {
    return cityCode.indexOf(outBoundDeparture.substring(0, 3)) >= 0;
}

// populates the inbound cabin drop down
function doInboundCabin(cabinId)
{

    // clear down the select box
    clearOptions(document.main.classTypeReturn);

    if (canMixCabins)
    {
        // get the outbound cabin
        var outboundCabinId = document.main.classType.options[document.main.classType.selectedIndex].value;
        var outboundCabins = cabinGroups[getCabinList(true)];
        var flexible = false;
        var neither = false;

        // now checked whether it is lowest, flexible or neither
        for (var i = 0; i < outboundCabins.length; i++)
        {
            var cabin = outboundCabins[i];
            if (cabin.myId == outboundCabinId)
            {
                if (cabin.neither == true)
                {
                    neither = true;
                }
                else
                {
                    flexible = cabin.flexible;
                }
            }
        }

        var selected = 0;
        var optionIndex = 0;
        // get the array of cabins
        var inboundCabins = cabinGroups[getCabinList(false)];
        // loop through these populating the class drop down
        for (var i = 0; i < inboundCabins.length; i++)
        {
            var cabin = inboundCabins[i];
            // if the outbound cabins are neither flexible or lowest then add only the lowest inbound options
            if (neither)
            {
                if (!cabin.flexible)
                {
                    document.main.classTypeReturn.options[optionIndex++] = new Option(cabin.myFriendlyName, cabin.myId);
                    if (cabin.myId == cabinId) selected = optionIndex - 1;
                }
            }
            else // or else filter them
            {
                if (flexible && cabin.flexible)
                {
                    document.main.classTypeReturn.options[optionIndex++] = new Option(cabin.myFriendlyName, cabin.myId);
                    if (cabin.myId == cabinId) selected = optionIndex - 1;
                }
                else if (!flexible && !cabin.flexible)
                {
                    document.main.classTypeReturn.options[optionIndex++] = new Option(cabin.myFriendlyName, cabin.myId);
                    if (cabin.myId == cabinId) selected = optionIndex - 1;
                }
            }
        }
        // now set the default
        document.main.classTypeReturn.options[selected].selected = true;
    }
    else
    {
        // can't mix cabins, inbound option must be the same as outbound

        // if either the outbound or inbound have different (non-combinable) options to each other, reduce
        // the options in the drop down with the most in till we have parity
        trimClassTypeOptions();

        // get the outbound cabin
        var outboundCabinId = document.main.classType.options[document.main.classType.selectedIndex].value;
        // get the inbound cabins
        var inboundCabins = cabinGroups[getCabinList(false)];
        // loop through these populating the class drop down
        for (var i = 0; i < inboundCabins.length; i++)
        {
            var cabin = inboundCabins[i];

            if (cabin.myId == outboundCabinId)
            {
                document.main.classTypeReturn.options[0] = new Option(cabin.myFriendlyName, cabin.myId);
                break;
            }
        }
    }
}
// trims the class type options in the case where you can't mix cabins so that they are the same
function trimClassTypeOptions()
{
    // get the one presently selected - we may need this
    var outboundSelected = document.main.classType.options.selectedIndex;

    clearOptions(document.main.classType);

    var outboundCabins = cabinGroups[getCabinList(true)];

    var inboundCabins = cabinGroups[getCabinList(false)];

    var optionIndex = 0;

    // loop through these populating the class drop down
    for (var i = 0; i < outboundCabins.length; i++)
    {
        var outboundCabin = outboundCabins[i];

        for (var j = 0; j < inboundCabins.length; j++)
        {
            var inboundCabin = inboundCabins[j];
            if (outboundCabin.myId == inboundCabin.myId)
            {
                document.main.classType.options[optionIndex++] = new Option(outboundCabin.myFriendlyName, outboundCabin.myId);
                break;
            }
        }
    }
    // set the selected one
    if (outboundSelected
            < document.main.classType.options.length) document.main.classType.options[outboundSelected].selected = true;
}
// checks that the outbound cabins tally with the inbound
// if the inbound cabins are 'neither' then filter the
// outbound for all but 'lowest' cabins
function checkOutboundCabins()
{
    var inboundCabinList = getCabinList(false);

    if (inboundCabinList != -1)
    {
        var inboundCabins = cabinGroups[inboundCabinList];

        if (inboundCabins[0].neither)
        {
            var outboundCabins = cabinGroups[getCabinList(true)];
            if (!outboundCabins[0].neither)
            {

                // clear them down
                clearOptions(document.main.classType);

                var optionIndex = 0;
                // now filter them
                for (var i = 0; i < outboundCabins.length; i++)
                {
                    var cabin = outboundCabins[i];
                    if (!cabin.flexible)
                    {
                        document.main.classType.options[optionIndex++] = new Option(cabin.myFriendlyName, cabin.myId);
                    }
                }
            }
        }
    }
}

// gets the city name from the city code
function getCityName(cityCode)
{
    var city;
    // loop through the cities till we find this one
    for (var i = 0; i < cityNames.length; i++)
    {
        city = cityNames[i];
        if (city.code == cityCode) break;
    }
    return city.name;
}

// returns the route object with this departCity and arriveCity
function getRoute(departCity, arriveCity)
{
    var route;

    // this will occur on first entry into the main booking page as the inbound cities are not set
    // when this method is first called
    if (departCity == '' || arriveCity == '')
    {
        route = -1;
    }
    else
    {
        for (var i = 0; i < ourRoutes.length; i++)
        {
            route = ourRoutes[i];
            if (route.departCity == departCity && route.arriveCity == arriveCity) break;
        }
    }
    return route;
}

// gets the cabin list number from the selected departure and arrival options
function getCabinList(outbound)
{
    // get the route
    var route;

    if (outbound)
    {
        route = getRoute(document.main.departure.options[document.main.departure.selectedIndex].value,
                document.main.arrival.options[document.main.arrival.selectedIndex].value);
    }
    else
    {
        route = getRoute(document.main.departureReturn.options[document.main.departureReturn.selectedIndex].value,
                document.main.arrivalReturn.options[document.main.arrivalReturn.selectedIndex].value);
    }

    var cabinList;

    if (route != -1)
    {
        cabinList = route.cabinList;
    }
    else
    {
        cabinList = -1;
    }

    // need to return the cabin list number
    return cabinList;
}

// --------DROP DOWN EVENT HANDLERS-------

// Outbound Departure drop down changed
function obDepChanged()
{
    // do outbound arrival cities
    var departCity = document.main.departure.options[document.main.departure.selectedIndex].value;
    doOutboundArrival(departCity, getDefaultArrival(departCity));

    // do outbound classes, inbound cities and classes if necessary
    obArrivalChanged();
}

// Outbound arrival drop down changed
function obArrivalChanged()
{
    // do outbound classes
    doOutboundCabin(document.main.classType.options[document.main.classType.selectedIndex].value);

    // if we are on the main booking page then do the inbound stuff
    if (detailedBookingPage)
    {
        // do inbound departure - set this to the same as the outbound arrival
        doInboundDeparture(document.main.arrival.options[document.main.arrival.selectedIndex].value);

        // do inbound arrival and classes - call the event as if the inbound departure has changed
        ibDepChanged();
    }
}

// update the booking class types for outbound and inbound flights
function updateClassTypes()
{

    // do outbound classes
    var outboundCabinId = 0;

    if (document.main.classType.options[document.main.classType.selectedIndex]) {
        outboundCabinId = document.main.classType.options[document.main.classType.selectedIndex].value;
    }

    doOutboundCabin(outboundCabinId);

    // if we are on the main booking page then do the inbound stuff
    if (detailedBookingPage)
    {
        // do inbound classes - call the event as if the inbound arrival has changed
        ibArrivalChanged();
    }

    // if flexible, update the class types accordingly
    var flexible = false;
    if (document.main.flexible2)  flexible = document.main.flexible2.checked;
    doJourneyType(flexible);
}

// Outbound cabins drop down has changed
function obCabinChanged()
{
    // set the inbound cabin to this one
    doInboundCabin(document.main.classType.options[document.main.classType.selectedIndex].value);
}

// Inbound departure drop down changed
function ibDepChanged()
{
    // do inbound arrival cities
    doInboundArrival(document.main.departureReturn.options[document.main.departureReturn.selectedIndex].value,
            document.main.departure.options[document.main.departure.selectedIndex].value);

    // do inbound classes
    ibArrivalChanged();

}

// Inbound arrival drop down changed
function ibArrivalChanged()
{

    // check whether we can mix cabins now
    if (!isRedemption) checkRoutesForMultiSector();

    // refresh the outbound cabins
    doOutboundCabin(document.main.classType.options[document.main.classType.selectedIndex].value);

    // do inbound cabins
    doInboundCabin(document.main.classTypeReturn.options[document.main.classTypeReturn.selectedIndex].value);

    // check that the cabins tally - i.e. if the inbound options are 'neither'
    // filter the outbound cabins so that they only have 'lowest' options
    checkOutboundCabins();
}

// the journey type radio's have been changed (flexible or must travel)
function doJourneyType(flexible)
{

    if (flexible)
    {
        canMixCabins = false;
        isFlexbile = true;
    }
    else
    {
        canMixCabins = true;
        isFlexbile = false;
    }

    // check whether the routes are mutlisector and sets the canMixCabins var accordingly
    checkRoutesForMultiSector();
    // do the inbound cabins
    doInboundCabin(document.main.classTypeReturn.options[document.main.classTypeReturn.selectedIndex].value);
}


// checks whether the routes are mutlisector and sets the canMixCabins var accordingly
// if this is Redemption Booking then it is set to false automatically so this method is ignored
function checkRoutesForMultiSector()
{
    // ignore this if we are on flexible booking as we can't mix cabins for this booking type at all
    if (!isFlexbile)
    {
        var outboundRoute = getRoute(document.main.departure.options[document.main.departure.selectedIndex].value,
                document.main.arrival.options[document.main.arrival.selectedIndex].value);
        var inboundRoute = getRoute(document.main.departureReturn.options[document.main.departureReturn.selectedIndex].value,
                document.main.arrivalReturn.options[document.main.arrivalReturn.selectedIndex].value);

        if (outboundRoute.multiSector || inboundRoute.multiSector)
        {
            canMixCabins = false;
        }
        else
        {
            canMixCabins = true;
        }
    }
}

// gets the default arrival city for this departure city
function getDefaultArrival(departCity)
{
    var arrivalCity;
    if (departCity.substring(0, 3) == 'LON')
    {
        arrivalCity = 'NYC';
    }
    else if (departCity == 'MAN')
    {
        arrivalCity = 'MCO';
    }
    else
    {
        arrivalCity = 'LON';
    }
    return arrivalCity;
}

// Clears the select box
function clearOptions(theSelect)
{

    if (theSelect.type == 'select-one')
        while (theSelect.length > 0)
            theSelect.options[0] = null;
}

// Returns the value of the city currently selected in
// whatever dropdown is passed in the parameter
function selectedCityValue(dropdownAirport)
{
    var objCity;
    var intSelected;

    eval('objCity = document.forms[0].' + dropdownAirport + ';');
    intSelected = objCity.selectedIndex;
    return objCity.options[intSelected].value;
}

// Shows a message if one or more infants are selected
function doInfantDropDownCheck()
{
    var objInfant = document.forms[0].infant;
    if (objInfant == null) return;
    var intSelected = objInfant.selectedIndex;
    var blnShow = false;

    if (objInfant != null)
    {
        if (objInfant.options[intSelected].text == '0')
            blnShow = false;
        else
            blnShow = true;
    }
    toggleInfantInfo(blnShow);
}

// Shows a message if one or more children are selected
function doChildDropDownCheck()
{
    var objChild = document.forms[0].child;
    var intSelected = objChild.selectedIndex;
    var blnShow = false;

    if (objChild != null)
    {
        if (objChild.options[intSelected].text == '0')
            blnShow = false;
        else
            blnShow = true;
    }
    toggleChildInfo(blnShow);
}

// Toggles the restricted mobility message - browser independent
function toggleRestrictedMobility(blnShow)
{
    if (blnMSIE)
    {
        eval('document.all.div_mobility.style.top = 895;');
        eval('document.all.div_mobility.style.left = 40;');
        var sVisible = (blnShow) ? "visible" : "hidden";
        eval('document.all.div_mobility.style.visibility = "' + sVisible + '";');
    }
    else if (blnDOM)
    {
        var oItem = document.getElementById("div_mobility");
        oItem.style.top = "880";
        oItem.style.left = "40";
        var sVisible = (blnShow) ? "visible" : "hidden";
        oItem.style.visibility = sVisible;
    }
}

// Toggles the infant message - browser independent
function toggleInfantInfo(blnShow)
{
    if (blnMSIE)
    {
        eval('document.all.div_infant.style.top = 935;');
        eval('document.all.div_infant.style.left = 40;');
        var sVisible = (blnShow) ? "visible" : "hidden";
        eval('document.all.div_infant.style.visibility = "' + sVisible + '";');
    }
    else if (blnDOM)
    {
        var oItem = document.getElementById("div_infant");
        oItem.style.top = "925";
        oItem.style.left = "40";
        var sVisible = (blnShow) ? "visible" : "hidden";
        oItem.style.visibility = sVisible;
    }
}

// Toggles the child message - browser independent
function toggleChildInfo(blnShow)
{
    if (blnMSIE)
    {
        eval('document.all.div_child.style.top = 965;');
        eval('document.all.div_child.style.left = 40;');
        var sVisible = (blnShow) ? "visible" : "hidden";
        eval('document.all.div_child.style.visibility = "' + sVisible + '";');
    }
    else if (blnDOM)
    {
        var oItem = document.getElementById("div_child");
        oItem.style.top = "955";
        oItem.style.left = "40";
        var sVisible = (blnShow) ? "visible" : "hidden";
        oItem.style.visibility = sVisible;
    }
}

// called when the one way option is clicked on Book 1
function doOneWay()
{
    document.main.departureReturn.disabled = true;
    document.main.arrivalReturn.disabled = true;
    document.main.returnday.disabled = true;
    document.main.returnmonth.disabled = true;
    document.main.returnyear.disabled = true;
    document.main.classTypeReturn.disabled = true;
}

// called when the return option is clicked on Book 1
function doRoundTrip()
{
    document.main.departureReturn.disabled = false;
    document.main.arrivalReturn.disabled = false;
    document.main.returnday.disabled = false;
    document.main.returnmonth.disabled = false;
    document.main.returnyear.disabled = false;
    document.main.classTypeReturn.disabled = false;
}

// removes whitespace before and after the string
function trimString(untrimmed)
{
    count = 0;
    maybeMoreSpaces = true
    while (maybeMoreSpaces)
    {
        if (untrimmed.charAt(untrimmed.length - count) == " ")
            count++;
        else
            maybeMoreSpaces = false;
    }
    // num chars to trim == count - 1
    return untrimmed.substring(0, untrimmed.length - count + 1);
}

// checks if mixed cabins are allowed
function mixedCabinsAllowed()
{
    // must be a 'must travel'search
    mustTravel = document.forms[0].flexible && document.forms[0].flexible[1].checked;
    outDeparture = document.forms[0].departure.value;
    outArrival = document.forms[0].arrival.value;
    inDeparture = document.forms[0].departureReturn.value;
    inArrival = document.forms[0].arrivalReturn.value;

    if (mustTravel)
    {
        return false;
    }
    else
    {
        // now we allow mixed classes on all must travel routes
        // return ( !isMultiSector( outDeparture, outArrival ) &&
        //         !isMultiSector( inDeparture, inArrival ) );
        return true;
    }
}

// copys an option an returns it
function copyOption(option)
{
    newOption = new Option(option.text, option.value, option.selected);
    return newOption;
}

// -------------------------- JS OBJECTS --------------------------------

// represents a city for the drop downs
function City(cd, nm, cdp)
{
    this.code = cd;
    this.name = nm;
    this.canDepart = cdp;
}

// The CabinDetails class represents info on a cabin such as cabin ID 
// (for submission to the backend) and a friendly name for display.
function CabinDetails(id, fn, flx, nei, sk)
{
    this.myId = id;
    this.myFriendlyName = fn;
    this.flexible = flx;
    this.neither = nei;
    this.sortKey = sk;
}
// The Route class represents an individiual route
function Route(dc, ac, cl, ms)
{
    this.departCity = dc;
    this.arriveCity = ac;
    this.cabinList = cl;
    this.multiSector = ms;
}
//Function to check whether the cities are in the allowed routes
function checkDepartCities(outBoundDepart, inBoundDepart) {

    if (!checkDepartCity(outBoundDepart)) {
        return true;
    }

    if (!checkDepartCity(inBoundDepart)) {
        return true;
    }
    return false;
}
//function to check city is in the departures list
function checkDepartCity(departureCityName) {

    for (var i = 0; i < ourRoutes.length; i++)
    {
        var route = ourRoutes[i];
        // if this route departs from our departcity then true
        if (route.departCity == departureCityName)
        {
            return true;
        }
    }
    return false;
}
//function to return whether city is in the list of can depart cities
function isDepartCity(cityToDepart)
{
    for (var i = 0; i < cityNames.length; i++)
    {
        var city = cityNames[i];
        if (city.code == cityToDepart) {
            if (city.canDepart) return true;
        }
    }
    return false;
}




