<?php
// Copyright 1999-2022. Plesk International GmbH. All rights reserved.
?>
<script type="text/javascript">
    //<![CDATA[
    Jsw.onReady(function() {
        var backupPasswordSourceChanged = function () {
            var useBackupPasswordCheckbox = document.getElementById('securitySettings-useBackupPasswordCheckbox');
            var backupPasswordManualInput = document.getElementById('securitySettings-backupPasswordSource-backupPasswordManualInput');

            [
                document.getElementById('securitySettings-backupPasswordSource-backupPasswordFromFtpSettings'),
                backupPasswordManualInput
            ].forEach(function (element) {
                if (element) {
                    if (useBackupPasswordCheckbox.checked) {
                        element.disabled = false;
                    } else {
                        element.disabled = true;
                    }
                }
            });

            [
                document.getElementById('securitySettings-backupPassword'),
                document.getElementById('securitySettings-confirmBackupPassword')
            ].forEach(function (element) {
                if (element) {
                    if (useBackupPasswordCheckbox.checked && (!backupPasswordManualInput || backupPasswordManualInput && backupPasswordManualInput.checked)) {
                        element.disabled = false;
                    } else {
                        element.disabled = true;
                    }
                }
            });
        };

        [
            document.getElementById('securitySettings-useBackupPasswordCheckbox'),
            document.getElementById('securitySettings-backupPasswordSource-backupPasswordFromFtpSettings'),
            document.getElementById('securitySettings-backupPasswordSource-backupPasswordManualInput')
        ].forEach(function (element) {
            if (element) {
                element.addEventListener('click', backupPasswordSourceChanged);
            }
        });
        backupPasswordSourceChanged();
    });
    //]]>
</script>
