<?php
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('default', "Change Password");
$this->breadcrumbs = array(
    Yii::t('default', "Change Password"),
);
?>
<?php
$this->widget('bootstrap.widgets.TbAlert');
$form = $this->beginWidget('ext.bootstrap.widgets.TbActiveForm', array(
            'id' => 'signup-form',
            'enableAjaxValidation' => false,
        ));

echo $form->passwordFieldRow($model, 'current_password');
echo $form->passwordFieldRow($model, 'new_password');
?>
&nbsp;<span id="passstrength"></span><?php
echo $form->hiddenField($model, 'password_strength');
echo $form->passwordFieldRow($model, 'password_repeat');
?>

<div class="actions">
<?php echo CHtml::submitButton(Yii::t('default', "Save"), array('class' => 'btn')); ?>
</div>
<?php $this->endWidget(); ?>

<script language="javascript">
    $('#ChangePasswordForm_new_password').keyup(function(e) {
        var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
        var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
        var enoughRegex = new RegExp("(?=.{6,}).*", "g");
        strength = '';
        if (false == enoughRegex.test($(this).val())) {
            $('#passstrength').html('<u><span style="color:red"><?php echo Yii::t('default', 'New Password Too Short'); ?></span>');
            strength = 'too short';
        } else if (strongRegex.test($(this).val())) {
            $('#passstrength').html('<u><span style="color:blue"><?php echo Yii::t('default', 'New Password Strong'); ?></span>');
            strength = 'strong';
        } else if (mediumRegex.test($(this).val())) {
            $('#passstrength').html('<u><span style="color:green"><?php echo Yii::t('default', 'New Password Good'); ?></span>');
            strength = 'good';
        } else {
            $('#passstrength').html('<u><span style="color:orange"><?php echo Yii::t('default', 'New Password Weak'); ?></span>');
            strength = 'weak';
        }

        $("#ChangePasswordForm_password_strength").val(strength);
        return true;
    });
</script>