{if file_exists("templates/$template/includes/overwrites/pwstrength.tpl")}
    {include file="{$template}/includes/overwrites/pwstrength.tpl"}  
{else}   
    <div class="password-content password-content-group">
         <button tabindex="0" type="button" class="btn btn-default btn-sm generate-password" data-targetfields="inputNewPassword1,inputNewPassword2">
            <i class="ls ls-refresh"></i>{$LANG.generatePassword.btnLabel}
        </button>
    </div>
   
    <script type="text/javascript">
    jQuery("#inputNewPassword1").keyup(function() {


    if(typeof window.langPasswordWeak === 'undefined'){
        window.langPasswordWeak = "{$LANG.pwstrengthweak}";
    }
    if(typeof window.langPasswordModerate === 'undefined'){
        window.langPasswordModerate = "{$LANG.pwstrengthmoderate}";
    }
    if(typeof window.langPasswordStrong === 'undefined'){
        window.langPasswordStrong = "{$LANG.pwstrengthstrong}";
    }
    if(typeof window.tooShort === 'undefined'){
        {if isset($rslang)}
            window.langPasswordTooShort = "{$rslang->trans('login.at_least_pass')}";
        {else}
            window.langPasswordTooShort = "at least 5 characters";
        {/if}
    }

    {if isset($pwStrengthErrorThreshold)}
        var pwStrengthErrorThreshold = {$pwStrengthErrorThreshold};
    {else}
        var pwStrengthErrorThreshold = 50;
    {/if}
    {if isset($pwStrengthWarningThreshold)}
        var pwStrengthWarningThreshold = {$pwStrengthWarningThreshold};
    {else}
        var pwStrengthWarningThreshold = 75;
    {/if}

        var $newPassword1 = jQuery("#newPassword1");
        var pw = jQuery("#inputNewPassword1").val(),
        pwlength = (pw.length),
        maximumPasswordLength = {if isset($maximumPasswordLength) && $maximumPasswordLength != ""}{$maximumPasswordLength}{else}64{/if};
        if(pwlength > 4){
            $('#passwordStrengthBar').show();
            if(pwlength>5)pwlength=5;
            var numnumeric=pw.replace(/[0-9]/g,"");
            var numeric=(pw.length-numnumeric.length);
            if(numeric>3)numeric=3;
            var symbols=pw.replace(/\W/g,"");
            var numsymbols=(pw.length-symbols.length);
            if(numsymbols>3)numsymbols=3;
            var numupper=pw.replace(/[A-Z]/g,"");
            var upper=(pw.length-numupper.length);
            if(upper>3)upper=3;
            var pwstrength=((pwlength*10)-20)+(numeric*10)+(numsymbols*15)+(upper*10);
            if (pwstrength < 0) pwstrength = 0;
            if (pwstrength > 100) pwstrength = 100;
            
            $newPassword1.removeClass('has-error has-warning has-success');
            jQuery("#passwordStrengthBar .progress-bar").removeClass("progress-bar-danger progress-bar-warning progress-bar-success").css("width", pwstrength + "%").attr('aria-valuenow', pwstrength);

            if ((pwstrength < pwStrengthErrorThreshold) || pw.length > maximumPasswordLength) {
                $newPassword1.addClass('has-error');
                jQuery("#passwordStrengthAriaLabel").attr("aria-label", langPasswordWeak);
                jQuery("#passwordStrengthSrLabel").html(langPasswordWeak);
                jQuery("#passwordStrengthTextLabel").html(langPasswordWeak).css("color", "#be0f1a");
                jQuery("#passwordStrengthBar .progress-bar").addClass("progress-bar-danger");
            } else if (pwstrength < pwStrengthWarningThreshold) {
                $newPassword1.addClass('has-warning');
                jQuery("#passwordStrengthAriaLabel").attr("aria-label", langPasswordModerate);
                jQuery("#passwordStrengthSrLabel").html(langPasswordModerate);
                jQuery("#passwordStrengthTextLabel").html(langPasswordModerate).css("color", "#c59301");
                jQuery("#passwordStrengthBar .progress-bar").addClass("progress-bar-warning");
            } else {
                $newPassword1.addClass('has-success');
                jQuery("#passwordStrengthAriaLabel").attr("aria-label", langPasswordStrong);
                jQuery("#passwordStrengthSrLabel").html(langPasswordStrong);
                jQuery("#passwordStrengthTextLabel").html(langPasswordStrong).css("color", "#198810");
                jQuery("#passwordStrengthBar .progress-bar").addClass("progress-bar-success");
            }
        }
        else{
            $('#passwordStrengthBar').hide();

            var $progressBar = jQuery("#passwordStrengthBar .progress-bar");
            var $textLabel = jQuery("#passwordStrengthTextLabel");

            $textLabel.html(langPasswordTooShort).css("color", "");
            jQuery("#passwordStrengthSrLabel").html(langPasswordTooShort);
            jQuery("#passwordStrengthAriaLabel").attr("aria-label", langPasswordTooShort);

            $progressBar.removeClass("progress-bar-danger progress-bar-warning progress-bar-success").removeAttr('style');
            $newPassword1.removeClass('has-error has-warning has-success');
        }
        validatePassword2();
    });

    function validatePassword2() {
        var password1 = jQuery("#inputNewPassword1").val();
        var password2 = jQuery("#inputNewPassword2").val();
        var $newPassword2 = jQuery("#newPassword2");
        var maximumPasswordLength = {if isset($maximumPasswordLength) && $maximumPasswordLength != ""}{$maximumPasswordLength}{else}64{/if};

        if (password2 && password1 !== password2) {
            $newPassword2.removeClass('has-success').addClass('has-error');
            jQuery("#inputNewPassword2Msg").html('<p class="help-block" id="nonMatchingPasswordResult">{$LANG.pwdoesnotmatch|escape}</p>');
            {if !isset($noDisable)}jQuery('input[type="submit"]').attr('disabled', 'disabled');{/if}
        } else {
            if (password2 && password1.length <= maximumPasswordLength) {
                $newPassword2.removeClass('has-error').addClass('has-success');
                {if !isset($noDisable)}jQuery('input[type="submit"]').removeAttr('disabled');{/if}
            } else {
                $newPassword2.removeClass('has-error has-success');
            }
            jQuery("#inputNewPassword2Msg").html('');
        }
    }

    jQuery(document).ready(function(){
        {if !isset($noDisable)}jQuery('.using-password-strength input[type="submit"]').attr('disabled', 'disabled');{/if}
        jQuery("#inputNewPassword2").keyup(function() {
            validatePassword2();
        });
    });

    </script>
{/if}