var objLoadFunctions = new Array();

var g_strAdminServer 	= null;
var g_strDomain 		= null;

function ShowError( strError )
{
	alert( strError );
}


function AttachToLoad( objFunction )
{
	objLoadFunctions[ objLoadFunctions.length ] = objFunction;
}

function InitLoads()
{
	for ( var i = 0 ; i < objLoadFunctions.length ; i++ )
	{
		eval(objLoadFunctions[ i ]);
	}
}

function OpenSecondaryWindow( strURL )
{
	window.open( strURL, "_blank", "toolbar=no, menubar=no, location=no, resizable=yes, status=yes" );
}

function CloseSecondaryWindow()
{
	window.top.close();
}

function GetAdminServer()
{
	if ( g_strAdminServer == null )
	{
		g_strAdminServer = "" + CallServer( GetSiteRootPath() + "/solution/operations/soap_Operations.aspx", "GetAdminServer", "GET" );
	}

	return g_strAdminServer;
}

function GetAdminDomain()
{
	if ( g_strDomain == null )
	{
		try
		{
			if ( window.top.g_strDomain )
			{
				g_strDomain = window.top.g_strDomain;
				return g_strDomain;
			}
		}
		catch ( e ) { /* Do nothing. Fetch correct domain name from server! */ }

		var strAdminServer = GetAdminServer();
		if ( !strAdminServer )
		{
			g_strDomain = "";
			return g_strDomain;
		}

		if ( strAdminServer.indexOf( "." ) != -1 && strAdminServer.split( "." ).length > 2 )
		{
			var objParts = strAdminServer.split( "." );
			g_strDomain = objParts[ objParts.length - 2 ] + "." + objParts[ objParts.length - 1 ];
		}
		else
		{
			g_strDomain = strAdminServer;
		}
		
		// Strip end slash
		if ( g_strDomain.substring( g_strDomain.length - 1 ) == "/" )
		{
			g_strDomain = g_strDomain.substring( 0, g_strDomain.length - 1 );
		}
		
		// Strip 'http://' prefix
		if ( g_strDomain.substring( 0, 7 ).toLowerCase() == "http://" )
		{
			g_strDomain = g_strDomain.substring( 7 );
		}
	}

	return g_strDomain;
}


function SetCurrentUserMenuID ( strMenuID )
{
	CallServer( GetSiteRootPath() + "/solution/operations/soap_preFabUtilities.aspx", "SetCurrentUserMenuID", "POST", strMenuID );
}

// Set the domain of the document to equal the domain of the admin server
// This is to enable modal dialogs after the MSIE Patch of Feb 2003
var strDomain = GetAdminDomain();
if ( strDomain && strDomain != "" && strDomain != "null" && new String( "" + document.domain ).toLowerCase() != strDomain.toLowerCase() )
{
	//document.domain = strDomain;
}

window.onload = InitLoads;