//初始化;
function bulid(id,w,h,l,t,tit,msg,url)
{
//风格
var style=document.getElementById('manner').value;
if (style=="")style="style1";
var color=document.getElementById('color').value;
if(color=="")color='#ffffff';
//窗体
var str = ""
+ "<table id='mywin" + id + "'  cellpadding='0' cellspacing='0' style='position:absolute; left:" + l + "; top:" + t + "; width:" + w + "; height:" + h + "; FONT-SIZE:12; FONT-FAMILY:宋体;' onmousedown=Focus(this)>"

+ "<tr onmousedown=Down(this) onmousemove=Remove(this) onmouseup=Up(this)>"
+ "<td width=7 nowrap><img src='style/"+style+"/win_left.gif'></td>"
+ "<td nowarp background='style/"+style+"/win_bg.gif' style='font-weight:bolder; ' ondblclick='max(\"mywin"+id+"\")'>"
//标题栏
+ "<table cellpadding='0' cellspacing='0' border='0' style='table-layout: fixed;' width='100%'> "
+ " <tr> "
+ " <td title='"+name+"' style='overflow: hidden; white-space: nowrap; text-overflow: ellipsis; '>"  
+ "<img align='absmiddle' src='os/images/ie.gif'>"
+ "<span id='popwin"+tabCount+"' style='color:" + color + "'>" + tit +"</span>"
+ " </td> "
+ " </tr> "
+ "</table> "
//标题栏
+ "</td>"
+ "<td nowrap background='style/"+style+"/win_bg.gif' width=150  align='right' >"

+ "<img border=0 onmouseout=this.src='style/"+style+"/win_min.gif' onmouseover=this.src='style/"+style+"/win_min_over.gif' src='style/"+style+"/win_min.gif' onclick='min(\"mywin"+id+"\")'>"
+ "<img border=0 onmouseout=this.src='style/"+style+"/win_max.gif' onmouseover=this.src='style/"+style+"/win_max_over.gif' src='style/"+style+"/win_max.gif' onclick='max(\"mywin"+id+"\")'>"
+ "<img border=0 onmouseout=this.src='style/"+style+"/win_close.gif' onmouseover=this.src='style/"+style+"/win_close_over.gif' src='style/"+style+"/win_close.gif' onclick='closeUp(\"mywin"+id+"\");'>"



+ "</td>"
+ "<td width=7 nowrap><img src='style/"+style+"/win_right.gif'></td>"
+ "</tr>"
+ "<tr>"
+ "<td background='style/"+style+"/win_border_bg.gif' nowrap colspan='4' valign='top' style='height:100%; padding-top:0; padding-left:4; padding-right:4; padding-bottom:0'>"
+ "<IFRAME id='frame"+id+"' frameBorder=0 scrolling=auto src='' width='100%' height='100%'></IFRAME>"
+ "</td>"
+ "</tr>"
+ "<tr>"
+ "<td nowrap background='style/"+style+"/win_border_bg.gif' align='right' colspan='4'  style='cursor:se-resize; padding-top:0; padding-left:4; padding-right:4; padding-bottom:0' onmousedown=Down(this) onmousemove=Resize(this) onmouseup=Up(this)>"
//底边
+ "<table cellpadding='0' cellspacing='0' width=100% background='style/"+style+"/win_bottom_bg.gif'>"
+ "<tr><td align='right' >"
+ "<img  src='style/"+style+"/win_bottom_resize.gif'></td>"
+ "</tr></table>"
//底边结束
+ "</td>"
+ "</tr>"
+ "<tr>"
+ "<td height=4 colspan='4' background='style/"+style+"/win_border_hbg.gif'></td>"
+ "</tr>"
+ "</table>"

//写入窗体
document.body.insertAdjacentHTML("beforeEnd",str);

try{
//写入框架和获得焦点
var fid="frame" + id;
if(url!="") document.getElementById(fid).src=url;//网址
if(msg!="") frames(fid).document.writeln(msg);//文字
document.getElementById(fid).focus(); //获得焦点

//最前
var obj=document.getElementById("mywin" + id);
zmax = zmax +10; //最高层（变量）每次点击加10，以保证最高
obj.style.zIndex = zmax; //将当前层置顶，当前层 = 最高层
}catch(err){alert("生成窗体："+err.message)}

}


