//-winbox.js------------------------------------------------------
function WinBoxGroup_add(obj){
	var l = this.group.length;
	this.group [l] = obj;
	obj.group = this;
}
function WinBoxGroup_create(obj, handle, title, locksize, hidetitle){
	var l = this.group.length;
	var id = obj + "_id_" + l;
	var hObj = obj + ".group" + "[" + l + "]";
	this.group [l] = new WindowBox (hObj, id, handle, title, locksize, hidetitle);
	this.group [l].group = this;
	return hObj;
}
function WinBoxGroup_resume(id){
/*
	var i, l = this.group.length;
	var obj;
	for (i=1; i<=l; i++){
		obj = this.group [i - 1];
		if (obj.isvisible && obj.id != id){
			this.refresh (obj);
			return;
		}
	}
*/
	var i, l = this.group.length, max = 0, pos = 0;
	var obj;
	
	for (i=1; i<=l; i++){
		obj = this.group [i - 1];
		if (obj.id != id && obj.isvisible){
			if (obj.activeBoxNum > max){
				max = obj.activeBoxNum;
				pos = i - 1;
			}
		}
	}
	if (max == 0 && pos == 0){
		this.activeBoxNum = 0;
	}
	this.refresh (this.group [pos]);
}
function WinBoxGroup_swap(obja, objb){
	var t = new obja;
	obja = objb;
	objb = t;
	return;
}
function WinBoxGroup_refresh(obj){
	var i, l = this.group.length;
	var box, t;
	for (i=1; i<=l; i++){
		if (this.group [i - 1].id == obj.id){
			obj.activeBoxNum = this.activeBoxNum;
			this.activeBoxNum++;
		}else{
			box = document.getElementById (this.group [i - 1].id);
			box.style.zIndex = 100;
			box.style.filter="alpha(enabled=1, opacity=60)";
		}
	}
	box = document.getElementById (obj.id);
	box.style.zIndex = 1000;
	box.style.filter="alpha(enabled=1, opacity=95)";
	return;
}
function WinBoxGroup(){
	this.activeBoxNum = 0;
	this.group = new Array ();
	this.add = WinBoxGroup_add;
	this.create = WinBoxGroup_create;
	this.refresh = WinBoxGroup_refresh;
	this.resume = WinBoxGroup_resume;
	this.swap = WinBoxGroup_swap;
}
function WindowBox_Minimize(body, resizeVid, resizeHid, obj, box){
	if (body.style.display=='none'){
		box.style.height = box.bakh;
		obj.innerHTML='_';
		body.style.display='';
		resizeVid.style.display='';
		resizeHid.style.display='';
	}else{
		box.bakh = box.style.height;
		box.style.height = "25px";
		obj.innerHTML='+';
		body.style.display='none';
		resizeVid.style.display='none';
		resizeHid.style.display='none';
	}
}
function WindowBox_Maximize(boxid, obj){
	if (boxid.style.width!='100%'){
		obj.innerHTML='-';
		boxid.posx=boxid.style.left;
		boxid.posy=boxid.style.top;
		boxid.normalwidth = boxid.style.width;
		boxid.normalheight = boxid.style.height;
		boxid.style.width='100%';
		boxid.style.height='100%';
		boxid.style.left=1;
		boxid.style.top=1;
	}else{
		obj.innerHTML='O';
		boxid.style.width=boxid.normalwidth;
		boxid.style.height=boxid.normalheight;
		boxid.style.left=boxid.posx;
		boxid.style.top=boxid.posy;
	}
}
function WindowBox_Close(disablescript){
	var box = document.getElementById (this.id);
//	var box = this.obox;//document.getElementById (this.id);
	box.style.display="none";
	this.isvisible = false;
	this.setDeactive ();
	box.innerHTML = "";
	if (!disablescript){
		eval (this.onclose);
	}
//	eval ("delete " + this.objName);
	return false;
}
function WindowBox_doShow(skipexec){
	this.sethtml ();
	if (!skipexec){
		eval (this.onshow);
	}
	return true;
}
function WindowBox_Hide(){
//	var box = this.obox;//document.getElementById (this.id);
	var box = document.getElementById (this.id);
	box.style.display = "none";
	this.isvisible = false;
	this.setDeactive ();
}
function WindowBox_SetTitle(text, setstyle){
	var obj;
	if (setstyle){
		obj = document.getElementById (this.titleboxid);
	}else{
		obj = document.getElementById (this.titlefontid);
	}
	obj.innerHTML = text;
}
function WindowBox_Sethtml(html){
	var contentbox, contentstr;
	var box = document.getElementById (this.id);
	var str = "<font style='color=gray; font-size:12px; font-family:courier new'>&nbsp;Loading ...</font>";
//	var box = this.obox;
	box.innerHTML = this.html;
	if (this.contentBoxId == "[empty]"){
		this.contentBoxId = this.id + "_content";
		if (this.hidetitle){
	 		contentbox = document.getElementById (this.bodyid);
	 	}else{
	 		contentbox = document.getElementById (this.bodycellid);
	 	}
		if (html){
			contentbox.innerHTML = html;
		}else{
			contentbox.innerHTML = str;
		}
		str = "<div id='" + this.contentBoxId + "' style='display:none;visibility:hidden;'>" + str + "</div>";
		window.setTimeout ("document.body.innerHTML += \"" + str + "\";", 1, "javascript");
	}else{
		var htmlbox = document.getElementById (this.contentBoxId);
		if (this.hidetitle){
	 		contentbox = document.getElementById (this.bodyid);
	 	}else{
	 		contentbox = document.getElementById (this.bodycellid);
	 	}
		if (html){
			contentstr = unescape (html);
		}else{
			contentstr = unescape (htmlbox.innerHTML);
		}
		contentstr = contentstr.change ("$_obj_$", this.objName);
		contentstr = contentstr.change ("$_boxid_$", this.id);
		contentstr = contentstr.change ("$_bodyid_$", this.bodyid);
		contentbox.innerHTML = contentstr;
//		alert (contentbox.id + "," + contentbox.outerHTML);
	}
}
function WindowBox_SetDeactive(){
	if (this.group != "[empty]"){
		this.group.resume (this.id);
		this.isactive = false;
	}
}
function WindowBox_Resize(mode, ax, ay, bx, by){
	var box = document.getElementById (this.id);
	if (mode == "accurate"){
		if (ax && ay && bx && by){
			box.style.left = ax;
			box.style.top = ay;
			box.style.right = bx;
			box.style.bottom = by;
		}
	}else if (mode == "size"){
		if (ax && ay){
			box.style.width = ax;
			box.style.height = ay;
		}
	}else if (mode == "sizepos"){
		if (ax && ay && bx && by){
			box.style.width = bx;
			box.style.height = by;
			box.style.left = ax;
			box.style.top = ay;
		}
	}
	return;
}
function WindowBox_Show(mode, ax, ay, bx, by){
	var wboxStyle = new Property ("WindowBox");
	var wboxTitleStyle = new Property ("WindowBoxTitleBoxStyle");
	var wboxResizeStyle = new Property ("WindowBoxResizeStyle");
	var wboxIconStyle = new Property ("WindowBoxIconStyle");
	var html = String (CodeWindowBox.value);
	var box = document.getElementById (this.id);
	if (this.locksize){
		wboxResizeStyle.set ("display", "none");
	}
	if (this.hidetitle){
		wboxTitleStyle.set ("display", "none");
	}
	if (!this.disableIconNew){
		wboxIconStyle.set ("display", "");
	}else{
		wboxIconStyle.set ("display", "none");
	}
	html = html.change ("[boxstyle]", wboxStyle.toString ());
	html = html.change ("[boxid]", this.id);
	html = html.change ("[body]", this.bodyid);
	html = html.change ("[bodycell]", this.bodycellid);
	html = html.change ("[obj]", this.objName);
	html = html.change ("[handle]", this.handle);
	html = html.change ("[titlecell]", this.titlecellid);
	html = html.change ("[titlestr]", this.title);
	html = html.change ("[titlecolor]", this.titlecolor);
	html = html.change ("[titlebox]", this.titleboxid);
	html = html.change ("[titleboxstyle]", wboxTitleStyle.toString ());
	html = html.change ("[iconnewstyle]", wboxIconStyle.toString ());
	html = html.change ("[onclosefunc]", this.onclose);
	html = html.change ("[oncreatefunc]", this.oncreate);
	html = html.change ("[onshowfunc]", this.onshow);
	html = html.change ("[onhidefunc]", this.onhide);
	html = html.change ("[titlefont]", this.titlefontid);
	html = html.change ("[resizeCid]", this.id + "resize");
	html = html.change ("[resizeVid]", this.id + "resizeV");
	html = html.change ("[resizeHid]", this.id + "resizeH");
	html = html.change ("[resizeV]", wboxResizeStyle.toString ());
	wboxResizeStyle.set ("width", "3");
	wboxResizeStyle.set ("height", "20");
	html = html.change ("[resizeH]", wboxResizeStyle.toString ());
	wboxResizeStyle.set ("width", "20");
	wboxResizeStyle.set ("height", "20");
	wboxResizeStyle.set ("background", "");
	html = html.change ("[resizeC]", wboxResizeStyle.toString ());
	this.html = html;
//	document.write (this.html);
//	return;
	if (mode != 1){
		this.doshow ();
	}else{
		this.doshow (true);
	}
	
	this.resize (mode, ax, ay, bx, by);
	box.style.display = "";
	this.setActive();
	this.isvisible = true;
	if (mode != 1){
		eval (this.onshown);
	}
}
function WindowBox_SetContentSource(tagid){
	var obj = document.getElementById (tagid);
	this.contentBoxId = tagid;
	obj.innerHTML = escape (obj.innerHTML);
}
function WindowBox_SetActive(){
	if (this.group != "[empty]"){
//		alert ();
		this.setDeactive ();
		this.group.refresh (this);
		this.isactive = true;
	}
}
function WindowBox(obj, id, handleName, title, locksize, hidetitle){
	var wboxStyle = new Property ("WindowBox");
	var html = String (CodeWindowBox.value);

	this.id = id;
	this.objName = obj;
	this.bodyid = id + "_body";
	this.bodycellid = id + "_bodycell";
	this.title = title;
	this.titlefontid = id + "_titlefont";
	this.titlecolor="blue";
	this.titleboxid = id + "_titlebox";
	this.titlecellid = id + "_titlecell";
	this.newWindowid = id + "_newcell";
	this.contentBoxId = "[empty]";
	this.handle = handleName;
	
	if (locksize){
		this.locksize = true;
	}else{
		this.locksize = false;
	}
	if (hidetitle){
		this.hidetitle = true;
	}else{
		this.hidetitle = false;
	}
	this.isactive = false;
	this.isvisible = false;
	this.disableIconNew = true;
	this.group = "[empty]";
	this.activeBoxNum = 0;
	
	html = html.change ("[boxid]", this.id);
	html = html.change ("[body]", this.bodyid);
	html = html.change ("[bodycell]", this.bodycellid);
	html = html.change ("[obj]", this.objName);
	html = html.change ("[handle]", this.handle);
	html = html.change ("[titlecell]", this.titlecellid);
	html = html.change ("[titlestr]", this.title);
	html = html.change ("[titlecolor]", this.titlecolor);
	html = html.change ("[titlebox]", this.titleboxid);
	html = html.change ("[onclosefunc]", this.onclose);
	html = html.change ("[oncreatefunc]", this.oncreate);
	html = html.change ("[onshowfunc]", this.onshow);
	html = html.change ("[onhidefunc]", this.onhide);
	html = html.change ("[titlefont]", this.titlefontid);
	html = html.change ("[resizeVid]", this.id + "resizeV");
	html = html.change ("[resizeHid]", this.id + "resizeH");
	this.html = html;

	this.close = WindowBox_Close;
	this.hide = WindowBox_Hide;
	this.onclose = "";
	this.show = WindowBox_Show;
	this.doshow = WindowBox_doShow;
	this.onshow = "";
	this.onshown = "";
	this.resize = WindowBox_Resize;
	this.setActive = WindowBox_SetActive;
	this.sethtml = WindowBox_Sethtml;
	this.setTitle = WindowBox_SetTitle;
	this.setContent = WindowBox_SetContentSource;
	this.setDeactive = WindowBox_SetDeactive;		
	document.body.innerHTML = document.body.innerHTML + "<div bakh=0 style=\""+wboxStyle.toString ()+"\" dragIndex=1 id=\""+this.id+"\" mouseout=0>" + this.html + "</div>";
	this.obox = document.getElementById (this.id);
//	CodeWindowBox_output.value = this.html;
}
function StartWindowBoxControl(){
	document.body.innerHTML += unescape ("%3Ctextarea%20id%3D%22CodeWindowBox%22%20style%3D%22display%3Anone%3B%22%20rows%3D%2226%22%20cols%3D%2239%22%3E%0D%0A%3Cdiv%20onmousedown%3D%22%5Bobj%5D.setActive%28%29%3B%22%3E%0D%0A%20%20%3Ctable%20onselectstart%3D%22return%20false%3B%22%20width%3D100%25%20height%3D100%25%3E%0D%0A%20%20%3Ctr%20id%3D%22%5Btitlebox%5D%22%20style%3D%22%5Btitleboxstyle%5D%22%20ondblclick%3D%22WindowBox_Minimize%28%5Bbody%5D%2C%5BresizeVid%5D%2C%5BresizeHid%5D%2C%20%5Bboxid%5D_mincell%2C%20%5Bboxid%5D%29%3B%22%3E%0D%0A%20%20%20%3Ctd%20width%3D10%3E%3C/td%3E%0D%0A%20%20%20%3Ctd%20id%3D%22%5Btitlecell%5D%22%20style%3D%22width%3A100%25%3Bheight%3A100%25%3B%22%20onmouseout%3D%22%5Bboxid%5D.mouseout%3D1%3B%22%20onmouseover%3D%22this.style.cursor%3D%27move%27%22%20onmouseup%3D%22%5Bboxid%5D.mouseout%3D1%3B%20%5Bhandle%5D.handleMouseDrop%20%28%29%3B%22%20onmousedown%3D%22%5Bboxid%5D.mouseout%3D0%3B%20%5Bhandle%5D.targetId%3D%27%5Bboxid%5D%27%3B%5Bhandle%5D.type%3D%27move%27%3B%5Bhandle%5D.dragDx%3Devent.clientX%20-%20parseInt%20%28%5Bboxid%5D.style.left%29%3B%5Bhandle%5D.dragDy%3Devent.clientY%20-%20parseInt%20%28%5Bboxid%5D.style.top%29%3B%22%20align%3Dleft%3E%3Cfont%20style%3D%22font-family%3A%u5B8B%u4F53%3B%20font-size%3A12px%3B%20color%3D%5Btitlecolor%5D%3B%22%20id%3D%22%5Btitlefont%5D%22%3E%5Btitlestr%5D%3C/font%3E%3C/td%3E%0D%0A%20%20%20%3Ctd%20id%3D%22%5Bboxid%5D_newcell%22%20style%3D%22%5Biconnewstyle%5D%22%20align%3Dright%20width%3D20%20onmouseover%3D%22this.style.cursor%3D%27hand%27%3B%22%20onmousedown%3D%22win_%5Bboxid%5D%20%3D%20window.open%20%28%27about%3Ablank%27%29%3Bwin_%5Bboxid%5D.document.write%20%28%27%3Ctitle%3E%5Btitlestr%5D%3C/title%3E%27+%5Bbody%5D.innerHTML%29%3B%5Bobj%5D.close%20%28%29%3B%22%3E*%3C/td%3E%0D%0A%20%20%20%3Ctd%20id%3D%22%5Bboxid%5D_mincell%22%20style%3D%22font-weight%3Abolder%3B%20font-family%3Acourier%20new%3B%20font-size%3A16px%3B%20color%3Dblue%3B%22%20align%3Dright%20width%3D20%20onmouseover%3D%22this.style.cursor%3D%27hand%27%3B%22%20onmousedown%3D%22WindowBox_Minimize%20%28%5Bbody%5D%2C%5BresizeVid%5D%2C%5BresizeHid%5D%2C%20this%2C%20%5Bboxid%5D%29%3B%22%3E_%3C/td%3E%0D%0A%20%20%20%3Ctd%20id%3D%22%5Bboxid%5D_maxcell%22%20style%3D%22font-weight%3Abolder%3B%20font-family%3Acourier%20new%3B%20font-size%3A16px%3B%20color%3Dblue%3B%22%20align%3Dright%20width%3D20%20onmouseover%3D%22this.style.cursor%3D%27hand%27%3B%22%20onmousedown%3D%22WindowBox_Maximize%20%28%5Bboxid%5D%2C%20this%29%3B%22%3EO%3C/td%3E%0D%0A%20%20%20%3Ctd%20style%3D%22font-weight%3Abolder%3B%20font-family%3Acourier%20new%3B%20font-size%3A12px%3B%20color%3Dblue%3B%22%20align%3Dright%20width%3D20%20onmouseover%3D%22this.style.cursor%3D%27hand%27%3B%22%20onmousedown%3D%22%5Bobj%5D.close%28%29%3B%22%3EX%3C/td%3E%0D%0A%20%20%20%3Ctd%20width%3D10%3E%3C/td%3E%0D%0A%20%20%3C/tr%3E%0D%0A%20%20%3C/table%3E%0D%0A%20%3Cdiv%20id%3D%22%5Bbody%5D%22%20style%3D%22overflow%3Aauto%3Bposition%3Aabsolute%3Bleft%3A0px%3Btop%3A0px%3Bwidth%3A100%25%3Bheight%3A100%25%3Bbackground%3Awhite%3Bz-index%3A102%3Bborder%3A1px%20dotted%20%23C0C0C0%3B%20%22%3E%0D%0A%20%3Ctable%20border%3D%220%22%20cellpadding%3D%220%22%20style%3D%22border-collapse%3A%20collapse%22%20width%3D%22100%25%22%20height%3D%22100%25%22%3E%0D%0A%20%20%3Ctr%20height%3D25%3E%3Ctd%3E%3C/td%3E%3C/tr%3E%0D%0A%20%20%3Ctr%3E%3Ctd%20id%3D%22%5Bbodycell%5D%22%20valign%3Dtop%3E%3C/td%3E%3C/tr%3E%0D%0A%20%3C/table%3E%0D%0A%20%3C/div%3E%0D%0A%20%3Cdiv%20id%3D%22%5BresizeVid%5D%22%20style%3D%22%5BresizeV%5D%22%20onmouseout%3D%22%5Bboxid%5D.mouseout%3D1%3B%22%20onmouseover%3D%22this.style.cursor%3D%27nw-resize%27%22%20onmouseup%3D%22%5Bboxid%5D.mouseout%3D1%3B%20%5Bhandle%5D.handleMouseDrop%28%29%3B%22%20onmousedown%3D%22%5Bboxid%5D.mouseout%3D0%3B%20%5Bhandle%5D.targetId%3D%27%5Bboxid%5D%27%3B%5Bhandle%5D.type%3D%27resize%27%3B%5Bhandle%5D.dragDx%3D%5Bboxid%5D.style.left%3B%5Bhandle%5D.dragDy%3D%5Bboxid%5D.style.top%3B%22%3E%3C/div%3E%0D%0A%20%3Cdiv%20id%3D%22%5BresizeCid%5D%22%20style%3D%22%5BresizeC%5D%22%20onmouseout%3D%22%5Bboxid%5D.mouseout%3D1%3B%22%20onmouseover%3D%22this.style.cursor%3D%27nw-resize%27%22%20onmouseup%3D%22%5Bboxid%5D.mouseout%3D1%3B%20%5Bhandle%5D.handleMouseDrop%28%29%3B%22%20onmousedown%3D%22%5Bboxid%5D.mouseout%3D0%3B%20%5Bhandle%5D.targetId%3D%27%5Bboxid%5D%27%3B%5Bhandle%5D.type%3D%27resize%27%3B%5Bhandle%5D.dragDx%3D%5Bboxid%5D.style.left%3B%5Bhandle%5D.dragDy%3D%5Bboxid%5D.style.top%3B%22%3E%3C/div%3E%0D%0A%20%3Cdiv%20id%3D%22%5BresizeHid%5D%22%20style%3D%22%5BresizeH%5D%22%20onmouseout%3D%22%5Bboxid%5D.mouseout%3D1%3B%22%20onmouseover%3D%22this.style.cursor%3D%27nw-resize%27%22%20onmouseup%3D%22%5Bboxid%5D.mouseout%3D1%3B%20%5Bhandle%5D.handleMouseDrop%28%29%3B%22%20onmousedown%3D%22%5Bboxid%5D.mouseout%3D0%3B%20%5Bhandle%5D.targetId%3D%27%5Bboxid%5D%27%3B%5Bhandle%5D.type%3D%27resize%27%3B%5Bhandle%5D.dragDx%3D%5Bboxid%5D.style.left%3B%5Bhandle%5D.dragDy%3D%5Bboxid%5D.style.top%3B%22%3E%3C/div%3E%0D%0A%3C/div%3E%0D%0A%3C/textarea%3E%20");
}
//-----------------------------------------------------------------