//<script>
	//*****************文件描述********************
	//文件名: DataCheck.js
	//版本:1.0
	//作者:刘晓雷
	//描述:FORM 数据合法性检查
	//创建日期:2004.6.30
	//*********************************************
	
	//*******************************************************
	//	function fnCheckStr(bAllowNull,intMaxLen)
	//	描述:检查字符串
	//	
	//	参数:
	//		strValue:	字符串
	//		intMaxLen:	最大长度
	//		bAllowNull:	是否必填
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckStr(objValue,bAllowNull,intMaxLen)
	{
		objValue=trim(objValue);
		if(objValue =="" && !bAllowNull) return false;
		if(objValue.length > intMaxLen) return false;
		return true;
	}
	
	//*******************************************************
	//	function fnCheckNumber(bAllowNull,intMaxValue)
	//	描述:检查数字
	//	
	//	参数:
	//		intMaxValue:最大值
	//		bAllowNull:	是否必填
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckNumber(objValue,bAllowNull,intMaxValue)
	{
		var i;
		//objValue=trim(objValue);
		if(objValue == "" && bAllowNull) return true;
		if(objValue == "" && !bAllowNull) return false;
		if(objValue * 1 > intMaxValue)
		{
			return false;
		}
		for(i=0;i<objValue.length;i++)
		{
			if( (objValue.charAt(i) < "0" || objValue.charAt(i) > "9") && objValue.charAt(i) != "-" && objValue.charAt(i) != "+"  && objValue.charAt(i) != "." )
				return false;
		}
		return true;
	}
	
	//*******************************************************
	//	function fnCheckDate(bAllowNull)
	//	描述:检查日期
	//	
	//	参数:
	//		bAllowNull:	是否必填
	//		strFormat:	YYYYMM/YYYYMMDD
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckDate(objValue,bAllowNull,strFormat)
	{
		var objDate;
		var intYYYY,intMM,intDD;
		var i,i1,intTempYear;
		objValue=trim(objValue);
		if(objValue == "" && bAllowNull) return true;
		if(objValue == "" && !bAllowNull) return false;
		
		
		switch(strFormat)
		{
			case "YYYYMM":
				i=objValue.indexOf("-")
				if(i==-1) return false;
				intYYYY=objValue.substring(0,i);
				intMM=objValue.substring(i+1);
				
				if(intYYYY  =="" || intMM =="" ) return false;
				intMM--;
				objDate=new Date(intYYYY,intMM,1);
				intTempYear=objDate.getYear();
				if(intTempYear < 100) intTempYear+=1900;
				if(intTempYear < 1900) return false;
				//alert(objDate);
				//alert(objDate.getMonth());
				if (intYYYY==intTempYear && intMM==objDate.getMonth())
				{
				}
				else
				{
					return false;
				}

				break;
			case "YYYYMMDD":
				i=objValue.indexOf("-")
				if(i==-1) return false;
				intYYYY=objValue.substring(0,i);
				i1=objValue.lastIndexOf("-")
				if(i1==-1) return false;
				if(i==i1) return false;
				intMM=objValue.substring(i+1,i1);
				intDD=objValue.substring(i1+1);
				//alert(intYYYY +"_" + intMM + "_" + intDD);
				if(intYYYY  =="" || intMM =="" || intDD=="") return false;
				intMM--;
				objDate=new Date(intYYYY,intMM,intDD);
				intTempYear=objDate.getYear();
				
				//alert(intTempYear);
				//alert(objDate);
				if(intTempYear < 100) intTempYear+=1900;				
				if(intTempYear < 1900) return false;
				
				//alert(objDate.getMonth());
				if (intYYYY==intTempYear && intMM==objDate.getMonth())
				{
				}
				else
				{
					return false;
				}
				break;
		}
		
		return true;
	}
	
	//*******************************************************
	//	function fnCheckEmail(bAllowNull)
	//	描述:检查Email
	//	
	//	参数:
	//		bAllowNull:	是否必填
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckEmail(objValue,bAllowNull)
	{
		objValue=trim(objValue);
		if(objValue == "" && bAllowNull) return true;
		if(objValue == "" && !bAllowNull) return false;
		
		if(objValue.indexOf("@") == -1)
			return false;
		if(objValue.indexOf(".") == -1)
			return false;
		if(objValue.indexOf("@") == 0)
			return false;
		if(objValue.indexOf("@") != objValue.lastIndexOf("@"))
			return false;
		
		return true;
	}
	
	//*******************************************************
	//	function fnCheckIDCard(bAllowNull,strBirthday,intSex)
	//	描述:检查身份证号
	//	
	//	参数:
	//		bAllowNull:	是否必填
	//		strBirthday: 生日
	//		intSex:		性别(1:男,2:女)
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckIDCard(objValue,bAllowNull,strBirthday,intSex)
	{
		//objValue=trim(objValue);
		
		if(objValue == "" && bAllowNull) return true;
		if(objValue == "" && !bAllowNull) return false;
		
		if(objValue.length != 15 && objValue.length !=18)
			return false;
		
		for(i=0;i<objValue.length;i++)
		{
			if(objValue.charAt(i) < "0" || objValue.charAt(i) > "9")
				return false;
		}
		return true;
	}
	
	//*******************************************************
	//	function fnCheckPhone(bAllowNull)
	//	描述:检查电话号码
	//	
	//	参数:
	//		bAllowNull:	是否必填
	//	返回:
	//		True:合法 False:非法
	//*******************************************************	
	function fnCheckPhone(objValue,bAllowNull)
	{
		objValue=trim(objValue);
		if(objValue == "" && bAllowNull) return true;
		if(objValue == "" && !bAllowNull) return false;
		return true;
	}

	//*******************************************************
	//	function fnCheckZipCode(bAllowNull)
	//	描述:检查邮编
	//	
	//	参数:
	//		bAllowNull:	是否必填
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckZipCode(objValue,bAllowNull)
	{
		//objValue=trim(objValue);
		if(objValue == "" && bAllowNull) return true;
		if(objValue == "" && !bAllowNull) return false;
		
		if(objValue.length != 6) return false;
		for(i=0;i<objValue.length;i++)
		{
			if(objValue.charAt(i) < "0" || objValue.charAt(i) > "9")
				return false;
		}
		return true;
	}
	//*******************************************************
	//	function CheckRadioSelected(objRadioButton)
	//	描述:检查RADIOBUTTON是否选中
	//	
	//	参数:
	//		bAllowNull:	是否必填
	//	返回:
	//		True:选中 False:为选
	//*******************************************************		
	function CheckRadioSelected(objRadioButton)
	{
		var i,bChecked;
		bChecked=false;
		
		for(i=0;i<objRadioButton.length;i++)
		{	
			
			if(objRadioButton[i].checked)
				bChecked=true;
		}
		return bChecked;
		
	}	

	//*******************************************************
	//	function fnCheckNull(objValue)
	//	描述:检查是否为空
	//	
	//	参数:
	//		-
	//	返回:
	//		True:合法 False:非法
	//*******************************************************		
	function fnCheckNull(objValue)
	{
		objValue=trim(objValue);
		if(objValue =="") 
			return false;
		else
			return true;
	}
	
	function ltrim(str)
	{
		for(var i = 0 ; i<str.length && str.charAt ==" " ; i++ ) ;
		return str.substring(i,str.length); 
	}
	function rtrim(str)
	{
		for(var i = str.length ; i>0 && str.charAt ==" " ; i-- ) ;
		return str.substring(0,i); 
	}
	function trim(str)
	{
		return str.replace(/(^\s*)|(\s*$)/g,"");
	}	
//</script>
