DomainMap = {
	cookieDomain:'.163.com',
	serverHostName:'blog.163.com',
	serverDomain:'.blog.163.com',
	getParentDomain:function(s){
		if(s.indexOf('@') != -1||s.indexOf('_') != -1||s.indexOf('..') != -1||s.charAt(s.length -1) == '.'||s.toLowerCase().substr(s.length - 4) == '.www')
			return this.serverHostName + '/' +s;
		return s + this.serverDomain;
	}	
};
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
var Cookie = {
	set : function(name, value, expirationInDays, path, domain) {
		var cookie = escape(name) + "=" + escape(value)
		if (expirationInDays) {
			var date = new Date()
			date.setDate(date.getDate() + expirationInDays)
			cookie += "; expires=" + date.toGMTString()
		} 
		if (path) {
			cookie += ";path=" + path
		}
		if (domain) {
			cookie += ";domain=" + domain;
		}
		document.cookie = cookie

		if (value && (expirationInDays == undefined || expirationInDays > 0) && !this.get(name)) {
			Logger.error("Cookie (" + name + ") was not set correctly... The value was " + value.toString().length + " charachters long (This may be over the cookie limit)");
		}
	},
		
	get : function(name) {
		var pattern = "(^|;)\\s*" + escape(name) + "=([^;]+)"
		var m = document.cookie.match(pattern)
		if (m && m[2]) {			
			return unescape(m[2])
		}
		else return null
	},

	getAll : function() {
		var cookies = document.cookie.split(';')
		var cookieArray = []				

		for (var i = 0; i < cookies.length; i++) {			
			try {
				var name = unescape(cookies[i].match(/^\s*([^=]+)/m)[1])
				var value = unescape(cookies[i].match(/=(.*$)/m)[1])
			}
			catch (e) {
				continue
			}

			cookieArray.push({name : name, value : value})

			if (cookieArray[name] != undefined) {
				Logger.waring("Trying to retrieve cookie named(" + name + "). There appears to be another property with this name though.");
			}			

			cookieArray[name] = value
		}

		return cookieArray
	},

	clear : function(name) {
		this.set(name, "", -1);
		try{this.set(name, "", -1, "/",".163.com");}catch(e){}
	},

	clearAll : function() {
		var cookies = this.getAll()

		for(var i = 0; i < cookies.length; i++) {
			this.clear(cookies[i].name)
		}

	}
}   
function setHomePageUtil(url){
//	UserBean.incrPageView("sethomepage", null);
	if(document.all){
		document.body.style.behavior="url(#default#homepage)";
		document.body.setHomePage(url);
	}else{
		alert("浏览器不支持，请手动设置为首页");
	}
	return false;
}
function checkLogin(){
	var netAName = getLoginName();
	if(netAName!=null){
		return true;		
	}
	return blogTop_login();
}

function getLoginName(){
	var name = Cookie.get("NETEASE_AUTH_USERNAME");
	if(name == "") name = null;
	return name;
}

function afterLogin(loginName){
	if(loginName && loginName!=''){
		window.location.reload();
	}
}

function logout(){
	Cookie.set("NETEASE_AUTH_USERNAME",null,-1,"/",".163.com");
	Cookie.set("NETEASE_AUTH_USERNAME",null,-1,"/",null);
	Cookie.set("NETEASE_AUTH_SOURCE",null,-1,"/",".163.com");
	Cookie.set("NTES_SESS",null,-1,"/",".163.com");
	Cookie.set("USERNAME_FROM_URS",null,-1,"/",".163.com");
	Cookie.set("NETEASE_SSN",null,-1,"/",".163.com");	
	window.location.href="http://blog.163.com/exit.do?target="+encodeURIComponent(window.location.href);
	return false;
}
function blogLoginedAndShowMsgCount(o){			
	var $_blogusername=Cookie.get("NETEASE_AUTH_USERNAME");				 		
	var str='<a class="a07" href="http://blog.163.com/username/homeDispatch/?fromservicesmyblog">回我的博客</a><span class="sep">|</span><a class="a07" href="http://my.163.com/username/home/">娱乐中心</a><span class="sep">|</span><a class="a07" href="http://blog.163.com/username/message/" target="_blank" id="tlbrmsg">消息(<span class="red" id="tlbrmsg_size">remindCount</span>)</a>' ;
	str = str.replace(/username/g,$_blogusername).replace("remindCount",o.remindCount);
	document.getElementById("blog_loginedDiv").innerHTML = str;
	document.getElementById("blog_notLoginedDiv").style.display="none";
	document.getElementById("blog_loginedDiv").style.display="inline";
	document.getElementById("blog_logined_ExistDiv").style.display="inline";	
}
//功能服务页面顶部的登录
function blogTop_login(){		
	window.location.href='http://blog.163.com/pub/services/outlogin.html?url='+window.location.href; 
	return false;	
}
function lpSubmitSearch() {
	var q = document.getElementById("indexWords").value;
//	g_curSearchType = document.getElementById("curSearchType").value;
//	if (!g_curSearchType || g_curSearchType==""){
//		if (window.location.href.indexOf("http://mp3.163.com")>=0)  g_curSearchType="Music";
//		else g_curSearchType="blog";
//	}
//	var o="all";
//	if(g_curSearchType=="Music"){
//		o="name";
//	}else if(g_curSearchType=="Tag"){
//		o="photo";
//	}else if(g_curSearchType=="Author"){
//		o="nickname";
//	}
//	if (q=="" &&g_curSearchType!="Music")
//		document.getElementById("indexSearchForm").action= "http://blog.163.com/search.html";
//	else{
//		if (g_curSearchType=="Music")
//			document.getElementById("indexSearchForm").action= "http://mp3.163.com/iting/search/?key=" +q;
//		else
//			document.getElementById("indexSearchForm").action= "http://blog.163.com/search?t=" + g_curSearchType.toLowerCase() +"&q=" + encodeURIComponent(q) + "&o="+o+"";	
//	}
	document.getElementById("indexSearchForm").action = encodeURI('http://blog.youdao.com/search?q=' + q + ' site:blog.163.com&ue=utf8');
	document.getElementById("submitIndexSearchFormBtn").click();
}

