Index: modules/book/book.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.module,v
retrieving revision 1.436
diff -u -p -r1.436 book.module
--- modules/book/book.module	19 Aug 2007 08:08:44 -0000	1.436
+++ modules/book/book.module	20 Aug 2007 16:15:33 -0000
@@ -385,15 +385,12 @@ function _book_parent_select($book_link)
     $form['#prefix'] .= '<em>'. t('No book selected.') .'</em>';
   }
   else {
-    // If the item has children, there is an added limit to the depth of valid parents.
-    $limit = MENU_MAX_DEPTH - 1 - ($book_link['has_children'] ? menu_link_children_relative_depth($book_link) : 0);
-
     $form = array(
       '#type' => 'select',
       '#title' => t('Parent item'),
       '#default_value' => $book_link['plid'],
       '#description' => t('The parent page in the book. The maximum depth for a book and all child pages is !maxdepth.  Some pages in the selected book may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
-      '#options' => book_toc($book_link['bid'], array($book_link['mlid']), $limit),
+      '#options' => book_toc($book_link['bid'], array($book_link['mlid']), $book_link['parent_depth_limit']),
       '#attributes' => array('class' => 'book-title-select'),
     );
   }
@@ -422,7 +419,7 @@ function _book_add_form_elements(&$form,
     '#tree' => TRUE,
     '#attributes' => array('class' => 'book-outline-form'),
   );
-  foreach (array('menu_name', 'mlid', 'nid', 'router_path', 'has_children', 'options', 'module', 'original_bid') as $key) {
+  foreach (array('menu_name', 'mlid', 'nid', 'router_path', 'has_children', 'options', 'module', 'original_bid', 'parent_depth_limit') as $key) {
     $form['book'][$key] = array(
       '#type' => 'value',
       '#value' => $node->book[$key],
@@ -442,7 +439,7 @@ function _book_add_form_elements(&$form,
   $options = array();
   $nid = isset($node->nid) ? $node->nid : 'new';
 
-  if (isset($node->nid) && ($nid == $node->book['original_bid']) && $node->book['has_children'] && (MENU_MAX_DEPTH - 1 - menu_link_children_relative_depth($node->book) == 0)) {
+  if (isset($node->nid) && ($nid == $node->book['original_bid']) && ($node->book['parent_depth_limit'] == 0)) {
     // This is the top level node in a maximum depth book and thus cannot be moved.
     $options[$node->nid] = $node->title;
   }
@@ -499,6 +496,10 @@ function book_outline_form(&$form_state,
   else {
     $node->book['original_bid'] = $node->book['bid'];
   }
+  // Find the depth limit for the parent select.
+  if (!isset($node->book['parent_depth_limit'])) {
+    $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
+  }
   $form['#node'] = $node;
   $form['#id'] = 'book-outline';
   _book_add_form_elements($form, $node);
@@ -901,11 +902,22 @@ function book_nodeapi(&$node, $op, $teas
           $node->book['original_bid'] = $node->book['bid'];
         }
       }
+      // Find the depth limit for the parent select.
+      if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) {
+        $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
+      }
       break;
   }
 }
 
 /**
+ * Find the depth limit for items in the parent select.
+ */
+function _book_parent_depth_limit($book_link) {
+  return MENU_MAX_DEPTH - 1 - (($book_link['mlid'] && $book_link['has_children']) ? menu_link_children_relative_depth($book_link) : 0);
+}
+
+/**
  * Form altering function for the confirm form for a single node deletion.
  */
 function book_form_node_delete_confirm_alter(&$form, $form_state) {
Index: modules/menu/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v
retrieving revision 1.135
diff -u -p -r1.135 menu.module
--- modules/menu/menu.module	19 Aug 2007 08:08:44 -0000	1.135
+++ modules/menu/menu.module	20 Aug 2007 16:15:33 -0000
@@ -403,7 +403,12 @@ function menu_edit_item_submit($form, &$
 function menu_parent_options($menus, $item) {
 
   // If the item has children, there is an added limit to the depth of valid parents.
-  $limit = MENU_MAX_DEPTH - 1 - (($item['mlid'] && $item['has_children']) ? menu_link_children_relative_depth($item) : 0);
+  if (isset($item['parent_depth_limit'])) {
+    $limit = $item['parent_depth_limit'];
+  }
+  else {
+    $limit = _menu_parent_depth_limit($item);
+  }
 
   foreach ($menus as $menu_name => $title) {
     $tree = menu_tree_all_data($menu_name, NULL);
@@ -729,11 +734,22 @@ function menu_nodeapi(&$node, $op) {
         // Set default values.
         $node->menu = $item + array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu_name, 'weight' => 0, 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0, 'customized' => 0);
       }
+      // Find the depth limit for the parent select.
+      if (!isset($node->menu['parent_depth_limit'])) {
+        $node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
+      }
       break;
   }
 }
 
 /**
+ * Find the depth limit for items in the parent select.
+ */
+function _menu_parent_depth_limit($item) {
+  return MENU_MAX_DEPTH - 1 - (($item['mlid'] && $item['has_children']) ? menu_link_children_relative_depth($item) : 0);
+}
+
+/**
  * Implementation of hook_form_alter(). Adds menu item fields to the node form.
  */
 function menu_form_alter(&$form, $form_state, $form_id) {
@@ -764,7 +780,7 @@ function menu_form_alter(&$form, $form_s
       $form['menu']['#collapsed'] = TRUE;
     }
 
-    foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden') as $key) {
+    foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden', 'parent_depth_limit') as $key) {
       $form['menu'][$key] = array('#type' => 'value', '#value' => $item[$key]);
     }
 
