﻿function checkform()
{
for(i=0;i<13;i++)
{
if (document.mynews.elements[i].value.length==0 )
{
qw.innerText="请认真填写每项信息，以下所有信息均不能为空"
return false;
}
}

if (document.mynews.password.value!=document.mynews.r_password.value)
{

return false;
}
if (isNaN(document.mynews.tel.value)==true)
{

return false;
}
 var email=document.mynews.mail.value
    var pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    flag=pattern.test(email);
    if (!flag)
{
return false;
}

}
function cpassword()
{

if (document.mynews.password.value.length==0)
{
dpassword.innerText="请输入密码";

}
else
{

dpassword.innerText="正确";

}

}
function rpassword()
{
if (document.mynews.r_password.value.length==0)
{
rpassword1.innerText="请再一次输入密码";
}
else if (document.mynews.password.value!=document.mynews.r_password.value)
{
rpassword1.innerText="两次输入的密码不一致";
}
else
{
rpassword1.innerText="正确";
}

}
function t_tel()
{
if (document.mynews.tel.value.length==0)
{
ttel.innerText="请填写电话号码";
}
else if(isNaN(document.mynews.tel.value)==true)
{

ttel.innerText="请正确填写电话号码";
}
else
{
ttel.innerText="正确";
}

}
function cmail()
{
   var email=document.mynews.mail.value
    var pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    flag=pattern.test(email);
    if (flag)
    {
eemail.innerText="正确";

}
    else
        {
         eemail.innerText="请正确填写邮箱地址";

        }

 }
 var xmlHttp;
			//定义一个用于创建XMLHttpRequest对象的函数
			function createXMLHttpRequest()
			{
				if (window.ActiveXObject)
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				else if (window.XMLHttpRequest)
				{
					xmlHttp = new XMLHttpRequest();
				}
			}
			
			//判断用户名是否已经被使用
			function showUserErr()
			{
				if (xmlHttp.readyState==4)
				{
					if (xmlHttp.status==200 || xmlHttp.status==0)
					{
						//获取用户名单，并放入数组中
						var registerNames = xmlHttp.responseText;
						var registerName = registerNames.split("|");
						var bFlag = true;
						//判断已输入的用户名是否在数组中已经存在
						for (var i=0;i<registerName.length;i++)
						{
							if (registerName[i]==document.mynews.s_name.value )
							{   
								bFlag = false;
								break;
								
							}
						}
						//使用DOM中的getElementById()方法查找到要显示文字的节点（<userNameNode>节点）
						var node = document.getElementById("userNameNode");
						if (bFlag)
						{
							//<userNameNode>标签与</userNameNode>标签之间的文字，是DOM中的文本节点。
							//可以使用firstChild属性来获取<userNameNode>节点下的第1个子节点，即<userNameNode>标签与</userNameNode>标签之间的文字
							//nodeValue属性可以设置节点的值，在文本节点中为文本内容
							node.firstChild.nodeValue = "该用户名没有注册，可以使用";
							
						}
						else
						{
							tian();
							node.firstChild.nodeValue = "该用户名有人注册，请选择其他用户名称注册";
							
						}
					}
					else
					{
						//如果异步调用未成功，弹出警告框，并显示出错信息
						alert("异步调用出错\n返回的HTTP状态码为：" + xmlHttp.status + "\n返回的HTTP状态信息为：" + xmlHttp.statusText);
					}
				}
			}
			
			//准备http请求并发送
			function checkUser()
			{
				//判断是否输入用户名
				if (document.mynews.s_name.value.length==0)
				{
					var node = document.getElementById("userNameNode");
					node.firstChild.nodeValue = "请输入用户名";
				}
				else
				{
					createXMLHttpRequest();
					if (xmlHttp!=null)
					{
						//从sample05.txt文件提取已注册人名单
						xmlHttp.open("get","05.asp",true);
						xmlHttp.onreadystatechange = showUserErr;
						xmlHttp.send(null);
					}
				}
			}
			function tian()
			{
				document.mynews.s_name.value="";
				
				}
			
