/*
    Method to make an ajax call and populate a select box with a list of cities that have
    either a store or a famous project and are within a particular selected state.
    Copyright (C) 2000-2007 Kohler Company.    All Rights Reserved.
    Author: Chris O'Connell
    Date Created: 10/19/07
    @param stateSelect The ID of the select box that has the selected state
    @param citySelect the ID of the select box that needs to be populated with the list
    of cities
    @param type the type of cities, those with stores (i.e. STORES) or those
    with Famous Projects (i.e. PROJECTS).
 */
function getCitiesForState(stateSelect, citySelect, type){

    var selectedState = $(stateSelect).selectedValues();

    $(citySelect).removeOption(/./);

    if (selectedState == null || selectedState[0] == 'XXX' || selectedState == ''){
        // this means the user hasn't selected anything, so we just clear out
        // the cities and add a default


        //$(citySelect).addOption('XXX', '?');

    } else {

        $(citySelect).ajaxAddOption('/ajax/getStoreCities.cn',
                {stateName: selectedState, cityType: type}, 
                false);

    } 

}

//
// on DOM-load events
//
$(function() {

    if ($("#province")) {
        // Set the onchange event of the 'states' dropdown to call the ajax function that
        // populates the cites select.  This is in the global util nav.
        $("#province").change(
              function() {
                  getCitiesForState('#province', '#city', 'STORES');
              }
         );
     }

});