var kk_cookie = new function() {	

	this.isCookieEnable = function() {
		if (typeof window.navigator.cookieEnabled == 'undefined') {
			var c = document.cookie;
			document.cookie = 'testEnable';
			cookieEnabled = (document.cookie == "testEnable")? true : false
			document.cookie = c;
		} else {
			cookieEnabled = window.navigator.cookieEnabled ? true : false;
		}
		return cookieEnabled;
	}

	this.getUsername = function() {
		try {
			return decodeURI($.cookie('kk_account_username'));
		} catch (e) {
			try {
				return unescape($.cookie('kk_account_username'));
			} catch (e) {
				try {
					return $.cookie('kk_account_username');
				} catch (e) {
					return null;
				}
			}
		}
	}
	
	this.getNickname = function() {
		try {
			return decodeURI($.cookie('kk_account_nickname'));
		} catch (e) {
			try {
				return unescape($.cookie('kk_account_nickname'));
			} catch (e) {
				try {
					return $.cookie('kk_account_nickname');
				} catch (e) {
					return null;
				}
			}
		}
	}
	
	this.getSex = function() {
		try {
			sex = $.cookie('kk_account_sex');
			if (sex == '0' || sex == 0) {
				return '女';
			} else if (sex == '1' || sex == 1) {
				return '男';
			} else {
				return '保密';
			}
		} catch (e) {
			return '保密';
		}
	}
	
	this.getProvince = function() {
		try {
			var p = $.cookie('kk_account_province');
			if (p== null || p.toLowerCase() == 'null'  ||p.toLowerCase() == 'none') {
				return '未知';
			} else {
				return p;
			}
		} catch (e) {
			return '未知';
		}
	}
	
	this.getCity = function() {
		try {
			var p = $.cookie('kk_account_city');
			if (p== null || p.toLowerCase() == 'null'  ||p.toLowerCase() == 'none') {
				return '未知';
			} else {
				return p;
			}
		} catch (e) {
			return '未知';
		}
	}
	
	this.getPoints = function() {
		try {
			return parseInt($.cookie('kk_account_points'));
		} catch (e) {
			return null;
		}
	}
	
	this.getKKNumber = function() {
		try {
			return $.cookie('kk_account_no');
		} catch (e) {
			return null;
		}
	}
	
	this.getMessageNum = function() {
		try {
			var num= $.cookie('msg_num');
			return num;
		} catch (e) {
			return null;
		}
	}
	
	this.getKKFace = function() {
		try {
			var face = $.cookie('kk_account_face');
			return face.substring(1, face.length - 1);
		} catch (e) {
			return null;
		}
	}
	
	this.getTutorial = function() {
		try {
			return $.cookie('kk_web_tutorial');
		} catch (e) {
			return null;
		}
	}
	
	this.setTutorial = function(v) {
		try {
			$.cookie('kk_web_tutorial', v || 'true', {path:'/', domain:DEFAULT_TOMAIN, expires:new Date(2099, 11, 31)});
		} catch (e) {
			return null;
		}		
	}
	
	this.getQuickTips = function() {
		try {
			return $.cookie('kk_web_quicktips');
		} catch (e) {
			return null;
		}
	}
	
	this.setQuickTips = function(v) {
		try {
			$.cookie('kk_web_quicktips', v, {path:'/', domain:DEFAULT_TOMAIN, expires:0});
		} catch (e) {
			return null;
		}		
	}
	
	this.getPrivilege = function() {
		try {
			return $.cookie('kk_account_privilege');
		} catch (e) {
			return null;
		}
	}
	
	this.hasPrivilege = function(privilege) {
		var b = false;
		var not_b = false;
		var user_pv = this.getPrivilege();
		if (!user_pv) {
			user_pv = 'VISITOR';
		}
		if (user_pv) {
			var pvs = privilege.split(' ');
			if (pvs[0] == 'NOT') {
				not_b = true;
			}
			
			for (var i = 0; i < pvs.length; i++) {
				var p =  pvs[i];
				if (user_pv.indexOf(p) >= 0) {
					b = true;
					break;
				}
			}
			
			if (not_b) {
				b = !b;
			}
		}
		return b;
	}
	
	this.getActive = function() {
		try {
			var active = $.cookie('kk_account_active');
			if(active == null){
				return '1';
			}
			return active;
		} catch (e) {
			return '1';
		}
	}
	
	this.getRank = function() {
		try {
			var rank = {
				value: $.cookie('kk_account_rank')?$.cookie('kk_account_rank'):'0',
				sun: $.cookie('kk_account_rank_sun')?$.cookie('kk_account_rank_sun'):'0',
				moon: $.cookie('kk_account_rank_moon')?$.cookie('kk_account_rank_moon'):'0',
				star: $.cookie('kk_account_rank_star')?$.cookie('kk_account_rank_star'):'1'
			};
			return rank;
		} catch (e) {
			return {value:'0',sun:'0',moon:'0',star:'1'};
		}		
	}
	
	this.setClosedTaskNotice = function(v) {
		try {
			$.cookie('kk_web_closed_task_notice', v, {path:'/', domain:DEFAULT_TOMAIN, expires:7});
		} catch (e) {
			return null;
		}		
	}
	
	this.getClosedTaskNotice = function() {
		try {
			return $.cookie('kk_web_closed_task_notice');
		} catch (e) {
			return null;
		}	
	}
	
	this.isUpdate = function() {
		try {
			var update = $.cookie('kk_account_user_update');
			if (update == null) {
				return false;
			} else if ((parseInt(update) & 1) == 1){
				return true;
			} else {
				return false;
			}
		} catch (e) {
			return null;
		}		
	}
	
	this.isLogin = function() {
		try {
			if (!this.hasKKAccountUsername()) {
				return false;
			} else {
				return true;
			}
		} catch (e) {
			return null;
		}
	}
	
	this.hasKKAccountUsername = function(){
		try {
			if($.cookie('kk_account_username') && $.cookie('kk_account_username') != '' && $.cookie('kk_account_user') && $.cookie('kk_account_user') != ''){
				return true;
			}
		} catch (e) {
			return false;
		}		
	}
	
	this.get_login_user_cookie_key = function() {
		try {
			var user_login_user_name_cookie_key = $.cookie('user_login_user_name_cookie_key');
			if(user_login_user_name_cookie_key == null){
				return '';
			}
			return user_login_user_name_cookie_key;
		} catch (e) {
			return '';
		}
	}
	
	this.getShareTips = function() {
		try {
			if($.cookie('kk_share_tips') && $.cookie('kk_share_tips') == 'true'){
				return true;
			}
		} catch (e) {
			return false;
		}
	}
	
	this.setShareTips = function(v) {
		try {
			$.cookie('kk_share_tips', v || 'true', {path:'/', domain:DEFAULT_TOMAIN, expires:new Date(2099, 11, 31)});
		} catch (e) {
			return false;
		}
	}
};
var kkc = kk_cookie;