'JavaScript client-side validation for Registration / User profile
- needed to check for passwords being same, etc'

@staticmethod
def s3_register_validation():

    T = current.T
    request = current.request
    appname = request.application
    settings = current.deployment_settings
    s3 = current.response.s3
    scripts_append = s3.scripts.append
    if s3.debug:
        scripts_append(('/%s/static/scripts/jquery.validate.js' % appname))
        scripts_append(('/%s/static/scripts/jquery.pstrength.2.1.0.js' % appname))
        scripts_append(('/%s/static/scripts/S3/s3.register_validation.js' % appname))
    else:
        scripts_append(('/%s/static/scripts/jquery.validate.min.js' % appname))
        scripts_append(('/%s/static/scripts/jquery.pstrength.2.1.0.min.js' % appname))
        scripts_append(('/%s/static/scripts/S3/s3.register_validation.min.js' % appname))
    js_global = []
    js_append = js_global.append
    if settings.get_auth_registration_mobile_phone_mandatory():
        js_append('S3.auth_registration_mobile_phone_mandatory=1')
    if settings.get_auth_registration_organisation_required():
        js_append('S3.auth_registration_organisation_required=1')
        js_append(('i18n.enter_your_organisation="%s"' % T('Enter    your    organization')))
    if settings.get_auth_terms_of_service():
        js_append('S3.auth_terms_of_service=1')
        js_append(('i18n.tos_required="%s"' % T('You    must    agree    to    the    Terms    of    Service')))
    if (request.controller != 'admin'):
        if settings.get_auth_registration_organisation_hidden():
            js_append('S3.auth_registration_hide_organisation=1')
        table = current.s3db.auth_organisation
        query = ((table.organisation_id != None) & (table.domain != None))
        whitelists = current.db(query).select(table.organisation_id, table.domain)
        if whitelists:
            domains = []
            domains_append = domains.append
            for whitelist in whitelists:
                domains_append(("'%s':%s" % (whitelist.domain, whitelist.organisation_id)))
            domains = ','.join(domains)
            domains = ('S3.whitelists={%s}' % domains)
            js_append(domains)
    js_append(('i18n.enter_first_name="%s"' % T('Enter    your    first    name')))
    js_append(('i18n.provide_password="%s"' % T('Provide    a    password')))
    js_append(('i18n.repeat_your_password="%s"' % T('Repeat    your    password')))
    js_append(('i18n.enter_same_password="%s"' % T('Enter    the    same    password    as    above')))
    js_append(('i18n.please_enter_valid_email="%s"' % T('Please    enter    a    valid    email    address')))
    js_append(('S3.password_min_length=%i' % settings.get_auth_password_min_length()))
    js_append(('i18n.password_min_chars="%s"' % T('You    must    enter    a    minimum    of    %d    characters')))
    js_append(('i18n.weak="%s"' % T('Weak')))
    js_append(('i18n.normal="%s"' % T('Normal')))
    js_append(('i18n.medium="%s"' % T('Medium')))
    js_append(('i18n.strong="%s"' % T('Strong')))
    js_append(('i18n.very_strong="%s"' % T('Very    Strong')))
    script = '\n'.join(js_global)
    s3.js_global.append(script)
    s3.jquery_ready.append('s3_register_validation()')
