var PopUp_OpenFrames = [];
var PopUp_TimeoutId = [];

function PopUp_GetFrame(source)
{
	var iframe = source.previousSibling;
	if (iframe != null && iframe.nodeName == 'IFRAME')
		return iframe;
	else
		return null;
}

function PopUp_OnResize(source)
{
	var iframe = PopUp_GetFrame(source);
	if (iframe)
	{
		iframe.style.width = source.offsetWidth + 'px';
		iframe.style.height = source.offsetHeight + 'px';
	}
}

function PopUp_Show(id, timeout, manualClose)
{
	PopUp_ClearTimeouts(id);
	var div = document.getElementById(id);
	if (div)
	{
		if (timeout)
		{
			PopUp_TimeoutId[id] = window.setTimeout('PopUp_Show("' + id + '",,' + manualClose + ');', timeout);
			return;
		}
		
		if (div.style.display == 'none')
		{
			PopUp_CloseAllImplicit();
			div.style.display = '';
			var iframe = PopUp_GetFrame(div);
			if (iframe)
				iframe.style.display = '';
		}
		PopUp_OpenFrames[id] = 1;
		window.setTimeout('PopUp_OpenFrames["' + id + '"] = ' + (manualClose ? 3 : 2) + ';', 20);
	}
}

function PopUp_Toggle(id, manualClose)
{
	PopUp_ClearTimeouts(id);
	var div = document.getElementById(id);
	if (div)
	{
		var iframe = PopUp_GetFrame(div);
		if (div.style.display == 'none')
		{
			PopUp_CloseAllImplicit();
			div.style.display = '';
			if (iframe)
				iframe.style.display = '';
			PopUp_OpenFrames[id] = 1;
			window.setTimeout('PopUp_OpenFrames["' + id + '"] = ' + (manualClose ? 3 : 2) + ';', 20);
		}
		else
		{
			PopUp_OpenFrames[id] = 0;
			div.style.display = 'none';
			if (iframe)
				iframe.style.display = 'none';
		}
	}
}

function PopUp_Hide(id, timeout)
{
	PopUp_ClearTimeouts(id);
	var div = document.getElementById(id);
	if (div)
	{
		if (timeout)
		{
			PopUp_OpenFrames[id] = 2;
			PopUp_TimeoutId[id] = window.setTimeout('PopUp_HideAuto("' + id + '");', timeout);
		}
		else
		{
			PopUp_OpenFrames[id] = 0;
			if (div.style.display != 'none')
			{
				div.style.display = 'none';
				var iframe = PopUp_GetFrame(div);
				if (iframe)
					iframe.style.display = 'none';
			}
		}
	}
}

function PopUp_HideAuto(id)
{
	var div = document.getElementById(id);
	if (div)
	{
		PopUp_OpenFrames[id] = 0;
		PopUp_TimeoutId[id] = null;
		if (div.style.display != 'none')
		{
			div.style.display = 'none';
			var iframe = PopUp_GetFrame(div);
			if (iframe)
				iframe.style.display = 'none';
		}
	}
}

function PopUp_ClearTimeouts(id)
{
	var timeoutId = PopUp_TimeoutId[id];
	if (timeoutId)
	{
		PopUp_TimeoutId[id] = null;
		window.clearTimeout(timeoutId);
	}
}

function PopUp_CloseAll()
{
	for (var i in PopUp_OpenFrames)
	{
		var state = PopUp_OpenFrames[i];
		if (state != 0)
			PopUp_Hide(i);
	}
}

function PopUp_CloseAllImplicit()
{
	for (var i in PopUp_OpenFrames)
	{
		var state = PopUp_OpenFrames[i];
		if (state == 2)
			PopUp_Hide(i);
	}
}

if (document.body.attachEvent)
	document.body.attachEvent('onclick', PopUp_CloseAllImplicit);
else
{
	var document_body_onclick = document.body.onclick;
	if (document_body_onclick != null)
		document.body.onlick = function() { document_body_onclick(); PopUp_CloseAllImplicit(); };
	else
		document.body.onlick = PopUp_CloseAllImplicit;
}