<?php
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('default', "Change Password");
$this->breadcrumbs = array(
    Yii::t('default', "Change Password"),
);

$this->widget('bootstrap.widgets.TbAlert');
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'signup-form',
            'enableAjaxValidation' => false,
        ));

echo $form->passwordFieldControlGroup($model, 'current_password',array('class'=>'textField'));
echo $form->passwordFieldControlGroup($model, 'new_password',array('class'=>'textField'));?>

<span id="passstrength"></span><?php
echo $form->hiddenField($model, 'password_strength');
echo $form->passwordFieldControlGroup($model, 'password_repeat',array('class'=>'textField'));
?>

<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>