<script>

    (function($) {

        var timeRangeIsAbsolute = function(earliest, latest) {
            var timeRange = new Splunk.TimeRange(earliest, latest);
            return timeRange.isAbsolute();
        };

        var showErrorMessage = function(message) {
            var $messagesUl = $('.content > form > ul');
            if($messagesUl.length === 0) {
                $messagesUl = $('<ul class="errors"></ul>').prependTo($('.content form'));
            }
            $messagesUl.empty().append($('<li></li>').text(message));

            // attempt to trigger the iframe onresize function by simulating the mouseup event
            parent.$('body').find('iframe').contents().find('body').trigger('mouseup');
        };

        $('#next-button').click(function(e) {
            e.preventDefault();
            var earliest = $('input[name="dispatch.earliest_time"]').val(),
                    latest = $('input[name="dispatch.latest_time"]').val(),
                    hasAbsoluteRange = timeRangeIsAbsolute(earliest, latest);

            if(hasAbsoluteRange) {
                showErrorMessage(_('Time range must be relative'));
            }
            else {
                $(document.forms[0]).trigger('submit')
            }
        });

    })(jQuery);

</script>