// Load a page in a specified frame
function go(url, frame)
{
	// Go to specified url, else -> reload the page
	if (url)
	{
		// Load url in specified frame, else -> load in it self
		if (frame)
			window.parent.frames(frame).location = url;
		else
			document.location = url;
	}
	else
	{
		// Load url in specified frame, else -> load in it self
		if (frame)
			window.parent.frames(frame).location = window.parent.frames(frame).location;
		else
			document.location = document.location;
	}
}



var registerNamespace = function(namespace)
{
	var root = window;
	var namespaceParts = namespace.split(".");
	for(var i = 0; i < namespaceParts.length; i++)
	{
		var currentPart=namespaceParts[i];
		if(!root[currentPart])
			root[currentPart] = new Object();
		root = root[currentPart];
	}
};



// Some browsers don't like expressions such as foo.concat(arguments)
// or arguments.concat(foo), because argument objects are not really arrays.
// Therefore, we'll just operate on these pseudoarrays manually.
function concat()
{
	var result = [];

	for (var i = 0; i < arguments.length; i++)
		for (var j = 0; j < arguments[i].length; j++)
			result.push(arguments[i][j]);

	return result;
}
// Returns the given array without the first element
function withoutFirst(sequence)
{
	result = [];

	for (var i = 1; i < sequence.length; i++)
		result.push(sequence[i]);

	return result;
}
// With this we can bind a method to whatever
// see: http://www.brockman.se/writing/method-references.html.utf8
Function.prototype.bind = function (object)
{
	var method = this;
	var preappliedArguments = withoutFirst(arguments);
	return function () { return method.apply(object, concat(preappliedArguments, arguments)); };
};
// With this we can bind a method to an event
// see: http://www.brockman.se/writing/method-references.html.utf8
Function.prototype.bindEventListener = function (object)
{
	var method = this;
	var preappliedArguments = withoutFirst(arguments);
	return function (event) { return method.apply(object, concat([event || window.event], preappliedArguments)); };
};


var EventUtil = new Object;
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler)
{
	if (oTarget.addEventListener)
	{
		oTarget.addEventListener(sEventType, fnHandler, false);
	}
	else if (oTarget.attachEvent)
	{
		oTarget.attachEvent("on" + sEventType, fnHandler);
	}
	else
	{
		oTarget["on" + sEventType] = fnHandler;
	}
};

EventUtil.removeEventHandler = function (oTarget, sEventType, fnHandler)
{
	if (oTarget.removeEventListener)
	{
		oTarget.removeEventListener(sEventType, fnHandler, false);
	}
	else if (oTarget.detachEvent)
	{
		oTarget.detachEvent("on" + sEventType, fnHandler);
	}
	else
	{
		oTarget["on" + sEventType] = null;
	}
};

EventUtil.formatEvent = function (oEvent)
{
	if ((isIE && isWin) || isOpera)
	{
		oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
		//oEvent.eventPhase = 2;
		oEvent.isChar = (oEvent.charCode > 0);
		oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
		oEvent.pageY = oEvent.clientY + document.body.scrollTop;
		oEvent.preventDefault = function ()
		{
			this.returnValue = false;
		};

		if (oEvent.type == "mouseout")
		{
			oEvent.relatedTarget = oEvent.toElement;
		}
		else if (oEvent.type == "mouseover")
		{
			oEvent.relatedTarget = oEvent.fromElement;
		}

		oEvent.stopPropagation = function ()
		{
			this.cancelBubble = true;
		};

		//oEvent.target = oEvent.srcElement;
		oEvent.time = (new Date).getTime();
	}
	return oEvent;
};

EventUtil.getEvent = function()
{
	if (window.event)
	{
		return this.formatEvent(window.event);
	}
	else
	{
		return EventUtil.getEvent.caller.arguments[0];
	}
};


