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 msvRewriteLinks() {
// 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("msvContentFocalBody");
	
	var arrLinks = objContext.getElementsByTagName('a');
	for( var i=0; i < arrLinks.length; i++ ){
		switch(arrLinks[i].className) {
			case "msvPopup":
				arrLinks[i].onclick = function()
				{
					var popWin = window.open(this.href,"Popup");
					return false;
				}
				hasClass = true;
				break
		}
	}
}


function msvShowHide(objTrigger,strObjID) {
// Hides and reveals the object with ID strObjID
	var objS = document.getElementById(strObjID);
	var objI = getElementsByClassName("msvPlus","img",objTrigger)[0];
	if(objS) {
		if(objS.style.display == "none") {
			objS.style.display = "block";
			if(objI) { objI.src="/brasil/servidores/virtualization/assets/images/common/minus.gif"; }
		} else {
			objS.style.display = "none";
			if(objI) { objI.src="/brasil/servidores/virtualization/assets/images/common/plus.gif"; }
		}
	}
	objTrigger.blur();
}


addLoadEvent(msvRewriteLinks);
