		
		function div_window(set_new)
		{
			this.obj = null;
			this.controlPanel = null;
			
			this.mouseDown = false;
			
			this.x = 0;
			this.y = 0;
			
			this.x0 = 0;
			this.y0 = 0;
			
			this.isIE = false;
			
			if (navigator.userAgent.indexOf('MSIE')>0) this.isIE = true;
			
			this.getObjOffset = function(obj)
			{
				var offset = new Object();
				offset["left"] = 0;
				offset["top"] = 0;
				offset["width"] = 0;
				offset["height"] = 0;
				
				if (obj!=null)
				{
					offset["width"] = obj.offsetWidth;
					offset["height"] = obj.offsetHeight;
				}
				while (obj!=null)
				{
					offset["left"] += obj.offsetLeft;
					offset["top"] += obj.offsetTop;
					obj = obj.offsetParent;
				}
				return offset;
			}
			
			this.setEvent = function(elem,event,func)
			{
				if ( elem.addEventListener ) 
				{ 
					elem.addEventListener(event, func, true);
				} else 
				if ( elem.attachEvent ) 
				{ 
					elem.attachEvent("on" + event, function(e){ func.handleEvent(e); });
				}
			}
			
			this.newWindow = function(id)
			{
				this.obj = document.createElement("div");
				if (id!=null) this.obj.id = id;
				this.obj.style.display = "block";
				this.obj.style.position = "absolute";
				this.obj.style.left = "0px";
				this.obj.style.top = "0px";
				this.obj.style.visibility = "hidden";
				this.x0 = 0;
				this.y0 = 0;
				this.x = 0;
				this.y = 0;
			}
			
			this.setWindow = function(obj)
			{
				this.obj = obj;
				this.getPos();
			}
			
			this.getPos = function()
			{
				this.x = this.obj.offsetLeft;
				this.y = this.obj.offsetTop;
				this.x0 = this.x;
				this.y0 = this.y;
			}
			
			this.setPos = function(x,y)
			{
				this.obj.style.left = x + "px";
				this.obj.style.top = y + "px";
			}
			
			this.setCenter = function(obj)
			{
				if ( (obj==undefined) || (obj==null) )
				{
					width = document.body.offsetWidth || window.innerWidth;
					height = document.body.offsetHeight || window.innerHeight;
					this.obj.style.left = ( ( width / 2 ) - ( this.obj.offsetWidth / 2 ) ) + "px";
					this.obj.style.top = ( ( height / 2 ) - ( this.obj.offsetHeight / 2 ) ) + "px";
				} else
				{
					offset = this.getObjOffset(obj);
					this.obj.style.left = ( ( offset["left"] + ( offset["width"] / 2 ) ) - ( this.obj.offsetWidth / 2 ) ) + "px";
					this.obj.style.top = ( ( offset["top"] + ( offset["height"] / 2 ) ) - ( this.obj.offsetHeight / 2 ) ) + "px";
				}
			}
			
			this.setInScreen = function()
			{
				width = document.body.offsetWidth || window.innerWidth;
				height = document.body.offsetHeight || window.innerHeight;
				
				if (this.obj.offsetLeft<0) this.obj.style.left = "0px";
				if (this.obj.offsetTop+this.obj.offsetHeight>height) this.obj.style.top = (height - this.obj.offsetHeight - 150) + "px";
			}
			
			this.moveToScreen = function()
			{
				width = document.documentElement.clientWidth || window.innerWidth;
				height = document.documentElement.clientHeight || window.clientHeight;
				
				
				offset = this.getObjOffset(this.obj);
				
				if (offset["top"]<document.documentElement.scrollTop) this.obj.style.top = (document.documentElement.scrollTop + 15) + "px";
				
				if (this.obj.offsetLeft<0) this.obj.style.left = document.documentElement.scrollLeft + "px";
				if (offset["top"] + offset["height"]>height + document.documentElement.scrollTop) this.obj.style.top = (height + document.documentElement.scrollTop - offset["height"] - 15) + "px";
			}
			
			this.setHTML = function(html)
			{
				this.obj.innerHTML = html;
			}
			
			this.clear = function()
			{
				this.innerHTML = '';
			}
			
			this.setControlPanel = function(obj)
			{
				this.controlPanel = obj;
				this.controlPanel.style.cursor = "move";
				this.setEvent(this.controlPanel,"mousedown",this);
				this.setEvent(this.controlPanel,"mousemove",this);
				this.setEvent(this.controlPanel,"mouseout",this);
				this.setEvent(this.controlPanel,"mouseup",this);
			}
			
			this.show = function()
			{
				this.obj.style.visibility = "visible";
			}
			
			this.hide = function()
			{
				this.obj.style.visibility = "hidden";
			}
			
			this.handleEvent = function(evt)
			{
				evt = evt || window.event;
				
				
				//evt.preventDefault;
				if (this.isIE) { evt.cancelBubble = true; } else { evt.stopPropagation; }
				
				if (evt.type=="mousedown") 
				{
					this.getPos();
					this.mouseDown = true;
					this.x0 = evt.clientX;
					this.y0 = evt.clientY;
					
					_left = this.x + evt.clientX - this.x0;
					_top = this.y + evt.clientY - this.y0;
					
					this.setPos(_left, _top );
					this.x0 = evt.clientX;
					this.y0 = evt.clientY;
				}
				
				if (evt.type=="mousemove")
				{
					if (this.mouseDown)
					{
						this.setPos(this.x + evt.clientX - this.x0, this.y + evt.clientY - this.y0 );
					}	
				}
				
				if (evt.type=="mouseout")
				{
					this.mouseDown = false;
				}
				
				if (evt.type=="mouseup")
				{
					this.mouseDown = false;
				}
			}
			
			if (set_new) this.newWindow();
			
			return this;
		}
