function HandlerItem(targetID, sourceIDs)
{
	this.TargetID = targetID;
	this.SourceIDs = sourceIDs;
}

function HandlerItemsCollection()
{
	this.Items = [];
}

HandlerItemsCollection.prototype.Add = function(item) 
{
	this.Items.push(item);
}

HandlerItemsCollection.prototype.GetTargetID = function(sourceID)
{
	for (var i = 0; i < this.Items.length; i++)
	{
		var item = this.Items[i];
		for (var j = 0; j < item.SourceIDs.length; j++)
		{
			if (item.SourceIDs[j] == sourceID)
			{
				return this.Items[i].TargetID;
			}
		}
	}
	return null;
}

function CheckKeyPress(e)
{
	if (!e) e = event;
	var code = (!e.keyCode) ? e.which : e.keyCode;
	if (code == 13)
	{
		var targ;
		if (e.target) targ = e.target;
		else if (e.srcElement) targ = e.srcElement;
		if (targ.nodeType == 3) targ = targ.parentNode;
		
		var sourceID = targ.id;
		
		var targetID = document.handlerItems.GetTargetID(sourceID);
		var target = document.getElementById(targetID);		
		
		if (target == null)
			return;
		
		if (target.click)
			target.click();
		else
		{
			if (target.onclick && typeof target.onclick == "function")
				target.onclick();
				
			if (target.href.indexOf("javascript:") != -1)
				eval(target.href.replace("javascript:", ""));
			else
				window.location.href = target.href;
		}
		
		return false;
	}
}

document.handlerItems = new HandlerItemsCollection();

if (document.addEventListener) document.addEventListener("keypress", CheckKeyPress, false);
else if (document.attachEvent) document.attachEvent("onkeypress", CheckKeyPress);
