if (NetEase==undefined){
	var NetEase={};
}

NetEase.ConfirmDlg = Class.create();

NetEase.ConfirmDlg.prototype = {
	initialize: function(sObjectName) {
		this._oOptions = Object.extend({
			sDlgId			: 	null,
			width			: 	250,
			height			:	85,
			left			:	300,
			top				: 	300,
			sAlert			:	'',
			sContent		: 	'',
			jsWindowManager	:	null,
			fnOK			:	null,
			oFnOKParam		:	null
		}, arguments[1] || {});
		this._sObjectName = sObjectName;
		this.oConfirmWin = null;
		this._init();
	},
	
	_init: function() {
		if(!this._oOptions.jsWindowManager){
		 	this._oOptions.jsWindowManager = new NetEase.JSWindowManager();
	 	}
	 	this.oConfirmWin = this._oOptions.jsWindowManager.createWindow(this._oOptions.sDlgId,{
              className:'g_crd_21', width:this._oOptions.width, height:this._oOptions.height,
              hasSystemBar:false,
              onTop:false,needCover:true,allowScroll:true,allowDrag:false
        });
        this.oConfirmWin.panel.innerHTML = 
        		'<div class="alert">' + this._oOptions.sAlert + '</div>'+
        		'<div class="cont"><span>' + this._oOptions.sContent + '</span></div>'+
        		'<div class="btnbar">'+
	    			'<input type="button" class="btncm btnok" value="确　定" id="$_confirmOK" />'+
	    			'<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>'+
	    			'<input type="button" class="btncm btncc" value="取　消" id="$_confirmCancel" onclick="'+
	    					this._sObjectName + '.close();" />'+
	  			'</div>';
	  	if(window.attachEvent){
			$('$_confirmOK').attachEvent("onclick", function(e){
				this.close();
				if (this._oOptions.fnOK != null) {
					this._oOptions.fnOK(this._oOptions.oFnOKParam);
				}
			}.bind(this));
		} else if(window.addEventListener){
			$('$_confirmOK').addEventListener("click", function(e){
				this.close();
				if (this._oOptions.fnOK != null) {
					this._oOptions.fnOK(this._oOptions.oFnOKParam);
				}
			}.bind(this),true);
		}
	},
	
	show: function() {
		this._oOptions.jsWindowManager.showWindow(this._oOptions.sDlgId);
	},
	
	close: function() {
		this._oOptions.jsWindowManager.closeWindow(this._oOptions.sDlgId);
	}
}
if (NetEase==undefined){
	var NetEase={};
}
NetEase.MsgTool = Class.create();
NetEase.MsgTool.prototype ={
	initialize: function(){
		this.options = Object.extend(
			{
				jsWindowManager: false,
				dwrAlert: false,
				dialogId: "cardDialog",
				style: '/style/common',
				objName: 'msgTool'
			}, arguments[0]||{});
		this.sendUserId = UD.visitorId;
		this.sendUserName = UD.visitorName;
		this.sendUserNickName = UD.visitorNickname;
		if(this.sendUserNickName == null || this.sendUserNickName.trim()==""){
			this.sendUserNickName = this.sendUserName;
		}
		this.cardpageHash = {};
		this.lastCategoryId = null;
		this.card_stat_slide = false;
		this.COM_ID = "$_commend"; //推荐的hash id
		this.initTemplate();
	 	if(!this.options.jsWindowManager){
		 	this.jsWindowManager = new NetEase.JSWindowManager();
	 	}else{
	 		this.jsWindowManager = this.options.jsWindowManager;
	 	}
	},	
	
	showSendCardDialog: function(receiveUserId,receiveUserName,receiveUserNickName){
		if(UD.visitorRank<0){
			showLoginDlg(UD.serverName);
			return;
		}
		if(receiveUserId == this.sendUserId){
			return;
		}		
		this.receiveUserId = receiveUserId;
		this.receiveUserName = receiveUserName.unescape_freemark();
		this.receiveUserNickName = receiveUserNickName.unescape_freemark();
		this._initSendCardDialog(this.options.dialogId);		
	},

	_initSendCardDialog: function(id){
		if(this.sendCardDialog == null){
			this.sendCardDialog = this.jsWindowManager.createWindow(id,{title:'赠送贺卡',
				width: 580, height: 480,notKeepPos: false, className:'g_win_10',beforeHiddenFunc: this._cancelCardSend.bind(this)
			});
		}
		this._loadSendCategorys();
		this.sendCardDialog.showWindow();
		this.sendCardDialog.focusWindow();				
	},
	
	_loadSendCategorys: function(){
		if(this.notFirstShow == null){
			this.notFirstShow = true;				
			var callback = function(cardCategoryList){
				var data ={cardCategoryList:cardCategoryList};
				this.sendCardDialog.panel.innerHTML = this.jst_cardsend_template.processUseCache(data);
				this.cardInfo = $("$$_card_info");
				this.cardContent = $("$$_card_content");
				this.cardTip = $("$$_card_tip");
				this.cardTip.style.display = "";
				this.cardSend = $("$$_card_send");
				this.cardSend.style.display = "none";
				this.cardReceive = $("$$_card_receive");
				this.cardReceive.innerHTML = '送给 <span class="a_a c_c d_d" href="http://'+DomainMap.getParentDomain(this.receiveUserName.escape()) +'/" target="_blank">'+this.receiveUserNickName.escape()+'</span> 的祝福';			
				this.cardBlessContent = $("$$_bless_content");
				this.cardInputZone = $("$$_card_input_zone");
				this.cardInputTip = $("$$_card_input_tip");
				this.commendCategory = $("$$_commend_category");
				if(this.commendCategory)
					this._selectSendCategory(this.commendCategory,this.COM_ID);	
			}.bind(this);
			CardBean.getCardCategoryList(callback);			
		}else{
			this.cardReceive.innerHTML = '送给 <span class="a_a c_c d_d" href="http://'+DomainMap.getParentDomain(this.receiveUserName.escape()) +'/" target="_blank">'+this.receiveUserNickName.escape()+'</span> 的祝福';			
		}
	},
	
	_selectSendCategory: function(obj,id){
		if(this.lastObj != null){
			Element.removeClassName(this.lastObj,'selected');
		}
		Element.addClassName(obj,'selected');
		this.lastObj = obj;
		if(this.cardpageHash[id]==null){
			var loadFunc;
			if(id == this.COM_ID){
				loadFunc = this._loadCommendFunc.bind(this);
			}else{
				loadFunc = this._loadCommonFunc.bind(this);
			}
			this.cardpageHash[id] = new NetEase.CachePage({
				loadFunc:loadFunc,loadParam:{cateId:id},presentFunc:this._presentCardsFunc.bind(this),presentSlideFunc:this._presentCardFunc.bind(this),
				organizeFunc:this._organizeFunc.bind(this),detSlideIterator:this._detSlideIterator.bind(this),
				pageSize:9,prefetch:true,prefetchMulti:1,markID:false,customPageIds:['$$_card_prev','$$_card_next'],
				styleDir:this.options.style
			});
			this.cardpageHash[id].nextPage();
			if(this.lastCategoryId!=null)
				this.cardpageHash[this.lastCategoryId].resetCachePageEvent();
		}else{
			if(this.lastCategoryId != id || this.card_stat_slide == true){
				if(this.lastCategoryId != id)
					this.cardpageHash[this.lastCategoryId].resetCachePageEvent();
				this.cardpageHash[id].refreshCurPage();
			}	
		}
		if(id == this.COM_ID){
			this._showCardCommendInfo(true);
		}else{
			this._showCardCommendInfo(false);			
		}
		this.lastCategoryId = id;
		this.card_stat_slide = false;
	},
		
	_organizeFunc: function(dataList){
		for(var i=0;i<dataList.length;i++){
			dataList[i].smallSrc=this._constructSrc(dataList[i].srcId,false);
			dataList[i].bigSrc=this._constructSrc(dataList[i].srcId,true);
		}
		return dataList;
	},
	
	_constructSrc: function(srcId,isBig){
		var aId = srcId % 10;
		if(isBig)
			return "http://cardimg.163.com/mcards/"+aId+"/big/"+srcId+".swf";
		return "http://cardimg.163.com/mcards/"+aId+"/small/s"+srcId+".swf";
	},
		
	_loadCommendFunc: function(param,callback){
		CardBean.getCommendCardInfoList(param.offset,param.limit,callback);
	},
	
	_loadCommonFunc: function(param,callback){
		CardBean.getCardInfoList(param.cateId,param.offset,param.limit,callback);
	},
	
	_presentCardsFunc: function(dataList){
		var data={cardInfoList: dataList};
		this.cardContent.innerHTML = this.jst_cards_template.processUseCache(data);
		this.cardContent.style.borderWidth="1px";
		this.cardTip.style.display = "";
		this.cardSend.style.display = "none";
	},
		
	_presentCardFunc: function(cardInfo){
		if(cardInfo){
			var data={cardInfo: cardInfo};
			this.cardContent.innerHTML = this.jst_card_template.processUseCache(data);
			this.cardContent.style.borderWidth="0px";
			this.cardTip.style.display = "none";
			this.cardSend.style.display = "";
			this.cardBlessContent.focus();
		}
	},
	
	_selectCardInfo: function(id){
		if(this.cardpageHash[this.lastCategoryId]){
			this.cardpageHash[this.lastCategoryId].changeToSlideMode(id);
			this.card_stat_slide = true;
			this._showCardCommendInfo(false);
			this.cardBlessContent.focus();
		}
	},
	
	_showCardCommendInfo: function(show){
		if(show == true){
			this.cardInfo.style.display = "";
		}else{
			this.cardInfo.style.display = "none";			
		}
	},
	
	_detSlideIterator: function(id,e){
		if(id == e.id)
			return true;
		return false;
	},

	_cancelCardSend: function(){
		if(this.cardpageHash[this.lastCategoryId]){
			this.cardpageHash[this.lastCategoryId].refreshCurPage();
			this.card_stat_slide = false;
			if(this.lastCategoryId== this.COM_ID){
				this._showCardCommendInfo(true);
			}else{
				this._showCardCommendInfo(false);			
			}
		}		
	},
	
	_submitCardSend: function(){
		if(this.cardpageHash[this.lastCategoryId]){
			var content = this.cardBlessContent.value.trim();
			if(content==""){
				alert("请输入您的祝福!");
				this.cardBlessContent.focus();
				return;
			}
			if(content.length > 1000){
				alert("祝福语长度不能超过1000");
				this.cardBlessContent.focus();
				return;
			}
			var obj = this.cardpageHash[this.lastCategoryId].getSelectSlide();
			if(obj){
				this.cardInputZone.style.display='none';
				this.cardInputTip.style.display='block';
//				var cardSRMap = {cardId:obj.id,sendUserId:this.sendUserId,
//				sendUserName:this.sendUserName,sendUserNickName:this.sendUserNickName,
//				receiveUserId:this.receiveUserId,receiveUserName:this.receiveUserName,
//				receiveUserNickName:this.receiveUserNickName,content:content};
				
				RemindBean.sendCard(this.sendUserId, this.sendUserName, this.sendUserNickName,
					this.receiveUserId, this.receiveUserName, this.receiveUserNickName, 
					content, obj.id, UD.visitorIP, {
					callback:this._afterCardSent.bind(this),
					errorHandler: function(errorString, ex) {
						this._afterCardSent(-1);
						filterWarning(ex, false);;
					}.bind(this)
					}
				);				
			}
		}	
	},
	
	_afterCardSent: function(result){
		if(result <0){
			switch(result){
				case -3:	this.options.dwrAlert("发送的博友不存在", "error"); break;
				case -4:	this.options.dwrAlert("消息内容中包含敏感关键字", "error"); break;
				case -5:	this.options.dwrAlert("消息接受者在您的黑名单中，发送失败", "error"); break;
				case -10:	this.options.dwrAlert("发送贺卡失败!贺卡只能博友之间发送!", "error"); break;
				default:	this.options.dwrAlert("发送贺卡失败", "error"); break;
			}
		}else{
			this.options.dwrAlert("发送贺卡成功!","ok");
			this._cancelCardSend();
		}
		this.cardInputZone.style.display='block';
		this.cardInputTip.style.display='none';
	},
	_getCaptchaImgSrc: function(){
		var _iRandom = Math.floor(Math.random()*10001);
		var _sId = (_iRandom+"_"+new Date().getTime()).toString();
		var ss = "/cap/captcha.jpgx?parentId=" + encodeURIComponent(UD.hostId) + "&" + _sId;
		return ss;
		},
	genValidCodeImg: function(){		   
		var _oCodeDiv = $("valimg");
		
			//不管页面中是否已经生成过验证码, 都重新生成一次
		if(_oCodeDiv != undefined && _oCodeDiv != null && _oCodeDiv != "") 						
				_oCodeDiv.src =  this._getCaptchaImgSrc() ;
					
	},
	//添加一个判定是否为陌生人的参数isStranger，布尔值
		msgTo: function(fromId, fromName, fromNickName, toId, toName, toNickName,isStranger){
		if(!this.messageWindow){
			this.messageWindow = this.jsWindowManager.createWindow('remind_message',{
					className:"g_win_6",width: 400, height:240,onTop:true,notKeepPos: true,title:"发送新消息"
				}
			);
		}
		
		var s = [];
		s.push('<div class="g_t_14  g_t_left g_c_mvlft">发送给：');
		s.push(toNickName.escape());
		s.push('</div>');
		s.push('<div><textarea id="remind_msg" class="g_h_105 g_w_90" onpropertychange="textareaLimit(this, 250)"></textarea></div>');
		if (isStranger){
			 s.push('<div class="g_t_14  g_t_left g_c_mvlft" ><span style="line-height:24px;align:middle;">验证码：</span><input  style="width:70px" value="" maxlength="4" id="msgToolValcode" /><img id="valimg" class ="valcodeimg" style="position: absolute; width: 60px; height: 24px; margin-left: 10px;"  alt="验证码" src="');
		     s.push(this._getCaptchaImgSrc());
		     s.push('" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="');
		     s.push('msgTool.genValidCodeImg();return false;">看不清 换一张</a></div>');
		}
		s.push('<div class="g_h_30 g_t_center">');
		s.push('<div id="ne_frame_submit"><input type="button" class="btncm btnok" value="确　定" onclick="');
		s.push(this.options.objName);
		if (isStranger){
			s.push('.submitMsgWithValcode(');	
		}
		else{
			s.push('.submitMsg(');
		}
		s.push(fromId);
		s.push(', ');
		s.push(toId);
		s.push(', \'' + toName + '\'');
		s.push(');" />');
		s.push('<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>');
		s.push('<input type="button" class="btncm btncc" value="取　消" onclick="'+this.options.objName+'.closeMsg();" />');
		s.push('</div><div id="ne_frame_info" style="display:none;">处理中...</div>');
		s.push('</div>');
		
		this.messageWindow.panel.innerHTML= s.join('');
		this.messageWindow.showWindow();
		$('remind_msg').focus();		
	},
	submitMsgWithValcode:function(fromId, toId, toName){
		 var msgValcode =  $F('msgToolValcode').trim();
		 if(fromId == toId){
			this._afterSubmit(-7);
			return;
		}
		var _msg = $F("remind_msg").trim(); 
		if(_msg.length==0){this.options.dwrAlert("消息内容不能为空!","info");this.genValidCodeImg();  return;};					
		if(_msg.length>250){this.options.dwrAlert("消息长度不能超过250!","info");this.genValidCodeImg();  return;};
        if (msgValcode == undefined || msgValcode == null || msgValcode == ""){                 	    
        	 this.options.dwrAlert("请输入验证码!","error");  
        	 this.genValidCodeImg();            
               
        	return ;
        }
        else if (msgValcode != undefined && msgValcode != null && msgValcode != "" && msgValcode.length < 4){ 
        	this.options.dwrAlert("验证码为4位!","error");        
        	 this.genValidCodeImg();                           
        	return ;
        }
        else {
        	$("ne_frame_submit").style.display='none';
		    $("ne_frame_info").style.display='';				
		     RemindBean.sendUserMsgWithValcode(toId, toName, _msg, msgValcode, {
			callback:this._afterSubmit.bind(this),
			errorHandler: function(errorString, ex) {
				if (ex == undefined || ex == null ||ex.type == "CaptchaException") {
					this.options.dwrAlert("验证码不正确!", "error"); 
					this.genValidCodeImg();  
					$("ne_frame_info").style.display='none';
		            $("ne_frame_submit").style.display='';	    
				}
				else {
				this._afterSubmit(-1);
				filterWarning(ex, false);;
				}
			}.bind(this)
		});
        }
	},
	submitMsg: function(fromId, toId, toName){
		if(fromId == toId){
			this._afterSubmit(-7);
			return;
		}
		var _msg = $F("remind_msg").trim(); 
		if(_msg.length==0){this.options.dwrAlert("消息内容不能为空!","info");return;};					
		if(_msg.length>250){this.options.dwrAlert("消息长度不能超过250!","info");return;};
		$("ne_frame_submit").style.display='none';
		$("ne_frame_info").style.display='';		
		
		RemindBean.sendUserMsg(toId, toName, _msg, {
			callback:this._afterSubmit.bind(this),
			errorHandler: function(errorString, ex) {
				this._afterSubmit(-1);
				filterWarning(ex, false);;
			}.bind(this)
		});
	},
	
	_afterSubmit: function(result){
		if(result <0){
			switch(result){
				case -3:	this.options.dwrAlert("发送的博友不存在!", "error"); break;
				case -4:	this.options.dwrAlert("消息内容中包含敏感关键字", "error"); break;
				case -5:	this.options.dwrAlert("消息接受者在您的黑名单中，发送失败!", "error"); break;
				case -7:	this.options.dwrAlert("不能给自己发送消息!", "error"); break;
				case -11:	this.options.dwrAlert("消息发送过于频繁，请三分钟后再试!", "error"); break;
				default:	this.options.dwrAlert("发送消息失败!", "error"); break;
			}
			this.genValidCodeImg(); 
			$("ne_frame_submit").style.display='';
			$("ne_frame_info").style.display='none';
		}else{
			this.options.dwrAlert("发送消息成功!","ok");
			this.closeMsg();
		}
	},
	
	closeMsg: function(){
		this.messageWindow.hiddenWindow();		
	},
	
	initTemplate: function(){		
		this.jst_cardsend_template = 
		new String('{var commentInfo = ""}\
		 <div>\
			<div class="g_tab_btn03">\
			{for category in cardCategoryList}\
				{if category.commend == true}\
					{var commentInfo = category.info}\
					<div id="$$_commend_category" class="selected" onclick="'+this.options.objName+'._selectSendCategory(this,\''+this.COM_ID+'\');">${category.name|default:""|escape}</div>\
				{else}\
					<div onclick="'+this.options.objName+'._selectSendCategory(this,\'${category.id}\');">${category.name|default:""|escape}</div>\
				{/if}\
			{/for}\
			</div>\
			<table class="case" border="0" cellspacing="0" cellpadding="0">\
				 <tr id="$$_card_info"><td width="40">&nbsp;</td><td class="g_t_left"><p class="g_h_20 clr00">${commentInfo|default:""|escape}</p></td><td width="40">&nbsp;</td></tr>\
				 <tr><td width="40" class="g_t_left"><div class="g_img_14 g_c_hand p_ p27" onmouseover="Element.replaceClassName(this,\'p27\',\'p25\');" onmouseout="Element.replaceClassName(this,\'p25\',\'p27\');" title="上页" id="$$_card_prev">&nbsp;</div></td>\
				 <td><div class="cnt" id="$$_card_content"></div></td>\
				 <td width="40" class="g_t_right"><div class="g_img_14 g_c_hand p_ p28" onmouseover="Element.replaceClassName(this,\'p28\',\'p26\');" onmouseout="Element.replaceClassName(this,\'p26\',\'p28\');" title="下页" id="$$_card_next">&nbsp;</div></td></tr>\
				 <tr id="$$_card_tip"><td>&nbsp;</td><td class="g_t_left g_h_25 clr02"><span class="n_ n9">&nbsp;</span>点击贺卡或者贺卡名，查看贺卡并发送。</td><td class="g_w_5">&nbsp;</td></tr>\
			</table>\
			<table class="case" border="0" cellspacing="0" cellpadding="0" id="$$_card_send">\
				<tr><td width="40">&nbsp;</td><td class="g_t_left g_h_25" id="$$_card_receive" style="font-size:14px;">&nbsp;</td><td width="40">&nbsp;</td></tr>\
				<tr><td>&nbsp;</td><td><textarea class="g_h_105" id="$$_bless_content"></textarea></td><td>&nbsp;</td></tr>\
				<tr><td>&nbsp;</td><td class="g_t_center g_h_30" >\
					<div id="$$_card_input_zone">\
					<input type="button" class="btncm btnok" value="发　送" onclick="'+this.options.objName+'._submitCardSend();"/>\
					<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>\
					<input type="button" class="btncm btncc" value="取　消" onclick="'+this.options.objName+'._cancelCardSend();"/>\
					</div><div id="$$_card_input_tip" style="display:none;">贺卡发送中...</div>\
				</td><td>&nbsp;</td></tr>\
			</table>\
		</div>');		
		
		this.jst_cards_template = 
			new String('{for cardInfo in cardInfoList}\
			 <div class="item">\
			 	<span class="a_a c_c" onclick="'+this.options.objName+'._selectCardInfo(\'${cardInfo.id}\');">\
			 	<img src="${cardInfo.smallSrc|default:"#"}" /></span>\
				<p><span class="a_a d_d" onclick="'+this.options.objName+'._selectCardInfo(\'${cardInfo.id}\');">${cardInfo.name|default:""|escape}</span></p>\
			</div>\
			{/for}\
			<br class="g_p_clear" />');
		
		this.jst_card_template = new String('<div><p class="g_h_20 g_t_14 g_t_bold clr00">${cardInfo.name|default:""|escape}</p></div>\
								  <div><embed width="500px" height="400px" src="${cardInfo.bigSrc|default:"#"}" quality="high" \
								 	  pluginspage="http://www.macromedia.com/go/getflashplayer" \
									  type="application/x-shockwave-flash" wmode="transparent"></embed>\
								  </div>');	
	}
	
}

/*
 * NetEase SimpleDragDrop 拖拽效果简化版
 * 实现页面元素能够在页面的控制范围内拖放，并且不具备对元素的强制归位功能
 * method:
 * 创建SimpleDragDrop对象
 * 		top: 可拖拽范围的起始点	  当top和height有false则该方向上范围失效
 * 		left: 可拖拽范围的起始点 当left和width有false则该方向上范围失效
 * 		width: 可拖拽范围宽度
 * 		height: 可拖拽范围长度	
 *		useDragOpacity: true     // 拖动时是否启用阴影效果 add by mml
 * 		simpleDrag: false         // 拖动时是否启动简单模式 add by bezy
 * 		constraint: 对拖拽方向的控制 all||horizontal||vertical
 * 		handle: 用于定义可拖拽的handle.具体为css名称,当不存在该ccs的元素时,则使用整个元素
 * 		starteffect：拖拽开始的效果函数
 * 		endeffect：	 拖拽结束的效果函数
 * addDraggable：	添加一个可拖拽的对象
 * 		element: 可拖拽元素,可以是整个对象或者对象id
 * removeDraggable： 移除一个可拖拽的对象
 * 		element: 可拖拽元素,可以是整个对象或者对象id
 */
if (NetEase==undefined){
	var NetEase={};
}

