function SetCookie(name, value, days){
var finalDays = 7; //cookie存储时间默认7天
if (typeof (days) != "undefined" && !isNaN(days)){
finalDays = parseInt(days);
}
var exp = new Date();
exp.setTime(exp.getTime() + finalDays * 24 * 60 * 60 * 1000);
document.cookie = name + "=" + escape(value) + ";path=/ ;expires=" + exp.toGMTString();
}
//删除Cookie
function DeleteCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = GetCookie(name);
document.cookie = name + "=" + cval + "; path=/ ;expires=" + exp.toGMTString();
}
//获取Cookie
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
//获取Cookie
function GetCookieVal(offset) {
var endstr = document.cookie.indexOf(";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//初始化用户名及密码
function GetUser(userIndex) {
var nameKey = "RecordName";
var pwdKey = "RecordPwd";
if (userIndex > 0) {
nameKey += userIndex;
pwdKey += userIndex;
}
var loginCode = GetCookie(nameKey);
var pwd = GetCookie(pwdKey);
if (loginCode != null) {
$("#txtLoginCode").val(loginCode);
} else {
$("#txtLoginCode").val("");
}
if (pwd != null) {
$("#chkPwd").attr("checked", true);
$("#txtPwd").val(pwd);
} else {
$("#chkPwd").attr("checked", false);
$("#txtPwd").val("");
}
}
//记录用户名、密码及用户头像
function SaveUser(loginCode, pwd, photoData) {
//头像
var userIndex = 0;
var loginType = $("#hidLoginType").val().toLowerCase();
var photoKey = "RecordPhoto";
if (loginType == "slide") {
userIndex = $(".contentUser ul li.loginCurrent").index();
if (userIndex > 0) {
photoKey += userIndex;
}
}
if (photoData) {
SetCookie(photoKey, photoData);
} else {
DeleteCookie(photoKey);
}
//用户名、密码
var nameKey = "RecordName";
var pwdKey = "RecordPwd";
if (userIndex > 0) {
nameKey += userIndex;
pwdKey += userIndex;
}
SetCookie(nameKey, loginCode);
if ($("#chkPwd").attr("checked"))
SetCookie(pwdKey,pwd);
else
DeleteCookie(pwdKey);
}
//判断浏览器是否禁用cookie
function IsAllowCookie() {
var flag = false;
if ($.browser.msie) {
var cookieStr = "wb_check=kcehc_bw";
document.cookie = cookieStr;
if (document.cookie.indexOf(cookieStr) > -1) {
flag = true;
var date = new Date();
date.setTime(date.getTime() - 1000);
document.cookie = cookieStr + "; expires=" + date.toGMTString();
}
} else {
flag = navigator.cookieEnabled;
}
return flag;
}
function Login() {
if (CheckInput()) {
var loginCode = $.trim($("#txtLoginCode").val());
var pwd = $.trim($("#txtPwd").val());
SetCookie(loginCode,pwd,7);
SaveUser(loginCode,pwd,7);
$("#spring_sexurity_login_form").submit();
}
}