//function doSearchNow(searchType){
//	document.getElementById("curSearchType").value=searchType;
//	lpSubmitSearch();
//	document.getElementById("searchTypeDiv").style.display="none";
//}

function getBlogMsgCount(){
	try{
		var $_blogusername=Cookie.get("NETEASE_AUTH_USERNAME");
		if ($_blogusername) document.write('<scri'+'pt src="http://blog.163.com/pub/services-js/count.do"></scri'+'pt>');	
	}catch(e){}
}

function popupMusic(){
    try{
		var netAName = Cookie.get("NETEASE_AUTH_USERNAME");
		var isLogined = (netAName != null && netAName != "");	
		var domain="";
		if (isLogined) domain =  DomainMap.getParentDomain(netAName);		
		var url ="";
		if (Browser.isFirefox ){			
			if (isLogined) url = "http://"+domain+"/musicBox.do";
			else {alert('该操作只支持IE浏览器');return false;}
			window.open(url+"?myInfoMusic","_blank","resizable=no,scrollbars=no,status=yes,width=365px,height=300px");	
		}
		else {
		  	if (isLogined) url = "http://"+domain+"/m";
			else url = "http://blog.163.com/m_i";
			window.open(url+"/?myInfoMusic","_blank","resizable=no,scrollbars=no,status=yes,width=768px,height=558px");
		}
	}catch(e){}
}

var layerIds =["searchTypeDiv","allLoginTypesDiv"];
function bodyClick(e) {
	for(var i=0;i<layerIds.length;i++){
		var ele = document.getElementById(layerIds[i]);
		if(ele != null && ele.style.display != "none") ele.style.display = "none";
	}
}

function stdClick(e) {	
	for(var i=0;i<layerIds.length;i++){
		if(document.getElementById(layerIds[i]) == null) return;
	}	
	var event = window.event || e;
	if(document.all){
			event.cancelBubble = true;
	}else{
		event.stopPropagation();
	}
}

//function stdbtnClick(e) {
//	var ele = document.getElementById("searchTypeDiv");
//	if(ele != null) ele.style.display = "";
//	_stopEvent(e);
//}

function stdbtnClickshowAllLoginTypesDiv(e) {
	var ele = document.getElementById("allLoginTypesDiv");
	if(ele != null){showAllLoginTypesDiv();}
	_stopEvent(e);	
}
function _stopEvent(e){
	var event = window.event || e;
	if(document.all){
			event.cancelBubble = true;
	}else{
		event.stopPropagation();
	}	
}

function niPageInit() {
	try{
		if(document.all) {
			document.body.attachEvent("onclick", bodyClick);
			for(var i=0;i<layerIds.length;i++){
				if(document.getElementById(layerIds[i]))
				document.getElementById(layerIds[i]).attachEvent("onclick", stdClick);
			}	
			
		}else{
			document.body.addEventListener("click", bodyClick, false);
			for(var i=0;i<layerIds.length;i++){
				if(document.getElementById(layerIds[i]))
					document.getElementById(layerIds[i]).addEventListener("click", stdClick, false);
			}
		}
	}catch(e){}
}


try{
	if (!document.all){
		window.addEventListener("DOMContentLoaded",niPageInit,false);
	}else{
		document.write("<script defer>niPageInit();<"+"/script>");
	}
}catch(e){}

function pageAnalytics(params){
	for(var id in params){var param=params[id];if(document.getElementById(id)==null)continue;var aArray=document.getElementById(id).getElementsByTagName("a");for(var i=0;i<aArray.length;i++){var a=aArray[i];var url=a.href;if(url.indexOf("#")>=0)continue;if(url.indexOf("?")<0)
			url=url+"?"+param;else
			url=url+"&"+param;a.href=url;}}
}


var $_blogTop_timecount=0;
var $_blogTop_blindTimerId = null;
var $_blogTop_documentTitle = document.title;
function blogTop_setMsgUI(remindCount){	
	$("tlbrmsg_size").innerHTML = remindCount;
	if($_blogTop_blindTimerId)
		window.clearTimeout($_blogTop_blindTimerId);
	if (remindCount > 0)
		$_blogTop_blindTimerId = window.setInterval(blogTop_blindTitleNow,1000);
	else 
	   document.title=$_blogTop_documentTitle;
}
function blogTop_blindTitleNow(){
	document.title = $_blogTop_timecount % 2 ? "【　　　】 - " + $_blogTop_documentTitle : "【新消息】 - " + $_blogTop_documentTitle;
	$_blogTop_timecount ++;
}
//起个定时器，去不断调用这个方法
function getBlogMsgCountAlways(){
	try{
		getBlogMsgCount();	
		window.setInterval(blogTop_pollMsgCount,60000);
	}catch(e){}
}
if (PollingBean == null) var PollingBean = {};
PollingBean._path = 'http://m.163.com/pl/dwr';
PollingBean.pollingMsg= function(p0, callback) {
	NEPlatform.DwrHook.Switch.shutDownHook();
    dwr.engine._execute(PollingBean._path, 'PollingBean', 'pollingMsg', p0, callback);
}
function  blogTop_pollMsgCount(){
	PollingBean.pollingMsg(currentUser.userId, {
			callback:function(oData){				
				blogTop_setMsgUI(oData.newMsgSize);				
			},"rpcType":dwr.engine.ScriptTag
		});	
}