function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function getObject(name){
  if(document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
function doPopup() {
	  
	if (!document.getElementsByTagName) return false; 

	
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("popup")) {

			var SectionID = links[i].getAttribute("href").split("#")[1];
			var helpTextDiv = document.getElementById(SectionID);
			helpTextDiv.style.display = 'none';	
			links[i].onclick = function() {

				var popups = document.getElementsByTagName("a");
				for (var i=0; i < popups.length; i++) {
					if (popups[i].className.match("popup")) {

						var ThisPopupID = popups[i].getAttribute("href").split("#")[1];
						var SelectedPopupID = this.getAttribute("href").split("#")[1];

						if(ThisPopupID == SelectedPopupID){							
						}else{					
							UnselectedPopupDiv = document.getElementById(ThisPopupID);
							UnselectedPopupDiv.style.display = 'none';	
						}
					}
				}

				var coors = findPos(this);

				var SectionID = this.getAttribute("href").split("#")[1];
				var helpTextDiv = document.getElementById(SectionID);

				if(helpTextDiv.style.display == "block"){
					helpTextDiv.style.display = 'none';
				}else{
					/* display popup */
					helpTextDiv.style.zIndex = '10';
					helpTextDiv.style.display = 'block';
					helpTextDiv.style.position = 'absolute';
					
					helpTextDiv.style.left = coors[0]+'px';
					helpTextDiv.style.top = (coors[1]+20)+'px';
					
					helpTextDiv.focus();
				}
				return false;
			}		  
		}
	}
}

function closePopup(PopupID){
	var oPopUpDiv=document.getElementById(PopupID);
	oPopUpDiv.style.zIndex = '110';
	oPopUpDiv.style.display = 'none';	
}

function closePopups(){
		var popups = document.getElementsByTagName("a");
		for (var i=0; i < popups.length; i++) {
			if (popups[i].className.match("popup")) {
			
				var ThisPopupID = popups[i].getAttribute("href").split("#")[1];	
				ThisPopup = document.getElementById(ThisPopupID);						
				if(ThisPopup.style.display == "block"){
						ThisPopup.style.display = 'none';
				}
			}
		}
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(doPopup);
