# File lib/action_view/helpers/upload_progress_helper.rb, line 149
      def form_tag_with_upload_progress(url_for_options = {}, options = {}, status_url_for_options = {}, *parameters_for_url_method)
        
        ## Setup the action URL and the server-side upload_status action for
        ## polling of status during the upload

        options = options.dup

        upload_id = url_for_options.delete(:upload_id) || next_upload_id
        upload_action_url = url_for(url_for_options)

        if status_url_for_options.is_a? Hash
          status_url_for_options = status_url_for_options.merge({
            :action => 'upload_status', 
            :upload_id => upload_id})
        end

        status_url = url_for(status_url_for_options)
        
        ## Prepare the form options.  Dynamically change the target and URL to enable the status
        ## updating only if javascript is enabled, otherwise perform the form submission in the same 
        ## frame.
        
        upload_target = options[:target] || upload_target_id
        upload_id_param = "#{upload_action_url.include?('?') ? '&' : '?'}upload_id=#{upload_id}"
        
        ## Externally :begin and :finish are the entry and exit points
        ## Internally, :finish is called :complete

        js_options = {
          :decay => options[:decay] || FREQUENCY_DECAY,
          :frequency => options[:frequency] || FREQUENCY,
        }

        updater_options = '{' + js_options.map {|k, v| "#{k}:#{v}"}.sort.join(',') + '}'

        ## Finish off the updating by forcing the progress bar to 100% and status text because the
        ## results of the post may load and finish in the IFRAME before the last status update
        ## is loaded. 

        options[:complete] = "$('#{status_tag_id}').innerHTML='#{escape_javascript upload_progress_text(:finish)}';"
        options[:complete] << "#{upload_progress_update_bar_js(100)};"
        options[:complete] << "#{upload_update_object} = null"
        options[:complete] = "#{options[:complete]}; #{options[:finish]}" if options[:finish]

        options[:script] = true

        ## Prepare the periodic updater, clearing any previous updater

        updater = "if (#{upload_update_object}) { #{upload_update_object}.stop(); }"
        updater << "#{upload_update_object} = new Ajax.PeriodicalUpdater('#{status_tag_id}',"
        updater << "'#{status_url}', Object.extend(#{options_for_ajax(options)},#{updater_options}))"

        updater = "#{options[:begin]}; #{updater}" if options[:begin]
        updater = "#{upload_progress_update_bar_js(0)}; #{updater}"
        updater = "$('#{status_tag_id}').innerHTML='#{escape_javascript upload_progress_text(:begin)}'; #{updater}"
        
        ## Touch up the form action and target to use the given target instead of the
        ## default one. Then start the updater

        options[:onsubmit] = "if (this.action.indexOf('upload_id') < 0){ this.action += '#{escape_javascript upload_id_param}'; }"
        options[:onsubmit] << "this.target = '#{escape_javascript upload_target}';"
        options[:onsubmit] << "#{updater}; return true" 
        options[:multipart] = true

        [:begin, :finish, :complete, :frequency, :decay, :script].each { |sym| options.delete(sym) }

        ## Create the tags
        ## If a target for the form is given then avoid creating the hidden IFRAME

        tag = form_tag(upload_action_url, options, *parameters_for_url_method)

        unless options[:target]
          tag << content_tag('iframe', '', { 
            :id => upload_target, 
            :name => upload_target,
            :src => '',
            :style => 'width:0px;height:0px;border:0' 
          })
        end

        tag
      end