/**
 *
 *将字符串的首尾空格去除
 *
 */
function trim(s) {
	if (s == null) return s;

	var i, beginIndex = 0;
	var endIndex = s.length - 1;

	for (i=0; i<s.length; i++) {
		if (s.charAt(i) == ' ' || s.charAt(i) == unescape("%u3000")) {
			beginIndex++;
		} else {
			break;
		}
	}

	for (i = s.length - 1; i >= 0; i--) {
		if (s.charAt(i) == ' ' || s.charAt(i) == unescape("%u3000")) {
			endIndex--;
		} else {
			break;
		}
	}

	if (endIndex < beginIndex) {
		return "";
	}

	return s.substring(beginIndex, endIndex + 1);
}
/**
 *
 *打开意见编辑器(办公用语)
 *一般需在“textarea”上加右键事件，该textarea应有明确的id
 *代码例如<textarea id="LeaderMind0" name="LeaderMind0" runat="server" oncontextmenu="OpenOfficediction(this)"></textarea>
 *
 */
function OpenOfficediction(it)
{
	window.open("../myconfig/office_diction_page.aspx?documentname="+it.id,"diction",'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=640,height=480,left=200,top=80');
	event.returnValue=false;
}

/**
 *
 *打开附件相关窗口
 *
 */
function OpenAttachmentWindow(url) {
	window.open(url,null,'status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=600,height=600');
}

/**
 *
 *打开通知窗口
 *
 */
function OpenMsgView(url) {
	window.open(url,"msg",'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width=640,height=480,left=200,top=80');
}



function SetAttachfileInfo(fileid,filename,querystring)
{
	ReloadMe();
}
function DeleteAttachfileInfo(filecount)
{
	ReloadMe();
}

/**
 *
 *打开weboffice窗口
 *
 */
function OpenWebOffice(url) {
	window.open(url,"weboffice",'status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=2,top=2,width=' + (screen.width-15) + ',height=' + (screen.height-80) + '');
}


/**
 *
 *指定的字符串是否是纯数字字符
 *
 */
function isNumber(str) {
	for ( var i=0; i<str.length; i++ ) {
		if (str.charCodeAt(i)<0x0030 || str.charCodeAt(i)>0x0039) {
			return false;
		}
	}
	return true;
}


/**
 *
 *取得一个字符串的字节数长度
 *
 */
function GetStringCharCount(m_str)
{
	if(m_str==null)
	{
		return 0;
	}
	var cnt=0;
	for(var i=0;i<m_str.length;i++)
	{
		if(m_str.charCodeAt(i)<128)
		{
			cnt++;
		}
		else
		{
			cnt+=2;
		}
	}
	return cnt;
}

/**
 *
 *页面显示的动画效果
 *
 */
function doFilterBegin(obj)
{
	obj.filters.item(0).Apply();
	obj.filters.item(0).Transition=4;
	obj.filters.item(0).play(0.3);
}
/**
 *
 *onkeyup_chkNum
 *
 */
function onkeyup_chkNum(__objId)
{
	var temp = "";
	var sql = "0123456789.";
	var arr = new Array(2);
	for(i=0;i<__objId.value.length;i++)
	{
		if(sql.indexOf(__objId.value.charAt(i))>=0)
		{
			if(temp.indexOf(".")>=0)
			{
				if (__objId.value.charAt(i)==".")
				{
					break;
				}
				if(temp.split(".").length!=2)
				{
					break;
				}
				arr = temp.split(".");
				//if (arr[0].length>3)
				//{
				//	break;
				//}
				if (arr[1].length>1)
				{
					break;
				}
			}
			else
			{
				//if (__objId.value.charAt(i)!=".")
				//{
				//	if (temp.length>3)
				//	{
				//		break;
				//	}
				//}
			}
			temp = temp + __objId.value.charAt(i);
		}
	}
	__objId.value=temp;
	return;
}
/**
 *
 *onkeyup_chkInt
 *
 */
