/******************************************************
描述：	显示指定大小风格固定的模式对话框
返回：	对话框的返回值
参数：	strURL 对话框文件地址
		intWidth 对话框的宽度
		intHeight 对话框的高度
		aryParam 对话框的传入参数
******************************************************/
function openDialog(strURL, intWidth, intHeight, aryParam){
	return window.showModalDialog(strURL,aryParam,'dialogHeight:' + intHeight + 'px;dialogWidth:' + intWidth + 'px;status:no;resizable:no;help:no;center:yes;');

}
/******************************************************
描述：	打开指定大小风格固定的新窗口
返回：	对话框的返回值
参数：	strfileName 对话框文件地址
		intWidth 对话框的宽度
		intHeight 对话框的高度
******************************************************/
function openNewWindow(strfileName,intWidth, intHeight){
	var d = Math.floor(Math.random() * 10000000000000000);
	var StrWindowName = "ExGovInfoWindow" + d.toString();
	window.open(strfileName,StrWindowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=" + intWidth + ",height=" + intHeight )
}

function openInfoWindow(strfileName,intWidth, intHeight){
	var d = Math.floor(Math.random() * 10000000000000000);
	var StrWindowName = "ExGovInfoWindow" + d.toString();
	window.open("Department.asp?Redirect="+strfileName,StrWindowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=" + intWidth + ",height=" + intHeight )
	//var newwin=window.open(strfileName,StrWindowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=" + intWidth + ",height=" + intHeight )

}

function openNewFullWindow(strfileName,intWidth,intHeight) {
	var d = Math.floor(Math.random() * 10000000000000000);
	var StrWindowName = "ExGovInfoWindow" + d.toString();
	window.open("Department.asp?Redirect="+strfileName,StrWindowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,top=0,left=0,width=" + intWidth + ",height=" + intHeight )
}

//关闭当前窗口
function closeCurWindow(){
	window.close();
}
/******************************************************
描述：	显示选择用户的对话框
返回：	返回被选择的用户数组
参数：	strUserFormURL 选择用户的表单文件所在路径
		aryUser 已选用户数组
******************************************************/
function selectUsers(strUserFormURL, aryUser){
	return openDialog(strUserFormURL, 500, 550, aryUser);
}
/******************************************************
描述：	显示选择栏目的对话框
返回：	返回被选择的栏目集合对象
参数：	strMenuFormURL 选择栏目的表单文件所在路径
		oMenus 已选栏目集合对象
******************************************************/
function selectMenus(strMenuFormURL, oMenus){
	return openDialog(strMenuFormURL, 500, 550, oMenus);
}
/******************************************************
描述：	检查指定的字符串是否符合指定规则
返回：	不包含则返回true。否则返回false。
参数：	strInputString	用户输入字符串
		bolPermitNull	是否允许字符串为空
		bolCheckChar	是否对特殊字符进行校验
		bolInputCN		是否允许输入中文
		intMaxLength	字符串允许的最大长度
******************************************************/
function checkInputString(strInputString, bolPermitNull, bolCheckChar, bolInputCN, intMaxLength){
	//校验字符串是否为空
	if (!bolPermitNull){
		if (strInputString == '' || strInputString == null)
			return false;
	}
	
	//校验字符串中是否包含特殊字符
	
	if (bolCheckChar){
		if (bolInputCN){
			if (!checkInputStringCharCN(strInputString)){
				return false;
			}
		}else{
			if (!checkInputStringChar(strInputString)){
				return false;
			}		
		}
	}
	//校验字符串的长度
	if (intMaxLength != null){
		if (strInputString.length > intMaxLength)
			return false;
	}
	return true;
}

/******************************************************
描述：	检查指定的字符串是包含特殊字符(只包含英文、数字及下划线)
返回：	不包含则返回true。否则返回false。
参数：	用户输入地字符串
******************************************************/
function checkInputStringChar(strInputString){
	strInputString = trimStr(strInputString);
	var i;
	for (i=0; i<strInputString.length; i++){
		if (!((strInputString.charCodeAt(i) >= 65 && strInputString.charCodeAt(i) <= 90)||(strInputString.charCodeAt(i) >= 97 && strInputString.charCodeAt(i) <= 122)||(strInputString.charCodeAt(i) >= 48 && strInputString.charCodeAt(i) <= 57) || strInputString.charCodeAt(i) == 95)){
			return false;
		}
	}
	return true;
}
/******************************************************
描述：	检查指定的字符串是包含特殊字符(只包含英文、数字、下划线及中文)
返回：	不包含则返回true。否则返回false。
参数：	用户输入地字符串
******************************************************/
function checkInputStringCharCN(strInputString){
	strInputString = trimStr(strInputString);
	var i;
	for (i=0; i<strInputString.length; i++){
		if (!((strInputString.charCodeAt(i) >= 8481 && strInputString.charCodeAt(i) <= 63486) || (strInputString.charCodeAt(i) >= 65 && strInputString.charCodeAt(i) <= 90)||(strInputString.charCodeAt(i) >= 97 && strInputString.charCodeAt(i) <= 122)||(strInputString.charCodeAt(i) >= 48 && strInputString.charCodeAt(i) <= 57) || strInputString.charCodeAt(i) == 95)){
			return false;
		}
	}
	return true;
}
//校验用户输入是否是数字

function IsDigit()
{
	return ((event.keyCode >= 48) && (event.keyCode <= 57))
}
/******************************************************
描述：	执行服务器端的程序文件
返回：	成功则返回程序执行结果。失败则返回-1
参数：	strPrgmURL	程序文件路径
		strMethod	发送方法（POST或GET）
		strParamString POST方法时的参数字符串
******************************************************/
function ExecServerPrgm(strPrgmURL, strMethod, strParamString, strUserID, strPwd)
{
	try{ 
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (strUserID != "" && strUserID != null)
			xmlhttp.Open(strMethod, strPrgmURL, false, strUserID, strPwd);
		else
			xmlhttp.Open(strMethod, strPrgmURL, false);
			
		if (strMethod.toUpperCase() == 'POST'){ 
			strParamString = ExEscape(strParamString);
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.Send(strParamString);
		}else{
			xmlhttp.Send();				
		}
		if (xmlhttp.status == 200)
			return unescape(trimStr(xmlhttp.responseText));
		else
			return -1;
	}catch(e){
		return -1;
	}
}

/******************************************************
描述：	刷新页面
返回：	
参数：	
******************************************************/
function refreshPage(){
	window.location.href = window.location.href;
}
/******************************************************
描述：	去掉字符串的前后空格
返回：	
参数：	
******************************************************/
function trimStr(sVal)
{
	var iPos;
	//clear starting space
	while(true)
	{
		iPos = sVal.indexOf(' ');
		if(iPos == -1) break;
		if(iPos > 0) break;
		sVal = sVal.slice(1);
	}
	//clear ending space
	while(true)
	{
		iPos = sVal.lastIndexOf(' ');
		if(iPos == -1) break;
		if(iPos < sVal.length-1) break;
		sVal = sVal.slice(0, iPos);
	}
	return(sVal);
}
/******************************************************
描述：	根据权限对象构造权限XML字符串
返回：	表达权限的XML字符串
参数：	XMLDom对象
******************************************************/
function getRightXmlString(oRight){
	var strXmlString = "";
	for(i=0; i<oRight.documentElement.selectNodes("node").length; i++){
		strXmlString = strXmlString + "<right>";
		var oTempNode = oRight.documentElement.selectNodes("node").item(i);
		
		//部门节点
		
		if (oTempNode.selectSingleNode("nodetype").text == '1'){
			strXmlString = strXmlString + "<dept>" + oTempNode.selectSingleNode("nodeid").text + "</dept>";
			strXmlString = strXmlString + "<role></role>";
			strXmlString = strXmlString + "<user></user>";					
		}
		
		//角色节点
		
		if (oTempNode.selectSingleNode("nodetype").text == '2'){
			strXmlString = strXmlString + "<dept>" + oTempNode.selectSingleNode("parentid").text + "</dept>";
			strXmlString = strXmlString + "<role>" + oTempNode.selectSingleNode("nodeid").text + "</role>";
			strXmlString = strXmlString + "<user></user>";
		}
		
		//用户节点
		
		if (oTempNode.selectSingleNode("nodetype").text == '3'){
			strXmlString = strXmlString + "<dept></dept>";
			strXmlString = strXmlString + "<role></role>";
			strXmlString = strXmlString + "<user>" + oTempNode.selectSingleNode("nodeid").text + "</user>";					
		}
		
		//系统角色节点
		
		if (oTempNode.selectSingleNode("nodetype").text == '11'){
			strXmlString = strXmlString + "<dept></dept>";
			strXmlString = strXmlString + "<role>" + oTempNode.selectSingleNode("nodeid").text + "</role>";
			strXmlString = strXmlString + "<user></user>";					
		}
		strXmlString = strXmlString + "</right>";
	}
	return strXmlString;
}
//对特殊字符进行处理
function encodeString(strInputString){
	strInputString = strInputString.replace(/\'/g,"\'\'")
	strInputString = strInputString.replace(/&/g,"&amp;")
	strInputString = strInputString.replace(/>/g,"&gt;")
	strInputString = strInputString.replace(/</g,"&lt;")
	return strInputString;
}
//查看指定信息。
strInfoViewPath = "http://www.gzfood.cn/SysParts/DepartDoc/InfoView.aspx";
function infoView(strInfoID){
	openInfoWindow(strInfoViewPath + "?InfoID=" + strInfoID, 600, 480);
}
//得到指定文件的扩展名
function getFileType(strFilePath){
	var intP = strFilePath.lastIndexOf('.');
	if (intP != -1)
		return strFilePath.substring(intP, strFilePath.length);
	else
		return '';
}

/******************************************************
描述：	检查指定的字符串是否符合指定规则
返回：	不包含则返回true。否则返回false。
参数：	strInputString	用户输入字符串
		bolPermitNull	是否允许字符串为空
		bolCheckChar	是否对特殊字符进行校验
		bolInputCN		是否允许输入中文
		intMaxLength	字符串允许的最大长度
******************************************************/
function validateInputString(strInputString, bolPermitNull, bolCheckChar, bolInputCN, intMaxLength){
	//校验字符串是否为空
	if (!bolPermitNull){
		if (strInputString == '' || strInputString == null)
			return false;
	}
	
	//校验字符串中是否包含特殊字符
	
	if (bolCheckChar){
		if (bolInputCN){
			if (!validateInputStringCharCN(strInputString)){
				return false;
			}
		}else{
			if (!validateInputStringChar(strInputString)){
				return false;
			}		
		}
	}
	//校验字符串的长度
	if (intMaxLength != null){
		if (strInputString.length > intMaxLength)
			return false;
	}
	return true;
}
/******************************************************
描述：	检查指定的字符串是包含特殊字符(只包含英文、数字及下划线)
返回：	不包含则返回true。否则返回false。
参数：	用户输入地字符串
******************************************************/
function validateInputStringChar(strInputString){
	strInputString = trimStr(strInputString);
	var i;
	for (i=0; i<strInputString.length; i++){
		var chrChar = strInputString.charAt(i);
		if (validateSingleChar(chrChar))
			return false;
	}
	return true;
}
/******************************************************
描述：	检查指定的字符串是包含特殊字符(只包含英文、数字、下划线及中文)
返回：	不包含则返回true。否则返回false。
参数：	用户输入地字符串
******************************************************/
function validateInputStringCharCN(strInputString){
	strInputString = trimStr(strInputString);
	var i;
	for (i=0; i<strInputString.length; i++){
		var chrChar = strInputString.charAt(i);
		if (validateSingleChar(chrChar)){
			if (strInputString.charCodeAt(i) < 8481 && strInputString.charCodeAt(i) > 63486) 
				return false;
		}
	}
	return true;
}

function validateSingleChar(chrChar){
	if (chrChar.charCodeAt(0) >= 21 && chrChar.charCodeAt(0) <= 255){
		return false;
	}
	return true;
}

/******************************************************
描述：	清空指定Select列表框的所有选项
返回：	true OR false
参数：	Select对象
******************************************************/
function clearSelectOptions(oSel){
	try{
		var intOptionLength = oSel.options.length;
		for (var i=0;i<intOptionLength;i++)
		{
			oSel.options.remove(0);
		}
		return true;
	}catch(e){
		return false;
	}
}

/********************************************************************************

********************************************************************************/
			//检查电话
			function checkPhone(strInputPhone)
			{
				var i;
				for (i=0; i<strInputPhone.length; i++)
				{
					var iCode = strInputPhone.charCodeAt(i);					
					if(iCode != 45)
					{
						if (iCode < 48 || iCode > 57)
						{
							return false;
						}
					}
				}				
				if(strInputPhone.indexOf("--",1) != -1 || strInputPhone.length < 7 ||strInputPhone.length >15)
				{
					return false;
				}
				
				return true;				
			}
			
			//检查年龄
			function checkAge(strInputAge)
			{
				var i;
				for (i=0; i<strInputAge.length; i++)
				{
					var iCode = strInputAge.charCodeAt(i);					
					
					if (iCode < 48 || iCode > 57)
					{
						return false;
					}					
				}
				if(strInputAge < 0 || strInputAge > 150)
				{
					return false;
				}
				return true;
			}
			
			//检查邮政编码
			function checkZip(strInputZip)
			{
				var i;
				for (i=0; i<strInputZip.length; i++)
				{
					var iCode = strInputZip.charCodeAt(i);					
					
					if (iCode < 48 || iCode > 57)
					{
						return false;
					}
					
				}
				if(strInputZip.length != 6)
				{
					return false;
				}
				return true;		
			}
			
			//验证url
			function checkUrl(strInputUrl)
			{
				var httpHead = strInputUrl.substring(0,7);
				if( httpHead.toUpperCase() != "HTTP://")
				{
					return false;
				}
				return true;
			}
			
			//清空输入
			function clearInput()
			{
				var i;
				var oItem;
				var oAllItems = document.all.tags("INPUT")
				for (i=0;i<oAllItems.length;i++)
				{
					oItem = oAllItems.item(i);
					if(oItem.type.toLowerCase()=='text' || oItem.type.toLowerCase() == 'password')
					{
						oItem.value = '';
					}
				}
			}
         function Navigator(PartID,Url,InfoID,intWidth,intHeight)
		  {
			if(InfoID=='')
			{
				if(Url!=null && Url!="")
				{
					window.open("Department.asp?Redirect="+Url,"","toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,top=0,left=0,width=" + intWidth + ",height=" + intHeight );
				}else
				{
					return;
				}
			}
			else
			{
			    infoView(InfoID);
			}
			
		  }
		  
		  
		  
		  
		  
		  
		  function NavigatorPage(PageID,Url,DepartID)
		  {
			oXmlCurAD = new ActiveXObject("Microsoft.XMLDOM");
			oXmlCurAD.loadXML("<data></data>");
			var strParamString = "<param><action>pagecount</action><pagecount><pageid>" + PageID + "</pageid></pagecount></param>";
			var strURL = '/CmdCount.aspx';
			var strResult = ExecServerPrgm(strURL, 'POST', 'param='  + escape(strParamString));
			window.location.href=Url;
		  }
		  
function ExEscape(strParam)
{
	strParam = strParam.replace(/</g, "##");
	strParam = strParam.replace(/%3C/g, "##");
	strParam = strParam.replace(/>/g, "**");
	strParam = strParam.replace(/%3E/g, "**");
	return strParam;
}
//add by wangl on 2003-11-26
function EspecialExEscape(strParam)
{
	strParam = strParam.replace(/</g, "@@");
	strParam = strParam.replace(/%3C/g, "@@");
	strParam = strParam.replace(/>/g, "**");
	strParam = strParam.replace(/%3E/g, "**");
	return strParam;
}

//用于屏蔽掉当鼠标指向信息列表中信息时状态栏显示相对路径信息。
function View(strPartID,strParam,strInfoID,intwidth,intheight)
{ 
	
	if(strInfoID!="")
	{
		Navigator(strPartID,"",strInfoID,intwidth,intheight);
	}else
	{
		var strTemp="/Sys/PagePrgm/MoreInfoPage.aspx?";
		Navigator(strPartID,strTemp+strParam,"",intwidth,intheight);
	}
}





			//add by wangl on 20040605
			//打开对应内网信息新窗口
         function SpecialNavigator(Url,intWidth,intHeight)
		  {
				if(Url!=null && Url!="")
				{
					window.open(Url,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=" + intWidth + ",height=" + intHeight );
				}else
				{
					return;
				}
		  }
		  
		  
		  
		  
		  //#######################################################################################

//          function:            convert the UTF-8 string to normal format

//          parameter:         szInput

//          explain: 

//          return:               the string that have been coverted

//          Example:          unicodeFromUtf8(unescape(url))

//#######################################################################################

function Utf8ToUnicode(strUtf8) 

{

            var bstr = "";

            var nTotalChars = strUtf8.length;  // total chars to be processed.

            var nOffset = 0;                                                  // processing point on strUtf8

            var nRemainingBytes = nTotalChars;       // how many bytes left to be converted

            var nOutputPosition = 0;

            var iCode, iCode1, iCode2;                                  // the value of the unicode.

            

            while (nOffset < nTotalChars)

            {

                        iCode = strUtf8.charCodeAt(nOffset);

                        if ((iCode & 0x80) == 0)                          // 1 byte.

                        {

                                    if ( nRemainingBytes < 1 )                      // not enough data

                                                break;

 

                                    bstr += String.fromCharCode(iCode & 0x7F);

                                    nOffset ++;

                                    nRemainingBytes -= 1;

                        }

                        else if ((iCode & 0xE0) == 0xC0) // 2 bytes

                        {

                                    iCode1 =  strUtf8.charCodeAt(nOffset + 1);

                                    if ( nRemainingBytes < 2 ||                                  // not enough data

                                                 (iCode1 & 0xC0) != 0x80 )                      // invalid pattern

                                    {

                                                break;

                                    }

 

                                    bstr += String.fromCharCode(((iCode & 0x3F) << 6) | (      iCode1 & 0x3F));

                                    nOffset += 2;

                                    nRemainingBytes -= 2;

                        }

                        else if ((iCode & 0xF0) == 0xE0) // 3 bytes

                        {

                                    iCode1 =  strUtf8.charCodeAt(nOffset + 1);

                                    iCode2 =  strUtf8.charCodeAt(nOffset + 2);

                                    if ( nRemainingBytes < 3 ||                                  // not enough data

                                                 (iCode1 & 0xC0) != 0x80 ||                     // invalid pattern

                                                 (iCode2 & 0xC0) != 0x80 )

                                    {

                                                break;

                                    }

 

                                    bstr += String.fromCharCode(((iCode & 0x0F) << 12) | 

                                                            ((iCode1 & 0x3F) <<  6) |

                                                            (iCode2 & 0x3F));

                                    nOffset += 3;

                                    nRemainingBytes -= 3;

                        }

                        else                                                                                          // 4 or more bytes -- unsupported

                                    break;

            }

 

            if (nRemainingBytes != 0)

            {

                        // bad UTF8 string.

                        return "";

            }

            

            return bstr;

}
