document.write("<div id='TxTopDiv' style='z-Index:1000;position:absolute;top:expression(document.body.clientHeight/2 - TxTopDiv.offsetHeight/2);left:expression(document.body.clientWidth/2 - TxTopDiv.offsetWidth/2);display:none;' class='dd-demo'></div>");
document.write("<div id='__$mask$container' style='z-index:999;background:#cccccc;filter:Alpha(opacity=50);position:absolute;width:100%;height:100%;left:0;top:0;display:none;'></div>");

var xmlns1999 = false;
try{xmlns1999 = (document.getElementsByTagName("html")[0].xmlns.toLowerCase()=='http://www.w3.org/1999/xhtml')?true:false;}catch(e){}
function getScroll() {
	var t, l, dde=document.documentElement, db=document.body;
	if (dde && (dde.scrollTop || dde.scrollLeft)) {
		t = dde.scrollTop;
		l = dde.scrollLeft;
	} else if (db) {
		t = db.scrollTop;
		l = db.scrollLeft;
	} else {}
	return { top: t, left: l };
}
TxOverlay = function(){	//覆盖层
	this.DomObj = null;
}
TxOverlay.prototype = {
	Show:function(){
		this.DomObj = document.getElementById("__$mask$container");
		if (this.DomObj == null) return;
		this.DomObj.style.display = "";
		this.DomObj.style.height = document.body.scrollHeight + "px";
	},

	Hide:function(){
		this.DomObj = document.getElementById("__$mask$container");
		if (this.DomObj == null)return;
		this.DomObj.style.display = 'none';
	},

	Close:function(){
		this.DomObj = document.getElementById("__$mask$container");
		if (this.DomObj == null)return;
		this.DomObj.style.display = 'none';
		CollectGarbage();
	}
}

