function KeysProfileUI(user_id, send_revoke, sr_init, grant_deny, request, has_private) { 
    this.user_id = user_id;
    this.has_private = has_private;

    if (send_revoke || grant_deny) {
        if (sr_init) {
            if (this.has_private) {
                jQuery('#send_key').hide();
            }
        }
        else {
            jQuery('#revoke_key').hide();
        }
        
        this.initRevokeKey();
        
        if (this.has_private) {
            this.initSendKey();
        }
    }

    if (grant_deny && jQuery('#grant_deny').length) {
        this.initGrantRequest();
        this.initDenyRequest();
        this.grant_deny = true;
    }
    else {
        this.grant_deny = false;
    }

    if (request) {
        jQuery(jQuery.proxy(this.initRequestKey, this));
    }
};

KeysProfileUI.prototype = {
    initRequestKey: function() {
        jQuery('.request_key').click(jQuery.proxy(function() { 
            show_hide('#top_err_not_message', true);
            show_hide('#loading_top', false);
            
            jQuery.get('/index.php?c=keys&a=request', { user_id: this.user_id, ajax: 1, ts: (new Date()).getTime() }, function(data) { 
                var ajax_response = ajax_response_msg(data);
            });
            
            return false;
        }, this));
    },

    initSendKey: function() {
        jQuery('#send_key').click(jQuery.proxy(function() {
            show_hide('#top_err_not_message', true);
            show_hide('#loading_top', false);
            
            jQuery.get('/index.php?c=keys&a=grant', { user_id: this.user_id, ajax: 1, ts: (new Date()).getTime() }, function(data) { 
                var ajax_response;
                if (ajax_response = ajax_response_msg(data)) {
                    jQuery('#send_key').hide();
                    jQuery('#revoke_key').show();
                    if (jQuery('#grant_deny').length) {
                        jQuery('#grant_deny').remove();
                        jQuery('#key_request_count').html(parseInt(jQuery('#key_request_count').text(), 10) - 1);
                    }
                }
            });
            
            return false;
        }, this));
    },

    initRevokeKey: function() {
        jQuery('#revoke_key').click(jQuery.proxy(function() {
            show_hide('#top_err_not_message', true);
            show_hide('#loading_top', false);
            
            jQuery.get('/index.php?c=keys&a=revoke', { user_id: this.user_id, ajax: 1, ts: (new Date()).getTime() }, jQuery.proxy(function(data) { 
                var ajax_response;
                if (ajax_response = ajax_response_msg(data)) {
                    jQuery('#revoke_key').hide();
                    if (this.has_private) {
                        jQuery('#send_key').show();
                    }
                }
            }, this));
            
            return false;
        }, this));
    },

    initGrantRequest: function() {
        jQuery('#grant_key').click(jQuery.proxy(function(){
            show_hide('#top_err_not_message', true);
            show_hide('#loading_top', false);
            
            jQuery.get('/index.php?c=keys&a=grant', { user_id: this.user_id, ajax: 1, ts: (new Date()).getTime() }, function(data) { 
                var ajax_response;
                if (ajax_response = ajax_response_msg(data)) {
                    jQuery('#revoke_key').show();
                    jQuery('#send_key').hide();
                    jQuery('#grant_deny').remove();
                    jQuery('#key_request_count').html(parseInt(jQuery('#key_request_count').text(), 10) - 1);
                }
            });
            
            return false;
        }, this));
    },

    initDenyRequest: function() {
        jQuery('#deny_key').click(jQuery.proxy(function() { 
            show_hide('#top_err_not_message', true);
            show_hide('#loading_top', false);
            
            jQuery.get('/index.php?c=keys&a=deny', { user_id: this.user_id, ajax: 1, ts: (new Date()).getTime() }, jQuery.proxy(function(data) { 
                var ajax_response;
                if (ajax_response = ajax_response_msg(data)) {
                    jQuery('#revoke_key').hide();
                    if (!this.has_private) {
                        jQuery('#send_key').hide();
                    }
                    jQuery('#grant_deny').remove();
                    jQuery('#key_request_count').html(parseInt(jQuery('#key_request_count').text(), 10) - 1);
                }
            }, this));
            
            return false;
        }, this));
    }
};
