
/* AJAX */
function InitAjax() {

	var agt = navigator.userAgent.toLowerCase();
	var is_opera = (agt.indexOf("opera") != -1);
	var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
	var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;

	if (is_ie) {    
		var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
		try {      
			return new ActiveXObject(control);
		} catch(e) {
			alert("You need to enable active scripting and activeX controls");
			DumpException(e);
		}
	} else {
		return new XMLHttpRequest();
	}

}
function chkreg(){
var obj=document.reg_form;
var reg = /^([0-9a-zA-Z_])*$/;
var rule=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
if(obj.UserName.value==""){alert("请输入Email地址");obj.UserName.focus();return false;}
if(obj.Password.value==""){alert("请输入您的密码");obj.Password.focus();return false;}
if(obj.Password2.value==""){alert("请输入您确认的密码");obj.Password2.focus();return false;}
if(obj.Password.value.length > 16 || obj.Password.value.length < 6){alert("长度在6-16之间");obj.Password.focus();return false;}
if(!reg.test(obj.Password.value)){alert("密码只允许为字母，数字或下划线组成");obj.Password.focus();return false;}
if (!rule.test(obj.UserName.value)){alert("请输入有效Email地址!");obj.UserName.focus();return false;}
if(obj.Password.value!=obj.Password2.value){alert("确认密码不一致");obj.Password.focus();return false;}
if(obj.Name.value==""){alert("请输入您的昵称！");obj.Name.focus();return false;}
if(obj.QQ.value==""){alert("请输入您的QQ号码！");obj.Name.focus();return false;}
if(obj.CompanyName.value==""){alert("请输入您的公司名称！");obj.Name.focus();return false;}


var UserName = obj.UserName.value;
var Password = obj.Password.value;
var Name = escape(obj.Name.value);
var Sex = escape(obj.Sex.value);
var QQ = obj.QQ.value;
var Mobile = obj.Mobile.value;
var CompanyName = escape(obj.CompanyName.value);
var Website = obj.Website.value;
var BlogUrl = obj.BlogUrl.value;
var InputCode = obj.InputCode.value;
var url = "/member_ok.php?Action=Register&UserName="+ UserName +"&Password="+ Password +"&Name="+ Name+"&Sex="+ Sex+"&BlogUrl="+ BlogUrl+"&QQ="+ QQ+"&Mobile="+ Mobile+"&CompanyName="+ CompanyName+"&Website="+ Website+"&Code="+ InputCode;
var ajax = InitAjax();

	
	ajax.open("GET", url, true); 
	
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 4 && ajax.status == 200) { 	
			
		strdiv = ajax.responseText;
		alert(strdiv);
		window.location.href='/login.html';
			
		} 
	}
	ajax.setRequestHeader("Content-Type","text/html; charset=UTF-8");
	ajax.setRequestHeader("If-Modified-Since","0");
	//发送空
	ajax.send(null); 
}


function check_name()
{
	var name = document.getElementById("UserName").value; 
	var url="/member_ok.php?Action=ChkName&name="+name;
	
	
	var div_show = document.getElementById("msg"); 
	div_show.style.visibility = "visible";
	
	if(name=="")
	{
     div_show.innerHTML="<font color=red>请先输入用户名!</font>";
	 
	  return false();
    }
	var strdiv = "";


	//需要进行Ajax的URL地址
	//实例化Ajax对象
	var ajax = InitAjax();

	//使用Get方式进行请求
	
	ajax.open("GET", url, true); 

	//获取执行状态
	div_show.innerHTML = "<img src=\"/images/loading.gif\">";
	ajax.onreadystatechange = function() { 
		if (ajax.readyState == 4 && ajax.status == 200) { 	
			
			strdiv = ajax.responseText;
			
			switch(strdiv)
			{
			  case "CanReg":
			 // alert("抱歉!该用户名已存在,请重新填写！");
			 // document.reg.UserName.focus();
              div_show.innerHTML = "<img src=\"/images/ico-ok.gif\">";
			  return false;
			  break;

			  case "exist":
			  //alert("恭喜!该用戶名可以注冊！");
			  //document.reg.UserName.focus();
              div_show.innerHTML = "<img src=\"/images/ico-x.gif\">";
			  return true;
			  break;
			}
			
			
		} 
	}
	ajax.setRequestHeader("Content-Type","text/html; charset=UTF-8");
	ajax.setRequestHeader("If-Modified-Since","0");
	//发送空
	ajax.send(null); 
}