//  描述 : 多文档窗口
var timer = null;
var win = null;
var wins = new Array();

function init(){
	win =  new mywin();	//新建对象
}

function AddWin(Url,Title){
		if(win==null)
		{
			alert("数据项还未加载完成，请稍候！");
			return;
		}
	wins[wins.length] = win.addwin(Url, Title);//添加窗体；
}

function mywin(){
	this.winlist		= new Array();	//窗口列表
	this.maxWins		= 7;			//最大窗口数
	this.tagTitleWidth	= 100;			//标签宽度
	this.indentWidth	= 0;			//标签缩进宽度
	this.currentwin		= null;
	this.addwin			= addwin;		//新建窗口方法
	this.removewin		= removewin;	//移除窗体
	this.activewin		= activewin;	//激活窗口
	this.container		= container;
	this.padLeft		= padLeft;		//标题离左边缘的距离
	this.padRight		= padRight;		//标题离右边缘的距离
	this.scrollWidth	= scrollWidth;

	function container(url,title){
		for(var i=0;i<this.winlist.length;i++){
			if(this.winlist[i].title == title && this.winlist[i].url == url){
				return i;
			}
		}
		return -1;
	}
	
	//激活窗口
	function activewin(oEl){
		if(oEl == null){
			this.currentwin = null;
			return;
		}
		var tempzindex = this.currentwin.style.zIndex;
		this.currentwin.wintitle.style.zIndex = this.currentwin.index;
		this.currentwin.style.display = "none";
		this.currentwin.wintitle.style.backgroundImage = 'url(/images/tab1.gif)';
		oEl.wintitle.style.zIndex = tempzindex;
		oEl.style.display = "";
		oEl.wintitle.style.backgroundImage = 'url(/images/tab2.gif)';
		this.currentwin = oEl;
	}

	function padLeft(oEl){
		var padleft = oEl.index * this.tagTitleWidth - this.indentWidth*(oEl.index-1);
		return padleft;
	}

	function padRight(oEl){
		var count = (this.winlist.length - oEl.index) + 1;
		var padright = this.tagTitleWidth * count - this.indentWidth*(count-1);
		return padright;
	}
	
	//方法的具体实现
	function addwin(url,title){
		
		var con = this.container(url,title);
		if(con>-1){
			this.activewin(this.winlist[con]);
			return;
		}
		if(this.winlist.length >= this.maxWins){
			alert("超过最大窗口数限制（"+this.maxWins+"），请先关闭部分窗口");
			return false;
		}

		today1.style.display = 'none';//隐藏“今日”层
		today2.style.display = 'none';//隐藏“今日”层
		
		oDIV = window.document.createElement( "TABLE" );
		this.winlist[this.winlist.length] = oDIV;//往列表内添加窗体对象
		oDIV.url = url;
		oDIV.title = title;
		oDIV.index = this.winlist.length;
		oDIV.className = "win";
		oDIV.width = 790;
		oDIV.height = 520;
		//oDIV.cellSpacing = 0;
		oDIV.insertRow().insertCell().innerHTML = "<iframe src='"+url+"' class = 'win1' frameborder='0'></iframe>";

		var oTitle = window.document.createElement( "SPAN" );
		oTitle.className ='wintitle';
		oTitle.style.width = this.tagTitleWidth;
		oTitle.style.backgroundImage = 'url(/images/tab2.gif)';
		oTitle.style.left = this.winlist.length == 1 ? 0 : this.winlist[this.winlist.length-2].wintitle.style.pixelLeft - this.indentWidth;
		oTitle.title = title;
		title = title;
		oTitle.innerHTML= title == null ? "unkown windows" : title + "<img src=/images/x.gif onclick=win.removewin(win.currentwin) onmouseover=src='/images/x2.gif' onmouseout=src='/images/x.gif'>";
		oTitle.win=oDIV;
		oTitle.onmouseover = new Function("win.activewin(this.win)")

		if(this.currentwin != null){
			this.currentwin.wintitle.style.backgroundImage = 'url(/images/tab1.gif)';
			this.currentwin.style.display = "none";
			this.currentwin.wintitle.style.zIndex = this.currentwin.index;
		}
		oDIV.style.zIndex = this.maxWins+1;
		oTitle.style.zIndex = this.maxWins+1;
		oDIV.wintitle = oTitle;
		titlelist.insertAdjacentElement( "beforeEnd" , oTitle );

		var scrollwidth = this.scrollWidth();
		if(scrollwidth > titlelist.parentElement.clientWidth)
			titlelist.style.marginLeft = titlelist.parentElement.clientWidth - scrollwidth;
		mywindows.insertAdjacentElement( "beforeEnd" , oDIV );

		this.currentwin = oDIV;
		return oDIV;
	}

	function scrollWidth(){
		var n = this.winlist.length;
		var scrollwidth = this.tagTitleWidth*n - this.indentWidth*(n-1);
		return scrollwidth;
	}

	//移除窗体
	function removewin(obj){
		if(obj == null)return;
			var temparr = new Array();
			var afterwin = false;
			for(var i=0;i<this.winlist.length;i++){
				if(afterwin) this.winlist[i].wintitle.style.left =  this.winlist[i].wintitle.style.pixelLeft + this.indentWidth;
				if(this.winlist[i] != obj)
					temparr[temparr.length] = this.winlist[i];
				else
					afterwin = true;
		}
		
		if(this.winlist.length == 1){
			return false;
		}
		this.winlist = temparr;
		if(this.currentwin == obj)
			this.activewin(this.winlist[this.winlist.length-1]);
		obj.wintitle.removeNode(true) ;
		obj.removeNode(true) ;
		obj = null;
		
		if(this.winlist.length == 0){//移除窗体为空 0
			//today1.style.display = 'block';//显示“今日”层
			//today2.style.display = 'block';//显示“今日”层
			//AddWin('DataManage/Index.aspx','今日');
		}
	}
}