//删除窗口
function closeUp(obj){
	try{
		//删除窗口
		curobj=document.getElementById(obj);
		curobj.parentNode.removeChild(curobj);

		curobj=document.getElementById('taskTools');
		maxcell=curobj.rows(0).cells.length;
		name=obj.replace("mywin","tab")

		//删除指定的标签名
		for(i=0;i<maxcell;i++){
			tab=curobj.rows(0).cells(i).getAttribute('name');
			if(tab==name)curobj.rows(0).deleteCell(i);
			maxcell=curobj.rows(0).cells.length;
		}
		
	}catch(err){alert(err.message)}

}




//最大化窗口
function max(obj){
//获得实体
curobj = document.getElementById(obj); 
//取得原有高度
ww=curobj.style.pixelWidth;
hh=curobj.style.pixelHeight;
//屏幕高宽
w=document.body.clientWidth;
h=document.body.clientHeight;
t=30;
if (ww==w){
	//缩小
	w1=700;
	h1=500;
	curobj.style.pixelWidth=w1;
	curobj.style.pixelHeight=h1;
	curobj.style.left = (w-w1)/2;
	curobj.style.top = (h-h1)/2;
}else{
	//放大
	curobj.style.pixelWidth=w;
	curobj.style.pixelHeight=h-t;
	curobj.style.left = 0;
	curobj.style.top =t;
}
}


//最小化;

var curobj;
var w;
var s;
var ww;
var hh;
function min(obj){
//获得实体
curobj = document.getElementById(obj); 
if(curobj.style.display!='none'){
	curobj.style.display='none';
}else{alert("已经最小!")}
//取得原有高度
//ww=curobj.style.pixelWidth;
//hh=curobj.style.pixelHeight;
//高宽比例
//s=hh/ww;
//tomin();
}

function tomin(){
w=curobj.style.pixelWidth-200;
curobj.style.pixelWidth=w ;
curobj.style.pixelHeight=w*s ;
//逐渐缩小
if(w>0){setTimeout('tomin()',10)}
else{
curobj.style.display='none'
//设回原有高度
curobj.style.pixelWidth=ww ;
curobj.style.pixelHeight=hh ;
}
}

//显示隐藏窗口
function ShowHide(obj){
  try{
   //alert("max"+obj);
   document.getElementById(obj).style.display = "";
   zmax = zmax +10; //最高层（变量）每次点击加10，以保证最高
   document.getElementById(obj).style.zIndex = zmax; //将当前层置顶，当前层 = 最高层
 } catch(err) {
   //document.writeln("Error name: " + err.name + "");
    //document.writeln("Error message: " + err.message);
   alert("Error message: " + err.message);
 }

}


//删除窗口
function deleteWin(obj){
curobj=document.getElementById(obj);
curobj.parentNode.removeChild(curobj);
}


/**
* 初始化
*/
move = null; //移动标记
wmin = 100; //最小的窗口为100x100
zmax = 10000; //记录当前的最高层
ssize = 4; //阴影宽度

/**
* 父窗口内按下鼠标时，得到相关的值
*/
function Down(obj)
{

//document.getElementById('wo').innerHTML="<table id='mywin1' value='141' cellpadding='4' cellspacing='0' style='position:absolute; left:expression(mdiv.offsetLeft+100); top:expression(mdiv.offsetTop+100); width:100; height:100; z-index:100; TABLE-LAYOUT:fixed; WORD-BREAK:break-all; border:1 solid #BED9EB; background-color:#ffffff; FONT-SIZE:12; FONT-FAMILY:宋体;' > <tr style='display:none'><td></td><td style='width:45;'></td><td style='width:10;'></td></tr> <!-- 固定单元格宽度 --><tr style='cursor:default; background-color:#BED9EB;' onmousedown=Down(this) onmousemove=Remove(this) onmouseup=Up(this)><td nowrap style='font-weight:bolder; color:#3C8DC4; filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#FFFFFF, endColorStr=#BED9EB, gradientType=0);'>er4e </td><td nowrap colspan='2' align='right' style='filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#FFFFFF, endColorStr=#BED9EB, gradientType=0);'></td></tr><tr><td colspan='3' valign='top' style='height:100%; padding-top:10; padding-left:10; padding-right:10; padding-bottom:0'>内容 </td></tr><tr><td colspan='2'><td style='cursor:se-resize; height:10; background-color:#BED9EB; filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#BED9EB, endColorStr=#FFFFFF, gradientType=1);' onmousedown=Down(this) onmousemove=Resize(this) onmouseup=Up(this)></td></tr></table>";
move = 1;
obj.x = event.x; //鼠标起始位置
obj.y = event.y;
obj.l = obj.offsetParent.offsetLeft; //父元素当前位置
obj.t = obj.offsetParent.offsetTop;
obj.w = obj.offsetParent.offsetWidth;
obj.h = obj.offsetParent.offsetHeight;
obj.ml = mdiv.offsetLeft; //最大的层
obj.mt = mdiv.offsetTop;
obj.mw = mdiv.offsetWidth;
obj.mh = mdiv.offsetHeight;
Shadow(obj) //重画阴影
obj.setCapture(); //得到鼠标
}

