/**
     * Note that the HTML in $option_html should match the JavaScript version of 
     * the same HTML in js/dropdown.js (see the append_dropdown_option() function).
     * I couldn't think of a clean way to do this, but the fundamental problem is 
     * that both PHP and JS need to draw the same HTML into this form:
     * PHP draws it when an existing definition is *edited*, whereas JS draws it
     * when you dynamically *create* new dropdown options.
     *
     * @param mixed $def	nested array of existing definition.
     */
    public function get_edit_field_definition($def)
    {
        $is_checked = '';
        $is_sql_checked = '';
        $readonly_str = ' readonly="readonly"';
        if (isset($def['use_key_values']) && $def['use_key_values']) {
            $is_checked = 'checked="checked"';
            $readonly_str = '';
        }
        if (isset($def['is_sql']) && $def['is_sql']) {
            $is_sql_checked = 'checked="checked"';
        }
        // Standard
        $out = $this->format_standard_fields($def, false);
        // Options
        $out .= '
			<div class="postbox">
				<div class="handlediv" title="Click to toggle"><br /></div>
				<h3 class="hndle"><span>' . __('Options', CCTM_TXTDOMAIN) . '</span></h3>
				<div class="inside">
					<table><tr><td width="600" style="vertical-align:top">';
        // Use Key => Value Pairs?  (if not, the simple usage is simple options)
        $out .= '<input type="hidden" name="use_key_values" value="0"/>
				<div class="' . self::wrapper_css_class . '" id="use_key_values_wrapper">
				 <label for="use_key_values" class="cctm_label cctm_checkbox_label" id="use_key_values_label">' . __('Distinct options/values?', CCTM_TXTDOMAIN) . '</label>
				 <br />
				 <input type="checkbox" name="use_key_values" class="cctm_checkbox" id="use_key_values" value="1" onclick="javascript:toggle_readonly();" ' . $is_checked . '/> <span>' . $this->descriptions['use_key_values'] . '</span>
			 	</div>';
        // OPTIONS
        $option_cnt = 0;
        if (isset($def['options'])) {
            $option_cnt = count($def['options']);
        }
        // using the parse function because this got too crazy with escaping single quotes
        $hash = array();
        $hash['option_cnt'] = $option_cnt;
        $hash['delete'] = __('Delete');
        $hash['options'] = __('Options', CCTM_TXTDOMAIN);
        $hash['values'] = __('Stored Values', CCTM_TXTDOMAIN);
        $hash['add_option'] = __('Add Option', CCTM_TXTDOMAIN);
        $hash['set_as_default'] = __('Set as Default', CCTM_TXTDOMAIN);
        $tpl = '
			<script type="text/javascript">
				jQuery(function() {
					jQuery( "#dropdown_options2" ).sortable();
					// jQuery( "#dropdown_options2" ).disableSelection();
				});			
			</script>
			<table id="dropdown_options">
				<thead>
				<td scope="col" id="sorter" class=""  style="">&nbsp;</td>	
				<td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+options+]</label></td>
				<td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+values+]</label></td>
				<td>
				 <span class="button" onclick="javascript:append_dropdown_option(\'dropdown_options\',\'[+delete+]\',\'[+set_as_default+]\',\'[+option_cnt+]\');">[+add_option+]</span>
				</td>
				</thead>
				<tbody id="dropdown_options2">';
        $out .= CCTM::parse($tpl, $hash);
        // this html should match up with the js html in manager.js
        $option_html = '
			<tr id="%s">
				<td><span class="ui-icon ui-icon-arrowthick-2-n-s"></span></td>
				<td><input type="text" name="options[]" id="option_%s" value="%s"/></td>
				<td><input type="text" name="values[]" id="value_%s" value="%s" class="possibly_gray"' . $readonly_str . '/></td>
				<td><span class="button" onclick="javascript:remove_html(\'%s\');">%s</span>
				<span class="button" onclick="javascript:set_as_default(\'%s\');">%s</span></td>
			</tr>';
        $opt_i = 0;
        // used to uniquely ID options.
        if (!empty($def['options']) && is_array($def['options'])) {
            $opt_cnt = count($def['options']);
            for ($i = 0; $i < $opt_cnt; $i++) {
                // just in case the array isn't set
                $option_txt = '';
                if (isset($def['options'][$i])) {
                    $option_txt = CCTM::charset_decode_utf_8(trim($def['options'][$i]));
                }
                $value_txt = '';
                if (isset($def['values'][$i])) {
                    $value_txt = CCTM::charset_decode_utf_8(trim($def['values'][$i]));
                }
                $option_css_id = 'cctm_dropdown_option' . $opt_i;
                $out .= sprintf($option_html, $option_css_id, $opt_i, $option_txt, $opt_i, $value_txt, $option_css_id, __('Delete'), $opt_i, __('Set as Default'));
                $opt_i = $opt_i + 1;
            }
        }
        $out .= '
			</tbody>
		</table>';
        // close id="dropdown_options"
        // Display: multi-select or as multiple checkboxes
        $checkboxes_is_selected = '';
        $multiselect_is_selected = '';
        if (isset($def['display']) && $def['display'] == 'checkboxes') {
            $checkboxes_is_selected = ' selected="selected"';
        } elseif (isset($def['display']) && $def['display'] == 'multiselect') {
            $multiselect_is_selected = ' selected="selected"';
        }
        $out .= '<div class="' . self::wrapper_css_class . '" id="display_wrapper">
				 <label for="display" class="cctm_label" id="display_label">' . __('Display', CCTM_TXTDOMAIN) . '</label>
				 <select name="display" id="display">
				 	<option value="checkboxes" ' . $checkboxes_is_selected . '>' . __('Checkboxes', CCTM_TXTDOMAIN) . '</option>
				 	<option value="multiselect" ' . $multiselect_is_selected . '>' . __('Multi-select', CCTM_TXTDOMAIN) . '</option>
				 </select>
				<span class="cctm_description">' . __('Multiple options can be selected either as a series of checkboxes or as a multi-select field.', CCTM_TXTDOMAIN) . '</span>
			 	</div>';
        // Secondary Input options
        $out .= '</td><td style="vertical-align:top">
			<label class="cctm_label cctm_textarea_label" id="advanced_label">' . __('Alternate Input', CCTM_TXTDOMAIN) . '</label>
			<span>' . __('Use this input if you want to add options in bulk. 
				Separate options and values using double-pipes "||" with the visible option on the left, the corresponding value
				to be stored on the right (if present).  You may also enter a valid MySQL query. This field overrides 
				other inputs!', CCTM_TXTDOMAIN) . '</span><br/>
			<textarea name="alternate_input" id="alternate_input" cols="50" rows="10">' . CCTM::get_value($def, 'alternate_input') . '</textarea>';
        // Execute as MySQL?
        $out .= '<div class="' . self::wrapper_css_class . '" id="is_sql_wrapper">
				<input type="hidden" name="is_sql" value="0"/>
				 <input type="checkbox" name="is_sql" class="cctm_checkbox" id="is_sql" value="1"' . $is_sql_checked . '/> 				 <label for="is_sql" class="cctm_label cctm_checkbox_label" id="is_sql_label">' . __('Execute as a MySQL query?', CCTM_TXTDOMAIN) . '</label> <span>' . __('Select up to 2 columns: the 1st column will be the visible label and the 2nd column (if present) will represent the value stored in the database. 
				 	Use [+table_prefix+] instead of hard-coding your WordPress database table prefix.', CCTM_TXTDOMAIN) . '</span>
			 	</div>';
        $out .= '
					</td></tr></table>		
				</div><!-- /inside -->
			</div><!-- /postbox -->';
        // Validations / Required
        $out .= $this->format_validators($def, false);
        // Output Filter
        $out .= $this->format_available_output_filters($def);
        return $out;
    }