/*
A function that runs after page load looking for double square brackets with stuff in it like [[wmuserid,text]] 
and turn that stuff into a mailto and wm.edu address.

uses 2 regexs:
1) if there is only a wmuserid in the brackets use the wm email address as the link text
2) if there are 2 things in the brackets use the second thing as the link text 

TODO: If possible use xslt and regex to find double closed square brackets with stuff in it [[...]] and append after
it a no script tag like:
<noscript>&nbsp;(email this user id at wm.edu)&nbsp;</noscript>

Requirements:
- jquery is used for the document.ready function only 


9/25: THIS FUNCTIONALITY HAS BEEN ADJUSTED TO WORK FOR VIMS.EDU EMAIL ADDRESS INSTEAD -MW

*/




$(document).ready(function(){

	//check browser for javascript    
	if (!document.getElementsByTagName) return false;
	if (!document.createElement) return false;

	page = document.body.innerHTML;

	// email fix
	page = page.replace(/\[\[\s*([a-zA-Z0-9_\.]+)\s*\,?\s*\]\]/g, "<a href=\"mailto:$1@vims.edu\">$1@vims.edu</a>");
	page = page.replace(/\[\[\s*([a-zA-Z0-9_\.]+)\s*\,{1}\s*([^\]]*)\s*\]\]/g, "<a href=\"mailto:$1@vims.edu\">$2</a>");

	// directory url, make it link
	page = page.replace(/\{\{\s*(http\:\/\/[^\}\,]+)\s*\}\}/g, "<a href=\"$1\">$1</a>");
	page = page.replace(/\{\{\s*(http\:\/\/[^\}\,]+)\s*\,{1}\s*([^\}]*)\s*\}\}/g, "<a href=\"$1\">$2</a>");

	document.body.innerHTML = page;
}); 
