/*
 * @(#)dwt.js
 *
 * Copyright (C) 2006 Brian Alexander Gaydek
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Based on Bride of Windows Copyright (C) 2002 Mike Hall.
 * @see	http://www.brainjar.com/dhtml/windows/
 */


/**
 * DHTML Windowing Toolkit package.
 */
var dwt;
if (!dwt) {
	dwt = { };
}


/**
 * Global DWT window properties.
 */
dwt.WindowManager = {
	
	// Window styles
	FRAME: {
		tagName:			"div",
		activeClassName:	"dwtWindow",
		inactiveClassName:	"dwtInactiveWindow"
	},
	TITLE_BAR: {
		tagName:			"div",
		activeClassName:	"dwtWindowTitleBar",
		inactiveClassName:	"dwtInactiveWindowTitleBar"
	},
	TITLE_BAR_CHROME_LEFT: {
		tagName:			"td",
		activeClassName:	"dwtWindowTitleBarChromeLeft",
		inactiveClassName:	"dwtInactiveWindowTitleBarChromeLeft"
	},
	TITLE_BAR_CHROME_RIGHT: {
		tagName:			"td",
		activeClassName:	"dwtWindowTitleBarChromeRight",
		inactiveClassName:	"dwtInactiveWindowTitleBarChromeRight"
	},
	TITLE_BAR_CELL: {
		tagName:			"td",
		activeClassName:	"dwtWindowTitleBar",
		inactiveClassName:	"dwtInactiveWindowTitleBar"
	},
	TITLE_BAR_TEXT: {
		tagName:			"div",
		activeClassName:	"dwtWindowTitleBarText",
		inactiveClassName:	"dwtInactiveWindowTitleBarText"
	},
	TITLE_BAR_CONTROL: {
		tagName:			"img",
		activeClassName:	"dwtWindowTitleBarControl"
	},
	BORDER: {
		tagName:			"div",
		activeClassName:	"dwtWindowBorder",
		inactiveClassName:	"dwtInactiveWindowBorder"
	},
	CONTENTS: {
		tagName:			"div",
		activeClassName:	"dwtWindowContents",
		inactiveClassName:	"dwtInactiveWindowContents"
	},
	STATUS_BAR: {
		tagName:			"div",
		activeClassName:	"dwtWindowStatusBar",
		inactiveClassName:	"dwtWindowStatusBar"
	},
	
	// Windows
	windows: 			new Array(),
	
	// Focus
	activeWindow:		null,
	activeZIndex:		0,
	
	// Move
	isMoving:			false,
	moveXOffset:		null,
	moveYOffset:		null,
	
	// Minimize
	titleBarTextMinimizedWidth: 85,
	
	// Resize
	isResizing:			false,
	resizeCornerSize:	13,
	resizeDirection:	null,
	resizeXPosition:	null,
	resizeYPosition:	null,
	resizeLeft:			null,
	resizeTop:			null,
	resizeWidth:		null,
	nsResizeTargets:	null,
	
	/**
	 * The comparator that will be used to sort
	 * a window's north-south resize targets.
	 *
	 * @param	o1	The first object to be compared.
	 * @param	o2	the first object to be compared.
	 *
	 * @return	A negative integer, zero, or a positive integer as the first
	 *        	argument is less than, equal to, or greater than the second.
	 */
	nsResizeTargetsOrdering: function (o1, o2) {
		
		return o1.resized - o2.resized;
	}
	
};


/**
 * A DHTML window.  
 */ 
