var kick = ""

$(document).ready(function() {
			var cook = new Cookie();
			var uid = cook.getCookie("uid");
			if (uid != undefined && uid != "")
				$("#uname").val(uid);
		});

var goLogin = function(events) {
	var intkey = events.charCode || events.keyCode;
	if (intkey == 13) {
		login();
	}
};
var login = function(autoSign) {
	var uid = $('#uname').val().trim();
	var pwd = $('#upwd').val().trim();
	if (uid == "" || pwd == "") {
		alert("请输入用户名和密码。");
		return;
	}
	var remUser = "";
	var temprid = getE("autologin");
	if (temprid)
		if (temprid.checked)
			remUser = "1";
	var code = $('#uyzm').val().trim();
	var data = {
		'uid' : uid,
		'pwd' : pwd,
		'code' : code,
		'isKick' : kick,
		'remUser' : remUser
	};
	$.ajax({
				type : 'post',
				url : '/account/UserLogin.do?method=login',
				data : data,
				complete : function(json) {
					var data = eval("(" + json.responseText + ")");
					if (data && data.state == 'failed') {
						if (data.result == 'DEGREE5') {
							alert('赠送会员查询材价次数已用完！');
							window.location.reload();
							// window.location = '/module/netpay/index.jsp';
						} else if (data.result == 'LOCKED') {
							alert('帐号已经被停用！');
							// window.location = 'contact.html';
						} else if (data.result == 'INVALID') {
							alert('帐号已经过期！');
							// window.location = '/module/netpay/index.jsp';
						} else if (data.result == "EPLOCK"
								&& data.state == "failed") {
							alert("您的帐号已锁定，请联系管理员！");
							location.reload();
						} else if (data.result == 'VIPNOTFOUND') {
							alert("您的VIP库尚未开通，请联系管理员！");
							location.reload();
						} else {
							alert(data.result);
							location.reload();
						}
					} else if (data && data.state == "islogin") {
						if (confirm(data.result)) {
							kick = "true";
							$("#addopt li#wait").remove();
							$("#addopt li#waittxt").remove();
							login();
						} else {
							$('#uname').val("");
							$('#upwd').val("");
							$('#uyzm').val("");
							location.reload();
						}
					} else if (data && data.state == 'success') {
						fromUrl = window.location.search.split("?from=")[1];
						if (data.result.degree == 8) {
							window.location = "/module/vip/index.jsp";
							return;
						}
						if (data.result.degree == 9) {
							window.location = "/module/company/index.jsp";
							return;
						}
						if (typeof fromUrl == "undefined") {
							fromUrl = "/index.html";
							window.location = fromUrl;
						} else {
							if (fromUrl.indexOf("/default") == -1) {
								window.location = fromUrl;
							} else
								window.location = "/index.html";
						};
						return
					} else {
						alert("用户名或密码错误，登录失败");
						$('#uname').val("");
						$('#upwd').val("")
					}
				}
			})
};

/**
 * 刷新验证码
 */
function refreshCode() {
	$("#imgCode").attr("src", "/authImg?t=" + new Date().getTime());
};

$(document).ready(function() {
	var cook = new Cookie();
	var uid = cook.getCookie("uid");
	var upwd = cook.getCookie("upwd");
	var upwdstate = cook.getCookie("upwdstate");
	if (uid != undefined && uid != "")
		$("#uname").val(uid);
	if (upwd != undefined && upwd != "")
		$("#upwd").val(upwd);
	if (upwdstate == "1")
		$("#rememberPwd").attr("checked", true);
		// $.ajax({type:'post',url:'/account/UserLogin.do?method=getLoginCode',data:null,complete:function(json){
		// var result=eval("("+json.responseText+")");
		// if(result){$('#code').val(result)}
		// }
		// })
	});
