Rectangle = function(l, t, w, h)
{
	this._left = -1;
	this._top = -1;
	this._right = -1;
	this._bottom = -1;

	if (typeof(l) != "undefined" && l != null)
		this._left = l;

	if (typeof(t) != "undefined" && t != null)
		this._top = t;

	if (typeof(w) != "undefined" && w != null)
		this._right = this._left + w;

	if (typeof(h) != "undefined" && h != null)
		this._bottom = this._top + h;
}

Rectangle.prototype.get_left = function()
{
	return this._left;
}

Rectangle.prototype.set_left = function(v)
{
	var w = this.get_width();

	this._left = v;
	this._right = this._left + w;
}

Rectangle.prototype.get_top = function()
{
	return this._top;
}

Rectangle.prototype.set_top = function(v)
{
	var h = this.get_height();

	this._top = v;
	this._bottom = this._top + h;
}

Rectangle.prototype.toString = function()
{
	return "left=" + this._left + ", top=" + this._top + ", right=" + this._top + ", bottom=" + this._bottom;
}

Rectangle.prototype.isEmpty = function()
{
	return this.get_width() <= 0 || this.get_height() <= 0;
}

Rectangle.prototype.get_width = function()
{
	return this._right - this._left;
}

Rectangle.prototype.set_width = function(w)
{
	this._right = this._left + w;
}

Rectangle.prototype.get_height = function()
{
	return this._bottom - this._top;
}

Rectangle.prototype.set_height = function(h)
{
	this._bottom = this._top + h;
}

WindowFeature = function()
{
	this.resizable = true;
	this.status = false;
	this.location = false;
	this.toolbar = false;
	this.center = true;
	this.help = false;
	this.scroll = false;
	this.toolbar = false;

	this.toOpenWindowFeature = function()
	{
		var feature = "";

		feature = this._appendOpenWindowParams("location", this._boolToString(this.location), feature);
		feature = this._appendOpenWindowParams("status", this._boolToString(this.status), feature);
		feature = this._appendOpenWindowParams("resizable", this._boolToString(this.resizable), feature);
		feature = this._appendOpenWindowParams("toolbar", this._boolToString(this.toolbar), feature);
		feature = this._appendOpenWindowParams("scrollbars", this._boolToString(this.scroll), feature);
		feature = this._appendOpenWindowParams("toolbar", this._boolToString(this.toolbar), feature);
		
		return feature;
	}
	
	this._appendOpenWindowParams = function(paramName, paramValue, feature)
	{
		if (feature.length > 0)
			feature += ",";

		feature += paramName + "=" + paramValue;

		return feature;
	}

	this.toDialogWindowFeature = function()
	{
		var feature = "";

		feature = this._appendDialogWindowParams("status", this._boolToString(this.status), feature);
		feature = this._appendDialogWindowParams("resizable", this._boolToString(this.resizable), feature);
		feature = this._appendDialogWindowParams("scroll", this._boolToString(this.scroll), feature);
		feature = this._appendDialogWindowParams("help", this._boolToString(this.help), feature);
		feature = this._appendDialogWindowParams("center", this._boolToString(this.center), feature);
		
		return feature;
	}

	this._appendDialogWindowParams = function(paramName, paramValue, feature)
	{
		if (feature.length > 0)
			feature += ";";

		feature += paramName + ":" + paramValue;

		return feature;
	}

	this._boolToString = function(boolData)
	{
		if (boolData)
			return "yes";
		else
			return "no";
	}
}

WindowHelperClass = function()
{
	this.openWindow = function(link, name, rect, wFeature)
	{
		if (!wFeature)
			wFeature = new WindowFeature();

		if (!name)
			name = "_blank";

		var feature = "";

		if (rect)
		{
			rect = this._adjustRect(rect);

			if (rect.isEmpty() == false)
				feature = this._rectToFeatureString(rect, wFeature);
		}

		if (feature.length > 0)
			feature += "," + wFeature.toOpenWindowFeature();
		else
			feature = wFeature.toOpenWindowFeature();

		window.open(link, name, feature);
	}

	this.showModalDialog = function(link, rect, wFeature, arg)
	{
		if (!wFeature)
			wFeature = new WindowFeature();

		var feature = "";

		if (rect)
		{
			rect = this._adjustRect(rect);

			if (rect.isEmpty() == false)
				feature = this._rectToDialogFeatureString(rect, wFeature);
		}

		if (feature.length > 0)
			feature += ";" + wFeature.toDialogWindowFeature();
		else
			feature = wFeature.toDialogWindowFeature();

		return window.showModalDialog(link, arg, feature);
	}

	this._adjustRect = function(rect)
	{
		if (rect.isEmpty() == false)
		{
			if (rect.get_width() > window.screen.width)
				rect.set_width(window.screen.width * 0.98);

			if (rect.get_height() > window.screen.height)
				rect.set_height(window.screen.height * 0.90);

			if (rect.get_left() < 0)
				rect.set_left((window.screen.width - rect.get_width()) * 0.5 - 4);

			if (rect.get_top() < 0)
				rect.set_top((window.screen.height - rect.get_height()) * 0.5 - 32);
		}

		return rect;
	}

	this._rectToFeatureString = function(rect, wFeature)
	{
		var feature = "";

		feature = wFeature._appendOpenWindowParams("left", rect._left, feature);
		feature = wFeature._appendOpenWindowParams("top", rect._top, feature);
		feature = wFeature._appendOpenWindowParams("width", rect.get_width(), feature);
		feature = wFeature._appendOpenWindowParams("height", rect.get_height(), feature);

		return feature;
	}

	this._rectToDialogFeatureString = function(rect, wFeature)
	{
		var feature = "";

		if (!wFeature.center)
		{
			feature = wFeature._appendDialogWindowParams("dialogLeft", rect._left + "px", feature);
			feature = wFeature._appendDialogWindowParams("dialogTop", rect._top + "px", feature);
		}

		feature = wFeature._appendDialogWindowParams("dialogWidth", rect.get_width() + "px", feature);
		feature = wFeature._appendDialogWindowParams("dialogHeight", rect.get_height() + "px", feature);

		return feature;
	}
}

document.get_head = function()
{
	var head = null;
	var objs = this.getElementsByTagName("HEAD");

	if (objs.length > 0)
		head = objs[0];

	return head;
}

document.get_base = function()
{
	var base = null;
	var objs = this.getElementsByTagName("BASE");

	if (objs.length > 0)
		base = objs[0];

	return base;
}

document.setBaseElement = function(target, href)
{
	var base = this.get_base();

	if (!base)
	{
		var head = this.get_head();

		if (head != null)
		{
			base = this.createElement("BASE");
			head.appendChild(base);
		}
	}

	if (target)
		base.target = target;

	if (href)
		base.href = href;
}