dwt.Window = function (element) {
	
	// Frame
	this.frame = element;
	this.frame.dwtWindow = this;

	this.setFocusClassNames(
			this.frame, dwt.WindowManager.FRAME.inactiveClassName);
	this.id = this.frame.id || this.frame.getAttribute("id");
	this.effect = this.frame.getAttribute("effect") || this.frame.effect;
	Event.observe(this.frame, "mousemove",
			dwt.Window.prototype.frameMousemove, false);
	Event.observe(this.frame, "mouseout",
			dwt.Window.prototype.frameMouseout, false);
	Event.observe(this.frame, "mousedown",
			dwt.Window.prototype.frameMousedown, false);
	
	// Title Bar
	this.titleBar = this.getWindowComponent(this.frame,
			dwt.WindowManager.TITLE_BAR.tagName,
			dwt.WindowManager.TITLE_BAR.activeClassName);
	this.setFocusClassNames(this.titleBar,
			dwt.WindowManager.TITLE_BAR.inactiveClassName);
	this.titleBar.minimizedClassName =
			this.titleBar.getAttribute("minimizedClass");
	if (!this.titleBar.minimizedClassName) {
		this.titleBar.minimizedClassName =
				this.titleBar.restoreClassName;
	}
	this.titleBar.inactiveMinimizedClassName =
			this.titleBar.getAttribute("inactiveMinimizedClass");
	if (!this.titleBar.inactiveMinimizedClassName) {
		this.titleBar.inactiveMinimizedClassName =
				this.titleBar.inactiveClassName;
	}
	Event.observe(this.titleBar, "mousedown",
			dwt.Window.prototype.titleBarMousedown, false);
	var titleBarCells = this.titleBar.getElementsByTagName(
			dwt.WindowManager.TITLE_BAR_CELL.tagName);
	for (var i = 0; i < titleBarCells.length; i++) {
		titleBarCells[i].dwtWindow = this;
		if (Element.hasClassName(titleBarCells[i],
				dwt.WindowManager.TITLE_BAR_CHROME_LEFT.activeClassName)) {
			this.setFocusClassNames(titleBarCells[i],
					dwt.WindowManager.TITLE_BAR_CHROME_LEFT.inactiveClassName);
		} else if(Element.hasClassName(titleBarCells[i],
				dwt.WindowManager.TITLE_BAR_CHROME_RIGHT.activeClassName)) {
			this.setFocusClassNames(titleBarCells[i],
					dwt.WindowManager.TITLE_BAR_CHROME_RIGHT.inactiveClassName);
		} else {
			this.setFocusClassNames(titleBarCells[i],
					dwt.WindowManager.TITLE_BAR_CELL.inactiveClassName);
		}
	}
	this.titleBarText = this.getWindowComponent(this.titleBar,
			dwt.WindowManager.TITLE_BAR_TEXT.tagName,
			dwt.WindowManager.TITLE_BAR_TEXT.activeClassName);
	this.titleBarText.dwtWindow = this;
	this.setFocusClassNames(this.titleBarText,
			dwt.WindowManager.TITLE_BAR_TEXT.inactiveClassName);
	
	// Controls
	this.minimizeControl = null;
	this.closeControl = null;
	var controls = Element.getElementsByTagAndClassName(this.frame,
			dwt.WindowManager.TITLE_BAR_CONTROL.tagName,
			dwt.WindowManager.TITLE_BAR_CONTROL.activeClassName);
	for (var i = 0; i < controls.length; i++) {
		if (controls[i].getAttribute("controlType").toLowerCase()
				== "minimize") {
			this.minimizeControl = controls[i];
			this.minimizeControl.dwtWindow = this;
			this.setControlImgSrcs(this.minimizeControl);
		} else if (controls[i].getAttribute("controlType").toLowerCase()
				== "close") {
			this.closeControl = controls[i];
			this.closeControl.dwtWindow = this;
			this.setControlImgSrcs(this.closeControl);
		}
		Event.observe(controls[i], "mouseover",
				dwt.Window.prototype.controlMouseover, false);
		Event.observe(controls[i], "mouseout",
				dwt.Window.prototype.controlMouseout, false);
		Event.observe(controls[i], "click",
				dwt.Window.prototype.controlClick, false);
	}
	
	// Border
	this.border = this.getWindowComponent(this.frame,
			dwt.WindowManager.BORDER.tagName,
			dwt.WindowManager.BORDER.activeClassName);
	this.setFocusClassNames(this.border,
			dwt.WindowManager.BORDER.inactiveClassName);
	
	// Contents
	this.contents = new Array();
	var elements = Element.getElementsByTagAndClassName(this.frame,
			dwt.WindowManager.CONTENTS.tagName,
			dwt.WindowManager.CONTENTS.activeClassName);
	for (var i = 0; i < elements.length; i++) {
		elements[i].dwtWindow = this;
		this.setFocusClassNames(elements[i],
				dwt.WindowManager.CONTENTS.inactiveClassName);
		Event.observe(elements[i], "click",
				dwt.Window.prototype.contentsClick, false);
		this.contents.push(elements[i]);
	}
	elements = Element.getElementsByTagAndClassName(this.frame,
			dwt.WindowManager.STATUS_BAR.tagName,
			dwt.WindowManager.STATUS_BAR.activeClassName);
	for (var i = 0; i < elements.length; i++) {
		elements[i].dwtWindow = this;
		this.setFocusClassNames(elements[i],
				dwt.WindowManager.STATUS_BAR.inactiveClassName);
		Event.observe(elements[i], "click",
				dwt.Window.prototype.contentsClick, false);
		this.contents.push(elements[i]);
	}
	
	// Vertical (north-south) resize targets
	this.nsResizeTargets = new Array();
	for (var i = 0; i < this.contents.length; i++) {
		var attribute = this.contents[i].getAttribute("nsResizeTarget")
				|| this.contents[i].nsResizeTarget;
		if (attribute && attribute.toLowerCase() == "true") {
			this.nsResizeTargets.push(this.contents[i]);
		}
	}
	// If no targets are specified, use the first contents child.
	if (this.nsResizeTargets.length == 0) {
		this.nsResizeTargets.push(this.getWindowComponent(this.frame,
				dwt.WindowManager.CONTENTS.tagName,
				dwt.WindowManager.CONTENTS.activeClassName));
	}
	
	// State
	this.isOpen				= false;
	this.isMinimized		= false;
	
	// Callbacks
	this.setZIndexOnFocus	= new Array();
	this.setZIndexOnFocus.push(this.frame);
	
	// Minimum dimensions
	this.minimumWidth		= null;
	this.minimumHeight		= 1;
	this.textClipWidth		= null;
	
	// Restore position
	this.restoreFrameLeft	= null;
	this.restoreFrameTop	= null;
	this.restoreFrameWidth	= null;
	this.restoreFrameHeight	= null;
	this.restoreTextWidth	= null;
	
	// Save the inital window position and width and reposition the window
	var initialLeft = this.frame.style.left;
	var initialWidth = parseInt(this.frame.style.width);
	this.frame.style.left = -this.titleBarText.offsetWidth + "px";
	
	// Determine the offset from the frame to the contents for MSIE
	if (navigator.appVersion.match(/\bMSIE\b/)) {
		Element.hide(this.titleBarText);
		var initialOffsetWidth = this.border.offsetWidth;
		var offsetFromFrame = this.frame.offsetWidth - initialOffsetWidth;
		this.border.style.width = initialOffsetWidth + "px";
		var outerBoxWidth = this.border.offsetWidth - initialOffsetWidth;
		this.border.offsetFromFrame = offsetFromFrame + outerBoxWidth;
		this.border.style.width = "";
		for (var i = 0; i < this.contents.length; i++) {
			initialOffsetWidth = this.contents[i].offsetWidth;
			offsetFromFrame =
					this.frame.offsetWidth - initialOffsetWidth;
			this.contents[i].style.width = initialOffsetWidth + "px";
			outerBoxWidth = this.contents[i].offsetWidth - initialOffsetWidth;
			this.contents[i].offsetFromFrame = offsetFromFrame + outerBoxWidth;
			this.contents[i].style.width =
					(initialWidth - this.contents[i].offsetFromFrame) + "px";
		}
		this.border.style.width =
					(initialWidth - this.border.offsetFromFrame) + "px";
		Element.show(this.titleBarText);
	}
	
	// Determine the width of the frame box, including MSIE discrepancy.
	this.titleBarText.parentNode.style.width = "";
	var initialOffsetWidth = this.frame.offsetWidth;
	this.frame.style.width = initialOffsetWidth + "px";
	var outerBoxWidth = this.frame.offsetWidth - initialOffsetWidth;
	var contentWidth = initialOffsetWidth - outerBoxWidth;
	this.frame.style.width = contentWidth + "px";
	if (navigator.appVersion.match(/\bMSIE\b/)) {
		this.border.offsetFromFrame -= outerBoxWidth;
		for (var i = 0; i < this.contents.length; i++) {
			this.contents[i].offsetFromFrame -= outerBoxWidth;
		}
	}
	
	// Determine the minimum width
	this.isOpen = true;
	this.minimize();
	if (navigator.appVersion.match(/\bMSIE\b/)) {
		this.minimumWidth = this.frame.offsetWidth - outerBoxWidth;
	} else {
		this.minimumWidth = this.frame.offsetWidth;
	}
	
	// Determine the title bar text clipping width
	this.titleBarText.style.width = "";
	this.clipTextMinimumWidth = this.frame.offsetWidth - outerBoxWidth;
	
	// Restore the window
	this.restore();
	this.titleBarText.parentNode.style.width = "100%";
	this.isOpen = false;
	initialWidth = Math.max(initialWidth, this.minimumWidth);
	this.frame.style.width = initialWidth + "px";
	if (navigator.appVersion.match(/\bMSIE\b/)) {
		for (var i = 0; i < this.contents.length; i++) {
			this.contents[i].style.width =
					(initialWidth - this.contents[i].offsetFromFrame) + "px";
		}
	}
	
	// Clip the title bar text if necessary
	if (this.clipTextMinimumWidth >= this.minimumWidth) {
		this.titleBarText.style.width =
				(dwt.WindowManager.titleBarTextMinimizedWidth
				+ initialWidth - this.minimumWidth) + "px";
	}
	
	// Restore the window position
	Element.hide(this.frame);
	this.frame.style.left = initialLeft;
	
	// Set style.visibility so to "visible" so that visibility
	// can be controlled using the style.display property.
	Element.hide(this.frame);
	this.frame.style.visibility = "visible";
}