// Get a the value of a style element of an object,
// that has not been set inline in HTML or with code,
// but has been specified by a separate css file.
function getStyle(object, style)
{
	if (object.currentStyle)
	{
		// IE
		while (style.indexOf("-") != -1)
		{
			var pos = style.indexOf("-");
			var begin = style.substring(0, pos);
			var digit = style.substring(pos + 1, pos + 2);
			var end = style.substring(pos + 2, style.length + 1);
			style = begin + digit.toUpperCase() + end;
		}
		return object.currentStyle[style];
	}
	else if (window.getComputedStyle)
	{
		//Other browsers
		return document.defaultView.getComputedStyle(object, null).getPropertyValue(style);
	}
}


// Generate a shadow for the current object (Gecko only)
Object.prototype.generateShadow = function ()
{
	// Only for Gecko browsers
	if (!BrowserInfo.isGecko)
		return;

	// Weve already got a shadow, make sure its displayed
	if (this.shadow && this.shadow.length && this.shadow.length == 6)
	{
		for (var i = 0; i < 6; i++)
			this.shadow[i].style.display = "block";
		return;
	}

	// Get some size info
	var offsetTop = 0;
	var offsetLeft = 0;
	if (getStyle(this, "position") != "absolute")
	{
		var offsetTop = this.offsetTop;
		var offsetLeft = this.offsetLeft;
	}
	var offsetWidth = this.clientWidth + 1;
	var offsetHeight =  this.clientHeight + 1;
	var offsetRight = offsetLeft + offsetWidth;
	var offsetBottom = offsetTop + offsetHeight;

	// Create the divs that represent the shadow
	this.shadow = new Array();
	var opacity = 0.25;
	for (var i = 0; i < 3; i++)
	{
		this.shadow[i] = document.createElement("div");
		this.shadow[i].id = this.id + "Shadow" + i;
		this.shadow[i].style.position = "absolute";
		this.shadow[i].style.top = (offsetBottom + i) + "px";
		this.shadow[i].style.left = (offsetLeft + i+1) + "px";
		this.shadow[i].style.width = offsetWidth + "px";
		this.shadow[i].style.height = "1px";
		this.shadow[i].style.backgroundColor = "#000000";
		this.shadow[i].style.zIndex = "1";
		this.shadow[i].style.opacity = opacity;
		this.appendChild(this.shadow[i]);
		opacity -= 0.08;
	}
	var opacity = 0.25;
	for (var i = 3; i < 6; i++)
	{
		this.shadow[i] = document.createElement("div");
		this.shadow[i].id = this.id + "Shadow" + i;
		this.shadow[i].style.position = "absolute";
		this.shadow[i].style.top = (offsetTop + i-2) + "px";
		this.shadow[i].style.left = (offsetRight + i-3) + "px";
		this.shadow[i].style.width = "1px";
		this.shadow[i].style.height = (offsetHeight - 1) + "px";
		this.shadow[i].style.backgroundColor = "#000000";
		this.shadow[i].style.zIndex = "1";
		this.shadow[i].style.opacity = opacity;
		this.appendChild(this.shadow[i]);
		opacity -= 0.08;
	}
};

Object.prototype.hideShadow = function ()
{
	// Only for Gecko and IE browsers
	if (!BrowserInfo.isGecko && !BrowserInfo.isIE)
		return;

	// Hide the shadow
	if (this.shadow && this.shadow.length && this.shadow.length == 6)
	{
		for (var i = 0; i < 6; i++)
			this.shadow[i].style.display = "none";
	}
};



// Browser Info
var BrowserInfo = new Object();
var sAgent = navigator.userAgent.toLowerCase();
BrowserInfo.isIE = (sAgent.indexOf("msie") != -1 && sAgent.indexOf("opera") == -1);
BrowserInfo.isOpera = (sAgent.indexOf("opera") != -1);
BrowserInfo.isGecko = !BrowserInfo.isIE && !BrowserInfo.isOpera;



