// JavaScript Document

/*	
-- Introduction -- 
	The purpose of all of the functions in this document is to obscure e-mail addresses 
	from web crawlers that access pages looking to harvest e-mail addresses, usually 
	for the purpose of sending unsolicited bulk e-mail.  No guarantees are made about
	the efficacy of these measures, but once in place, they should take relatively
	little work to implement, and as long as they work in all applications, it seems
	better to have them than not.
	
	These measures constitute the second part of this defensive measure, and have to do
	with making the e-mail address into a functioning link.  The first part of the measure,
	which is equally important, has to do with the comments and spaces between the @ sign
	and the rest of the e-mail address in the text of the html document itself.
	
	It is highly recommended that the text of the e-mail link be a modified version of the
	actual e-mail address rather than, for example, "e-mail us" or the name of a person,
	because there is always the possibility that the user may have disabled JavaScript in
	their browser, or may have an older version of JavaScript that doesn't work with the code,
	or that the user may print the document out and then want to read the e-mail address from the
	print out.
	
	See site documentation for more details on these measures.
*/

/*
-- setMail--

	Should be called on: body onLoad
	-- example: <body onLoad="setMail();">
					[page content]
				</body>

	This function looks for the e-mail links in the document (which must be identified first
	by the "Mail" id,) and gives them each a unique, numbered id based on their position within
	the document.  This will allow the links to identify themselves to the other functions.
	
	This function *must* be used where there is more than one e-mail link on a page in order for
	the function that changes the links to work.
--------------------
*/

function setMail(){	
	for (var i = 0; i < top.document.links.length; i++){
		if (top.document.links[i].id == "Mail"){
			top.document.links[i].id = "Mail" + i + "";
			}//end if
		}// end for
	}//end function

/*
-- changeToMail--

	Should be called on: a onMouseOver, onKeyPress
	-- example: <a href="javascript:;"
				onMouseOver="changeToMail(this.id,'sampleuser','test.despammed.com');"
				onKeyPress="changeToMail(this.id,'sampleuser','test.despammed.com');">sampleuser @ test.despammed.com</a>
		or
	-- example: <a href="javascript:;" onMouseOver="changeToMail(this.id,'sampleuser');"
				onKeyPress="changeToMail(this.id,'sampleuser');">sampleuser @ mail.sdsu.edu</a>

	---- note that the text of the links in these examples is not precisely identical to how they ought 
		to appear on the page.  See site documentation for details on the exact code for each e-mail link.

	This function assembles the link to the e-mail address from the pieces that are passed when
	the function is called. It needs three pieces of information to do this:
		- the id of the link from which it is being called,
		- the user portion of the address where the e-mail will be sent,
		and
		- the domain name portion of the address where the e-mail will be sent.
	These pieces are sent to the function in this order.  Because it is expected that most of the
	e-mail addresses linked to the site will be to someone at mail.sdsu.edu, that portion of the 
	e-mail address is set as default.  Specifying anything in the third position for information 
	will override that default.
	
	When sending information to the function in the caller, it is important that the pieces are 
	all separated by commas.   The first piece should always be this.id, without surrounding 
	quotes.  This tells the function what portion of the document it is making changes to.
	
	The second piece should be the username portion of the address, exactly as it would appear 
	before the @ sign, but surrounded by single quotes, like this: 'username' .
	
	The third piece is optional, and is only needed if the portion of the e-mail address after
	the @ sign is not mail.sdsu.edu.  If the link needs to be to an address somewhere other 
	than mail.sdsu.edu, give the entire portion of the address after the @ sign surrounded in 
	single quotes, like this: 'mail.despammed.com'.

	See the examples above.
	
	It is important that this function be called both when the mouse rolls over the link and
	when the link is selected by key press because some users may navigate the webpage using the
	keyboard rather than the mouse.  The information sent to the function on key press should be
	identical to that sent on mouse over.
	
	There are two main reasons that this function is called on mouse over and key press instead
	of simply changing the links when the page is loaded.  The first is to require some user
	interaction, and thereby make it harder for a program to access the e-mail addresses without
	human intervention.  The second is to make it easier to pass individual data about the links
	to the function.
--------------------
*/

function changeToMail(callerID, username, newDom){
	var user = username;
	var domain = "sdsu.edu";
	var prefix = "mail.";
	if (newDom){
		domain = newDom;
		prefix = "";
		}
	
	var finalString = ("mailto:" + user + "@" + prefix + domain +"");
	top.document.getElementById(callerID).href = finalString;
	}