	window.TabControl=function()
	{
		this.getName=function()
		{
			var i=0;
			var baseName="TabControl";
			var result=null;
			while(true)
			{
				var id=baseName+i.toString();
				result=document.getElementById(id);
				if(!result)	return id;
			}
		}
		this.TabPages=[];
                this.defaultpage=0;
		this.width=300;
		this.height=30;
		this.currentPage=null;
		this.name=this.getName();
		this.fontSize="13";
		this.bgColor="#E0E2E2";
		this.bgGround="url(\"../js/RadioBox/tabselect.gif\")";
		this.fontColor="#444444";
		this.borderColor="#52534D";
		this.selectBGColor="#343432";
		this.selectBGGround="url(\"../js/RadioBox/tabselected.gif\")";
		this.selectFontColor="#444444";
		this.selectBorderColor="#444444";
		this.body=null;
		this.onPageChange=null;
		this.HTMLObj=null;
		this.LastTD=null;
		this.Create=function()
		{
			var len=this.TabPages.length;
			if(len==0)	return;
			var topDiv=document.createElement("div");
			topDiv.id=this.name;
						
			//******************构造头部**************************
			var headTable=document.createElement("table");
			var headBody=document.createElement("tbody");
			headTable.appendChild(headBody);
			headTable.cellSpacing=0;
			headTable.cellPadding=0;
			headTable.style.color=this.fontColor;
			headTable.style.fontSize=this.fontSize+"px";
			headTable.style.wordWrap="break-word";
			var headTr=document.createElement("tr");
			headTr.style.height="26px";
			headBody.appendChild(headTr);
			for(var i=0;i<len;i++)
			{
				var td=document.createElement("td");
				td.width="90";
				td.vAlign="middle";
				td.style.color=this.fontColor;
				td.style.borderLeft="0px solid "+this.borderColor;
				td.style.borderBottom="0px solid "+this.borderColor;
				td.style.borderTop="0px solid "+this.borderColor;
				td.innerHTML+="<nobr><div align='center'>&nbsp;"+this.TabPages[i].title+"&nbsp;</div></nobr>";
				//td.style.backgroundColor=this.bgColor;
                                td.style.background=this.bgGround;
				td.style.cursor="pointer";
				td.DataObj=this.TabPages[i];
				this.TabPages[i].HTMLObj=td;
				//如果内容不是字符,则当成对象处理,提取对明的HTML代码当成内容
				if(this.TabPages[i].content==null)	this.TabPages[i].content="";
				else if(typeof(this.TabPages[i].content)!="string")
				{
					var tempElement=document.createElement("div");
					tempElement.appendChild(this.TabPages[i].content);
					this.TabPages[i].content=tempElement.innerHTML;
				}
				td.onclick=function()
				{
					if(this.DataObj.parent.currentPage==this.DataObj)	return;
					this.DataObj.parent.PageChange(this.DataObj);
				}				
				headTr.appendChild(td);
			}
			topDiv.appendChild(headTable);
			document.getElementById("test").appendChild(topDiv);
			this.HTMLObj=topDiv;
			//***************构造最后一个TD**************			
			if(headTable.offsetWidth<this.width)
			{
				var lastTd=document.createElement("td");
				this.LastTD=lastTd;
				lastTd.style.width=(this.width-headTable.offsetWidth-1)+"px";
				if(document.all)	lastTd.style.width=(this.width-headTable.offsetWidth-1)+"px";
				else	lastTd.style.width=(this.width-headTable.offsetWidth+1)+"px";
				lastTd.innerHTML="&nbsp;";
				lastTd.style.borderLeft="0px solid "+this.borderColor;
				lastTd.style.borderBottom="0px solid "+this.borderColor;
				headTr.appendChild(lastTd);
			}
			//***********构造BODY部分******************
                        /*
			var bodyDiv=document.createElement("div");
			bodyDiv.style.borderLeft="1px solid "+this.borderColor;
			bodyDiv.style.borderBottom="1px solid "+this.borderColor;
			bodyDiv.style.borderRight="1px solid "+this.borderColor;
			bodyDiv.style.width=this.width+"px";
			bodyDiv.style.height="0px";//(this.height-headTable.offsetHeight)+"px";
			bodyDiv.style.fontSize=this.fontSize+"px";
			bodyDiv.style.wordWrap="break-word";
			bodyDiv.style.overflow="auto";
			bodyDiv.style.paddingTop="0px";//"10px";
			topDiv.appendChild(bodyDiv);
			this.body=bodyDiv;
                        */
			this.PageChange(this.TabPages[this.defaultpage],true);	//设置第一页为当前页*/
		}

		this.addPage=function(TabPage)
		{
			if(TabPage)
			{
				this.TabPages[this.TabPages.length]=TabPage;
				TabPage.parent=this;
			}
		}

		//页面改变事件,isFirst指的是:是否是系统调用,即第一次调用
		this.PageChange=function(selectPage,isSystem)
		{      
			if(!isSystem)
			{
				if(this.onPageChange!=null)
				{
					//如果返回false,则不进行任何操作
					if((this.onPageChange(this,selectPage))==false)	return;
				}
			}
			if(selectPage.HTMLObj==null)	return;
			if(this.currentPage!=null && this.currentPage.HTMLObj!=null)
			{
				//this.currentPage.content=this.body.innerHTML;	//保存现有的状态
				this.currentPage.HTMLObj.style.borderBottom="0px solid "+this.borderColor;
				this.currentPage.HTMLObj.style.background=this.bgGround;
				//this.currentPage.HTMLObj.style.backgroundColor=this.bgColor;
				this.currentPage.HTMLObj.style.color=this.fontColor;
			}
			this.currentPage=selectPage;
			selectPage.HTMLObj.style.background=this.selectBGGround;
			//selectPage.HTMLObj.style.backgroundColor=this.selectBGColor;
			selectPage.HTMLObj.style.color=this.selectFontColor;
			selectPage.HTMLObj.style.borderBottom="";
			//this.body.innerHTML=selectPage.content;
		}

		//移除TabControl对象
		this.Free=function()
		{
			document.body.removeChild(this.HTMLObj);
		}

		this.ReMoveChild=function(index)
		{
			try
			{
				this.TabPages[index].Free();
			}
			catch (e)
			{
			}
		}
	}

	window.TabPage=function(aTitle,aContent,aValue)
	{
		this.getName=function()
		{
			var i=0;
			var baseName="TabPage";
			var result=null;
			while(true)
			{
				var id=baseName+i.toString();
				result=document.getElementById(id);
				if(!result)	return id;
			}
		}
		this.name=this.getName();
		this.title=aTitle?aTitle:"";
		this.content=aContent?aContent:null;
                this.aValue=aValue?aValue:"";
		this.parent=null;
		this.HTMLObj=null;
		
		//移除TabPage
		this.Free=function()
		{
			if(this.HTMLObj!=null)
			{
				//补全长度
				this.parent.LastTD.style.width=parseInt(this.parent.LastTD.style.width)+parseInt(this.HTMLObj.offsetWidth)+"px";
				this.HTMLObj.parentNode.removeChild(this.HTMLObj);
				this.HTMLObj=null;
				var arr=this.parent.TabPages;
				for(var i=0;i<arr.length;i++)
				{
					if(arr[i]==this)	this.parent.TabPages.splice(i,1);
				}
				//移除数据结构
				if(this.parent.TabPages.length!=0)	this.parent.PageChange(this.parent.TabPages[0],true);
			}
		}
	}


