Bw.Widgets = {};

Bw.Widgets.Widget = 
{	
	superclassName: null,
	selfclassName: "Bw.Widgets.Widget",
	
	initialize: function ()
	{
		this.oncontextmenu = function () { return false; };
		return false;
	},
	
	getContainer: function (containerClass, terminal)
	{
		var e = this.parentNode;
		while (e != null)
		{
			if (e.selfclass)
			{
				if (!containerClass) return e;
				else if (terminal && Bw.instanceOf (e, containerClass)) return e;
				else if (!terminal && Bw.inherits (e, containerClass)) return e;
			}
	
			e = e.parentNode;
		}
		
		return null;
	},
	
	isContainedBy: function (el)
	{
		var p = this;
		while (p != null)
		{
			if (p == el)
			{
				return true;
			}
			p = el.parentNode;
		}
		return false;
	},
	
	setSize: function (w, h)
	{
		this.style.width = w + "px";
		this.style.height = h + "px";
	},
	
	getGlobalPosition: function ()
	{
		var t = this.offsetTop;
		var l = this.offsetLeft;
		
	    var p = this.offsetParent;
	    while (p) 
		{
	        t += p.offsetTop;
	       	l += p.offsetLeft;
	        p = p.offsetParent;
	    }
	    
	    return { x: l, y: t};
	},
	
	reparentChildren: function (to)
	{
		var f;
		while ((f = this.firstChild) != null)
		{
			this.removeChild (f);
			if (to) to.appendChild (f);
		}
	},
	
	enable: function ()
	{
		this.disabled = false;
	},

	disable: function ()
	{
		this.disabled = true;
	},
	
	show: function ()
	{
		this.style.display = "block";
	},
	
	hide: function ()
	{
		this.style.display = "none";
	},
	
	visible: function ()
	{
		return (this.style.display != "none");
	}
};

