$(function(){
	//var _widht = document.documentElement.clientWidth;  //屏幕宽
	var _height = document.documentElement.clientHeight; //屏幕高
	//var boxWidth = $(".loginbox").width();
	var boxHeight = $(".loginbox").height();
	$(".loginbox").css({ top: (_height - boxHeight) / 2 +"px"});
//	console.log(_widht);
//	console.log(_height);	
//	console.log(boxWidth);	
//	console.log(boxHeight);
})
	var namePass = false;
	var passwordPass = false;
	//校验登录账户
	function nameVal()
	{
		var loginName= $("#loginName").val();
		
		if(loginName.length==0)
		{
	        $(".msg1").text("请输入您的手机号码或邮箱地址");
	    }else
	    {
	        var hun=/\s+/;
	        if(hun.test(loginName.trim()))
	        {
	            $(".msg1").text("请输入");
	            namePass = false;
	        }else
	        {

	            //var gunf=/^\w+@\w+\.((cn)|(com)|(com\.cn))$/;
	            var gunf= /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; 
	            if(gunf.test(loginName.trim()))
	            { 
	               userRegisterOk()
	               $(".msg1").text("");
	               namePass = true;
	            }
	            else
	            {
	            	var hunPhone=/^1[3|4|5|7|8]\d{9}$/;
					if(hunPhone.test(loginName.trim()))
					{
						userRegisterOk()
						$(".msg1").text("");
						namePass = true;
					}
					else
					{
						namePass = false;
						$(".msg1").text("格式不对，请输入正确的格式");
					}
	            }
	        }
	    }
		
		
	    
	}
	
	//校验登录密码
	function passwordVal(){
		var password = $("#password").val();
		if(password.length==0){
			$(".msg3").text("请输入密码");
			passwordPass = false;
		}else if(password.length < 6){
			$(".msg3").text("密码不少于6位，请输入正确的密码");
		}else{
			$(".msg3").text("");
			passwordPass = true;
		}
	}	
   
	//判断账号是否注册
	function userRegisterOk(){
		var loginName= $("#loginName").val();
		//console.log(loginName);
		$.ajax("/ajax/isReg?key="+loginName,{
			type:"GET",
			async: true,
			success:function($data){ 
				//console.log($data);
			    if($data.data==true){
			    	 $(".msg1").text("账户不存在，请先注册");
			    	 return false; 
			    }
			},
			error:function(){
				$.MsgBox.Alert('消息','服务器请求失败')},
			}
		);
	}	
	//判断用户第一次登录，是否填写了个人信息
	function firstLogin(){
		var professorId = $.cookie('userid');
		//console.log(professorId);
		$.ajax({	
			"url":"ajax/professor/"+professorId,
			"type":"get",
			"async": false,
			"success":function(data){
				if(data.data!=null)
				{	
					location.href="index.html";
					//console.log(data);
				}
				else
				{
					//console.log(data);
					location.href="information-add.html?id="+ professorId;
				}
			},
			"error":function(){$.MsgBox.Alert('message','failed')}
		})	
	}
	
	//提交登录
	function login(){
		nameVal();
		passwordVal();
		if(namePass && passwordPass){
			$.ajax("/ajax/login",{
					type:"POST",
					 async: false,
					success:function(data){  

						if(data.success){
							if(data.data != "null" && data.data != null){
								firstLogin();
							}else{
								$(".msg5").text("登录账号和密码不匹配!");
							}
						}else{
							$(".msg5").text("系统异常!");
							// alert("系统异常!");
						}
					},
					error:function(){$.MsgBox.Alert('message','fail')},
					data:{"pw":$("#password").val(),"lk":$("#loginName").val()},
				 	dataType: 'json'
				});
			}

	}	
	
	function restSub(data) {  
         $(".msg5").text("");
     } 