TopPanel = function(){
	this.onOk = null;
	this.onCancel = null;
	this.onClose = null;
	this.Obj = document.getElementById("TxTopDiv");
}
TopPanel.prototype = {
	IsNumber:function(value){	//数字判断
		if (value==null || value=="") return false;
		return !isNaN(value);
	},
    CallBack:function(BackInfo){
		switch(BackInfo){
		case 1:	//确定
			if (this.onOk != null && typeof(this.onOk)=='function') 
			{
			    this.Close();this.onOk();
			}
			else
			{
			    this.Close();
			}
			break;
		case 2:	//取消
			if (typeof(this.onCancel)=='function') {this.Close();this.onCancel();}
			break;
		default:this.Close();
		}
		
    },
    //等待信息
    Process:function(Title){
		this.Obj = document.getElementById("TxTopDiv");
		this.Obj.style.zIndex = 1000;
		this.Obj.innerHTML = "<div><center>";
		if (typeof(Title)=="string") this.Obj.innerHTML+= Title + "<br>";
		this.Obj.innerHTML+= "<img src='http://js.itiexue.net/com/tiexue/images/loading.gif' />";
		this.Obj.innerHTML+= "</center></div>";

		this.Obj.style.display = "";
		this.FixCenter();
    },

	//提示对话框
    Alert:function(Title,Content,DlgWidth,fCallBack){
		this.onClose = this.onCancel = this.onOk = null;
		if (typeof(fCallBack)=='function') this.onClose = fCallBack;
		if (typeof(DlgWidth)=='undefined') DlgWidth =300;
		this.Obj = document.getElementById("TxTopDiv");
		this.Obj.style.zIndex = 1000;
		this.Obj.innerHTML = this.GetDlgInfo(false,Title,Content);

		this.Obj.style.display = "";
		this.Obj.style.width = DlgWidth + "px";
		drag("TxTopDiv","DropEventObj",true);
		this.FixCenter();
    },
	//确认对话框
    Confirm:function(Title,Content,DlgWidth,fOkBack,fCancelBack){
		this.onOk = this.onCancel = this.onClose = null;
		if (typeof(fOkBack)=='function') this.onOk=fOkBack;
		if (typeof(fCancelBack)=='function') this.onClose = this.onCancel=fCancelBack;
		if (typeof(DlgWidth)=='undefined') DlgWidth =300;

		this.Obj = document.getElementById("TxTopDiv");
		this.Obj.style.zIndex = 1000;
		this.Obj.innerHTML = this.GetDlgInfo(true,Title,Content);
		
		this.Obj.style.display = "";
		this.Obj.style.width = DlgWidth + "px";
		drag("TxTopDiv","DropEventObj",true);
		this.FixCenter();
		//this.Obj.style.left = "20px";this.Obj.style.top = "20px";
    },
    //自定义对话框
    CustomDlg:function(html,IsFixCenter,DragObjID,Left,Top,Width,Height){
		this.Obj = document.getElementById("TxTopDiv");
		with(this.Obj){
			innerHTML = html;
			style.zIndex = 1000;
			style.display = "";
			if (this.IsNumber(Left)) style.left = Left + "px";
			if (this.IsNumber(Top)) style.top = Top + "px";

			if (this.IsNumber(Width)) style.width = Width + "px";
			if (this.IsNumber(Height)) style.height = Height + "px";
		}
		if (IsFixCenter) this.FixCenter();
		if (typeof(DragObjID)=='string') this.initDrag(DragObjID);
    },

    Close:function(){
		this.Obj = document.getElementById("TxTopDiv");
		if (this.Obj==null)return;
		if (this.Obj.innerHTML=="")return;

		if (this.orig_scroll!=null){
			window.onscroll = this.orig_scroll;
		}

		this.Obj.innerHTML = "";
		this.Obj.style.display = "none";
		if (typeof(this.onClose)=='function') this.onClose();
    },

    FixCenter:function(DragID){
		if (typeof DragID == 'undefined') DragID = "TxTopDiv"
		this.Obj = document.getElementById(DragID);
		if (this.Obj==null)return;
		var viewpos = getScroll();
		if (xmlns1999){
			this.Obj.style.left = viewpos.left + (document.documentElement.clientWidth  - this.Obj.offsetWidth)/2 + "px";
			this.Obj.style.top = viewpos.top + (document.documentElement.clientHeight - this.Obj.offsetHeight)/2 + "px";
		}else{
			this.Obj.style.left = viewpos.left + (document.body.clientWidth  - this.Obj.offsetWidth)/2 + "px";
			this.Obj.style.top = viewpos.top + (document.body.clientHeight - this.Obj.offsetHeight)/2 + "px";
		}
    },
    ResetPanelObj:function(){
        if (this.Obj== null){this.Obj = document.getElementById("TxTopDiv");}
        if (this.Obj.children.length > 0)
        {
            var firstChild = this.Obj.children[0];
            if (firstChild.getAttribute("id") == "TxTablePanel")
            {
                var parentObj1 = document.getElementById("TxTablePanelParent");
                parentObj1.innerHTML = "";
                parentObj1.appendChild(firstChild);
            }
            else if(firstChild.getAttribute("id") == "processAlert")
            {
                var parentObj1 = document.getElementById("processAlertParent");
                parentObj1.innerHTML = "";
                parentObj1.appendChild(firstChild);
            }
        }
    },
    GetDlgInfo:function(OkCancelInfo,Title,Content){
 		var temp = "<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>";
		temp+= "<tr>";
		temp+= "    <td width='14' height='27'> <img src='http://js.itiexue.net/com/tiexue/images/080325_1.gif' width='14' height='27'/></td>";
		temp+= "    <td id='DropEventObj' height='27' background='http://js.itiexue.net/com/tiexue/images/080325_2.gif' style='font-size: 12px;color: #3A0000;line-height:18px;' style='cursor:move'>" + Title + "</td>";	// onmousedown='MoveStart(\"TxTopDiv\")'
		temp+= "    <td width='29' height='24' background='http://js.itiexue.net/com/tiexue/images/080325_3.gif' style='padding-top:3px;'><img src='http://js.itiexue.net/com/tiexue/images/close.gif' width='14' height='14' onclick='TxTopPanel.CallBack(0)' style='cursor:hand'/></td>";
		temp+= "</tr>";
		temp+= "<tr>";
		temp+= "    <td width='14' background='http://js.itiexue.net/com/tiexue/images/080325_4.gif'>&nbsp; </td>";
		temp+= "    <td align='center' background='http://js.itiexue.net/com/tiexue/images/080325_5.gif' style='font-size: 12px;color: #3A0000;line-height:18px;'>";
		temp+= "		<table width='100' border='0' cellspacing='0' cellpadding='0'><tr><td height='10'></td></tr></table>";

		temp+= this.GetDlgData(OkCancelInfo,Content);

		temp+= "	</td>";
		temp+= "	<td width='29' background='http://js.itiexue.net/com/tiexue/images/080325_6.gif'>&nbsp; </td>";
		temp+= "</tr>";
		temp+= "<tr>";
		temp+= "	<td width='14' height='17' valign='top'><img src='http://js.itiexue.net/com/tiexue/images/080325_7.gif' width='14' height='17'/></td>";
		temp+= "	<td background='http://js.itiexue.net/com/tiexue/images/080325_8.gif'>&nbsp; </td>";
		temp+= "	<td width='29' height='17' valign='top'><img src='http://js.itiexue.net/com/tiexue/images/080325_9.gif' width='29' height='17'/></td>";
		temp+= "</tr>";
		temp+= "</table>";
		return temp;
	},

	GetDlgData:function(OkCancelInfo,msgInfo){
		var temp = null;
		temp = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		temp+= "<tr>";
		temp+= "	<td align='center' style='font-size:12px;color: #3A0000;line-height:18px;vertical-align:top;'>" + msgInfo + "</td>";
		temp+= "</tr>";
		temp+= "</table>";
		temp+= "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		temp+= "<tr>";
		temp+= "	<td height='30' align='center' style='vertical-align:bottom;'>";
		temp+= "		<img src='http://js.itiexue.net/com/tiexue/images/OkBt.gif' width='41' height='22' onclick='TxTopPanel.CallBack(1)' style='cursor:hand'/>";
		if (OkCancelInfo){	//确定取消
			temp+= "		<img src='http://js.itiexue.net/com/tiexue/images/CancelBt.gif' width='41' height='22' onclick='TxTopPanel.CallBack(2)' style='cursor:hand'/>";
		}//else{	//提示信息
		//	temp = msgInfo;
		//}
		temp+= "	</td>";
		temp+= "</tr>";
		temp+= "</table>";
		return temp;
	}
}
function drag(DragObj,EventObj,fixedcenter)	//被拖动的对象,事件对象,修复中心位置
{
	if (typeof DragObj == "string") DragObj = document.getElementById(DragObj);
	if (typeof EventObj == "string") EventObj = document.getElementById(EventObj);
 
	EventObj.onmousedown = function(a)
	{
		if(!a)a=window.event;

		var d=document;
		var x = a.clientX-DragObj.offsetLeft;
		var y = a.clientY-DragObj.offsetTop;

		if(DragObj.setCapture)
			DragObj.setCapture();
		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		d.onmousemove = function(a)
		{
			if(!a)a=window.event;
			var viewpos = getScroll();
			var left =0;
			if (!document.all && document.getElementById){
				left = a.clientX+document.body.scrollLeft-x;
				if (left>viewpos.left+10){
					if (left < document.documentElement.clientWidth  - DragObj.offsetWidth + viewpos.left - 10){
						DragObj.style.left = left;

						DragObj.orig_x = parseInt(DragObj.style.left) - document.body.scrollLeft;
					}
				}
			}else{
				if (xmlns1999){
					if (a.clientX - x <= document.documentElement.scrollLeft + 10)
						left = document.documentElement.scrollLeft + 10; 
					else if (a.clientX - x >= document.documentElement.clientWidth - DragObj.offsetWidth + document.documentElement.scrollLeft - 10) 
						left = (document.documentElement.clientWidth - DragObj.offsetWidth + document.documentElement.scrollLeft - 10); 
					else 
						left = a.clientX - x;
				}else{
					if (a.clientX - x <= document.body.scrollLeft + 10)
						left = document.body.scrollLeft + 10; 
					else if (a.clientX - x >= document.body.clientWidth - DragObj.offsetWidth + document.body.scrollLeft - 10) 
						left = (document.body.clientWidth - DragObj.offsetWidth + document.body.scrollLeft - 10); 
					else 
						left = a.clientX - x;
				}

				DragObj.style.left = left + "px";
			}

			var top = a.clientY-y;
			if (top>viewpos.top+10){
				if (xmlns1999){
					if (top < document.documentElement.clientHeight - DragObj.offsetHeight + viewpos.top-10) DragObj.style.top = top + "px";
				}else{
					if (top < document.body.clientHeight - DragObj.offsetHeight + viewpos.top-10) DragObj.style.top = top + "px";
				}
			}
		}
		d.onmouseup = function()
		{
			if(DragObj.releaseCapture)
				DragObj.releaseCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			d.onmousemove = null;
			d.onmouseup = null;
		 }
	 }
	 if (fixedcenter)
	 {
		var orig_scroll = null;
		if (window.onscroll) orig_scroll = window.onscroll;
		window.onscroll = function ()
		{
			if (orig_scroll!=null) orig_scroll();

			var viewpos = getScroll();
			if (xmlns1999){
				DragObj.style.left = viewpos.left + (document.documentElement.clientWidth  - DragObj.offsetWidth)/2 + "px";
				DragObj.style.top = viewpos.top + (document.documentElement.clientHeight - DragObj.offsetHeight)/2 + "px";
			}else{
				DragObj.style.left = viewpos.left + (document.body.clientWidth  - DragObj.offsetWidth)/2 + "px";
				DragObj.style.top = viewpos.top + (document.body.clientHeight - DragObj.offsetHeight)/2 + "px";
			}
		}
	}
}