/**
* 标题栏托动窗口
* 重要说明：所有窗口的left, top是mdiv的相对位置；width, height是窗口本身的值
*/
function Remove(obj)
{
if(move != null)
{
  cur = event.x - obj.x + obj.l; //父元素新位置 = 鼠标移过的位置 + 父元素原位置
  cur = Math.max(cur, obj.ml); //父元素的最小位置
  obj.offsetParent.style.left = Math.min(cur, obj.ml + obj.mw - obj.w); //父元素的最大位置

  cur = event.y - obj.y + obj.t;
  cur = Math.max(cur, obj.mt);
  obj.offsetParent.style.top = Math.min(cur, obj.mt + obj.mh - obj.h);

  Shadow(obj) //重画阴影
  }
}

/**
* 状态栏改变窗口大小
*/
function Resize(obj)
{
if(move != null)
{
  cur = event.x - obj.x + obj.w; //父元素新宽度 = 鼠标移过的位置 + 父元素原宽度
  cur = Math.max(cur, obj.mw / 10); //父元素的最小宽度
  obj.offsetParent.style.width = Math.min(cur, obj.mw - (obj.l - obj.ml)); //父元素的最大宽度

  cur = event.y - obj.y + obj.h;
  cur = Math.max(cur, obj.mw / 10);
  obj.offsetParent.style.height = Math.min(cur, obj.mh - (obj.t - obj.mt));

  Shadow(obj) //重画阴影
}
}

/**
* 放开鼠标时，清理不用的东西
*/
function Up(obj)
{
move = null;
sdiv.style.visibility = 'hidden'; //隐藏阴影
obj.releaseCapture(); //释放鼠标
}

/**
* 父窗口按下鼠标时，将当前层置顶
*/
function Focus(obj)
{
zmax = zmax +10; //最高层（变量）每次点击加10，以保证最高
obj.style.zIndex = zmax; //将当前层置顶，当前层 = 最高层
sdiv.style.zIndex = zmax - 1; //阴影的层 = 最高层 - 1
}

/**
* 标题栏按下鼠标或移动窗口时，重画阴影
*/
function Shadow(obj)
{
/**
* 阴影的位置 = 新的父元素位置 + 阴影宽度
*/
sdiv.style.left = obj.offsetParent.offsetLeft + ssize;
sdiv.style.top = obj.offsetParent.offsetTop + ssize;
sdiv.style.width = obj.offsetParent.offsetWidth;
sdiv.style.height = obj.offsetParent.offsetHeight;
sdiv.style.visibility = 'visible';
}

/**
* 提交
* data format: left,top,width,height,zindex,id|
* 100,100,100,194,100,123|100,100,100,411,100,122|
*/
function Save()
{
for(i=0; i<=count.value; i++)
{
  mywin = document.getElementById('mywin'+i);
  myleft = mywin.offsetLeft - mdiv.offsetLeft;
  mytop = mywin.offsetTop - mdiv.offsetTop;
  mywidth = mywin.offsetWidth;
  myheight = mywin.offsetHeight;
  myzindex = mywin.style.zIndex;
  myid = mywin.value;
  form1.mydata.value += myleft + ',' + mytop + ',' + mywidth + ',' + myheight + ',' + myzindex + ',' + myid + '|';
}
form1.mydata.value = form1.mydata.value.substr(0, form1.mydata.value.length - 1);
}