% ##############################################################################
% ### Header and Footer Page
% ##############################################################################

\pagestyle{fancyplain}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\renewcommand{\plainheadrulewidth}{0.5pt}
\renewcommand{\plainfootrulewidth}{0.5pt}
\setcounter{page}{1}

\def\releasebox{%
  \ifthenelse{\equal{\DBKreleaseinfo}{}}{}%
  {\framebox{\textsc{\textsf{\DBKreleaseinfo}}}}%
}

% Define front/main/back matter if not available
\@ifundefined{frontmatter}{
  \def\frontmatter{\cleardoublepage\pagenumbering{roman}\chead[]{\DBKcheadfront}}
}{}
\@ifundefined{mainmatter}{
  \def\mainmatter{\cleardoublepage\pagenumbering{arabic}\chead[]{\DBKcheadbody}}
}{}
\@ifundefined{backmatter}{
  \def\backmatter{\if@openright\cleardoublepage\else\clearpage\fi}
}{}


% Fancy header/footer for the first page

\chead[]{%
  \begin{tabular}{
    >{\raggedright}p{5.6cm} >{\centering}p{5.6cm} >{\raggedleft}p{5.6cm}} %
    \multirow{3}{5.6cm}{\DBKtitle}
    & & \tabularnewline%
    & \releasebox
    & \textsf{\thepage} \tabularnewline %
    & & \tabularnewline%
  \end{tabular}%
} %

\lfoot[]{\@ifundefined{DBKpublisher}{}{\DBKpublisher}}
\rfoot[]{}
\cfoot[]{}

% Fancy header/footer for the front matter

\def\DBKcheadfront{%
  \begin{tabular}{
    >{\raggedright}p{5.6cm} >{\centering}p{5.6cm} >{\raggedleft}p{5.6cm}} %
    \multirow{3}{5.6cm}{\DBKtitle}
    & & \textsf{\DBKreference{} \edhead} \tabularnewline%
    & \releasebox & \tabularnewline %
    & & \textsf{\thepage}
  \tabularnewline%
  \end{tabular}%
}

% Fancy header/footer for the doc body

\def\DBKcheadbody{%
  \begin{tabular}{
    >{\raggedright}p{5.6cm} >{\centering}p{5.6cm} >{\raggedleft}p{5.6cm}} %
    \multirow{3}{5.6cm}{\DBKtitle}
    & & \textsf{\DBKreference{} \edhead} \tabularnewline%
    & \releasebox & \tabularnewline %
    & & \textsf{\thepage{} / \getpagerefnumber{LastPage}}
  \tabularnewline%
  \end{tabular}%
}

\lhead[]{}
\rhead[]{}

