// JavaScript Document

function setMailtoLinks()
{
  if (!document.getElementsByTagName) { return; }
  ar_spans = document.getElementsByTagName('span');
  for (i=0; i<ar_spans.length; i++)
  {
    if (ar_spans[i].className == 'elinkhidden')
    {
      var ex = ar_spans[i].firstChild.nodeValue.split(',');
      var tmp = document.createElement('a');
	  var str = ex[1] + '@' + ex[0];
	  if (ex[2] != null) {
		str = (str += '?Subject=' + ex[2]);
	  }
      tmp.href = 'mailto:' + str;	  
      tmp.appendChild(document.createTextNode(ex[3]? ex[3] : ex[1] + '@' + ex[0]));
      cssjs('swap',ar_spans[i],'elinkhidden','elinkshown');
      ar_spans[i].replaceChild(tmp, ar_spans[i].firstChild);
    }
  }
}

function addEvent(elm, evType, fn, useCapture){
		if (elm.addEventListener) 
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	}
	
// cssjs tests
/* This function takes four parameters:
a - defines the action you want the function to perform. 
o - the object in question. 
c1 - the name of the first class 
c2 - the name of the second class 
Possible actions are:
swap - replaces class c1 with class c2 in object o. 
add - adds class c1 to the object o. 
remove - removes class c1 from the object o. 
check - test if class c1 is already applied to object o and returns true or false. 
*/
function cssjs(a,o,c1,c2){
	switch (a){
		case 'swap':
			o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp("(^|\\s)" + c1 + "(\\s|$)").test(o.className)
		break;
	}
}

	
addEvent(window, 'load', setMailtoLinks, false);	
