/**
*	@desc: constructor, creates single window under dhtmlxWindows system
*	@pseudonym: win
*	@type: public
*/
function dhtmlXWindowsSngl(){
	
}
/**
*	@desc: constructor, creates button for window under dhtmlxWindows system
*	@pseudonym: btn
*	@type: public
*/
function dhtmlXWindowsBtn(){
	
}

/**
*   @desc: constructor, creates a new dhtmlxWindows object
*   @type: public
*/
function dhtmlXWindows() {
	
	var that = this;
	// image manipulation
	this.imagePath = "codebase/imgs/";
	/**
	*   @desc: sets path to the directory where used images are located
	*   @param: path - url to where images are located
	*   @type: public
	*/
	this.setImagePath = function(path) {
		this.imagePath = path;
	}
	
	// skins
	this.skin = "standard";
	this.skinParams = { // standard
			    "standard": { "header_height": 32, "border_left_width": 6, "border_right_width": 7, "border_bottom_height": 6 },
			    // web
			    "web": { "header_height": 21, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
			    // modern
			    "modern_black": { "header_height": 39, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
			    "modern_blue": { "header_height": 39, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
			    "modern_red": { "header_height": 39, "border_left_width": 2, "border_right_width": 2, "border_bottom_height": 2 },
			    // clear
			    "clear_blue": { "header_height": 32, "border_left_width": 6, "border_right_width": 6, "border_bottom_height": 6 },
			    "clear_green": { "header_height": 32, "border_left_width": 6, "border_right_width": 6, "border_bottom_height": 6 },
			    "clear_silver": { "header_height": 32, "border_left_width": 6, "border_right_width": 6, "border_bottom_height": 6 },
			    // aqua
			    "aqua_dark": { "header_height": 31, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 },
			    "aqua_orange": { "header_height": 31, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 },
			    "aqua_sky": { "header_height": 31, "border_left_width": 3, "border_right_width": 3, "border_bottom_height": 3 }
	};
	/**
	*   @desc: changes window skin
	*   @param: skin - skin name
	*   @type: public
	*/
	this.setSkin = function(skin) {
		this.skin = skin;
		this._redrawSkin();
	}
	this._redrawSkin = function() {
		
		for (var a in this.wins) {
			var win = this.wins[a];
			var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
			//
			win.childNodes[0].className = "dhtmlx_wins_"+this.skin;
			// icon
			win.childNodes[1].className = "dhtmlx_wins_icon_"+this.skin;
			this._restoreWindowIcons(win);
			// title
			win.childNodes[2].className = "dhtmlx_wins_title_"+this.skin;
			// butons
			win.childNodes[3].className = "dhtmlx_wins_buttons_"+this.skin;
			this._redrawWindow(win);
		}
		// this._restoreWindowIcons(this.getTopmostWindow());
	}
	
	// return true if window with specified id is exists
	/**
	*   @desc: returns true if window with specified id exists
	*   @param: id
	*   @type: public
	*/
	this.isWindow = function(id) {
		var t = (this.wins[id] != null);
		return t;
	}
//#wind_uber:09062008{}
	// return array of handlers finded by text
	/**
	*   @desc: returns array of window handlers found by header text
	*   @param: id
	*   @type: public
	*/
	this.findByText = function(text) {
		var wins = new Array();
		for (var a in this.wins) {
			if (this.wins[a].getText().search(text, "gi") >= 0) {
				wins[wins.lentgh] = this.wins[a];
			}
		}
		return wins;
	}
//#}	
	// return handler by id
	/**
	*   @desc: returns window handler (dhtmlXWindowSngl object) found by id
	*   @param: id
	*   @type: public
	*/
	this.window = function(id) {
		var win = null;
		if (this.wins[id] != null) { win = this.wins[id]; }
		return win;
	}
//#wind_uber:09062008{
	// iterator
	/**
	*   @desc: iterator - goes through all windows and calls user handler
	*   @param: hander (user function)
	*   @type: public
	*/
	this.forEachWindow = function(handler) {
		for (var a in this.wins) {
			handler(this.wins[a]);
		}
	}
	
	// return bottommost focused window handler
	/**
	*   @desc: returns bottommost window
	*   @type: public
	*/
	this.getBottommostWindow = function() {
		var bottommost = this.getTopmostWindow();
		for (var a in this.wins) {
			if (this.wins[a].zi < bottommost.zi) {
				bottommost = this.wins[a];
			}
		}
		return (bottommost.zi != 0 ? bottommost : null);
	}
//#}	

	// return topmost focused window handler
	/**
	*   @desc: returns topmost window
	*   @type: public
	*/
	this.getTopmostWindow = function(visibleOnly) {
		var topmost = {"zi": 0};
		for (var a in this.wins) {
			
			if (this.wins[a].zi > topmost.zi) {
				if (visibleOnly == true && !this._isWindowHidden(this.wins[a])) {
					topmost = this.wins[a];
				}
				if (visibleOnly != true) {
					topmost = this.wins[a];
				}
			}
		}
		return (topmost.zi != 0 ? topmost : null);
	}
	
	// windows storage
	this.wins = {};
	
	// viewport
	this.autoViewport = true;
	this._createViewport = function() {
		this.vp = document.body;
		//
		this.modalCoverI = document.createElement("IFRAME");
		this.modalCoverI.frameBorder = "0";
		this.modalCoverI.className = "dhx_modal_cover_ifr";
		this.modalCoverI.style.display = "none";
		this.modalCoverI.style.zIndex = 0;
		this.vp.appendChild(this.modalCoverI);
		this.modalCoverD = document.createElement("DIV");
		this.modalCoverD.className = "dhx_modal_cover_dv";
		this.modalCoverD.style.display = "none";
		this.modalCoverD.style.zIndex = 0;
		this.vp.appendChild(this.modalCoverD);
	}
	this._autoResizeViewport = function() {
		for (var a in this.wins) {
			if (this.wins[a]._isFullScreened) {
				this.wins[a]._content.style.width = document.body.offsetWidth+"px";
				this.wins[a]._content.style.height = document.body.offsetHeight+"px";
				if (this.wins[a].layout != null) {
					this.wins[a].layout.setSizes(this.wins[a]);
				}
			}
			if (this.wins[a]._isMaximized && this.wins[a].style.display != "none") {
				this._restoreWindow(this.wins[a]);
				this._maximizeWindow(this.wins[a]);
			}
		}
		
		if (this.vp == document.body) { return; }
		if (this.autoViewport == false) { return; }
		this.vp.style.width = (_isIE ? document.body.offsetWidth - 4 : window.innerWidth) + "px";
		this.vp.style.height = (_isIE ? document.body.offsetHeight - 4 : window.innerHeight) + "px";
		//
		// check windows out of viewports edge
		for (var a in this.wins) {
			var win = this.wins[a];
			var overX = false;
			var overY = false;
			if (win.x > this.vp.offsetWidth - 10) {
				win.x = this.vp.offsetWidth - 10;
				overX = true;
			}
			var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
			if (win.y + skinParams["header_height"] > this.vp.offsetHeight) {
				win.y = this.vp.offsetHeight - skinParams["header_height"];
				overY = true;
			}
			if (overX || overY) {
				this._redrawWindow(win);
			}
		}
	}
	/**
	*   @desc: if true - allows object to adjust viewport automatically to document.body
	*   @param: state - true|false
	*   @type: public
	*/
	this.enableAutoViewport = function(state) {
		
		if (this.vp != document.body) { return; }
		this.autoViewport = state;
		if (state == false) {
			this.vp = document.createElement("DIV");
			this.vp.className = "dhtmlx_winviewport";
			this.vp.style.left = "0px";
			this.vp.style.top = "0px";
			document.body.appendChild(this.vp);
			this.vp.ax = 0;
			this.vp.ay = 0;
			this._autoResizeViewport();
			this.vp.appendChild(this.modalCoverI);
			this.vp.appendChild(this.modalCoverD);
		}
	}
	/**
	*   @desc: attach a vp to an existing object on page (render an object as a viewport)
	*   @param: objId - object id
	*   @type: public
	*/
	this.attachViewportTo = function(objId) {
		if (this.autoViewport == false) {
			if (this.vp != document.body) { this.vp.parentNode.removeChild(this.vp); }
			this.vp = document.getElementById(objId);
			if (this.vp.style.position == null) {
				//this.vp.style.position = "relative";
			}
			this.vp.style.overflow = "hidden";
			this.vp.ax = 0;
			this.vp.ay = 0;
			this.vp.appendChild(this.modalCoverI);
			this.vp.appendChild(this.modalCoverD);
		}
	}
	/**
	*   @desc: sets user-defined viewport if enableAutoViewport(false)
	*   @param: x - top-left viewport corner's X-coordinate
	*   @param: y - top-left viewport corner's Y-coordinate
	*   @param: width - viewport's width
	*   @param: height - viewport's height
	*   @type: public
	*/
	this.setViewport = function(x, y, width, height, parentObj) {
		if (this.autoViewport == false) {
			this.vp.style.left = x + "px";
			this.vp.style.top = y + "px";
			this.vp.style.width = width + "px";
			this.vp.style.height = height + "px";
			// attach to parent
			if (parentObj != null) { parentObj.appendChild(this.vp); }
			this.vp.ax = getAbsoluteLeft(this.vp);
			this.vp.ay = getAbsoluteTop(this.vp);
		}
	}
	
	// windows
	/**
	*   @desc: creates new window and returns its handler
	*   @param: id - window id
	*   @param: x - top-left window corner's X-coordinate
	*   @param: y - top-left window corner's Y-coordinate
	*   @param: width - window's width
	*   @param: height - window's height
	*   @type: public
	*/
	this.createWindow = function(id, x, y, width, height) {
		var win = document.createElement("DIV");
		win.className = "dhtmlx_window_inactive";
		// move all available windows up
		for (var a in this.wins) {
			this.wins[a].zi += this.zIndexStep;
			this.wins[a].style.zIndex = this.wins[a].zi;
		}
		// bottom, bring on top will at the end of createWindow function
		win.zi = this.zIndexStep;// this._getTopZIndex(true) + this.zIndexStep;
		win.style.zIndex = win.zi;
		//
		win.active = false;
		//
		win._isWindow = true;
		//
		// win.that = this;
		//
		win.w = width;
		win.h = height;
		win.x = x;
		win.y = y;
		this._fixWindowPositionInViewport(win);
		//
		win.style.width = win.w + "px";
		win.style.height = win.h + "px";
		win.style.left = win.x + "px";
		win.style.top = win.y + "px";
		win._isModal = false;
		// resize params
		win._allowResize = true;
		win.maxW = "auto"; // occupy all viewport on click or 
		win.maxH = "auto";
		win.minW = 200;
		win.minH = 140;
		win.iconsPresent = true;
		win.icons = new Array(this.imagePath+this.skin+"/active/icon_normal.gif", this.imagePath+this.skin+"/inactive/icon_normal.gif");
		//
		win._allowMove = true;
		win._allowMoveGlobal = true;
		win._allowResizeGlobal = true;
		//
		win._keepInViewport = false;
		//
		var skin = this.skinParams[this.skin];
		win.idd = id;
		win._midd = "dhxWMNObj_"+this._genStr(12);
		win._tidd = "dhxWTBObj_"+this._genStr(12);
		win._sidd = "dhxSTBObj_"+this._genStr(12);
		//
		win.innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='"+win.h+"' class='dhtmlx_wins_"+this.skin+"'>"+
					// head
					"<tr><td class='dhtmlx_wins_td_header_full' clearonselect='yes'>"+
						"<table border='0' cellspacing='0' cellpadding='0' width='100%' class='dhtmlx_wins_header' clearonselect='yes'>"+
							"<tr>"+
								"<td class='dhtmlx_wins_td_header_left' clearonselect='yes'>&nbsp;</td>"+
								"<td class='dhtmlx_wins_td_header_middle' clearonselect='yes'>&nbsp;</td>"+
								"<td class='dhtmlx_wins_td_header_right' clearonselect='yes'>&nbsp;</td>"+
							"</tr>"+
						"</table>"+
					"</td></tr>"+
					// body
					"<tr><td class='dhtmlx_wins_td_body_full' height='"+(win.h-skin["header_height"])+"'>"+
						"<table border='0' cellspacing='0' cellpadding='0' width='100%' height='"+(win.h-skin["header_height"])+"' class='dhtmlx_wins_body'>"+
							// window middle row
							"<tr>"+
								"<td class='dhtmlx_wins_body_border_middle_left' clearonselect='yes'>&nbsp;</td>"+
								"<td class='dhtmlx_wins_body_content' align='left' valign='top'>"+
									"<div class='dhtmlx_wins_body_content' style='width: "+(win.w-skin["border_left_width"]-skin["border_right_width"])+"px; height:"+(win.h-skin["header_height"]-skin["border_bottom_height"])+"px;'>"+
										"<div id='"+win._midd+"' class='dhtmlxWebMenuInWin' style='height: 0px; display: none;'></div>"+
										"<div id='"+win._tidd+"' class='dhtmlxWebToolbarInWin' style='height: 0px; display: none;'></div>"+
										"<div class='dhtmlxWindowMainContent' style='position: absolute; overflow: hidden; top: 0px; bottom: 0px; height:100%; left: 0px; right: 0px;'></div>"+
										"<div id='"+win._sidd+"' class='dhtmlxWebStatusBarInWin' style='height: 0px; display: none;'></div>"+
									"</div>"+
								"</td>"+
								"<td class='dhtmlx_wins_body_border_middle_right' clearonselect='yes'>&nbsp;</td>"+
							"</tr>"+
							// window bottom row
							"<tr clearonselect='yes'>"+
								"<td class='dhtmlx_wins_body_border_bottom_left' clearonselect='yes'>&nbsp;</td>"+
								"<td class='dhtmlx_wins_body_border_bottom_middle' clearonselect='yes'>&nbsp;</td>"+
								"<td class='dhtmlx_wins_body_border_bottom_right' clearonselect='yes'>&nbsp;</td>"+
							"</tr>"+
						"</table>"+
					"</td></tr>"+
				"</table>"+
				// window icon
				"<img clearonselect='yes' class='dhtmlx_wins_icon_"+this.skin+"' src='"+win.icons[0]+"'>"+
				// window title
				"<div clearonselect='yes' class='dhtmlx_wins_title_"+this.skin+"'>Untitled dhtmlxWindow</div>"+
				// buttons
				"<div class='dhtmlx_wins_buttons_"+this.skin+"'>"+
					"<table border='0' cellspacing='0' cellpadding='0'><tr></tr></table>"+
				"</div>"+
				// progress
				"<div clearonselect='yes' class='dhtmlx_wins_progress_"+this.skin+"'></div>"+
				"";
		this.vp.appendChild(win);
		win._content = win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
		this._diableOnSelectInWin(win, true);
		//
		this.wins[id] = win;
		//
		win.dhx_Event = this.dhx_Event;
		win.dhx_Event();
		//
		this._makeActive(win);
		// moving
		var hdr = win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0]; // table class='header'
		// hdr.that = this;
		// hdr.win = win;
		hdr.onmousedown = function(e) {
			if (!win._allowMove || !win._allowMoveGlobal) { return; }
			e = e || event;
			// save last coords to determine moveFinish event
			win.oldMoveX = win.x;
			win.oldMoveY = win.y;
			//
			win.moveOffsetX = win.x - e.clientX;
			win.moveOffsetY = win.y - e.clientY;
			that.movingWin = win;
			that._blockSwitcher("none");
			// cursor
			that.movingWin.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].style.cursor = "move";
			that.movingWin.childNodes[2].style.cursor = "move";
		}
		
		hdr.ondblclick = function() {
			// maximize/minimize
			if (win._allowResizeGlobal && !win._isParked) {
				if (win._isMaximized == true) {
					that._restoreWindow(win);
				} else {
					that._maximizeWindow(win);
				}
			}
			// parkup/parkup
			/*
			if (win._isParkedAllowed && win.button("park").isEnabled()) {
				that._parkWindow(win);
			}
			*/
		}
		
		var h_title = win.childNodes[2];
		h_title.onmousedown = hdr.onmousedown;
		h_title.ondblclick = hdr.ondblclick;
		
		win.isWindow = true;
		
		// set text
		/**
		*   @desc: sets window's header text
		*   @param: text
		*   @type: public
		*/
		win.setText = function(text) {
			this.childNodes[2].innerHTML = text;
			that.callEvent("onTextChange", [this._dockCell, text]);
		}
		// get text
		/**
		*   @desc: returns window's header text
		*   @type: public
		*/
		win.getText = function() {
			return this.childNodes[2].innerHTML;
		}
		// het id by handler
		/**
		*   @desc: returns window id
		*   @type: public
		*/
		win.getId = function() {
			return this.idd;
		}
		// show
		/**
		*   @desc: shows window
		*   @type: public
		*/
		win.show = function() {
			that._showWindow(this);
		}
		// hide
		/**
		*   @desc: hides window
		*   @type: public
		*/
		win.hide = function() {
			that._hideWindow(this);
		}
		// minimize
		/**
		*   @desc: minimizes window
		*   @type: public
		*/
		win.minimize = function() {
			that._restoreWindow(this);
		}
		// maximize
		/**
		*   @desc: maximizes window
		*   @type: public
		*/
		win.maximize = function() {
			that._maximizeWindow(this);
		}
		// close
		/**
		*   @desc: closes window
		*   @type: public
		*/
		win.close = function() {
			that._closeWindow(this);
		}
		// park
		/**
		*   @desc: parks window (next action is based on window's current state)
		*   @type: public
		*/
		win.park = function() {
			if (this._isParkedAllowed) {
				that._parkWindow(this);
			}
		}
		// stick/unstick
		/**
		*   @desc: sticks window
		*   @type: public
		*/
		win.stick = function() {
			that._stickWindow(this);
		}
		/**
		*   @desc: unsticks window
		*   @type: public
		*/
		win.unstick = function() {
			that._unstickWindow(this);
		}
		/**
		*   @desc: returns true if window is sticked
		*   @type: public
		*/
		win.isSticked = function() {
			return this._isSticked;
		}
		// set icon
		/**
		*   @desc: sets window's header icon
		*   @param: iconEnabled - url to enabled icon
		*   @param: iconDisabled - url to disabled icon
		*   @type: public
		*/
		win.setIcon = function(iconEnabled, iconDisabled) {
			that._setWindowIcon(win, iconEnabled, iconDisabled);
		}
		// return array(iconEnabled, iconDisabled) icons for window
		/**
		*   @desc: returns current window's header icon
		*   @param: text
		*   @type: public
		*/
		win.getIcon = function() {
			return that._getWindowIcon(this);
		}
		// clear icon
		/**
		*   @desc: clears window's header icon
		*   @type: public
		*/
		win.clearIcon = function() {
			that._clearWindowIcons(this);
		}
		// restore default window icon according the loaded skin
		/**
		*   @desc: restores default window's header icon (based on skin)
		*   @type: public
		*/
		win.restoreIcon = function() {
			that._restoreWindowIcons(this);
		}
		//
		/**
		*   @desc: keeps window within viewport
		*   @param: state - if true - window is not allowed to be placed outside viewport, 
				    if false - window is not allowed to be placed outside viewport leaving only a small part of its header within viewport
		*   @type: public
		*/
		win.keepInViewport = function(state) {
			this._keepInViewport = state;
		}
		// ask window be/not be modal
		/**
		*   @desc: makes window modal/modeless
		*   @param: state - true|false
		*   @type: public
		*/
		win.setModal = function(state) {
			if (state == true) {
				if (that.modalWin != null || that.modalWin == this) { return; }
				that._setWindowModal(this, true);
			} else {
				if (that.modalWin != this) { return; }
				that._setWindowModal(this, false);
			}
		}
		// return true if window is modal
		/**
		*   @desc: returns true if window is modal
		*   @type: public
		*/
		win.isModal = function() {
			return this._isModal;
		}
		// return true if window is hidden
		/**
		*   @desc: returns true if window is hidden
		*   @type: public
		*/
		win.isHidden = function() {
			return that._isWindowHidden(this);
		}
		// return true if window is maximized
		/**
		*   @desc: returns true if window is maximized
		*   @type: public
		*/
		win.isMaximized = function() {
			return this._isMaximized;
		}
		// return true if window is parkded
		/**
		*   @desc: returns true if window is parked
		*   @type: public
		*/
		win.isParked = function() {
			return this._isParked;
		}
		// allow/deny park
		/**
		*   @desc: allows window to be parked
		*   @type: public
		*/
		win.allowPark = function() {
			that._allowParking(this);
		}
		/**
		*   @desc: denies window from parking
		*   @type: public
		*/
		win.denyPark = function() {
			that._denyParking(this);
		}
		/**
		*   @desc: returns true if window is parkable
		*   @type: public
		*/
		win.isParkable = function() {
			return this._isParkedAllowed;
		}
		// allow/deny for allow window to be resized
		/**
		*   @desc: allows window to be resized
		*   @type: public
		*/
		win.allowResize = function() {
			that._allowReszieGlob(this);
		}
		/**
		*   @desc: denies window from resizing
		*   @type: public
		*/
		win.denyResize = function() {
			that._denyResize(this);
		}
		// return true if window resizeable
		/**
		*   @desc: returns true if window is resizable
		*   @type: public
		*/
		win.isResizable = function() {
			return this._allowResizeGlobal;
		}
		// move
		/**
		*   @desc: allows window to be moved
		*   @type: public
		*/
		win.allowMove = function() {
			if (!this._isMaximized) { this._allowMove = true; }
			this._allowMoveGlobal = true;
		}
		/**
		*   @desc: denies window from moving
		*   @type: public
		*/
		win.denyMove = function() {
			this._allowMoveGlobal = false;
		}
		/**
		*   @desc: returns true if window is movable
		*   @type: public
		*/
		win.isMovable = function() {
			return this._allowMoveGlobal;
		}
		// bring window to top and set focus
		/**
		*   @desc: brings/sends window on top (z-positioning)
		*   @type: public
		*/
		win.bringToTop = function() {
			that._bringOnTop(this);
			that._makeActive(this);
		}
		// bring window to bottom and set focus
		/**
		*   @desc: brings/sends window to bottom (z-positioning)
		*   @type: public
		*/
		win.bringToBottom = function() {
			that._bringOnBottom(this);
		}
		// return true if window is on top
		/**
		*   @desc: returns true if window is on top
		*   @type: public
		*/
		win.isOnTop = function() {
			return that._isWindowOnTop(this);
		}
		// return true if window if on bottom
		/**
		*   @desc: returns true if window is on bottom
		*   @type: public
		*/
		win.isOnBottom = function() {
			return that._isWindowOnBottom(this);
		}
		// set new position for window, if it will outlay the viewport it was moved into it visible area
		/**
		*   @desc: sets window position (moves window to the point set by user)
		*   @param: x - x coordinate
		*   @param: y - y coordinate
		*   @type: public
		*/
		win.setPosition = function(x, y) {
			this.x = x;
			this.y = y;
			that._fixWindowPositionInViewport(this);
			// fixing mozilla artefakts
			if (_isFF) {
				this.h++;
				that._redrawWindow(this);
				this.h--;
			}
			that._redrawWindow(this);
		}
		// return array(x, y) with position of window
		/**
		*   @desc: returns current window position
		*   @type: public
		*/
		win.getPosition = function() {
			return new Array(this.x, this.y);
		}
		// set new dimension for window, if it will outlay the viewport it was moved into it visible area
		/**
		*   @desc: sets window dimension
		*   @param: width
		*   @param: height
		*   @type: public
		*/
		win.setDimension = function(width, height) {
			this.w = width;
			this.h = height;
			that._fixWindowDimensionInViewport(this);
			that._fixWindowPositionInViewport(this);
			that._redrawWindow(this);
		}
		// return array(width, height) with current dimension of window
		/**
		*   @desc: returns current window dimension
		*   @type: public
		*/
		win.getDimension = function() {
			return new Array(this.w, this.h);
		}
		// set max dimension for window
		/**
		*   @desc: sets max window dimension
		*   @param: maxWidth
		*   @param: maxHeight
		*   @type: public
		*/
		win.setMaxDimension = function(maxWidth, maxHeight) {
			this.minW = "auto"; // maxWidth;
			this.minH = "auto"; // maxHeight;
			that._redrawWindow(this);
		}
		// return array(maxWidth, maxheight) with max dimension for window
		/**
		*   @desc: returns current max window dimension
		*   @type: public
		*/
		win.getMaxDimension = function() {
			return new Array(this.maxW, this.maxH);
		}
		// set min dimensuion for window
		/**
		*   @desc: sets min window dimension
		*   @param: minWidth
		*   @param: minHeight
		*   @type: public
		*/
		win.setMinDimension = function(minWidth, minHeight) {
			this.minW = minWidth;
			this.minH = minHeight;
			that._fixWindowDimensionInViewport(this);
			that._redrawWindow(this);
		}
		// return array(minWidth, minHeight) with min dimension for window
		/**
		*   @desc: returns current min window dimension
		*   @type: public
		*/
		win.getMinDimension = function() {
			return new Array(this.minW, this.minH);
		}
//#wind_buttons:09062008{
		// add user button
		/**
		*   @desc: adds user button
		*   @param: id - button id
		*   @param: pos - button position
		*   @param: title - button tooltip
		*   @param: label - button name (according to css)
		*   @type: public
		*/
		win.addUserButton = function(id, pos, title, label) {
			var userBtn = that._addUserButton(this, id, pos, title, label);
			return userBtn;
		}
		// remove user button
		/**
		*   @desc: removes user button
		*   @param: id - button id
		*   @type: public
		*/
		win.removeUserButton = function(id) {
			if (!((id == "minmax1") || (id == "minmax2") || (id == "park") || (id == "close") || (id == "stick") || (id == "unstick") || (id == "help"))) {
				var btn = this.button(id);
				// if (btn != null) { that._removeUserButton(win, id, btn); }
				if (btn != null) { that._removeUserButton(this, id, btn); }
			}
		}
//#}				
		/**
		*   @desc: show progress indicator
		*   @type: public
		*/
		win.progressOn = function() {
			that._switchProgress(this, true);
		}
		/**
		*   @desc: hide progress indicator
		*   @type: public
		*/
		win.progressOff = function() {
			that._switchProgress(this, false);
		}
		/**
		*   @desc: attach status bar to a window
		*   @type: private
		*/
		win.attachStatusBar = function() {
			return that._attachStatusBar(this);
		}
		/**
		*   @desc: attach dhtmlxWebMenu to a window
		*   @type: private
		*/
		win.attachWebMenu = function() {
			return that._attachWebMenu(this);
		}
		/**
		*   @desc: attach dhtmlxWebToolbar to a window
		*   @type: private
		*/
		win.attachWebToolbar = function() {
			return that._attachWebToolbar(this);
		}
//#wind_comps:09062008{
		/**
		*   @desc: attach dhtmlxGrid to a window
		*   @type: public
		*/
		win.attachGrid = function() {
			var obj = document.createElement("DIV");
			obj.id = "dhxGridObj_"+that._genStr(12);
			obj.style.width = "100%";
			obj.style.height = "100%";
			document.body.appendChild(obj);
			this.attachObject(obj.id, true);
			this.grid = new dhtmlXGridObject(obj.id);
			return this.grid;
		}
		/**
		*   @desc: attach dhtmlxTree to a window
		*   @param: rootId - identifier of level parent to tree root level (superroot)
		*   @type: public
		*/
		win.attachTree = function(rootId) {
			var obj = document.createElement("DIV");
			obj.id = "dhxTreeObj_"+that._genStr(12);
			obj.style.width = "100%";
			obj.style.height = "100%";
			document.body.appendChild(obj);
			this.attachObject(obj.id, true);
			this.tree = new dhtmlXTreeObject(obj.id, "100%", "100%", rootId);
			// this.tree.allTree.style.paddingTop = "2px";
			this.tree.allTree.childNodes[0].style.marginTop = "2px";
			this.tree.allTree.childNodes[0].style.marginBottom = "2px";
			return this.tree;
		}
		/**
		*   @desc: attach dhtmlxTabbar to a window
		*   @type: public
		*/
		win.attachTabbar = function() {
			var obj = document.createElement("DIV");
			obj.id = "dhxFoldersObj_"+that._genStr(12);
			obj.style.width = "100%";
			obj.style.height = "100%";
			obj.style.overflow = "hidden";
			document.body.appendChild(obj);
			this.attachObject(obj.id, true);
			// manage dockcell if exists
			if (this._dockCell != null && that.dhxLayout != null) {
				var dockCell = that.dhxLayout.polyObj[this._dockCell];
				if (dockCell != null) {
					dockCell.childNodes[0]._tabbarMode = true;
					that.dhxLayout.hidePanel(this._dockCell);
					dockCell.className = "dhtmlxLayoutSinglePolyTabbar";
					// dockCell.childNodes[0]._h = -2;
					// dockCell.childNodes[1].style.height = parseInt(dockCell.childNodes[1].style.height) - dockCell.childNodes[0]._h + "px";
					// dockCell.className = "dhtmlxLayoutSinglePolyTabbar";
					// fix panel
					// that.dhxLayout._panelForTabs(this._dockCell);
				}
			}
			//
			this.tabbar = new dhtmlXTabBar(obj.id, "top");
			this.tabbar._EARS = true;
			this.tabbar.adjustOuterSize();
			return this.tabbar;
		}
		/**
		*   @desc: attach dhtmlxFolders to a window
		*   @type: public
		*/
		win.attachFolders = function() {
			var obj = document.createElement("DIV");
			obj.id = "dhxFoldersObj_"+that._genStr(12);
			obj.style.width = "100%";
			obj.style.height = "100%";
			obj.style.overflow = "hidden";
			document.body.appendChild(obj);
			this.attachObject(obj.id, true);
			this.folders = new dhtmlxFolders(obj.id);
			return this.folders;
		}
		/**
		*   @desc: attach dhtmlxAccordion to a window
		*   @type: public
		*/
		win.attachAccordion = function() {
			var obj = document.createElement("DIV");
			obj.id = "dhxAccordionObj_"+that._genStr(12);
			obj.style.width = "100%";
			obj.style.height = "100%";
			obj.style.position = "relative";
			document.body.appendChild(obj);
			this.attachObject(obj.id, true);
			this.accordion = new dhtmlXAccordion(obj.id);
			if (this._dockCell != null && that.dhxLayout != null) {
				var dockCell = that.dhxLayout.polyObj[this._dockCell];
				if (dockCell != null) { that.dhxLayout.hidePanel(this._dockCell); }
			}
			this.accordion.setSizes();
			return this.accordion;
		}
		/**
		*   @desc: attach dhtmlxLayout to a window
		*   @param: view - layout view
		*   @type: public
		*/
		win.attachLayout = function(view) {
			var obj = document.createElement("DIV");
			obj.id = "dhxLayoutObj_"+that._genStr(12);
			obj.style.position = "relative";
			document.body.appendChild(obj);
			//
			this.attachObject(obj.id, true);
			// this.layout = new dhtmlXLayoutObject(obj.id, this);
			// console.log(this._content.style.width, this._content.style.height)
			// var w = parseInt(this._content.style.width);
			// var h = parseInt(this._content.style.height);
			
			var w = this._content.childNodes[2].offsetWidth;
			var h = this._content.childNodes[2].offsetHeight;
			if (w == 0) { w = parseInt(this._content.style.width); }
			
			obj.style.width = w+"px";
			obj.style.height = h+"px";
			
			obj._skipChecksOnStartUp = true;
			
			this.layout = new dhtmlXLayoutObject(obj, view);
			this.layout._parentWindow = this;
			// alert(w+" "+h)
			// console.log(w,h)
			
			// this.layout._fixPositionInWin(w, h);
			this.attachEvent("_onBeforeTryResize", this.layout._defineWindowMinDimension);
			return this.layout;
		}
//#}
		win.attachEditor = function() {
			var obj = document.createElement("DIV");
			obj.id = "dhxEditorObj_"+that._genStr(12);
			obj.style.position = "relative";
			obj.style.display = "none";
			obj.style.width = "100%";
			obj.style.height = "100%";
			document.body.appendChild(obj);
			//
			this.attachObject(obj.id, true);
			//
			this.editor = new dhtmlXEditor(obj.id);
			return this.editor;
			
		}
		/**
		*   @desc: set window to fullscreen mode
		*   @param: state - true|false
		*   @type: public
		*/
		win.setToFullScreen = function(state) {
			that._setWindowToFullScreen(this, state);
		}
		/**
		*   @desc: show window header
		*   @type: public
		*/
		win.showHeader = function() {
			that._showWindowHeader(this);
		}
		/**
		*   @desc: hide window header
		*   @type: public
		*/
		win.hideHeader = function() {
			that._hideWindowHeader(this);
		}
		//
		win.progressOff();
		// resize cursor modifications and handlers
		win.canStartResize = false;
		win.onmousemove = function(e) {
			// resize not allowed
			if ((!this._allowResize) || (this._allowResizeGlobal == false)) {
				this.canStartResize = false;
				this.style.cursor = "";
				return;
			}
			
			if (that.resizingWin != null) { return; }
			if (this._isParked) { return; }
			//
			e = e || event;
			var targetObj = e.target || e.srcElement;
			//
			var useDefaultCursor = true;
			this.canStartResize = true;
			//
			var skin = (this._skinParams!=null?this._skinParams:that.skinParams[that.skin]);
			var hh = skin["header_height"];
			var bwl = skin["border_left_width"] + 2;
			var bwr = skin["border_right_width"] + 2;
			var bhb = skin["border_bottom_height"] + 2;
			// left border
			if (targetObj.className == "dhtmlx_wins_body_border_middle_left") {
				that.resizingDirs = "border_left";
				this.style.cursor = "w-resize";
				this.resizeOffsetX = this.x - e.clientX;
				useDefaultCursor = false;
			}
			// right border
			if (targetObj.className == "dhtmlx_wins_body_border_middle_right") {
				that.resizingDirs = "border_right";
				this.style.cursor = "e-resize";
				this.resizeOffsetXW = this.x + this.w - e.clientX;
				useDefaultCursor = false;
			}
			// bottom border
			if (targetObj.className == "dhtmlx_wins_body_border_bottom_middle") {
				that.resizingDirs = "border_bottom";
				this.style.cursor = "n-resize";
				this.resizeOffsetYH = this.y + this.h - e.clientY;
				useDefaultCursor = false;
			}
			// corner left
			if (targetObj.className == "dhtmlx_wins_body_border_bottom_left") {
				that.resizingDirs = "corner_left";
				this.style.cursor = "sw-resize";
				this.resizeOffsetX = this.x - e.clientX;
				this.resizeOffsetYH = this.y + this.h - e.clientY;
				useDefaultCursor = false;
			}
			// corner right
			if (targetObj.className == "dhtmlx_wins_body_border_bottom_right") {
				that.resizingDirs = "corner_right";
				this.style.cursor = "nw-resize";
				this.resizeOffsetXW = this.x + this.w - e.clientX;
				this.resizeOffsetYH = this.y + this.h - e.clientY;
				useDefaultCursor = false;
			}
			
			// no matching elements
			if (useDefaultCursor) {
				this.canStartResize = false;
				this.style.cursor = "";
			}
		}
		win.onmousedown = function() {
			that._makeActive(this);
			that._bringOnTop(this);
			if (this.canStartResize) {
				that._blockSwitcher("none");
				that.resizingWin = this;
				if (this.layout) { this.callEvent("_onBeforeTryResize", [this]); }
			}
		}
		// add buttons
		this._addDefaultButtons(win);
		//
//#wind_buttons:09062008{		
		// return button handler
		win.button = function(id) {
			var b = null;
			if (this.btns[id] != null) { b = this.btns[id]; }
			return b;
		}
//#}		
		//
		// attach content obj|url
		/**
		*   @desc: attaches object into window
		*   @param: objId - object or object id
		*   @param: changeDisp - removes style="display: none;" after adding
		*   @type: public
		*/
		win.attachObject = function(obj, changeDisp) {
			if (typeof(obj) == "string") { obj = document.getElementById(obj); }
			that._attachContent(this, "obj", obj, changeDisp);
		}
		/**
		*   @desc: attaches url into window
		*   @param: url
		*   @type: public
		*/
		win.attachURL = function(url) {
			that._attachContent(this, "url", url, false);
		}
		/**
		*   @desc: centring window in viewport
		*   @type: public
		*/
		win.center = function() {
			that._centerWindow(this, false);
		}
		/**
		*   @desc: centring window in screen
		*   @type: public
		*/
		win.centerOnScreen = function() {
			that._centerWindow(this, true);
		}
		//
		this._attachContent(win, "empty", null, false);
		win.bringToTop();
		//
		return this.wins[id];
	}
	
	this._diableOnSelectInWin = function(obj, state) {
		for (var q=0; q<obj.childNodes.length; q++) {
			var child = obj.childNodes[q];
			if ((child.tagName == "TD") || (child.tagName == "TR") || (child.tagName == "TABLE")  || (child.tagName == "DIV")) {
				if (child.getAttribute("clearonselect") != null) {
					if (state) {
						child.onselectstart = function(e) { e = e || event; e.returnValue = false; }
						
					} else {
						child.onselectstart = null;
					}
				}
			}
			if (child.childNodes.length > 0) { this._diableOnSelectInWin(child, state); }
			child = null;
		}
	}
	
	this._redrawWindow = function(win) {
		if (win._isFullScreened) return;
		//
		win.style.left = win.x + "px";
		win.style.top = win.y + "px";
		// win.style.width = win.w + "px";
		// win.style.height = win.h + "px";
		win.style.width = (win.w == "100%" ? win.w : win.w+"px");
		win.style.height = (win.h == "100%" ? win.h : win.h+"px");
		if (win.w == "100%") {
			var winW = "100%";
			win.w = win.offsetWidth;
		}
		if (win.h == "100%") {
			var winH = "100%";
			win.h = win.offsetHeight;
		}
		// inner elements
		win.childNodes[0].style.height = win.h + "px";
		var p = win.childNodes[0].childNodes[0].childNodes[1].childNodes[0];
		var s = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
		p.style.height = win.h-s["header_height"] + "px";
		p.childNodes[0].style.height = win.h-s["header_height"] + "px";
		// title width
		// win.childNodes[2].className = "title_"+this.skin;
		var wdth = win.childNodes[3].offsetLeft - win.childNodes[2].offsetLeft - 5;
		if (wdth < 0) { wdth = 0; }
		win.childNodes[2].style.width = wdth + "px";
		// content div
		var w = win.w - s["border_left_width"] - s["border_right_width"];
		var h = win.h - s["header_height"] - s["border_bottom_height"];
		if (w < 0) { w = 0; }
		if (h < 0) { h = 0; }
		//
		var bd = p.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
		//
		/*
		if (win._manageAddons) {
			win._manageAddons(w, h);
		} else {
			bd.style.width = w + "px";
			bd.style.height = h + "px";
		}
		*/
		
			if (bd == null) {
				bd = win._content;
			}
			// new
			bd.style.width = w + "px";
			bd.style.height = h + "px";
			//
		if (winW != null) { win.w = winW; }
		if (winH != null) { win.h = winH; }
	}
	
	this.zIndexStep = 150;
	this._getTopZIndex = function(ignoreSticked) {
		var topZIndex = 0;
		for (var a in this.wins) {
			if (ignoreSticked == true) {
				if (this.wins[a].zi > topZIndex) { topZIndex = this.wins[a].zi; }
			} else {
				if (this.wins[a].zi > topZIndex && !this.wins[a]._isSticked) { topZIndex = this.wins[a].zi; }
			}
		}
		return topZIndex;
	}
	
	this.movingWin = null;
//#wind_move:09062008{
	this._moveWindow = function(e) {
		
		if (this.movingWin != null) {
			//
			if (!this.movingWin._allowMove || !this.movingWin._allowMoveGlobal) { return; }
			//
			this.movingWin.oldMoveX = this.movingWin.x;
			this.movingWin.oldMoveY = this.movingWin.y;
			//
			this.movingWin.x = e.clientX + this.movingWin.moveOffsetX;
			this.movingWin.y = e.clientY + this.movingWin.moveOffsetY;
			//
			// check out of viewport
			this._fixWindowPositionInViewport(this.movingWin);
			//
			this._redrawWindow(this.movingWin);
			//
			if (this._compoEnabled) { this._compoFixMove(this.movingWin); }
		}
		
		if (this.resizingWin != null) {
			//
			if (!this.resizingWin._allowResize) { return; }
			//
			// resize through left border
			if (this.resizingDirs == "border_left" || this.resizingDirs == "corner_left") {
				var ofs = e.clientX + this.resizingWin.resizeOffsetX;
				var sign = (ofs > this.resizingWin.x ? -1 : 1);
				newW = this.resizingWin.w + Math.abs(ofs - this.resizingWin.x)*sign;
				if ((newW < this.resizingWin.minW) && (sign < 0)) {
					this.resizingWin.x = this.resizingWin.x + this.resizingWin.w - this.resizingWin.minW;
					this.resizingWin.w = this.resizingWin.minW;
				} else {
					this.resizingWin.w = newW;
					this.resizingWin.x = ofs;
				}
				this._redrawWindow(this.resizingWin);
			}
			// resize through right border
			if (this.resizingDirs == "border_right" || this.resizingDirs == "corner_right") {
				var ofs = e.clientX - (this.resizingWin.x + this.resizingWin.w) + this.resizingWin.resizeOffsetXW;
				newW = this.resizingWin.w + ofs;
				if (newW < this.resizingWin.minW) { newW = this.resizingWin.minW; }
				this.resizingWin.w = newW;
				this._redrawWindow(this.resizingWin);
			}
			// resize through bottom border
			if (this.resizingDirs == "border_bottom" || this.resizingDirs == "corner_left" || this.resizingDirs == "corner_right") {
				var ofs = e.clientY - (this.resizingWin.y + this.resizingWin.h) + this.resizingWin.resizeOffsetYH;
				newH = this.resizingWin.h + ofs;
				if (newH < this.resizingWin.minH) { newH = this.resizingWin.minH; }
				this.resizingWin.h = newH;
				
				if (this._compoEnabled) {
					this._compoFixResize(this.resizingWin, this.resizingDirs);
				} else {
					this._redrawWindow(this.resizingWin);
				}
				//
			}
			//
			// if (this._compoEnabled) { this._compoFixResize(this.resizingWin, this.resizingDirs); }
		}
	}
	
	this._stopMove = function() {
		if (this.movingWin != null) {
			var win = this.movingWin;
			this.movingWin = null;
			this._blockSwitcher("");
			// cursor
			win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].style.cursor = "";
			win.childNodes[2].style.cursor = "";
			// fixing mozilla artefakts
			if (_isFF) {
				win.h++;
				this._redrawWindow(win);
				win.h--;
				this._redrawWindow(win);
			}
			// events
			if (!(win.oldMoveX == win.x && win.oldMoveY == win.y)) {
				//
				if (win.checkEvent("onMoveFinish")) {
					win.callEvent("onMoveFinish",[win]);
				} else {
					this.callEvent("onMoveFinish",[win]);
				}
			}
		}
		if (this.resizingWin != null) {
			var win = this.resizingWin;
			this.resizingWin = null;
			this._blockSwitcher("");
			// sizes in attached grid
			if (win.grid) { win.grid.setSizes(); }
			// sizes in attached tabbar
			if (win.tabbar) { win.tabbar.adjustOuterSize(); }
			// sizes in acordion
			if (win.accordion) { win.accordion.setSizes(); }
			// sizes in layout
			if (win.layout) {
				win.layout.setSizes(win);
				win.layout.callEvent("onResize", []);
			}
			// events
			if (win.checkEvent("onResizeFinish")) {
				win.callEvent("onResizeFinish",[win]);
			} else {
				this.callEvent("onResizeFinish",[win]);
			}
		}
	}
//#}	
	
	// check viewport overflow
	this._fixWindowPositionInViewport = function(win) {
		var skin = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
		if (win._keepInViewport) { // keep strongly in viewport
			if (win.x < 0) { win.x = 0; }
			if (win.x + win.w > this.vp.offsetWidth) { win.x = this.vp.offsetWidth - win.w; }
			if (win.y < 0) { win.y = 0; }
			if (win.y + win.h > this.vp.offsetHeight) { win.y = this.vp.offsetHeight - win.h; }
		} else {
			if (win.y < 0) { win.y = 0; }
			if (win.y + skin["header_height"] > this.vp.offsetHeight) { win.y = this.vp.offsetHeight - skin["header_height"]; }
			if (win.x + win.w - 10 < 0) { win.x = 10 - win.w; }
			if (win.x > this.vp.offsetWidth - 10) { win.x = this.vp.offsetWidth - 10; }
		}
	}
	
	// check and correct window dimensions
	this._fixWindowDimensionInViewport = function(win) {
		if (win.w < win.minW) { win.w = win.minW; }
		if (win.h < win.minH) { win.h = win.minH; }
	}
	
	this._bringOnTop = function(win) {
		var cZIndex = win.zi;
		var topZIndex = this._getTopZIndex(win._isSticked);
		for (var a in this.wins) {
			if (this.wins[a] != win) {
				if (win._isSticked || (!win._isSticked && !this.wins[a]._isSticked)) {
					if (this.wins[a].zi > cZIndex) {
						this.wins[a].zi = this.wins[a].zi - this.zIndexStep;
						this.wins[a].style.zIndex = this.wins[a].zi;
					}
				}
			}
		}
		win.zi = topZIndex;
		win.style.zIndex = win.zi;
	}
	
	this._makeActive = function(win) {
		for (var a in this.wins) {
			if (this.wins[a] == win) {
				var needEvent = false;
				if (this.wins[a].className != "dhtmlx_window_active") { needEvent = true; }
				this.wins[a].className = "dhtmlx_window_active";
				this.wins[a].childNodes[1].src = this.wins[a].icons[0];
				if (needEvent == true) {
					if (win.checkEvent("onFocus")) {
						win.callEvent("onFocus",[win]);
					} else {
						this.callEvent("onFocus",[win]);
					}
				}
			} else {
				this.wins[a].className = "dhtmlx_window_inactive";
				this.wins[a].childNodes[1].src = this.wins[a].icons[1];
			}
		}
	}
	
	this._getActive = function() {
		var win = null;
		for (var a in this.wins) {
			if (this.wins[a].className == "dhtmlx_window_active") {
				win = this.wins[a];
			}
		}
		return win;
	}
	
	this._centerWindow = function(win, onScreen) {
		if (win._isMaximized == true) { return; }
		if (win._isParked == true) { return; }
		if (onScreen == true) {
			var vpw = (_isIE?document.body.offsetWidth:window.innerWidth);
			var vph = (_isIE?document.body.offsetHeight:window.innerHeight);
		} else {
			var vpw = (this.vp==document.body?document.body.offsetWidth:(Number(parseInt(this.vp.style.width))&&String(this.vp.style.width).search("%")==-1?parseInt(this.vp.style.width):this.vp.offsetWidth));
			var vph = (this.vp==document.body?document.body.offsetHeight:(Number(parseInt(this.vp.style.height))&&String(this.vp.style.height).search("%")==-1?parseInt(this.vp.style.height):this.vp.offsetHeight));
		}
		var newX = Math.round((vpw/2) - (win.w/2));
		var newY = Math.round((vph/2) - (win.h/2));
		win.x = newX;
		win.y = newY;
		this._fixWindowPositionInViewport(win);
		this._redrawWindow(win);
	}
	
	this._switchProgress = function(win, state) {
		if (state == true) {
			win.childNodes[1].style.display = "none";
			win.childNodes[4].style.display = "";
		} else {
			win.childNodes[4].style.display = "none";
			win.childNodes[1].style.display = "";
		}
	}
	
	this._addDefaultButtons = function(win) {
//#wind_buttons:09062008{
		// stick
		var btnStick = document.createElement("DIV");
		btnStick.className = "button_stick_default";
		btnStick.title = "Stick";
		btnStick.isVisible = false;
		btnStick._isEnabled = true;
		btnStick.isPressed = false;
		win._isSticked = false;
		btnStick.label = "stick";
		btnStick._doOnClick = function() {
			this.isPressed = true;
			that._stickWindow(win);
		}
		
		// sticked
		var btnSticked = document.createElement("DIV");
		btnSticked.className = "button_sticked_default";
		btnSticked.title = "Unstick";
		btnSticked.isVisible = false;
		btnSticked._isEnabled = true;
		btnSticked.isPressed = false;
		btnSticked.label = "sticked";
		btnSticked._doOnClick = function() {
			this.isPressed = false;
			that._unstickWindow(win);
		}
		
		// help
		var btnHelp = document.createElement("DIV");
		btnHelp.className = "button_help_default";
		btnHelp.title = "Help";
		btnHelp.isVisible = false;
		btnHelp._isEnabled = true;
		btnHelp.isPressed = false;
		btnHelp.label = "help";
		btnHelp.that = this;
		btnHelp._doOnClick = function() { that._needHelp(win); }
		
		// park
		var btnPark = document.createElement("DIV");
		btnPark.className = "button_park_default";
		btnPark.titleIfParked = "Park Down";
		btnPark.titleIfNotParked = "Park Up";
		btnPark.title = btnPark.titleIfNotParked;
		btnPark.isVisible = true;
		btnPark._isEnabled = true;
		btnPark.isPressed = false;
		btnPark.label = "park";
		win._isParked = false;
		win._isParkedAllowed = true;
		btnPark._doOnClick = function() { that._parkWindow(win); }
		
		// minmax maximize
		var btnMinMax1 = document.createElement("DIV");
		btnMinMax1.className = "button_minmax1_default";
		btnMinMax1.title = "Maximize";
		btnMinMax1.isVisible = true;
		btnMinMax1._isEnabled = true;
		btnMinMax1.isPressed = false;
		btnMinMax1.label = "minmax1";
		win._isMaximized = false;
		btnMinMax1._doOnClick = function() { that._maximizeWindow(win); }
		
		// minmax restore
		var btnMinMax2 = document.createElement("DIV");
		btnMinMax2.className = "button_minmax2_default";
		btnMinMax2.title = "Restore";
		btnMinMax2.isVisible = false;
		btnMinMax2._isEnabled = true;
		btnMinMax2.isPressed = false;
		btnMinMax2.label = "minmax2";
		btnMinMax2._doOnClick = function() { that._restoreWindow(win); }
		
		// close
		var btnClose = document.createElement("DIV");
		btnClose.className = "button_close_default";
		btnClose.title = "Close";
		btnClose.isVisible = true;
		btnClose._isEnabled = true;
		btnClose.isPressed = false;
		btnClose.label = "close";
		btnClose._doOnClick = function() { that._closeWindow(win); }
		
		//
		win.btns = {};
		win.btns["stick"] = btnStick;
		win.btns["sticked"] = btnSticked;
		win.btns["help"] = btnHelp;
		win.btns["park"] = btnPark;
		win.btns["minmax1"] = btnMinMax1;
		win.btns["minmax2"] = btnMinMax2;
		win.btns["close"] = btnClose;
		
		var b = win.childNodes[3].childNodes[0].childNodes[0].childNodes[0];
		
		// events
		for (var a in win.btns) {
			
			var btn = win.btns[a];
			
			// add on header
			var td = document.createElement("TD");
			td.className = "dhtmlx_wins_btn_" + (btn.isVisible ? "visible" : "hidden");
			b.appendChild(td);
			td.appendChild(btn);
			// attach events
			this._attachEventsOnButton(win, btn);
			//
			btn = null;
		}
//#}		
	}
//#wind_buttons:09062008{
	this._attachEventsOnButton = function(win, btn) {
		// add events
		
		btn.onmouseover = function() {
			if (this._isEnabled) {
				this.className = "button_"+this.label+"_over_" + (this.isPressed ? "pressed": "default");
			} else {
				this.className = "button_"+this.label+"_disabled";
			}
		}
		btn.onmouseout = function() {
			if (this._isEnabled) {
				this.isPressed = false;
				this.className = "button_"+this.label+"_default";
			} else {
				this.className = "button_"+this.label+"_disabled";
			}
		}
		btn.onmousedown = function() {
			if (this._isEnabled) {
				this.isPressed = true;
				this.className = "button_"+this.label+"_over_pressed";
			} else {
				this.className = "button_"+this.label+"_disabled";
			}
		}
		btn.onmouseup = function() {
			if (this._isEnabled) {
				var wasPressed = this.isPressed;
				this.isPressed = false;
				this.className = "button_"+this.label+"_over_default";
				if (wasPressed) {
					// events
					if (this.checkEvent("onClick")) {
						this.callEvent("onClick", [win, this]);
					} else {
						this._doOnClick();
					}
				}
			} else {
				this.className = "button_"+this.label+"_disabled";
			}
		}
/**
*   @desc: show button
*   @type:  public
*/
		btn.show = function() {
			that._showButton(win, this.label);
		}
/**
*   @desc: hide button
*   @type:  public
*/
		btn.hide = function() {
			that._hideButton(win, this.label);
		}
/**
*   @desc: enable button
*   @type:  public
*/

		btn.enable = function() {
			that._enableButton(win, this.label);
		}

/**
*   @desc: disable button
*   @type:  public
*/
		btn.disable = function() {
			that._disableButton(win, this.label);
		}
/**
*   @desc: check if button is enabled
*	@returns: true if enabled, otherwise - false
*   @type:  public
*/
		btn.isEnabled = function() {
			return this._isEnabled;
		}

/**
*   @desc: check if button is hidden
*	@returns: true if hidden, otherwise - false
*   @type:  public
*/
		btn.isHidden = function() {
			return (!this.isVisible);
		}
		btn.dhx_Event = this.dhx_Event;
		btn.dhx_Event();
	}
//#}	
//#wind_park:09062008{
	this._parkWindow = function(win) {
		if (!win._isParkedAllowed) { return; }
		if (this.enableParkEffect && win.parkBusy) { return; }
		if (win._isParked) {
			if (this.enableParkEffect) {
				win.parkBusy = true;
				// win.childNodes[0].childNodes[0].childNodes[1].style.display = "";
				win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "";
				this._doParkDown(win);
			} else {
				win.h = win.lastParkH;
				win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "";
				win.btns["park"].title = win.btns["park"].titleIfNotParked;
				if (win._allowResizeGlobal == true) {
					this._enableButton(win, "minmax1");
					this._enableButton(win, "minmax2");
				}
			}
		} else {
			win.lastParkH = (String(win.h).search(/\%$/)==-1?win.h:win.offsetHeight);
			if (win._allowResizeGlobal == true) {
				this._disableButton(win, "minmax1");
				this._disableButton(win, "minmax2");
			}
			//
			if (this.enableParkEffect) {
				win.parkBusy = true;
				this._doParkUp(win);
			} else {
				var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
				win.h = skinParams["header_height"] + skinParams["border_bottom_height"];
				win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "none";
				win.btns["park"].title = win.btns["park"].titleIfParked;
			}
		}
		if (!this.enableParkEffect) {
			win._isParked = !win._isParked;
			this._redrawWindow(win);
			// events
			if (!win._isParked) {
				// fix tabbar
				if (win.tabbar) { win.tabbar.adjustOuterSize(); }
				// fix menu toplevel visibility
				if (win.menu != null) { win.menu._redistribTopLevelPositions(); }
				// fix grid sizes
				if (win.grid != null) { win.grid.setSizes(); }
				// onParkDown event
				if (win.checkEvent("onParkDown")) {
					win.callEvent("onParkDown", [win]);
				} else {
					this.callEvent("onParkDown", [win]);
				}
			} else {
				// bottom border fix for opera
				if (_isOpera) {
					win.childNodes[0].border = 1;
					win.childNodes[0].border = 0;
				}
				// onParkUp event
				if (win.checkEvent("onParkUp")) {
					win.callEvent("onParkUp", [win]);
				} else {
					this.callEvent("onParkUp", [win]);
				}
			}
		}
	}
	
	this._allowParking = function(win) {
		win._isParkedAllowed = true;
		this._enableButton(win, "park");
	}
	this._denyParking = function(win) {
		win._isParkedAllowed = false;
		this._disableButton(win, "park");
	}
	
	// park with effects
	this.enableParkEffect = true;
	this.parkStartSpeed = 80;
	this.parkSpeed = this.parkStartSpeed;
	this.parkTM = null;
	this.parkTMTime = 5;
	
	this._doParkUp = function(win) {
		if (String(win.h).search(/\%$/) != -1) {
			win.h = win.offsetHeight;
		}
		win.h -= this.parkSpeed;
		var skinParams = (win._skinParams!=null?win._skinParams:this.skinParams[this.skin]);
		if (win.h <= skinParams["header_height"] + skinParams["border_bottom_height"]) {
			// end purkUp
			win.h = skinParams["header_height"] + skinParams["border_bottom_height"];
			// win.childNodes[0].childNodes[0].childNodes[1].style.display = "none";
			win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.display = "none";
			win.btns["park"].title = win.btns["park"].titleIfParked;
			win._isParked = true;
			win.parkBusy = false;
			this._redrawWindow(win, true);
			// bottom border fix for opera
			if (_isOpera) {
				win.childNodes[0].border = 1;
				win.childNodes[0].border = 0;
			}
			// onParkUp event
			if (win.checkEvent("onParkUp")) {
				win.callEvent("onParkUp", [win]);
			} else {
				this.callEvent("onParkUp", [win]);
			}
		} else {
			// continue purkUp
			this._redrawWindow(win);
			this.parkTM = window.setTimeout(function(){that._doParkUp(win);}, this.parkTMTime);
		}
	}
	
	this._doParkDown = function(win) {
		win.h += this.parkSpeed;
		
		if (win.h >= win.lastParkH) {
			win.h = win.lastParkH;
			win.btns["park"].title = win.btns["park"].titleIfNotParked;
			if (win._allowResizeGlobal == true) {
				this._enableButton(win, "minmax1");
				this._enableButton(win, "minmax2");
			}
			win._isParked = false;
			win.parkBusy = false;
			this._redrawWindow(win);
			// fix tabbar
			if (win.tabbar) { win.tabbar.adjustOuterSize(); }
			// fix menu toplevel visibility
			if (win.menu != null) { win.menu._redistribTopLevelPositions(); }
			// fix grid sizes
			if (win.grid != null) { win.grid.setSizes(); }
			// onParkDown event
			if (win.checkEvent("onParkDown")) {
				win.callEvent("onParkDown", [win]);
			} else {
				this.callEvent("onParkDown", [win]);
			}
		} else {
			// continue purkDown
			this._redrawWindow(win);
			this.parkTM = window.setTimeout(function(){ that._doParkDown(win); }, this.parkTMTime);
		}
	}
//#}
//#wind_buttons:09062008{
	this._enableButton = function(win, btn) {
		win.btns[btn]._isEnabled = true;
		win.btns[btn].className = "button_"+win.btns[btn].label+"_default";
	}
	
	this._disableButton = function(win, btn) {
		win.btns[btn]._isEnabled = false;
		win.btns[btn].className = "button_"+win.btns[btn].label+"_disabled";
	}
//#}
	// header control
	this._showWindowHeader = function(win) {
		win.childNodes[1].style.display = "";
		win.childNodes[2].style.display = "";
		win.childNodes[3].style.display = "";
		for (var a in win._skinParams) { delete win._skinParams[a]; }
		win._skinParams = null;
		var h = this.skinParams[this.skin]["header_height"]+"px";
		win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // td class="dhtmlx_wins_td_header_full"
		win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // table class="dhtmlx_wins_header"
		var hdr = win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
		for (var q=0; q<hdr.childNodes.length; q++) { hdr.childNodes[q].style.height = h; }
		this._redrawWindow(win);
	}
	this._hideWindowHeader = function(win) {
		win.childNodes[1].style.display = "none";
		win.childNodes[2].style.display = "none";
		win.childNodes[3].style.display = "none";
		win._skinParams = {};
		for (var a in this.skinParams[this.skin]) { win._skinParams[a] = Number(this.skinParams[this.skin][a]).valueOf(); }
		win._skinParams["header_height"] = win._skinParams["border_bottom_height"];
		var h = win._skinParams["header_height"]+"px";
		win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // td class="dhtmlx_wins_td_header_full"
		win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].style.height = h; // table class="dhtmlx_wins_header"
		var hdr = win.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
		for (var q=0; q<hdr.childNodes.length; q++) { hdr.childNodes[q].style.height = h; }
		this._redrawWindow(win);
	}
	// resize
	this._allowReszieGlob = function(win) {
		win._allowResizeGlobal = true;
		this._enableButton(win, "minmax1");
		this._enableButton(win, "minmax2");
	}
	
	this._denyResize = function(win) {
		win._allowResizeGlobal = false;
		this._disableButton(win, "minmax1");
		this._disableButton(win, "minmax2");
	}
	
	this._maximizeWindow = function(win) {
		if (win._allowResizeGlobal == false) { return; }
		win.lastMaximizeX = win.x;
		win.lastMaximizeY = win.y;
		win.lastMaximizeW = win.w;
		win.lastMaximizeH = win.h;
		win.x = 0;
		win.y = 0;
		win._isMaximized = true;
		win._allowMove = false;
		win._allowResize = false;
		// win.w = (win.maxW == "auto" ? (this.vp == document.body ? document.body.offsetWidth:parseInt(this.vp.style.width)) : win.maxW);
		// win.h = (win.maxH == "auto" ? (this.vp == document.body ? document.body.offsetHeight:parseInt(this.vp.style.height)) : win.maxH);
		//
		win.w = (win.maxW == "auto" ? (this.vp == document.body ? "100%" : (this.vp.style.width != "" ? parseInt(this.vp.style.width) : this.vp.offsetWidth)) : win.maxW);
		win.h = (win.maxH == "auto" ? (this.vp == document.body ? "100%" : (this.vp.style.height != "" ? parseInt(this.vp.style.height) : this.vp.offsetHeight)) : win.maxH);
		//
		this._hideButton(win, "minmax1");
		this._showButton(win, "minmax2");
		this._redrawWindow(win);
		// sizes in attached grid
		if (win.grid) { win.grid.setSizes(); }
		// sizes in attached tabbar
		if (win.tabbar) { win.tabbar.adjustOuterSize(); }
		// sizes in acordion
		if (win.accordion) { win.accordion.setSizes(); }
		// layout sizes
		if (win.layout) { win.layout.setSizes(win); }
		// event
		if (win.checkEvent("onMaximize")) {
			win.callEvent("onMaximize", [win]);
		} else {
			this.callEvent("onMaximize", [win]);
		}
	}
	
	this._restoreWindow = function(win) {
		if (win._allowResizeGlobal == false) { return; }
		if (win.layout) { win.layout._defineWindowMinDimension(win); }
		win.x = win.lastMaximizeX;
		win.y = win.lastMaximizeY;
		win.w = win.lastMaximizeW;
		win.h = win.lastMaximizeH;
		win._isMaximized = false;
		win._allowMove = win._allowMoveGlobal;
		win._allowResize = true;
		this._fixWindowDimensionInViewport(win);
		this._hideButton(win, "minmax2");
		this._showButton(win, "minmax1");
		this._redrawWindow(win);
		// sizes in attached grid
		if (win.grid) { win.grid.setSizes(); }
		// sizes in attached tabbar
		if (win.tabbar) { win.tabbar.adjustOuterSize(); }
		// sizes in acordion
		if (win.accordion) { win.accordion.setSizes(); }
		// layout sizes
		if (win.layout) { win.layout.setSizes(win); }
		// events
		if (win.checkEvent("onMinimize")) {
			win.callEvent("onMinimize", [win]);
		} else {
			this.callEvent("onMinimize", [win]);
		}
	}
