var timer;
var dropdownid;

function showDropDown(ctrl, id)
{
	var dropdown = document.getElementById('dropdown' + id);
	
	if(dropdown==null || ctrl==null)
		return;
	
	if(id!=dropdownid)
		hideDropDown();
		
	clearDelay();
	
	dropdown.style.top = (findTopOfControl(ctrl) + ctrl.offsetHeight) + "px";
	dropdown.style.left = (findLeftOfControl(ctrl) - 6) + "px";
	dropdown.style.visibility = "visible";
	
	dropdownid = id;
}

function hideDropDown()
{
	var dropdown = document.getElementById('dropdown' + dropdownid);
	
	if(dropdown!=null)
	{
		dropdown.style.visibility = "hidden";
		dropdownid = -1;
	}
}

function clearDelay()
{
	clearTimeout(timer);
}

function delayHideDropDown()
{
	timer = setTimeout(hideDropDown, 100);
}

function findTopOfControl(control)
{
	//returns the top of the control in pixels
	//
	//control:	the control to get the top of
	
	var boxTop = 0;
	
	if(control.offsetParent)
	{
		do
		{
			boxTop += control.offsetTop;
		} while(control = control.offsetParent);
	}
	
	return boxTop;
}

function findLeftOfControl(control)
{
	//returns the left of the control, in pixels
	//
	//control:	the control to get the left of
	
	var boxLeft = 0;
	
	if(control.offsetParent)
	{
		do
		{
			boxLeft += control.offsetLeft;
		} while(control = control.offsetParent);
	}

	return boxLeft;
}
