var WonLoad = new function ()
{
	this.onLoad = new Array();
		
	this.add = function(func, url)
	{
		var load = new Array();
		load[0] = func;
		load[1] = url;
		
		this.onLoad[this.onLoad.length] = load;

		delete load;
	}
	
	this.run = function(href)
	{
		for(i = 0; i < this.onLoad.length; i++)
		{
			var func = this.onLoad[i][0];
			var url = this.onLoad[i][1];
			var URLQuery = "";
			
			try
			{
				var delimiter = 'action';
				var name = delimiter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
				var regexS = "[\\?&]"+name+"=([^&#]*)";
				var regex = new RegExp( regexS );
				var results = regex.exec( href );
				if( results != null ) {
					URLQuery = results[1];
				}

				var delimiter = 'id';
				var name = delimiter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
				var regexS = "[\\?&]"+name+"=([^&#]*)";
				var regex = new RegExp( regexS );
				var results = regex.exec( href );
				if( results != null ) {
					URLQuery += "&id=" + results[1];
				}
			}
			catch (E) { }

			if(url == "" || url == URLQuery || URLQuery == "")
			{
				eval(func);
			}

			delete func, url, URLQuery;
		}
	}
}

window.onload = function ()
{
	if (ajaxd == 1)
		modifyForAJAX();
	WonLoad.run();
}

function modifyForAJAX()
{
	var anchors = document.getElementsByTagName("a");
	
	for(var i = 0; i < anchors.length; i++)
	{
		if(anchors[i].rel == "content")
		{
			anchors[i].onclick = function () {
				ajaxLink(this.getAttribute('href'));
				return false;
			}
		}
	}

	delete anchors;
}

var _href;
function ajaxLink(href)
{
	var content = document.getElementById('content');

	_href = href;

	var ajaxIndex = ajaxObjects.length;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = href + '&ajax=1';
	ajaxObjects[ajaxIndex].onLoading = function()
	{
		content.innerHTML = '<div class="loading" align="center"><img src="includes/loading.gif" alt="Loading" /></div>';
	};
	ajaxObjects[ajaxIndex].onCompletion = function() 
	{
		var resp = ajaxObjects[ajaxIndex].response;
		
		content.innerHTML = unescape(resp);

		if (document.getElementById('location') != null)
		{
			var SubajaxIndex = ajaxObjects.length;
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].async = true;
			ajaxObjects[ajaxIndex].requestFile = '?action=location&href=' + escape(href) + '&ajax=1';
			ajaxObjects[ajaxIndex].onCompletion = function() 
			{
				var resp = ajaxObjects[ajaxIndex].response;
				document.getElementById('location').innerHTML = unescape(resp);
				delete resp;
			};
			ajaxObjects[ajaxIndex].runAJAX();
		}

		modifyForAJAX();

		WonLoad.run(href);

		delete resp, content, SubajaxIndex;
	};
	ajaxObjects[ajaxIndex].runAJAX();

	delete ajaxIndex;
	
	return false;
}

/*
if(navigator.appName == "Netscape")
{
	document.onkeypress = function (evt)
	{
		try
		{
			var r = '';
			if (document.getElementById)
			{
				r += evt.ctrlKey ? 'Ctrl-' : '';
				r += evt.charCode;
				if (evt.keyCode =="116" || r == "Ctrl-114")
				{
					evt.preventDefault();
					evt.stopPropagation();
					window.setTimeout(currentURI, 10);
					return false;
				}
			}
		}
		catch (E) { }
	}
}
else
{
	document.onkeydown = function()
	{
		try
		{
			if(window.event && window.event.keyCode == 116)
			{
				window.event.keyCode = 505;
			}

			if(window.event && window.event.ctrlKey || window.event.keyCode == 114)
			{
				window.event.keyCode = 505;
				return false;
			}

			if(window.event && window.event.keyCode == 505)
			{
				window.setTimeout(currentURI, 10);
				return false;
			}
		}
		catch (E) { }
	}
}
*/