//#wind_buttons:09062008{	
	this._showButton = function(win, btn) {
		win.btns[btn].isVisible = true;
		// win.btns[btn].parentNode.className = "dhtmlx_wins_btn_visible";
		var p = win.btns[btn].parentNode;
		p.className = "dhtmlx_wins_btn_visible";
		p = null;
	}
	
	this._hideButton = function(win, btn) {
		win.btns[btn].isVisible = false;
		// win.btns[btn].parentNode.className = "dhtmlx_wins_btn_hidden";
		var p = win.btns[btn].parentNode;
		p.className = "dhtmlx_wins_btn_hidden";
		p = null;
	}
//#}	
	this._showWindow = function(win) {
		win.style.display = "";
		// event
		if (win.checkEvent("onShow")) {
			win.callEvent("onShow", [win]);
		} else {
			this.callEvent("onShow", [win]);
		}
		// fixed 24.03.2008
		var w = this._getActive();
		if (w == null) {
			this._bringOnTop(win);
			this._makeActive(win);
		} else if (this._isWindowHidden(w)) {
			this._bringOnTop(win);
			this._makeActive(win);
		}
	}
	
	this._hideWindow = function(win) {
		win.style.display = "none";
		// event
		if (win.checkEvent("onHide")) {
			win.callEvent("onHide", [win]);
		} else {
			this.callEvent("onHide", [win]);
		}
		// fixed 24.03.2008
		var w = this.getTopmostWindow(true);
		if (w != null) {
			this._bringOnTop(w);
			this._makeActive(w);
		}
	}
	
	this._isWindowHidden = function(win) {
		var isHidden = (win.style.display == "none");
		return isHidden;
	}
	
	this._closeWindow = function(win) {
		// event
		if (win.checkEvent("onClose")) {
			if (!win.callEvent("onClose", [win])) return;
		} else {
			if(!this.callEvent("onClose", [win])) return;
		}
		// closing
		// for (var a in win.btns) { this._removeButtonGlobal(win, a, win.btns[a]); }
		this._removeWindowGlobal(win);
		/*
		this.vp.removeChild(win);
		delete this.wins[win.idd];
		// make active latest window
		*/
		var latest = { "zi": 0 };
		for (var a in this.wins) { if (this.wins[a].zi > latest.zi) { latest = this.wins[a]; } }
		if (latest != null) { this._makeActive(latest); }
	}
	
	this._needHelp = function(win) {
		// event only
		if (win.checkEvent("onHelp")) {
			win.callEvent("onHelp", [win]);
		} else {
			this.callEvent("onHelp", [win]);
		}
	}
	
	this._attachContent = function(win, type, obj, state) {
		// clear old content
		while (win._content.childNodes[2].childNodes.length > 0) { win._content.childNodes[2].removeChild(win._content.childNodes[2].childNodes[0]); }
		// clear cover if exists
		while (win._content.childNodes.length > 4) { win._content.removeChild(win._content.childNodes[4]); }
		// attach
		if (type == "url") {
			//
			var fr = document.createElement("IFRAME");
			fr.frameBorder = 0;
			fr.border = 0;
			fr.style.width = "100%";
			fr.style.height = "100%";
			fr.src = obj;
			win._content.childNodes[2].appendChild(fr);
			win._frame = fr;
			if (_isIE) {
				win._frame.onreadystatechange = function(a) { if (win._frame.readyState == "complete") { that.callEvent("onContentLoaded", [win]); } }
			} else {
				win._frame.onload = function() { that.callEvent("onContentLoaded", [win]); }
			}
			//
		} else if (type == "obj") {
			win._frame = null;
			win._content.childNodes[2].appendChild(obj);
			if (state) { obj.style.display = ""; }
		}
		var cover = document.createElement("DIV");
		cover.className = "dhx_content_cover_blocker";
		cover.style.display = "none";
		win._content.appendChild(cover);
	}
	
	this._setWindowIcon = function(win, iconEnabled, iconDisabled) {
		win.iconsPresent = true;
		win.icons[0] = this.imagePath + iconEnabled;
		win.icons[1] = this.imagePath + iconDisabled;
		win.childNodes[1].src = win.icons[win.isOnTop()?0:1];
	}
	
	this._getWindowIcon = function(win) {
		if (win.iconsPresent) {
			return new Array(win.icons[0], win.icons[1]);
		} else {
			return new Array(null, null);
		}
	}
	
	this._clearWindowIcons = function(win) {
		win.iconsPresent = false;
		win.icons[0] = this.imagePath + this.skin + "/active/icon_blank.gif";
		win.icons[1] = this.imagePath + this.skin + "/inactive/icon_blank.gif";
		win.childNodes[1].src = win.icons[win.isOnTop()?0:1];
	}
	
	this._restoreWindowIcons = function(win) {
		win.iconsPresent = true;
		win.icons[0] = this.imagePath + this.skin + "/active/icon_normal.gif";
		win.icons[1] = this.imagePath + this.skin + "/inactive/icon_normal.gif";
		win.childNodes[1].src = win.icons[win.isOnTop()?0:1];
	}
	
	this._attachWindowContentTo = function(win, obj, w, h) {
		
		var data = win._content;
		data.parentNode.removeChild(data);
		win.hide();
		//
		data.style.left = "0px";
		data.style.top = "0px";
		data.style.width = (w!=null?w:obj.offsetWidth)+"px";
		data.style.height = (h!=null?h:obj.offsetHeight)+"px";
		data.style.position = "relative";
		//
		obj.appendChild(data);
		
	}
	
	this._setWindowToFullScreen = function(win, state) {
		if (state == true) {
			//
			var data = win._content;
			data.parentNode.removeChild(data);
			win.hide();
			win._isFullScreened = true;
			//
			data.style.left = "0px";
			data.style.top = "0px";
			data.style.width = document.body.offsetWidth+"px";
			data.style.height = document.body.offsetHeight+"px";
			data.style.position = "absolute";
			
			document.body.appendChild(data);
			
		} else if (state == false) {
			
			var data = win.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1];
			var base = win._content;
			document.body.removeChild(base);
			data.appendChild(base);
			win._isFullScreened = false;
			win.setDimension(win.w, win.h);
			//
			win.show();
			win.bringToTop();
			win.center();
			//
			if (win.layout != null) { win.layout.setSizes(win); }
		}
	}
	
	this._isWindowOnTop = function(win) {
		var state = (this.getTopmostWindow() == win);
		return state;
	}
	
	this._bringOnBottom = function(win) {
		for (var a in this.wins) {
			if (this.wins[a].zi < win.zi) {
				this.wins[a].zi += this.zIndexStep;
				this.wins[a].style.zIndex = this.wins[a].zi;
			}
		}
		win.zi = 50;
		win.style.zIndex = win.zi;
		//
		this._makeActive(this.getTopmostWindow());
	}
	
	this._isWindowOnBottom = function(win) {
		var state = true;
		for (var a in this.wins) {
			if (this.wins[a] != win) {
				state = state && (this.wins[a].zi > win.zi);
			}
		}
		return state;
	}
	
	this._stickWindow = function(win) {
		win._isSticked = true;
		this._hideButton(win, "stick");
		this._showButton(win, "sticked");
		this._bringOnTop(win);
	}
	
	this._unstickWindow = function(win) {
		win._isSticked = false;
		this._hideButton(win, "sticked");
		this._showButton(win, "stick");
		this._bringOnTopAnyStickedWindows();
	}
