// COPYRIGHT NOTICE
// Copyright (c) Design Matrix, 2004, all rights reserved.
// http://www.designmatrix.com
// This file is provided without any warranty or liability whatsoever.
// Permission is granted to copy and modify this file provided that
// this COPYRIGHT NOTICE is included and modifications are noted.
// Download it here:
// 	http://www.designmatrix.com/services/javascript_email.html

// VERSION 1.3, 08/23/2006

// DESCRIPTION
// This Javascript illustrates methods to maintain a "database" of
// email addresses in one location, so that they only need to be
// maintained in one file rather than in many separate HTML files.

// THE DATABASE
// Define a database for the email addresses as a string array object.
// The form of each line is "First_Name Last_Name Email_Handle Domain".
// The number inside "[ ]" is the numerical index used in makeAddr().
// Change these examples for your own web site.  Use "//" for comments.
var addr = new Array();
addr[0] = "Tom Fizzlebottom fizzle whistle.con";
addr[1] = "Dick Dinglewitz wizard oz.con";
addr[2] = "Mary Contrary silverbell gardengrow.con";
addr[3] = "Your Name you yourdomain.con";
addr[4] = "Contact Us info yourdomain.con";
// Note the backslash "\" for a "null" last name here.
addr[5] = "Webmaster \ webmaster yourdomain.con";
// To use an image instead of text for the link:
addr[6] = "<IMG SRC='image.gif'> contact your_domain.con";
//
// You can also define the email addresses in an array with named
// indices, similar to an associative array in Perl.  The advantage of
// arrays with numerical indices is that they would be easier to use in
// loops.  The advantage of the named indices is that they might be
// easier to remember for the makeAddr() function (i.e., so you don't
// have to look up the numerical index for a particular persons' email
// address).  It appears that numerical and named indices may be mixed
// in one array but we recommend you use one or the other consistently.
addr["Tom"]  = "Tom Fizzlebottom fizzle whistle.con";
addr["Dick"] = "Dick Dinglewitz wizard oz.con";
addr["Mary Contrary"] = "Mary Contrary silverbell gardengrow.con";
addr["Your Name"] = "Your Name you yourdomain.con";
// Note the backslash for a 'null' last name here.
addr["Info"] = "info&#064;yourdomain.con \ info yourdomain.con";
addr["Webmaster"] = "webmaster&#064;yourdomain.con \ webmaster yourdomain.con";

// THE PROGRAM SCRIPT
// Define some makeAddr() variables for the email HTML links.
var cmd = "mail" + "to:";
// Any of these work.
//var at = '@';
var at = '&#064;';
// at sign is hex %40
//var at = escape('@');
//
// You can add any amount of extra HTML code to use in makeAddr().
// For example this variable writes an HTML break before the links:
//	var preextra = "<BR>";
// If your extra variables contain double quotes, you must escape them:
//	var preextra = "<TD WIDTH=\"50%\">";
// The mailextra variable puts email headers inside the mailto links,
// such as a Subject, Cc or Bcc.  For example this adds a Subject:
//	var mailextra ="?Subject=Howdy";
// This variable adds code to terminate a TABLE cell after the links:
//	var postextra = "</TD>";
// Note that if you leave extras in the makeAddr() function they must
// be defined, but you can define them as null string (nothing):
var preextra = "";
var mailextra = "";
var postextra = "";
//
// Here is the function definition.  We split the string referenced
// by the index into a subarray, then assemble it for the HTML code.
// The "\n" prints a newline.
function makeAddr(index) {
    var subarr = addr[index].split(" ");
    var name = subarr[0] +" " +subarr[1];
    var mail = name.link(cmd +subarr[2] +at +subarr[3] +mailextra);
    document.write(preextra +"\n" +mail +"\n" +postextra);
}

// USAGE
// To use this Javascript save it in a file.  Next put the following
// (uncommented) inside the <HEAD> (or <BODY>) of your HTML file.
// Change the SCRIPT SRC argument to match the script's file name.
// The filename suffix ".js" is required to identify it as Javaacript.
//
//	<SCRIPT SRC="addr.js" TYPE="text/javascript"> </SCRIPT>
//
// Then call makeAddr() where you want an email link in the HTML file.
// Make each index match the person's address line index in the array.
// For named indices put the makeAddr() index argument in quotes.
// Write several email links as follows.  Note that you can redefine
// the extra variables before you call the makeAddr() functions, e.g.:
//
//	<SCRIPT TYPE="text/javascript">
//	<!--
//	    var preextra = "<TD WIDTH=\"50%\">";
//	    // Tom is index 0.
//	    makeAddr(0);
//	    var preextra = "<BR>";
//	    // Dick is index 1.
//	    makeAddr(1);
//	    var mailextra = "?Subject=Hi Mary!";
//	    var postextra = "</TD>";
//	    // Mary's index is self-explanatory.
//	    makeAddr("Mary Contrary");
//	// -->
//	</SCRIPT>