dwt.Window.prototype = {
	
	/**
	 * Gets the window component with the specified values and
	 * sets the dwtWindow property of the component to this window.
	 *
	 * @param	element		The parent element.
	 * @param	tagName		The tag name.
	 * @param	className	The class name.
	 *
	 * @return	The window component.
	*/
	getWindowComponent: function (element, tagName, className) {
		
		var component = Element.getFirstChildByTagAndClassName(
				element, tagName, className);
		if (component) {
			component.dwtWindow = this;
		}
		
		return component;
	},
	
	/**
	 * Sets the class names for active and inactive focus states of the
	 * specified element.  The class names of the active and inactive
	 * focus states are set to the values of the activeClass and inactiveClass
	 * attributes, respectively, if they exist.  If the corresponding attribute
	 * does not exist, then the class name of the active state is set to the
	 * element's current class name while the class name of the inactive state
	 * is set to the specified default value. 
	 *
	 * @param	element						The element.
	 * @param	defaultInactiveClassName	The default class name
	 *       	                        	of the inactive state.
	 */
	setFocusClassNames: function (element, defaultInactiveClassName) {
		


		element.activeClassName = element.getAttribute("activeClass");



		if (!element.activeClassName) {
			element.activeClassName = element.className;
		}
		element.inactiveClassName = element.getAttribute("inactiveClass");
		if (!element.inactiveClassName) {
			element.inactiveClassName = defaultInactiveClassName;
		}
	},
	
	/**
	 * Sets the mouseover, restore, and restore mouseover src values for
	 * the specified control.  The mouseover, restore, and restore mouseover
	 * src values are set to the values of the mouseoverSrc, restoreSrc, and
	 * restoreMouseoverSrc attributes, respectively, if they exist.  If the
	 * restoreSrc attribute does not exist then the restore src is set to
	 * the current src value.  If the corresponding mouseoversrc value
	 * does not exist for a state then the mouseover src value is set to
	 * the normal src value for that state.
	 * 
	 * @param	control		The control img.
	 */
	setControlImgSrcs: function (control) {
		
		control.mouseoutSrc = control.src;
		
		var mouseoverSrc = control.getAttribute("mouseoverSrc");
		if (mouseoverSrc) {
			new Image().src = mouseoverSrc;
			control.mouseoverSrc = mouseoverSrc;
		} else {
			control.mouseoverSrc = control.src;
		}
		
		var restoreSrc = control.getAttribute("restoreSrc");
		if (restoreSrc) {
			new Image().src = restoreSrc;
			control.restoreSrc = restoreSrc;
		} else {
			control.restoreSrc = control.src;
		}
		
		var restoreMouseoverSrc = control.getAttribute("restoreMouseoverSrc");
		if (restoreMouseoverSrc) {
			new Image().src = restoreMouseoverSrc;
			control.restoreMouseoverSrc = restoreMouseoverSrc;
		} else {
			control.restoreMouseoverSrc = control.restoreSrc;
		}
	},
	
	/**
	 * Removes focus from the active window and gives focus to this window.
	 */
	focus: function () {
		
	  	if (this == dwt.WindowManager.activeWindow) {
			return;
		}
		
		// Remove focus from the active window
		if (dwt.WindowManager.activeWindow) {
			var elements = new Array();
			elements.push(dwt.WindowManager.activeWindow.frame);
			if (dwt.WindowManager.activeWindow.isMinimized) {
				dwt.WindowManager.activeWindow.titleBar.className =
						dwt.WindowManager.activeWindow.titleBar.inactiveMinimizedClassName;
			} else {
				elements.push(dwt.WindowManager.activeWindow.titleBar);
			}
			var titleBarCells =
					dwt.WindowManager.activeWindow.titleBar.getElementsByTagName("td");
			for (var i = 0; i < titleBarCells.length; i++) {
				elements.push(titleBarCells[i]);
			}
			elements.push(dwt.WindowManager.activeWindow.titleBarText);
			elements.push(dwt.WindowManager.activeWindow.border);
			for (var i = 0;
					i < dwt.WindowManager.activeWindow.contents.length;
					i++) {
				elements.push(dwt.WindowManager.activeWindow.contents[i]);
			}
			
			for (var i = 0; i < elements.length; i++) {
				if (elements[i].inactiveClassName) {
					elements[i].className = elements[i].inactiveClassName;
				}
			}
		}
		
		// Give focus to this window
		var elements = new Array();
		elements.push(this.frame);
		if (this.isMinimized) {
			this.titleBar.className = this.titleBar.minimizedClassName;
		} else {
			elements.push(this.titleBar);
		}
		var titleBarCells = this.titleBar.getElementsByTagName("td");
		for (var i = 0; i < titleBarCells.length; i++) {
			elements.push(titleBarCells[i]);
		}
		elements.push(this.titleBarText);
		elements.push(this.border);
		for (var i = 0; i < this.contents.length; i++) {
				elements.push(this.contents[i]);
		}
		
		for (var i = 0; i < elements.length; i++) {
			if (elements[i].inactiveClassName) {
				elements[i].className = elements[i].activeClassName;
			}
		}
		var zIndex = ++dwt.WindowManager.activeZIndex;
		for (var i = 0; i < this.setZIndexOnFocus.length; i++) {
			if (this.setZIndexOnFocus[i].style) {
				this.setZIndexOnFocus[i].style.zIndex = zIndex;
			}
		}
		
		dwt.WindowManager.activeWindow = this;
	},
	
	/**
	 * Shows this window.
	 *
	 * @param	effect	The (optional) open effect.
	 */
	open: function (effect) {
		
		if (this.isOpen) {
			return;
		}
		
		if (this.isMinimized) {
			this.restore();
		}
		this.focus();
		
		if (effect && effect != "" && effect.toLowerCase() != "none") {
			if (Effect[effect]) {
				new Effect[effect](this.frame);
			} else {
				Element.show(this.frame);
			}
		} else {
			Element.show(this.frame);
		}
		
		this.isOpen = true;
	},
	
	/**
	 * Hides this window.
	 *
	 * @param	effect	The (optional) close effect.
	 */
	close: function (effect) {
		
		if (effect && effect != "" && effect.toLowerCase() != "none") {
			if (Effect[effect]) {
				new Effect[effect](this.frame);
			} else {
				Element.hide(this.frame);
			}
		} else {
			Element.hide(this.frame);
		}
		
		this.isOpen = false;
	},
	
	/**
	 * Hides the contents of this window.
	 *
	 * @param	effect	The (optional) minimize effect.
	 */
	minimize: function (effect) {
		
		if (!this.isOpen || this.isMinimized) {
			return;
		}
		
		// Hide the contents
		if (effect && effect != "" && effect.toLowerCase() != "none") {
			if (Effect[effect]) {
				// TODO: Save the scroll positions
			/*	for (var i = 0; i < this.contents.length; i++) {
					this.contents[i].minimizeScrollTop =
							this.contents[i].scrollTop;
				}
			 */
				new Effect[effect](this.border);
			} else {
				Element.hide(this.border);
			}
		} else {
			Element.hide(this.border);
		}
		
		// Save the widths
		this.restoreFrameWidth = this.frame.style.width;
		this.restoreTextWidth = this.titleBarText.style.width;
		
		// Set the minimized widths
		this.titleBarText.style.width =
				dwt.WindowManager.titleBarTextMinimizedWidth + "px";
		this.titleBarText.parentNode.style.width = "";
		if (this.minimumWidth) {
			this.frame.style.width = this.minimumWidth + "px";
			this.titleBarText.parentNode.style.width = "100%";
		} else {
			this.frame.style.width = "";
			
			// TODO: Without a defined width style, Opera expands the frame
			//       rather than contraining the frame to the contents.
			if (this.frame.offsetWidth > parseInt(this.restoreFrameWidth)) {
				this.frame.style.width = this.restoreFrameWidth;
			}
		}
		this.titleBar.className = this.titleBar.minimizedClassName;
		
		// Minimize control -> restore control
		if (this.minimizeControl) {
			this.minimizeControl.src = this.minimizeControl.restoreSrc;
		}
		
		this.isMinimized = true;
	},	
	
	/**
	 * Shows the contents of this window.
	 *
	 * @param	effect	The (optional) restore effect.
	 */
	restore: function(effect) {
		
		if (!this.isMinimized) {
			return;
		}
		
		this.frame.style.width = this.restoreFrameWidth;
		this.titleBarText.style.width = this.restoreTextWidth;
		this.titleBar.className = this.titleBar.activeClassName;
		
		// Show the contents
		if (effect && effect != "" && effect.toLowerCase() != "none") {
			if (Effect[effect]) {
				new Effect[effect](this.border);
				// TODO: Restore the scroll positions
			/*	for (var i = 0; i < this.contents.length; i++) {
						this.contents[i].scrollTop =
								this.contents[i].minimizeScrollTop;
				}
			 */
			} else {
				Element.show(this.border);
			}
		} else {
			Element.show(this.border);
		}
		
		// Restore control -> minimize control
		if (this.minimizeControl) {
			this.minimizeControl.src = this.minimizeControl.mouseoutSrc;
		}
		
		this.isMinimized = false;
	},
	
	/**
	 * Responds to frame mousemove events by setting the resize cursor.
	 *
	 * @param	event	The user interface event.
	 */
	frameMousemove: function (event) {
		
		var target = null;
		if (window.event) {
			target = window.event.srcElement;
		} else if (event) {
			target = event.target;
		}
		
		// Check target, if minimized, or if resizing.
		var dwtWindow = target.dwtWindow;
		if (!dwtWindow ||
				(target != dwtWindow.frame && target != dwtWindow.border)
				|| dwtWindow.isMinimized || dwt.WindowManager.isResizing) {
			return;
		}
		
		// Get the resize direction
		var x;
		var y;
		if (window.event) {
			x = window.event.offsetX;
			y = window.event.offsetY;
		} else if (event) {
			x = event.layerX;
			y = event.layerY;
		}
		dwt.WindowManager.resizeDirection = "";
		if (y <= dwt.WindowManager.resizeCornerSize) {
			dwt.WindowManager.resizeDirection += "n";
		} else if (y >=
				dwtWindow.border.offsetHeight
				- dwt.WindowManager.resizeCornerSize) {
			dwt.WindowManager.resizeDirection += "s";
		}
		if (x <= dwt.WindowManager.resizeCornerSize) {
			dwt.WindowManager.resizeDirection += "w";
		} else if (x >=
				dwtWindow.border.offsetWidth
				- dwt.WindowManager.resizeCornerSize) {
			dwt.WindowManager.resizeDirection += "e";
		}
		
		// If not on the resize component, restore cursor;
		// otherwise set cursor to appropriate direction.
		if (dwt.WindowManager.resizeDirection == "") {
			dwt.Window.prototype.frameMouseout(event);
			return;
		}
		
		// TODO: Opera?
		document.documentElement.style.cursor =
				dwt.WindowManager.resizeDirection + "-resize";
	},
	
	/**
	 * Responds to frame mouseout events by restoring the default cursor.
	 *
	 * @param	event	The user interface event.
	 */
	frameMouseout: function (event) {
		
		if (dwt.WindowManager.isResizing) {
			return;
		}
		
		var dwtWindow = null;
		if (window.event) {
			dwtWindow = window.event.srcElement.dwtWindow;
		} else if (event) {
			dwtWindow = event.target.dwtWindow;
		}
		
		document.documentElement.style.cursor = "";
	},
	
	/**
	 * Responds to frame mousedown events by starting a resize drag.
	 *
	 * @param	event	The user interface event.
	 */
	frameMousedown: function (event) {
		
		var target = null;
		if (window.event) {
			target = window.event.srcElement;
		} else if (event) {
			target = event.target;
		}
		
		// Check target, if minimized, or if resizing.
		var dwtWindow = target.dwtWindow;
		if (!dwtWindow ||
				(target != dwtWindow.frame && target != dwtWindow.border)
				|| dwtWindow.isMinimized || dwt.WindowManager.isResizing) {
			return;
		}
		
		dwtWindow.focus();

		// Save the cursor position
		var x;
		var y;
		if (window.event) {
			x = window.event.x;
			y = window.event.y;
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		} else if (event) {
			x = event.pageX;
			y = event.pageY;
			event.preventBubble();
			event.preventDefault();
		}
		dwt.WindowManager.resizeXPosition = x;
		dwt.WindowManager.resizeYPosition = y;
		
		// Save the window position and size
		dwt.WindowManager.resizeLeft =
				parseInt(dwtWindow.frame.style.left);
		dwt.WindowManager.resizeTop =
				parseInt(dwtWindow.frame.style.top);
		dwt.WindowManager.resizeWidth =
				parseInt(dwtWindow.frame.style.width);
		dwt.WindowManager.nsResizeTargets = new Array();
		for (var i = 0; i < dwtWindow.nsResizeTargets.length; i++) {
			var resizeHeight =
					parseInt(dwtWindow.nsResizeTargets[i].style.height);
			if (!isNaN(resizeHeight)) {
				dwtWindow.nsResizeTargets[i].resizeHeight = resizeHeight;
				dwtWindow.nsResizeTargets[i].resized = 0;
				dwt.WindowManager.nsResizeTargets.push(
						dwtWindow.nsResizeTargets[i]);
			}
		}
		
		// Start capturing mousemove and mouseup events
		Event.observe(document, "mousemove",
				dwt.Window.prototype.resizeDocumentMousemove, false);
		Event.observe(document, "mouseup",
				dwt.Window.prototype.resizeDocumentMouseup, false);
		
		dwt.WindowManager.isResizing = true;
	},
	
	
	/**
	 * Responds to document mousemove events by performing a resize drag.
	 *
	 * @param	event	The user interface event.
	 */
	resizeDocumentMousemove: function (event) {
		
		if (!dwt.WindowManager.isResizing) {
			return;
		}
		
		// Set resize direction flags
		var resizeNorth = false;
		var resizeSouth = false;
		var resizeEast = false;
		var resizeWest = false;
		if (dwt.WindowManager.resizeDirection.charAt(0) == "n") {
			resizeNorth = true;
		} else if (dwt.WindowManager.resizeDirection.charAt(0) == "s") {
			resizeSouth = true;
		}
		if (dwt.WindowManager.resizeDirection.charAt(0) == "e"
				|| dwt.WindowManager.resizeDirection.charAt(1) == "e") {
			resizeEast = true;
		} else if (dwt.WindowManager.resizeDirection.charAt(0) == "w"
				|| dwt.WindowManager.resizeDirection.charAt(1) == "w") {
			resizeWest = true;
		}
		
		// Get the change in cursor position
		var deltaX;
		var deltaY;
		if (window.event) {
			deltaX = window.event.x - dwt.WindowManager.resizeXPosition;
			deltaY = window.event.y - dwt.WindowManager.resizeYPosition;
			dwt.WindowManager.resizeXPosition = window.event.x;
			dwt.WindowManager.resizeYPosition = window.event.y;
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		} else if (event) {
			deltaX = event.pageX - dwt.WindowManager.resizeXPosition;
			deltaY = event.pageY - dwt.WindowManager.resizeYPosition;
			dwt.WindowManager.resizeXPosition = event.pageX;
			dwt.WindowManager.resizeYPosition = event.pageY;
			event.preventBubble();
			event.preventDefault();
		}
		
		// Invert appropriate delta if resizing north and/or west
		if (resizeNorth) {
			deltaY = -deltaY;
		}
		if (resizeWest) {
			deltaX = -deltaX;
		}
		
		// Get new size, check minimum size
		var width = dwt.WindowManager.resizeWidth  + deltaX;
		if (width < dwt.WindowManager.activeWindow.minimumWidth) {
			width = dwt.WindowManager.activeWindow.minimumWidth;
			deltaX = width - dwt.WindowManager.resizeWidth;
		}
		dwt.WindowManager.resizeWidth = width;
		
		// Distribute north-south delta across the resize targets
		var nsResizeTargets = dwt.WindowManager.nsResizeTargets;
		if (deltaY < 0) {
			nsResizeTargets = new Array();
			for (var i = 0; i < dwt.WindowManager.nsResizeTargets.length; i++) {
				if (parseInt(dwt.WindowManager.nsResizeTargets[i].style.height)
						> dwt.WindowManager.activeWindow.minimumHeight) {
					nsResizeTargets.push(dwt.WindowManager.nsResizeTargets[i]);
				}
			}
		}
		nsResizeTargets.sort(dwt.WindowManager.nsResizeTargetsOrdering);
		var height = new Array();
		var yByTargets 	= deltaY > 0
				? Math.floor(deltaY / nsResizeTargets.length)
				: Math.ceil(deltaY / nsResizeTargets.length);
		var yModTargets = Math.abs(deltaY % nsResizeTargets.length);
		topDeltaY = 0;
		for (var i = 0; i < nsResizeTargets.length; i++) {
			var deltaHeight = yByTargets;
			if (i < yModTargets) {
				deltaHeight += deltaY > 0 ? 1 : -1;
				nsResizeTargets[i].resized++;
			}
			var resizeHeight = nsResizeTargets[i].resizeHeight + deltaHeight;
			if (resizeHeight < dwt.WindowManager.activeWindow.minimumHeight) {
				resizeHeight = dwt.WindowManager.activeWindow.minimumHeight;
			}
			topDeltaY += resizeHeight - nsResizeTargets[i].resizeHeight;
			height.push(resizeHeight);
		}
	
		// Resize the window (and contents).
		if (resizeEast || resizeWest) {
			if (navigator.appVersion.match(/\bMSIE\b/)) {
				for (var i = 0;
						i < dwt.WindowManager.activeWindow.contents.length;
						i++) {
					dwt.WindowManager.activeWindow.contents[i].style.width =
							(width - dwt.WindowManager.activeWindow.contents[i].offsetFromFrame) + "px";
				}
				dwt.WindowManager.activeWindow.border.style.width =
						(width - dwt.WindowManager.activeWindow.border.offsetFromFrame) + "px";
			}
			dwt.WindowManager.activeWindow.frame.style.width = width + "px";
		}
		if (resizeNorth || resizeSouth) {
			for (var i = 0; i < nsResizeTargets.length; i++) {
				if (height[i] != nsResizeTargets[i].resizeHeight) {
					nsResizeTargets[i].style.height = height[i] + "px";
					nsResizeTargets[i].resizeHeight = height[i];
				}
			}
		}
		// Clip the title bar text if necessary
		if (resizeEast || resizeWest) {
			if (width < dwt.WindowManager.activeWindow.clipTextMinimumWidth) {
				dwt.WindowManager.activeWindow.titleBarText.style.width =
						(dwt.WindowManager.titleBarTextMinimizedWidth + width
						- dwt.WindowManager.activeWindow.minimumWidth) + "px";
			} else {
				dwt.WindowManager.activeWindow.titleBarText.style.width = "";
			}
		}
		
		// Move the window if resizing north and/or west
		if (resizeNorth) {
			dwt.WindowManager.activeWindow.frame.style.top  =
					(dwt.WindowManager.resizeTop - topDeltaY) + "px";
			dwt.WindowManager.resizeTop -= topDeltaY;
		}
		if (resizeWest) {
			dwt.WindowManager.activeWindow.frame.style.left =
					(dwt.WindowManager.resizeLeft - deltaX) + "px";
			dwt.WindowManager.resizeLeft -= deltaX;
		}
	},
	
	/**
	 * Responds to document mouseup events by stopping the resize drag.
	 *
	 * @param	event	The user interface event.
	 */
	resizeDocumentMouseup: function (event) {
		
		Event.stopObserving(document, "mousemove",
				dwt.Window.prototype.resizeDocumentMousemove, true);
		Event.stopObserving(document, "mouseup",
				dwt.Window.prototype.resizeDocumentMouseup, true);
		
		dwt.WindowManager.isResizing = false;
	},
	
	/**
	 * Responds to title bar mousedown events by starting a move drag.
	 *
	 * @param	event	The user interface event.
	 */
	titleBarMousedown: function (event) {
		
		var target = null;
		if (window.event) {
			target = window.event.srcElement;
		} else if (event) {
			target = event.target;
		}
		// Ignore controls
		if (!target
				|| target.getAttribute("controlType")
				|| target.controlType) {
			return;
		}
		
		var dwtWindow = target.dwtWindow || target.parentNode.dwtWindow;
		if (dwtWindow) {
			dwtWindow.focus();
		}
		
		// Get the cursor position
		var x;
		var y;
		if (window.event) {
			x = window.event.x;
			y = window.event.y;
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		} else if (event) {
			x = event.pageX;
			y = event.pageY;
			event.preventBubble();
			event.preventDefault();
		}
		
		// Start capturing mousemove and mouseup events
		Event.observe(document, "mousemove",
				dwt.Window.prototype.moveDocumentMousemove, false);
		Event.observe(document, "mouseup",
				dwt.Window.prototype.moveDocumentMouseup, false);
		
		// Set cursor offset and moving flag
		dwt.WindowManager.moveXOffset =
				dwt.WindowManager.activeWindow.frame.offsetLeft - x;
		dwt.WindowManager.moveYOffset =
				dwt.WindowManager.activeWindow.frame.offsetTop  - y;
		
		dwt.WindowManager.isMoving = true;
	},
	
	/**
	 * Responds to document mousemove events by performing a move drag.
	 *
	 * @param	event	The user interface event.
	 */
	moveDocumentMousemove: function(event) {
		
		if (!dwt.WindowManager.isMoving) {
			return;
		}
		
		// Get the cursor position
		var x;
		var y;
		if (window.event) {
			x = window.event.x;
			y = window.event.y;
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		} else if (event) {
			x = event.pageX;
			y = event.pageY;
			event.preventBubble();
			event.preventDefault();
		}
		
		// Move the window frame based on the cursor offset
		dwt.WindowManager.activeWindow.frame.style.left =
				(x + dwt.WindowManager.moveXOffset) + "px";
		dwt.WindowManager.activeWindow.frame.style.top  =
				(y + dwt.WindowManager.moveYOffset) + "px";
	},
	
	/**
	 * Responds to document mouseup events by stopping the move drag.
	 *
	 * @param	event	The user interface event.
	 */
	moveDocumentMouseup: function(event) {
		
		Event.stopObserving(document, "mousemove",
				dwt.Window.prototype.moveDocumentMousemove, true);
		Event.stopObserving(document, "mouseup",
				dwt.Window.prototype.moveDocumentMouseup, true);
		
		dwt.WindowManager.isMoving = false;
	},
	
	/**
	 * Responds to control mouseover events by updating the control image.
	 *
	 * @param	event	The user interface event.
	 */
	controlMouseover: function (event) {
		
		var control = null;
		if (window.event) {
			control = window.event.srcElement;
		} else if (event) {
			control = event.target;
		}
		
		if (control) {
			var controlType = control.getAttribute("controlType")
					|| control.controlType;
			if (controlType
					&& controlType.toLowerCase() == "minimize"
					&& control.dwtWindow
					&& control.dwtWindow.isMinimized) {
				control.src = control.restoreMouseoverSrc;
			} else {
				control.src = control.mouseoverSrc;
			}
		}
	},
	
	/**
	 * Responds to control mouseout events by updating the control image.
	 *
	 * @param	event	The user interface event.
	 */
	controlMouseout: function (event) {
		
		var control = null;
		if (window.event) {
			control = window.event.srcElement;
		} else if (event) {
			control = event.target;
		}
		
		if (control) {
			var controlType = control.getAttribute("controlType")
					|| control.controlType;
			if (controlType
					&& controlType.toLowerCase() == "minimize"
					&& control.dwtWindow
					&& control.dwtWindow.isMinimized) {
				control.src = control.restoreSrc;
			} else {
				control.src = control.mouseoutSrc;
			}
		}
	},
	
	/**
	 * Responds to control click events by performing the appropriate action.
	 *
	 * @param	event	The user interface event.
	 */
	controlClick: function (event) {
		
		var control = null;
		if (window.event) {
			control = window.event.srcElement;
		} else if (event) {
			control = event.target;
		}
		
		if (control) {
			if (control.dwtWindow) {
				var controlType = control.getAttribute("controlType")
						|| control.controlType;
				var effect = control.getAttribute("effect")
						|| control.effect;
				if (controlType
						&& controlType.toLowerCase() == "minimize") {
					control.dwtWindow.focus();
					if (control.dwtWindow.isMinimized) {
						var restoreEffect =
								control.getAttribute("restoreEffect")
								|| control.restoreEffect;
						control.dwtWindow.restore(restoreEffect);
					} else {
						control.dwtWindow.minimize(effect);
					}
				} else if (controlType
						&& controlType.toLowerCase() == "close") {
					control.dwtWindow.close(effect);
				}
			}
		}
	},
	
	/**
	 * Responds to contents click events by giving focus to the window.
	 *
	 * @param	event	The user interface event.
	 */	
	contentsClick: function (event) {
		
		var target = null;
		if (window.event) {
			target = window.event.srcElement;
		} else if (event) {
			target = event.target;
		}
		
		var dwtWindow = null;
		while (target.parentNode != document.body) {
			if (target.dwtWindow) {
				dwtWindow = target.dwtWindow;
				break;
			}
			target = target.parentNode;
		}
		
		if (dwtWindow) {
			dwtWindow.focus();
		}
	}
	
};