//#wind_buttons:09062008{
	// add user button
	this._addUserButton = function(win, id, pos, title, label) {
		var btn = document.createElement("DIV");
		
		btn.className = "button_"+label+"_default";
		btn.title = title;
		btn.isVisible = true;
		btn._isEnabled = true;
		btn.isPressed = false;
		btn.label = label;
		//
		win.btns[id] = btn;
		//
		btn._doOnClick = function() {}
		// events
			
		// btn.that = this;
		// btn.win = win;
		var b = win.childNodes[3].childNodes[0].childNodes[0].childNodes[0];
		// add on header
		var td = document.createElement("TD");
		td.className = "dhtmlx_wins_btn_" + (btn.isVisible ? "visible" : "hidden");
		if (pos > b.childNodes.length) {
			b.appendChild(td);
		} else {
			if (pos < 0) { pos = 0; }
			b.insertBefore(td, b.childNodes[pos]);
		}
		
		td.appendChild(btn);
		
		// attach events
		this._attachEventsOnButton(win, btn);
	}
	
	// remove user button
	this._removeUserButton = function(win, id, btn) {
		this._removeButtonGlobal(win, id, btn);
	}
//#}	
	// add iframe blockers before drag and resize
	this._blockSwitcher = function(state) {
		for (var a in this.wins) {
			/*
			var winContent = this.wins[a].childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
			var cover = null;
			for (var q=0; q<winContent.childNodes.length; q++) { if (winContent.childNodes[q].className == "dhx_content_cover_blocker") { cover = winContent.childNodes[q]; } }
			if (cover != null) {
				cover.style.display = (state ? "" : "none");
			}
			*/
			var winContent = this.wins[a]._content;
			var cover = null;
			for (var q=0; q<winContent.childNodes.length; q++) { if (winContent.childNodes[q].className == "dhx_content_cover_blocker") { cover = winContent.childNodes[q]; } }
			if (cover != null) {
				cover.style.display = (state ? "" : "none");
			}
		}
	}
	
	this.resizingWin = null;
	this.modalWin = null;
	this.resizingDirs = "none";
	
	// init functions
	
	this._createViewport();
