addLoadEvent(externalLinks);
function addLoadEvent(func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}

function externalLinks() 
{
	if (!document.getElementsByTagName) 
		return; 
	// to do: check case sensitivity... of a and A
	var anchors = document.getElementsByTagName("a");
	var fn = "";
	for (var i=0; i< anchors.length; i++) 
	{ 
		var anchor = anchors[i];
		if (anchor.getAttribute("href"))
		{
			anchor.target = "mainframe";
			if (fn == "")
			if (anchor.getAttribute("mode") == "main")
			{
				fn = anchor.getAttribute("href");
			}
		} 
	}
	if (fn != "")
		top.mainframe.location = fn;
}




function mngt()
{
	if (event.shiftKey) 
{
	var uri = parseUri(location);
//	alert(uri['directoryPath']);
	top.mainframe.location="/.admin/index.php?xdir="+uri['directoryPath'];
}
}
function parseUri(sourceUri)
{
	var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
	// Wow... don't touch this! 
	var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
	var uri = {};
	
	for(var i = 0; i < 10; i++)
	{
		uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
	}
	
	if(uri.directoryPath.length > 0)
	{
		uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
	}
    
	return uri;
}