NetEase.SimpleDragDrop = Class.create();
NetEase.SimpleDragDrop.prototype = {
	initialize: function(){
		this.drags = [];
		// 定义拖拽的最大活动区域
		this.options = Object.extend({
			top: -1,
			left: 0,
			width: 0,
			height: 0,        //0 表示没有限制,同时当left 为0时,width 是没有意义的;top 和 height 同理
			constraint: 'all',	//horizontal || vertical
			useDragOpacity: true,     // 拖动时是否启用阴影效果
			simpleDrag: false          //是否启用简单拖动模式
		}, arguments[0] || {});
		this.options.top = parseInt(this.options.top || '0');
		this.options.left = parseInt(this.options.left || '0');
		this.options.width = parseInt(this.options.width || '0');
		this.options.height = parseInt(this.options.height || '0');
	},
	
	addDraggable: function(element){
		new NetEase.Draggable(element, this,
			Object.extend(this.options, arguments[1]||{}));
	},
	
	removeDraggable: function(element){
		element = $(element);
		this.drags.select(function(e){ return e.getElement()==element;}).each(function(e){e.destroy()});
	},
	
  	register: function(draggable) {
    	if(this.drags.length == 0) {
      		this.eventMouseUp   = this.endDrag.bindAsEventListener(this);
      		this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
      		this.eventKeypress  = this.keyPress.bindAsEventListener(this);
      
      		Event.observe(document, "mouseup", this.eventMouseUp);
      		Event.observe(document, "mousemove", this.eventMouseMove);
      		Event.observe(document, "keypress", this.eventKeypress);
    	}
    	this.drags.push(draggable);
  	},
  
  	unregister: function(draggable) {
    	this.drags = this.drags.reject(function(d) { return d==draggable });
    	if(this.drags.length == 0) {
      		Event.stopObserving(document, "mouseup", this.eventMouseUp);
      		Event.stopObserving(document, "mousemove", this.eventMouseMove);
      		Event.stopObserving(document, "keypress", this.eventKeypress);
    	}
  	},
  
  	activate: function(draggable) {
    	window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
    	this.activeDraggable = draggable;
  	},
  
  	deactivate: function() {
    	this.activeDraggable = null;
  	},
  
  	updateDrag: function(event) {
    	if(!this.activeDraggable) return;
    	var pointer = this.activeDraggable.getPointer(event);//[Event.pointerX(event), Event.pointerY(event)];
    	// Mozilla-based browsers fire successive mousemove events with
    	// the same coordinates, prevent needless redrawing (moz bug?)
    	if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
    	this._lastPointer = pointer;
    	this.activeDraggable.updateDrag(event, pointer);
  	},
  
  	endDrag: function(event) {
    	if(!this.activeDraggable) return;
    	this._lastPointer = null;
    	this.activeDraggable.endDrag(event);
    	this.activeDraggable = null;
  	},
  
  	keyPress: function(event) {
    	if(this.activeDraggable)
      	this.activeDraggable.keyPress(event);
  	}
};


NetEase.Draggable = Class.create();
NetEase.Draggable.prototype = {
 	initialize: function(element, draggables) {
    	var options = Object.extend({
      		handle: false,
      		starteffect: function(element) { 
        		new Effect.Opacity(element, {duration:0.2, from:1.0, to:0.7}); 
      		},
      		endeffect: function(element) { 
       	 		new Effect.Opacity(element, {duration:0.2, from:0.7, to:1.0}); 
      		},
      		zindex: 1000,
      		onDrag: Prototype.emptyFunction,
      		useDragOpacity: true,
      		simpleDrag: false
    	}, arguments[2] || {});

    	this.element = $(element);
    
    	if(options.handle && (typeof options.handle == 'string'))
      		this.handle = this._childrenWithClassName(this.element, options.handle)[0];  
    	if(!this.handle) this.handle = $(options.handle);
    	if(!this.handle) this.handle = this.element;
    
    	Element.makePositioned(this.element); // fix IE    

   		this.delta    = this.currentDelta();
    	this.options  = options;
    	this.dragging = false;   

    	this.eventMouseDown = this.initDrag.bindAsEventListener(this);
    	Event.observe(this.handle, "mousedown", this.eventMouseDown);
    	
    	this.draggables = draggables;
    
    	this.draggables.register(this);
    	
    	if(this.options.useDragOpacity == false || this.options.simpleDrag){
    		this.options.starteffect = null;
    		this.options.endeffect = null;	
    	}
  	},
  	
  	getElement: function(){
  		return this.element;
  	},
  
  	destroy: function() {
    	Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
    	this.draggables.unregister(this);
  	},
  
  	currentDelta: function() {
  		if(this._simpleNode) _e = this._simpleNode;
  		else _e = this.element;
   	 	return([
      		parseInt(Element.getStyle(_e,'left') || '0'),
      		parseInt(Element.getStyle(_e,'top') || '0')]);
  	},
  	getPointer: function(event){
  		if(this.element.container=='in'){
  			return [Event.cursorX(event), Event.cursorY(event)];
  		}else{
  			return [Event.pointerX(event), Event.pointerY(event)];
  		}
  	},
  	initDrag: function(event) {
    	if(Event.isLeftClick(event)) {    
      		// abort on form elements, fixes a Firefox issue
      		var src = Event.element(event);
      		if(src.tagName && (
        		src.tagName=='INPUT' ||
        		src.tagName=='SELECT' ||
        		src.tagName=='OPTION' ||
        		src.tagName=='BUTTON' ||
        		src.tagName=='TEXTAREA')) return;
        
      		var pointer = this.getPointer(event);//[Event.pointerX(event), Event.pointerY(event)];
      		var pos     = Position.cumulativeOffset(this.element);
      		this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
      
      		this.draggables.activate(this);
     	 	Event.stop(event);
    	}
 	},
  
  	startDrag: function(event) {
    	this.dragging = true;
    
    	if(this.options.zindex) {
     		this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
      		this.element.style.zIndex = this.options.zindex;
    	}
    	
    	if(this.options.simpleDrag) {
	        this._simpleNode = this.element.cloneNode(false);
	        this._simpleNode.innerHTML='';
	        this._simpleNode.className='';
	        Element.setStyle(this._simpleNode,{zIndex:this.element.style.zIndex,border:'2px dotted red',cursor:'move',width:this.element.offsetWidth+'px',height:this.element.offsetHeight+'px'});
	        Element.setStyle(this.element,{display:'none'});
	  		if(this.element.container=='in'){
	  			UD.body.appendChild(this._simpleNode);
	  		}else{
	    	    document.body.appendChild(this._simpleNode);
			}
    	    Element.makePositioned(this._simpleNode); // fix IE
      		var pointer = this.getPointer(event);//[Event.pointerX(event), Event.pointerY(event)];
      		var pos     = Position.cumulativeOffset(this._simpleNode);
      		this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
    	}
    
    	if(this.options.starteffect) this.options.starteffect(this.element);
  	},
  
  	updateDrag: function(event, pointer) {
    	if(!this.dragging) this.startDrag(event);
    	Position.prepare();
    	this.draw(pointer);
    	if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
    	this.options.onDrag();
    	Event.stop(event);
  	},
  
  	finishDrag: function(event, success) {
    	this.dragging = false;
    	this.delta = this.currentDelta();
        this.element.style.zIndex = this.originalZ;
		
		if(this._simpleNode){
			if(this.element.container=='in'){
//				UD.body.removeChild(this._simpleNode);
				Element.removeChild(this._simpleNode);
			}else{
//				document.body.removeChild(this._simpleNode);
				Element.removeChild(this._simpleNode);
			}
			Element.setStyle(this.element, {left: this.delta[0]+'px',top: this.delta[1]+'px',display:'block'});	
		}
		
    	if(this.options.endeffect) 
      		this.options.endeffect(this.element);

    	this.draggables.deactivate(this);
  	},
  
  	keyPress: function(event) {
    	if(event.keyCode!=Event.KEY_ESC) return;
    	this.finishDrag(event, false);
    	Event.stop(event);
  	},
  
  	endDrag: function(event) {
   		if(!this.dragging) return;
    	this.finishDrag(event, true);
    	Event.stop(event);
  	},
  
  	draw: function(point) {
  		var _e;
  		if(this._simpleNode) _e = this._simpleNode;
  		else _e = this.element;

    	var pos = Position.cumulativeOffset(_e);
    	var d = this.currentDelta();
    	pos[0] -= d[0]; pos[1] -= d[1];
    
        var p = [0,1].map(function(i){ 
      		return (point[i]-pos[i]-this.offset[i]) 
    		}.bind(this));
    		
    	if (this.options.left!=0){
    		if ((this.options.width!=0) && (p[0]>this.options.left+this.options.width))
    			p[0] = this.options.left+this.options.width;
    		else if (p[0]<this.options.left)
    			p[0] = this.options.left;
    	}
    	
    	if (this.options.top!=0){
	    	if ((this.options.height!=0) && (p[1]>this.options.top+this.options.height))
    			p[1] = this.options.top+this.options.height;
    		else if (p[1]<this.options.top)
    			p[1] = this.options.top;
    	}
    
    	if(this.options.constraint=='horizontal')
      		Element.setStyle(_e, {left: p[0]+'px'});
   		else if(this.options.constraint=='vertical')
      		Element.setStyle(_e, {top: p[1]+'px'});
      	else
    		Element.setStyle(_e, {
    			left: p[0] + 'px', top: p[1] + 'px'});
    	if (Element.getStyle(_e, 'visibility') == 'hidden')
    		Element.setStyle(_e, {visibility: ''}); // fix gecko rendering
  	},
  
  	_childrenWithClassName: function(element, className) {  
  		return $A($(element).getElementsByTagName('*')).select(
	    	function(c) { return Element.hasClassName(c, className) });
	}  
}
/**
* NetEase QuickLogin快速登陆，也可用于首页登陆模块
* @param {Boolean}bFromIndex
*		  是否是首页调用
*/

if (NetEase==undefined){
	var NetEase={};
}
NetEase.quickLoginTemplate = null;
NetEase.indexLoginTemplate = null;
var type163 = 0;
var typePopo = 1;
var type126 = 2;
var type188 = 3;
var typeVip =4;
var typeYeah =5;
var typePlayer =6;
//blog自动登录cookie，格式type;
var ckLoginInfoKey = "NEBLOG_LOGIN";
//自动登录cookie信息
var ckLoginInfo = {type:null, name:null, pass:null};
var ckPath = "/";
var ckDomain=DomainMap.cookieDomain;
var errInfo = ["用户名或密码不正确，请重新输入", "该网易博客用户名不存在", "超时退出或无权限访问，请重新登录"];

NetEase.QuickLogin = Class.create();
/**
 * bFromIndex [Boolean]	是否首页登录框
 */
NetEase.QuickLogin.prototype = {
	initialize: function(presentShowId, serverName, bFromIndex){
		this.options = Object.extend({
			err:false,
			jsWindowManager:null,
			loginTarget: null,
			invitor:null, //邀请者用户名
			group:null, //邀请者把注册用户加入到的博友分组名（中文）
			app:null //游戏组件app的id
		}, arguments[3] || {});
		//全局变量
		this.presentShowId = presentShowId;
		this.serverName = serverName;
		this.bFromIndex = bFromIndex;		
		this.err = false;
		this.jsWindowManager = this.options.jsWindowManager;
		this.objUsername;
		this.objPassword;
		this.objSetCkCheck;
		this.frmLogin;
		this.divNotice;
		this.btn_login;
		this.btn_reg;
		this.curUserType = 0;
		this.noticeInit = "请输入用户名和密码登录";
		this.noticeAccount = "请输入网易通行证用户名";
		this.noticePassword = "请完整填写登录信息，密码不能为空";
		this.isPwdFromCk = false;
		this.pwdFromCk;
		this.pwdFromCkTrim;	
		this.strUsername;
		this.strPassword;
		this.qLoginZone = null;
		this.loginTarget = this.options.loginTarget; 
		this._load();
	},
	_load: function(){	
		//从cookie得到用户名，密码等。get Login info  from last login .
		getLoginCookie();
		
		if(!this.bFromIndex || this.presentShowId=="qIndexLoginDiv"){
			//快速登录
			if (NetEase.quickLoginTemplate == null) 
				NetEase.quickLoginTemplate = quicklogin_jst;
			//注册通行证按钮的跳转地址
			var regUrl = "http://reg.163.com/reg0.shtml?product=blog&url=http://blog.163.com/ntesRegBlank.html";
			//如果是组件邀请
			if(this.options.invitor != null && this.options.group != null){
				regUrl += encodeURIComponent("?invitor=" + this.options.invitor + "&group=" + this.options.group);
				if(this.options.app != null) {
					regUrl = "http://reg.163.com/reg0.shtml?product=blog&url=http://my.163.com/webos/ntesRegBlankMy.html";
					regUrl += encodeURIComponent("?invitor=" + this.options.invitor + "&group=" + this.options.group);
					regUrl += encodeURIComponent("&app=" + this.options.app);
				}
			}
			var data={err:false, regUrl:regUrl};
			var result = NetEase.quickLoginTemplate.processUseCache(data);
			if(this.presentShowId){
				this.qLoginZone = this.jsWindowManager.createWindow(this.presentShowId, {
					className:'g_win_4',width: 408, height:236,hideFlash:true,
					title:'登录', onTop:true,notKeepPos:true
				});			
				this.qLoginZone.panel.innerHTML = result;	
				this.qLoginZone.showWindow();
			}
		}else{
			//首页登录
			if (NetEase.indexLoginTemplate == null) 
				NetEase.indexLoginTemplate = indexlogin_jst;
			
			var data={err:false};
			var result = NetEase.indexLoginTemplate;//.process(data);
			$("outLoginDiv").innerHTML = result;	
		}
		var input = new NECtrl.CxtInput('div_in_username',{inputId:'in_username',className:'cxt-input',onchange:neteasebloglogin_getList,onsuccess:function(){$('in_password').focus();}});
		this.frmLogin = $("frmLogin");
		this.frmLogin.setAttribute('autocomplete', 'off');
		this.divNotice = $("notice_bar");
		this.objUsername = $("in_username");
		this.objPassword = $("in_password");
		this.objSetCkCheck = $("setCookieCheck");
				
		if(document.all) { // ie
			this.objPassword.attachEvent("onfocus", this.fnPassOnFocus.bind(this));
			this.objPassword.attachEvent("onblur", this.checkPassword.bind(this));
			$("qLoginButt").attachEvent("onclick", this.dologin.bind(this));
			this.frmLogin.attachEvent("onkeypress", this.frmDologinIE.bind(this));
			this.objSetCkCheck.attachEvent("onclick", this.changeCookieCheck.bind(this));
		}
		else {
			this.objPassword.addEventListener("focus", this.fnPassOnFocus.bind(this), true);
			this.objPassword.addEventListener("blur", this.checkPassword.bind(this), true);			
			$("qLoginButt").onclick = this.dologin.bind(this);
			this.frmLogin.onkeypress = this.frmDologin.bind(this);	
			this.objSetCkCheck.onclick = this.changeCookieCheck.bind(this);			
		}	
		this.selectUserType();
	},
	
	showWindow: function(target, title, submitButtonValue){
		if(target){
			this.loginTarget = target;
		}
		if(title){
			this.jsWindowManager.updateTitle(this.presentShowId, title);
		}
		if(submitButtonValue){
			$("qLoginButt").value = submitButtonValue;
		}	
		this.qLoginZone.showWindow();
	},
	
	frmDologinIE: function(){
		if(event.keyCode==13) 
			this.dologin();
	},
	frmDologin: function(event){
		if(event.keyCode==13) 
			this.dologin();
	},
	
	changeCookieCheck:function(){
		if(!this.objSetCkCheck.checked){	
			//get Login type from last login 
			clearLoginCookie();			
		}
	},
	
	checkUsername: function(){	
		var strUsername = this.getUserName();
		
		//不能输入特殊字符，用户名只能由不区分大小写的字母、数字、点、减号、下划线组成
		strUsername=Trim(strUsername);
		var filter = /^[@0-9a-zA-Z_\.\-\s]+$/;
        if (false==filter.test(strUsername) || strUsername.indexOf(" ")>0){
			this.divNotice.innerHTML = "请输入正确的用户名";
			return false;
        }
        
		if (strUsername.length>0){		
			this.divNotice.innerHTML = this.noticeAccount;
		} else {
			this.divNotice.innerHTML = this.noticeInit;
		}	
		return true;
	},
	
	//不响应onfocus事件，只做从cookie获得密码
	checkPasswordFocus: function(){
		var strPassword = this.objPassword.value;
		if(strPassword==""){
			strPassword = ckLoginInfo.pass;
			if(null != strPassword){
				this.pwdFromCk = strPassword;
				this.pwdFromCkTrim = strPassword;//.substring(0,11);			
				this.isPwdFromCk = true;
				this.objPassword.value = strPassword;//.substring(0,11);
			}
		}
		this.checkPassword();
	},
	
	//响应密码输入框的onfocus事件
	fnPassOnFocus: function(){
		this.objPassword.select();
		this.checkPassword();
	},
	
	checkPassword: function(){
		var strPassword = this.objPassword.value;
		if(null==strPassword || strPassword==""){
			this.isPwdFromCk = false;
		}
		
		var rePassword = /^[\s]*$/g;
			if (strPassword.match(rePassword) != null){
				this.divNotice.innerHTML = this.noticePassword;
				//this.objPassword.style.backgroundColor = "#fff";
				return false;
			} else {
				this.divNotice.innerHTML = this.noticeInit;
				//this.objPassword.style.backgroundColor = "#fff";
				return true;
			}
	},
	
	dologin: function(){
		if(this.checkUsername() && this.checkPassword()) { //顺利登录
			this.divNotice.innerHTML = "正在登录，请稍候...";
			this.objUsername.disabled=true;
			this.objPassword.disabled=true;
			
			if(document.all){
				this.objUsername.detachEvent("onblur", this.checkUsername);
				this.objPassword.detachEvent("onfocus", this.checkPassword);
				this.objPassword.detachEvent("onblur", this.checkPassword);
		
				$("frmLogin").detachEvent("onkeypress", this.frmDologinIE);	
				$("qLoginButt").detachEvent("onclick", this.dologin);
				this.objSetCkCheck.detachEvent("onclick", this.changeCookieCheck);				
			}else {
				this.objUsername.removeEventListener("blur", this.checkUsername, true);
				this.objPassword.removeEventListener("focus", this.checkPassword, true);
				this.objPassword.removeEventListener("blur", this.checkPassword, true);
			}
			
			var strPassword = this.objPassword.value;
			var strPwdOld;
			if(!this.isPwdFromCk || strPassword != this.pwdFromCkTrim){
				if(this.getCurUserType()==typeVip)
					strPassword = this.pwd_js_string(strPassword);
				if(this.getCurUserType()==type163  || this.getCurUserType()==typeVip){
					strPassword = strPassword.substring(0,16);
				}else if(this.getCurUserType()==typePopo){
					strPassword = strPassword.substring(0,21);
				}			
				strPwdOld = strPassword;
				strPassword = this.convertToMd5(strPassword);		
			}else{
				//get from cookie
				strPassword = this.pwdFromCk;
				strPwdOld = strPassword;
			}
			
			var strUsername = Trim(this.objUsername.value.toLowerCase());	
			strUsername=neteaselogin_getBlogusername(strUsername);
			var strUsernameOld = strUsername;
			
			
			if(this.getCurUserType() == type126 || this.getCurUserType() == type188 || this.getCurUserType() == typeYeah){				
				strPassword = strPwdOld;//.replace(/#/g,"%23");			
			}
			
			if(this.objSetCkCheck.checked){
				//username
				clearLoginCookie();
				
				setLoginCookie(1, strUsernameOld);
				setLoginCookie(2, strPassword);
			}else{
				clearLoginCookie();
			}			
			var bSavePass = this.objSetCkCheck.checked;
			//save cookie for login type
			setLoginCookie(0, this.getCurUserType());
			
			this.strUsername = strUsername;
			this.strPassword = strPassword;
			if(this.bFromIndex || this.presentShowId=="qIndexLoginDiv"){
				loginFromIndex(strUsername, strPassword,bSavePass);
			}else{
				UserBean.checkPassportVN (strUsername, strPassword,bSavePass,this.getCurUserType(),this.preloginCb.bind(this));	
			}		
		}
		return false;
	},
	
	convertToMd5:function(strPassword){
	    if(escape(strPassword).indexOf("%u")<0){
           return hex_md5(strPassword);	
        }else{
        	//包含中文字符
        	DWREngine.setAsync(false);   
        	UserBean.getUrsMd5(strPassword,function(md5){
							this.md5Result= md5;
						}.bind(this));
        	DWREngine.setAsync(true);  
        	return this.md5Result;
        }
	},
	
	preloginCb: function(b){
		if(b==null){
			this.objPassword.value = "";
			this.objUsername.disabled=false;
			this.objPassword.disabled=false;
			this.divNotice.innerHTML = "<span class='clr03'>用户名或密码不正确，请重新输入。</span>";
			$("in_username").focus();
			return;
		}
		if (this.getCurUserType()==typePlayer) {
					this.strUsername = b;
					this.dologinCb("not reg!!");
					return;
		}
		this.dologinCb(b);
	},
	calTarget: function() {
				//modified by xcc, 用户可以指定loginTarget
				if (this.loginTarget==null){
					if ( $("$_oppoPageUrlForLogin")&&(UD.hostName == this.strUsername) ){
					  if (UD.hostPath =="") //如果是个性化域名
					     this.loginTarget = "http://"+DomainMap.getParentDomain(this.strUsername)+$("$_oppoPageUrlForLogin").value;					 
					  else 
					     this.loginTarget = $("$_oppoPageUrlForLogin").value;
					}
					else
						this.loginTarget=window.location;
				} 			
	},
	getCurUserType:function(){
		var  strUsername=this.objUsername.value;
		for(var i =0;i<neteasebloglogin_posts.length;i++){
			if (strUsername.endsWith(neteasebloglogin_posts[i]))
				return neteasebloglogin_types[i];
		}
		return -1;
	},
	getUserName:function(){
		var strUsername = this.objUsername.value;
		return neteaselogin_getBlogusername(strUsername);		
	},
	getFullUserName:function(userName){		
		for(var i =0;i<neteasebloglogin_blogsuffixs.length;i++){
			if (neteasebloglogin_blogsuffixs[i]!="" && userName.endsWith(neteasebloglogin_blogsuffixs[i]))
				return userName.replace(neteasebloglogin_blogsuffixs[i],neteasebloglogin_posts[i]);
		}
		return userName+"@163.com";
	},
	
	getEntryByType:function (type){
	  if(type == type188)  
	     return "188";
	  else if(type == typePlayer)
	     return "game";
	  
	   return "urs";
    },

	dologinCb: function(b){
		if(b!=null){
			this.calTarget();
			if (b=="not reg!!") {
				var entry = this.getEntryByType(this.getCurUserType());
				
				if(this.options.invitor != null && this.options.group != null){
					var url = "http://blog.163.com/passportIn.do?in_username="+this.strUsername+"&in_password="+encodeURIComponent(this.strPassword) +
						"&invitor=" + this.options.invitor + "&group=" + this.options.group;
					if(this.options.app != null && this.options.app>0)
						url += "&app=" + this.options.app;
					location.href= url + "&internal=true&type="+this.getCurUserType() + "&entry="+entry+"&target="+encodeURIComponent(this.loginTarget);
				}else{
					location.href="http://blog.163.com/passportIn.do?in_username="+this.strUsername+"&in_password="+encodeURIComponent(this.strPassword) + "&entry="+entry+"&target="+encodeURIComponent(this.loginTarget)+"&internal=true&type="+this.getCurUserType();;
				}
			} else {
				var loginFullUsername = NetEase.QuickLogin.prototype.getFullUserName(this.strUsername);
				Cookie.set("NETEASE_LOGIN_USERNAME",loginFullUsername,30,"/","blog.163.com");
				Cookie.set("NETEASE_AUTH_USERNAME",this.strUsername,0,"/",".163.com");
				location.href =  "http://blog.163.com/loginGate.do?username="+this.strUsername+"&target="+encodeURIComponent(this.loginTarget);
				
			}
		}else{
			//this.objUsername.value = "";
			this.objPassword.value = "";
			this.objUsername.disabled=false;
			this.objPassword.disabled=false;
			this.divNotice.innerHTML = "<span class='clr03'>用户名或密码不正确，请重新输入。</span>";
			$("in_username").focus();
		}
		
		return false;
	},
	
	pwd_js_string: function(s){
		return String(s).replace(/\\/g, "\\\\").replace(/'/g, "\\\'").replace(/"/g, "\\\"");
	},
	selectUserType: function(){					
		//填充用户名和密码
		this.objUsername.value ="";
		this.objPassword.value ="";
		var userNameInit = ckLoginInfo.name;		
		if(userNameInit){
			this.objUsername.value = this.getFullUserName(userNameInit);
			this.checkPasswordFocus();
			this.objSetCkCheck.checked = true;
			this.noticeAccount = "请点击登录按钮";
			this.noticeInit = "请点击登录按钮";
		}else{
			this.objSetCkCheck.checked = false;		
		}		
		
		//处理出错信息
		var urlStr = window.location.href;
		var i = urlStr.indexOf("err=");
		if(i != -1){
			var errStr = urlStr.charAt(i+4);
			if(errStr=="1" || errStr=="2" || errStr=="3"|| errStr=="4"){
				var n = parseInt(errStr);
				if (n>3)n=1;
				this.noticeInit = this.noticeAccount = "<span class='cr'>"+errInfo[n-1]+"</span>";
			}
		}
		this.checkUsername();	
		if ($("in_username")) try{Field.activate("in_username");}catch(e){};		
		return false;
	}
	
}

function neteaselogin_getBlogusername(username){
	return  username.replace("@163.com","").replace("@126.com","@126").replace("@yeah.net","@yeah").replace("@popo.163.com",".popo").replace("@188.com","@188").replace("@vip.163.com",".vip").replace("@game.163.com","");
}


//从cookie得到登录类型、用户名、密码
function getLoginCookie(){
	var a;
	var v = Cookie.get(ckLoginInfoKey);
	if(v){
		a = v.split("|");
		try{
			if (a.length>3){
				Cookie.clear(ckLoginInfoKey, ckPath);
				return ;
			}
		}catch(e){}
		var type = null;
		if(a[0])
			ckLoginInfo.type = parseInt(a[0]);
		if(ckLoginInfo.type == null || ckLoginInfo.type == undefined || ckLoginInfo.type<0 || ckLoginInfo.type>5){
			ckLoginInfo.type = null;
			//类型取不到，用户名和密码为空
			return;
		}
		
		if(a[1] != null && a[1] != undefined && a[1] != "null" && a[2] != null && a[2] != undefined){
			ckLoginInfo.name = a[1]; 
			//取密码，从第二个|开始			
			ckLoginInfo.pass = a[2];
		}
	}
}

//设置cookie登录类型(which=0)、用户名(which=1)、密码(which=2)
function setLoginCookie(which, value){
	getLoginCookie();
	if(which==0)
		ckLoginInfo.type = value;
	else if(which==1)
		ckLoginInfo.name = value;
	else if(which==2)
		ckLoginInfo.pass = value;
		
	Cookie.clear(ckLoginInfoKey, ckPath);
	//cookie value将以ascii编码传输，类似url encoding,服务器端需要decode
	Cookie.set(ckLoginInfoKey, ckLoginInfo.type + "|" + ckLoginInfo.name + "|" + ckLoginInfo.pass, 30, ckPath, ckDomain);			
}

//清除ckLoginInfoKey的cookie，同时也清除ckLoginInfo的name和pass，但保留type
function clearLoginCookie(){
	ckLoginInfo.name = null;
	ckLoginInfo.pass = null;
	Cookie.clear(ckLoginInfoKey, ckPath);	
	if(ckLoginInfo.type != null && ckLoginInfo.type != undefined && ckLoginInfo.type != "null")
		Cookie.set(ckLoginInfoKey, ckLoginInfo.type, 30, ckPath, ckDomain);			
}

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)) {
			return false;
		}
	},

	clear : function(name, path) {
		this.set(name, "", -1, path, ckDomain);
	},
	
	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;
		}
	}
}   

