function getElementsByClassName(className, tag, elm){
// http://www.robertnyman.com/index.php?p=256 
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function addLoadEvent(func) {
// http://simonwillison.net/2004/May/26/addLoadEvent/  
// Unobtrusively add onLoad events to the window, without losing any onLoad events hard-coded elsewhere 
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function rewriteLinks() {
// Attaches onClick event handlers to all <a> elements, depending on their CSS class names:
//  'popup' : load the contents of the href into a new browser window
// If no CSS class is detected, or a non-matching one is detected, no onClick handler is attached 

	var objContext = document.getElementById("mv_container2");
	
	var arrLinks = objContext.getElementsByTagName('a');
	for( var i=0; i < arrLinks.length; i++ ){
		switch(arrLinks[i].className) {
				
			case "popup":
				arrLinks[i].onclick = function()
				{
					var popWin = window.open(this.href,"Popup");
					return false;
				}
				hasClass = true;
				break
							
		}
	}
}


addLoadEvent(rewriteLinks);