//#wind_move:09062008{	
	this._doOnMouseUp = function() {
		that._stopMove();
	}
	this._doOnMoseMove = function(e) {
		e = e||event;
		that._moveWindow(e);
	}
//#}	
	this._resizeTM = null;
	this._resizeTMTime = 200;
	this._doOnResize = function() {
		window.clearTimeout(that._resizeTM);
		that._resizeTM = window.setTimeout(function(){that._autoResizeViewport();}, that._resizeTMTime);
	}
	this._doOnUnload = function() {
		that.unload();
	}
	this._doOnSelectStart = function(e) {
		e = e||event;
		if (that.resizingWin != null) { e.returnValue = false; }
	}
	if (_isIE) 
		document.body.attachEvent("onselectstart", this._doOnSelectStart);
		
		dhtmlxEvent(window,"resize", this._doOnResize);
		dhtmlxEvent(document.body,"unload", this._doOnUnload);
//#wind_move:09062008{		
		dhtmlxEvent(document.body,"mouseup", this._doOnMouseUp);
		dhtmlxEvent(this.vp,"mousemove", this._doOnMoseMove);
		dhtmlxEvent(this.vp,"mouseup", this._doOnMouseUp);
//#}
	
	
	this._setWindowModal = function(win, state) {
		
		if (state == true) {
			
			this._makeActive(win);
			this._bringOnTop(win);
			this.modalWin = win;
			win._isModal = true;
			//
			this.modalCoverI.style.zIndex = win.zi - 2;
			this.modalCoverI.style.display = "";
			//
			this.modalCoverD.style.zIndex = win.zi - 2;
			this.modalCoverD.style.display = "";
		} else {
			this.modalWin = null;
			win._isModal = false;
			//
			this.modalCoverI.style.zIndex = 0;
			this.modalCoverI.style.display = "none";
			//
			this.modalCoverD.style.zIndex = 0;
			this.modalCoverD.style.display = "none";
		}
	}
	
	this._bringOnTopAnyStickedWindows = function() {
		var wins = new Array();
		for (var a in this.wins) { if (this.wins[a]._isSticked) { wins[wins.length] = this.wins[a]; } }
		for (var q=0; q<wins.length; q++) { this._bringOnTop(wins[q]); }
		// if no more sticked search any non-top active and move them on top
		if (wins.length == 0) {
			for (var a in this.wins) {
				if (this.wins[a].className == "dhtmlx_window_active") { this._bringOnTop(this.wins[a]); }
			}
		}
	}
	
	/**
	*   @desc: unloads object and clears memory
	*   @param: id - button id
	*   @type: public
	*/
	this.unload = function() {
		this._clearAll();
	}
	
	this._removeButtonGlobal = function(win, id, btn) {
//#wind_buttons:09062008{
		// clear functions
		this._parseNestedForEvents(btn);
		for (var a in btn) {
			if (typeof(btn[a]) == "function") {
				var k = (btn[a].toString()).split("\n");
				if (!(k.length == 3 && k[1].search(/\[native\scode\]/gi) != -1)) { btn[a] = null; }
			}
		}
		// remove from page
		var p = btn.parentNode;
		p.removeChild(btn);
		delete win.btns[id];
		btn = null;
		p = null;
//#}
	}
	
	this._removeWindowGlobal = function(win) {
		// modal check
		if (this.modalWin == win) { this._setWindowModal(win, false); }
		// clear functions
		this._parseNestedForEvents(win);
//#wind_buttons:09062008{				
		for (var a in win.btns) {
			this._removeButtonGlobal(win, a, win.btns[a]);
		}
//#}		
		for (var a in win) {
			if (typeof(win[a]) == "function") {
				var k = (win[a].toString()).split("\n");
				if (!(k.length == 3 && k[1].search(/\[native\scode\]/gi) != -1)) { win[a] = null; }
			}
		}
		// remove from page
		win._content = null;
		var p = win.parentNode;
		p.removeChild(win);
		delete this.wins[win.idd];
		win = null;
		p = null;
	}
	
	this._removeEvents = function(obj) {
		obj.onmouseover = null;
		obj.onmouseout = null;
		obj.onmousemove = null;
		obj.onclick = null;
		obj.ondblclick = null;
		obj.onmouseenter = null;
		obj.onmouseleave = null;
		obj.onmouseup = null;
		obj.onmousewheel = null;
		obj.onmousedown = null;
		obj.onselectstart = null;
		obj.onfocus = null;
		obj.style.display = "";
	}
	this._parseNestedForEvents = function(obj) {
		this._removeEvents(obj);
		for (var q=0; q<obj.childNodes.length; q++) {
			if (obj.childNodes[q].tagName != null) { this._parseNestedForEvents(obj.childNodes[q]); }
		}
	}
	
	this._attachStatusBar = function() {
		
	}
	
	this._attachWebMenu = function() {
		return null;
	}
	
	this._attachWebToolbar = function() {
		return null;
	}
	
	this._clearAll = function() {
		this._clearDocumentEvents();
		for (var a in this.wins) {
			this._diableOnSelectInWin(this.wins[a]);
			this._removeWindowGlobal(this.wins[a]);
		}
		// modal covers and vp
		this.modalCoverD.style.display = "";
		this._parseNestedForEvents(this.modalCoverD);
		this.modalCoverD.parentNode.removeChild(this.modalCoverD);
		this.modalCoverD = null;
		this._parseNestedForEvents(this.modalCoverI);
		this.modalCoverI.style.display = "";
		this.modalCoverI.parentNode.removeChild(this.modalCoverI);
		this.modalCoverI = null;
		if (this.vp != document.body) { this.vp.parentNode.removeChild(this.vp); }
		this.vp = null;
		// skin params
		for (var a in this.skinParams) { delete this.skinParams[a]; }
		this.skinParams = null;
		that = null;
		// self functions
		for (var a in this) { if (typeof(this[a]) == "function") { this[a] = null; } }
		for (var a in this) { delete this[a]; }
		//
		// console.log(this)
	}
	
	this._clearDocumentEvents = function() {
		if (_isIE) {
			window.detachEvent("onresize", this._doOnResize);
			document.body.detachEvent("onselectstart", this._doOnSelectStart);
			document.body.detachEvent("onmouseup", this._doOnMouseUp);
			document.body.detachEvent("onunload", this._doOnUnload);
			this.vp.detachEvent("onmousemove", this._doOnMoseMove);
			this.vp.detachEvent("onmouseup", this._doOnMouseUp);
		} else {
			window.removeEventListener("resize", this._doOnResize, false);
			document.body.removeEventListener("mouseup", this._doOnMouseUp, false);
			document.body.removeEventListener("unload", this._doOnUnload, false);
			this.vp.removeEventListener("mousemove", this._doOnMoseMove, false);
			this.vp.removeEventListener("mouseup", this._doOnMouseUp, false);
		}
	}
	
	/* additional features */
	if (this._enableStatusBar != null) { this._enableStatusBar(); }
	if (this._enableWebMenu != null) { this._enableWebMenu(); }
	if (this._enableWebToolbar != null) { this._enableWebToolbar(); }
	
	this._genStr = function(w) {
		var s = ""; var z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		for (var q=0; q<w; q++) { s = s + z.charAt(Math.round(Math.random() * z.length)); }
		return s;
	}
	
	// events
	this.dhx_Event = function() {
		//
		this.dhx_SeverCatcherPath = "";
		this.attachEvent = function(original, catcher, CallObj) {
			CallObj = CallObj||this;
			original = 'ev_'+original;
			if ((!this[original]) || (!this[original].addEvent)) {
				var z = new this.eventCatcher(CallObj);
				z.addEvent(this[original]);
				this[original] = z;
			}
			return (original + ':' + this[original].addEvent(catcher)); //return ID (event name & event ID)
		}
		this.callEvent = function(name,arg0) {
			if (this["ev_"+name]) return this["ev_"+name].apply(this,arg0);
			return true;
		}
		this.checkEvent = function(name){
			if (this["ev_"+name]) return true;
			return false;
		}
		this.eventCatcher = function(obj) {
			var dhx_catch = new Array();
			var m_obj = obj;
			var z = function() {
				if (dhx_catch) var res=true;
				for (var i=0; i<dhx_catch.length; i++) {
					if (dhx_catch[i] != null) {
						var zr = dhx_catch[i].apply( m_obj, arguments );
						res = res && zr;
					}
				}
				return res;
			}
			z.addEvent = function(ev) {
				if (typeof(ev) != "function")
					ev = eval(ev);
				if (ev)
					return dhx_catch.push( ev ) - 1;
				return false;
			}
			z.removeEvent = function(id) {
				dhx_catch[id] = null;
			}
			return z;
		}
		this.detachEvent = function(id) {
			if (id != false) {
				var list = id.split(':'); //get EventName and ID
				this[ list[0] ].removeEvent(list[1]); //remove event
			}
		}
	}
	this.dhx_Event();
	return this;
};
