function ValidateMust(objfrm)
{
	for (i=0; i<objfrm.elements.length; i++)
	{
		if (objfrm.elements[i].mustfill)
			if (objfrm.elements[i].mustfill=='true' && objfrm.elements[i].value=='')
			{
				alert('请将所有必填的内容填完!');
				objfrm.elements[i].focus();
				return false;
			}
	}
	return true;
}

function IfCheck(formobj, checkname)
{
	for (i=0; i<formobj.elements.length; i++)
	{
		if (formobj.elements[i].name == checkname && formobj.elements[i].checked)
			return confirm('确定要删除选中项吗？');
	}
	return false;
}

function isEmail(email)
{
	var regstr = /^\w(\w*\.*)*@(\w+\.)+\w{2,4}$/;
	return regstr.test(email);
}

function isDate(str)
{
		var reg	=	/^[0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}(\s[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})?$/;
		return (reg.test(str) && vbIfDate(str));
}

function Validate_On_Submit(objform)
{
	var e		=	objform.elements;
	var reg1	=	/^[0-9]+$/;
	for (i=0; i<e.length; i++)
	{
		if (e[i].TextLength)
		{
			if (e[i].value.length > parseInt(e[i].TextLength))
			{
				alert('您在该文本框内输入了过多的文本，请删减!');
				e[i].focus();
				return false;
			}
		}

		//CompareTo:要求与另一控件内容相同
		if (e[i].CompareTo)
		{
			if (e[i].value != objform.elements[e[i].CompareTo].value)
			{
				alert('您两次所输入的内容不同，请确认!');
				e[i].focus();
				return false;
			}
		}

		//DataType: Date,Email,Int,Custom(自定义数据类型，跟随Regstr属性作为检验条件),Float暂不考虑
		//Int: IntLength-整数长度，IntMin-最小值，IntMax-最大值
		//Custom: Regstr-正则表达式，注意在页面中不要写入 //
		//IDCard: 身份证
		if (e[i].DataType)
		{
			var datatype = e[i].DataType.toLowerCase();
			if (datatype == 'date')
			{
				if (e[i].value != '' && !isDate(e[i].value))
				{
					alert('请按以下格式输入正确的日期：yyyy-mm-dd hh:mm:ss\n\n例如：2002-12-4 9:45:00(时间可忽略)');
					e[i].focus();
					return false;				
				}
			}

			//============================================
			else if (datatype == 'email')
			{
				if (e[i].value != '' && !isEmail(e[i].value))
				{
					alert('请输入一个正确的Email地址!');
					e[i].focus();
					return false;				
				}
			}

			//============================================
			else if (datatype == 'int')
			{
				if (!reg1.test(e[i].value))
				{
					alert('请输入一个整数!');
					e[i].focus();
					return false;
				}

				if (e[i].IntLength)
				{
					var intlength = parseInt(e[i].IntLength);
					if (e[i].value !='')
					{
						var max	= Math.pow(2,intlength);
						if (e[i].value > max-1)
						{
							alert('您所输入的数字过大!');
							e[i].focus();
							return false;
						}
					}
				}
				else
				{
					if (e[i].IntMax)
					{
						if (e[i].value > e[i].IntMax)
						{
							alert('您所输入的数字过大!');
							e[i].focus();
							return false;
						}
					}
					if (e[i].IntMin)
					{
						if (e[i].value < e[i].IntMin)
						{
							alert('您所输入的数字太小!');
							e[i].focus();
							return false;
						}
					}
				}
			}

			//============================================
			else if (datatype == 'idcard')
			{
				if (e[i].value != '' && !isIDCard(e[i].value))
				{
					alert('您输入的身份证号码不正确!');
					e[i].focus();
					return false;
				}
			}

			//============================================
			else if (datatype == 'custom')
			{
				if (e[i].Regstr)
				{
					var customreg = /test/;
					eval('customreg=/'+e[i].Regstr+'/');
					if (!customreg.test(e[i].value))
					{
						alert('请正确填写该内容!');
						e[i].focus();
						return false;
					}
				}
			}

		}// end if (e[i].DataType)
	}//end for
	return ValidateMust(objform);
}
