var __COMPONENT_PATH__ = "/comp";
var __VERBOSE__ = false;
var __USE_CONTEXT__ = false;
var __FIXED_CONTEXT__ = null;

/**
 * Retrieves the current component path
 *
 * @return The current component path
 */
function getComponentPath()
{
	return __COMPONENT_PATH__;
}

/**
 * Sets the component path
 *
 * @param locale The new component path
 */
function setComponentPath(path)
{
	__COMPONENT_PATH__ = path;
}

function setUseContext(state)
{
	__USE_CONTEXT__ = state;
}

function isUseContext()
{
	return __USE_CONTEXT__;
}

/**
 * Retrieves the first part of the current location.
 *
 * @return The first part of the current location
 */
function getContext()
{
	if (isUseContext())
	{
		if (__FIXED_CONTEXT__ != null)
		{
			return __FIXED_CONTEXT__;
		}
		return location.pathname.substring(0, location.pathname.indexOf("/", 1));
	}
	return "";
}

function setFixedContext(context)
{
	__FIXED_CONTEXT__ = context;
}

/**
 * Imports the resource specified by name. The name is relative to the
 * component path
 * 
 * @param name The filename relative to the component path
 */
function importComponent(name)
{
	importExternal(getContext() + getComponentPath() + name);
}

/**
 * Imports the resource specified by name. The name is an absolute path
 * 
 * @param name The filename
 */
function importExternal(name)
{
	if (name.indexOf(".js") != -1)
	{
		__importJS(name);
	}
	else if (name.indexOf(".css") != -1)
	{
		__importCSS(name);
	}
}

function __importJS(name)
{
	document.writeln('<script language="JavaScript" type="text/javascript" src="' + name + '"></script>');
}

function __importCSS(name)
{
	document.writeln('<link rel="stylesheet" type="text/css" href="' + name + '"></link>');
}