var Select = new Object();
Select.add = function (oList, sText, sValue, bSelected)
{
	var oOption = document.createElement("option");
	oOption.appendChild(document.createTextNode(sText));

	oOption.setAttribute("value", sValue);

	if (bSelected)
	{
		oOption.setAttribute("selected", "selected");
	}

	oList.appendChild(oOption);
};

Select.remove = function (oList, iIndex)
{
	oList.options[iIndex] = null;
};

Select.select = function (oList, iIndex)
{
	iIndex = Math.min(oList.options.length - 1, iIndex);
	iIndex = Math.max(0, iIndex);
	if (oList.options.length > 0)
	{
		oList.options[iIndex].selected = true;
	}
};

Select.getSelectedIndexes = function (oList)
{
	var aIDs = new Array();
	for (var i = 0; i < oList.options.length; i++)
	{
		if (oList.options[i].selected)
		{
			aIDs.push(i);
		}
	}
	return aIDs;
};

Select.getSelectedIndex = function (oList)
{
	for (var i = 0; i < oList.options.length; i++)
	{
		if (oList.options[i].selected)
		{
			return i;
		}
	}
};

Select.deselectAll = function (oList)
{
	for (var i = 0; i < oList.options.length; i++)
	{
		oList.options[i].selected = false;
	}
};

Select.clear = function (oList)
{
	for (var i = oList.options.length - 1; i >= 0; i--)
	{
		Select.remove(oList, i);
	}
};

Select.removeDummy = function (oList)
{
	if (oList.options.length == 1 && oList.options[0].text == "")
	{
		Select.remove(oList, 0);
	}
};

Select.move = function (oListFrom, oListTo, iIndex)
{
	var oOption = oListFrom.options[iIndex];
	var sText = oOption.text;
	var sValue = oOption.value;

	Select.remove(oListFrom, iIndex);

	Select.add(oListTo, sText, sValue, true);

	Select.select(oListFrom, iIndex);
};

Select.moveMultiple = function (oListFrom, oListTo, aIndexes)
{
	aIndexes.sort();

	var iSelectIndex = 0;

	for (var i = 0; i < aIndexes.length; i++)
	{
		var oOption = oListFrom.options[aIndexes[i]];
		var sText = oOption.text;
		var sValue = oOption.value;

		Select.add(oListTo, sText, sValue, true);

		iSelectIndex = aIndexes[i];
	}

	for (var i = aIndexes.length - 1; i >= 0; i--)
	{
		Select.remove(oListFrom, aIndexes[i]);
	}

	Select.select(oListFrom, iSelectIndex - aIndexes.length);
};

Select.shiftUp = function (oList, iIndex)
{
	if (iIndex > 0)
	{
		var oOption = oList.options[iIndex];
		var oPrevOption = oList.options[iIndex - 1];
		var sText = oOption.text;
		var sValue = oOption.value;
		oOption.text = oPrevOption.text;
		oOption.value = oPrevOption.value;
		oPrevOption.text = sText;
		oPrevOption.value = sValue;

		Select.deselectAll(oList);
		Select.select(oList, iIndex - 1);
	}
};

Select.shiftDown = function (oList, iIndex)
{
	if (iIndex < oList.options.length - 1)
	{
		var oOption = oList.options[iIndex];
		var oNextOption = oList.options[iIndex + 1];
		var sText = oOption.text;
		var sValue = oOption.value;
		oOption.text = oNextOption.text;
		oOption.value = oNextOption.value;
		oNextOption.text = sText;
		oNextOption.value = sValue;

		Select.deselectAll(oList);
		Select.select(oList, iIndex + 1);
	}
};

function linkSubmit(oLink, sFormID)
{
	oHidden = document.createElement("input");
	oHidden.id = oLink.id + "Hidden";
	oHidden.name = oLink.id;
	oHidden.type = "hidden";
	oHidden.value = oLink.innerHTML;
	oLink.parentNode.appendChild(oHidden);

	oForm = document.getElementById(sFormID);
	oForm.submit();

	return false;
}