%
% $Id: qletter.sty,v 1.10 1999/04/17 21:58:57 ejb Exp $
% $Source: /home/ejb/tex/macros/RCS/qletter.sty,v $
% $Author: ejb $
%
% This is a .sty file specifically designed for Jay Berkenbilt's
% letters. 
%

%
% First, general page parameters...
%
\errorcontextlines=10
\raggedbottom
\setlength{\headsep}{0in}
\setlength{\topmargin}{.5in}
\setlength{\textheight}{8in}
\setlength{\oddsidemargin}{.5in}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\textwidth}{5.5in}
\setlength{\parskip}{2ex}
\setlength{\parindent}{0em}
\thispagestyle{empty}

%
% Our letter consists of the following: 
% 1.  A required from address that is always present and is not
%     modifiable except with the \qlhome command which causes
%     the home address to be used instead of the work address.
% 2.  A date that defaults to \today but can be overridden
% 3.  An optional to address
% 4.  A required opening
% 5.  A closing that defaults to ``Sincerely,''
% 6.  A signature that has a default value that can be
%     overridden.
% 7.  An optional list of enclosures.
% 8.  An optional list of carbon copies (cc)
%

%
% Specify \bigpage if you'd rather have smaller margins on the letter.
%
\newcommand{\bigpage}{
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{10in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\textwidth}{6.5in}
}

%
% Now we create some if's to use to determine whether we have any
% optional items.
%
\newif\ifqltoaddr\qltoaddrfalse
\newif\ifqlencl\qlenclfalse
\newif\ifqlcc\qlccfalse
\newif\ifqlclosing\qlclosingtrue

% We often find the need to skip halfway across  the page...
\newcommand{\halfway}{\hspace*{.5\textwidth}}

%
% Set up from address.
%
\newcommand{\ql@fromaddr}{}

%
% Then, set up defaults and establish which fields are required
%
\newcommand{\ql@date}{\today}
\newcommand{\ql@toaddr}{~}
\newcommand{\ql@opening}{\qlerror Opening must be specified}
\newcommand{\ql@closing}{Sincerely,}
\newcommand{\ql@signature}{E.\ Jay Berkenbilt}
\newcommand{\ql@encl}{~}
\newcommand{\ql@cc}{~}

% 
% Provide commands for editing above when necessary
%
\newcommand{\qldate}[1]{\renewcommand{\ql@date}{#1}}

\newcommand{\qltoaddr}[1]{
\qltoaddrtrue
\renewcommand{\ql@toaddr}{#1}
}

\newcommand{\qlwork}{
\renewcommand{\ql@fromaddr}{
Apex Data Services \\
12355 Sunrise Valley Drive, Suite 680 \\
Reston, VA 20191-3458 \\
Phone: 703-264-1300 \quad Fax: 703-264-1330 \\
Email: \texttt{ejb@apexinc.com} \\
}}

\newcommand{\qlhome}{
\renewcommand{\ql@fromaddr}{
13191 Ladybank Lane \\
Oak Hill, VA 20171-4052 \\
}}

\newcommand{\qlnoclosing}{\qlclosingfalse}

\newcommand{\qlopening}[1]{\renewcommand{\ql@opening}{#1}}
\newcommand{\qlclosing}[1]{\renewcommand{\ql@closing}{#1}}
\newcommand{\qlsignature}[1]{\renewcommand{\ql@signature}{#1}}

\newcommand{\qlencl}[1]{
\qlencltrue
\renewcommand{\ql@encl}{#1}
}

\newcommand{\qlcc}[1]{
\qlcctrue
\renewcommand{\ql@cc}{#1}
}

%
% Set up qletter environment to put everything in the right
% place.  All parameter commands should be issued before
% starting the qqletter environment.  Only the body of the
% letter should appear within the environment.
% 
\newenvironment{qletter}{

\noindent \halfway \parbox{.5\textwidth}{
\begin{flushleft}
\ql@fromaddr
\end{flushleft}
}

\vspace*{-\baselineskip}
\noindent \halfway \ql@date\relax

\ifqltoaddr 
\begin{flushleft}
\ql@toaddr
\end{flushleft}
\else
\fi

\noindent \ql@opening

}{

\ifqlclosing
\vspace*{\baselineskip}
\noindent \halfway \ql@closing

\vspace*{3\baselineskip}
\noindent \halfway \parbox{.5\textwidth}{
\begin{flushleft}
\ql@signature
\end{flushleft}
}
\else
\fi

\ifqlencl
\vspace*{\baselineskip}
\noindent encl: \ql@encl
\else
\fi 

\ifqlcc
\ifqlencl
\else
\vspace*{\baselineskip}
\fi
\noindent cc: \ql@cc
\else
\fi 

}
