function reloadCode(){//刷新验证码
	var time=Math.floor(Math.random () * 900) + 100;
	document.getElementById('alcode').src = 'login/createImg.do?timestamp=' + time;
}
 function loginFun(){
		var uname=$("#uname").val();
		 if(uname==''){
			 $("#msg").html("请填写登录账号");
			 return;
		 }
		var pwd=$("#pwd").val();
		 if(pwd==''){
			 $("#msg").html("请填写密码");
			 return;
		 }
		 var code=$("#ckcode").val();
		 if(code==''){
			$("#msg").html("请填写验证码");
			 return;
		 }
		 
		//使用公钥加密
		    var encrypt = new JSEncrypt();
		    encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + public_key + '-----END PUBLIC KEY-----');
		    var encrypted = encrypt.encrypt(pwd);
		$.ajax({
			type: "post", 
			url : "login/userLogin.do", 
			dataType:'json',
			data:{
				userName:uname,
				password:encrypted,
				code:code
			},
			success: function(data){
				if(data.success=='true'){
					var TOKEN=data.message;
					localStorage.setItem(TOKEN, TOKEN);
					localStorage.setItem(TOKEN+"orgid", data.orgid);
					window.location.href="view/index.html?JSONID="+TOKEN;
				}else{
					$("#msg").html(data.message);
					reloadCode();
				}
			}
		});
	}
function keyLogin(){//回车登录
	 if (event.keyCode==13)  //回车键的键值为13
	 	loginFun();
}