var dt_session=20;
var dt_session_remain=3;
var dt_start=new Date();
var dt_end=new Date();
dt_end.setTime(dt_end.getTime()+dt_session*60*1000);
var dt_remain=new Date();
var dt_remain_minute=dt_session_remain;

var strTitle="此处为在线编写帖子停留时间。如果您要编写的帖子很大，请在其它编辑器中预先编辑好，再粘贴到正文处。否则在页面超时后，帖子发送将会失败！"
var strTipsStart="在线写帖时间请勿超过 <b>"+dt_session+"</b> 分钟。";
var strTipsWaring="在线写帖时间不到 <b>"+dt_remain_minute+"</b> 分钟，请及时保存帖子。";
var strTipsEnd="页面可能已经超时，若发送失败请重新登录。";
var strTips=strTipsStart;

var TimeCellColorTurnOn=true;
var timeoutid_remain="";
var timeoutid_change="";
var changestart=true;
var makeremain=true;
var arrWeek=new Array(7);
    arrWeek[0]="日";
    arrWeek[1]="一";
    arrWeek[2]="二";
    arrWeek[3]="三";
    arrWeek[4]="四";
    arrWeek[5]="五";
    arrWeek[6]="六";

function RemainTime()
{
	var dt_current = new Date();
	var week=dt_current.getDay();
	var weekday=arrWeek[week];
	dt_remain.setTime(dt_current.getTime()-dt_start.getTime()+dt_current.getTimezoneOffset()*60*1000);
	dt_remain_minute=dt_session-dt_remain.getMinutes();
	var str="<table border=\"0\" cellspadding=\"0\" cellSpacing=\"0\" class=\"white\"><tr onmouseover=\"this.style.cursor='help';\" title='"+strTitle+"'>";
	str+="<td>"+strTips+"</td>";
	str+="<td id='TimeCell'> <b>"+IfZero(dt_remain.getHours())+":"+IfZero(dt_remain.getMinutes())+":"+IfZero(dt_remain.getSeconds())+"</b></td>";
	str+="</tr></table>";
	if (document.all)
	{
		DispRemainTime.innerHTML=str;
		var Minutes=dt_remain.getMinutes();
		var Seconds=dt_remain.getSeconds();
		if (Minutes>=(dt_session-dt_session_remain) && makeremain) 
		{
			strTips="在线写帖时间不到 <b>"+dt_remain_minute+"</b> 分钟，请及时保存帖子。";
			if (changestart)
			{
				timeoutid_change=setInterval("ChangeCellBG()", 500);
				changestart=false;
			}
		}
		if (Minutes==dt_session && Seconds<1) 
		{
			if (!changestart)
			{
				strTips=strTipsEnd;
				clearInterval(timeoutid_change);
				makeremain=false;
				alert("请及时保存好您的帖子，当前页面会话可能已经超时。\n\n如果点击发送帖子失败，请重新登录后再发送。");
			}
		}
		if (!makeremain)
		{
			TimeCellColorTurnOn=true;
			ChangeCellBG();
		}
	}
	setTimeout("RemainTime()",1000);
}

function IfZero(num)
{
	return ((num <= 9) ? ("0" + num) : num);
}

function ChangeCellBG()
{
	if (TimeCellColorTurnOn)
	{
		TimeCell.style.backgroundColor='#FF0000';
		TimeCell.style.color='#FFFFFF';
		TimeCellColorTurnOn=false;
	}else
	{
		TimeCell.style.backgroundColor='';
		TimeCell.style.color='#FFFFFF';
		TimeCellColorTurnOn=true;
	}
}