function addUserCookie(username,password){
	addCookie("username",username,14*60*60*24*1000);
	addCookie("password",password,14*60*60*24*1000);
}
function addCookie(key,value,expiretime){
	var str = key+ "=" + escape(value);
	var date =new Date();
	date.setTime(date.getTime() + expiretime);
	str += ";expires=" + date.toGMTString();
	document.cookie = str;
}
function getCookie(key){
	var arrStr = document.cookie.split(";");
	for(var i=0;i<arrStr.length;i++){
		var temp = arrStr[i].split("=");
		temp[0]=temp[0].replace(/(^\s+)|(\s+$)/, "");
		//alert('/'+temp[0]);
		if(temp[0]==key){
			return unescape(temp[1]);
		}
	} 
}
function getCookieInfo(){
	var arrStr = document.cookie.split(";");
	var str="";
	for(var i=0;i<arrStr.length;i++){
		var temp = arrStr[i].split("=");
		temp[0]=temp[0].replace(/(^\s+)|(\s+$)/, "");
		str+="key:"+temp[0]+";";
		str+="value:"+unescape(temp[1]);
	} 
	alert(str);
}

function delCookie(){
	var date = new Date();
	var username="username";
	var password="password";
	date.setTime(date.getTime() - 10000);
	document.cookie=username+"=a;expires="+date.toGMTString();
	document.cookie=password+"=a;expires="+date.toGMTString();
	window.location="/index.jsp";
}
function autoLogin(){
	var username="username";
	var password="password";
	username=getCookie(username);
	password=getCookie(password);
	if(username!=null&&password!=null){
		UserAction.login(username,password,"",false,{
			callback:function(data){
				if(data){
					window.location.href="/user/accounts.jsp";
				}else{
					window.location.href="/user/";
				}
			},
			errorHandler:function(msg){
			}
		});
	}
}
function logCookies(loadCookie){
	if(loadCookie){
		autoLogin();
	}
}