
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function getElementsByClassName(find, node, tag) {

    var classElements = new Array();
    if (node == null)
    	node = document;
    if (tag == null)
    	tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + find + "(\\s|$)");
    for (var i = 0, j = 0; i < elsLen; i++)
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    return classElements;

}

function formatStaffPictures(){

	var noMails = getElementsByClassName('nomail', document, 'div');	
		
	for(var i=0; i < noMails.length; i++) {
		var staffLink = getElementsByClassName('name', noMails[i], 'p')[0].getElementsByTagName('a')[0];
		staffLink.onclick = showPopup;
		staffLink.href = "";	// this prevents users from right clicking and using "copy email address"	
	}
}

//addLoadEvent(formatStaffPictures);


function showPopup() {
	
	var b_version=navigator.appVersion;
	var isIE6 = false;
	
	if(b_version.indexOf("MSIE 6") != -1)
		isIE6 = true;	

	var outString = "This staff member is not able to respond to emails during the summer. Instead, try emailing one of the professional staff members for your hall.";

	var staffLink;
	
	// get AC name and email, if present
	var ac = getElementsByClassName('ac', document, 'div');
	if(ac[0] != null){
		staffLink = ac[0].getElementsByTagName('p')[0].getElementsByTagName('a')[0];
		if(isIE6)
			outString += '\n\nArea Coordinator: ' + staffLink.innerHTML + ' - ' + staffLink.href.substr(7);
		else
			outString += '<br/><br/>Area Coordinator: <a href="' + staffLink.href + '">' + staffLink.innerHTML + '</a>';
	}
	
	// get RLC name and email, if present
	var rlc = getElementsByClassName('rlc', document, 'div');
	if(rlc[0] != null){
		staffLink = rlc[0].getElementsByTagName('p')[0].getElementsByTagName('a')[0];
		if(isIE6)
			outString += '\n\nResidence Life Coordinator: ' + staffLink.innerHTML + ' - ' + staffLink.href.substr(7);
		else
			outString += '<br/><br/>Residence Life Coordinator: <a href="' + staffLink.href + '">' + staffLink.innerHTML + '</a>';
	}
	
	
	if(isIE6)
		alert(outString);	
	else{
	
		outString += '<br/><br/><a href="javascript:closePopup();">Close</a>';
	
		// the screen -- goes behind the popup to shade the rest of the page
		var wilbur = document.createElement('div');
		wilbur.id = "screen";
	
		// the popup div, contains the message
		var orville = document.createElement('div');
		orville.id = "popup"
		orville.innerHTML = outString;
		
		// append elements to DOM
		var bod = document.getElementsByTagName('body')[0]; // i want your bod
		if(typeof document.body.style.maxHeight != "undefined") // check for IE6
			bod.appendChild(wilbur);
		bod.appendChild(orville); //tod man, by toddy fantasies
		
		orville.style.display = "block";
		if(typeof document.body.style.maxHeight != "undefined")
			wilbur.style.display = "block";
		else
			orville.style.position = "absolute";	
	}
	
	return false;
}

function closePopup() {
	var bod = document.getElementsByTagName('body')[0]; // more, more!
	bod.removeChild(document.getElementById('popup'));
	if(typeof document.body.style.maxHeight != "undefined")
		bod.removeChild(document.getElementById('screen'));
}