// 左 事件
var TabCassName;

function TabOver(oTab){
	TabCassName = oTab.className.toLowerCase();
	oTab.className = "GlTabs";
}

function TabOut(oTab){
	if (TabCassName == "gltabsture")
		oTab.className = "GlTabsTure";
	else
		oTab.className = "GlTabsFalse";
}

function slide1() {
	page1.style.display = 'block';
	gLtab1.className = 'GlTabsTure';
	page2.style.display = 'none';
	gLtab2.className = 'GlTabsFalse';
	page3.style.display = 'none';
	gLtab3.className = 'GlTabsFalse';
	page4.style.display = 'none';
	gLtab4.className = 'GlTabsFalse';
	page5.style.display = 'none';
	gLtab5.className = 'GlTabsFalse';
	page6.style.display = 'none';
	gLtab6.className = 'GlTabsFalse';
	TabCassName = "gltabsture";
}

function slide2() {
	page1.style.display = 'none';
	gLtab1.className = 'GlTabsFalse';
	page2.style.display = 'block';
	gLtab2.className = 'GlTabsTure';
	page3.style.display = 'none';
	gLtab3.className = 'GlTabsFalse';
	page4.style.display = 'none';
	gLtab4.className = 'GlTabsFalse';
	page5.style.display = 'none';
	gLtab5.className = 'GlTabsFalse';
	page6.style.display = 'none';
	gLtab6.className = 'GlTabsFalse';
	TabCassName = "gltabsture";
}

function slide3() {
	page1.style.display = 'none';
	gLtab1.className = 'GlTabsFalse';
	page2.style.display = 'none';
	gLtab2.className = 'GlTabsFalse';
	page3.style.display = 'block';
	gLtab3.className = 'GlTabsTure';
	page4.style.display = 'none';
	gLtab4.className = 'GlTabsFalse';
	page5.style.display = 'none';
	gLtab5.className = 'GlTabsFalse';
	page6.style.display = 'none';
	gLtab6.className = 'GlTabsFalse';
	TabCassName = "gltabsture";
}

function slide4() {
	page1.style.display = 'none';
	gLtab1.className = 'GlTabsFalse';
	page2.style.display = 'none';
	gLtab2.className = 'GlTabsFalse';
	page3.style.display = 'none';
	gLtab3.className = 'GlTabsFalse';
	page4.style.display = 'block';
	gLtab4.className = 'GlTabsTure';
	page5.style.display = 'none';
	gLtab5.className = 'GlTabsFalse';
	page6.style.display = 'none';
	gLtab6.className = 'GlTabsFalse';
	TabCassName = "gltabsture";
}

function slide5() {
	page1.style.display = 'none';
	gLtab1.className = 'GlTabsFalse';
	page2.style.display = 'none';
	gLtab2.className = 'GlTabsFalse';
	page3.style.display = 'none';
	gLtab3.className = 'GlTabsFalse';
	page4.style.display = 'none';
	gLtab4.className = 'GlTabsFalse';
	page5.style.display = 'block';
	gLtab5.className = 'GlTabsTure';
	page6.style.display = 'none';
	gLtab6.className = 'GlTabsFalse';
	TabCassName = "gltabsture";
}

function slide6() {
	page1.style.display = 'none';
	gLtab1.className = 'GlTabsFalse';
	page2.style.display = 'none';
	gLtab2.className = 'GlTabsFalse';
	page3.style.display = 'none';
	gLtab3.className = 'GlTabsFalse';
	page4.style.display = 'none';
	gLtab4.className = 'GlTabsFalse';
	page5.style.display = 'none';
	gLtab5.className = 'GlTabsFalse';
	page6.style.display = 'block';
	gLtab6.className = 'GlTabsTure';
	TabCassName = "gltabsture";
}
