// File: cacpgh.js
// Description: Miscellaneous JavaScript used in CAC of Pittsburgh website, www.cacpittsburgh.org


//////////// function MakeEmailAddr ////////////
// Purpose: Used to avoid e-mail address detection by crawlers. Assembles an address from passed values.
function MakeEmailAddr(usr, dom, tld)
{
   addr = usr + '@' + dom + '.' + tld;
   return(addr);
}
//////////// END function MakeEmailAddr ////////////


//////////// function SetValues ////////////
// Purpose: Sets and/or modifies values of a message-sending form, upon submission.
function SetValues()
{
   // filter "," and ";" from realname to avoid recipient address corruption upon sending
   rgExp = /,|;/g;
   msgform.realname.value = msgform.realname.value.replace(rgExp, '~');
   // add newline at beginning of message field, for output readability, unless one is already present
   if (!msgform.message.value.match(/^(\n|\r)/))
      msgform.message.value = '\n' + msgform.message.value;
   // assemble fragmented script file name to avoid crawler detection
   msgform.action = '/cg'+'i-bi'+'n/msg_cacp'+'ittsburgh.p'+'l';
   // provide a dummy value for realname and email, unless it is a required field
   if (!msgform.realname.value && !msgform.required.value.match(/.*realname.*/))
      msgform.realname.value = 'anonymous website visitor';
   if (!msgform.email.value && !msgform.required.value.match(/.*email.*/))
   {
      msgform.realname.value += ' - NO E-MAIL';
      msgform.email.value = MakeEmailAddr('unspecified_address', 'cacpittsburgh', 'org');  // DEFAULT SENDER ADDRESS
   }
}
//////////// END function SetValues ////////////


//////////// function Messenger ////////////
// Purpose: Opens a window containing a form for sending a message to a CAC official from the website
// Arguments:
//    recipient - alias of recipient of message (must me defined in fm_cacpittsburgh.pl)
//    subject - text to appear as subject of message
// Implementation:
// 1) In calling page <HEAD>:
//    <script type="text/javascript" src="./cacpgh.js" language="JavaScript">
//    function Messenger() {}
//    </script>
// 2) In calling page <HTML>:
//    <button class="contact" onClick="javascript:Messenger('Recipient','Subject');">Contact Recipient</button>
// Requirements:
// 1) Page messenger.htm, containing form to send message by e-mail
function Messenger(recipient, subject)
{
   messengerPage = new Object;
   messengerPage.src = '/messenger.htm';
   messengerPage.recipient = recipient;
   messengerPage.subject = subject;
   messenger = window.open(messengerPage.src,'messengerWindow','menubar=0,toolbar=0,status=0,width=520,height=460');
   messenger.focus();
}
//////////// END function Messenger ////////////


//////////////////////// !!!! BEGIN OBSOLETE !!!! ////////////////////////
//////////// FUNCTIONS MailSend and MailSendExt BELOW ARE NOW OBSOLETE! ////////////

//////////// function MailSend ////////////
// Purpose: Composes e-mail (mailto:) link and opens e-mail message composition window.
//    Used as replacement for conventional e-mail link, to prevent detection of addresses
//    resulting in spam and other abuse.
// Requirements: Web pages containing mailto: links must include the following:
//    1) Reference to this file in a SCRIPT block in the page HEAD:
// <script type="text/javascript" src="./cacpgh.js" language="JavaScript">
// function MailSend() {}
// </script>
//    2) Each typical mailto: link replaced with code of the following form:
// <a href="JavaScript:MailSend('acct','domain');">acct&#173;@&#173;domain</a>
//       where "acct" is the portion of the address to the left of the @ character, and
//          "domain" is the portion to the right (may be empty string if default as set below).
//       Note: &#173; is soft hyphen character & usually does not display anything;
//          it provides additional protection from detection for abuse.

function MailSend(acct, domain)
{
   if (domain == '') domain = 'cacpittsburgh.org';   // default domain
   url = 'mailto:' + acct + '@' + domain;
   (window.open(url));
}

//////////// function MailSendExt ////////////
// Purpose: Same as MailSend, with addition of extension of address for CC:, SUBJECT:, etc.
// Requirements: Same as MailSend, except:
//    1) Reference to this file in a SCRIPT block in the page HEAD:
// <script type="text/javascript" src="./cacpgh.js language="JavaScript"">
// function MailSendExt() {}
// </script>
//    If function MailSend is also used, add the function line within the script block for MailSend.
//    2) Each typical mailto: link replaced with code of the following form:
// <a href="JavaScript:MailSend('acct','domain', ext);">acct&#173;@&#173;domain</a>
//       where "ext" is the portion of the address to the right of the ? character.
//       NOTE: for membership info requests from request.htm, the value of "ext" is "InfoRequest".

function MailSendExt(acct, domain, ext)
{
   // default domain
   if (domain == '') domain = 'cacpittsburgh.org';
   // membership request e-mail
   if (ext == 'InfoRequest') ext = 'SUBJECT=CAC%20Membership%20Inquiry&BODY=Please%20send%20me%20CAC%20membership%20information.%0D%0A%0D%0AName:%20%0D%0AStreet%20address:%20%0D%0ACity,%20State,%20ZIP:%20%0D%0APhone%20number%20(optional):%20%0D%0AHow%20you%20heard%20about%20CAC:%20%0D%0AAny%20additional%20message%20(optional):%0D%0A';
   url = 'mailto:' + acct + '@' + domain + '?' + ext;
   (window.open(url));
}

//////////////////////// !!!! END OBSOLETE !!!! ////////////////////////