//快速登录
var quicklogin_jst = new String('\
<div>\
   <form name="frmLogin"  id="frmLogin"  onsubmit="return false;"  method="post">\
			<table border="0" cellpadding="0" cellspacing="0">\
				<tr class="row0"><td width="40">&nbsp;</td><td><div class="mgntxt clr02" id="notice_bar" style="display-left:0px;">请输入网易通行证用户名和密码登录</div></td></tr>\
				<tr><td class="fcb">用户名</td><td><div id="div_in_username"></div></td></tr>\
				<tr><td class="fcb">密　码</td><td><input type="password" tabindex="2" class="txt" name="in_password" id="in_password"/></td></tr>\
				<tr><td>&nbsp;</td><td><a href="http://reg.163.com/RecoverPasswd1.shtml" tabindex="4" target="_blank" id="getPass_add" class="a-pwd">忘记密码？</a><input name="setCookieCheck" tabindex="3" id="setCookieCheck" type="checkbox"/><label for="setCookieCheck">自动登录</label></td></tr>\
				<tr><td>&nbsp;</td><td><div class="btns"><a href="${regUrl}" tabindex="6" target="_blank" class="a-reg">注册通行证 --></a><input class="ok" tabindex="5" type="button" value="登　录" id="qLoginButt"/></div></td></tr>\
			</table>\
   </form>\
</div>');
var neteasebloglogin_blogsuffixs = ['','@126','.popo','@188','.vip','@yeah','@game'];
var neteasebloglogin_posts = ['@163.com','@126.com','@popo.163.com','@188.com','@vip.163.com','@yeah.net','@game.163.com'];
var neteasebloglogin_types=[type163,type126,typePopo,type188,typeVip,typeYeah,typePlayer];

function	getNameSuffix(type){
		for(var i =0;i<neteasebloglogin_types.length;i++){
			if (type==neteasebloglogin_types[i])
				return neteasebloglogin_blogsuffixs[i];
		}
		return -1;
};
function neteasebloglogin_getList(value,cb){
		if(value==undefined||value==''||!cb) return;
		var arr = /([^@]*)(.*)/.exec(value),list=[];
		var pre = arr[1],post = arr[2];
		neteasebloglogin_posts.each(function(pt){
			if(pt.indexOf(post)!=-1){
				list.push(pre+pt);
			}
		});
		var loginUsername = Cookie.get("NETEASE_LOGIN_USERNAME");
		if(loginUsername && loginUsername.match("^"+value)==value){
			var length = list.length;
			if(length > 0 && loginUsername != list[0])
				list.unshift(loginUsername);
		}
		cb(list);
}

String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}
function PlayerBean() { }
PlayerBean.getPlayerUserName = function(p0, p1, callback) {dwr.engine._execute('/dwr', 'PlayerBean', 'getPlayerUserName', p0, p1, callback);}
function UserBean() { }
UserBean._path="/dwr";
UserBean.clearSession = function(callback) {dwr.engine._execute(UserBean._path, 'UserBean', 'clearSession', false, false, callback);}
UserBean.check = function(p0, p1, callback) {dwr.engine._execute(UserBean._path, 'UserBean', 'check', p0, p1, false, false, false, callback);}
UserBean.checkPassport = function(p0, p1, p2, callback) {dwr.engine._execute(UserBean._path, 'UserBean', 'checkPassport', p0, p1, p2, false, false, false, callback);}
UserBean.checkPassportVN = function(p0, p1, p2, p3, callback) {dwr.engine._execute(UserBean._path, 'UserBean', 'checkPassportVN', p0, p1, p2, p3, false, false, false, callback);}
UserBean.getProvinceAndCity = function(callback) {	dwr.engine._execute(UserBean._path, 'UserBean', 'getProvinceAndCity', false, false, callback);}  	          

/**************************************************************
*				163 blog context input  				   	  *
*                                                             *
* Written by:  魏文庆                                       *
* Important: to use this script don't                         *
*            remove these comments                            *
* Version 2.0 (MSIE 6.0 above,Firefox1.0,Netscape.)           *
* Created Date: 2009-2-13									  *
* Copyright：1999-2009 NetEase.com Inc. All rights reserved.  *
**************************************************************/

/** 
 * @fileoverview 
 * 具有上下文提示的输入框
 * 
 * @author  	moonface@(wqwei@corp.netease.com)
 * @version 	1.0 
 * @requires  	prototype.js
 * @see		    
 */
if(NECtrl == undefined){
	var NECtrl = {};
}

/**
 * 具有上下文提示的输入框对象
 * @constructor
 * @class   具有上下文提示的输入框对象
 * @param  {String|Node} oParent  控件所在的父节点ID或者对象
 * @param  {Object}      oOptions 可选配置参数，已处理的参数列表
 * 								  inputId   [String]   - 输入框id
 * 								  className [String]   - 控件关联样式
 *                                onchange  [Function] - 输入框内容发生改变时的回调函数
 *                                onsuccess [Function] - 选中用户名的回调函数
 * 
 */	
NECtrl.CxtInput = Class.create();

/**
 * 控件初始化函数
 * @param {String|Node} oParent		父节点id或者对象
 * @param {Object} 		oOptions	可选配置参数
 */
NECtrl.CxtInput.prototype.initialize = function(oParent,oOptions){
	oParent = $(oParent);
	if(!oParent) return;
	oOptions = oOptions || {};
	this.body = document.createElement('div');
	this.body.className = oOptions.className || '';
	this.cbChange = oOptions.onchange || Prototype.emptyFunction;
	this.cbSuccess = oOptions.onsuccess;
	var	str = '<input type="text" autocomplete="off" class="txt"';
	if (oOptions.inputId)  str += ' id="'+oOptions.inputId+'"'+' name="'+oOptions.inputId+'"';
	str += '/><div class="' +  oOptions.className + '-cxt" style="display:none;"></div>';
	this.body.innerHTML = str;
	this.input = this.body.getElementsByTagName('input')[0];
	this.context = this.body.getElementsByTagName('div')[0];
	Event.observe(this.input,'input',this.onChange.bind(this));
	Event.observe(this.input,'propertychange',this.onChange.bind(this));
	Event.observe(this.input,'keypress',this.onKeyPress.bindAsEventListener(this));
	Event.observe(document,'click',this.onClick.bind(this));
	Event.observe(this.input,'click',function(){Event.stop(window.event||arguments[0]);});
	oParent.appendChild(this.body);
};
/**
 * 输入框输入的消息响应函数
 */
NECtrl.CxtInput.prototype.onChange = function(){
	if(this.input.value == ''){
		this.context.style.display = 'none';
		return;
	}
	this.cbChange(this.input.value,this.onListChange.bind(this));
};
/**
 * 上下文列表变化的回调函数
 * @param {Array} list	上下文列表
 */
NECtrl.CxtInput.prototype.onListChange = function(list){
	if(!list||!list.length) return;
	this.resetList(list);
	this.context.style.display = '';
};
/**
 * 在输入框中输入的消息响应函数
 * @param {Object} event	事件对象
 * 
 */
NECtrl.CxtInput.prototype.onKeyPress = function(event){
	switch(event.keyCode){
		case 9 :
		case 13:
			this.select(this.context.curIndex);
			Event.stop(event);
		break;
		case 38:
			if(this.context.curIndex > 0){
				Element.removeClassName(this.context.getElementsByTagName('div')[this.context.curIndex+1],'cur');
				this.context.curIndex--;
				Element.addClassName(this.context.getElementsByTagName('div')[this.context.curIndex+1],'cur');
			}
		break;
		case 40:
			if(this.context.curIndex < this.list.length - 1){
				Element.removeClassName(this.context.getElementsByTagName('div')[this.context.curIndex+1],'cur');
				this.context.curIndex++;
				Element.addClassName(this.context.getElementsByTagName('div')[this.context.curIndex+1],'cur');
			}
		break;
	}
};
/**
 * 设置上下文列表
 * @param {Array}	list	上下文列表
 */
NECtrl.CxtInput.prototype.resetList = function(list){
	if(!list||!list.length) list = [];
	this.list = list;
	for(var i=0,cs=this.context.childNodes,len=cs.length;i<len;i++)
		this.context.removeChild(this.context.firstChild);
	var frag = document.createDocumentFragment(),tpl=document.createElement('div'),div;
	div = tpl.cloneNode(false);
	div.className = 'hint';
	div.innerText = div.textContent = '请选择用户';
	div.onclick = this.select.bind(this,this.context.curIndex);
	frag.appendChild(div);
	for(var i=0,l=list.length,self = this;i<l;i++){
		div = tpl.cloneNode(false);
		div.innerText = div.textContent = list[i];
		if(i == 0){
			Element.addClassName(div,'cur');
			this.context.curIndex = i;
		}
		div.onmouseover = this.onMouseOver.bind(this,i);
		frag.appendChild(div);
	}
	this.__count = 0;
	this.context.appendChild(frag);
};
/**
 * 鼠标over上下文中的一项的消息响应函数
 */
NECtrl.CxtInput.prototype.onMouseOver = function(index){
	if(!this.__count++) return;
	Element.removeClassName(this.context.getElementsByTagName('div')[this.context.curIndex+1], 'cur');
	this.context.curIndex = index;
	Element.addClassName(this.context.getElementsByTagName('div')[this.context.curIndex+1], 'cur');
};
/**
 * 鼠标点击的消息响应函数
 */
NECtrl.CxtInput.prototype.onClick = function(){
	if(this.context.curIndex != undefined&&this.context.style.display != 'none') this.select(this.context.curIndex);
};
/**
 * 选中上下文列表中的一项
 * @param {Number} index	索引值
 */
NECtrl.CxtInput.prototype.select = function(index){
	if(index == undefined||this.context.style.display == 'none') return;
	this.input.value = this.list[index];
	this.context.style.display = 'none';
	this.cbSuccess&&this.cbSuccess();
};

/** predefined variables
movie_name	swf文件名，包括完整路径和.swf
target_div_id	目标div的id
majorv	主版本号
minorv	副版本号
rev	修订号
*/

function getContent(params) {
	var movie_name = params["movie_name"];
	var movie_id = params["movie_id"];
	var majorv = params["majorv"].valueOf();
	var minorv = params["minorv"].valueOf();
	var rev = params["rev"].valueOf();
	
	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
	var hasProductInstall = DetectFlashVer(6, 0, 65);
	
	// Version check based upon the values defined in globals
	var hasRequestedVersion = DetectFlashVer(majorv, minorv, rev);
	
	// for debug
	//hasProductInstall = true;
	//hasRequestedVersion = false;
	
	var content = "";
	
	if(hasRequestedVersion) {
		content = "<embed wmode=\"transparent\" src=\"" + movie_name + "\" ";
		if(movie_id != undefined)
			content += "id=\"" + movie_id + "\" ";
		content += "quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"100%\"></embed>";
	} else {
	
		content = "Flash播放器版本太低，请您<br>" +
			"<a href=\"http://www.macromedia.com/go/getflashplayer\" target=_blank>点击这里从adobe主页更新Flash播放器</a><br>";			
	
		if(hasProductInstall) {
			content += "或者<br>" +
				"<a href=\"\" target=_blank>点击这里尝试自动更新</a>";	
		}
	}
	return content;
}

function getParams(typeid) {
	var params = initParas[typeid][0];
	// for debug
	/* var paramtext = "";
	for(var key in params) {
		paramtext += key + " = " + params[key] + "\n";
	}
	alert(paramtext); */
	return params;
}

function writeDiv(typeid) {
	var params = getParams(typeid);
	$(params["target_div_id"]).innerHTML = getContent(params);
}

/**************************************************************
*				163 blog JS Common Control					  *
*                                                             *
* Written by:  zhujingbo                                      *
* Important: to use this script don't                         *
*            remove these comments                            *
* Version 1.0 (MSIE 6.0 above,Firefox1.0,Netscape.)           *
* Created Date: 2006-11-17									  *
* Copyright：1997-2006 NetEase.com Inc. All rights reserved.  *
**************************************************************/
/** 
 * @fileoverview 
 *  用于Selenium测试时对，各页面需要增加dom加载信息来提供给测试程序使用
 *  该文件提供统一的调用接口来处理页面上对dom加载信息的填充。
 *
 * @author  zhujingbo (zhujingbo@corp.netease.com)
 * @version 1.0 
 * @requires 
 */
 
// 注册名字空间 
//gNameSpace.register('NECtrl.SeleniumTester');

/**
 * SeleniumTester class
 * @class	管理用于帮助Selenium测试的dom加载信息控制。
 */
NECtrl.SeleniumTester = Class.create();
NECtrl.SeleniumTester.prototype	= {
	/**
	 * SeleniumTester对象构造函数
	 * 
	 */
	initialize	:	function(){
		this._sPrefix = "suf";
		this._oHash = [];
	},
		
	/**
	 * 设置一个单值到对应类别
	 * 形式为<div>xxx</div>
	 * @param	{String}	sElement	元素类别
	 * @param	{String}	sValue		元素对应的值，为单值
	 * @return	{Void}
	 */
	setSingle	:	function(sElement, sValue) {
		this._oHash[this._sPrefix + sElement] = sValue;
		$(this._sPrefix + sElement).innerHTML = sValue;
	}, 
	
	/**
	 * 设置一个一维数组型的值到对应列表
	 * 形式为<div>xxx,xxx,xxx</div>
	 * @param	{String}	sElement	元素类别
	 * @param	{Array}		aValue		元素对应的值，为一维数组
	 * @return	{Void}
	 */
	setArray	: 	function(sElement, aValue) {
		this._oHash[this._sPrefix + sElement] = aValue;
		if (aValue != "null")
			$(this._sPrefix + sElement).innerHTML = aValue.toString();
		else
			$(this._sPrefix + sElement).innerHTML = "null";
	},
	
	/**
	 * 设置一个二维数组型的值到对应列表
	 * 形式为<div>[xxx],[xxx,xxx,xxx],[]</div>
	 * @param	{String}	sElement	元素类别
	 * @param	{Array}		aValue		元素对应的值，为二维数组
	 * @param	{String}	sRelElem	相关父元素的类别
	 * @param	{String}	sRelValue	相关父元素的值
	 * @return	{Void}
	 */
	set2DArray	:	function(sElement, aValue, sRelElem, sRelValue) {
		if (!this._oHash[this._sPrefix + sElement]) { 
			var _oElem = this._oHash[this._sPrefix + sElement] = [];
			var _oRelElem = this._oHash[this._sPrefix + sRelElem];
			for (var i = 0, l = this._oHash[this._sPrefix + sRelElem].length; i < l; i++) {
				_oElem[_oRelElem[i]] = [];
			}
		}
		this._oHash[this._sPrefix + sElement][sRelValue] = aValue;
		if (aValue != "null")
			$(this._sPrefix + sElement).innerHTML = this._get2DString(this._oHash[this._sPrefix + sElement]);
		else
			$(this._sPrefix + sElement).innerHTML = "null";
	},
	
	/**
	 * 获取二维数组的字符串表达形式，用于设置到dom对象上去
	 * @private
	 * @param	{Array}		oElement	二维数组
	 * @return	{String}
	 */
	_get2DString	:	function(oElement) {
		var s = "";
		var _oElem = $H(oElement);
		var _aElemValues = _oElem.values();
		for (var i = 0, l = _aElemValues.length; i < l; i++) {
			s += "[" + _aElemValues[i].toString() + "]";
		}
		return s;
	}

};

/**************************************************************
*				163 blog JS Util							  *
*                                                             *
* Written by:  wangchen                                       *
* Important: to use this script don't                         *
*            remove these comments                            *
* Version 1.0 (MSIE 6.0 above,Firefox1.0,Netscape.)           *
* Created Date: 2006-10-12									  *
* Copyright：1997-2006 NetEase.com Inc. All rights reserved.  *
**************************************************************/

/** 
 * @fileoverview 
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 *
 * GUID	:	{F6707A8B-BD1E-413e-AE9F-04A9B6A9506C}
 * 
 * @author  wangchen (wangchen@corp.netease.com)
 * @version 1.0 
 * @requires  netease/Util/NameSpace.js
 * @requires  netease/Util/NEBase.js
 */
 
// 注册名字空间 
gNameSpace.register('NEUtil');

/********************MD5 Class Implement**********************/
/**
 * Static Class MD5 
 * 将MD5对象做为静态类使用 使用其提供的接口做为静态方法
 * hex		:		function(sValue)			产生Hex格式的MD5串
 * b64		:		function(sValue)			产生B64格式的MD5串
 * str		:		function(sValue)			产生普通字串格式的MD5串
 */
