function isMail(s)   
{   
	var patrn=/^(.+)@(.+)$/;   
	if (!patrn.exec(s)) return false;
	return true;
}

function CheckForm()
{
	var parray = document.all["pp"].value.split("_");
	
	if(parray[8]==1)
	{
		if(document.all["gtitle"].value=="")
		{
			alert("Title can not be empty");
			document.all["gtitle"].focus();
			return false;
		}
		if(document.all["gtitle"].value.length>=50)
		{
			alert("Title can not be more than 50 characters");
			document.all["gtitle"].focus();
			return false;
		}
		if(document.all["gcategory"].value=="")
		{
			alert("Category can not be empty");
			document.all["gcategory"].focus();
			return false;
		}
		if(document.all["gcontent"].value=="")
		{
			alert("Message can not be empty");
			document.all["gcontent"].focus();
			return false;
		}
		if(document.all["gcontent"].value.length>=1000)
		{
			alert("Message can not be more than 50 characters");
			document.all["gcontent"].focus();
			return false;
		}
		//以上是必需检查
		
		if(parray[0]=="1")
		{
			if(document.all["gusername"].value=="")
			{
				alert("User names can not be empty");
				document.all["gusername"].focus();
				return false;
			}
			if(document.all["gusername"].value.length>50)
			{
				alert("User names can not be more than 50 characters");
				document.all["gusername"].focus();
				return false;
			}
		}
		
		if(parray[1]=="1")
		{
			if(document.all["gtel"].value=="")
			{
				alert("Phone can not be empty");
				document.all["gtel"].focus();
				return false;
			}
			if(document.all["gtel"].value.length>50)
			{
				alert("Phone can not be more than 50 characters");
				document.all["gtel"].focus();
				return false;
			}
		}
		
		if(parray[2]=="1")
		{
			if(document.all["gfax"].value=="")
			{
				alert("Fax can not be empty");
				document.all["gfax"].focus();
				return false;
			}
			if(document.all["gfax"].value.length>50)
			{
				alert("Fax can not be more than 50 characters");
				document.all["gfax"].focus();
				return false;
			}
		}
		
		if(parray[3]=="1")
		{
			if(document.all["gmail"].value=="")
			{
				alert("Email can not be empty");
				document.all["gmail"].focus();
				return false;
			}
			if(document.all["gmail"].value.length>200)
			{
				alert("Emai can not be more than 50 characters");
				document.all["gmail"].focus();
				return false;
			}
			if(!isMail(document.all["gmail"].value))
			{
				alert("E-mail format error");
				document.all["gmail"].focus();
				return false;
			}
			
		}
		
		if(parray[4]=="1")
		{
			if(document.all["gcountry"].value=="")
			{
				alert("Country can not be empty");
				document.all["gcountry"].focus();
				return false;
			}
			if(document.all["gcountry"].value.length>50)
			{
				alert("Country can not be more than 50 characters");
				document.all["gcountry"].focus();
				return false;
			}
		}
		
		if(parray[5]=="1")
		{
			if(document.all["gcity"].value=="")
			{
				alert("City can not be empty");
				document.all["gcity"].focus();
				return false;
			}
			if(document.all["gcity"].value.length>50)
			{
				alert("City can not be more than 50 characters");
				document.all["gcity"].focus();
				return false;
			}
		}

		if(parray[6]=="1")
		{
			if(document.all["gaddress"].value=="")
			{
				alert("Address can not be empty");
				document.all["gaddress"].focus();
				return false;
			}
			if(document.all["gaddress"].value.length>200)
			{
				alert("Address can not be more than 200 characters");
				document.all["gaddress"].focus();
				return false;
			}
		}
		
		if(parray[7]=="1")
		{
			if(document.all["gpostcode"].value=="")
			{
				alert("Postcode can not be empty");
				document.all["gpostcode"].focus();
				return false;
			}
			if(document.all["gpostcode"].value.length>50)
			{
				alert("Postcode can not be more than 50 characters");
				document.all["gpostcode"].focus();
				return false;
			}
		}
	}
	else
	{
		if(document.all["gtitle"].value=="")
		{
			alert("用户留言标题不以为空");
			document.all["gtitle"].focus();
			return false;
		}
		if(document.all["gtitle"].value.length>=50)
		{
			alert("用户留言标题不能起过50个字符");
			document.all["gtitle"].focus();
			return false;
		}
		if(document.all["gcategory"].value=="")
		{
			alert("留言分类不能为空");
			document.all["gcategory"].focus();
			return false;
		}
		if(document.all["gcontent"].value=="")
		{
			alert("用户留言不可以为空");
			document.all["gcontent"].focus();
			return false;
		}
		if(document.all["gcontent"].value.length>=1000)
		{
			alert("用户留言内容起过1000个字符");
			document.all["gcontent"].focus();
			return false;
		}
		//以上是必需检查
		
		if(parray[0]=="1")
		{
			if(document.all["gusername"].value=="")
			{
				alert("留言用户名称不可以为空");
				document.all["gusername"].focus();
				return false;
			}
			if(document.all["gusername"].value.length>50)
			{
				alert("留言用户名称超过50字符");
				document.all["gusername"].focus();
				return false;
			}
		}
		
		if(parray[1]=="1")
		{
			if(document.all["gtel"].value=="")
			{
				alert("用户联系电话不可以为空");
				document.all["gtel"].focus();
				return false;
			}
			if(document.all["gtel"].value.length>50)
			{
				alert("留言电话长度超过50字符");
				document.all["gtel"].focus();
				return false;
			}
		}
		
		if(parray[2]=="1")
		{
			if(document.all["gfax"].value=="")
			{
				alert("用户联系传真不可以为空");
				document.all["gfax"].focus();
				return false;
			}
			if(document.all["gfax"].value.length>50)
			{
				alert("用户联系传真长度超过50字符");
				document.all["gfax"].focus();
				return false;
			}
		}
		
		if(parray[3]=="1")
		{
			if(document.all["gmail"].value=="")
			{
				alert("用户用户邮箱不可以为空");
				document.all["gmail"].focus();
				return false;
			}
			if(document.all["gmail"].value.length>200)
			{
				alert("用户用户邮箱长度超过50字符");
				document.all["gmail"].focus();
				return false;
			}
			if(!isMail(document.all["gmail"].value))
			{
				alert("E-mail格式错误");
				document.all["gmail"].focus();
				return false;
			}
		}
		
		if(parray[4]=="1")
		{
			if(document.all["gcountry"].value=="")
			{
				alert("用户所在国家不可以为空");
				document.all["gcountry"].focus();
				return false;
			}
			if(document.all["gcountry"].value.length>50)
			{
				alert("用户所在国家长度超过50字符");
				document.all["gcountry"].focus();
				return false;
			}
		}
		
		if(parray[5]=="1")
		{
			if(document.all["gcity"].value=="")
			{
				alert("用户所在城市不可以为空");
				document.all["gcity"].focus();
				return false;
			}
			if(document.all["gcity"].value.length>50)
			{
				alert("用户所在城市长度超过50字符");
				document.all["gcity"].focus();
				return false;
			}
		}

		if(parray[6]=="1")
		{
			if(document.all["gaddress"].value=="")
			{
				alert("用户联系地址不可以为空");
				document.all["gaddress"].focus();
				return false;
			}
			if(document.all["gaddress"].value.length>50)
			{
				alert("用户联系地址长度超过50字符");
				document.all["gaddress"].focus();
				return false;
			}
		}
		
		if(parray[7]=="1")
		{
			if(document.all["gpostcode"].value=="")
			{
				alert("用户联系邮政编码不可以为空");
				document.all["gpostcode"].focus();
				return false;
			}
			if(document.all["gpostcode"].value.length>50)
			{
				alert("用户联系邮政编码长度超过50字符");
				document.all["gpostcode"].focus();
				return false;
			}
		}
		
		//以上处理成为不可以为空、而且不可以大于数据的长度
	}
	return true;
}