/**
  * Configures, and repopulates on postback, a dropdown list to manage one property of a related data item
  *
  * @param XhtmlSelect $select
  * @param string $s_validated_value
  * @param string $s_name
  * @param int $i_row_count
  * @param int $i_total_rows
  * @param bool $b_required
  * @param string $s_default_value
  * @return XhtmlSelect
  */
 protected function ConfigureSelect($select, $s_validated_value, $s_name, $i_row_count, $i_total_rows, $b_required = false, $s_default_value = '')
 {
     # Establish current status
     $b_is_add_row = is_null($i_row_count);
     $b_repopulate_add_row = (!$this->IsValid() or $this->DeleteClicked() or $this->IsUnrelatedInternalPostback());
     $select->SetXhtmlId($this->GetNamingPrefix() . $s_name . $i_row_count);
     if ($b_required) {
         $select->SetCssClass('required');
     }
     # If this is the row used to add a new related item...
     # Add a blank option only if data is not required, or there's no obvious default
     if ($b_is_add_row and (!$b_required or !strlen($s_default_value))) {
         $select->SetBlankFirst(true);
     }
     # If there is a default, set it
     if ($b_is_add_row and !$this->IsPostback() and strlen($s_default_value)) {
         $select->SelectOption($s_default_value);
     }
     # But if it's an existing row and data is required, there's no blank option...
     if (!$b_is_add_row and !$b_required) {
         $select->SetBlankFirst(true);
     }
     # If this is the row used to add a new related item...
     if ($b_is_add_row) {
         # ...if we repopulate, it'll be with the exact value posted,
         # as validation has either failed or not occurred
         if ($b_repopulate_add_row and isset($_POST[$select->GetXhtmlId()])) {
             $select->SelectOption($_POST[$select->GetXhtmlId()]);
         }
     } else {
         if ($this->IsValid()) {
             if ($this->AddClicked() and $i_row_count == $this->i_row_added) {
                 # If a new row was posted, is valid, and is now displayed here, need to get the posted value from the add row
                 $s_select_in_add_row = substr($select->GetXhtmlId(), 0, strlen($select->GetXhtmlId()) - strlen($i_row_count));
                 $select->SelectOption($_POST[$s_select_in_add_row]);
             } else {
                 # Even though the editor as a whole is valid, this row wasn't validated
                 # so just restore the previous value
                 if (isset($_POST[$select->GetXhtmlId()])) {
                     $select->SelectOption($_POST[$select->GetXhtmlId()]);
                 } else {
                     # Won't be in $_POST when page is first loaded
                     $select->SelectOption($s_validated_value);
                 }
             }
         } else {
             # Repopulate with the exact value posted, as validation has failed
             $select->SelectOption($_POST[$select->GetXhtmlId()]);
         }
     }
     # Return dropdown so that other things can be done to it - eg add a CSS class
     return $select;
 }