
<HTML>
<HEAD>
  <TITLE>Personnel Office Mailer</TITLE>
  <!--- Apply simple CSS formatting to <TH> cells --->
  <STYLE>
    TH {background:blue;color:white;
        font-family:sans-serif;font-size:12px;
        text-align:right;padding:5px;}
  </STYLE>

  <!--- Function to guess email based on first/last name --->  
  <SCRIPT LANGUAGE="JavaScript">
    function guessEmail() {
      var guess;
      
      with (document.mailForm) {
        guess = FirstName.value.substr(0,1) + LastName.value;
        ToAddress.value = guess.toLowerCase();
      };
    };
  </SCRIPT>
</HEAD>

<!--- Put cursor in FirstName field when page loads --->
<BODY <CFIF NOT IsDefined("FORM.Subject")>
        onLoad="document.mailForm.FirstName.focus()"
      </CFIF>>

<!--- If the user is submitting the form... --->
<CFIF IsDefined("FORM.Subject")>
  <CFSET RecipEmail = ListFirst(FORM.ToAddress, "@") & "@orangewhipstudios.com">

  <!--- We do not want ColdFusion to suppress whitespace here --->
  <CFPROCESSINGDIRECTIVE SUPPRESSWHITESPACE="No">

  <!--- Send the mail message, based on form input --->
  <CFMAIL
    SUBJECT="#Form.Subject#"
    FROM="""Personnel Office"" <personnel@orangewhipstudios.com>"
    TO="""#FORM.FirstName# #FORM.LastName#"" <#RecipEmail#>"
    BCC="personneldirector@orangewhipstudios.com"
>This is a message from the Personnel Office:

#UCase(FORM.Subject)#

#FORM.MessageBody#

If you have any questions about this message, please
write back or call us at extension 352.  Thanks!</CFMAIL>

  </CFPROCESSINGDIRECTIVE>
  
  <!--- Display "success" message to user --->
  <P>The email message was sent.<BR>
  By the way, you look fabulous today. 
  You should be in pictures!<BR>

<!--- Otherwise, display the form to user... --->  
<CFELSE>
  <!--- Provide simple form for recipient and message --->
  <CFFORM ACTION="#CGI.SCRIPT_NAME#" NAME="mailForm" METHOD="POST">
    
    <TABLE CELLPADDING="2" CELLSPACING="2">
      <!--- Table row: Input for Recipient's Name --->
      <TR>
        <TH>Recipient's Name:</TH>
        <TD>
          <CFINPUT
            TYPE="Text"
            NAME="FirstName"
            REQUIRED="Yes"
            SIZE="15"
            MESSAGE="You must provide a first name."
            onChange="guessEmail()">
        
          <CFINPUT
            TYPE="Text"
            NAME="LastName"
            REQUIRED="Yes"
            SIZE="20"
            MESSAGE="You must provide a first name."
            onChange="guessEmail()">
        </TD>
      </TR>

      <!--- Table row: Input for Email Address --->
      <TR>
        <TH>E-Mail Address:</TH>
        <TD>
          <CFINPUT 
            TYPE="Text" 
            NAME="ToAddress"
            REQUIRED="Yes"
            SIZE="20"
            MESSAGE="You must provide the recipient's e-mail.">@orangewhipstudios.com
        </TD>
      </TR>
    
      <!--- Table row: Input for E-mail Subject --->
      <TR>
        <TH>Subject:</TH>
        <TD>
          <CFSELECT
            NAME="Subject">
            <OPTION>Sorry, but you have been fired.
            <OPTION>Congratulations! You got a raise!
            <OPTION>Just FYI, you have hit the glass ceiling.
          </CFSELECT>  
        </TD>
      </TR>

      <!--- Table row: Input for actual Message Text --->
      <TR>
        <TH>Your Message:</TH>
        <TD>
          <TEXTAREA
            NAME="MessageBody"
            COLS="50"
            ROWS="5"
            WRAP="Hard"></TEXTAREA>
           
        </TD>
      </TR>

      <!--- Table row: Submit button to send message --->
      <TR>
        <TD></TD>
        <TD>
          <INPUT
            TYPE="Submit"
            VALUE="Send Message Now">
        </TD>
      </TR>
    </TABLE>
  </CFFORM>
</CFIF>  

</BODY>
</HTML>

