
############### HEADERS & FOOTERS ##################

# Note: The headers and footers are defined in terms of other variables
# as this approach makes it easier for an author to customise them.

# Define the first page header
!macro PAGE_FIRST_HEADER
!if $var{'OPT_HEADINGS'} == 1
    HEADER:[[PAGE_FIRST_HEADER_INNER1]]
    [[tab]][[PAGE_FIRST_HEADER_CENTER1]]
    [[tab]][[PAGE_FIRST_HEADER_OUTER1]]
!elsif $var{'OPT_HEADINGS'} >= 2
    HEADER:[[PAGE_FIRST_HEADER_INNER1]]
    [[tab]][[PAGE_FIRST_HEADER_CENTER1]]
    [[tab]][[PAGE_FIRST_HEADER_OUTER1]]
     [[nl]][[PAGE_FIRST_HEADER_INNER2]]
    [[tab]][[PAGE_FIRST_HEADER_CENTER2]]
    [[tab]][[PAGE_FIRST_HEADER_OUTER2]]
!endif
!endmacro

# Define the first page footer
!macro PAGE_FIRST_FOOTER
!if $var{'OPT_HEADINGS'} == 1
    FOOTER:[[PAGE_FIRST_FOOTER_INNER1]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER1]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER1]]
!elsif $var{'OPT_HEADINGS'} == 2
    FOOTER:[[PAGE_FIRST_FOOTER_INNER1]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER1]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER1]]
     [[nl]][[PAGE_FIRST_FOOTER_INNER2]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER2]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER2]]
!elsif $var{'OPT_HEADINGS'} == 3
    FOOTER[size='7pt'][[PAGE_FIRST_FOOTER_INNER1]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER1]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER1]]
     [[nl]][[PAGE_FIRST_FOOTER_INNER2]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER2]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER2]]
     [[nl]][[PAGE_FIRST_FOOTER_INNER3]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER3]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER3]]
!elsif $var{'OPT_HEADINGS'} >= 4
    FOOTER[size='7pt'][[PAGE_FIRST_FOOTER_INNER0]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER0]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER0]]
     [[nl]][[PAGE_FIRST_FOOTER_INNER1]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER1]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER1]]
     [[nl]][[PAGE_FIRST_FOOTER_INNER2]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER2]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER2]]
     [[nl]][[PAGE_FIRST_FOOTER_INNER3]]
    [[tab]][[PAGE_FIRST_FOOTER_CENTER3]]
    [[tab]][[PAGE_FIRST_FOOTER_OUTER3]]
!endif
!endmacro

# Define the right page header
!macro PAGE_RIGHT_HEADER
!if $var{'OPT_HEADINGS'} == 1
    HEADER:[[PAGE_RIGHT_HEADER_INNER1]]
    [[tab]][[PAGE_RIGHT_HEADER_CENTER1]]
    [[tab]][[PAGE_RIGHT_HEADER_OUTER1]]
!elsif $var{'OPT_HEADINGS'} >= 2
    HEADER:[[PAGE_RIGHT_HEADER_INNER1]]
    [[tab]][[PAGE_RIGHT_HEADER_CENTER1]]
    [[tab]][[PAGE_RIGHT_HEADER_OUTER1]]
     [[nl]][[PAGE_RIGHT_HEADER_INNER2]]
    [[tab]][[PAGE_RIGHT_HEADER_CENTER2]]
    [[tab]][[PAGE_RIGHT_HEADER_OUTER2]]
!endif
!endmacro

# Define the right page footer
!macro PAGE_RIGHT_FOOTER
!if $var{'OPT_HEADINGS'} == 1
    FOOTER:[[PAGE_RIGHT_FOOTER_INNER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER1]]
!elsif $var{'OPT_HEADINGS'} == 2
    FOOTER:[[PAGE_RIGHT_FOOTER_INNER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER1]]
     [[nl]][[PAGE_RIGHT_FOOTER_INNER2]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER2]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER2]]
!elsif $var{'OPT_HEADINGS'} == 3
    FOOTER[size='7pt'][[PAGE_RIGHT_FOOTER_INNER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER1]]
     [[nl]][[PAGE_RIGHT_FOOTER_INNER2]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER2]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER2]]
     [[nl]][[PAGE_RIGHT_FOOTER_INNER3]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER3]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER3]]
