var loader$paramName = "requestId";

// Called by the main page to load a child page in a container
function loadPage( src, idContainer, showLoadingImage )
{
	var pos = src.indexOf( '?' );
	if( pos < 0 )
	{
		src += "?";
	}
	else
	{
		src += "&";
	}
	src += loader$paramName + "=" + idContainer;
	var container = document.getElementById( idContainer );
	container.loader$align = container.style.textAlign;
	container.style.textAlign = "center";
	container.loader$html = container.innerHTML;
	var html = "";
	if( showLoadingImage )
	{
		html = "<img src='imagini/incarcare.gif'" +
		" title='Aşteptaţi, se încarcă...'" +
		" style='margin-top: 16px;'>";
	}
	container.innerHTML = html +
		"<iframe style='display: none;'" +
		" src='" + src + "'>" +
		"</iframe>"; // Starts loading
}

// Called by the child page after loading (from body.onload)
function loadCompleted()
{
	var params = location.search;
	var pos = params.indexOf( loader$paramName + "=" );
	if( pos < 0 )
	{
		return; // Not embedded
	}
	var idContainer = params.substr( pos + loader$paramName.length + 1 );
	var container = parent.document.getElementById( idContainer );
	container.style.textAlign = container.loader$align;
	container.loader$align = null;
	container.loader$display = container.style.display;
	container.loader$html = document.body.innerHTML + container.loader$html;
	container.style.display = 'none';
	parent.setTimeout( "handleLoadCompleted( '" + idContainer + "' )", 1 ); // delegate to the parent (loader) thread
}

function handleLoadCompleted( idContainer )
{
	var div = document.getElementById( idContainer );
	div.innerHTML = div.loader$html; // gc the IFRAME
	div.loader$html = null;
	if( div.className == "flex" )
	{
		flex$init();
		if( !div.getElementsByTagName( "div" ).length )
		{
			div.className = "flex leaf";
		}
	}
	div.style.display = div.loader$display;
	div.loader$display = null;
	if( window.pageLoaded instanceof Function )
	{
		pageLoaded( idContainer );
	}
}

