﻿var Popup; //the control that is popped up

function ShowPopup(DivName, Anchor, XOffset, YOffset){
    //check if this div is already showing. If so, we'll hide it
    var alreadyVisible = false;
    if(document.getElementById(DivName).style.display==''){
        alreadyVisible = true; 
    }
    
    //first hide any existing popups
    HidePopup('');
    
    if(!alreadyVisible){
        //get the item we're popping up
        Popup = document.getElementById(DivName);
        
        //find the anchor point
        var Apoint = document.getElementById(Anchor);
            
        //get it's position 
        var x = Apoint.offsetLeft;
        var y = Apoint.offsetTop;
        
        var parent = Apoint;
	    while ((parent=parent.offsetParent) != null) {
	        x += parent.offsetLeft; 
	        y += parent.offsetTop;
	    }
    	   
        //calculate the popup's position
        x += XOffset;
        y += YOffset;
        
        
        Popup.style.left = x + "px";
        Popup.style.top = y + "px";
        
        //show it
        Popup.style.display='';
    }
}

function HidePopup(SkipDiv){
    //SkipDiv indicates which popup NOT to hide    
    if(Popup != null){
        if(Popup.id != SkipDiv){
            //if it exists, hide it
            Popup.style.display='none';
        }
    }
}