!elsif $var{'OPT_HEADINGS'} >= 4
    FOOTER[size='7pt'][[PAGE_RIGHT_FOOTER_INNER0]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER0]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER0]]
     [[nl]][[PAGE_RIGHT_FOOTER_INNER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER1]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER1]]
     [[nl]][[PAGE_RIGHT_FOOTER_INNER2]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER2]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER2]]
     [[nl]][[PAGE_RIGHT_FOOTER_INNER3]]
    [[tab]][[PAGE_RIGHT_FOOTER_CENTER3]]
    [[tab]][[PAGE_RIGHT_FOOTER_OUTER3]]
!endif
!endmacro

# Define the left page header
!macro PAGE_LEFT_HEADER
!if $var{'OPT_HEADINGS'} == 1
    HEADER:[[PAGE_LEFT_HEADER_INNER1]]
    [[tab]][[PAGE_LEFT_HEADER_CENTER1]]
    [[tab]][[PAGE_LEFT_HEADER_OUTER1]]
!elsif $var{'OPT_HEADINGS'} >= 2
    HEADER:[[PAGE_LEFT_HEADER_OUTER1]]
    [[tab]][[PAGE_LEFT_HEADER_CENTER1]]
    [[tab]][[PAGE_LEFT_HEADER_INNER1]]
     [[nl]][[PAGE_LEFT_HEADER_OUTER2]]
    [[tab]][[PAGE_LEFT_HEADER_CENTER2]]
    [[tab]][[PAGE_LEFT_HEADER_INNER2]]
!endif
!endmacro

# Define the left page footer
!macro PAGE_LEFT_FOOTER
!if $var{'OPT_HEADINGS'} == 1
    FOOTER:[[PAGE_LEFT_FOOTER_INNER1]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_OUTER1]]
!elsif $var{'OPT_HEADINGS'} == 2
    FOOTER:[[PAGE_LEFT_FOOTER_OUTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER1]]
     [[nl]][[PAGE_LEFT_FOOTER_OUTER2]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER2]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER2]]
!elsif $var{'OPT_HEADINGS'} == 3
    FOOTER[size='7pt'][[PAGE_LEFT_FOOTER_OUTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER1]]
     [[nl]][[PAGE_LEFT_FOOTER_OUTER2]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER2]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER2]]
     [[nl]][[PAGE_LEFT_FOOTER_OUTER3]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER3]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER3]]
!elsif $var{'OPT_HEADINGS'} >= 4
    FOOTER[size='7pt'][[PAGE_LEFT_FOOTER_OUTER0]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER0]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER0]]
     [[nl]][[PAGE_LEFT_FOOTER_OUTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER1]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER1]]
     [[nl]][[PAGE_LEFT_FOOTER_OUTER2]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER2]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER2]]
     [[nl]][[PAGE_LEFT_FOOTER_OUTER3]]
    [[tab]][[PAGE_LEFT_FOOTER_CENTER3]]
    [[tab]][[PAGE_LEFT_FOOTER_INNER3]]
!endif
!endmacro

# Macro to build the left page as a mirror of the right page
!macro left_mirror_right_page
# Copy the page layout
!define PAGE_LEFT_HEADER_BORDER   $var{'PAGE_RIGHT_HEADER_BORDER'}
!define PAGE_LEFT_HEADER_HEIGHT   $var{'PAGE_RIGHT_HEADER_HEIGHT'}
!define PAGE_LEFT_HEADER_GAP      $var{'PAGE_RIGHT_HEADER_GAP'}
!define PAGE_LEFT_FOOTER_BORDER   $var{'PAGE_RIGHT_FOOTER_BORDER'}
!define PAGE_LEFT_FOOTER_HEIGHT   $var{'PAGE_RIGHT_FOOTER_HEIGHT'}
!define PAGE_LEFT_FOOTER_GAP      $var{'PAGE_RIGHT_FOOTER_GAP'}

# Mirror the header
!define PAGE_LEFT_HEADER_INNER1   $var{'PAGE_RIGHT_HEADER_INNER1'}
!define PAGE_LEFT_HEADER_INNER2   $var{'PAGE_RIGHT_HEADER_INNER2'}
!define PAGE_LEFT_HEADER_CENTER1  $var{'PAGE_RIGHT_HEADER_CENTER1'}
!define PAGE_LEFT_HEADER_CENTER2  $var{'PAGE_RIGHT_HEADER_CENTER2'}
!define PAGE_LEFT_HEADER_OUTER1   $var{'PAGE_RIGHT_HEADER_OUTER1'}
!define PAGE_LEFT_HEADER_OUTER2   $var{'PAGE_RIGHT_HEADER_OUTER2'}