function onkeyup_chkInt(__objId)
{
	var temp = "";
	var sql = "0123456789";
	var arr = new Array(2);
	for(i=0;i<__objId.value.length;i++)
	{
		if(sql.indexOf(__objId.value.charAt(i))>=0)
		{
			temp = temp + __objId.value.charAt(i);
		}
	}
	__objId.value=temp;
	return;
}
/**
 *
 *手写意见录入
 *
 */
function openHandWrite(url)
{
	window.open(url,"handwrite",'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=210,top=155,width=800 ,height=550');
}
/**
 *
 *手写意见查看
 *
 */
function openHandWriteList(url)
{
	window.open(url,"handwriteList",'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=210,top=155,width=800 ,height=550');
}

/**
 *
 *滤除所有的特殊字符
 *
 */
function TrimHTML(it)
{
	var sText;
	if (typeof(it) == "string")
	{
		sText=it;
	}
	else
	{
		sText=it.value;
	}
	sText=sText.replace(/\</g,"").replace(/\>/g,"").replace(/\?/g,"").replace(/\|/g,"");
	sText=sText.replace(/\\/g,"").replace(/\;/g,"").replace(/\"/g,"").replace(/\//g,"");
	sText=sText.replace(/\'/g,"").replace(/\[/g,"").replace(/\]/g,"").replace(/\{/g,"");
	sText=sText.replace(/\}/g,"").replace(/\+/g,"").replace(/\&/g,"").replace(/\%/g,"");
	sText=sText.replace(/\#/g,"").replace(/\@/g,"").replace(/\!/g,"").replace(/\=/g,"");
	sText=trim(sText.replace(/ /g,""));
	if (typeof(it) == "string")
	{
		return sText;
	}
	else
	{
		it.value = sText;
	}
}
/*
 *
 *帮助
 *typeof(array) == "object"
 *typeof(td || input) == "object"
 *typeof(input.value) == "string"
 *根据一个字符串，强制转换其为一个可表达为金额型数字的字符串，若无法转换，则返回""
 *
 */
function genmoney(it)
{
	//Returns sText if value is a number
	//otherwise returns ""
	var sText;
	if (typeof(it) == "string")
	{
		sText=TrimHTML(it);
	}
	else
	{
		sText=TrimHTML(it.value);
	}
	if (sText.length == 0)
	{
		if (typeof(it) == "string")
		{
			return sText;
		}
		else
		{
			it.value = sText;
		}
	}
	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var sStartFormat = " .+-0123456789";
	var sNumberFormat = " .0123456789";
	var nCheckChar;
	var bDecimal = false;
	var bTrailingBlank = false;
	var bDigits = false;

	//The first character can be + - .  blank or a digit.
	nCheckChar = sStartFormat.indexOf(sText.charAt(0));
	//Was it a decimal?
	if (nCheckChar == 1)
		bDecimal = true;
	else if (nCheckChar < 1)
	{
		if (typeof(it) == "string")
		{
			return "";
		}
		else
		{
			it.value = "";
		}
	}
	
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < sText.length; i++) {
		nCheckChar = sNumberFormat.indexOf(sText.charAt(i));
		if (nCheckChar < 0)
			return "";
		else if (nCheckChar == 1) {
			if (bDecimal)		// Second decimal.
			{
				if (typeof(it) == "string")
				{
					return "";
				}
				else
				{
					it.value = "";
				}
			}
			else
				bDecimal = true;
		}
		else if (nCheckChar == 0) {
			if (bDecimal || bDigits)	
				bTrailingBlank = true;
		// ignore leading blanks
		}
			else if (bTrailingBlank)
			{
				if (typeof(it) == "string")
				{
					return "";
				}
				else
				{
					it.value = "";
				}
			}
		else
			bDigits = true;
	}	
	//All tests passed, so...
	if (typeof(it) == "string")
	{
		return sText;
	}
	else
	{
		it.value = sText;
	}
}
/*
 *
 *取得一个URL的包含指定级别的父目录的相对路径名
 *
 */
function GetPageurlWithParentPath(url,level)
{
	var s = url;
	var query = "";
	if (s.indexOf("?") > 0)
	{
		query = s.substr(s.indexOf("?"));
	}
	s = url.substr(0,url.length - query.length);
	if (s.replace("//" , "").indexOf("/") == s.replace("//" , "").lastIndexOf("/"))
	{
		return url;
	}
	var l = 2;
	if (typeof(level) == "number")
	{
		l = parseInt(level);
		if (l <= 1)
		{
			l = 2;
		}
	}
	for (var i=0;i<l;i++)
	{
		if (s.replace("//","").lastIndexOf("/")>=0)
		{
			query = s.substr(s.lastIndexOf("/")) + query;
			s = url.substr(0,url.length - query.length);
		}
		else
		{
			return url;
		}
	}
	return query;
}
/**
 *
 *数字型单元格的onblur事件
 *用于BizForm填写界面
 *
 */
function NumericInputOnblur(it)
{
	var old_value = it.value;
	if (old_value.length == 0)
	{
		return ;
	}
	if (isNaN(parseFloat(old_value)))
	{
		alert(it.title);
		it.focus();
		return ;
	}
	var new_value = parseFloat(genmoney(old_value));
	if (isNaN(new_value))
	{
		alert(it.title);
		it.focus();
		return ;
	}
	it.minvalue = parseFloat(it.minvalue);
	it.maxvalue = parseFloat(it.maxvalue);
	if ( ("" + it.minvalue).indexOf(".") < 0 )
	{
		it.minvalue = it.minvalue - 0.000001;
	}
	if ( ("" + it.maxvalue).indexOf(".") < 0 )
	{
		it.maxvalue = it.maxvalue + 0.000001;
	}
	if (new_value > it.maxvalue || new_value < it.minvalue)
	{
		alert(it.title);
		it.focus();
		return ;
	}
	it.value = new_value;
}
/**
 *
 *取得一个querystring
 *
 */
function Request(strkey){
	var url=window.location.toString().toLowerCase();
	var key=strkey.toLowerCase();
	var pos1=0,pos2=0;
	var strReturn="";
	pos1=url.indexOf("&"+key+"=");
	if(pos1==-1)
		pos1=url.indexOf("?"+key+"=");
	if(pos1==-1)
		return null;
	else{
		pos2=url.indexOf("&",pos1+1);
		if(pos2==-1)
			pos2=url.length;
		strReturn=window.location.toString().substring(pos1+key.length+2,pos2);
		strReturn=unescape(strReturn);
		return strReturn;
	}
}
/**
 *
 *ParentHeaderBarAdd
 *
 */
function ParentHeaderBarAdd(it)
{
	if (parent == window)
	{
		alert("the parent is not a mdi page!");
		return ;
	}
	if (parent.location.href.toLowerCase().indexOf("/mdi.htm") == -1)
	{
		try
		{
			parent.ParentHeaderBarAdd(it);
		}
		catch(e)
		{
		}
		return ;
	}
	parent.HeaderBarAdd(it.caption,it.href ? it.href : it.url,it.caption,it.noclose ? (parent.i_index == 0) : false);
	try
	{
		event.returnValue = false;
	}
	catch(e)
	{
	}
}
/**
 *
 *ParentHeaderBarParamChange
 *param:caption,url,noclose,change
 *
 */
function ParentHeaderBarParamChange(param , newvalue)
{
	if (parent == window)
	{
		alert("the parent is not a mdi page!");
		return ;
	}
	if (parent.location.href.toLowerCase().indexOf("/mdi.htm") == -1)
	{
		try
		{
			parent.ParentHeaderBarParamChange(it);
		}
		catch(e)
		{
		}
		return ;
	}
	parent.HeaderBarParamChange(param , newvalue);
	try
	{
		event.returnValue = false;
	}
	catch(e)
	{
	}
}

/**
 *
 *Chk_Document_Change
 *
 */
var Chk_Document_Change_Old_Values = null;
var Chk_Document_Change_Changed = false;
function Chk_Document_Change()
{
	if (Chk_Document_Change_Changed || parent.location.href.toLowerCase().indexOf("/mdi.htm") == -1)
	{
		return ;
	}
	var s = "";
	var objs = document.getElementsByTagName("INPUT");
	for (i = 0 ; i < objs.length ; i++)
	{
		s += objs[i].value;
	}
	objs = document.getElementsByTagName("TEXTAREA");
	for (i = 0 ; i < objs.length ; i++)
	{
		s += objs[i].value;
	}
	if (Chk_Document_Change_Old_Values == null)
	{
		try
		{
			parent.HeaderBarParamChange("change" , false);
		}
		catch(e)
		{
			Chk_Document_Change_Changed = true;
			Chk_Document_Change_Old_Values = "";
			return ;
		}
		Chk_Document_Change_Old_Values = s;
	}
	else if (Chk_Document_Change_Old_Values != s)
	{
		try
		{
			parent.HeaderBarParamChange("change" , true);
		}
		catch(e)
		{
		}
		Chk_Document_Change_Changed = true;
		Chk_Document_Change_Old_Values = "";
	}
}
//end Chk_Document_Change

function refuse()
{
	try
	{
		event.returnValue = false;
	}
	catch(e)
	{
	}
}
/**
 *
 *打开附件相关脚本
 *
 */
var attachfile_frame_handle;
var attachfile_setinterval_handle = null;
function OpenIframe_hid_for_attachfile()
{
	if (attachfile_setinterval_handle)
	{
		window.clearInterval(attachfile_setinterval_handle);
		attachfile_setinterval_handle = null;
		try{frame_handle.close();}catch(e){};
	}
	frame_handle = window.open("about:blank","Iframe_hid_for_attachfile","status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=" + ((screen.width-50)/2) + ",top=" + ((screen.height-50)/2) + ",width=50,height=50");
	try
	{
		event.srcElement.target = "Iframe_hid_for_attachfile";
	}
	catch(e)
	{
	}
	attachfile_setinterval_handle = window.setInterval("try{frame_handle.close();}catch(e){}" , 1000 , "javascript");
}

/**
 *
 *附件上传事件相关脚本
 *
 */
var old_filepath = "";
var old_filename = "";
var maxSize = 1024 * 1024 * 10;
var extnamelist = "xls,pdf,doc,jpg,gif,jpeg,avi,wav,mpg,mpeg,mp3,xkh";
function Input_File_Control_onchange()
{

	InsertInternetFileControl();
	var it =event.srcElement;
	var s = it.value;
	if (s.length == 0 || s == old_filepath)
	{
		return ;
	}
	if (s.indexOf(".") <= 0)
	{
		/**
		 *
		 *请选择合理的文件类型，正确的文件类型扩展名限于：
		 *
		 */
		var s = "%u8BF7%u9009%u62E9%u5408%u7406%u7684%u6587%u4EF6%u7C7B%u578B%uFF0C%u6B63%u786E%u7684%u6587%u4EF6%u7C7B%u578B%u6269%u5C55%u540D%u9650%u4E8E%uFF1A";
		alert(unescape(s) + "\n" + extnamelist + " !");
		it.form.reset();
		return ;
	}
	var extname = s.substr(s.lastIndexOf(".") + 1).toLowerCase();
	if ( ("," + extnamelist + ",").indexOf("," + extname + ",") < 0 )
	{
		/*
		 *
		 *您所选择的文件类型“
		 *”不允许被上传，正确的文件类型扩展名限于：
		 *
		 */
		alert(unescape("%u60A8%u6240%u9009%u62E9%u7684%u6587%u4EF6%u7C7B%u578B%u201C") + extname + unescape("%u201D%u4E0D%u5141%u8BB8%u88AB%u4E0A%u4F20%uFF0C%u6B63%u786E%u7684%u6587%u4EF6%u7C7B%u578B%u6269%u5C55%u540D%u9650%u4E8E%uFF1A") + "\n" + extnamelist + " !");
		it.form.reset();
		return ;
	}
	if (InternetFile.GetFileSize(it.value) > maxSize)
	{
		/**
		 *
		 *文件过大，系统限制单个文件不得大于 
		 *
		 */
		alert(unescape("%u6587%u4EF6%u8FC7%u5927%uFF0C%u7CFB%u7EDF%u9650%u5236%u5355%u4E2A%u6587%u4EF6%u4E0D%u5F97%u5927%u4E8E") + " " + (maxSize / 1024 / 1024) + "M !");
		it.form.reset();
		old_filepath = "";
		old_filename = "";
		return ;
	}
	old_filepath = s;
	old_filename = s.substring(s.lastIndexOf("\\") + 1 , s.lastIndexOf("."));
}


/**
 *
 *插入文件输入框检测控件
 *
 */
function InsertInternetFileControl()
{
	if (document.all("InternetFile") == null)
	{
		document.body.insertAdjacentHTML("beforeEnd" , "<OBJECT id=InternetFile style='display:none' CLASSID='CLSID:6B9EE84E-1D5A-11DB-AC25-0003FFA57CA7' CODEBASE='../inc/cab/InternetFile.CAB#version=1,0,0,0' VIEWASTEXT></OBJECT>");
	}
}

/**
 *
 *加载全局检测事件
 *目前主要有：是否页面中有文本输入框
 *是否页面需注册已输入：需同步到MDI中的红色*号
 *
 */
var UseChk_Document_Change = false;

function CheckOnLoad_ByComm()
{
	if (parent.location.href.toLowerCase().indexOf("/mdi.htm") > 0 && (parent.frames[0] != window || UseChk_Document_Change))
	{
		window.setInterval("Chk_Document_Change();" , 3000 , "javascript");
	}
	if(window.document.forms.length > 0 && window.document.forms[0].enctype.toLowerCase() == "multipart/form-data")
	{
		window.setInterval("InsertInternetFileControl();" , 500 , "javascript");
	}
}

document.onreadystatechange = function()
{
	if ((document.readyState + "").toLowerCase() == "complete")
	{
		CheckOnLoad_ByComm();
		Chk_Document_Change();
	}
}

/**
 *
 *ReloadMe
 *
 */
function ReloadMe()
{
	window.location = window.location.href;
}

/**
 *
 *关闭并还原DIV的路径
 *
 */
function ClientDivClose()
{
	try
	{
		refuse();
		parent.document.all("Btn_Tailorform").click();
		parent.location = parent.location.href;
	}
	catch(e){}
}

/*
*根据href刷新特定的window
*/
function ReloadWindows()
{	
	//var index = parent.parent.window.GetIndexByAbsoluteUri(document.getElementById("parenthref").value);
	
	//parent.parent.window.frames[index].location = parent.parent.window.frames[index].location.href;
	//alert("改变MDI上的状态");
	//改变MDI上的状态
	parent.window.HeaderBarParamChange('change', 0);
}

/*
*根据设置页面table的显示颜色
*/
function Load_Table_BorderColor(color)
{
	var obj = document.all("summarytable");
	if ( obj == null )
	{
		return;
	}
	obj.borderColor = color;
}
/*
设置弹出DIV框隐藏
*/
function Div_Hidden()
{
	parent.document.getElementById('client_div').style.display='none';		
	var objtable = parent.document.all("ConveringTable");
	if ( objtable == null )
	{
		return;
	}
	objtable.style.display='none';
}

/*
* 打开自由裁量窗体
*/
function OpenPowerPunishWindow(ctl)
{
	ParentHeaderBarAdd(ctl);
}

/*
*根据href刷新特定的window
*/
function ReloadWindows()
{	//alert(document.getElementById("parenthref").value);
	var index = parent.parent.window.GetIndexByAbsoluteUri(document.getElementById("parenthref").value);
	//alert(index);
	parent.parent.window.frames[index].location = parent.parent.window.frames[index].location.href;
	
	//改变MDI上的状态
	parent.parent.window.HeaderBarParamChange('change', 0);
}