'Helper function to inject the document-ready-JavaScript for
this widget.
@param field: the Field
@param value: the current value
@param attr: the HTML attributes for the widget'

def inject_script(self, selector, options):

    if (not selector):
        return
    s3 = current.response.s3
    appname = current.request.application
    request = current.request
    s3 = current.response.s3
    jquery_ready = s3.jquery_ready
    datepicker_l10n = None
    timepicker_l10n = None
    calendars_type = None
    calendars_l10n = None
    calendars_picker_l10n = None
    datepicker_l10n_path = os.path.join(request.folder, 'static', 'scripts', 'ui', 'i18n')
    timepicker_l10n_path = os.path.join(request.folder, 'static', 'scripts', 'ui', 'i18n')
    calendars_l10n_path = os.path.join(request.folder, 'static', 'scripts', 'calendars', 'i18n')
    calendar = options['calendar'].lower()
    if (calendar != 'gregorian'):
        filename = ('jquery.calendars.%s.js' % calendar)
        lscript = os.path.join(calendars_l10n_path, filename)
        if os.path.exists(lscript):
            calendars_type = ('calendars/i18n/%s' % filename)
    language = current.session.s3.language
    if (language in current.deployment_settings.date_formats):
        if ('-' in language):
            parts = language.split('-', 1)
            language = ('%s-%s' % (parts[0], parts[1].upper()))
        filename = ('datepicker-%s.js' % language)
        path = os.path.join(timepicker_l10n_path, filename)
        if os.path.exists(path):
            timepicker_l10n = ('ui/i18n/%s' % filename)
        filename = ('jquery-ui-timepicker-%s.js' % language)
        path = os.path.join(datepicker_l10n_path, filename)
        if os.path.exists(path):
            datepicker_l10n = ('ui/i18n/%s' % filename)
        if ((calendar != 'gregorian') and language):
            filename = ('jquery.calendars.%s-%s.js' % (calendar, language))
            path = os.path.join(calendars_l10n_path, filename)
            if os.path.exists(path):
                calendars_l10n = ('calendars/i18n/%s' % filename)
            filename = ('jquery.calendars.picker-%s.js' % language)
            path = os.path.join(calendars_l10n_path, filename)
            if os.path.exists(path):
                calendars_picker_l10n = ('calendars/i18n/%s' % filename)
    else:
        language = ''
    options['language'] = language
    if s3.debug:
        scripts = ('jquery.plugin.js', 'calendars/jquery.calendars.all.js', 'calendars/jquery.calendars.picker.ext.js', 'S3/s3.ui.calendar.js', datepicker_l10n, timepicker_l10n, calendars_type, calendars_l10n, calendars_picker_l10n)
    else:
        scripts = ('jquery.plugin.min.js', 'S3/s3.ui.calendar.min.js', datepicker_l10n, timepicker_l10n, calendars_type, calendars_l10n, calendars_picker_l10n)
    for script in scripts:
        if (not script):
            continue
        path = ('/%s/static/scripts/%s' % (appname, script))
        if (path not in s3.scripts):
            s3.scripts.append(path)
    script = ("$('#%(selector)s').calendarWidget(%(options)s);" % {'selector': selector, 'options': json.dumps(options)})
    s3.jquery_ready.append(script)