Object.extend(Element, {
	
	/**
	 * Returns an array of children of the element with
	 * the specified tag name and class name values.
	 *
	 * @param	element		The parent element.
	 * @param	tagName		The tag name.
	 * @param	className	The class name.
	 *
	 * @return	An array of children of the element with
	 *        	the specified tag name and class name values.
	 */
	getElementsByTagAndClassName: function (element, tagName, className) {
		
		var elements = new Array();
		if (!element || !tagName || !className) {
			return elements;
		}
		
		var elementsByTagName = element.getElementsByTagName(tagName);
		for (var i = 0; i < elementsByTagName.length; i++) {
			var classNames = elementsByTagName[i].className.split(' ');
			for (var j = 0; j < classNames.length; j++) {
				if (classNames[j] == className) {
					elements.push(elementsByTagName[i]);
					break;
				}
			}
		}
		
		return elements;
	},
	
	/**
	 * Returns the first child of the element with
	 * the specified tag name and class name values.
	 *
	 * @param	element		The parent element.
	 * @param	tagName		The tag name.
	 * @param	className	The class name.
	 *
	 * @return	The first child of the element with
	 *        	the specified tag name and class name values.
	 */
	getFirstChildByTagAndClassName: function (element, tagName, className) {
		
		var elements = Element.getElementsByTagAndClassName(
				element, tagName, className);
		
		if (!elements || elements.length == 0) {
			return null;
		}
		
		return elements[0];
	}
	
});


