
    var currentCityList = "";
    currentCityList = getCityList(cityCodes, cityNames);

    var from1 = new PopupWindow("citydiv");
    from1.offsetX=60;
    from1.offsetY=0;
    //from1.autoHide();
    var from1input=null;

    var to1 = new PopupWindow("citydiv");
    to1.offsetX=60;
    to1.offsetY=0;
    //to1.autoHide();
    var to1input=null;

    function getCityList(cityCodesArray, cityNamesArray)
    {
        var cityList = '';
        for ( cityIndex = 0; cityIndex < cityCodesArray.length; cityIndex++ )
        {
            cityList += '<option value="' + cityCodesArray[cityIndex] + '">' + cityNamesArray[cityIndex] + ' - ' + cityCodesArray[cityIndex] + '</option>';
        }

        return cityList;
    }

    function from1activate(obj,anchor,populate)
    {
        if (populate)
        {
            currentCityList = getCityList(cityCodes, cityNames);
        }

        from1input=obj;
        from1.populate('<SELECT NAME="selFrom1" onChange="from1pick(this.options[this.selectedIndex].value);">' + '<option>Please select a from city</option>' + currentCityList + '</SELECT>');
        from1.showPopup(anchor);
    }

    function from1pick(val)
    {
        from1input.value = val;
        from1.hidePopup();
    }

    function to1activate(obj,anchor, populate)
    {
        if (populate)
        {
            currentCityList = getCityList(cityCodes, cityNames);
        }
        to1input=obj;
        to1.populate('<SELECT NAME="selTo1" onChange="to1pick(this.options[this.selectedIndex].value);">' + '<option>Please select a to city</option>' + currentCityList + '</SELECT>');
        to1.showPopup(anchor);
	}

    function to1pick(val)
    {
        to1input.value = val;
        to1.hidePopup();
	}

    function validateCity(city, cityText, showAlert)
    {
        //
        // Validate a City
        //
        var valid = false;
        var possibleCityCodes = new Array();
        var possibleCityNames = new Array();
        var possibleCount = 0;

        //
        // First check city codes
        //
        for ( cityIndex = 0; cityIndex < cityCodes.length; cityIndex++ )
        {
            if ( cityCodes[cityIndex].toUpperCase().indexOf(city.value.toUpperCase()) != -1)
            {
                possibleCityCodes.push(cityCodes[cityIndex]);
                possibleCityNames.push(cityNames[cityIndex]);
                possibleCount++;
                lastGoodCode = cityCodes[cityIndex];
            }
        }

        //
        // If there's one match for city code, use it
        // If not, scan the city names
        //
        if ( possibleCount != 1 )
        {
            for ( cityIndex = 0; cityIndex < cityCodes.length; cityIndex++ )
            {
                if ( cityNames[cityIndex].toUpperCase().indexOf(city.value.toUpperCase()) != -1)
                {
                    possibleCityCodes.push(cityCodes[cityIndex]);
                    possibleCityNames.push(cityNames[cityIndex]);
                    possibleCount++;
                    lastGoodCode = cityCodes[cityIndex];
                }
            }
        }

        if ( possibleCount == 1 )
        {
            city.value = lastGoodCode;
        }

        //
        // Zero matches, give them the full list
        // One match, use it
        // More than one, make them choose
        //
        switch ( possibleCount )
        {
            case 0:
                if (showAlert) alert("City Not Found, Please select a valid " + cityText + " city");
                if ( cityText == "To" )
                {
                    to1activate(document.forms['selectForm'].to1,'to1anchor', false)
                }
                else
                {
                    from1activate(document.forms['selectForm'].from1,'from1anchor', false)
                }
                return false;
                break;

            case 1:
                return true;
                break;

            default:
                if (showAlert) alert("Multiple " + cityText + " cities found, Please select one");
                currentCityList = getCityList(possibleCityCodes, possibleCityNames);
                if ( cityText == "To" )
                {
                    to1activate(document.forms['selectForm'].to1,'to1anchor', false)
                }
                else
                {
                    from1activate(document.forms['selectForm'].from1,'from1anchor', false)
                }
                return false;
                break;
        }

        return true;

    }

    function validateTo(showAlert)
    {
        return validateCity(document.forms['selectForm'].to1, "To", showAlert);
    }

    function validateFrom(showAlert)
    {
        return validateCity(document.forms['selectForm'].from1, "From", showAlert);
    }


    function validateCities()
    {
        if (!validateFrom(true))
        {
            return false;
        }

        if (!validateTo(true))
        {
            return false;
        }
    }

