## This code will reset the tab focus after a user has used the "to-top" module from Sitevision

## It needs to be written in velocity since Sitevisions script module will only execute the 
## velocity code on the client side. If JavaScript would be used it would be executed on the
## server side and hence not work.

<script type="text/javascript">
  document.addEventListener('DOMContentLoaded', function() {
    const topLink = document.getElementById('sv-to-top');
    let focusDoToContentNext = false; // Flag to indicate the next element to focus

    if (topLink) {
        topLink.addEventListener('click', function() {
            focusDoToContentNext = true; // Set the flag when sv-to-top is clicked
        });
    }

    document.addEventListener('keydown', function(event) {
        if (focusDoToContentNext && event.key === 'Tab') {
            event.preventDefault(); // Prevent the default tabbing behavior
            const doToContentElement = document.querySelector('.do-to-content');
            if (doToContentElement) {
                doToContentElement.focus(); // Set the focus to do-to-content
                focusDoToContentNext = false; // Reset the flag
            }
        }
    });
});

</script>
