function openWindow(url, width, height, name)
{
	var top = 0;
	var left = 0;
	if (!width)
		width = screen.availWidth - 10;
	else
	{
		if (width > screen.availWidth - 10)
			width = screen.availWidth - 10;
		left = (screen.availWidth - width - 10) / 2;
	}
	if (!height)
		height = screen.availHeight - 30;
	else
	{
		if (height > screen.availHeight - 30)
			height = screen.availHeight - 30;
		top = (screen.availHeight - height - 30) / 2;
	}
	var win = window.open(url, name, "top=" + top +",left=" + left + ",width=" + width + ",height=" + height + ",resize=no,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no,fullscreen=no");
	return win;
}

function offsetAbsolute(obj)
{
	var width = obj.offsetWidth;
	var height = obj.offsetHeight;
	var left = 0;
	var top = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			left += obj.offsetLeft;
			top += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		left = obj.x;
		top = obj.y;
	}
	return { top: top, bottom: top + height, left: left, right: left + width };
}

function AttachEvent(obj, evt, fnc, useCapture)
{
	if (!useCapture) useCapture = false;
	if (obj.attachEvent) return obj.attachEvent("on" + evt, fnc);
	if (evt == "selectstart" && fnc == PreventDefault && obj.style.setProperty)
		return obj.style.setProperty("-moz-user-select", "none", "");
	if (obj.addEventListener)
	{
		obj.addEventListener(evt, fnc, useCapture);
		return true;
	}
	return false;
}
function DetachEvent(obj, evt, fnc, useCapture)
{
	if (!useCapture) useCapture = false;
	if (obj.detachEvent) return obj.detachEvent("on" + evt, fnc);
	if (evt == "selectstart" && fnc == PreventDefault && obj.style.setProperty)
		return obj.style.setProperty("-moz-user-select", "", "");
	if (obj.removeEventListener) return obj.removeEventListener(evt, fnc, useCapture);
}
function PreventDefault(evt)
{
	if (!evt && window.event) evt = window.event;
	if (evt != null)
	{
		if (typeof(evt.preventDefault) == "function")
			evt.preventDefault();
		else
			evt.returnValue = false;
	}
	return false;
}

function RecentProgID(ids)
{
	if (!window.ActiveXObject)
		return null;
	var found = false;
	for (var i = 0; i < ids.length; i++)
	{
		try
		{
			var obj = new ActiveXObject(ids[i]);
			found = true;
			break;
		}
		catch (e) { }
	}
	if (!found)
		throw "Could not retreive a valid progID of Class: " + ids[ids.length - 1];
	return ids[i];
}
var XMLHTTP_PROGID = RecentProgID(["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"]);
function CreateXmlHttp()
{
	if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else
		return new ActiveXObject(XMLHTTP_PROGID);
}
function XmlHttpRequest(url, callback, userData)
{
	var xmlHttp;
	this.send = function(data)
	{
		xmlHttp = CreateXmlHttp();
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = _callback;
		xmlHttp.send(data);
		return true;
	}
	function _callback()
	{
		if (xmlHttp.readyState == 4)
		{
			if (!callback)
				return;
			var response =
			{
				status: xmlHttp.status,
				statusText: xmlHttp.statusText,
				text: xmlHttp.responseText,
				userData: userData
			};
			callback(response);
			xmlHttp = null;
		}
	}
}
