//----------------------------------------------------------------
// Copyright (C) 1999-2003 BEYONDINFO All rights reserved.
//
// 初始化页面//
//----------------------------------------------------------------

//超时时间重置
try
{
	window.top.ToolBarFrame.ResetOutTime();
}
catch(Error)
{
	//空
}
try
{
	opener.top.ToolBarFrame.ResetOutTime();
}
catch(Error)
{
	//空
}
try
{
	dialogArguments.top.ToolBarFrame.ResetOutTime();
}
catch(Error)
{
	//空
}

//选择日历 
function SelecteCalendar(e,X,Y) 
{
	//显示或隐藏
	if (document.getElementById("CalendarFrame").style.display == "none") 
	{
		//显示日历
		document.getElementById("CalendarFrame").style.display = "";
		
		//月历根据文本框中的位置定位
		document.getElementById("CalendarFrame").style.top	= e.previousSibling.offsetTop + Y;
		document.getElementById("CalendarFrame").style.left	= e.previousSibling.offsetLeft + X;
		document.getElementById("CalendarFrame").className	= e.previousSibling.id;
	}
	else 
	{
		document.getElementById("CalendarFrame").style.display = "none";
	}
}

//获取客户端COOKIE
function GetCookie(name) 
{
    //初始化
    var CookieFound = false;
    var start = 0;
    var end = 0;
    var CookieString = document.cookie;
    var i = 0;

	//读取
    while (i <= CookieString.length) 
    {
        start = i ;
        end = start + name.length;
        if (CookieString.substring(start, end) == name)
        {
			CookieFound = true;
			break; 
        }
        i++;
    }
	
	//找到COOKIE
    if (CookieFound)
    {
		start = end + 1;
		end = CookieString.indexOf(";",start);
		if (end < start)
		{
			end = CookieString.length;
		}
		return unescape(CookieString.substring(start, end));
    }
    
    //返回空
    return "";
}

//四舍五入到某位
function RoundToN(fNumber,nLen)
{     
	var ReturnValue = Math.round(fNumber * Math.pow(10,nLen))/(Math.pow(10,nLen));
	if(Math.round(ReturnValue)==ReturnValue)
	{
		ReturnValue+=".";
		for(var i=0;i<nLen;i++)
		{
		    ReturnValue+="0";
		}
		return ReturnValue;
	}
	else
	{
		ReturnValue+="";
		var tmp = ReturnValue.split(".");
		for(var i=0;i<(nLen-tmp[1].nLength);i++)
		{
		    ReturnValue += "0";
		}
		return ReturnValue;
	}
}

//初始化页面执行时间
var ElapseTime = GetCookie("ElapseTime")
if(ElapseTime != "")
{
	window.status = "执行时间：" + ElapseTime + " 毫秒";	
}

//全选或反选函数
function CheckItem()
{
	//执行
	oEl = event.srcElement;
	for(i = 0;i < document.all.tags("input").length; i++)
	{
		if(document.all.tags("input")(i).id.indexOf("chkItem") != -1)
		{
			if(oEl.checked)
			{
				document.all.tags("input")(i).checked = true;
				document.all.tags("input")(i).parentElement.parentElement.style.backgroundColor='#cccccc';
			}
			else
			{
				document.all.tags("input")(i).checked = false;
				document.all.tags("input")(i).parentElement.parentElement.style.backgroundColor='';
			}
		}
	}
	
	//停止冒泡
	event.cancelBubble = true;
}

//行鼠标选中事件
function RowMouseClick(e)
{
	if(!e.firstChild.firstChild.checked) 
	{
		e.firstChild.firstChild.checked = true;
	}
	else
	{
		e.firstChild.firstChild.checked = false;
	}
}

//行鼠标激活事件
function RowMouseOver(e)
{
	e.style.backgroundColor='#cccccc';
}

//行鼠标丢失事件
function RowMouseOut(e)
{
	if(!e.firstChild.firstChild.checked)
	{
		e.style.backgroundColor='';
	}
	else
	{
		e.style.backgroundColor='#cccccc';
	}
}

//检查权限
function CheckPower()
{
	//如果是特权权限则通过
	if(powerString == "[Privilege]")
	{
		return;
	}
		
	//执行
	for(i = 0;i < document.all.length; i++)
	{
		var idString = document.all(i).id;
		var index = idString.indexOf("_Power_");
		var itemPower = "";
		if(index != -1)
		{
			itemPower = idString.substr(index + 7,idString.length - index - 7);
			if(powerString.indexOf("[" + itemPower + "]") == -1)
			{
				document.all(i).disabled = true;
			}
		}		
	}	
}

//检查执行权限
function CheckExecPower()
{
	return !event.srcElement.disabled;	
}

//获取正则节点函数(如正则表达式字符串，如：[UserID]3434[/UserID][CreateDateTime]1900-01-01 01:01:01[/CreateDateTime])
function GetRegexNode(regexString,nodeName)
{
	//如果是空字符串
	if(regexString == null || regexString == "") 
	{
		return "";
	}
	
	//获取整个节的字符串
	var patternStr = "\\[" + nodeName + "\\](.*)\\[/" + nodeName + "\\]";
	var reg = new RegExp(patternStr,"gi");
	var matchStr = regexString.match(reg);
	
	//获取节点值
	if(matchStr != null) 
	{
		reg = new RegExp("\\[" + nodeName + "\\]","gi");
		matchStr[0] = matchStr[0].replace(reg,"");
		reg = new RegExp("\\[/" + nodeName + "\\]","gi");
		matchStr[0] = matchStr[0].replace(reg,"");
		return matchStr[0];
	}
	else
	{
		return "";
	}
}

