var CambiarClave = {
    maxLength: 32,
    minLength: 8,
    idAdmin: 1,

    init: function() {
        UsrAdmin.bindCheckPasswordStrength();

        $('#cambiarClave').on('click', function() {
            CambiarClave.guardarChgPass();
        });

        // validaciones cambio de clave header
        $('#show_password_head').on('click', function (e) {
            e.preventDefault();
            var $element = $('#psw1_head');
            if ($element.attr('type') == 'text') {
                $element.attr('type', "password");
            } else {
                $element.attr('type', "text");
            }
        });
    },
    // -------------------------------------------------------------------------
    guardarChgPass: function () {

        var configAjax = {
            formSelector: '#frmCambiarClave',
            actionURL: '/' + Admin.dir_cgi_cpn + '/prontus_usr_chgpass_sbmit.cgi'
        };

        var optsAjax = {
            success: function (json) {
                if (json.status == '1' && json.msg === '') {
                    window.location.href = '/' + Admin.dir_cgi_cpn + '/prontus_logout.cgi?_prontus_id=' + Admin.prontus_id;
                } else if (json.status == '1' && json.msg !== '') {
                    showModalAlert({
                        title: 'Resultado',
                        type: 'green',
                        msg: json.msg
                    });
                    window.location.href = '/' + Admin.dir_cgi_cpn + '/prontus_logout.cgi?_prontus_id=' + Admin.prontus_id;
                } else if (json.status == '0') {
                    showModalAlert({
                        title: 'Error de servidor',
                        type: 'red',
                        msg: json.msg
                    });
                }
            }, // success
            complete: function () {
                /* Cargando... */
            }
        };

        SubmitForm.submitGenericAjax(configAjax, optsAjax);
    }
};
$(document).ready(function () {
    CambiarClave.init();
});