var TxTopPanel = new TopPanel();

var layObj = null;	//覆盖层

function TxAlert(Msg,width,islay){
    if (typeof(width) == 'undifined' || width == null)
    {
        width = 225;
    }
	if (layObj == null) layObj = new TxOverlay();
	if (islay == true)
	{
	    layObj.Show();
	}
	TxTopPanel.Alert('提示',Msg,225,function(){layObj.Close();});
}

//confirm
function TxConfirm(Msg,callBack,callBackCance,width,islay){  //msg-提示信息 callback-点击“确定”的回调函数 callbackcance-点击“取消“的回调函数 width-提示框宽度 islay-是否显示底层覆盖
    if (typeof(width) == 'undifined' || width == null)
    {
        width = 225;
    }
	if (layObj == null) layObj = new TxOverlay();
	if (islay == true)
	{
	    layObj.Show();
	}
	TxTopPanel.Confirm('提示确认',Msg,225,function(){
		layObj.Close();
		if (typeof(callBack)=='function')callBack();
	},function(){layObj.Close();if (typeof(callBackCance)=='function')callBackCance();});
}

//进度条显示
function TxProcessShow(Title,islay){  //title-显示信息 islay-覆盖层是否显示
	if (layObj == null) layObj = new TxOverlay();
	if (islay == true)
	{
	    layObj.Show();
	}
	TxTopPanel.Process(Title);
}
//进度条隐藏
function TxProcessHide(){
	//if (layObj == null) return;
	TxTopPanel.Close();
	if (layObj != null)
	{
	    layObj.Close();
	}
}

//对话框图片预加载
function PreLoadImageFunc()
{
	var Imgsrc = new Array(
		"http://js.itiexue.net/com/tiexue/images/080325_1.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_2.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_3.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_4.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_5.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_6.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_7.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_8.gif",
		"http://js.itiexue.net/com/tiexue/images/080325_9.gif",
		"http://js.itiexue.net/com/tiexue/images/close.gif",
		"http://js.itiexue.net/com/tiexue/images/OkBt.gif",
		"http://js.itiexue.net/com/tiexue/images/CancelBt.gif"
	);
	for (var i=0;i<Imgsrc.length;i++)
	{
		var ImgList = new Image();
		ImgList.src=Imgsrc[i];
	}
}
PreLoadImageFunc();