//-----------------------------------------------------------------
// customize part start 
// wallace lau 
//-----------------------------------------------------------------

function createChatWindow(name) {
	
	// Frame
	var frame = document.createElement(dwt.WindowManager.FRAME.tagName);
	frame.setAttribute("id", name);
	frame.className = dwt.WindowManager.FRAME.activeClassName;
	frame.style.left = "250px";
	frame.style.top = "150px";
	frame.style.width = "350px";
	frame.setAttribute("effect", "Grow");
	
	// Title bar
	var titleBar = document.createElement(dwt.WindowManager.TITLE_BAR.tagName);
	titleBar.className = dwt.WindowManager.TITLE_BAR.activeClassName;
	titleBar.setAttribute("minimizedClass", "dwtMinimizedWindowTitleBar");
	titleBar.setAttribute("inactiveMinimizedClass", "dwtInactiveMinimizedWindowTitleBar");
	var table = document.createElement("table");
	var tbody = document.createElement("tbody");

	// Left chrome
	var tr = document.createElement("tr");
	var td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CHROME_LEFT.activeClassName;
	var img = document.createElement("img");
	img.className = "dwtWindowTitleBarChrome";
	img.src = "images/dwt/blank.gif";
	td.appendChild(img);
	tr.appendChild(td);
	
	// Title bar icon
	td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CELL.activeClassName;
	img = document.createElement("img");
	img.className = "dwtWindowTitleBarIcon";
	img.src = "images/dwt/blank.gif";
	td.appendChild(img);
	tr.appendChild(td);
	
	// Title bar text
	td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CELL.activeClassName;
	td.setAttribute("valign", "center");
	var titleBarText = document.createElement(dwt.WindowManager.TITLE_BAR_TEXT.tagName);
	titleBarText.className = dwt.WindowManager.TITLE_BAR_TEXT.activeClassName;
	titleBarText.appendChild(document.createTextNode(name));
	td.appendChild(titleBarText);
	tr.appendChild(td);
	td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CELL.activeClassName;
	img = document.createElement("img");
	img.className = "dwtWindowTitleBarWhitespace";
	img.src = "images/dwt/blank.gif";
	td.appendChild(img);
	tr.appendChild(td);
	
	// Controls (minimize, close)
	td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CELL.activeClassName
	img = document.createElement("img");
	img.className = dwt.WindowManager.TITLE_BAR_CONTROL.activeClassName;
	img.src = "images/dwt/minimize.gif";
	img.setAttribute("mouseoverSrc", "images/dwt/minimize.mouseover.gif");
	img.setAttribute("restoreSrc", "images/dwt/restore.gif");
	img.setAttribute("restoreMouseoverSrc", "images/dwt/restore.mouseover.gif");
	img.setAttribute("effect", "Fold");
	img.setAttribute("restoreEffect", "BlindDown");
	img.setAttribute("controlType", "minimize");
	td.appendChild(img);
	tr.appendChild(td);
	td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CELL.activeClassName;
	img = document.createElement("img");
	img.className = "dwtWindowTitleBarControl";
	img.src = "images/dwt/close.gif";
	img.setAttribute("mouseoverSrc", "images/dwt/close.mouseover.gif");
	img.setAttribute("effect", "SwitchOff");
	img.setAttribute("controlType", "close");
	td.appendChild(img);
	tr.appendChild(td);
	
	// Right chrome
	td = document.createElement("td");
	td.className = dwt.WindowManager.TITLE_BAR_CHROME_RIGHT.activeClassName;
	img = document.createElement("img");
	img.className = "dwtWindowTitleBarChrome";
	img.src = "images/dwt/blank.gif";
	td.appendChild(img);
	tr.appendChild(td);
	
	tbody.appendChild(tr);
	table.appendChild(tbody);
	titleBar.appendChild(table);
	frame.appendChild(titleBar);
	
	// Border, contents
	border = document.createElement(dwt.WindowManager.BORDER.tagName);
	border.className = dwt.WindowManager.BORDER.activeClassName;
	contents = document.createElement(dwt.WindowManager.CONTENTS.tagName);
	contents.className = dwt.WindowManager.CONTENTS.activeClassName;
	contents.style.height = "150px";
	border.appendChild(contents);
	
	// Message form (status bar)
	messageForm = document.createElement(dwt.WindowManager.STATUS_BAR.tagName);
	messageForm.className = dwt.WindowManager.STATUS_BAR.activeClassName;
	messageForm.style.borderTopWidth = "2px";
	messageForm.style.textAlign = "right";
	var div = document.createElement("div");
	div.className = "messageFormBodyBorder";
	var messageFormBody = document.createElement("textarea");
	messageFormBody.className = "messageFormBody";
	messageFormBody.setAttribute("rows", "2");
	div.appendChild(messageFormBody);
	messageForm.appendChild(div);
	div = document.createElement("div");
	div.style.paddingTop = "5px";
	div.style.paddingBottom = "3px";
	var submit = document.createElement("span");
	submit.className = "submit";
	submit.appendChild(document.createTextNode("Send"));
	div.appendChild(submit);
	messageForm.appendChild(div);
	border.appendChild(messageForm);
	
	frame.appendChild(border);
	document.body.appendChild(frame);
	
	var chatWindow = new dwt.Window(frame);
	
	// Update the zIndex of the text area's containers.
	// This is an attempt to work around Mozilla Bug 167801,
	// but it doesn't seem to have any effect :(
	chatWindow.setZIndexOnFocus.push(messageForm.parentNode);
	chatWindow.setZIndexOnFocus.push(messageForm);
	chatWindow.setZIndexOnFocus.push(messageFormBody.parentNode);
	chatWindow.setZIndexOnFocus.push(messageFormBody);
	
	dwt.WindowManager.windows[frame.id] = chatWindow;
	
	// Create an open button for this window
	var openButton = document.createElement("span");
	openButton.className = "openButton";
	openButton.dwtWindow = chatWindow;
	openButton.appendChild(document.createTextNode("Open " + chatWindow.id));
	document.body.appendChild(openButton);
	Event.observe(openButton, "click", window.openClick, false);
	
	return chatWindow;
}

