document.write('<link href="http://nav2.tom.com/style/tomnav.css" rel="stylesheet" type="text/css">'); 
(function() {
//需要显示733宽的页面
var a773 = [
	'a8.ent.tom.com',
    'a8.yule.tom.com'
];

var PD_NAV_WIDTH = 950;

var isShowMoreButton = true;
var hostname = document.location.hostname;
for (var i = 0; i < a773.length; i++) {
    if (hostname == a773[i]) {
        isShowMoreButton = false;
        PD_NAV_WIDTH = 773;
        break;
    }
}

PD_NAV_WIDTH = ((typeof(PD_NAV_WIDTH) == "undefined") ? false : PD_NAV_WIDTH);

var pdNavWidth = PD_NAV_WIDTH ? 'style="width:' + PD_NAV_WIDTH + 'px;"' : "";

var ss = '<div id="tomglobalnav" '+pdNavWidth+'>\<div class="globaltop">\<div class="mainlinks">\<a href="http://www.tom.com/" target="_blank">TOM首页</a>\<a href="http://news.tom.com/" target="_blank">新闻</a>\<a href="http://sports.tom.com/" target="_blank">体育</a>\<a href="http://yule.tom.com/" target="_blank">娱乐</a>\<a href="http://she.tom.com/" target="_blank">时尚</a>\<a href="http://auto.tom.com/" target="_blank">汽车</a>\<a href="http://html.hjsm.tom.com/" target="_blank">小说</a>\<a href="http://game.tom.com/" target="_blank">网游</a>\</div>\<div class="passport" id="nologin" style="display:none">\<form id="loginForm" method="post" action="http://pass.tom.com/dologin.php" onsubmit="return PassUtils.checkLogin();">\<span>通行证：</span><input type="text" name="tomid" id="tomid" onfocus="if(this.value==\'输入邮箱\')this.value=\'\';this.style.color=\'black\';" onblur="PassUtils.autoComplete(\'tomid\')" />\<span>密码：</span><input type="password" name="tompwd" id="tompwd" onfocus="if(this.value==\'输入密码\')this.value=\'\';this.style.color=\'black\';" />\<input type="submit" value="登录" class="passsub"/>\<input type="hidden" name="issave" value="0" style="margin:0;" />\<input type="hidden" name="svcid" value="1" style="margin:0;" />\<input type="hidden" name="backurl" id="backurl" value="" style="margin:0;" />\<a target="_bank" href="http://pass.tom.com/register.php?backurl='+encodeURIComponent(document.location.href)+'">立即注册</a>\</form>\</div>\<div class="passport" id="login" style="display:none">\<a id="username" href="http://pass.tom.com/" target="_blank"></a> | <a href="http://post.tom.com/publish_news.php"  target="_blank">发表文章</a> | <a href="http://pass.tom.com/logout.php" onclick="document.location=\'http://pass.tom.com/logout.php?goto=\'+encodeURIComponent(\'\'+document.location.href);return false;">退出</a>\</div>\</div>\<div class="globalbtm">\<div class="sublinks">\<a href="http://club.tom.com/" target="_blank">社区</a>-\<a href="http://zhazha.tom.com/" target="_blank">喳喳</a>-\<a href="http://a8.yule.tom.com/" target="_blank">玩乐吧</a>-\<a href="http://skype.tom.com/" target="_blank">skype</a>-\<a href="http://stardoll.tom.com/" target="_blank">stardoll</a>-\<a href="http://life.news.tom.com/" target="_blank">生活</a>-\<a href="http://dushu.tom.com/" target="_blank">读书</a>-\<a href="http://alive.tom.com/" target="_blank">alive</a>-\<a href="http://photo.tom.com/" target="_blank">相册</a>-\<a href="http://shawei.tom.com/" target="_blank">鲨威</a>-\<a href="http://music.yule.tom.com/" target="_blank">音乐</a>-\<a href="http://test.tom.com/" target="_blank">测试</a>-'+ (isShowMoreButton ? '<a href="http://astro.tom.com/" target="_blank">星座</a>-' : '') +' <a href="http://story.tom.com/" target="_blank">故事</a>-\<a href="http://discovery.tom.com/" target="_blank">探索</a>-\<a href="http://nba.tom.com/" target="_blank">NBA</a>-\<a href="http://weiqi.sports.tom.com/" target="_blank">围棋</a>-\<a href="http://www.yxnpc.com/" target="_blank">游戏</a>-\<a href="http://dgbest.tom.com/" target="_blank">DGBest数码</a>\</div>'+ (isShowMoreButton ? '<div class="morelinks"><a href="http://nav2.tom.com/sitemap.html" target="_blank">更多</a></div>' : '') +'</div>\</div>';
document.write(ss);
		
})();

var PassUtils = {
  trim: function(text) {
    if (typeof(text) == "string") {
      return text.replace(/^\s*|\s*$/, "");
    } else {
      return text;
    }
  },
  isEmail: function(email) {
    var tomid	= /^(\d|[a-zA-Z])+(-|\.|\w)*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    return tomid.test( email );
  },
  password: function(password) {
	var tompwd	= /^[a-zA-Z0-9-_\?\.`!@#\$%\^\*\(\)\+\|\{\}\'\[\]\";:\/\?> <,]{6,32}$/;
	return tompwd.test(password);
  },
  isChinese: function(str) {
	var nLen = str.length;
	for(i = 0; i < nLen; i ++) {
	  if(str.charCodeAt(i) > 255)	return true;
	}
	return false;
  },
  autoComplete: function(id) {
	var tomid = this.trim(document.getElementById(id).value);
	var constant = "@tom.com";
	if(tomid.length > 0 && tomid.indexOf("@") == -1) {
	  document.getElementById(id).value = tomid + constant;
	}
	return;
  },
  GetCookie: function(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 this.GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
  },
  GetCookieVal: function(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
  },
  pwdKeypress: function(e) {
    e = e ? e : window.event;
    if (e.keyCode == 13) PassUtils.loginSub();
  },
  checkLogin: function() {
	var tomid = document.getElementById("tomid");
	var tompwd = document.getElementById("tompwd");
	if (tomid.value == "" || tomid.value == "输入邮箱") {
		tom.alert("请输入用户名", "INFO");
		tomid.focus();
		return false;
	}
	if (tompwd.value == "" || tompwd.value == "输入密码") {
		tom.alert("请输入密码", "INFO");
		tompwd.focus();
		return false;
	}
	try {
    	var params = new tom.XHConn.Parameter().append("tomid", tomid.value).append("tompwd", tompwd.value).append("rdm", new Date().getTime()).stringValue();
    	var xhconn = new tom.XHConn();
        xhconn.connectAsync("/passValidate.php", "post", params, function(xhr) {
            if (xhr.responseText == "true") {
              document.getElementById("loginForm").submit();
            } else {
              tom.alert("用户名或密码不正确", "ERROR");
            }
          });
	} catch (e) {
	  return true;
	}  
      
	return false;
  },
  init: function() {
    document.getElementById("backurl").value = encodeURIComponent(document.location.href);
	 var username = this.GetCookie("TOM_QU");
	 document.getElementById("nologin").style.display  = "none";
	 document.getElementById("login").style.display  = "none";
	 if(username != null) {
	   var lastUserName = username;
		//username	= username.substr(0, username.indexOf('@'));
		document.getElementById("username").innerHTML = username;
		document.getElementById("login").style.display  = "";
	 } else {
		document.getElementById("nologin").style.display  = "";
	 }
  }
}

PassUtils.init();

