//dispatch sets up setting panel for panel type of domaininfo
var certinfo_dispatch = function(){
    if ( packagemanager.permissions.cansave == true ) {
        // (re)assign certificate id
        if ( $('#certid').length > 0 ) {

            $('#certid')
            .wrap('<div class="d-flex align-items-center gap-2 mb-3"></div>')
            .after(
                '<button id="reassignbutton" class="btn btn-outline-secondary" type="button">' +
                    '<span>' + clientexec.lang('Reassign') + '</span>' +
                '</button>'
            );



            // btn = $('<button id="reassignbutton" style="margin-left: 5px" class="rich-button">Reassign</button>');
            // $('#certid').after(btn);

            $('#reassignbutton').click(function(e){
                e.preventDefault();
                 RichHTML.prompt('Please enter the certificate id:',{allowblank:true},certinfoAssignCertId);
            });
        }

        var appendee = '#status';
        if ($('#csr').length > 0) {
            appendee = '#csr';
        }

        $(appendee)
        .wrap('<div class="mb-3 position-relative"></div>')
        .after(
            '<div class="d-flex justify-content-center mt-2">' +
                '<button id="viewCSRDetails" class="btn btn-outline-secondary" type="button">' +
                    clientexec.lang('CSR Details') +
                '</button>' +
            '</div>'
        );


        $('#viewCSRDetails').click(function(e){
            e.preventDefault();
            viewDetailsWindow = new RichHTML.window({
                height: '200',
                width : '350',
                url   : 'index.php?fuse=clients&controller=userprofile&view=viewcsrdetails&id=' + packagemanager.package_id,
                title : clientexec.lang('CSR Details')
            });
            viewDetailsWindow.show();
        });
    }
}

function certinfoAssignCertId(response){
    if ( response.btn == clientexec.lang('OK') ) {

        $('#certid').removeAttr('disabled');
        $('#certid').val(response.elements.value);
        $('#btnUpdateProduct').click();

    }
}