//整型验证
function CheckInteger(object)
{
	var pattern = /^\s*[-\+]?\d+\s*$/;
	if(object.match(pattern) == null)
	{
		return false;
	}
	if(object > 32767 || object < -32767)
	{
		return false;
	}
	return true;
}














































//初始化函数
function Initial(PageState,AditionalHeight)
{
	//初始化变量
	var path = location.href;
	var actionname = path.substr(path.lastIndexOf("/")+1,path.length-path.lastIndexOf("/"));

	//初始化BodyPanel高度
	if(AditionalHeight != -1)
	{
		document.all.BodyPanel.style.height = document.body.clientHeight - AditionalHeight;
	}
	
	//显示浮动层时界面处理
	if(PageState == "Insert" || PageState == "Update" || PageState == "Search" || PageState == "Import" || PageState == "SetPower" || PageState == "Accept" || PageState == "Sort" || PageState == "VerNo" || PageState == "SetRole" || PageState == "SetIcons" || PageState == "SetInstitution" || PageState == "Approve" || PageState == "CancelApprove" || PageState == "ReturnDraft" || PageState == "Other" || PageState == "Reject" || PageState == "Impersonation" || PageState == "Resume")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}
	}
	
	//删除警告
	else if(PageState == "RemoveAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要删除吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Remove";
			}
			else
			{
				actionname = actionname.replace("Brows","Remove");
				actionname = actionname.replace("RemoveAlert","Remove");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}
	
	//拒绝警告
	else if(PageState == "RejectAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要拒绝吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Reject";
			}
			else
			{
				actionname = actionname.replace("Brows","Reject");
				actionname = actionname.replace("RejectAlert","Reject");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}
	
	//清除警告
	else if(PageState == "ClearAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要清除吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Clear";
			}
			else
			{
				actionname = actionname.replace("Brows","Clear");
				actionname = actionname.replace("ClearAlert","Clear");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}	
	
	//重新计算警告
	else if(PageState == "ReCalculateAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要重新计算吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=ReCalculate";
			}
			else
			{
				actionname = actionname.replace("Brows","ReCalculate");
				actionname = actionname.replace("ReCalculateAlert","ReCalculate");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}		
	
	//应用警告
	else if(PageState == "ApplyAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要应用吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Apply";
			}
			else
			{
				actionname = actionname.replace("Brows","Apply");
				actionname = actionname.replace("ApplyAlert","Apply");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}

	//审核警告
	else if(PageState == "ApproveAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要审核吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Approve";
			}
			else
			{
				actionname = actionname.replace("Brows","Approve");
				actionname = actionname.replace("ApproveAlert","Approve");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}

	//撤销审核警告
	else if(PageState == "CancelApproveAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要撤销审核吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=CancelApprove";
			}
			else
			{
				actionname = actionname.replace("Brows","CancelApprove");
				actionname = actionname.replace("CancelApproveAlert","CancelApprove");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}				
	
	//退稿警告
	else if(PageState == "ReturnDraftAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要退稿吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=ReturnDraft";
			}
			else
			{
				actionname = actionname.replace("Brows","ReturnDraft");
				actionname = actionname.replace("ReturnDraftAlert","ReturnDraft");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}
	
	//创建警告
	else if(PageState == "CreateAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要创建吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Create";
			}
			else
			{
				actionname = actionname.replace("Brows","Create");
				actionname = actionname.replace("CreateAlert","Create");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}	
	
	//归档警告
	else if(PageState == "PigeonholeAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要归档吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Pigeonhole";
			}
			else
			{
				actionname = actionname.replace("Brows","Pigeonhole");
				actionname = actionname.replace("PigeonholeAlert","Pigeonhole");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}	
	
	//初始化警告
	else if(PageState == "InitializeAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要初始化吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Initialize";
			}
			else
			{
				actionname = actionname.replace("Brows","Initialize");
				actionname = actionname.replace("InitializeAlert","Initialize");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}		
	else if(PageState == "Apply")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}
	}
	//退稿警告
	else if(PageState == "ResumeAlert")
	{
		//显示掩盖层
		try
		{
			MaskDiv.style.display = "";
		}
		catch(Error)
		{
			//空
		}

		//提示
		if(window.confirm("确认要还原吗？"))
		{
			if(actionname.indexOf("PageState") == -1)
			{
				actionname += "&PageState=Resume";
			}
			else
			{
				actionname = actionname.replace("Brows","Resume");
				actionname = actionname.replace("ResumeAlert","Resume");
			}
			document.forms[0].action = actionname;
			document.forms[0].submit();
		}
		else
		{
			try
			{
				MaskDiv.style.display = "none";
			}
			catch(Error)
			{
				//空
			}
		}	
	}
}

//全选或反选函数
function Sel()
{
	oEl = event.srcElement;
	
	for(i = 0;i < document.all.tags("input").length; i++)
	{
		if(document.all.tags("INPUT")(i).id.indexOf("SelCheckBox") != -1)
		{
			if(oEl.checked)
				document.all.tags("INPUT")(i).checked = true;
			else
				document.all.tags("INPUT")(i).checked = false;
		}
	}
}
/*
==================================================================
LTrim(string):去除左边的空格
==================================================================
*/

function LTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

/*
==================================================================
RTrim(string):去除右边的空格
==================================================================
*/

function RTrim(str)
{
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;

        }
        s = s.substring(0, i+1);
    }
    return s;
}

/*
==================================================================
Trim(string):去除前后空格
==================================================================
*/

function Trim(str)
{
    return RTrim(LTrim(str));
}