NEUtil.MD5 = {
	/**
	 * 产生Hex格式的MD5串
	 * @param 	{string} 	sValue 	需要编码字串
	 * @return	{string}	Hex格式的MD5串
	 */
	hex	:	function(sValue){
		return this._fnBin2Hex(this._fnCore(this._fnStr2Bin(sValue)), sValue.length * this._nChrsz);
	},
	
	/**
	 * 产生普通字串格式的MD5串
	 * @param 	{string} 	sValue 	需要编码字串
	 * @return	{string}	普通字串格式的MD5串
	 */
	str	:	function(sValue){
		return this._fnStr2B64(this._fnCore(this._fnStr2Bin(sValue)), sValue.length * this._nChrsz);
	},
	
	/**
	 * Convert an array of little-endian words to a hex string.
	 * @private
	 * @param	{array}		aBinArray	an array of little-endian words
	 * @return	{string}	hex string.
	 */
	_fnBin2Hex	:	function(aBinArray){
		var	_sHexTab = this._sHexTab;
		var _sStr = "";
		for (var i=0, l=aBinArray.length*4; i<l; i++){
			_sStr += _sHexTab.charAt((aBinArray[i>>2] >> ((i%4)*8+4)) & 0xF);
			_sStr += _sHexTab.charAt((aBinArray[i>>2] >> ((i%4)*8  )) & 0xF);
		}
		return _sStr;
	},
	
	/**
	 * Convert a string to an array of little-endian words
	 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
	 * @private
	 * @param	{string}	sStr	a string
	 * @return	{array}		an array of little-endian words
	 */
	_fnStr2Bin	:	function(sStr){
	  var _aBin = [];
	  var _nMask = (1 << this._nChrsz) - 1;
	  for(var i = 0, l=sStr.length*this._nChrsz; i < l; i += this._nChrsz)
	    _aBin[i>>5] |= (sStr.charCodeAt(i / this._nChrsz) & _nMask) << (i%32);
	  return _aBin;
	},
	
	/**
	 * basic operations the algorithm uses.
	 * @private
	 */
	_fnCmm	:	function(q, a, b, x, s, t){
		return this._fnAdd(this._fnBr(this._fnAdd(this._fnAdd(a, q), this._fnAdd(x, t)), s),b);
	},
	
	/**
	 * basic operations the algorithm uses.
	 * @private
	 */
	_fnFf	:	function(a, b, c, d, x, s, t){
	  	return this._fnCmm((b & c) | ((~b) & d), a, b, x, s, t);
	},
	
	/**
	 * basic operations the algorithm uses.
	 * @private
	 */
	_fnGg	:	function(a, b, c, d, x, s, t){
	 	return this._fnCmm((b & d) | (c & (~d)), a, b, x, s, t);
	},
	
	/**
	 * basic operations the algorithm uses.
	 * @private
	 */
	_fnHh	:	function(a, b, c, d, x, s, t){
	  	return this._fnCmm(b ^ c ^ d, a, b, x, s, t);
	},
	
	/**
	 * basic operations the algorithm uses.
	 * @private
	 */
	_fnIi	:	function(a, b, c, d, x, s, t){
	  	return this._fnCmm(c ^ (b | (~d)), a, b, x, s, t);
	},
	
	/**
	 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
	 * to work around bugs in some JS interpreters.
	 * @private
	 * @param	{integer}	nX
	 * @param	{integer}	nY
	 * @return	{integer}
	 */
	_fnAdd	:	function(nX, nY){
		var _nLsw = (nX & 0xFFFF) + (nY & 0xFFFF);
	  	var _nMsw = (nX >> 16) + (nY >> 16) + (_nLsw >> 16);
		return (_nMsw << 16) | (_nLsw & 0xFFFF);
	},
	
	/**
	 * Bitwise rotate a 32-bit number to the left.
	 * @private
	 * @param	{integer}	nNum	32-bit number
	 * @param	{integer}	nCount	count of bits to rotate left
	 * 								(count <= 32)
	 * @return	{integer}	new 32-bit number
	 */
	_fnBr	:	function(nNum, nCount){
		return (nNum << nCount) | (nNum >>> (32 - nCount));
	},
	
	/**
	 * Calculate the MD5 of an array of little-endian words, and a bit length
	 * @private
	 * @param	{array}		sX		an array of little-endian words
	 * @param	{integer}	nLen	a bit length
	 * @return	{array}		MD5 array
	 */
	_fnCore	:	function(sX, nLen){
		sX[nLen >> 5] |= 0x80 << ((nLen) % 32);
	  	sX[(((nLen + 64) >>> 9) << 4) + 14] = nLen;
	
	 	var _a =  1732584193;
		var _b = -271733879;
		var _c = -1732584194;
	  	var _d =  271733878;
	
	  	for(var i = 0, l=sX.length; i<l; i += 16){
	    	var _olda = _a;
	    	var _oldb = _b;
	    	var _oldc = _c;
	    	var _oldd = _d;
	
			// 第一轮计算
	    	_a = this._fnFf(_a, _b, _c, _d, sX[i+ 0], 7 , -680876936);
	    	_d = this._fnFf(_d, _a, _b, _c, sX[i+ 1], 12, -389564586);
	    	_c = this._fnFf(_c, _d, _a, _b, sX[i+ 2], 17,  606105819);
	    	_b = this._fnFf(_b, _c, _d, _a, sX[i+ 3], 22, -1044525330);
	    	_a = this._fnFf(_a, _b, _c, _d, sX[i+ 4], 7 , -176418897);
	    	_d = this._fnFf(_d, _a, _b, _c, sX[i+ 5], 12,  1200080426);
	    	_c = this._fnFf(_c, _d, _a, _b, sX[i+ 6], 17, -1473231341);
	    	_b = this._fnFf(_b, _c, _d, _a, sX[i+ 7], 22, -45705983);
	    	_a = this._fnFf(_a, _b, _c, _d, sX[i+ 8], 7 ,  1770035416);
	    	_d = this._fnFf(_d, _a, _b, _c, sX[i+ 9], 12, -1958414417);
	    	_c = this._fnFf(_c, _d, _a, _b, sX[i+10], 17, -42063);
	    	_b = this._fnFf(_b, _c, _d, _a, sX[i+11], 22, -1990404162);
	    	_a = this._fnFf(_a, _b, _c, _d, sX[i+12], 7 ,  1804603682);
	    	_d = this._fnFf(_d, _a, _b, _c, sX[i+13], 12, -40341101);
	    	_c = this._fnFf(_c, _d, _a, _b, sX[i+14], 17, -1502002290);
	    	_b = this._fnFf(_b, _c, _d, _a, sX[i+15], 22,  1236535329);
	
			// 第二轮计算
	    	_a = this._fnGg(_a, _b, _c, _d, sX[i+ 1], 5 , -165796510);
	    	_d = this._fnGg(_d, _a, _b, _c, sX[i+ 6], 9 , -1069501632);
	    	_c = this._fnGg(_c, _d, _a, _b, sX[i+11], 14,  643717713);
	    	_b = this._fnGg(_b, _c, _d, _a, sX[i+ 0], 20, -373897302);
	    	_a = this._fnGg(_a, _b, _c, _d, sX[i+ 5], 5 , -701558691);
	    	_d = this._fnGg(_d, _a, _b, _c, sX[i+10], 9 ,  38016083);
	    	_c = this._fnGg(_c, _d, _a, _b, sX[i+15], 14, -660478335);
	    	_b = this._fnGg(_b, _c, _d, _a, sX[i+ 4], 20, -405537848);
	    	_a = this._fnGg(_a, _b, _c, _d, sX[i+ 9], 5 ,  568446438);
	    	_d = this._fnGg(_d, _a, _b, _c, sX[i+14], 9 , -1019803690);
		    _c = this._fnGg(_c, _d, _a, _b, sX[i+ 3], 14, -187363961);
	    	_b = this._fnGg(_b, _c, _d, _a, sX[i+ 8], 20,  1163531501);
	    	_a = this._fnGg(_a, _b, _c, _d, sX[i+13], 5 , -1444681467);
	    	_d = this._fnGg(_d, _a, _b, _c, sX[i+ 2], 9 , -51403784);
	    	_c = this._fnGg(_c, _d, _a, _b, sX[i+ 7], 14,  1735328473);
		    _b = this._fnGg(_b, _c, _d, _a, sX[i+12], 20, -1926607734);
	
			// 第三轮计算
		    _a = this._fnHh(_a, _b, _c, _d, sX[i+ 5], 4 , -378558);
	    	_d = this._fnHh(_d, _a, _b, _c, sX[i+ 8], 11, -2022574463);
		    _c = this._fnHh(_c, _d, _a, _b, sX[i+11], 16,  1839030562);
	    	_b = this._fnHh(_b, _c, _d, _a, sX[i+14], 23, -35309556);
		    _a = this._fnHh(_a, _b, _c, _d, sX[i+ 1], 4 , -1530992060);
		    _d = this._fnHh(_d, _a, _b, _c, sX[i+ 4], 11,  1272893353);
		    _c = this._fnHh(_c, _d, _a, _b, sX[i+ 7], 16, -155497632);
		    _b = this._fnHh(_b, _c, _d, _a, sX[i+10], 23, -1094730640);
		    _a = this._fnHh(_a, _b, _c, _d, sX[i+13], 4 ,  681279174);
		    _d = this._fnHh(_d, _a, _b, _c, sX[i+ 0], 11, -358537222);
		    _c = this._fnHh(_c, _d, _a, _b, sX[i+ 3], 16, -722521979);
		    _b = this._fnHh(_b, _c, _d, _a, sX[i+ 6], 23,  76029189);
		    _a = this._fnHh(_a, _b, _c, _d, sX[i+ 9], 4 , -640364487);
		    _d = this._fnHh(_d, _a, _b, _c, sX[i+12], 11, -421815835);
		    _c = this._fnHh(_c, _d, _a, _b, sX[i+15], 16,  530742520);
		    _b = this._fnHh(_b, _c, _d, _a, sX[i+ 2], 23, -995338651);
		
			// 第四轮计算
			_a = this._fnIi(_a, _b, _c, _d, sX[i+ 0], 6 , -198630844);
		    _d = this._fnIi(_d, _a, _b, _c, sX[i+ 7], 10,  1126891415);
		    _c = this._fnIi(_c, _d, _a, _b, sX[i+14], 15, -1416354905);
		    _b = this._fnIi(_b, _c, _d, _a, sX[i+ 5], 21, -57434055);
		    _a = this._fnIi(_a, _b, _c, _d, sX[i+12], 6 ,  1700485571);
		    _d = this._fnIi(_d, _a, _b, _c, sX[i+ 3], 10, -1894986606);
		    _c = this._fnIi(_c, _d, _a, _b, sX[i+10], 15, -1051523);
	    	_b = this._fnIi(_b, _c, _d, _a, sX[i+ 1], 21, -2054922799);
		    _a = this._fnIi(_a, _b, _c, _d, sX[i+ 8], 6 ,  1873313359);
		    _d = this._fnIi(_d, _a, _b, _c, sX[i+15], 10, -30611744);
	    	_c = this._fnIi(_c, _d, _a, _b, sX[i+ 6], 15, -1560198380);
		    _b = this._fnIi(_b, _c, _d, _a, sX[i+13], 21,  1309151649);
		    _a = this._fnIi(_a, _b, _c, _d, sX[i+ 4], 6 , -145523070);
		    _d = this._fnIi(_d, _a, _b, _c, sX[i+11], 10, -1120210379);
		    _c = this._fnIi(_c, _d, _a, _b, sX[i+ 2], 15,  718787259);
		    _b = this._fnIi(_b, _c, _d, _a, sX[i+ 9], 21, -343485551);
	
	    	_a = this._fnAdd(_a, _olda);
	    	_b = this._fnAdd(_b, _oldb);
	    	_c = this._fnAdd(_c, _oldc);
	    	_d = this._fnAdd(_d, _oldd);
		}
	  	return Array(_a, _b, _c, _d);
	},
	
	/**
	 * hex output format. false - lowercase; true - uppercase
	 * @private
	 * @type	{boolean}
	 */
	_bHexcase	:	false,
	
	/**
	 * base-64 pad character. "=" for strict RFC compliance
	 * @private
	 * @type	{string}
	 */
	_sB64pad	:	'',
	
	/**
	 * bits per input character. 8 - ASCII; 16 - Unicode
	 * @private
	 * @type	{number}
	 */
	_nChrsz		:	8,
	
	/**
	 * Hex Table
	 * @private
	 * @type	{string}
	 */
	_sHexTab	:	this._bHexcase	?	'0123456789ABCDEF' : '0123456789abcdef',
	
	/**
	 * @private
	 * @type	{string}
	 */
	_sTab		:	'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
};

// 注册已经加载完成
gCodeLoad.regLoaded('{F6707A8B-BD1E-413e-AE9F-04A9B6A9506C}');


/**************************************************************
*				163 blog JS Util							  *
*                                                             *
* Written by:  wangchen                                       *
* Important: to use this script don't                         *
*            remove these comments                            *
* Version 1.0 (MSIE 6.0 above,Firefox1.0,Netscape.)           *
* Created Date: 2006-11-21									  *
* Copyright：1997-2006 NetEase.com Inc. All rights reserved.  *
**************************************************************/

/** 
 * @fileoverview 
 * 提供本地化文本串信息
 * 
 * @author  wangchen (wangchen@corp.netease.com)
 * @version 1.0 
 * @requires NameSpace.js
 */
 
gNameSpace.register('Local');
gNameSpace.register('Local.Message');
 
/**
 * 本地化文本串信息数组
 * 
 */
 
 
/**
 * blog相关提示信息文本串
 */
Local.Message.Blog = [	
	"你所发表的内容中包含非163.com域名的链接，发布不成功。"			// #0

];


if (NetEase==undefined){
	var NetEase={};
}

NetEase.StatusBar = Class.create();
NetEase.StatusBar.prototype = {
	initialize: function(msg){
		this.options = Object.extend({
			barId: "status_bar",
			fade: false,
			imgsrc: 'style/images/icon_confirm.gif',
			timeout: 5000
		}, arguments[1] || {});
		$(this.options.barId).style.display = 'block';
		$(this.options.barId).innerHTML = '<img src="'+this.options.imgsrc+'"/>&nbsp;' + msg;
		window.setTimeout(this._clean.bind(this), this.options.timeout);
	},
	
	_clean: function(){
		if (this.options.fade)
			Effect.Fade(this.options.barId);
		else {
			$(this.options.barId).innerHTML = '';
			$(this.options.barId).style.display = 'none';
		}
	}
}
 
function openFeedBackPage(){
	var url = 'http://feedback.163.com/fb/add/?productId=1';
	if(!!UD && ''!=UD.visitorName)
		url += '&user=' + UD.visitorName;
	window.open(url);
}

