/*
 * Kido JavaScript framework, version 1.0
 * Copyright (c) 2006 Lee Won-Gyoon <mail.kido@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * For details, see the Kido web site: http://www.kidoScript.net/
 * 
*******************************************************************************/
//alert("wet2452");
function Kidow(_instanceName) {
	this.Version = "1.0";
	this.instanceName = _instanceName;
	this.groupName = "KidoWindow";
//	this.opener = null;
//	this.TitleName="";
////	this.workArea = self;
//  this.workArea = top;
////	alert(this.workArea.);
//	if (this.workArea!=self) {
//		if (!this.workArea[this.instanceName]) {
//			this.workArea[this.instanceName] = new Kidow(this.instanceName);
//		}
//		this.windows = this.workArea[this.instanceName].windows;
//		//this.maxIndex = this.workArea[this.instanceName].maxIndex;
//		//this.maxZIndex = this.workArea[this.instanceName].maxZIndex;
//	} else {
//		this.windows = new Array;
//		this.maxIndex = 0;
//		this.maxZIndex = 2000;
//	}

this.opener = null;
	this.workArea = top;
	if (this.workArea!=self) {
		if (!this.workArea[this.instanceName]) {
			this.workArea[this.instanceName] = new Kidow(this.instanceName);
		}
		this.windows = this.workArea[this.instanceName].windows;
		//this.maxIndex = this.workArea[this.instanceName].maxIndex;
		//this.maxZIndex = this.workArea[this.instanceName].maxZIndex;
	} else {
		this.windows = new Array;
		this.maxIndex = 0;
		this.maxZIndex = 2000;
	}
	//PopUp Design Set
	this.vars = {
		  useBackgroundCover		: true
		, useTitleAreaBlurCover		: true
		, backgroundCoverColor		: "#FFFFFF"
		, backgroundCoverZIndex		: 1000
		, backgroundCoverOpacity	: 0.7
		, titleAreaBlurCoverOpacity	: 0.5
		, width						: 200
		, height					: 200
		, left						: null
		, top						: null
		, scrollbars				: "no"
		, bgcolor					: "#F0F0F0"
		, titlebarbgcolor			: "#000000"
		, alertTimer				: null
	};
	
	this.ids = {
		  backgroundCover : this.instanceName + "-backgroundCover"
		, backgroundCoverElement1 : this.instanceName + "-backgroundCoverElement1"
		, backgroundCoverElement2 : this.instanceName + "-backgroundCoverElement2"
		
		, alertBackgroundCover : this.instanceName + "-alertBackgroundCover"
		, alertBackgroundCoverElement1 : this.instanceName + "-alertBackgroundCoverElement1"
		, alertBackgroundCoverElement2 : this.instanceName + "-alertBackgroundCoverElement2"
		
		, alertBoxArea1 : this.instanceName + "-alertBoxArea1"
		, alertBoxArea2 : this.instanceName + "-alertBoxArea2"
		, alertBoxArea3 : this.instanceName + "-alertBoxArea3"
		, alertBoxArea4 : this.instanceName + "-alertBoxArea4"
		
		, openerName : this.instanceName + "-openerName"
		, isFirstChild : this.instanceName + "-isFirstChild"
	};
	this.$ = function(_objId) {
		return this.workArea.$(_objId);
	}
	
	this.hasBackgroundCover = function() {
		return (!this.$(this.ids.backgroundCover).isNull) ? true : false;
	}
	
	this.removeBackgroundCover = function() {
		var div = this.$(this.ids.backgroundCover);
		if (!div.isNull) this.workArea.document.body.removeChild(div);
		$E.removeAction(this.ids.backgroundCover);
	}
	
	this.writeBackgroundCover = function() {
		if (this.vars.useBackgroundCover&&!this.hasBackgroundCover()) {
			var cover = this.workArea.document.createElement("DIV");
			cover.setAttribute("id",this.ids.backgroundCover);
			cover.style.position = "absolute";
			cover.style.zIndex = this.vars.backgroundCoverZIndex;
			cover.style.filter = "alpha(opacity=" + (this.vars.backgroundCoverOpacity*100) + ")";
			cover.style.opacity = this.vars.backgroundCoverOpacity;
			cover.style.backgroundColor = this.vars.backgroundCoverColor;

			this.workArea.document.body.insertBefore(cover,this.workArea.document.body.firstChild);
			//cover.innerHTML = '<center id="'+this.ids.backgroundCoverElement1+'"><div id="'+this.ids.backgroundCoverElement2+'" style="width:'+this.workArea.document.body.scrollWidth+'px;height:'+this.workArea.document.body.scrollHeight+'px;background-color:'+this.vars.backgroundCoverColor+';"></div></center>';
			var scrollWidth = this.workArea.document.documentElement.scrollWidth;
			var scrollHeight = this.workArea.document.documentElement.scrollHeight;
			//alert(this.workArea.document.documentElement.scrollHeight + ':' + this.workArea.document.body.scrollHeight + ':' + this.workArea.document.documentElement.clientHeight);
			cover.innerHTML = '<center id="'+this.ids.backgroundCoverElement1+'"><div id="'+this.ids.backgroundCoverElement2+'" style="width:'+scrollWidth+'px;height:'+scrollHeight+'px;background-color:'+this.vars.backgroundCoverColor+';"></div></center>';
			$E.addAction("onMouseDown", this.ids.backgroundCover, this.instanceName+"._onMouseDownFromBackground()");
		}
	}
	
	this._onMouseDownFromBackground = function() {
		var elementId = $E.getElement().id;
		if (elementId==this.ids.backgroundCover||elementId==this.ids.backgroundCoverElement1||elementId==this.ids.backgroundCoverElement2) {
			this.focusWindow();
		}
	}
	
	this.getIds = function(_windowName) {
		return {
			  window				: _windowName + "-window"
			, windowArea			: _windowName + "-windowArea"
			, windowOffset			: _windowName + "-windowOffset"
			, textTitle				: _windowName + "-textTitle"
			, textTitleArea			: _windowName + "-textTitleArea"
			, imageTitle			: _windowName + "-imageTitle"
			, imageTitleArea		: _windowName + "-imageTitleArea"
			, loadingArea			: _windowName + "-loadingArea"
			, contentsFrame			: _windowName + "-contentsFrame"
			, contentsFrameArea		: _windowName + "-contentsFrameArea"
			, contentsArea			: _windowName + "-contentsArea"
			, contentsAreaCover		: _windowName + "-contentsAreaCover"
			, contentsAreaBlurCover	: _windowName + "-contentsAreaBlurCover"
			, titleArea				: _windowName + "-titleArea"
			, titleAreaBlurCover	: _windowName + "-titleAreaBlurCover"
		};
	}
	
	this.getNewValue = function(_oldValue, _newValue) {
		if (_newValue==null||_newValue==undefined) {
			return _oldValue;
		} else {
			return _newValue;
		}
	}
	
	this.getOptions = function(_options) {
		if (_options==null) _options = "";
		var temp = _options.split(",");
		var opt = new Object;
		for (var i=0; i<temp.length; i++) {
			if (temp[i].indexOf("=")>-1) {
				var temp2 = temp[i].split("=");
				opt[temp2[0].toLowerCase().trim()]=temp2[1].trim();
			}
		}
		var options = {
			  width				: this.getNewValue(this.vars.width, opt.width)
			, height			: this.getNewValue(this.vars.height, opt.height)
			, left				: this.getNewValue(this.vars.left, opt.left)
			, top				: this.getNewValue(this.vars.top, opt.top)
			, scrollbars		: this.getNewValue(this.vars.scrollbars, opt.scrollbars)
			, bgcolor			: this.getNewValue(this.vars.bgcolor, opt.bgcolor)
			, titlebarbgcolor	: this.getNewValue(this.vars.titlebarbgcolor, opt.titlebarbgcolor)
		};
		return options;
	}
	
	this.getCenterX = function(_width,_targetFrame) {
		if (_targetFrame==null) _targetFrame = this.workArea;
		//var bodyW = _targetFrame.document.documentElement.clientWidth;
		var bodyW = _targetFrame.document.body.clientWidth;
		var posX = Math.ceil(bodyW/2-(parseInt(_width)+20)/2);
		if (posX<10) posX = 10;
		//var scrollX = _targetFrame.document.body.scrollLeft;
		var scrollX = _targetFrame.document.documentElement.scrollLeft;
		return posX+scrollX;
	}
	
	this.getCenterY = function(_height,_targetFrame) {
		if (_targetFrame==null) _targetFrame = this.workArea;
		//var bodyH = _targetFrame.document.body.clientHeight;
		var bodyH = _targetFrame.document.documentElement.clientHeight;
		var posY = Math.ceil(bodyH/2-(parseInt(_height)+50)/2);
		if (posY<10) posY = 10;
		//var scrollY = _targetFrame.document.body.scrollTop;
		var scrollY =_targetFrame.document.documentElement.scrollTop;
        //alert(posY+scrollY);
		return posY+scrollY;
	}
	
	this.hasSameWindow = function(_windowName) {
		var hasSame = false;
		for (var i=0; i<this.windows.length; i++) {
			if (this.windows[i]==_windowName) {
				hasSame = true;
				break;
			}
		}
		return hasSame;
	}
	
	this._showContentsAreaCover = function() {
		var windows = this.windows.compact();
		for (var i=0; i<windows.length; i++) {
			var ids = this.getIds(windows[i]);
			this.$(ids.contentsAreaCover).setStyle("width", this.$(ids.contentsArea).getW());
			this.$(ids.contentsAreaCover).setStyle("height", this.$(ids.contentsArea).getH());
			this.$(ids.contentsAreaCover).setStyle("display", true);
		}
	}
	
	this._hideContentsAreaCover = function() {
		var windows = this.windows.compact();
		for (var i=0; i<windows.length; i++) {
			var ids = this.getIds(windows[i]);
			this.$(ids.contentsAreaCover).setStyle("display", false);
		}
	}
	
	this.connectToMouseEvent = function(_windowName) {
		$E.stop();
		var ids = this.getIds(_windowName);
		if ($E.vars.focusedWindow==null||$E.vars.focusedWindow==undefined) {
			$E.vars.focusedWindow = new Array;
		}
		if (this.$(ids.window).moveMode!="ing") {
			this._showContentsAreaCover();
			$E.vars.focusedWindow.push(_windowName);
			$E.vars.startX = $E.pointerX();
			$E.vars.startY = $E.pointerY();
			$E.addAction("onMouseMove", _windowName, this.instanceName+".moveToMousePointer(\""+_windowName+"\")");
			$E.addAction("onMouseUp", this.instanceName, this.instanceName+".disconnectFromMouseEvent()");
			$E.addAction("onSelectStart", this.instanceName, "$E.stop()");
			$E.addAction("onMouseMove", this.instanceName, "$E.stop()");
		}
	}
	
	this.moveToMousePointer = function(_windowName) {
		var ids = this.getIds(_windowName);
		if (this.$(ids.window).moveMode!="ing") {
			this.$(ids.window).moveMode = "ing";
			$E.vars.prevX = $E.vars.startX;
			$E.vars.prevY = $E.vars.startY;
		}
		var pointerX = $E.pointerX();
		var pointerY = $E.pointerY();
		var moveX = pointerX - $E.vars.prevX;
		var moveY = pointerY - $E.vars.prevY;
		var targetX = this.$(ids.window).getX()+moveX;
		var targetY = this.$(ids.window).getY()+moveY;
		if (targetX<0) targetX = 0;
		if (targetY<0) targetY = 0;
		this.$(ids.window).setStyle("left",targetX);
		this.$(ids.window).setStyle("top",targetY);
		$E.vars.prevX = pointerX;
		$E.vars.prevY = pointerY;
	}
	
	this.disconnectFromMouseEvent = function() {
		for (var i=0; i<$E.vars.focusedWindow.length; i++) {
			var ids = this.getIds($E.vars.focusedWindow[i]);
			$E.removeAction($E.vars.focusedWindow[i]);
			$E.vars.focusedWindow.remove($E.vars.focusedWindow[i]);
			this.$(ids.window).moveMode = "";
		}
		$E.removeAction(this.instanceName);
		$E.vars.focusedWindow = $E.vars.focusedWindow.compact();
		this._hideContentsAreaCover();
	}
	
	this._setTitleAreaBlurCoverWidth = function(_windowName) {
		var ids = this.getIds(_windowName);
		this.$(ids.titleAreaBlurCover).setStyle("width", this.$(ids.titleArea).getW());
		if (this.$(ids.contentsFrame).getAttribute("resizeStatus")=="ing") {
			setTimeout(this.instanceName+"._setTitleAreaBlurCoverWidth(\""+_windowName+"\")",20);
		}
	}
	
	this.focusWindow = function(_windowName) {
		var windows = this.windows.compact();
		 
		for (var i=0; i<windows.length; i++) {
			var ids = this.getIds(windows[i]);
			if (_windowName!=null&&windows[i]==_windowName) {
				if (this.vars.useTitleAreaBlurCover) {
					this.$(ids.titleAreaBlurCover).setStyle("display", false);
				}
				this.$(ids.contentsAreaBlurCover).setStyle("display", false);
				this.$(ids.window).setStyle("zIndex",this.workArea[this.instanceName].maxZIndex++);
			} else {
				if (this.vars.useTitleAreaBlurCover) {
					this._setTitleAreaBlurCoverWidth(windows[i]);
					this.$(ids.titleAreaBlurCover).setStyle("height", this.$(ids.titleArea).getH());
					this.$(ids.titleAreaBlurCover).setStyle("display", true);
				}
				this.$(ids.contentsAreaBlurCover).setStyle("width", this.$(ids.contentsArea).getW());
				this.$(ids.contentsAreaBlurCover).setStyle("height", this.$(ids.contentsArea).getH());
				this.$(ids.contentsAreaBlurCover).setStyle("display", true);
			}
		}
	}
	
	this.writeWindowLayer = function(_windowName, _options) {
		if (!this.hasSameWindow(_windowName)) {
		   
		var options = this.getOptions(_options);
		
			var ids = this.getIds(_windowName);
			    var s = '';
                s +='<table cellpadding="0" cellspacing="0">\n';
                s +='  <tr>\n';
	            s +='    <td class="vpt1" width="10"><img src="/hantaCommon/image/product/vtopl.gif" alt="." /></td>\n';
	            s +='    <td class="vpt2">\n';
		        s +='       <div class="vclose"><img src="/hantaCommon/image/common/close.gif" alt="close" onClick="'+this.instanceName+'.close(\''+_windowName+'\');"  style="cursor:pointer;" /></div>\n';
		        s +='      <div class="vtit">'+ this.TitleName+'</div>\n';						
	            s +='    </td>\n';
	            s +='    <td class="vpt3" width="10"><img src="/hantaCommon/image/product/vtopr.gif" alt="." /></td>\n';
                s +='  </tr>\n';
                s +='  <tr>\n';
	            s +='   <td class="vpc1"></td>\n';
	            s +='   <td class="vpc2">\n';
	            s += '		<table width="10" cellpadding="0" cellspacing="0" border="0" style="\n';
		        s += '		">\n';
		        s += '			<tr>\n';
		        s += '				<td>\n';
		        s += '				<div id="'+ids.titleAreaBlurCover+'"></div>\n';
		        s += '				<table id="'+ids.titleArea+'" width="100%" cellpadding="0" cellspacing="0" border="0">\n';
		        s += '					<tr>\n';
		        s += '						<td valign="top" width="100%" height="25" style="display:none;">\n';
		        s += '							<div id="'+ids.imageTitleArea+'" style="display:none;">\n';
		        s += '								<div style="position:absolute;cursor:move;display:none;"><table width="100%" height="25" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table></div>\n';
		        s += '								<div style="padding-right:30px;display:none;"><img id="'+ids.imageTitle+'" src="/img/common/trans.gif" onError="this.style.display=\'none\'"></div>\n';
		        s += '							</div>\n';
		        s += '							<div id="'+ids.textTitleArea+'" style="display:none;">\n';
		        s += '								<div id="'+ids.textTitle+'" style="padding:5px 30px 0 16px;display:none;font-size:'+((document.all)?"10":"13")+'px;color:#FFFFFF;font-weight:bold;"></div>\n';
		        s += '							</div>\n';
		        s += '						</td>\n';
//		        s += '						<td valign="top" width="1" align="right">\n';
//		        s += '							<div style="position:absolute;">\n';
//		        s += '								<div style="position:relative;left:-25px;top:3px;"><img onClick="'+this.instanceName+'.close(\''+_windowName+'\');" style="cursor:pointer;" src="/img/common/etc/close01.gif" width="20" height="19" border="0"></div>\n';
//		        s += '							</div>\n';
//		        s += '						</td>\n';
		        s += '					</tr>\n';
		        s += '				</table>\n';
		        s += '				</td>\n';
		        s += '			</tr>\n';
		        s += '			<tr>\n';
		        s += '				<td style="padding:0px;">\n';
		        s += '				<table id="'+ids.contentsAreaBlurCover+'" style="position:absolute;display:none;" width="'+options.width+'" height="'+options.height+'" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table>\n';
		        s += '				<table id="'+ids.contentsAreaCover+'" style="position:absolute;display:none;" width="'+options.width+'" height="'+options.height+'" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr></table>\n';
		        s += '				<div id="'+ids.contentsArea+'">\n';
		        s += '					<div id="'+ids.loadingArea+'"><table width="'+options.width+'" height="'+options.height+'" cellpadding="0" cellspacing="0" border="0"><tr><td align="center"><img src="/hantaCommon/image/common/start_loading02.gif" width="75" height="75"></td></tr></table></div>\n';
		        s += '					<div id="'+ids.contentsFrameArea+'" style="display:none;"><iframe id="'+ids.contentsFrame+'" name="'+_windowName+'" '+this.ids.openerName+'="'+window.name+'" '+this.ids.isFirstChild+'="'+((this.workArea==self)?"true":"false")+'" style="width:'+options.width+'px;height:'+options.height+'px;" marginheight="0" marginwidth="0" frameborder="0" scrolling="'+options.scrollbars+'" src="about:blank"></iframe></div>\n';
		        s += '				</div>\n';
		        s += '				</td>\n';
		        s += '			</tr>\n';
		        s += '		</table>\n';
	            s +='   </td>\n';
	            s +='   <td class="vpc3"></td>\n';
                s +=' </tr>\n';
                s +=' <tr>\n';
	            s +='   <td class="vpb1"><img src="/hantaCommon/image/product/vbtml.gif" alt="." /></td>\n';
	            s +='   <td class="vpb2"></td>\n';
	            s +='   <td class="vpb3"><img src="/hantaCommon/image/product/vbtmr.gif" alt="." /></td>\n';
                s +=' </tr>\n';
                s +='</table>\n';
			var div = this.workArea.document.createElement("DIV");
			div.setAttribute("id",ids.window);
			div.style.position = "absolute";
			var posX = options.left;
			var posY = options.top;
			if (posX==null||posX=="") posX = this.getCenterX(options.width);
			if (posY==null||posY=="") posY = this.getCenterY(options.height);
			div.style.left = posX + "px";
			div.style.top = posY + "px";

			div.setAttribute("frameWidth",options.width);
			div.setAttribute("frameHeight",options.height);
			this.workArea.document.body.insertBefore(div,this.workArea.document.body.firstChild);
			div.innerHTML = s;
			this.windows.push(_windowName);
			
		}
	}
	
	this.getTargetWindowName = function(_target) {
		if (_target==null||_target==undefined) _target = "";
		if (_target.toLowerCase()=="_blank"||_target.toLowerCase()=="_top"||_target.toLowerCase()=="_parent") _target = "";
		if (_target.toLowerCase()=="_self"&&window.name.indexOf(this.groupName)!=0) _target = "";
		
		var windowName = "";
		if (_target.toLowerCase()=="_self") {
			windowName = window.name;
		} else if (_target!="") {
			windowName = this.groupName + "-" + _target;
		} else {
			windowName = this.groupName + "-Untitled" + this.workArea[this.instanceName].maxIndex++;
		}
		return windowName;
	}
	
	this.open = function(_url, _target, _options) {
		if (_url==null) _url = "";
		if (_url=="") {
			alert("No URL!");
			return;
		}

		
		var windowName = this.getTargetWindowName(_target);  
		this.writeBackgroundCover();
		this.writeWindowLayer(windowName, _options);
		var ids = this.getIds(windowName);
		this.$(ids.contentsFrame).src = _url;
		this.focusWindow(windowName);
	}
	
	this.submit = function(_form, _options) {
		var target = _form.target;
		var windowName = this.getTargetWindowName(target);
		this.writeBackgroundCover();
		this.writeWindowLayer(windowName, _options);
		_form.target = windowName;
		_form.submit();
		_form.target = target;
		this.focusWindow(windowName);
	}
	
	this.removeWindow = function(_windowName) {
		if (_windowName==null) _windowName = window.name;
		var windowName = _windowName;
		if (windowName.indexOf(this.groupName)==0) { 
			var ids = this.getIds(windowName);
			if (!this.$(ids.window).isNull) {
				$(ids.contentsFrame).src = "about:blank";
				this.workArea.document.body.removeChild(this.$(ids.window));
				this.windows.remove(windowName);
				var windows = this.windows.compact();
				if (windows.length==0) {
					this.removeBackgroundCover();
				} else {
					var maxZindexWondow = {zIndex:0, windowName:""};
					for (var i=0; i<windows.length; i++) {
						var zIndex = parseInt(this.$(this.getIds(windows[i]).window).getStyle("zIndex"));
						if (maxZindexWondow.zIndex<zIndex) {
							maxZindexWondow.zIndex = zIndex;
							maxZindexWondow.windowName = windows[i];
						}
					}
					if (maxZindexWondow.windowName!="") {
						this.focusWindow(maxZindexWondow.windowName);
					}
				}
			}
		}
	}
	
	this.close = function(_windowName) {
		if (_windowName==null) _windowName = window.name;
		var windowName = _windowName;
		if (windowName.indexOf(this.groupName)==0) {
			var ids = this.getIds(windowName);
			//this.$(ids.window).moveTo(this.$(ids.window).getW()*-1-100,this.$(ids.window).getY(),this.instanceName+".removeWindow(\""+windowName+"\")");
			this.$(ids.window).setStyle("width",this.$(ids.window).getW());
			this.$(ids.window).setStyle("height",this.$(ids.window).getH());
			this.$(ids.window).setStyle("overflow","hidden");
			this.$(ids.window).resizeTo(1,1,this.instanceName+".removeWindow(\""+windowName+"\")");
		}
	}
	
	this.setTitle = function(_title) {
		if (_title==null) _title = "";
		var windowName = window.name;
		if (windowName.indexOf(this.groupName)==0) {
			var ids = this.getIds(windowName);
			try {
				this.$(ids.textTitle).innerHTML = _title;
				this.$(ids.imageTitleArea).setStyle("display", false);
				this.$(ids.textTitleArea).setStyle("display", true);
			} catch(e) {
			
			}
		}
	}
	
	this.setTitleImage = function(_src, _bgColor) {
		if (_src==null) {
			var pathName = location.pathname;
			while(pathName.indexOf("//")>-1) {
				pathName = pathName.replace("//","/");
			}
			if (pathName.indexOf("/")==0) {
				pathName = pathName.substring(1,pathName.lastIndexOf("/"));
			}
			var depth = pathName.split("/");
			_src = "/img/common/kidow/title/" + depth.join("_") + ".gif";
		}
		var windowName = window.name;
		if (windowName.indexOf(this.groupName)==0) {
			var ids = this.getIds(windowName);
			try {
				if (_bgColor!=null) {
					this.setTitleBarBgColor(_bgColor);
				}
				this.$(ids.imageTitle).src = _src;
				this.$(ids.textTitleArea).setStyle("display", false);
				this.$(ids.imageTitleArea).setStyle("display", true);
			} catch(e) {
			
			}
		}
	}
	
	this.setTitleBarBgColor = function(_color) {
		var windowName = window.name;
		if (windowName.indexOf(this.groupName)==0) {
			var ids = this.getIds(windowName);
			try {
				this.$(ids.titleArea).setStyle("backgroundColor", _color);
			} catch(e) {
			
			}
		}
	}
	
	this.resizeTo = function(_width, _height) {
		var windowName = window.name;
		if (windowName.indexOf(this.groupName)==0) {
			this.initialize();
			var ids = this.getIds(windowName);
			if (_width==null&&_height==null) {
				_width = document.documentElement.scrollWidth;
				_height = document.documentElement.scrollHeight;
				//_width = $(document.body).getW();
				//_height = $(document.body).getH();
			}
			_width = this.getNewValue(this.$(ids.contentsFrame).getW(),_width);
			_height = this.getNewValue(this.$(ids.contentsFrame).getH(),_height);
			this.$(ids.window).setAttribute("contentsWidth",_width);
			this.$(ids.window).setAttribute("contentsHeight",_height);
			this.$(ids.contentsFrame).resizeTo(_width, _height);
			if (this.vars.useTitleAreaBlurCover) {
				this._setTitleAreaBlurCoverWidth(windowName);
			}
		}
	}
	
	this.moveTo = function(_left, _top) {
		var windowName = window.name;
		if (windowName.indexOf(this.groupName)==0) {
			this.initialize();
			var ids = this.getIds(windowName);
			_left = this.getNewValue(this.$(ids.window).getX(),_left);
			_top = this.getNewValue(this.$(ids.window).getY(),_top);
			this.$(ids.window).moveTo(_left, _top);
		}
	}
	
	this.moveToCenter = function(_windowName) {
		var windowName = (_windowName==null) ? window.name : _windowName;
		if (windowName.indexOf(this.groupName)==0) {
			this.initialize();
			var ids = this.getIds(windowName);
			var width = this.$(ids.window).getAttribute("contentsWidth");
			var height = this.$(ids.window).getAttribute("contentsHeight");
			this.$(ids.window).moveTo(this.getCenterX(width), this.getCenterY(height));
		}
	}
	
	this.initialize = function() {
		var windowName = window.name;
		if (windowName.indexOf(this.groupName)==0) {
			var ids = this.getIds(windowName);
			var openerName = this.$(ids.contentsFrame).getAttribute(this.ids.openerName);
			var isFirstChild = (this.$(ids.contentsFrame).getAttribute(this.ids.isFirstChild)=="true") ? true : false;
			if (isFirstChild) {
				this.opener = this.workArea;
			} else {
				try {
					this.opener = this.workArea.frames[openerName];
				} catch(e) {
					this.opener = null;
				}
			}
			try {
				this.$(ids.loadingArea).setStyle("display", false);
				this.$(ids.contentsFrameArea).setStyle("display", true);
			} catch(e) {
			
			}
		}
	}
	
	this.removeAlertBackgroundCover = function() {
		var div = $(this.ids.alertBackgroundCover);
		if (!div.isNull) document.body.removeChild(div);
		$E.removeAction(this.ids.alertBackgroundCover);
	}
	
	this.writeAlertBackgroundCover = function() {
		var cover = document.createElement("DIV");
		cover.setAttribute("id",this.ids.alertBackgroundCover);
		cover.style.position = "absolute";
		cover.style.zIndex = 9999;
		cover.style.width = "100%";
		cover.style.height = "100%";
		document.body.insertBefore(cover,document.body.firstChild);
		cover.innerHTML = '<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="center" id="'+this.ids.alertBackgroundCoverElement1+'"><table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr><td id="'+this.ids.alertBackgroundCoverElement2+'" style="width:'+document.documentElement.scrollWidth+'px;height:'+document.documentElement.scrollHeight+'px;"></td></tr></table></td></tr></table>';
		$E.addAction("onMouseDown", this.ids.alertBackgroundCover, this.instanceName+"._onMouseDownFromAlertBackground()");
	}
	
	this.focusAlert = function() {
		if (!$(this.ids.alertBoxArea3).isNull) {
			var focusCount = $(this.ids.alertBoxArea3).getAttribute("focusCount");
			if (focusCount==undefined) {
				$(this.ids.alertBoxArea3).setAttribute("focusCount","0");
				focusCount = 0;
			}
			focusCount = parseInt(focusCount);
			if (focusCount<=4) {
				if (focusCount%2==1) {
					$(this.ids.alertBoxArea3).setStyle("backgroundColor","#000000");
				} else {
					$(this.ids.alertBoxArea3).setStyle("backgroundColor","#FFFFFF");
				}
				$(this.ids.alertBoxArea3).setAttribute("focusCount",++focusCount);
				setTimeout(this.instanceName+".focusAlert()", 50);
			} else {
				$(this.ids.alertBoxArea3).setStyle("backgroundColor","#000000");
				$(this.ids.alertBoxArea3).setAttribute("focusCount","0");
			}
		}
	}
	
	this._onMouseDownFromAlertBackground = function() {
		var elementId = $E.getElement().id;
		if (elementId==this.ids.alertBackgroundCover||elementId==this.ids.alertBackgroundCoverElement1||elementId==this.ids.alertBackgroundCoverElement2) {
			this.focusAlert();
		}
	}
	
	this.alert = function(_message, _isAutoClose, _timeout,args) {
		this.removeAlert(); 
		//UpDate :  _x,_y filed Add
		var _x=this.$(args).getX();
		var _y=this.$(args).getY();
		this.writeAlertBackgroundCover();
		if (_message==null) _message = "";
		_isAutoClose = (_isAutoClose==true) ? true : false; 
		if (_timeout==null) _timeout = 5;
		var s = '';
		s += '<table id="'+this.ids.alertBoxArea2+'" style="visibility:hidden;" cellpadding="0" cellspacing="0" border="0">\n';
		s += '	<tr>\n';
		s += '		<td align="center">\n';
		s += '			<div id="'+this.ids.alertBoxArea3+'" style="background-color:#000000;">\n';
		s += '				<div style="padding:1px 1px 1px 1px;">\n';
		s += '					<div style="padding:1px 1px 1px 1px;background-color:#FFFFFF;">\n';
		s += '						<div id="'+this.ids.alertBoxArea4+'" style="background-color:#000000;">\n';
		s += '							<div style="color:#FFFFFF;padding:30px 15px 10px 15px;font-weight:bold;text-decoration:underline;">'+_message+'</div>\n';
		s += '							<div style="margin:0 20px 0 20px;padding:10px 0 15px 0;">\n';
		s += '								<table width="100" cellpadding="0" cellspacing="0" border="0"><tr><td align="center">\n';
		s += '								<table cellpadding="0" cellspacing="0" border="0"><tr><td onClick="'+this.instanceName+'.closeAlert();" style="color:#EEEEEE;cursor:pointer;padding:0 10px 0 10px;"><img src="/img/common/etc/close03.gif" width="9" height="9" align="absmiddle"> Close</td></tr></table>\n';
		s += '								</td></tr></table>\n';
		s += '							</div>\n';
		s += '						</div>\n';
		s += '					</div>\n';
		s += '				</div>\n';
		s += '			</div>\n';
		s += '		</td>\n';
		s += '	</tr>\n';
		s += '</table>\n';
		
		var div = document.createElement("DIV");
		div.setAttribute("id", this.ids.alertBoxArea1);
		div.style.position = "absolute";
		div.style.zIndex = 10000;
		div.style.left = "0px";
		div.style.top = "0px";
		document.body.appendChild(div);
		div.innerHTML = s;
		$(this.ids.alertBoxArea4).setStyle("width",$(this.ids.alertBoxArea4).getW());
		$(this.ids.alertBoxArea4).setStyle("height",$(this.ids.alertBoxArea4).getH());
		var area2Width = $(this.ids.alertBoxArea2).getW();
		var area2Height = $(this.ids.alertBoxArea2).getH();
		$(this.ids.alertBoxArea2).setStyle("width",area2Width);
		$(this.ids.alertBoxArea2).setStyle("height",area2Height); 
		var maxWidth = $(this.ids.alertBoxArea3).getW();
		var maxHeight = $(this.ids.alertBoxArea3).getH();
		$(this.ids.alertBoxArea3).setStyle("width",1);
		$(this.ids.alertBoxArea3).setStyle("height",1);
		$(this.ids.alertBoxArea3).setStyle("overflow", "hidden");
		var targetX = (_x==null||""+parseInt(_x)=="NaN") ? this.getCenterX(area2Width,window) : parseInt(_x);
		var targetY = (_y==null||""+parseInt(_y)=="NaN") ? this.getCenterY(area2Height,window) : parseInt(_y);
		if (targetX+area2Width>document.body.scrollWidth) targetX = this.getCenterX(area2Width,window);
		if (targetY+area2Height>document.body.scrollHeight) targetY = this.getCenterY(area2Height,window);
		
		if (targetX+area2Width>document.body.scrollWidth) targetX = 0;
		if (targetY+area2Height>document.body.scrollHeight) targetY = 0;

		//UpDate :  targetX-->_x,targetY-->_y
		$(this.ids.alertBoxArea1).setStyle("left",_x);
		$(this.ids.alertBoxArea1).setStyle("top",_y);
		$(this.ids.alertBoxArea2).setStyle("visibility","");
		$(this.ids.alertBoxArea3).resizeTo(maxWidth,maxHeight);
		if (_isAutoClose) {
			this.vars.alertTimer = setTimeout(this.instanceName+".closeAlert()",1000*_timeout);
		}
	}
	this.alert2 = function(_message, _isAutoClose, _timeout, _x, _y) {

		this.removeAlert();
		this.writeAlertBackgroundCover();
		if (_message==null) _message = "";
		_isAutoClose = (_isAutoClose==true) ? true : false; 
		if (_timeout==null) _timeout = 5;
		var s = '';
		s += '<table id="'+this.ids.alertBoxArea2+'" style="visibility:hidden;" cellpadding="0" cellspacing="0" border="0">\n';
		s += '	<tr>\n';
		s += '		<td align="center">\n';
		s += '			<div id="'+this.ids.alertBoxArea3+'" style="background-color:#000000;">\n';
		s += '				<div style="padding:1px 1px 1px 1px;">\n';
		s += '					<div style="padding:1px 1px 1px 1px;background-color:#FFFFFF;">\n';
		s += '						<div id="'+this.ids.alertBoxArea4+'" style="background-color:#000000;">\n';
		s += '							<div style="color:#FFFFFF;padding:30px 15px 10px 15px;font-weight:bold;text-decoration:underline;">'+_message+'</div>\n';
		s += '							<div style="margin:0 20px 0 20px;padding:10px 0 15px 0;">\n';
		s += '								<table width="100" cellpadding="0" cellspacing="0" border="0"><tr><td align="center">\n';
		s += '								<table cellpadding="0" cellspacing="0" border="0"><tr><td onClick="'+this.instanceName+'.closeAlert();" style="color:#EEEEEE;cursor:pointer;padding:0 10px 0 10px;"><img src="/img/common/etc/close03.gif" width="9" height="9" align="absmiddle"> Close</td></tr></table>\n';
		s += '								</td></tr></table>\n';
		s += '							</div>\n';
		s += '						</div>\n';
		s += '					</div>\n';
		s += '				</div>\n';
		s += '			</div>\n';
		s += '		</td>\n';
		s += '	</tr>\n';
		s += '</table>\n';
		
		var div = document.createElement("DIV");
		div.setAttribute("id", this.ids.alertBoxArea1);
		div.style.position = "absolute";
		div.style.zIndex = 10000;
		div.style.left = "0px";
		div.style.top = "0px";
		document.body.appendChild(div);
		div.innerHTML = s;
		$(this.ids.alertBoxArea4).setStyle("width",$(this.ids.alertBoxArea4).getW());
		$(this.ids.alertBoxArea4).setStyle("height",$(this.ids.alertBoxArea4).getH());
		var area2Width = $(this.ids.alertBoxArea2).getW();
		var area2Height = $(this.ids.alertBoxArea2).getH();
		$(this.ids.alertBoxArea2).setStyle("width",area2Width);
		$(this.ids.alertBoxArea2).setStyle("height",area2Height);
		var maxWidth = $(this.ids.alertBoxArea3).getW();
		var maxHeight = $(this.ids.alertBoxArea3).getH();
		$(this.ids.alertBoxArea3).setStyle("width",1);
		$(this.ids.alertBoxArea3).setStyle("height",1);
		$(this.ids.alertBoxArea3).setStyle("overflow", "hidden");
		var targetX = (_x==null||""+parseInt(_x)=="NaN") ? this.getCenterX(area2Width,window) : parseInt(_x);
		var targetY = (_y==null||""+parseInt(_y)=="NaN") ? this.getCenterY(area2Height,window) : parseInt(_y);
		if (targetX+area2Width>document.body.scrollWidth) targetX = this.getCenterX(area2Width,window);
		if (targetY+area2Height>document.body.scrollHeight) targetY = this.getCenterY(area2Height,window);
		if (targetX+area2Width>document.body.scrollWidth) targetX = 0;
		if (targetY+area2Height>document.body.scrollHeight) targetY = 0;
		$(this.ids.alertBoxArea1).setStyle("left",targetX);
		$(this.ids.alertBoxArea1).setStyle("top",targetY);
		$(this.ids.alertBoxArea2).setStyle("visibility","");
		$(this.ids.alertBoxArea3).resizeTo(maxWidth,maxHeight);
		if (_isAutoClose) {
			this.vars.alertTimer = setTimeout(this.instanceName+".closeAlert()",1000*_timeout);
		}
	}
	this.closeAlert = function() {
		try {
			clearTimeout(this.vars.alertTimer);
			$(this.ids.alertBoxArea3).resizeTo(1,1,this.instanceName+".removeAlert()");
		} catch(e) {
			
		}
	}
	
	this.removeAlert = function() {
		try {
			clearTimeout(this.vars.alertTimer);
			document.body.removeChild($(this.ids.alertBoxArea1));
		} catch(e) {
			
		}
		this.removeAlertBackgroundCover();
	}
}
var kidow = new Kidow("kidow");








