function XIUtils() {
	var $this = this;
	var url = {
		"login" : "http://shop.xiaoi.com/loginIndex.do?fd=",
		"regist" : "http://passport.xiaoi.com/reg/index.do?aid=4&community=y&reme=y&fd="
	};
	var template = {
		"default_user" : "MSN乐园用户",
		"notLogin" : "<ul><li><a href=\"javascript:xi.login();\" onfocus=\"this.blur();\">登录</a></li><li><a href=\"javascript:xi.regist();\" onfocus=\"this.blur();\">注册</a></li></ul>",
		"login" : "<div class=\"xi_welcome\">您好！<span>@username</span>，欢迎来到MSN乐园购物！&nbsp&nbsp<a href=\"http://shop.xiaoi.com/order/my.do\" onfocus=\"this.blur();\" target=\"_blank\">我的订单</a>&nbsp&nbsp<a href=\"http://shop.xiaoi.com/logout.do\" onfocus=\"this.blur();\">退出</a></div>"
	};
	var logoLink = {
		"notLogin" : "http://happy.xiaoi.com",
		"hasLogin" : "http://happy.xiaoi.com/home.do"
	};
	var currLocation = window.location;
	this.login = function() {
		window.location = url["login"] + encodeURIComponent(currLocation)
				+ "&d=" + new Date().getTime();
	}
	this.regist = function() {
		window.location = url["regist"] + encodeURIComponent(currLocation)
				+ "&d=" + new Date().getTime();
	}
	this.showUserStatus = function(userName) {
		var content = template["notLogin"];
		userName = trim(userName);
		if (userName != "" && userName.length > 0) {
			content = template["login"].replace("@username",
					isPassportUsername(userName)
							? template["default_user"]
							: formatUserName(userName));
		}
		document.getElementById("xi_login_div").innerHTML = content;
	}
	function trim(str) {
		return str ? str.replace(/(^\s*)|(\s*$)/g, "") : "";
	}
	function isPassportUsername(userName) {
		var regex = /^\d+@i.com$/;
		return regex.test(userName);
	}
	function formatUserName(userName) {
		return userName.length > 8
				? userName.substring(0, 8) + "..."
				: userName;
	}
}

var xi = new XIUtils();
