function setup_product_category_observers() {
    // update categories list as the brand is changed
    $('product_brand').observe('change', function(event) {
        update_product_category_select();
    });
}

function update_product_category_select() {
    product_category = $('product_category');
    category_spinner = $('category_spinner');
    error_message = 'Unable to update category list. Please try again.';
    
    new Ajax.Updater(
        product_category,
        base_url + 'admin/categories/get_by_brand/' + $('product_brand').value, {
            method: 'get',
            
            onCreate: function() {
                product_category.disable();
                category_spinner.show();
            },
            
            onSuccess: function() {
                product_category.enable();
                category_spinner.hide();
            },
            
            onException: function() {
                alert(error_message);
                category_spinner.hide();
            },
            
            onFailure: function() {
                alert(error_message);
                category_spinner.hide();
            },
        }
    );
}
