
function PopupClickHandler(popupName, positionRefObj) {
	
	if (document.getElementById(popupName).style.visibility != 'hidden') {
		PopupClose(popupName);
		return;
	}	

	PopupCloseAll()
	
	var pos = ObjPosition(document.getElementById(positionRefObj));
	
	document.getElementById(popupName).style.top = pos[1];
	document.getElementById(popupName).style.left = pos[0];
	document.getElementById(popupName).style.visibility = 'visible';
	
}

function PopupClose(popupName) {
	document.getElementById(popupName).style.visibility = 'hidden';	
}



function PopupCloseAll() {
	if (document.getElementById('MenuMostra')) {
		document.getElementById('MenuMostra').style.visibility = 'hidden';	
	}
	if (document.getElementById('MenuOrdina')) {
		document.getElementById('MenuOrdina').style.visibility = 'hidden';	
	}
}


function ObjPosition(obj) {
	var curleft = 0;
	var curtop  = 0;
	if (obj.offsetParent) {
		do { 
			curleft += obj.offsetLeft; 
			curtop += obj.offsetTop;
		} 
		while (obj = obj.offsetParent);
		return [curleft,curtop+20];
	}
} 