function openClick(event) {
	
	var dwtWindow = null;
	if (window.event) {
		dwtWindow = window.event.srcElement.dwtWindow;
	} else if (event) {
		dwtWindow = event.target.dwtWindow;
	}
	
	if (dwtWindow) {
		dwtWindow.open(dwtWindow.effect);
	}
}

function onLoadBlock(type) {
	
	// Allows creation of chat windows with arbitrary titles
	//var inputTitle = document.createElement("input");
	//inputTitle.setAttribute("id", "input.title");
	//inputTitle.setAttribute("type", "text");
	//inputTitle.className = "title";
	//document.body.appendChild(inputTitle);
	//var buttonCreate = document.createElement("span");
	//buttonCreate.className = "openButton";
	//buttonCreate.style.backgroundColor = "#ebebe4";
	//buttonCreate.appendChild(document.createTextNode("Create: "));
	//document.body.appendChild(buttonCreate);
	/* Event.observe(buttonCreate, "click",
			function () {
				var inputText = document.getElementById("input.title");
				if (inputText && inputText.value && inputText.value != "") {
					var chatWindow = window.createChatWindow(inputText.value);
					chatWindow.open(chatWindow.effect);
					inputText.value = "";
				}
			},
			false);
	*/
	// Create pager window

	var _pager = document.getElementById(type+ ".pager.window");

	var pager = new dwt.Window(_pager);
	//var inputs = _pager.getElementsByTagName("input");
	//for (var i = 0; i < inputs.length; i++) {
	//	pager.setZIndexOnFocus.push(inputs[i]);
	//}
 	pager.open(pager.effect);
 	
 	// Create open button for pager window
	//var openButton = document.createElement("span");
	//openButton.className = "openButton";
	//openButton.appendChild(document.createTextNode("Open A Really Long Window Title..."));
	//openButton.dwtWindow = pager;
	//document.body.appendChild(openButton);
	//Event.observe(openButton, "click", window.openClick, false);
	
 	// Create a chat window
 	//chatWindow = createChatWindow("randomtaskdotorg");
 	//chatWindow.open(chatWindow.effect);
 	//var span = document.createElement("span");
 	//span.appendChild(document.createTextNode("Welcome to the DHTML Windowing Toolkit demo.  These windows can be opened, closed, minimized, restored, moved, and resized; with optional script.aculo.us effects.  Use the buttons above to open a window after you've closed it, or to dynamically create new windows."));
 	//chatWindow.contents[0].appendChild(span);
}


//-----------------------------------------------------------------
// customize part end
// wallace lau 
//-----------------------------------------------------------------
