<?php
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
?>
<script type="text/javascript">
//<![CDATA[

Jsw.namespace('Admin.Views.Subscription');
Admin.Views.Subscription.changeCurrentPresubmitHandler = function(form) {
    var notConfiguredMailPlans = <?php echo Zend_Json::encode($this->notConfiguredMailPlans); ?>;
    if (
        notConfiguredMailPlans.indexOf(+document.getElementById('subscriptionInfo-servicePlan').value) !== -1
    ) {
        Jsw.messageBox.show({
            type: Jsw.messageBox.TYPE_YESNO,
            buttonTitles: {
                yes: <?php echo $this->jsLmsg('confirmationYes'); ?>,
                no: <?php echo $this->jsLmsg('confirmationNo'); ?>,
            },
            text: <?php echo $this->jsLmsg('removeMailConfirmText'); ?>,
            subtype: 'toggle',
            onYesClick: function () {
                Jsw.submit(document.getElementById(form._applyTargetId));
            }
        });
        return false;
    }
    return true;
};

Jsw.onReady(function () {
    var updateControlsState = function () {
        var addonPlanSelector = document.getElementById('subscriptionInfo-addonPlanSelector');
        if ('0' === document.getElementById('subscriptionInfo-servicePlan').value) {
            if (addonPlanSelector) {
                addonPlanSelector.closest('.form-row').style.display = 'none';
            }
            document.getElementById('subscriptionInfo-customize').checked = true;
        } else {
            if (addonPlanSelector) {
                addonPlanSelector.closest('.form-row').style.display = '';
            }
            document.getElementById('subscriptionInfo-customize').checked = false;
        }
    }

    if (document.getElementById('subscriptionInfo-servicePlan')) {
        updateControlsState();
        document.getElementById('subscriptionInfo-servicePlan').addEventListener('change', updateControlsState);
    }
});
//]]>
</script>
