/**
* Author:xieaotian@163.com
* Prameter:
* Function:The username register information check
**/

$(document).ready(function(){
		$("input[@name='submit']").click(function(){
				var flag = true;
				if($("#uname").val() == ""){
					window.alert("用户名字不能为空");
					$("#uname").focus();
					flag = false;
					return false;
				}
				if($("#email").val() != ""){
					var regexp = new RegExp(/(\d|\w)+@+(\d|\w)+\.\w+/);
					if(!regexp.test($("#email").val())){
						window.alert("对不起您的email格式有问题,请检查");
						$("#email").focus();
						flag = false;
						return false;
					}
				}
				else{
					window.alert("email不能为空");
					$("#email").focus();
					flag = false;
					return false;
				}
				if($("#pwd").val() == ""){
					window.alert("密码不能为空");
					$("#pwd").focus();
					flag = false;
					return false;
				}
				if($("#password_confirm").val() != ""){
					if($("#password_confirm").val() != $("#pwd").val()){
						window.alert("两次输入密码不同，请检查");
						flag = false;
						return false;
					}
				}
				else{
					window.alert("确认密码不能为空");
					$("#password_confirm").focus();
					flag = false;
					return false;
				}
				if($("#math_question").val() != "是"){
					window.alert("验证码不对");
					$("#math_question").focus();
					flag = false;
					return false;
				}
				if($("#sex").val() == ""){
					window.alert("性别不能为空");
					$("#sex").focus();
					flag = false;
					return false;
				}
				if($("#birthday").val() != ""){
					var birthday = $("#birthday").val();
					var PregEXp_day = new RegExp(/^\d+\-+\d+\-+\d+$/);
					if(!PregEXp_day.test(birthday)){
						window.alert('您输入的日期不对，请检查');
						$("#birthday").focus();
						flag = false;
						return false;
					}
				}
				else{
					window.alert("出生年月日不能为空");
					$("#birthday").focus();
					flag = false;
					return false;
				}
//There's No need register information of check
				if($("#oicq").val() != ""){
					var regqq = new RegExp(/^\d+$/);
					if(!regqq.test($("#oicq").val())){
						window.alert("OICQ一定是数字才可以");
						$("#oicq").focus();
						return false;
					}
				}
//Ajax send userinfo
				var uname = $("#uname").val();
				var pwd = $("#pwd").val();
				var email    = $("#email").val();
				var sex      = $("#sex").val();
				var oicq      = $("#oicq").val();
				var msn      = $("#msn").val();
				var yahoo      = $("#yahoo").val();
				var aim		 = $("#aim").val()
				var website  = $("#website").val();
				var headaddress = $("#headaddress").val();
				var metier = $("#metier").val();
				var interests  = $("#interests").val();
				var signature  = $("#signature").val();

				if(flag == true){
					$("#regview").css("display","none");
					$("#statics").css("display","");
					$.ajax({
					 type: "POST",
					 url: "/userchk/",
					 data:"uname="+uname+"&pwd="+pwd+"&email="+email+"&birthday="+birthday+"&sex="+sex+"&oicq="+oicq+"&aim="+aim+"&msn="+msn+"&yahoo="+yahoo+"&website="+website+"&headaddress="+headaddress+"&metier="+metier+"&interests="+interests+"&signature="+signature,
					 success: function(msg){
                         if (msg == "no") {
                            alert("注册失败，请尝试换一个用户名");location='/register/';
                         }
                         else{
                            alert("注册成功，您现在可以登录了");location='/index/';
                         }
                     }
					});
				}

			}
		)
	}
);