# Mirror the footer
!define PAGE_LEFT_FOOTER_INNER0   $var{'PAGE_RIGHT_FOOTER_INNER0'}
!define PAGE_LEFT_FOOTER_INNER1   $var{'PAGE_RIGHT_FOOTER_INNER1'}
!define PAGE_LEFT_FOOTER_INNER2   $var{'PAGE_RIGHT_FOOTER_INNER2'}
!define PAGE_LEFT_FOOTER_INNER3   $var{'PAGE_RIGHT_FOOTER_INNER3'}
!define PAGE_LEFT_FOOTER_CENTER0  $var{'PAGE_RIGHT_FOOTER_CENTER0'}
!define PAGE_LEFT_FOOTER_CENTER1  $var{'PAGE_RIGHT_FOOTER_CENTER1'}
!define PAGE_LEFT_FOOTER_CENTER2  $var{'PAGE_RIGHT_FOOTER_CENTER2'}
!define PAGE_LEFT_FOOTER_CENTER3  $var{'PAGE_RIGHT_FOOTER_CENTER3'}
!define PAGE_LEFT_FOOTER_OUTER0   $var{'PAGE_RIGHT_FOOTER_OUTER0'}
!define PAGE_LEFT_FOOTER_OUTER1   $var{'PAGE_RIGHT_FOOTER_OUTER1'}
!define PAGE_LEFT_FOOTER_OUTER2   $var{'PAGE_RIGHT_FOOTER_OUTER2'}
!define PAGE_LEFT_FOOTER_OUTER3   $var{'PAGE_RIGHT_FOOTER_OUTER3'}
!endmacro

# Macro to build the first page as a copy of the right page
!macro first_copy_right_page
# Copy the page layout
!define PAGE_FIRST_HEADER_BORDER $var{'PAGE_RIGHT_HEADER_BORDER'}
!define PAGE_FIRST_HEADER_HEIGHT $var{'PAGE_RIGHT_HEADER_HEIGHT'}
!define PAGE_FIRST_HEADER_GAP    $var{'PAGE_RIGHT_HEADER_GAP'}
!define PAGE_FIRST_FOOTER_BORDER $var{'PAGE_RIGHT_FOOTER_BORDER'}
!define PAGE_FIRST_FOOTER_HEIGHT $var{'PAGE_RIGHT_FOOTER_HEIGHT'}
!define PAGE_FIRST_FOOTER_GAP    $var{'PAGE_RIGHT_FOOTER_GAP'}

# Copy the header
!define PAGE_FIRST_HEADER_INNER1   $var{'PAGE_RIGHT_HEADER_INNER1'}
!define PAGE_FIRST_HEADER_INNER2   $var{'PAGE_RIGHT_HEADER_INNER2'}
!define PAGE_FIRST_HEADER_CENTER1  $var{'PAGE_RIGHT_HEADER_CENTER1'}
!define PAGE_FIRST_HEADER_CENTER2  $var{'PAGE_RIGHT_HEADER_CENTER2'}
!define PAGE_FIRST_HEADER_OUTER1   $var{'PAGE_RIGHT_HEADER_OUTER1'}
!define PAGE_FIRST_HEADER_OUTER2   $var{'PAGE_RIGHT_HEADER_OUTER2'}

# Copy the footer
!define PAGE_FIRST_FOOTER_INNER0   $var{'PAGE_RIGHT_FOOTER_INNER0'}
!define PAGE_FIRST_FOOTER_INNER1   $var{'PAGE_RIGHT_FOOTER_INNER1'}
!define PAGE_FIRST_FOOTER_INNER2   $var{'PAGE_RIGHT_FOOTER_INNER2'}
!define PAGE_FIRST_FOOTER_INNER3   $var{'PAGE_RIGHT_FOOTER_INNER3'}
!define PAGE_FIRST_FOOTER_CENTER0  $var{'PAGE_RIGHT_FOOTER_CENTER0'}
!define PAGE_FIRST_FOOTER_CENTER1  $var{'PAGE_RIGHT_FOOTER_CENTER1'}
!define PAGE_FIRST_FOOTER_CENTER2  $var{'PAGE_RIGHT_FOOTER_CENTER2'}
!define PAGE_FIRST_FOOTER_CENTER3  $var{'PAGE_RIGHT_FOOTER_CENTER3'}
!define PAGE_FIRST_FOOTER_OUTER0   $var{'PAGE_RIGHT_FOOTER_OUTER0'}
!define PAGE_FIRST_FOOTER_OUTER1   $var{'PAGE_RIGHT_FOOTER_OUTER1'}
!define PAGE_FIRST_FOOTER_OUTER2   $var{'PAGE_RIGHT_FOOTER_OUTER2'}
!define PAGE_FIRST_FOOTER_OUTER3   $var{'PAGE_RIGHT_FOOTER_OUTER3'}
!endmacro