///////////////////////////////////

			//定义一个用于创建XMLHttpRequest对象的函数
			function createXMLHttpRequest1()
			{
				if (window.ActiveXObject)
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				else if (window.XMLHttpRequest)
				{
					xmlHttp = new XMLHttpRequest();
				}
			}
			
			//判断用户名是否已经被使用
			function showUserErr1()
			{
				if (xmlHttp.readyState==4)
				{
					if (xmlHttp.status==200 || xmlHttp.status==0)
					{
						//获取用户名单，并放入数组中
						var registerNames = xmlHttp.responseText;
						var registerName = registerNames.split("|");
						var bFlag = true;
						//判断已输入的用户名是否在数组中已经存在
						for (var i=0;i<registerName.length;i++)
						{
							if (registerName[i]==document.check.uName.value )
							{   
								bFlag = false;
								break;
								
							}
						}
						//使用DOM中的getElementById()方法查找到要显示文字的节点（<userNameNode>节点）
						var node = document.getElementById("userNode");
						if (bFlag)
						{
							//<userNameNode>标签与</userNameNode>标签之间的文字，是DOM中的文本节点。
							//可以使用firstChild属性来获取<userNameNode>节点下的第1个子节点，即<userNameNode>标签与</userNameNode>标签之间的文字
							//nodeValue属性可以设置节点的值，在文本节点中为文本内容
							node.firstChild.nodeValue = "该用户名没有注册，可以使用";
							
						}
						else
						{
							tian1();
							node.firstChild.nodeValue = "该用户名有人注册，请选择其他用户名称注册";
							
						}
					}
					else
					{
						//如果异步调用未成功，弹出警告框，并显示出错信息
						alert("异步调用出错\n返回的HTTP状态码为：" + xmlHttp.status + "\n返回的HTTP状态信息为：" + xmlHttp.statusText);
					}
				}
			}
			
			//准备http请求并发送
			function checkUser1()
			{
				//判断是否输入用户名
				if (document.check.uName.value.length==0)
				{
					var node = document.getElementById("userNode");
					node.firstChild.nodeValue = "请输入用户名";
				}
				else
				{
					createXMLHttpRequest1();
					if (xmlHttp!=null)
					{
						//从sample05.txt文件提取已注册人名单
						xmlHttp.open("get","05.asp",true);
						xmlHttp.onreadystatechange = showUserErr1;
						xmlHttp.send(null);
					}
				}
			}
			function tian1()
			{
				document.check.uName.value="";
				
				}
 function check1()
{
for(i=0;i<8;i++)
{
if (document.check.elements[i].value.length==0 )
{
qq.innerText="请认真填写每项信息，以下所有信息均不能为空"
return false;
}
 }
 if (document.check.p.value!=document.check.rp.value)
{

return false;
}
if (isNaN(document.check.phone.value)==true)
{

return false;
}
 var eemail=document.check.email.value
    var pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    flag=pattern.test(eemail);
    if (!flag)
{
return false;
}
}
function p_p()
{
if (document.check.p.value.length==0)
{
pl.innerText="请输入密码";

}
else
{
pl.innerText="正确";

}

}
function r_pp()
{
if (document.check.rp.value.length==0)
{
rpp.innerText="请再一次输入密码";
}
else if (document.check.p.value!=document.check.rp.value)
{
rpp.innerText="两次输入的密码不一致";
}
else
{
rpp.innerText="正确";
}

}
function t_l()
{
if (document.check.phone.value.length==0)
{
ttl.innerText="请填写电话号码";
}
else if(isNaN(document.check.phone.value)==true)
{

ttl.innerText="请正确填写电话号码";
}
else
{
ttl.innerText="正确";
}

}
function cl()
{
   var eemail=document.check.email.value
    var pattern=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    flag=pattern.test(eemail);
    if (flag)
    {
el.innerText="正确";
}
    else
        {
         el.innerText="请正确填写邮箱地址";

        }

 }
