/**
     * @access private
     */
    protected function _draw_scripts()
    {
        parent::_draw_scripts();
        ?>
  function upload_file_changed (ctrl)
  {
    if (ctrl.value)
    {
      ctrl.form.create_thumbnail.checked = true;
    }
  }

  function on_click_thumbnail (ctrl)
  {
    ctrl.form.thumbnail_size.disabled = ! ctrl.checked;
  }
<?php 
    }
    /**
     * @access private
     */
    protected function _draw_scripts()
    {
        parent::_draw_scripts();
        $atts = $this->_attachments();
        if (sizeof($atts)) {
            ?>
    var attachments = Array ();
    var types = Array ();
<?php 
            foreach ($atts as $att) {
                $f = $att->title_formatter();
                $f->max_visible_output_chars = 100;
                echo '    attachments ["' . $att->file_name . '"] = "' . str_replace('"', '\\"', $att->title_as_plain_text($f)) . "\";\n";
                echo '    types["' . $att->file_name . '"] = "' . $att->mime_type . "\";\n";
            }
        }
        ?>

    function on_insert_attachment ()
    {
      f = <?php 
        echo $this->js_form_name();
        ?>
;
      caption_text = attachments [f.attachments.value].replace (/"/g, "'");
      alignment = f.alignments.value;
      size = f.sizes.value;
      caption_mode = f.caption_modes.value;
      
      text = '';
      if (caption_mode == "caption")
      {
        text = ' caption="' + caption_text + '"';
      }
      else if (caption_mode == "tooltip")
      {
        text = ' title="' + caption_text + '"';
      }
      else if (caption_mode == "both")
      {
        text = ' caption="' + caption_text + '" title="' + caption_text + '"';
      }
      
      if (size == "thumbnail")
      {
        text_to_insert = '<img attachment="' + f.attachments.value + '" align="' + alignment + '"' + text + '>';
      }
      else
      {
        if (size == "100")
        {
          text_to_insert = '<img src="{att_link}' + f.attachments.value + '" align="' + alignment + '"' + text + '>';
        }
        else   
        {   
          text_to_insert = '<img src="{att_link}' + f.attachments.value + '" href="{att_link}' + f.attachments.value + '" align="' + alignment + '"' + text + ' scale="' + size + '%">';
        }
      }
      insert_text (<?php 
        echo $this->js_form_name();
        ?>
.description, text_to_insert);
    }
<?php 
    }