
var tabCount=0;
function tb_addnew(name){

tabCount++;
var obj=document.getElementById('taskTools');
var tab; //标签名称
 var style=document.getElementById('manner').value;
 var color=document.getElementById('color').value;
//新增单元格
tab = "tab"+tabCount;//标签名
newcell=obj.rows(0).insertCell();
newcell.setAttribute("background","style/"+style+"/task_show.gif"); //属性
newcell.setAttribute("name",tab); //属性
newcell.setAttribute("id",tab); //属性
newcell.setAttribute("align","center"); 
newcell.style.setAttribute("cursor","hand"); //属性
var winName;
winName ="mywin" +tabCount;
//document.getElementById(tab).onclick=function () { tb_delete(tab); }; //触发程序
document.getElementById(tab).onclick=function () { mouseonclick(this);ShowHide(winName); }; //触发程序
document.getElementById(tab).onmouseout=function () { mouseout(this,4); }; //触发程序
document.getElementById(tab).onmouseover=function () { mouseover(this,4); }; //触发程序

//newcell.innerText=name+tabCount; //内容

var str=""
+ "<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='prog"+tabCount+"' style='color:" + color + "'>" + name +"</span>"
+ " </td> "
+ " </tr> "
+ "</table> "
newcell.innerHTML=str;


//调整列宽
tb_setWidth()

//取消旧标签
var oldobj=document.getElementById(ontab);
if(oldobj!=null)oldobj.background="style/"+style + "/task_hide.gif";
ontab=tab;

//返回窗体ID号
return tabCount;
}

function tb_setWidth(){

//调整列宽
var obj=document.getElementById('taskTools');
var ll=document.body.clientWidth-228; //任务栏总长:开始100右边100搜索框150
var ww=160; //默认格宽
var max=Math.min(ll/ww); //任务栏允许格数
var w;//调整后宽度
var h=document.getElementById('start_space').height;//高度

maxcell=obj.rows(0).cells.length; //总数
if (maxcell<=max) {w=ww;}
else{ w=Math.min(ll/maxcell);}

//调整宽度
for(i=0;i<maxcell;i++) {
    obj.rows(0).cells(i).style.pixelWidth=w;
     obj.rows(0).cells(i).style.pixelHeight=h;
}

}

//排列窗口
function arrayAllwin(ss){
try{
	show="";
	var obj=document.getElementById('taskTools');
	maxcell=obj.rows(0).cells.length; //总数
	for(i=0;i<maxcell;i++){
		tab=obj.rows(0).cells(i).getAttribute('name');
		name=tab.replace("tab","mywin");
		curobj = document.getElementById(name); 
		if(curobj.style.display!='none'){
			if (show==""){show=name}else{show+=","+name}
		} 
	}
	if (show!=""){
		var a=show.split(",");
		var al=a.length;
		switch(ss){
			case 1://层叠
				w=700;h=500;l=20;t=40;
		
				//alert(a);
 				for(i=0;i<=al-1;i++){
 					name=a[i];
 					//alert(name);
					obj = document.getElementById(name)
					obj.style.pixelWidth=w;
					obj.style.pixelHeight=h;
					obj.style.left = l;
					obj.style.top = t;
					zmax = zmax +10; //最高层（变量）每次点击加10，以保证最高
					obj.style.zIndex = zmax; //将当前层置顶，当前层 = 最高层
					l+=22;t+=22;
						
 				}	
 				break; 
 			case 2://横向
 		
 				w=document.body.clientWidth;
 				h=document.body.clientHeight-35;
 				t=30;l=0;
 				hh=h/al;//窗高
 				for(i=0;i<=al-1;i++){
 					name=a[i];
 					obj = document.getElementById(name)
					obj.style.pixelWidth=w;
					obj.style.pixelHeight=hh;
					obj.style.left = l;
					obj.style.top = t;
					zmax = zmax +10; //最高层（变量）每次点击加10，以保证最高
					obj.style.zIndex = zmax; //将当前层置顶，当前层 = 最高层
					t+=hh;
						
 				}	
 				break; 
 			case 3://纵向
 		
 				w=document.body.clientWidth;
 				h=document.body.clientHeight-35;
 				t=30;l=0;
 				ww=w/al;//窗高
 				for(i=0;i<=al-1;i++){
 					name=a[i];
 					obj = document.getElementById(name)
					obj.style.pixelWidth=ww;
					obj.style.pixelHeight=h;
					obj.style.left = l;
					obj.style.top = t;
					zmax = zmax +10; //最高层（变量）每次点击加10，以保证最高
					obj.style.zIndex = zmax; //将当前层置顶，当前层 = 最高层
					l+=ww;
						
 				}	
 				break; 
		}
		
	}else{alert("当前没有可视窗口!")}
	
}catch(err){alert(err.message)}
}


function tb_delete(name){

var curobj=document.getElementById('taskTools');
var maxcell=curobj.rows(0).cells.length;
var 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;
}

//调整列宽
tb_setWidth()
}