function newPlaceEdit(hostId) {
	var hostId = hostId;
	if (g_urlPrefix==null || g_urlPrefix!="/photos"){
		new NetEase.PlaceEdit('spacename', hostId, saveSpaceNameFunc, {
			editStyle: 'g_w_20 bd01 g_t_14 g_c_input',savaButStyle:'g_c_smvdn g_c_button bd01 butn c05',cancelButStyle:'g_c_smvdn g_c_button bd01 butn c05',
			emptyText:'<nobr class="g_t_italic">点击这里添加博客名称</nobr>', maxLength: 20, btnBelow: false, editIcon:'spacenameop', attchEventToParent: true, bExtendText: true, extendText: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'});
		new NetEase.PlaceEdit('spacedesc', hostId, saveSpaceDescFunc, {
			editStyle: 'g_w_20 bd01 g_t_14 g_c_input',savaButStyle:'g_c_smvdn g_c_button bd01 butn c05',cancelButStyle:'g_c_smvdn g_c_button bd01 butn c05',
			emptyText:'<nobr class="g_t_italic">点击这里添加博客描述</nobr>', maxLength: 40, btnBelow: false, editIcon:'spacedescop', attchEventToParent: true, bExtendText: true, extendText: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'});
	}
	else if (g_urlPrefix=="/photos"){
		new NetEase.PlaceEdit('spacename', hostId, saveSpaceNameFunc, {
			editStyle: 'g_w_20 bd01 g_t_14 g_c_input',savaButStyle:'g_c_smvdn g_c_button bd01 butn c05',cancelButStyle:'g_c_smvdn g_c_button bd01 butn c05',
			emptyText:'<nobr class="g_t_italic">点击这里添加相册名称</nobr>', maxLength: 20, btnBelow: false, editIcon:'spacenameop', attchEventToParent: true, bExtendText: true, extendText: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'});
		new NetEase.PlaceEdit('spacedesc', hostId, saveSpaceDescFunc, {
			editStyle: 'g_w_20 bd01 g_t_14 g_c_input',savaButStyle:'g_c_smvdn g_c_button bd01 butn c05',cancelButStyle:'g_c_smvdn g_c_button bd01 butn c05',
			emptyText:'<nobr class="g_t_italic">点击这里添加相册描述</nobr>', maxLength: 40, btnBelow: false, editIcon:'spacedescop', attchEventToParent: true, bExtendText: true, extendText: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'});
	}
}

function saveSpaceNameFunc(resourceId, spaceName, callBackFunc){
	UserBean.updateSpaceName(resourceId, spaceName, {
		  callback:callBackFunc,
		  errorHandler:function(errorString, ex) {
		  	callBackFunc(false);
		  	filterWarning(ex, false);;		  	
		  }
	});
}

function saveSpaceDescFunc(resourceId, spaceDesc, callBackFunc){
	UserBean.updateSpaceDesc(resourceId, spaceDesc, {
		  callback:callBackFunc,
		  errorHandler:function(errorString, ex) {
		  	callBackFunc(false);
		  	filterWarning(ex, false);;		  	
		  }
	});
}


var visitorGroupListsForHost = null;
var inviteHost_Template;
var g_quickLoginCon;
var showImgDiv;
var sysPredefinedGroup = [                
    {id:-10, groupName:"亲人", isys: true},
    {id:-11, groupName:"现在同事", isys: true},
    {id:-12, groupName:"以前同事", isys: true},
    {id:-13, groupName:"大学同学", isys: true},
    {id:-14, groupName:"高中同学", isys: true},
    {id:-15, groupName:"普通朋友", isys: false},
    {id:-16, groupName:"朋友的朋友", isys: false}
];
function getSelectOptionForFriend(dataList){
        var h = [];
        //sysPredefinedGroup;
        var subUnExist = sysPredefinedGroup;
        for(var i=0;i<dataList.length;i++){
            h.push({id:dataList[i].id,groupName:dataList[i].groupName});
            subUnExist = subUnExist.reject(function(value, index){
                 return(value.groupName == dataList[i].groupName);
            });
        }
        subUnExist.each(function(value,index){
            h.push({id:value.id, groupName:value.groupName});
        });
        return h
};

var $_dwrLogger;
function dwrlog(msg,type){
	try{
		if(!$_dwrLogger)
			$_dwrLogger = new NetEase.DwrLogger();
		$_dwrLogger.appendMsg(msg,type);
	}catch(ex){alert("广告过滤机制异常!");}
}

function inviteHost(){
	var button = $('addHostButton');
	button.disabled = true;
	var message = $('message').value;
	if(message.length > 50)
		message = message.substr(0, 50);	
	closeInviteHost();
	var groupToBeadd_Host = $('groupToBeadd_Host');
	var groupid = groupToBeadd_Host[groupToBeadd_Host.selectedIndex].value;
	
    //var chummy = $('$_chummy_check').checked;
    UserBean.inviteFriendByIdWithMsg(childId, msg, groupid, false, {
	//UserBean.inviteHost(message, groupid,{
	  callback:function(returnData) {
	  	button.disabled = false;
	    afterInviteHost(returnData);
	  },
	  errorHandler:function(errorString, ex) {
	  	//关键字过滤提示
		button.disabled = false;
	  	var filterType = filterWarning(ex, false);
	  }
	});
}

function afterInviteHost(returnData){
	var message;
	var type;
    if(returnData == 0){
        message = '已经发送过邀请';
        type = "ok";
	}else if(returnData > 0){
		message = '发送邀请成功';
		type = "ok";
	}else if(returnData <= -10){
		message="添加博友成功";
		type = "ok";
	}else switch(returnData){
		case -1:
			message="添加失败";
			type = "error";
			break;
		case -2:
			message="已经是你的博友";
			type = "error";
			break;
		case -3:
			message="不能添加自己";
			type = "error";
			break;
		case -4:
			message="匿名用户不能执行此操作";
			type = "error";
			break;	
		case -5:
			message="对方拒绝任何添加博友请求";
			type = "error";
			break;			
		case -6:
			message="超过博友总数上限限制";
			type = "error";
			break;
		default:
			message="添加失败";
			type = "error";
	}
	dwrlog(message, type);
}



function closeInviteHost(){
	var change_group = $("invite_Host");
	if(change_group.style.display!="none")
		Effect.SlideUp('invite_Host',{duration:0.2});	
}

var jsWindowManager = new NetEase.JSWindowManager({simpleDrag:true,useDragOpacity:true});
function showLoginDlg(serverName, loginTarget){
	if(g_quickLoginCon == null){
		g_quickLoginCon = new NetEase.QuickLogin("qLoginDiv", serverName, false, {err:false, jsWindowManager:jsWindowManager, loginTarget:loginTarget});
    }
	g_quickLoginCon.showWindow(loginTarget);
}



function getMailType(userName){
	var mailType = 0;
	if(userName){
		if(userName.match(/(.+)(\.vip)$/i)){
			mailType = 5;
		}else if(userName.match(/(.+)(\.popo)$/i)){
			mailType = 3;
		}else if(userName.match(/(.+)(@188)$/i)){
			mailType = 4;
		}else if(userName.match(/(.+)(@126)$/i)){
			mailType = 2;
		}else if(userName.match(/(.+)(@yeah)$/i)){
			mailType = 6;
		}else if(userName.match(/(.+)(@game)$/i)){
			mailType = 7;
		}else{
			mailType = 1;
		}
	}
	return mailType;	
}




//消息中心相关的调用工具
var msgTool;
function initMsgTool(){
	if(msgTool == null){
		msgTool = new NetEase.MsgTool({dwrAlert:dwrlog,jsWindowManager:jsWindowManager,
			dialogId:'msg_tool_dialog',style: UD.style});
	}	
}

function loadEventRemind(){

//	UserBean.getCountInfos(UD.visitorId, {callback:function(countsMap){
//		if(UD.visitorRank < 0) return;
//		/*var _oMsgCount = $("tlbrmsg");
//		if(_oMsgCount != null && countsMap.remindCount>=0){
//			_oMsgCount.innerHTML="未读消息"+countsMap.remindCount;	
//			_oMsgCount.style.marginRight=0;
//			_oMsgCount.onclick = clickEventZone;
//			if(countsMap.remindCount >0){
//				var _alertZone = $('eventShowButtonZoneId');
//				if(_alertZone){
//					_alertZone.innerHTML = '<span class="g_msg_new" onclick="clickEventZone();return false;"><span>&nbsp;</span><div>&nbsp;</div></span>';
//					_alertZone.style.display = 'inline';
//				}
//			}
//		}*/
//		var _oNoteCount = $('tlbrnt');
//		if (_oNoteCount){
//			if(countsMap.noteCount>=0){
//				_oNoteCount.innerHTML="新留言"+countsMap.noteCount;
//			}
//			_oNoteCount.style.marginRight=0;
////			_oNoteCount.href="http://blog.163.com/"+UD.visitorName+"/profile/edit/?target=note";
//		}
//		var _oCommentCount = $('tlbrcmt');
//		if (_oCommentCount){
//			if(countsMap.commentCount>=0){
//				_oCommentCount.innerHTML="新评论"+countsMap.commentCount;
//			}
//			_oCommentCount.style.marginRight=0;
////			_oCommentCount.href="http://blog.163.com/"+UD.visitorName+"/profile/edit/?target=blogcomment";
//		}
//	}});
	
	//取消息计数
	getMsgOnLogin();
	
	//取未读系统消息计数
	if(UD.visitorRank >=0 && UD.visitorId > 0) {
		MessageCenterBean.getUnReadBulletins(UD.visitorId, UD.visitorUserType, {
			callback:function(oData){
				if(oData && oData.length > 0){
					showSysMsg(oData);
				}
			}
		});
	}
	
}

function showSysMsg(sysMsg){
	var size = sysMsg.length;
	var _s = '<div class="i"><span class="dot">&#183;</span>' + '<a href="' + sysMsg[0].url +'" target="_blank">' + sysMsg[0].title + '</a>'
	if(size >1){
		_s += '<a class="a-show" href="#" id="show_all_sysMsg">显示后'+ (size-1)+'条</a>'
	}
	_s+='</div>';
	$("sysmsgsContent").innerHTML = _s;
	
	if(size >1) {
		$("show_all_sysMsg").onclick = function(){
			allSysMsg(sysMsg);
		};
	}
	$("sysmsgs").style.display = "block";
}
	
function closeSysMsg() {
	$("sysmsgs").style.display = "none";
	MessageCenterBean.updateBulletinLoadTime(UD.visitorId, {
		callback:function(oData){}, httpMethod:"POST"});
}
	
function allSysMsg (sysMsg){
	var jst_sys = new String('{for m in sysMsg}<div class="i"><span class="dot">&#183;</span><a href="${m.url}" target="_blank">${m.title}</a></div>{/for}');
	var _s = jst_sys.processUseCache({sysMsg: sysMsg});
	$("sysmsgsContent").innerHTML = _s;
}

//添加一个参数isStranger ，布尔型
function sendMessage(fromId, fromName, fromNickName, toId, toName, toNickName,isStranger){
	initMsgTool();
	msgTool.msgTo(fromId, fromName, fromNickName, toId, toName, toNickName,isStranger);
}
function clickEventZone(){
	window.open('http://blog.163.com/'+ UD.visitorName + '/home/#tid=9996','_neopen');
	$('eventShowButtonZoneId').style.display = "none";
	return false;
}


//function doEventRemind(obj){
//	if(obj.type == 1){
//		initMsgTool();
//		msgTool.showReceiveCardDialog(obj.srId,obj.isSys);
//	}
//}

var simplePageLayer = new NetEase.SimplePageLayer();	
//var neToolBar;
//function showNetEaseToolBar(){
//	neToolBar = new NetEase.ToolBar($('ne_toolbar_open'),$('ne_toolbar_open_menu'),{visitorName:UD.visitorName,hostName:UD.hostName,mailType:getMailType(UD.visitorName),simplePageLayer:simplePageLayer,jsWindowManager:jsWindowManager,objName:'neToolBar'});
//	return false;
//}
//
//var neFocusMe;
//function showNetEaseFocusMe(invitedRank,serverName){
//	neFocusMe = new NetEase.FocusMe($('ne_focusme_open'),{invitedRank:invitedRank,serverName:serverName,simplePageLayer:simplePageLayer,jsWindowManager:jsWindowManager,objName:'neFocusMe'});	
//}

var remindTopId = false;

var inviteHost_jst=
'	<div style="width:160px">'+
' '+
'			<div style="text-align:left;padding:7px;30px"><b>附言：</b>'+
'			</div>	'+
'			<div style="text-align:left;padding:7px;30px">'+
'				<textarea id="message" rows="3" cols="20" class="textbox" maxlength="50" onpropertychange="textareaLimit(this, 50)" ></textarea>'+
'			</div>'+
'					'+
'			<div style="text-align:left;padding:7px;30px">'+
'			<b>选择分组：</b>	'+
'			<select id="groupToBeadd_Host" style="width:125px">'+
'				{for group in visitorGroupLists}'+
'				{if true == group.isDefault}'+
'				<option value=${group.id} selected>${group.groupName}</option>'+
'				{else}'+
'				<option value=${group.id}>${group.groupName}</option>'+
'				{/if}'+
'				{/for}'+
'				</select>'+
'			</div>		'+
'           <div style="text-align:left;padding:7px;30px">'+
'           <b>&nbsp;&nbsp;&nbsp;&nbsp;</b>'+
//'           <input id="$_chummy_check" type="checkbox"/><label for="$_chummy_check">&nbsp;关注Ta的博客</label>'+
'           </div>      '+
'			<div style="text-align:left;padding:7px;30px"><input id="addHostButton" class="input_button" style="width:60px" type="button" value="确定" onclick="inviteHost(); return false;">'+
'			<input class="input_button" type="button" style="width:60px" value="取消" onclick="closeInviteHost();">	'+
'			</div>	'+
'	</div>';

var pageTopBar;
function showPageTopBar(options){
	if(!pageTopBar){
		pageTopBar= new NetEase.PageTopBar(Object.extend({objName:'pageTopBar'},options||{}));
		if($('pgtpbr-show')){$('pgtpbr-show').style.display = 'block';}
		if($('rmdtpchgstl')){$('rmdtpchgstl').onclick= function(){pageTopBar.showStyleMenu(0);return false;}}//.style.display = '';}
		if($('prvusrlftpdv')){$('prvusrlftpdv').style.display = 'block';}
		if($('rmdtpcpstl')){$('rmdtpcpstl').onclick=function(){pageTopBar.shareThisTheme(-1,-1,-1,-1,true);return false;}}
		if($('atchtpthmuse')){ /*$('atchtpthmuse').onclick=function(){pageTopBar.useThisTheme(event, -1, -1);return false;};*/ $('atchtpthmuse').disabled=false;}
		if($('atchtpstfv')){ /*$('atchtpstfv').onclick=function(){pageTopBar.collectThisTheme(event, -1,-1);return false;};*/ $('atchtpstfv').disabled=false;}
		if($('atchtpthmevaluate')){ /*$('atchtpthmevaluate').onclick=function(){pageTopBar.openSingleTheme(event, -1,-1);return false;};*/ $('atchtpthmevaluate').disabled=false;}
	}
}

/**
 * 通行证登录，尚未开通对应博客，浏览其他博客地址，通行证帐号作为昵称显示其登录状态，点击"我的博客"进入博客开通页面
 */
function topFromUrsLogin(){
	try{
		var nameFromUrs = Cookie.get("USERNAME_FROM_URS");
		
		//对外部邮箱注册的通行证，不改变$("_$$_TopBarRight").innerHTML，即与未登录访问博客一样
		if(nameFromUrs != null && nameFromUrs.search("@") != -1 && nameFromUrs.search("@126|@188|@yeah|@game") == -1){
			return;
		}
		if(nameFromUrs != null && nameFromUrs != "" && UD.status=="prev" && UD.visitorId <=0){
			$("_$$_TopBarRight").innerHTML = '<span class="a_a c_c" id="ne_toolbar_open_menu" href="http://blog.163.com/activation.do?host=activation&&username='+ nameFromUrs +'" target="_blank">'+ nameFromUrs +'</span><span class="s c07">&nbsp;|&nbsp;</span>'
								　			+'<span class="a_a c_c" id="rmdtphlp" href="http://help.163.com/special/007525FT/blog.html?b13aze1" target="_blank">帮助</span>';
		}
	}catch(e){};
}

function initFlash(hasFlash){
   var _id = UD.themeId;
   var _src = '';
   if((hasFlash&&hasFlash==1)||hasFlash==null){//if (_id>=4000 && _id<8000){
       _src = Const.STDomain+'/style/css/fixed/'+_id+'/mda/top.swf';
       
   };_setFlash(_src);
};
function _setFlash(_src){
   var _oDiv = $('_$$_Top_Flash');
   if (!_src){
       var _ebd = _oDiv.getElementsByTagName("embed")[0];
//          _ebd && _oDiv.removeChild(_ebd);return;
       _ebd && Element.removeChild(_ebd);return;
   }
   _oDiv.innerHTML = '<embed class="ht wkg" src="'+_src+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
};

function exitAfterLogged(){
	_exit();
	return false;
}

function _exit(){
	var exitTarget = window.location.href;
	var newhref= "http://blog.163.com/exit.do?target="+encodeURIComponent(exitTarget);
	location.href = newhref;		
}

var TopSearch = {
	inputboxId : 'rmndtplin',
	formId : 'rmndtplfm',
	searchlinkId : 'rmndtplsr',
	submitSearch : function(needCheckType){
		var _inputbox = $(TopSearch.inputboxId);
		var _querytext = _inputbox.value.trim() + ' site:blog.163.com';
        var _url = 'http://blog.youdao.com/search?q='+encodeURIComponent(_querytext);
		window.open(_url,'_blank');
		return false;
		
	},
	/*switchType : function(str){
		TopSearch.search_type = str;
		$(TopSearch.typelistId).style.display='none';
		TopSearch.submitSearch(true);
		return false;
	},*/
	/*showTypeList : function(event){
        Event.stop(event||window.event);
		$(TopSearch.typelistId).style.display='block';
	},*/
	init : function(){
		if ($(TopSearch.inputboxId)){
			$(TopSearch.inputboxId).onkeypress = function(event){
				var eve = event||window.event;
				if(eve && eve.type=='keypress' && eve.keyCode!=Event.KEY_RETURN) return;
//				if($(TopSearch.inputboxId).value.trim()=="")return;
				TopSearch.submitSearch();
				return false;
			}.bind(this);
			$(TopSearch.inputboxId).disabled=false;
		}
		if ($(TopSearch.searchlinkId)) $(TopSearch.searchlinkId).onclick = TopSearch.submitSearch;
		/*if ($(TopSearch.arrowId)) $(TopSearch.arrowId).onclick = TopSearch.showTypeList;
		Event.observe(document,'click',function(){$(TopSearch.typelistId).style.display='none';});
		var _form = $(TopSearch.formId);
		var _listDiv= document.createElement('div');
		_listDiv.id = TopSearch.typelistId;
		_listDiv.style.display = 'none';
		_listDiv.innerHTML = 
			'<a href="#" onclick="TopSearch.switchType(\'blog\');">日志</a>'+
			'<a href="#" onclick="TopSearch.switchType(\'photo\');">相片</a>'+
			'<a href="#" onclick="TopSearch.switchType(\'music\');">音乐</a>'+
			'<a href="#" onclick="TopSearch.switchType(\'tag\');">标签</a>'+
			'<a href="#" onclick="TopSearch.switchType(\'author\');">作者</a>';
		$(TopSearch.formId).appendChild(_listDiv);*/
		
	}
	/*getOrderParam : function(_type){
		var _o="all";
		_type = _type||TopSearch.search_type;
		if(_type=="music"){
			_o="name";
		}else if(_type=="tag"){
			_o="photo";
		}else if(_type=="author"){
			_o="nickname";
		}
		return _o;
	}*/
};

//顶部博客子菜单的显示
function toggleBlogItems(e){
	
	if($('blog_items')){
		if($('blog_items').style.display==''){
			$('blog_items').style.display='none';
		}else{
			$('blog_items').style.display='';
		}
	}
	stopBubble(e);

}

function stopBubble(e){	
    e = e||window.event;   
	if(e){
		var eventSource =e.srcElement||e.target;  	
		if(eventSource.tagName == 'A' && eventSource!=$('$_topbarItmes')){
			return;
		}
	}
	if(Event){
	    Event.stop(e);
	}
}

function hideBlogItems(){
	if($('blog_items')){
	    $('blog_items').style.display='none';
	}
}








/**************************************************************
*				163 blog page top bar  			   	              *
*                                                             *
* Written by:  zyf                                           *
* Important: to use this script don't                         *
*            remove these comments                            *
* Version 2.0 (MSIE 6.0 above,Firefox1.0,Netscape.)           *
* Created Date: 2007-06-09									  *
* Copyright：1997-2006 NetEase.com Inc. All rights reserved.  *
**************************************************************/
if (NetEase==undefined){
	var NetEase={};
}

NetEase.PageTopBar = Class.create();

NetEase.PageTopBar.prototype = {
	initialize: function(){
		this.lastScrollY = 0;
		this.topBarId = 'tptlbr';
		this.topBarDiv = $("tptlbr");
		this.initOpacity = Element.getOpacity(this.topBarDiv);
		this.options = Object.extend(
			{
				serverName:'blog.163.com',
				serverHostName:'blog.163.com',
				objName:'pageTopBar',
				heightOnHide:0,
				heightOnShow:65,
//				neToolbarName:'neToolBar',
				autoScroll:false,
				chosenBtnCss:'chsnbtn',
				firstShowTime:0,
				hideWaitTime:500,
				effectTime:0,
				styleThemeId:UD.themeId,
				styleFromUserId:UD.hostId,
				styleToUserId:UD.visitorId,
				styleShareThemeId:-1
			}, arguments[0]||{}
		);
		this.hideEffect = null;
		this._initScroll();		
		this._bindHideAndShow();
		this._initStatus();
		this._initParamsByStatus();
		this._initHTML();
		this._firstShow();
        
        this.sysPredefinedGroup = [                
            {id:-10, groupName:"亲人", isys: true},
            {id:-11, groupName:"现在同事", isys: true},
            {id:-12, groupName:"以前同事", isys: true},
            {id:-13, groupName:"大学同学", isys: true},
            {id:-14, groupName:"高中同学", isys: true},
            {id:-15, groupName:"普通朋友", isys: false},
            {id:-16, groupName:"朋友的朋友", isys: false}
        ];
		Event.observe(window,"load",this._checkTarget.bind(this));
	},
	_initScroll: function(){
//		window.setInterval("pageTopBar.autoScroll()",10);
		if(this.options.autoScroll)window.onscroll = this.autoScroll.bind(this);
	},
	autoScroll: function(){
		var diffY = document.documentElement.scrollTop || document.body.scrollTop;
//		percent=1*(diffY-this.lastScrollY);
//		percent = (percent>0)?Math.ceil(percent):Math.floor(percent);
//		this.topBarDiv.style.top=parseInt(this.topBarDiv.style.top)+percent+"px";
//		this.lastScrollY=this.lastScrollY+percent;
		this.topBarDiv.style.top = diffY + "px";
	},
	_bindHideAndShow: function(){
		this.topBarDiv.needHide = 0;
		this.topBarDiv.over = this.show.bind(this);
		this.topBarDiv.out = this.hide.bind(this);
		this.topBarDiv.onmouseover = this.show.bind(this);
	},
	hide: function(bForce){
		var count = this.topBarDiv.needHide;
		count++;		
		this.topBarDiv.needHide = count;
		this._changeCSSStatus('tpnormal');
		if(this.options.hideWaitTime==0 || bForce==true)this._realHide(count);
		else {
			this.topBarDiv.onmouseover = this._overWhenHide.bind(this);
			window.setTimeout(this._realHide.bind(this,count),this.options.hideWaitTime);
		}
	},
	_realHide: function(count){
		if(this.topBarDiv.needHide == count){
//			Effect.Fade(this.topBarId,{duration:2,to:0.01,userCallBack:this._hideCallBack.bind(this)});
			if(this.options.effectTime==0){
				this._beforeHide();
				this.topBarDiv.style.display = 'none';
				this._hideCallBack();
				return;
			}
			this.hideEffect = new Effect.BlindUp(this.topBarId,{duration:this.options.effectTime,fps:2,
				afterFinishInternal:this._hideCallBack.bind(this),
				beforeStartInternal:this._beforeHide.bind(this)
			});
		}
	},
	_beforeHide: function(){
//		this.topBarDiv.needHide=0;alert("beforehide:"+this.topBarDiv.needHide);
		if(this.options.effectTime !=0){
			this.topBarDiv.onmouseover = this._overWhenHide.bind(this);
			this._changeCSSStatus('tponhide');
			this.topBarDiv.style.overflow = 'hidden';
		}
		if(this.prevSubMenuId)$(this.prevSubMenuId).style.display = 'none';
		if(this.hostCardId){$(this.hostCardId).style.display = 'none';}
	},
	_overWhenHide: function(){
		if(this.hideEffect != null)this.hideEffect.cancel();
		this.show();
	},
	_hideCallBack: function(){
		//this._changeCSSStatus('tphide');
		this.topBarDiv.style.height = this.options.heightOnHide+'px';
		if(this.options.heightOnHide==0)this.topBarDiv.style.display = 'none';
//		this.topBarDiv.style.overflow = 'visible';
//		Element.setOpacity(this.topBarDiv,this.initOpacity);
		this.topBarDiv.onmouseout = '';
		if(this.options.heightOnHide!=0)this.topBarDiv.onmouseover = this.topBarDiv.over;
	},
	show: function(){
//		if(this.pageStatus == 'edit'){
//			if($('tlbrmsg2'))$('tlbrmsg2').innerHTML = $('tlbrmsg').innerHTML;
//		}		
		this.topBarDiv.needHide += 1;
		if(this.hideEffect != null)this.hideEffect.cancel();
		this._changeCSSStatus('tpon');
		this.topBarDiv.style.height = this.options.heightOnShow+'px';
		if(this.options.heightOnHide == 0)this.topBarDiv.style.display = '';
		this.topBarDiv.onmouseover = '';
		this.topBarDiv.onmouseout = this.topBarDiv.out;
	},
	_firstShow:function(){
		this.topBarDiv.needHide = 0;
		this._changeCSSStatus('tpnormal');
		if(this.options.firstShowTime!=0){
		window.setTimeout(this._realHide.bind(this,0),this.options.firstShowTime);}
		else this._realHide(0);
	},
//	_topbarClasses:["tpnormal","tpon","tphide"],
	_changeCSSStatus:function(classname){
//		for(var i=this._topbarClasses.length-1;i>=0;i--){
//			if(this._topbarClasses[i]==classname)Element.addClassName(this.topBarDiv,classname);
//			else Element.removeClassName(this.topBarDiv,this._topbarClasses[i]);
//		}
		if(this.topBarDiv.className.indexOf(classname)>-1)return;
		var tpall = /\b(tpnormal|tpon|tphide|tponhide)\b/g;
		if(!tpall.test(this.topBarDiv.className))this.topBarDiv.className += " "+classname;
		else this.topBarDiv.className = this.topBarDiv.className.replace(tpall,classname);
		return;
	},
	_initStatus:function(){
//		if(UD.hostId == UD.visitorId)this.pageStatus = 'edit';
//		else if(UD.visitorId != -1)this.pageStatus = 'prev';
//		else this.pageStatus = 'unlogged';
		if(UD.visitorRank == 10000)this.pageStatus = 'edit';
		else if(UD.visitorRank >= 0)this.pageStatus = 'prev';
		else this.pageStatus = 'unlogged';
	},
	_initParamsByStatus: function(){
		if(this.pageStatus == 'edit'){
			this.editBarId = ["tpe1","tpe2","tpe3"];			
//			this.msgCount = 
		}else if(this.pageStatus == 'prev'){
			this.focusData={};
			this._initFocusFrame();
//			this.prevSubMenuId = 'prvsbmn';
//			this.hostCardId = 'tpshwcrd';
		}else{
			this.focusData={};
			this._initFocusFrame();
//			this.hostCardId = 'tpshwcrd';
		}
	},
	_initHTML:function(){
		if(this.pageStatus == 'edit'){
			this.topBarDiv.innerHTML = this._jst_edit.process({
				visitorNickname:UD.visitorNickname.js_escape()||UD.visitorName,
				visitorName:UD.visitorName,objName:this.options.objName,
				serverHostName:this.options.serverHostName, migStat:UD.migStat});
		}else if(this.pageStatus == 'prev'){
//			this.topBarDiv.innerHTML = this._jst_prev.process({
//				hasAdminCircles:UD.hasAdminCircles,visitorNickname:UD.visitorNickname.js_escape()||UD.visitorName,visitorName:UD.visitorName,
//				serverHostName:this.options.serverHostName,hostNickname:UD.hostNickname.js_escape()||UD.hostName,hostImgUrl:UD.hostImgUrl,
//				hostId:UD.hostId,objName:this.options.objName});
		}else{
//			this.topBarDiv.innerHTML = this._jst_unlog.process({
//				serverHostName:this.options.serverHostName,serverName:this.options.serverName,
//				hostNickname:UD.hostNickname.js_escape()||UD.hostName,hostImgUrl:UD.hostImgUrl,objName:this.options.objName});
		}
	},
	showPrevSubMenu: function(event){
		Event.stop(event || window.event);
		this.topBarDiv.style.overflow = 'visible';
		this.hideHostCard();
		var _psm = $(this.prevSubMenuId);
		if(_psm){
			if(_psm.style.display=='none')_psm.style.display = 'block';
			else _psm.style.display = 'none';			
		}
	},
	showStyleMenu: function(i){
//		$("tpe1").style.display = 'none';
//		$("tpe2").style.display = 'block';
//		this.changeEditBar(2);
//		this.show();
//		if(i!=1 && i!=2)i=0;
////		if(i==null)i=0;
////		this.topBarDiv.onmouseover = '';
////		this.topBarDiv.onmouseout = '';
//		if(!isNaN(i)){
//			this.hideCloseLink();
//			this._keepShow();
//			var _btn = $("tpe2btn"+i);
////			_btn && (_btn.className += (" "+this.options.chosenBtnCss));
//			Element.addClassName(_btn,this.options.chosenBtnCss);
//		}
//		if(i!=1 && i!=2)
		if (UD.pageName!="editHome"){
			if(i==undefined || isNaN(i))i=8;			
            window.name = '{op:"custom",tp:'+(parseInt(i)||0)+'}';
		 	window.location='http://'+DomainMap.getParentDomain(UD.visitorName) + '/edit/#'+i+"-";
		 	return;	
		 }
		if($(this.editBarId[1]).style.display=='none')this.changeEditBar(2);
		this.show();
		UD.bar.style.marginTop = this.options.heightOnShow+'px';
		this._keepShow();
		this.showCloseLink();
		if(i==null||i==8)return;
		this._showThemeSetting(i);
	},
	_showThemeSetting: function(index){
		if (UD.pageName!="editHome"){
            window.name = '{op:"custom",tp:'+(parseInt(index)||0)+'}';
		 	window.location='http://'+DomainMap.getParentDomain(UD.visitorName) + '/edit/#'+index+"-";
		 	return;	
		 }
		if(index!=1 && index!=2 && index!=3)index=0;
//		if(i==null)i=0;
//		this.topBarDiv.onmouseover = '';
//		this.topBarDiv.onmouseout = '';
		if(!isNaN(index)){
			this.hideCloseLink();
			var _btn = $("tpe2btn"+index);
//			_btn && (_btn.className += (" "+this.options.chosenBtnCss));
			Element.addClassName(_btn,this.options.chosenBtnCss);
		}
		 HomeManager.showSetWin(index);
//		 this._keepShow();		
	},
	changeSelectedButton: function(i){
		if(!this._styleButtons)this._styleButtons = [$("tpe2btn0"),$("tpe2btn1"),$("tpe2btn2")];
		if(i==null || isNaN(i)||i<0 ||i>=this._styleButtons.length){
			for(var j=0,l=this._styleButtons.length;j<l;j++){
				Element.removeClassName(this._styleButtons[j],this.options.chosenBtnCss);
			}
			this.showCloseLink();
//			this._cancelKeepShow();
		}else{
			for(var j=0,l=this._styleButtons.length;j<l;j++){
				if(j==i)Element.addClassName(this._styleButtons[j],this.options.chosenBtnCss);
				else Element.removeClassName(this._styleButtons[j],this.options.chosenBtnCss);
			}
			this.hideCloseLink();
			if(!(/\btphide\b/.test(this.topBarDiv.className))){
			this._keepShow();
			}
		}
	},
	changeEditBar: function(_i){
		_i--;
		if(!this.editBarId)return;
		else{
			for(var i=0,l=this.editBarId.length;i<l;i++){
				if(i==_i)continue;
				else $(this.editBarId[i]).style.display = 'none';
			}
			$(this.editBarId[_i]).style.display = '';
		}
	},
	closeStyleMenu: function(){
//		$("tpe2").style.display = 'none';
//		$("tpe1").style.display = 'block';
		if(!(/\btphide\b/.test(this.topBarDiv.className))){
		this._cancelKeepShow(true);
		//$('_$$_TopBar').style.marginTop = '0px';
		UD.bar.style.marginTop = '0px';
		this._hideCallBack();}
		this.changeEditBar(1);
	},
	_keepShow: function(){
//		var tpall = /(tpnormal|tphide|tponhide)/g;
		if(/(tpnormal|tphide|tponhide)/.test(this.topBarDiv.className)){
			this.show();
		}
		this.topBarDiv.onmouseover = '';
		this.topBarDiv.onmouseout = '';
//		this.hideCloseLink();
	},
	_cancelKeepShow: function(bForce){
//		this.topBarDiv.onmouseover = this.topBarDiv.over;
//		this.topBarDiv.onmouseout = '';
		this.hide(bForce);
		this.showCloseLink();
	},
	showCloseLink: function(){
		if ($('tpe2back')) {
			$('tpe2back').style.display = '';
		}
	},
	hideCloseLink: function(){
		if ($('tpe2back')) {
			$('tpe2back').style.display = 'none';
		}
	},
	showSaveBar: function(){
//		this.hideCloseLink();
		this.changeEditBar(3);		
//		$("tpe3").style.display = 'block';
		this._keepShow();
	},
	hideSaveBar: function(){
//		$("tpe3").style.display = 'none';
//		this.showCloseLink();
		if($("tpe3").style.display == 'none')return;
		UD.bar.style.marginTop = '0px';
		this._cancelKeepShow(true);
		this.changeEditBar(1);
	},
	
	popupMusic: function(url){
	if (!isIE)
		window.open(url,"_blank","resizable=no,scrollbars=no,status=yes,width=365px,height=300px");
	else
		window.open(url,"_blank","resizable=no,scrollbars=no,status=yes,width=770px,height=591px");
	},
	
	_showHostCardCallBack: function(returnData){
		if(returnData != null){
			var logged = 'no';
			if(UD.visitorRank>=0)
				logged = 'yes';
			var friend = returnData["host"];
			var blogList = 	returnData["listBlog"];
			var photoList = returnData["listPhoto"];
			if(friend.spaceName == null || friend.spaceName == "")
				friend.spaceName = friend.name+"的博客";	
			var onLine = returnData["onLine"];
			var genderClass = '';
			var onLineTitle = '离线';
			if(onLine){
				onLineTitle = '在线';
				if(friend.gender=='F')
					genderClass = 'n_ m10';
				else
					genderClass = 'n_ m12';
			}else{
				if(friend.gender=='F')
					genderClass = 'n_ m11';
				else
					genderClass = 'n_ m13';
			}
			var data = {inProcess:'no', hasBlog:'yes', blogList:blogList,logged:logged,
			 genderClass:genderClass, onLineTitle:onLineTitle,canInvite:'no',
			 userId:UD.hostId,photoList:photoList, friend:friend, objName:this.options.objName};
			var result = this._jst_host_card.process(data);	
			$("tpshwcrd").innerHTML = result;
			this.cardContent = result;	
		}
	
	},
	showHostCard: function(){
		var _cardDiv = $("tpshwcrd");
		this.topBarDiv.style.overflow='visible';
		if(this.prevSubMenuId)$(this.prevSubMenuId).style.display = 'none';
		_cardDiv.innerHTML = this._jst_host_card.process({inProcess:true});
		_cardDiv.style.display = 'block';
		_cardDiv.style.left = '150px';
		_cardDiv.style.top = '65px';
		if(this.cardContent){_cardDiv.innerHTML=this.cardContent;return;}
		UserBean.getHostMiniSpace(UD.hostId, {
		  callback:this._showHostCardCallBack.bind(this)
		});	
	},
	hideHostCard: function(){
		if(this.hostCardId)$(this.hostCardId).style.display = 'none';
	},
	switchCardShow: function(type,id){
		$(type+'Show_'+id).className = "selected";
		$(type+'Content_'+id).style.display = "";
		var opType = (type == 'blog')?'photo':'blog';
		$(opType+'Content_'+id).style.display = 'none';
		$(opType+'Show_'+id).className = '';
	},
	_jst_edit: '\
		<div id="tpe1" class="wrp">\
		  <div class="item tpeb"><div class="g_htc_hvr tpe_" onclick="window.location.href=\'http://${visitorName|parentDomain}/blog/getBlog.do\'"></div></div>\
		  {if migStat!=2}\
		  <div class="item tpep"><div class="g_htc_hvr tpe_" onclick="window.location.href=\'http://${visitorName|parentDomain}/editPhotoUpload.do\'"></div></div>\
		  {/if}\
		  <div class="item tpem"><div class="g_htc_hvr tpe_" onclick="${objName}.popupMusic(\'http://${visitorName|parentDomain}/m/\');"></div></div>\
		  {if migStat!=2 && migStat!=3}\
		  <div class="item tpec"><div class="g_htc_hvr tpe_" onclick="window.location.href=\'http://${visitorName|parentDomain}/editCamera.do\'"></div></div>\
		  {/if}\
		  <div class="item tpej"><div class="g_htc_hvr tpe_" onclick="window.open(\'http://blog.163.com/clone/clone.html\');"></div></div>\
		  <div class="item tpes"><div class="g_htc_hvr tpe_" onclick="${objName}.showStyleMenu();"></div></div>\
	      <div class="spanr2 a_a c_c" href="http://${visitorName|parentDomain}/setAuthority.do">系统设置</div>\
		  <div class="rtdv"><span>${visitorNickname}</span><span class="">|</span>\
			<span class="a_a" id="tlbrmsg2" href="#" onclick="newEventReminder._showEventRemindZone();">我的消息</span><span class="">|</span>\
			<span class="a_a" href="http://${serverHostName}" target="_blank">网易博客</span><span class="">|</span>\
		    <span class="a_a" href="http://help.163.com/special/007525FT/blog.html?b13aze1" target="_blank">帮助</span><span class="">|</span>\
		    <span class="a_a" href="http://${serverHostName}/exit.do">退出</span>\
		  </div>\
		</div>\
		<div id="tpe2" class="wrp" style="display:none;">\
		  <div class="tpe2btns">\
		    <div class="item tpesf"><div class="tpe_">&nbsp;</div></div>\
		    <div class="tpe2tl g_t_14">正在装扮我的博客，开始&nbsp;</div>\
		    <div class="btnwrp"><input type="button" id="tpe2btn0" class="g_c_hand" onclick="${objName}.showStyleMenu(0);" value="换风格"></input></div>\
		    <div class="btnwrp"><input type="button" id="tpe2btn2" class="g_c_hand" onclick="${objName}.showStyleMenu(2);" value="设置首页内容"></input></div>\
		    <div class="btnwrp"><input type="button" id="tpe2btn1" class=" g_c_hand" onclick="${objName}.showStyleMenu(1);" value="设置首页版式"></input></div>\
		  </div>\
		  <div id="tpe2back" class="tpe2bck" onclick="${objName}.closeStyleMenu();" style="display:none;">[<span>关闭</span>]</div>\
		</div>\
		<div id="tpe3" class="wrp" style="display:none;">\
			<div class="tpe3txt">你已经拖动模块改变了首页的布局，点击“保存修改”后修改生效。</div>\
		  <div id="tpe2sv" class="tpe2btns2">\
		  	<input type="button" class="btncm2" value="" onclick="HomeManager.saveModules();" />\
            <input type="button" class="btncm" value="取　消" onclick="HomeManager.cancelModules();" />\
		  </div>\
		</div>\
	',
	_jst_prev: '\
		<div class="wrp">\
		  <div class="item tppot"><div class="g_htc_hvr tpp_" onclick="window.open(\'http://${visitorName|parentDomain}\')">\
		    <div onmouseover="this.parentNode.className +=\' hvrrt\'" onmouseout="Element.removeClassName(this.parentNode,\'hvrrt\')" onclick="${objName}.showPrevSubMenu(event);"></div>\
		  </div></div>\
		  <div class="cntrdv">\
		    <div class="vstinfo">你正在访问<span>${hostNickname|escape}</span>的博客</div>\
		    <div class="imgwrp"><img src="${formatImageUrl(hostImgUrl)}" height="40" width="40" onclick="${objName}.showHostCard();" onerror="this.src=\''+Const.STDomain+'/style/common/user_default.png\'"/></div>\
		    <div class="btnwrp"><input type="button" class="g_c_hand" onclick="${objName}.sendMsg(${hostId},\'${hostNickname}\');" value="发送消息"/></div>\
		    <div class="btnwrp"><input type="button" class="g_c_hand" onclick="${objName}.showAddFriend();" value="加为博友"/></div>\
		    {if hasAdminCircles}<div class="btnwrp"><input type="button" class="g_c_hand" onclick="${objName}.showInviteCircle();" value="邀请加入圈子"/></div>{/if}\
		  </div>\
		  <div class="rtdv"><span>${visitorNickname}</span><span class="">|</span>\
		    <span class="a_a" href="http://${serverHostName}" target="_blank">网易博客</span><span class="">|</span>\
		    <span class="a_a" href="http://help.163.com/special/007525FT/blog.html" target="_blank">帮助</span><span class="">|</span>\
		    <span class="a_a" href="http://${serverHostName}/exit.do">退出</span>\
		  </div>\
		</div>\
		<div id="prvsbmn" style="display:none;">\
		  <div class="item tpeb"><div class="g_htc_hvr tpe_" onclick="window.open(\'http://${visitorName|parentDomain}/blog/getBlog.do\')"></div></div>\
		  <div class="item tpep"><div class="g_htc_hvr tpe_" onclick="window.open(\'http://${visitorName|parentDomain}/editPhotoUpload.do\')"></div></div>\
		  <div class="item tpem"><div class="g_htc_hvr tpe_" onclick="${objName}.popupMusic(\'http://${visitorName|parentDomain}/m/\');"></div></div>\
		  <div class="item tpec"><div class="g_htc_hvr tpe_" onclick="window.open(\'http://${visitorName|parentDomain}/editCamera.do\')"></div></div>\
		</div>\
		<div id="tpshwcrd" style="display:none;" class="g_lay_com g_crd_5">\
	',
	_jst_unlog: '\
		<div class="wrp">\
		  <div class="item tpuot"><div class="g_htc_hvr tpu_" onclick="showLoginDlg(\'${serverName}\');return false;"></div></div>\
		  <div class="cntrdv">\
		    <div class="vstinfo">你正在访问<span>${hostNickname|escape}</span>的博客</div>\
		    <div class="imgwrp"><img src="${formatImageUrl(hostImgUrl)}" height="40" width="40" onclick="${objName}.showHostCard();" onerror="this.src=\'http://b.bst.126.net/style/common/user_default.png\'"/></div>\
		    <div class="btnwrp"><input type="button" class="g_htc_hvr g_c_hand" onclick="${objName}.sendMsg();" value="发送消息"/></div>\
		    <div class="btnwrp"><input type="button"  class="g_htc_hvr g_c_hand" onclick="${objName}.showAddFriend();" value="加为博友"/></div>\
		  </div>\
		  <div class="rtdv">\
		    <span class="a_a" href="http://${serverHostName}" target="_blank">网易博客</span><span class="">|</span>\
		    <span class="a_a" onclick="showLoginDlg(\'${serverName}\');return false;">登录</span><span class="">|</span>\
		    <span class="a_a" href="http://reg.163.com/reg/reg0.jsp?url=http://blog.163.com/ntesRegBlank.html">注册</span>\
		  </div>\
		</div>\
		<div id="tpshwcrd" style="display:none;" class="g_lay_com g_crd_5">\
	',
	_jst_host_card: '\
		<span onclick="${objName}.hideHostCard(); return false;" class="close n_ n7" title="关闭">&nbsp;</span> \
			{if inProcess == "yes"} \
				&nbsp;<b>数据读取中...</b><br /><br /><br /> \
			{/if} \
			{if inProcess == "no"} \
		<div class="info"> \
		  <span class="a_a d_d" href="http://${friend.name|escape|parentDomain}/" target="_blank"><img class="g_img_02" src="${formatImageUrl(friend.imageUrl)}" onerror="this.src=\'http://b.bst.126.net/style/common/user_default.png\'" /></span> \
			<p class="g_h_25 g_t_hide g_t_14 g_t_bold"><span class="a_a d_d" href="http://${friend.name|escape|parentDomain}/" target="_blank">${friend.nickname}</span></p> \
			<p class="g_h_20"><span class="${genderClass}" title="${onLineTitle}">&nbsp;</span> \
			{if !friend.birthSec && friend.ageStr!="未透露"}${friend.ageStr}岁{/if}</p> \
			<p>${friend.province}&nbsp;${friend.city}</p> \
			<div class="g_p_absolute g_p_left_btm g_h_20 g_t_center"> \
			{if logged=="yes" && friend.affirm == 1} \
			  <span class="g_c_hand n_ n44" title="发送贺卡" onclick="showSendCardDialog(${friend.id},\'${friend.name|default:""|escape}\',\'${friend.nickname|default:""|js_string}\');return false;">&nbsp;</span>&nbsp; \
				<span class="g_c_hand n_ e5" title="发送消息" onclick="newEventReminder.msgTo(${friend.id},\'${friend.nickname|default:""|js_string}\'); return false;">&nbsp;</span>&nbsp; \
			{/if} \
			</div> \
		</div> \
		<div class="recmd frnd"> \
			<div class="g_tab_btn03"> \
			  <div id="blogShow_${friend.id}" class="selected" onclick="${objName}.switchCardShow(\'blog\', ${friend.id});return false;">最新日志(${blogList.length})<span class="n_ n32 g_p_none">&nbsp;</span></div> \
				<div id="photoShow_${friend.id}" onclick="${objName}.switchCardShow(\'photo\', ${friend.id});return false;">最新相片(${photoList.length})<span class="n_ n32 g_p_none">&nbsp;</span></div> \
			</div> \
			<div class="case" id="blogContent_${friend.id}"> \
				<div> \
				{if blogList != null} \
				{for blog in blogList} \
					<p class="g_t_hide"><em>&#149;</em> \
					<span class="a_a d_d" href="http://${friend.name|escape|parentDomain}/${blog.permalink}/" target="_blank">${blog.title|escape}</span> \
					</p> \
				{/for} \
				{/if} \
				</div><div class="g_p_absolute g_p_rght_btm g_h_20 g_t_left"><span class="n_ n30" title="最后登陆时间">&nbsp;</span>{var timeStr = getLongDateTime(friend.lastLoginTime)}${timeStr}</div> \
			</div> \
			<div class="case" id="photoContent_${friend.id}" style="display:none;"> \
				<div> \
				{if photoList != null} \
				{for photo in photoList} \
				 <span class="a_a c_c" href="http://${friend.name|escape|parentDomain}/prevPhoto.do?photoId=${photo.id}" target="_blank"> \
				    <img class="g_img_04 g_c_hand" src="${photo.squareUrl}" > \
				  </span> \
				{/for} \
				{/if} \
				</div><div class="g_p_absolute g_p_rght_btm g_h_20 g_t_left"><span class="n_ n30" title="最后登陆时间">&nbsp;</span>{var timeStr = getLongDateTime(friend.lastLoginTime)}${timeStr}</div> \
			</div> \
		</div>	\
		{/if} \
	',
	
	_checkTarget: function(){	
	   this.options.styleToUserId = UD.visitorId;
		if(UD.visitorRank>=10000){
//			dwrlog("您已经用博主帐号登录");
			switch(UD.externHash){
				case 'fm_6':
					this.showStyleMenu(0);
					break;
			}
		}else{
			switch(UD.externHash){
				case 'fm_1':
            UserBean.checkTargetVerifyRank(UD.visitorId, {
			   callback:function(isFriend){
                      if (!isFriend){
					this.sendMsgToStranger(UD.visitorId, UD.visitorName, UD.visitorNickname.js_escape(), UD.hostId, UD.hostName, UD.hostNickname.js_escape());
				    }
					else {
						this.sendMsg(UD.visitorId, UD.visitorName, UD.visitorNickname.js_escape(), UD.hostId, UD.hostName, UD.hostNickname.js_escape());
					}
			        }.bind(this)
		           });
					break;
				case 'fm_2':
					this.showAddFriend();
					break;
				case 'fm_3':
					this.showFocusFrame('web');
					break;
				case 'fm_4':
					this.showFocusFrame('rss');
					break;
				case 'fm_5':
					this.shareThisTheme(-1,-1,-1,-1,true);
					break;
				case 'fm_7':
					this.shareThisTheme(-1,-1,-1,-1,false);
					break;
				case 'fm_8':
					this.shareOpenModule();
					break;
				case 'fm_9':
					this.deleteFriend();
					break;
				case 'fm_10':
					this.followNormalUser();
					break;
				case 'fm_11':
					this.cancelFollowNormalUser();
					break;
			}
		}
	},
	
	_getLoginTarget: function(type){
		var href = window.location.href;
		href = href.replace(/^(.+)#.*?$/ig,"$1");
		return href+'#'+type;
	},
	
	_initFocusFrame: function(){
		if(this.focusFrame == null){
			if(!this.jsWindowManager){
				this.jsWindowManager = jsWindowManager;
			}			
			this.focusFrame = this.jsWindowManager.createWindow('$_ne_focus_frame',{
					className:"g_win_6", width: 350, height:100, notKeepPos: true,afterHiddenFunc:this._cancelKeepShow.bind(this,true),afterCloseFunc:this._cancelKeepShow.bind(this,true)
				}
			);
		}
	},
	closeFocusFrame: function(){
		this.focusFrame.hiddenWindow();
	},
    
    _changeGroupSelection: function(seletId){//, checkId){
       var selectTargetId = $F(seletId);
       var selectTarget = this.sysPredefinedGroup.detect(
           function(value, index){return value.id == selectTargetId}
       );
//       if(selectTarget && selectTarget.isys){
//           $(checkId).checked = true;
//           return;
//       }
//           $(checkId).checked = false;
    },
    
    _getSelectOptionForFriend: function(dataList){
        var h = [];
        //sysPredefinedGroup;
        var subUnExist = this.sysPredefinedGroup;
        for(var i=0;i<dataList.length;i++){
            h.push('<option value="'+dataList[i].id+'">'+dataList[i].groupName.escape()+'</option>');
            subUnExist = subUnExist.reject(function(value, index){
                  if(value.groupName == dataList[i].groupName){
                     Object.extend(value, dataList[i]);
                     Object.extend(dataList[i], value);
                     return true;
                  }
                  return false;
            });
        }
        subUnExist.each(function(value,index){
            h.push('<option value="'+value.id+'">'+value.groupName+'</option>');
        });
        return h.join('');
    },
    /*
	_getSelectOptionForFriend: function(dataList){
		var html='';
		for(var i=0;i<dataList.length;i++){
			html+='<option value="'+dataList[i].id+'">'+dataList[i].groupName.escape()+'</option>';	
		}		
		return html;
	},*/

	_getSelectOptionForCircle: function(dataList){
		var html='';
		for(var i=0;i<dataList.length;i++){
			html+='<option value="'+dataList[i].circleId+'">'+dataList[i].circle.name.escape()+'</option>';	
		}
		return html;
	},
	
	_getSelectOption: function(dataList){
		var html='';
		for(var i=0;i<dataList.length;i++){
			html+='<option value="'+dataList[i].id+'"' + (dataList[i].listName=='网址收藏'?'selected':'') + '>'+dataList[i].listName.escape()+'</option>';	
		}
		return html;
	},
	
	sendMsg: function(fromId, fromName, fromNickName, toId, toName, toNickName){
//		this._keepShow();
		if(UD.visitorRank<0){
			if(toId==UD.hostId){
				showLoginDlg(this.options.serverName,this._getLoginTarget('fm_1'));
			}else{//当收消息人的id不是当前博主的id（例如给博主的某个博友发消息）并且未登录时，仅仅登录即可
				showLoginDlg(this.options.serverName);
			}
			return;
		}
		sendMessage(fromId, fromName, fromNickName, toId, toName, toNickName,false);
	},
	
	sendHost: function(whetherFriend){
		if (whetherFriend == 0){
			this.sendMsgToStranger(UD.visitorId, UD.visitorName, UD.visitorNickname, UD.hostId, UD.hostName, UD.hostNickname);
		}
		else{
			 this.sendMsg(UD.visitorId, UD.visitorName, UD.visitorNickname, UD.hostId, UD.hostName, UD.hostNickname);
		}
	},
	sendMsgToStranger: function(fromId, fromName, fromNickName, toId, toName, toNickName){
//		this._keepShow();
		if(UD.visitorRank<0){
			if(toId==UD.hostId){
				showLoginDlg(this.options.serverName,this._getLoginTarget('fm_1'));
			}else{//当收消息人的id不是当前博主的id（例如给博主的某个博友发消息）并且未登录时，仅仅登录即可
				showLoginDlg(this.options.serverName);
			}
			return;
		}
		sendMessage(fromId, fromName, fromNickName, toId, toName, toNickName,true);
	},
	
	
	showAddFriend: function(){
//		this._keepShow();
		if(UD.visitorRank<0){
			showLoginDlg(this.options.serverName,this._getLoginTarget('fm_2'));
			return;
		}
		if(this.options.invitedRank == 2 || UD.invitedRank == 2){
			this.showDenyInvitingDlg();
			return;
		}
		if ($("friend_status") && $("friend_status").getAttribute("isFriend") == "true") return;
		if(this.focusData['friend'] == null){
			UserBean.getVisitorGroups(this._initAddFriendHtml.bind(this));
		}else{
			this._initAddFriendHtml(this.focusData['friend']);
		}
	},
	_initAddFriendHtml: function(dataList){
		if(dataList == null){
			dwrlog("对方不允许你加为博友","error");
			return;
		}
		this.focusData['friend'] = dataList;
		this.focusFrame.updateTitle('加为博友');
		var blogGender = '他';
		if($("follow_status"))
		   blogGender = $("follow_status").getAttribute("value");
		this.focusFrame.panel.innerHTML=
           		'<p style="padding-bottom:10px;color:#777;">&nbsp;在博主接受请求之前可以先关注'+blogGender+'，接收'+blogGender+'的动态更新。</p>\
           		<table class="g_c_mvdn" border="0" cellspacing="0" cellpadding="0">\
					   <tr><td class="g_t_right g_t_top g_t_hide" style="width:23%;padding-right:0px;"><span class="g_t_12">附　　言：</span></td><td><textarea class="g_h_40 g_w_90" id="ne_friend_msg" onpropertychange="textareaLimit(this, 50)"></textarea></td></tr>\
					   <tr><td class="g_t_right g_t_top g_t_hide" style="width:23%;padding-right:0px;"><span class="g_t_12">选择分组：</span></td><td><select style="width:92%" nohide="true" id="ne_friend_groupid" onChange="'+this.options.objName+'._changeGroupSelection(\'ne_friend_groupid\');">'+this._getSelectOptionForFriend(this.focusData['friend'])+'</select></td></tr>\
						 <tr><td class="g_t_top g_t_right g_t_hide" style="width:23%;padding-right:0px;"><span class="g_t_12" style="display:block;padding-top:4px;">验 证 码：</span></td><td id = "mvdn"style="align:middle;"><input  style="float:left;width:40px;" value="" maxlength="4" id="mvdnValcode" /><img id="valcodeimg" style="display:block;float:left;width:60px;height:24px;margin-left:10px;" alt="验证码" src="' + this._getCaptchaImgSrc() + '" /><a href="#" onclick="pageTopBar.genValidCodeImg();"style="height:24px;line-height:24px;margin-left:15px;">看不清 换一张</a></td></tr>\
						 <tr><td colspan="2" class="g_t_center">\
								<div id="ne_frame_submit">\
								<input type="button" class="btncm btnok" value="发送请求" onclick="'+this.options.objName+'.submitAddFriend();return false;"/>\
								<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>\
								<input type="button" class="btncm btncc" value="取　消" onclick="'+this.options.objName+'.closeFocusFrame();return false;"/>\
								</div><div id="ne_frame_info" style="display:none;">处理中...</div>\
								<div id="ne_frame_error" style="display:none;">添加博友失败, 请刷新重试!</div>\
						 </td></tr>\
				</table>';
		this.focusFrame.showWindow();
		$('ne_friend_msg').focus();
	},
	_getCaptchaImgSrc: function(){
		var _iRandom = Math.floor(Math.random()*10001);
		var _sId = (_iRandom+"_"+new Date().getTime()).toString();
		var ss = "/cap/captcha.jpgx?parentId=" + encodeURIComponent(UD.hostId) + "&" + _sId;
		return ss;
		},
	genValidCodeImg: function(){		   
		var _oCodeDiv = $("valcodeimg");
		
			//不管页面中是否已经生成过验证码, 都重新生成一次
		if(_oCodeDiv != undefined && _oCodeDiv != null && _oCodeDiv != "") 						
				_oCodeDiv.src =  this._getCaptchaImgSrc() ;
					
		
	},
	submitAddFriend: function(){
	    $('ne_frame_submit').style.display='none';
	    $('ne_frame_info').style.display='';
	    $('ne_frame_error').style.display='none';
		var msg = $F('ne_friend_msg').trim();
		if(msg.length > 50)
			msg = msg.substr(0, 50);	
		var groupid = $F('ne_friend_groupid');        
		//var chummy = $('$_chummy_check').checked;
        var valcode =  $F('mvdnValcode').trim();
        
        if (valcode != undefined &&(valcode == null || valcode == "")){                 	    
        	 dwrlog("请输入验证码","error");  
        	 this.genValidCodeImg();  
            $('ne_frame_info').style.display='none';
            $('ne_frame_submit').style.display='';
                 
        	return ;
        }
        else if (valcode != undefined && valcode != null && valcode.length < 4){ 
        	 dwrlog("验证码为4位","error");        
        	 this.genValidCodeImg();    
            $('ne_frame_info').style.display='none';
            $('ne_frame_submit').style.display='';     
            
        	return ;
        }
		else UserBean.inviteHostWithMsgAndValcode(msg, groupid, valcode,{
			  callback:function(returnData) {
			  	var message;
				var type;
				var relation = -1;
                if(returnData == 0){
                    message = '已经发送过邀请';
                    type = "ok";
                    relation = 0;
                }else if(returnData > 0){
                    message = '发送邀请成功';
                    type = "ok";
                    relation = 0;
				}else if(returnData <= -10){
					message="添加博友成功";
					type = "ok";
					relation = 1;
				}else switch(returnData){
					case -1:
						message="添加失败";
						type = "error";
						break;
					case -2:
						message="已经是你的博友";
						type = "error";
						relation = 1;
						break;
					case -3:
						message="不能添加自己";
						type = "error";
						break;
					case -4:
						message="匿名用户不能执行此操作";
						type = "error";
						break;	
					case -5:
						message="对方拒绝任何添加博友请求";
						type = "error";
						break;			
					case -6:
						message="超过博友总数上限限制";
						type = "error";
						break;
					default:
						message="添加失败";
						type = "error";
				}
				this.focusFrame.hiddenWindow();
				dwrlog(message, type);
				if (returnData == -6) {
					this.updateDialog('加为博友',  '<div style="height:90px;line-height:20px;margin-left:-15px;">\
														<div class="g_t_14" style="color:#333">你的博友数已经超过500，你不能主动添加好友，只能接受对方的好友请求。</div>\
														<div style="margin-top:20px;">\
														<INPUT class="btncm btnok" style="width:110px;margin-left:100px;" onclick="' + this.options.objName+　'._gotoFriendEditPage(\'\');return false;" type="button" value="管理我的博友" />\
														<INPUT class="btncm btncc" style="margin-left:30px;" onclick="' + this.options.objName+　'.closeFocusFrame();return false;" type="button" value="取消" />\
													  	</div>\
									   				  </div>');
				}
				else {
					this.changeRelationStatus(relation, 0);
					if(returnData == 5){
						this.changeRelationStatus(1, 1);
						this.updateDialog('加为博友',  '<div style="width:260px;height:90px;line-height:20px;padding:0;margin:0 auto;">\
														<div class="g_t_14" style="padding:0;color:#333">发送邀请成功，您现在已经关注了他。</div>\
														<div class="g_t_14" style="padding:0;color:#333">以后 <a class="g_c_ul" style="color:#005AFF;font-size:15px" href="http://' + 
														DomainMap.getParentDomain(UD.visitorName) + '/manage/" target="_self" class="icn-mng icn-mng-1">博客中心</a> 能收到他动态的更新了。</div>\
														<div style="margin-top:20px;padding:0;text-align:center;">\
														<INPUT class="btncm btncc" onclick="' + this.options.objName+　'.closeFocusFrame();return false;" type="button" value="确 定" />\
													  	</div>\
									   				  </div>');
					}
				}
			  }.bind(this),
			  errorHandler:function(errorString, ex) {
			  //验证码错误提示
			
			  	if (ex == undefined || ex == null ||ex.type == "CaptchaException") {
			  		dwrlog('验证码不正确','error'); 
			  		this.genValidCodeImg();
			  		$('ne_frame_info').style.display='none';
			  		$('ne_frame_submit').style.display=''; 
			  		return ;
			  	}
			  	else {
			  		//if(ex.type=="ExceedFriendsLimit")
			  		//dwrlog('超过博友总数上限限制','error');
				    //this.focusFrame.hiddenWindow();
			  	    //filterWarning(ex, false);
			  	    $('ne_frame_submit').style.display='';
	    			$('ne_frame_info').style.display='none';
	    			$('ne_frame_error').style.display='';
			  	}		  	
			  }.bind(this)
			  
		});
	},
	updateDialog: function(title, content){
		this.focusFrame.updateTitle(title);
		this.focusFrame.panel.innerHTML = content;
		this.focusFrame.showWindow();
	},
	showDenyInvitingDlg: function(){
		this.focusFrame.updateTitle('加为博友');
		var text = '<div style="height:90px;line-height:16px;margin-left:-20px;margin-top:-10px;">\
						<div class="g_t_12" style="color:#333">不好意思，博主谢绝任何人加为博友。</div>\
						<div class="g_t_12" style="color:#333">你关注'+$("follow_status").getAttribute("value")+'，就可以在博客中心里接收'+$("follow_status").getAttribute("value")+'的动态。</div>\
						<div style="margin-top:20px;">';
		if ($("follow_status").getAttribute("isFollow") == "true") {
			text += '<INPUT class="btncm btnok" style="width:90px;margin-left:100px;" onclick="' + this.options.objName+　'.closeFocusFrame();return false;" type="button" value="确定" />';
		}
		else {
			text += '<INPUT class="btncm btnok" style="width:110px;margin-left:35px;" onclick="' + this.options.objName+　'.followNormalUser();'+this.options.objName+'.closeFocusFrame();return false;" type="button" value="关注'+$("follow_status").getAttribute("value")+'" />\
					 <INPUT class="btncm btncc" style="margin-left:25px;width:85px;" onclick="' + this.options.objName+　'.closeFocusFrame();return false;" type="button" value="取消" />';
		}
		text + "</div></div>";
		this.focusFrame.panel.innerHTML = text;
		this.focusFrame.showWindow();
	},
	
	deleteFriend: function(){
		if(UD.visitorRank<0){
			showLoginDlg(this.options.serverName,this._getLoginTarget('fm_9'));
			return;
		}
		if ($("friend_status") && $("friend_status").getAttribute("isFriend") != "true") return;
		if (this.cancelFollowUserWin == null){
			this.cancelFollowUserWin = jsWindowManager.createWindow("_cancelFollowUserTopWinId",{width: 400, height:180,top:200,title:'取消关注', onTop: true, allowDrag:true,needCover:true});			
		}
		this.cancelFollowUserWin.updateTitle('删除博友');
		this.cancelFollowUserWin.panel.innerHTML = '<div style="height:90px;line-height:20px;margin-left:8px;">\
											<div class="g_t_14" style="color:#333">您是否真的要删除该博友？<br><font style="font-size:12px;color:#aaaaaa;">断开博友关系后，你将自动转为对方关注的博客，但是系统不会通知对方。</font></div>\
											<div id="removeFriendDiv" style="margin-top:20px;text-align:center;">\
												<INPUT class="btncm btnok" onclick="' + this.options.objName+　'.removeFriendAction(\'' + UD.visitorId + '\');return false;" type="button" value="确 定" />\
												<INPUT class="btncm btncc" style="margin-left:30px;" onclick="' + this.options.objName+　'.cancelFollowUserWin.hiddenWindow();return false;" type="button" value="取 消" />\
										  	</div>\
										  	<div id="removeFriendInfoDiv" style="margin-top:20px;text-align:center;display:none;">\
										  		<img src="http://b.bst.126.net/style/common/loading.gif" style="vertical-align: middle;border: 0;"/>&nbsp;正在删除博友, 请稍候...\
										  	</div>\
										  	<div id="removeFriendErrorDiv" style="margin-top:20px;text-align:center;display:none;">\
												<img src="http://b.bst.126.net/style/common/ico_error.gif" style="vertical-align: middle;border: 0;"/>&nbsp;删除博友失败, 请刷新重试!\
											</div>\
						   				  </div>';
		this.cancelFollowUserWin.showWindow();
	},
	
	removeFriendAction: function(userId){
		if($("removeFriendDiv")){$("removeFriendDiv").style.display="none";}
		if($("removeFriendInfoDiv")){$("removeFriendInfoDiv").style.display=""; }
		if($("removeFriendErrorDiv")){$("removeFriendErrorDiv").style.display="none"; }
		
		UserBean.removeFriend(userId, UD.hostName == UD.visitorName, {
			callback:function(returnData) {
				if(returnData){
					dwrlog('删除博友成功','ok');
					this.cancelFollowUserWin.hiddenWindow();
					this.changeRelationStatus(2, 0);
					this.changeRelationStatus(0, 1);
				}
				else {
					if($("removeFriendDiv")){$("removeFriendDiv").style.display="";}
					if($("removeFriendInfoDiv")){$("removeFriendInfoDiv").style.display="none"; }
					if($("removeFriendErrorDiv")){$("removeFriendErrorDiv").style.display=""; }
				}
			}.bind(this),
			errorHandler:function(errorString, ex)　{
				if($("removeFriendDiv")){$("removeFriendDiv").style.display="";}
				if($("removeFriendInfoDiv")){$("removeFriendInfoDiv").style.display="none"; }
				if($("removeFriendErrorDiv")){$("removeFriendErrorDiv").style.display=""; }
			}.bind(this)
		});
	},
	
	followNormalUser: function(){
		this.followNormalUserWithCode('');
	},

	followNormalUserWithCode: function(valCode){
		if(UD.visitorRank<0){
			showLoginDlg(this.options.serverName,this._getLoginTarget('fm_10'));
			return;
		}
		UserFollowBean.followUser(UD.hostId, valCode, 
			function(returnData) {
				if(returnData == "success"){
					dwrlog('关注用户成功','ok');
					this.changeRelationStatus(1, 1);
					$("followStatusHint").innerHTML = "<div onmouseover=\"this.parentNode.setAttribute('mouseover', 'yes');\" onmouseout=\"this.parentNode.setAttribute('mouseover', '');\">"
													  + "<span class='n_ n20'>&nbsp;</span>关注成功<p style='margin:0 0;'>以后<a href='http://"
													  + DomainMap.getParentDomain(UD.visitorName) + "/manage/' class='manage_link' target='_blank'>博客中心</a>能收到"
													  + $("follow_status").getAttribute("value") + "的动态更新了。</p></div>";
					$("followStatusHint").style.display = "";
					if ($("profileImageDiv") && $("profileImageDiv").parentNode.parentNode.className.indexOf("g_css_hom_k") > 0) {
						$("profileImageDiv").style.height = "270px";
					}
					this.intervalTimer = setInterval(function(){ this._hideFollowHint(false); }.bind(this), 4000);
				}
				else if(returnData == "maximum"){
					this.focusFrame.updateTitle('加为关注');
					this.focusFrame.panel.innerHTML = '<div style="height:90px;line-height:20px;margin-left:-15px;">\
														<div class="g_t_14" style="color:#333">你已经关注400个博客了，关注量太大会让你忽略某些重要的关注信息。</div>\
														<div style="margin-top:20px;">\
														<INPUT class="btncm btnok" style="width:110px;margin-left:40px;" onclick="' + this.options.objName+　'._gotoFriendEditPage(\'follow\');return false;" type="button" value="管理我的关注" />\
														<INPUT class="btncm btncc" style="margin-left:30px;" onclick="' + this.options.objName+　'.closeFocusFrame();return false;" type="button" value="取消" />\
													  	</div>\
									   				  </div>';
					this.focusFrame.showWindow();
				}
				else if (returnData == "friend") {
					dwrlog('已经是博友','ok');
					this.changeRelationStatus(1, 0);
				}
				else if(returnData == "failure"){
					dwrlog('关注用户失败','error');
				}
				if (returnData == "valCode") {
					this.focusFrame.updateTitle('关注' + $("follow_status").getAttribute("value"));
					this.focusFrame.panel.innerHTML = '<div style="height:90px;line-height:20px;margin:0 -12px 0 0;padding-left:0px;">\
							<div class="g_t_12" style="color:gray;padding-left:0px;margin:0 0 0 10px;">由于您今天已关注较多博客，需要输入验证码方能继续。</div>\
							<div style="color:#333;">\
								<span class="g_t_12">验 证 码：</span>\
								<input id="followValCode" class="g_f_focus g_c_input valid-input" value="" style="margin-left:10px;border:1px solid #DDDDDD;width:70px;" maxlength="4" />\
								<span id="followValCodeSpan" style="display:none;"><span id="followValCodeImg"></span>\
								<a href="#" onclick="' + this.options.objName+　'._genFollowValidCodeImg(false);"style="height:24px;line-height:24px;margin-left:4px;">看不清 换一张</a></span>\
							</div>\
							<div style="margin-top:8px;">\
								<INPUT class="btncm btnok" style="margin-left:65px;" onclick="' + this.options.objName+　'._followNormalUserSubmit();return false;" type="button" value="提 交" />\
								<INPUT class="btncm btncc" style="margin-left:30px;" onclick="' + this.options.objName+　'.closeFocusFrame();return false;" type="button" value="取 消" />\
								<span id="followValCodeError" class="circle_invite_error_img g_t_12" style="color:#333;"></span>\
							</div>\
						</div>';
					var fCodeInput = $('followValCode');
					if (fCodeInput) {
						Event.observe(fCodeInput, "focus", function(){
							this._genFollowValidCodeImg(true);
						}.bind(this));
					}
					this.focusFrame.showWindow();
					if (this.isFromFollowValWin && fCodeInput) {
						fCodeInput.focus();
						showInfo('followValCodeError', "验证码不正确", "info");
						this.isFromFollowValWin = null;
					}
				}
				else {
					this.isFromFollowValWin = null;
				}
			}.bind(this)
		);
	},
	
	_followNormalUserSubmit: function(){
		var value = "";
		var fCodeInput = $('followValCode');
		if (fCodeInput) value = fCodeInput.value;
		if (value == "") {
			fCodeInput.focus();
			showInfo('followValCodeError', "请输入验证码", "info");
		}
		else if (value.length != 4) {
			showInfo('followValCodeError', "验证码为4位", "info");
		}
		else {
			this.isFromFollowValWin = true;
			this.closeFocusFrame();
			this.followNormalUserWithCode(value);
		}
	},
	
	_genFollowValidCodeImg: function(bForce) {
		var codeSpan = $('followValCodeSpan');
		if (codeSpan) codeSpan.style.display = "";
		var divName = "followValCodeImg";
		this._genCommonValidCodeImg(UD.hostId, divName, bForce, "followCaptchaimgId");
	},
	
	_hideFollowHint: function(forceHide){
		var mouseOver = $("followStatusHint").getAttribute("mouseover");
		if (forceHide) {
			$("followStatusHint").setAttribute("mouseover", "");
			mouseOver = "";
		}
		if (mouseOver && mouseOver == "yes") {
			return;
		}
		else {
			clearInterval(this.intervalTimer);
			$("followStatusHint").style.display = "none";
			if ($("profileImageDiv") && $("profileImageDiv").parentNode.parentNode.className.indexOf("g_css_hom_k") > 0) {
				$("profileImageDiv").style.height = "205px";
			}
		}
	},
	
	cancelFollowNormalUser: function(){
		if(UD.visitorRank<0){
			showLoginDlg(this.options.serverName,this._getLoginTarget('fm_11'));
			return;
		}
		if ($("follow_status") && $("follow_status").getAttribute("isFollow") != "true") return;
		if (this.removeNormalFollow == null) {
			this.removeNormalFollow = '<div style="padding: 10px 20px;font-size:12px;">\
											<p style="height:70px;color:#333">您真的要取消关注 ${nickname} ？</p>\
											<p style="text-align: center;" id="btnDiv">\
												<button type="button" class="btncm btnok" onclick="${objectName}.cancelFollowNormalUserAction(${userId}, \'${nickname|js_string}\');">确 定</button>\
												<button type="button" class="btncm btncc" style="margin-left:30px;" onclick="${objectName}.cancelFollowUserWin.hiddenWindow();return false;">取 消</button>\
											</p>\
											<p style="text-align: center; display: none;" id="infoDiv">\
												<img src="http://b.bst.126.net/style/common/loading.gif" style="vertical-align: middle;border: 0;"/>&nbsp;正在取消对 ${nickname} 的关注, 请稍候...\
											</p>\
											<p style="text-align: center;  display: none;" id="errorDiv">\
												<img src="http://b.bst.126.net/style/common/ico_error.gif" style="vertical-align: middle;border: 0;"/>&nbsp;取消对 ${nickname} 的关注失败, 请刷新重试!\
											</p>\
								 		</div>';
		}
		if(jsWindowManager == null){
			jsWindowManager = new NetEase.JSWindowManager();
		}
		if (this.cancelFollowUserWin == null){
			this.cancelFollowUserWin = jsWindowManager.createWindow("$_cancelFollowUserTopWinId",{width: 400, height:180,top:200,title:'取消关注', onTop: true, allowDrag:true,needCover:true});			
		}
		this.cancelFollowUserWin.updateTitle('取消关注');
		this.cancelFollowUserWin.panel.innerHTML = this.removeNormalFollow.process({objectName: this.options.objName, nickname: UD.hostNickname, userId: UD.hostId});
		this.cancelFollowUserWin.showWindow();
	},
	
	cancelFollowNormalUserAction: function(userId, nickName) {
		//show waitinginfo		
		if($("btnDiv")){$("btnDiv").style.display="none";}
		if($("infoDiv")){$("infoDiv").style.display=""; }
		if($("errorDiv")){$("errorDiv").style.display="none";}
		
		UserFollowBean.cancelFollowUser(userId,  
			function(returnData) {
				if(returnData == "success"){
					dwrlog('取消关注成功','ok');
					this.cancelFollowUserWin.hiddenWindow();
					this._hideFollowHint(true);
					this.changeRelationStatus(0, 1);
				}
				else if (returnData == "friend") {
					dwrlog('已经是博友','ok');
					this.cancelFollowUserWin.hiddenWindow();
					this.changeRelationStatus(1, 0);
				}
				else {
					if($("btnDiv")){$("btnDiv").style.display="";}
					if($("infoDiv")){$("infoDiv").style.display="none"; }
					if($("errorDiv")){
						$("errorDiv").style.display="";
					}
				}
			}.bind(this));
	},
	
	/**
	 * 加博友的Action为0,博友等待添加状态为0,添加成功为1,不是博友状态为2,操作失败为-1,
	 * 	
	 * 加关注的Action为1,关注成功为1,取消关注为0,操作失败为-1.
	 */
	changeRelationStatus: function(relation, action) {
		if (!$("friend_status") || !$("follow_status")) return;		
		var marginLeft = !(UD.pageName == "prevBlogPerma");
		if (action == 0) {
			if (relation == 0) {
				if (marginLeft) $("friend_status").innerHTML = '<span class="c09" style="font-size:12px;margin-left:6px;margin-right:2px;">待确认　</span>&nbsp;&nbsp;';
				else $("friend_status").innerHTML = '<span class="c09" style="font-size:12px;margin-right:2px;">待确认　</span>&nbsp;&nbsp;';
			}
			else if (relation == 1) {
				var text = '<span style="position:relative;cursor:default;" onmouseover="pageTopBar.showActionCancelLink(\'action_cancel_friend_link\', true);return false;" onmouseout="pageTopBar.showActionCancelLink(\'action_cancel_friend_link\', false);return false;">' +
							'<span class="c09" style="font-size:12px;';
				if (marginLeft) text += "margin-left:6px;";
				text += ' margin-right:52px;">我们是博友</span>&nbsp;<a id="action_cancel_friend_link" href="#" class="c06" style="display:none;position:absolute;';
				if (marginLeft) text += 'left:67px;"';
				else text += 'left:61px;"';
				text += ' onclick="pageTopBar.deleteFriend();return false;">&lt;取消</a></span>';
				$("friend_status").innerHTML = text;
				$("follow_status").innerHTML = '';
				$("friend_status").setAttribute("isFriend", "true");
				$("follow_status").setAttribute("isFollow", "false");
			}
			else if (relation == 2) {
				$("friend_status").innerHTML = '<span class="n_ m1_1">&nbsp;</span>\
												<a class="c06" style="font-size:12px;text-decoration:underline;margin-left:-8px;" href="#"\
													onclick="pageTopBar.showAddFriend();return false;">加博友</a>&nbsp;&nbsp;';
				$("friend_status").setAttribute("isFriend", "false");
			}
		}
		else if (action == 1){
			var marginLength = "3px";
			var positionLeft = "40px";
			if (!marginLeft) {
				marginLength = "-1px";
				positionLeft = "36px";
			}
			if (relation == 0) {
				$("follow_status").innerHTML = '<span style="padding-left:20px;margin-left:'+marginLength+';font-size:12px;line-height:18px;background:url(http://b.bst.126.net/style/common/blogManage/followplus.png) no-repeat left center;">&nbsp;</span>\
												<a class="c06" style="font-size:12px;text-decoration:underline;margin-left:-12px;white-space:nowrap;" href="#" onclick="pageTopBar.followNormalUser();return false;">关注' + $("follow_status").getAttribute("value") +'</a>&nbsp;&nbsp;';
				$("follow_status").setAttribute("isFollow", "false");
			}
			else if (relation == 1) {
				var text = '<span style="position:relative;cursor:default;" onmouseover="pageTopBar.showActionCancelLink(\'action_cancel_follow_link\', true);return false;" ' +
							'onmouseout="pageTopBar.showActionCancelLink(\'action_cancel_follow_link\', false);return false;">';
				text += '<span class="c09" style="font-size:12px;margin-left:'+marginLength+';white-space:nowrap;padding-right:18px;">已关注</span>&nbsp;' +
						'<a id="action_cancel_follow_link" href="#" class="c06 g_hom_abt_action_bar_can" style="white-space:nowrap;display:none;position:absolute;left:'+positionLeft+';" onclick="pageTopBar.cancelFollowNormalUser();return false;">&lt;取消</a></span>';
				$("follow_status").innerHTML = text;
				$("follow_status").setAttribute("isFollow", "true");
			}
		}
	},
	
	showActionCancelLink: function(actionLink, isShow) {
		if (isShow) {
			$(actionLink).style.display = "";
		}
		else {
			$(actionLink).style.display = "none";
		}
	},
	
	_gotoFriendEditPage: function(part){
		var url = "http://" + DomainMap.getParentDomain(UD.visitorName) + "/friends/edit/";
		if (part != "") {
			url += "?p1=" + part;
		}
		window.location = url;
	},	
	
	showInviteCircle: function(){
//		this._keepShow();
		if(this.focusData['circle'] == null){
			SpaceCircleBean.getUserAdminCircles(this._initInviteCircleHtml.bind(this));
		}else{
			this._initInviteCircleHtml(this.focusData['circle']);
		}
	},
	
	_initInviteCircleHtml: function(dataList){
		if(dataList == null || dataList.length==0){
			dwrlog("你不是圈子管理员","error");
			return;
		}
		this.focusData['circle'] = dataList;
		var valCodeStr = "";
		if (UD.visitorRank < 100) {
			valCodeStr = '<tr><td class="g_w_30 g_t_right">验证码：</td>' +
					'<td><input type="text" class="g_f_focus g_c_input valid-input" value="" style="border:1px solid #DDDDDD;width:50px;" maxlength="4" id="circleInviteValCode" /><span id="circleInviteValSpan"></span><span id="circleInviteValError" class="circle_invite_error_img g_t_12"></span></td></tr>';
			this.circleInviteValCodeInput = 'circleInviteValCode';
			this.circleInviteValCodeError = 'circleInviteValError';
		}
		this.focusFrame.updateTitle('邀请加入圈子');
		this.focusFrame.panel.innerHTML=
           		'<table class="g_c_mvdn" border="0" cellspacing="0" cellpadding="0">\
					   <tr><td class="g_w_30 g_t_right">选择圈子：</td><td><select nohide="true" class="g_w_50" id="ne_circle_id">'+this._getSelectOptionForCircle(this.focusData['circle'])+'</select></td></tr>'
					   + valCodeStr 
					   + '<tr><td colspan="2" class="g_t_center">\
								<div id="ne_frame_submit">\
									<input type="button" class="btncm btnok" value="确　定" onclick="'+this.options.objName+'.submitInviteCircle();return false;"/>\
									<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>\
									<input type="button" class="btncm btncc" value="取　消" onclick="'+this.options.objName+'.closeFocusFrame();return false;"/>\
								</div><div id="ne_frame_info" style="display:none;">处理中...</div>\
						 </td></tr>\
				</table>';
		if (this.circleInviteValCodeInput) {
			var valInputId = $(this.circleInviteValCodeInput);
			if (valInputId) {
			Event.observe(valInputId, "focus", function(){
				this._genInviteValidCodeImg(this._getInviteValidCodeKey(), 'circleInviteValSpan', true);
				}.bind(this));
			}
		}
		this.focusFrame.showWindow();	
	},
	
	_getInviteValidCodeKey: function() {
		return "InviteCircle_" + UD.visitorId + "_" + UD.hostId;
	},
	
	_genInviteValidCodeImg: function(sParentId, sDivName, bForce) {
		this._genCommonValidCodeImg(sParentId, sDivName, bForce, "captchaimg${inviteparentId}");
	},
	
	_genCommonValidCodeImg: function(sParentId, sDivName, bForce, sImgId) {
		var valCodeDiv = $(sDivName);
		if (bForce) {
			if (valCodeDiv != null && valCodeDiv.innerHTML == "") {
				valCodeDiv.innerHTML = 
					'<img title="点击刷新验证码" onclick="this.src=pageTopBar._getInviteCaptchaImgSrc(\''+sParentId+'\')" class="g_t_middle" style="margin-left:5px;" id="' + sImgId + '" alt="验证码" src="' + this._getInviteCaptchaImgSrc(sParentId) + '" />';
			}
		} else {
			if (valCodeDiv != null) {
				valCodeDiv.innerHTML = 
					'<img title="点击刷新验证码" onclick="this.src=pageTopBar._getInviteCaptchaImgSrc(\''+sParentId+'\')" class="g_t_middle" style="margin-left:5px;" id="' + sImgId + '" alt="验证码" src="' + this._getInviteCaptchaImgSrc(sParentId) + '" />';
			}
		}
	},
	
	_getInviteCaptchaImgSrc: function(sParentId) {
		var _iRandom = Math.floor(Math.random()*10001);
		var _sId = (_iRandom+"_"+new Date().getTime()).toString();
		var preUrl = "/cap/captcha.jpgx?parentId=";
		return preUrl + encodeURIComponent(sParentId) + "&" + _sId;
	},
	
	submitInviteCircle: function(){
		var valCode = "";
		if (UD.visitorRank < 100) {
			var result = false;
			if ($(this.circleInviteValCodeInput)) {
				var valInputId = $(this.circleInviteValCodeInput);
				valCode = valInputId.value;
				result = (valCode.length == 4);
			}
			if (!result) {
	    		if ($(this.circleInviteValCodeError) && $(this.circleInviteValCodeInput)) {
	    			if (valCode.length == 0) {
	    				$(this.circleInviteValCodeInput).focus();
	    				showInfo(this.circleInviteValCodeError, "请输入验证码", "info");
	    			}
	    			else {
	    				showInfo(this.circleInviteValCodeError, "验证码为4位", "info");
	    			}
	    		}
	    		return;
	    	}
		}
	    $('ne_frame_submit').style.display='none';
	    $('ne_frame_info').style.display='';
		var circleId = $F('ne_circle_id');
		SpaceCircleBean.sendInvitation(circleId, UD.visitorIP, valCode, {
			  callback:function(returnData) {
			  	if(returnData){
					if (returnData == -1) {
						if ($(this.circleInviteValCodeError)) {
							showInfo(this.circleInviteValCodeError, "验证码不正确", "info");
							this._genInviteValidCodeImg(this._getInviteValidCodeKey(), 'circleInviteValSpan', false);
							$('ne_frame_submit').style.display='';
				    		$('ne_frame_info').style.display='none';
						}
					} else if(returnData == -100) {
						dwrlog("邀请发送过多", "error");
						$('ne_frame_submit').style.display='';
				    	$('ne_frame_info').style.display='none';
					} else if(returnData == -2) {
						dwrlog("邀请失败", "error");
						$('ne_frame_submit').style.display='';
				    	$('ne_frame_info').style.display='none';
					} else {
						dwrlog("邀请发送成功", "ok");				  		
						this.focusFrame.hiddenWindow();
					}
			  	}else{
					dwrlog("邀请发送失败", "error");			  		
				    $('ne_frame_submit').style.display='';
				    $('ne_frame_info').style.display='none';
			  	}
			  }.bind(this),
			  errorHandler:function(errorString, ex) {
				dwrlog("该用户已加入你的圈子",  "error");			  		
				this.focusFrame.hiddenWindow();
			  }.bind(this)
		});
	},
	
	showFocusFrame: function(type){
		if(UD.visitorRank<0){
			var t;
			if(type=='web'){
				t = 'fm_3';
			}else{
				t = 'fm_4';
			}
			showLoginDlg(this.options.serverName,this._getLoginTarget(t));
			return;
		}
		if(this.focusData[type] == null){
			FocusMeBean.getList(type,this._initFocusFrameHtml.bind(this,type));			
		}else{
			this._initFocusFrameHtml(type,this.focusData[type]);
		}
	},
		
	_initFocusFrameHtml: function(type,dataList){
		var name,title;
		if(type == 'web'){
			name='我的收藏';
			title='添加到收藏';
		}else
		if(type == 'rss'){
			name='我的订阅';
			title='RSS订阅博客';
		}
		if(dataList == null || dataList.length == 0){ dwrlog('请先建立一个收藏分类!', 'info');return;}
		this.focusData[type] = dataList;	
		this.focusFrame.updateTitle(title);
		this.focusFrame.panel.innerHTML='<table class="g_c_mvdn" border="0" cellspacing="0" cellpadding="0">\
					<tr><td class="g_w_20 g_t_right" style="padding-left:0!important;padding-left:0;">目　录：</td><td><select nohide="true" class="g_w_90" id="ne_frame_listid">'+this._getSelectOption(this.focusData[type])+'</select></td></tr>\
					<tr><td class="g_w_20 g_t_right" style="padding-left:0!important;padding-left:0;">名　称：</td><td><input class="g_w_90 g_h_ipt" id="ne_frame_name" type="text" maxlength="32" value="'+UD.hostNickname+' 的网易博客"/></td></tr>\
					<tr><td class="g_t_right g_t_top" style="padding-left:0!important;padding-left:0;">描　述：</td><td><input class="g_w_90 g_h_ipt" id="ne_frame_desc" maxlength="60" value=""/></td></tr>\
					<tr><td colspan="2" class="g_t_center">\
							<div id="ne_frame_submit">\
							<input type="button" class="btncm btnok" value="确　定" onclick="'+this.options.objName+'.submitFocusFrame(\''+type+'\');return false;"/>\
							<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>\
							<input type="button" class="btncm btncc" value="取　消" onclick="'+this.options.objName+'.closeFocusFrame();return false;"/>\
							</div><div id="ne_frame_info" style="display:none;">处理中...</div>\
					</td></tr>\
				</table>';
		this.focusFrame.showWindow();		
	},

	submitFocusFrame: function(type){
		if(type == 'web' || type=='rss'){
			var resourceItem= {};
		    resourceItem.title = $F('ne_frame_name').trim();
		    if(resourceItem.title == ''){dwrlog("名称不可以为空!","error");return;}		
		    resourceItem.description = $F('ne_frame_desc').trim();
		    resourceItem.url = 'http://' + DomainMap.getParentDomain(UD.hostName);
		    resourceItem.listId = $F('ne_frame_listid');
		    $('ne_frame_submit').style.display='none';
		    $('ne_frame_info').style.display='';
		    FocusMeBean.collectBlog(resourceItem,type,{
		    	callback:this._afterSubmit.bind(this,type),
		    	errorHandler:function(errorString, ex) {
		    					this.focusFrame.hiddenWindow();
							  	filterWarning(ex, false);
			  				 }.bind(this)
		    });
		}
	},
	
	_afterSubmit: function(type,stat){
		if(stat){
			if(type =='web'){
				dwrlog('收藏博客成功!','ok');
			}else
			if(type =='rss'){
				dwrlog('订阅至博客成功!','ok');
			}
			this.closeFocusFrame();
		}else{
		    $('ne_frame_submit').style.display='';
		    $('ne_frame_info').style.display='none';
			dwrlog('操作失败!','error');
		}				
	},
	
	showAddMail: function(){
		this.focusFrame.updateTitle('邮件订阅更新');
		this.focusFrame.panel.innerHTML=
            '<table class="g_c_mvdn" border="0" cellspacing="0" cellpadding="0">\
			   <tr><td class="g_w_20 g_t_right">邮件地址：</td><td><input class="g_w_50 g_h_ipt" type="text" name="emailAddr" id="emailAddr"/>&nbsp;<select nohide="true" class="g_w_30" name="emailPostfix" id="emailPostfix"><option value="@163.com">@163.com</option><option value="@126.com">@126.com</option><option value="@188.com">@188.com</option><option value="@vip.163.com">@vip.163.com</option></select></td></tr>\
				 <tr><td class="g_w_20 g_t_right">密　　码：</td><td><input class="g_w_50 g_h_ipt" type="password" name="emailPasswd" id="emailPasswd"/></td></tr>\
				 <tr><td colspan="2">\
					 <p class="t g_h_20 g_t_left">更新频率</p>\
					 <p class="t">\
						  <input name="subFrqc" id="FrqcDayly" type="radio" value="" checked="checked"/>&nbsp;<label for="FrqcDayly">每天更新一次</label>&nbsp;\
						  <input name="subFrqc" id="FrqcWeekly" type="radio" value="" />&nbsp;<label for="FrqcWeekly">每周更新一次</label>&nbsp;\
						  <input name="subFrqc" id="FrqcMonthly" type="radio" value="" />&nbsp;<label for="FrqcMonthly">每月更新一次</label>&nbsp;\
						  <input name="subFrqc" id="FrqcImdt" type="radio" value="" />&nbsp;<label for="FrqcImdt">即时更新</label>\
					 </p>\
				 </td></tr>\
				 <tr><td colspan="2" class="g_t_center">\
				 		<div id="ne_frame_submit">\
						<input type="button" class="btncm btnok" value="确　定" onclick="'+this.options.objName+'.submitAddMail();return false;"/>\
						<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>\
						<input type="button" class="btncm btncc" value="取　消" onclick="'+this.options.objName+'.closeFocusFrame();return false;"/>\
						</div><div id="ne_frame_info" style="display:none;">处理中...</div>\
				 </td></tr>\
			</table>';
		this.focusFrame.showWindow();			
	},
	
	submitAddMail: function(){
		var emailAddr = Trim($F('emailAddr')) + $F('emailPostfix');
		if(!checkMail(emailAddr)){
			dwrlog('邮件格式不正确!','error');
			return;	
		}
		var emailPasswd = $F('emailPasswd');
		if(emailAddr.indexOf('@163.com') != -1 || emailAddr.indexOf('@vip.163.com') != -1)
			emailPasswd = hex_md5(emailPasswd);
		var subFrqc = 0;
		if($('FrqcDayly').checked)
			subFrqc = 1;
		else if($('FrqcWeekly').checked)
			subFrqc = 2;	
		else if($('FrqcMonthly').checked)
			subFrqc = 3;	
		else if($('FrqcImdt').checked)
			subFrqc = 0;	
	    $('ne_frame_submit').style.display='none';
	    $('ne_frame_info').style.display='';
		SubscriptionBean.subscribByEmail(emailAddr, emailPasswd, subFrqc, {
		callback:function(returnData) {
			if(returnData){
				dwrlog('您订阅的博客内容将邮件至 '+emailAddr,'ok');
				this.closeFocusFrame();				
			}else{
				dwrlog('订阅出错','error');
		        $('ne_frame_submit').style.display='';
		        $('ne_frame_info').style.display='none';
			}	
		}.bind(this),
	  	errorHandler:function(errorString, ex) {
			if(ex == 'EmailFailed' ){
				dwrlog("验证邮箱密码出错",'error');
			}else if(ex == "AlreaySub"){
				dwrlog("该邮箱已经订阅过该博客",'error');
			}else if(ex == "SubExceed"){
				dwrlog("该邮箱订阅博客数已经超过限制",'error');
			}	
		    $('ne_frame_submit').style.display='';
		    $('ne_frame_info').style.display='none';
			}.bind(this)
		});		
	},
	
	showAddFavorite: function(){
		addFavoriteUtil('http://'+DomainMap.getParentDomain(UD.hostName),UD.hostNickname,UD.hostName);
	},
	//use theme from other people's blog
	shareThisTheme: function(themeId, fromUserId, toUserId, shareThemeId, isUpCurThemeId){
		var nullid = -1;
		var visitiorId = this.options.styleToUserId;
		if(visitiorId == null || visitiorId <= 0){
			showLoginDlg('blog.163.com');
			return false;
		}		
		themeId = (themeId==nullid)?this.options.styleThemeId:themeId;
		fromUserId = (fromUserId==nullid)?this.options.styleFromUserId:fromUserId;
		//toUserId = (toUserId==nullid)?this.options.styleToUserId:toUserId;
		//shareThemeId = (shareThemeId==nullid)?this.options.styleShareThemeId:shareThemeId;
		if(themeId<0){dwrlog("该风格无法被使用!","error");return;}
		if(confirm("您确定要使用这套风格吗？")){
			HomepageSetupBean.copyUserTheme(themeId, fromUserId, function(isSuccess){
				if(!isSuccess){dwrlog("风格使用失败，您可稍后尝试刷新页面后重新操作","error");}
				else{dwrlog("风格使用成功!","ok"); if($('rmdtpcpstl')){$('rmdtpcpstl').onclick=function(){dwrlog("风格使用成功!","ok"); return false;}}}
			});
		}
		return false;
		/*
		if(isUpCurThemeId==null)isUpCurThemeId = true;
		if(themeId<0){dwrlog("该风格无法被分享");return;}
		if(fromUserId == toUserId){dwrlog("您在自己的博客上，无需共享");return;}
		if(UD.visitorRank<0){
			showLoginDlg(this.options.serverName,this._getLoginTarget(isUpCurThemeId?'fm_5':'fm_7'));
			return;
//			dwrlog("您尚未登录，无法共享");return;
		}
		//现在权限应该正常了，开始处理
		HomepageSetupBean.canCopyThisThemeToUser(themeId, shareThemeId, fromUserId, toUserId, function(copyStatus){
			if(copyStatus<0){
				dwrlog("这套风格不能被您使用");return;
			}else if(copyStatus > 0){
				if(!isUpCurThemeId){//收藏，并且已经有过一套
					if(isUpCurThemeIdconfirm("您已收藏过此风格，是否要更新？")){
						HomepageSetupBean.copyUserTheme(themeId, fromUserId, toUserId, shareThemeId, isUpCurThemeId, function(isSuccess){
							if(!isSuccess){dwrlog("收藏未成功，您可稍后尝试刷新页面后重新操作");}
							else{dwrlog("已成功收藏至自定义风格");}
						});
					}
				}else{//使用，虽然有过一套但只需普通提示
					if(confirm(" 确定要使用这套风格吗？")){
						HomepageSetupBean.copyUserTheme(themeId, fromUserId, toUserId, shareThemeId, isUpCurThemeId, function(isSuccess){
							if(!isSuccess){dwrlog("使用未成功，您可稍后尝试刷新页面后重新操作");}
							else{dwrlog("使用成功");}
						});
					}
				}
			}else{//新增一套
				if(confirm(" 确定要"+(isUpCurThemeId?"使用":"收藏")+"这套风格吗？")){
					HomepageSetupBean.copyUserTheme(themeId, fromUserId, toUserId, shareThemeId, isUpCurThemeId, function(isSuccess){
						if(!isSuccess){dwrlog((isUpCurThemeId?"使用":"收藏")+"未成功，您可稍后尝试刷新页面后重新操作");}
						else{dwrlog(isUpCurThemeId?"使用成功":"已成功收藏至自定义风格");}
					});
				}
			}
		});*/
	},
	getThemeID: function(){
		if(typeof this.options == 'undefined' || this.options == null)
			return -1;
		var themeID = this.options.styleThemeId;
		if(this.options.styleShareThemeId >=10000)
			themeID = this.options.styleShareThemeId;
		return themeID;	
	},
	useThisTheme:function(event,themeId,creatorId){
		Event.stop(event||window.event);
		themeId = (themeId<0)? this.getThemeID():themeId;
		creatorId = (creatorId<0)?this.options.styleFromUserId:creatorId;
		var visitiorId = this.options.styleToUserId;
		if(visitiorId == null || visitiorId <= 0){
			showLoginDlg('blog.163.com');
			return false;
		}
		if(confirm('您确认要使用这套风格吗？')){
			HomepageSetupBean.useThisTheme(themeId,creatorId,function(isSuc){
				if(isSuc){dwrlog("使用成功!","ok"); if($('atchtpthmuse')){$('atchtpthmuse').disabled=true;} location.href='http://blog.163.com/'+UD.hostName;}
				else{dwrlog("出错啦[实在不行,重新登录试试哦]……","error"); }
			})
		}
		return false;
	},
	collectThisTheme:function(event,themeId,creatorId){
		Event.stop(event||window.event);
		themeId = (themeId<0)? this.getThemeID():themeId;
		creatorId = (creatorId<0)?this.options.styleFromUserId:creatorId;
		var visitiorId = this.options.styleToUserId;
		if(visitiorId == null || visitiorId <= 0){
			showLoginDlg('blog.163.com');
			return false;
		}
		if(visitiorId == creatorId){alert("自己不能收藏自己的作品哦!"); if($('atchtpstfv')) {$('atchtpstfv').disabled=true;} return false;};
		if(confirm('您确认要收藏这套风格吗？')){
			HomepageSetupBean.collectThisThemeToMyFavourite(themeId,creatorId,function(isSuc){
				if(isSuc){dwrlog('收藏成功!',"ok"); if($('atchtpstfv')){$('atchtpstfv').disabled=true;}}
				else{dwrlog("收藏失败了!","error");}  
			})
		};
		return false;
	},	
	openSingleTheme:function(event,themeId,creatorId){
		Event.stop(event||window.event);
		themeId = (themeId<0)? this.getThemeID():themeId;
		creatorId = (creatorId<0)? this.options.styleFromUserId:creatorId;		
		var url='http://blog.163.com/public/theme/single/?';
		if(themeId<10000){
			url += ("t="+themeId);
		}else{
			url += ("t="+themeId+"&c="+creatorId);
		}
		window.location.href = url;
		return false;
	},
	
	shareOpenModule: function() {
		var _sharedXhtmlUrl = UD.sharedXhtmlUrl;
		if (_sharedXhtmlUrl) {
			OpenModuleBean.createOpenModuleForVisitor(_sharedXhtmlUrl, true,
				function(_widget) {
					if (_widget == null) {
						alert('该开放模块链接非法或已失效，添加失败！');
					} else {
						var _url = 'http://blog.163.com/' + UD.visitorName;
						window.open(_url, '_blank');
					}
				}
			);
			delete UD.sharedXhtmlUrl;
		}
	}
}
var $_isHome = false; 
var $_isBlogCenter = false;
var $_newMsgCount = null;	//记录各种新消息计数
var $_newMsgTotalCount = 0;	//记录新消息的总数
var $_msgLastLoadTime = null; //记录各种消息的最后加载时间
var $_newMailCount = 0;		//记录新邮件数目

/* 登录时取消息接口*/
function getMsgOnLogin(isHome){
	if(isHome)
		$_isHome = true;
	if(UD.visitorRank >=0 && UD.visitorId > 0) {
		MessagePollingBean.getNewMsgCount(UD.visitorId, UD.visitorName, function(oData){
			$("tlbrmsg").onclick = clickNewMsg;
			$("tlbrmsg").onmouseover = mouseOverMsgTop;
			$_newMsgCount = oData;
			$_newMsgTotalCount = oData.userMsgNewCount + oData.comMsgNewCount + oData.comReplyMsgNewCount + oData.alertMsgNewCount;
			var hasNew = false;
			if($_newMsgTotalCount > 0)
				hasNew = true;
			setMsgUI(hasNew, $_newMsgTotalCount);
			window.setInterval(pollingNewMsg, 60000);//开始轮询消息
		});
		RemindBean.getMailCount(UD.visitorId, function(count){
			$_newMailCount = count;
			$('tlbremail_size').innerHTML = $_newMailCount;
			$('tlbremail').title = "未读邮件"+$_newMailCount+"封";
			window.setInterval(pollingNewMail, 300000);//开始轮询新邮件
		});
	}
}

var newMsgZone_jst = '<ul style="padding:0 5px">\
				    <li><span style="cursor:pointer;" onclick="location.href=\'http://blog.163.com/${userName}/message/\';">短消息：</span><a style="color:#005FA1;text-decoration:none;" href="http://blog.163.com/${userName}/message/">${userMsgNew}条新</a></li>\
				    <li><span style="cursor:pointer;" onclick="location.href=\'http://blog.163.com/${userName}/message/?type=com\';">评论：</span><a style="color:#005FA1;text-decoration:none;" href="http://blog.163.com/${userName}/message/?type=com">${comMsgNew}条新</a></li>\
				    <li><span style="cursor:pointer;" onclick="location.href=\'http://blog.163.com/${userName}/message/?type=comReply\';">评论回复：</span><a style="color:#005FA1;text-decoration:none;" href="http://blog.163.com/${userName}/message/?type=comReply">${comReplyMsgNew}条新</a></li>\
				    <li><span style="cursor:pointer;" onclick="location.href=\'http://blog.163.com/${userName}/message/?type=alert\';">通知：</span><a style="color:#005FA1;text-decoration:none;" href="http://blog.163.com/${userName}/message/?type=alert">${alertNew}条新</a></li>\
				  </ul>';

function mouseOutMsgZone(obj, e){
	if (e.currentTarget){   
		if(e.relatedTarget != obj){
			var isSon = false;
			if(!!e.relatedTarget){
				var p = e.relatedTarget.parentNode;
				while(p){
					if(obj == p){
						isSon = true;
						break; 
					}
					p = p.parentNode;
				}
			}
			if(!isSon)   
				obj.style.display = 'none';
		}
	} else {
		if(e.toElement != obj){
			var isSon = false;
			if(!!e.toElement){
				var p = e.toElement.parentNode;
				while(p){
					if(obj == p){
						isSon = true;
						break;
					}
					p = p.parentNode;
				}
			}
			if(!isSon)
				obj.style.display = 'none';
		}
	}	
}

function mouseOverMsgTop(){
	var _left = Position.positionedOffset($('tlbrmsg'));
	var msgZone = $('newMsgCountZone');
	msgZone.style.left = (_left[0]-95)+'px';
	msgZone.innerHTML = newMsgZone_jst.process({userName:UD.visitorName,userMsgNew:$_newMsgCount.userMsgNewCount,
		comMsgNew:$_newMsgCount.comMsgNewCount,comReplyMsgNew:$_newMsgCount.comReplyMsgNewCount,
		alertNew:$_newMsgCount.alertMsgNewCount});
	msgZone.style.display = '';
}

/* 每分钟轮询消息 */
function pollingNewMsg(){
	MessagePollingBean.pollingNewMsg(UD.visitorId, UD.visitorName, function(data){
			var hasNew = data[0];
			if(hasNew){
				$_newMsgCount = data[1];
				$_newMsgTotalCount = $_newMsgCount.userMsgNewCount + $_newMsgCount.comMsgNewCount + $_newMsgCount.comReplyMsgNewCount + $_newMsgCount.alertMsgNewCount;
				setMsgUI(hasNew, $_newMsgTotalCount);
			}
		});
}

/* 每5分钟轮询新邮件 */
function pollingNewMail(userId){
	RemindBean.getMailCount(userId, function(count){
		$_newMailCount = count;
		$('tlbremail_size').innerHTML = $_newMailCount;
		$('tlbremail').title = "未读邮件"+$_newMailCount+"封";
	});
}
/* 刷新新消息提示的总消息数目 */
function refreshNewMsgTotalCount(){
	var count = $_newMsgCount.userMsgNewCount + $_newMsgCount.comMsgNewCount + $_newMsgCount.comReplyMsgNewCount + $_newMsgCount.alertMsgNewCount;
	$("tlbrmsg_size").innerHTML = count;
	if(count == 0)//去掉新消息提醒的小图
		$('eventShowButtonZoneId').style.display = 'none';
}

function setMsgUI(bHasNew, iMsgSize){
	if(bHasNew) {//有新消息到来
		if(iMsgSize >0) {
			//增加未读消息图标
			var _alertZone = $('eventShowButtonZoneId');
			_alertZone.innerHTML = '<span class="g_msg_new" onclick="clickNewMsg();return false;"></span>';
			_alertZone.style.display = 'inline';
		}else{//消息已读
			//去除未读消息图标
			$('eventShowButtonZoneId').style.display = "none";
		}
	}
	//修改未读消息条数
	$("tlbrmsg_size").innerHTML = iMsgSize;
	
	//个人中心/首页的设置
	if($_isHome){
		if(iMsgSize >0){
			$("home_msgSize").innerHTML = iMsgSize;
			$("home_msgWrap").style.display = "inline";
		}else{
			$("home_msgWrap").style.display = "none";
		}
	}
	//博客中心设置
	if($_isBlogCenter && (NEPlatform.BlogCenter.Manage.Utils.showUnreadMessageCount != undefined)){
		NEPlatform.BlogCenter.Manage.Utils.showUnreadMessageCount($_newMsgCount);
	}
}

function clickNewMsg(){
	if ($_newMsgCount == null){
		location.href = 'http://blog.163.com/' + UD.visitorName + '/message/';
	}else{
		var m = Math.max($_newMsgCount.userMsgNewCount,$_newMsgCount.comMsgNewCount,$_newMsgCount.comReplyMsgNewCount,$_newMsgCount.alertMsgNewCount);
		if (m == $_newMsgCount.userMsgNewCount){
			location.href = 'http://blog.163.com/' + UD.visitorName + '/message/';
		}
		else if (m == $_newMsgCount.comMsgNewCount){
			location.href = 'http://blog.163.com/' + UD.visitorName + '/message/?type=com';
		}
		else if (m == $_newMsgCount.comReplyMsgNewCount){
			location.href = 'http://blog.163.com/' + UD.visitorName + '/message/?type=comReply';
		}
		else {
			location.href = 'http://blog.163.com/' + UD.visitorName + '/message/?type=alert';
		}
	}
	//去除未读消息图标
	$('eventShowButtonZoneId').style.display = "none";
	return false;
}
