def calculate_pagerange(pagenumber, numpages, pagerange):
    """ Calculate the pagerange for the navigation quicklinks """
    pagerange = max(0, pagerange + pagerange % 2 - 1)
    pagerangestart = max(1, round(pagenumber - (pagerange - 1) / 2))
    pagerangeend = min(round(pagenumber + (pagerange - 1) / 2), numpages) + 1
    return int(pagerange), int(pagerangestart), int(pagerangeend)
