/**
*@desc     實現根據用戶輸入匹配相似項下拉列表顯示
*@version  phpwnd 8.0 beta
*@date     2010-3-25
*@author   suqian wangmang
*/
//漢字拼音首字母列表
var pw_chinese = " ";
//多音字
var pw_muti={"19969":"DZ","19975":"WM","19988":"QJ","20048":"YL","20056":"SC","20060":"NM","20094":"QG","20127":"QJ","20167":"QC","20193":"YG","20250":"KH","20256":"ZC","20282":"SC","20285":"QJG","20291":"TD","20314":"YD","20340":"NE","20375":"TD","20389":"YJ","20391":"CZ","20415":"PB","20446":"YS","20447":"SQ","20504":"TC","20608":"KG","20854":"QJ","20857":"ZC","20911":"PF","20504":"TC","20608":"KG","20854":"QJ","20857":"ZC","20911":"PF","20985":"AW","21032":"PB","21048":"XQ","21049":"SC","21089":"YS","21119":"JC","21242":"SB","21273":"SC","21305":"YP","21306":"QO","21330":"ZC","21333":"SDC","21345":"QK","21378":"CA","21397":"SC","21414":"XS","21442":"SC","21477":"JG","21480":"TD","21484":"ZS","21494":"YX","21505":"YX","21512":"HG","21523":"XH","21537":"PB","21542":"PF","21549":"KH","21571":"E","21574":"DA","21588":"TD","21589":"O","21618":"ZC","21621":"KHA","21632":"ZJ","21654":"KG","21679":"LKG","21683":"KH","21710":"A","21719":"YH","21734":"WOE","21769":"A","21780":"WN","21804":"XH","21834":"A","21899":"ZD","21903":"RN","21908":"WO","21939":"ZC","21956":"SA","21964":"YA","21970":"TD","22003":"A","22031":"JG","22040":"XS","22060":"ZC","22066":"ZC","22079":"MH","22129":"XJ","22179":"XA","22237":"NJ","22244":"TD","22280":"JQ","22300":"YH","22313":"XW","22331":"YQ","22343":"YJ","22351":"PH","22395":"DC","22412":"TD","22484":"PB","22500":"PB","22534":"ZD","22549":"DH","22561":"PB","22612":"TD","22771":"KQ","22831":"HB","22841":"JG","22855":"QJ","22865":"XQ","23013":"ML","23081":"WM","23487":"SX","23558":"QJ","23561":"YW","23586":"YW","23614":"YW","23615":"SN","23631":"PB","23646":"ZS","23663":"ZT","23673":"YG","23762":"TD","23769":"ZS","23780":"QJ","23884":"QK","24055":"XH","24113":"DC","24162":"ZC","24191":"GA","24273":"QJ","24324":"NL","24377":"TD","24378":"QJ","24439":"PF","24554":"ZS","24683":"TD","24694":"WE","24733":"LK","24925":"TN","25094":"ZG","25100":"XQ","25103":"XH","25153":"PB","25170":"PB","25179":"KG","25203":"PB","25240":"ZS","25282":"FB","25303":"NA","25324":"KG","25341":"ZY","25373":"WZ","25375":"XJ","25384":"A","25457":"A","25528":"SD","25530":"SC","25552":"TD","25774":"ZC","25874":"ZC","26044":"YW","26080":"WM","26292":"PB","26333":"PB","26355":"ZY","26366":"CZ","26397":"ZC","26399":"QJ","26415":"ZS","26451":"SB","26526":"ZC","26552":"JG","26561":"TD","26588":"JG","26597":"CZ","26629":"ZS","26638":"YL","26646":"XQ","26653":"KG","26657":"XJ","26727":"HG","26894":"ZC","26937":"ZS","26946":"ZC","26999":"KJ","27099":"KJ","27449":"YQ","27481":"XS","27542":"ZS","27663":"ZS","27748":"TS","27784":"SC","27788":"ZD","27795":"TD","27812":"O","27850":"PB","27852":"MB","27895":"SL","27898":"PL","27973":"QJ","27981":"KH","27986":"HX","27994":"XJ","28044":"YC","28065":"WG","28177":"SM","28267":"QJ","28291":"KH","28337":"ZQ","28463":"TL","28548":"DC","28601":"TD","28689":"PB","28805":"JG","28820":"QG","28846":"PB","28952":"TD","28975":"ZC","29100":"A","29325":"QJ","29575":"SL","29602":"FB","30010":"TD","30044":"CX","30058":"PF","30091":"YSP","30111":"YN","30229":"XJ","30427":"SC","30465":"SX","30631":"YQ","30655":"QJ","30684":"QJG","30707":"SD","30729":"XH","30796":"LG","30917":"PB","31074":"NM","31085":"JZ","31109":"SC","31181":"ZC","31192":"MLB","31293":"JQ","31400":"YX","31584":"YJ","31896":"ZN","31909":"ZY","31995":"XJ","32321":"PF","32327":"ZY","32418":"HG","32420":"XQ","32421":"HG","32438":"LG","32473":"GJ","32488":"TD","32521":"QJ","32527":"PB","32562":"ZSQ","32564":"JZ","32735":"ZD","32793":"PB","33071":"PF","33098":"XL","33100":"YA","33152":"PB","33261":"CX","33324":"BP","33333":"TD","33406":"YA","33426":"WM","33432":"PB","33445":"JG","33486":"ZN","33493":"TS","33507":"QJ","33540":"QJ","33544":"ZC","33564":"XQ","33617":"YT","33632":"QJ","33636":"XH","33637":"YX","33694":"WG","33705":"PF","33728":"YW","33882":"SR","34067":"WM","34074":"YW","34121":"QJ","34255":"ZC","34259":"XL","34425":"JH","34430":"XH","34485":"KH","34503":"YS","34532":"HG","34552":"XS","34558":"YE","34593":"ZL","34660":"YQ","34892":"XH","34928":"SC","34999":"QJ","35048":"PB","35059":"SC","35098":"ZC","35203":"TQ","35265":"JX","35299":"JX","35782":"SZ","35828":"YS","35830":"E","35843":"TD","35895":"YG","35977":"MH","36158":"JG","36228":"QJ","36426":"XQ","36466":"DC","36710":"JC","36711":"ZYG","36767":"PB","36866":"SK","36951":"YW","37034":"YX","37063":"XH","37218":"ZC","37325":"ZC","38063":"PB","38079":"TD","38085":"QY","38107":"DC","38116":"TD","38123":"YD","38224":"HG","38241":"XTC","38271":"ZC","38415":"YE","38426":"KH","38461":"YD","38463":"AE","38466":"PB","38477":"XJ","38518":"YT","38551":"WK","38585":"ZC","38704":"XS","38739":"LJ","38761":"GJ","38808":"SQ","39048":"JG","39049":"XJ","39052":"HG","39076":"CZ","39271":"XT","39534":"TD","39552":"TD","39584":"PB","39647":"SB","39730":"LG","39748":"TPB","40109":"ZQ","40479":"ND","40516":"HG","40536":"HG","40583":"QJ","40765":"YQ","40784":"QJ","40840":"YK","40863":"QJG"};
function pw_search(dstId,view,selectView,prefix){
	var nav = navigator.userAgent.toLowerCase();
	this.dstId = dstId;
	this.dst = null;
	this.itemIndex = -1;
	this.resultDiv = null;
	this.itemPrefix = prefix?prefix:'resultItem';
	this.view = view?view:'viewName';
	this.selectView = selectView?selectView:'viewNameSelected';
	this.result = new Array();
	this.height = 18;
	this.scrollHeight = null;
	this.browser = nav.indexOf('msie') != -1?nav.indexOf('opera') == -1?'ie':'opera':navigator.product == 'Gecko'?'gecko':'';
	this.selDiv;
	this.separater = '#%';
	this.type=null;//調用的類型,目前為了消息中心做加,post 表示發帖，有title
	this.callback=null;
}
//緩存數據，避免過多操作數據庫
pw_search.cached = new Array();
pw_search.friend = new Array();
pw_search.attention = new Array();
pw_search.hasData=false;
pw_search.inArray=function( elem, array ) {
	if ( array.indexOf ) {
		return array.indexOf( elem );
	}
	for ( var i = 0, length = array.length; i < length; i++ ) {
		if ( array[ i ] === elem ) {
			return i;
		}
	}
	return -1;
};
pw_search.prototype = {
	move:function(eArgs){
		
		 var e = eArgs ? eArgs : window.event;
		 if( (e.keyCode==39 || e.keyCode==37) && this.dst.value==''){
				var node = (e.keyCode==37)?this.dst.previousSibling:this.dst.nextSibling;
				if(node && node.tagName=='SPAN'){
					var _dst = this.dst;
					if(is_ie){
						this.dst.swapNode(node);
					}else{
						if(e.keyCode==37)
							this.dst.parentNode.insertBefore(this.dst,node);
						else
							this.dst.parentNode.insertBefore(node,this.dst);
					}
					setTimeout(function(){_dst.focus();},100);					
				}
		}else if (e.keyCode == 40 || e.keyCode == 38) {
			if (this.result.length < 1){
				return;
			}else{
				var obj = null;
				if (e.keyCode == 40){
					if ((this.itemIndex+1) >= this.result.length){
					    obj = this.$(this.itemPrefix+"0");
						this.focusRow(obj,0);
					}else{
						obj = this.$(this.itemPrefix+(this.itemIndex+1));
						this.focusRow(obj,(this.itemIndex+1));
					}
				}
				if (e.keyCode == 38){
					if (this.itemIndex <= 0){
						obj = this.$(this.itemPrefix+(this.result.length - 1));
						this.focusRow(obj,(this.result.length - 1));
					}else{
						obj = this.$(this.itemPrefix+(this.itemIndex-1));
						this.focusRow(obj,(this.itemIndex-1));
					}
				}
				var divLocalHeight = this.itemIndex*this.height;
				var divisor = parseInt(divLocalHeight / this.scrollHeight);
				if(divLocalHeight > this.scrollHeight && divisor >= 1){
					this.resultDiv.scrollTop = divisor*this.scrollHeight+16.5;
				}else{
					this.resultDiv.scrollTop = 0;
				}
				this.dst.value = obj.innerHTML;
			}
		}else if(e.keyCode==8&&this.dst.value==''){
			var prev = this.dst.previousSibling;
			prev&&prev.tagName=='SPAN' && this.dst.parentNode.removeChild(prev);
			this.updateNum();
		}else if(this.dst.value!='' && (e.keyCode==188||e.keyCode==32||e.keyCode==13)){
				if(is_ie){
						e.returnValue=false;
					}else{
						e.preventDefault();
				}
				var str=this.dst.value;
				if(str==""||(pw_search.inArray(str,pw_search.cached)<0&&this.type=="post")){
					return false;
				}
				if(this.itemIndex>=0)
					return;
				var _psearch = this;
				setTimeout(function(){
					var str=_psearch.dst.value.replace(/[,\s]/ig,'');
					if(pw_search.inArray(str,pw_search.cached)<0&&_psearch.type=="post"){
						return false;
					}
					_psearch.add(str);
				},100);
				
		}else if(this.dst.value==""&&e.keyCode==13){
			if(is_ie){
						e.returnValue=false;
					}else{
						e.preventDefault();
					}
			return false;
		}
		
	},
	init:function(url,data,resultId,callback,initcb){//initcb 初始化數據後的回調用 可見編輯帖子
		if(callback){
			this.callback=callback;
		}
		this.createResultDiv(resultId);
		_obj = this;
		if(!pw_search.hasData){
			ajax.send(url,data,function(){
				var str = ajax.request.responseText.toString();
				var json = JSONParse(str);

				pw_search.friend = json.friend?json.friend.split(_obj.separater):[];
				pw_search.attention = json.attention?json.attention.split(_obj.separater):[];
				pw_search.cached = pw_search.attention;
				//pw_search.cached = json.friend?json.friend.split(_obj.separater):[];
				//pw_search.group = json.group?json.group.split(_obj.separater):[];

				pw_search.hasData=true;
				if(initcb){
					initcb(_obj);
				}
			});
		}
	},
	searchResult:function(e,height){
		var e = e?e:window.event;
		if(e.keyCode == 40 || e.keyCode == 38) {
			return false;
		}
		if(e.keyCode==13 && this.result.length && pw_search.cached.length){
			
			if(this.itemIndex>-1){
				this.resultDiv.getElementsByTagName('li')[this.itemIndex].onmousedown();
				if(is_ie){
					e.returnValue=false;
				}else{
					e.preventDefault();
				}
				return false;
			}
		}
		this.fliter(this.dst.value);
		if((e.keyCode == 13 || e.ctrlKey || e.artKey) || pw_search.cached.length == 0  || this.result.length == 0){			
			this.resultDiv.style.display = 'none';
			document.onclick=null;
			return false;	
		}
		this.resultDiv.style.display = 'none';
		this.resultDiv.innerHTML = '';
		_obj = this;
		var ul = document.createElement('ul');
		for(i=0;i<this.result.length;i++){		
			var resultItem = "<li id='"+(this.itemPrefix+i)+"'  onmouseover='_obj.focusRow(this,"+i+")'       onmousedown='_obj.putValue(this,"+i+")' class='"+this.view+"'>"+this.result[i]+"</li>";
			ul.innerHTML += resultItem;
		}
		this.resultDiv.appendChild(ul);
		this.resultDiv.style.top=this.dst.getBoundingClientRect().top+20+ietruebody().scrollTop+'px';
		this.resultDiv.style.left=this.dst.getBoundingClientRect().left+ietruebody().scrollLeft+'px';
		this.resultDiv.style.display = '';
		document.onclick=function(){
			pwSearch.resultDiv.style.display='none';
			document.onclick=null;
		};
		
	},
	focusRow:function(obj,index){
		var ul = this.resultDiv.getElementsByTagName('ul')[0];
		for(i=0;i<ul.childNodes.length;i++) {
			ul.childNodes[i].className = this.view;
		}
		obj.className = this.selectView;
		this.itemIndex = index;
	},
	createResultDiv:function(id){
		this.dst = this.$(this.dstId);
		this.resultDiv = this.$(id);
		if(!this.resultDiv){
			this.resultDiv = document.createElement('div');
			this.resultDiv.style.display='none';
			this.resultDiv.style.zIndex = '20';
			this.resultDiv.className='friListB';
			this.resultDiv.id=id;
			this.resultDiv.innerHTML='<ul></ul>';
			document.body.appendChild(this.resultDiv);
		}
	},
	createSelDiv:function(win){
		this.selDiv=document.createElement('div');
		this.selDiv.id=win;
		this.selDiv.innerHTML='<table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td class="bgcorner1"></td><td class="pobg1"></td><td class="bgcorner2"></td></tr><tr><td class="pobg4"></td><td><div class="popoutContent"><div class="popTop tar"><select name="" class="fn"><option value="-1">我關注的</option><option value="-2">我的好友</option></select></div><div class="friListA"><ul></ul></div><div class="popBottom"><span class="btn2" onclick="pwSearch.closeSel()"><span><button>確認</button></span></span></div></div></td><td class="pobg2"></td></tr><tr><td class="bgcorner4"></td><td class="pobg3"></td><td class="bgcorner3"></td></tr></tbody></table>';
		this.selDiv.style.display='none';
		this.selDiv.style.position="absolute";
		this.selDiv.className='popout';
		this.selDiv.onclick = function(e){
			if (window.event) //停止事件冒泡
				window.event.cancelBubble = true;
			else
				e.stopPropagation();
		};
		document.body.appendChild(this.selDiv);
	},
	$:function(id){
		return document.getElementById(id);
	},
	fliter:function(prefix){
		this.result = new Array();
		if(prefix=='')
			return;
		var regExp = new RegExp('^'+prefix);
		for(var i=0; i<pw_search.cached.length; i++){
			if(regExp.test(pw_search.cached[i])){
				this.result.push(pw_search.cached[i]);
				continue;
			}
			if(prefix.length == 1){
				var index = this.getIndex(pw_search.cached[i]);
				if((index.length == 1 && index == prefix.toLowerCase()) || (index.length == 2 && (prefix.toLowerCase() == index.substr(0,1) || prefix == index.substr(1,1))) ){
					this.result.push(pw_search.cached[i]);
				}
			}
		}
	},
	putValue:function(obj){
		clearTimeout(this.timer);
		var str=obj.innerHTML;
		if(pw_search.inArray(str,pw_search.cached)<0){
			return false;
		}
		this.add(str);
		this.resultDiv.style.display = 'none';
		this.itemIndex=-1;
		this.dst.focus();
	},
	getIndex:function(chinese){
		if(typeof(chinese) != "string")
			return false;
		var arrResult = new Array();
		for(var i=0;i<chinese.length;i++){		
			arrResult.push(this.checkChRange(chinese.charAt(i)));
		}	
		var returnResult = arrResult[0].length ==1? arrResult[0]:arrResult[0];
		return returnResult.toLowerCase();
	},
	checkChRange:function(ch){
		var code = ch.charCodeAt(0);
		if(code > 40869 || code < 19968){
			return ch; 
		}
		return (pw_muti[code]?pw_muti[code]:(pw_chinese.charAt(code-19968)));
	},
	del:function(eArgs){
		var e;
		if (is_ie) {
			e = event.srcElement;
	    } else {
	    	e = eArgs.target;
	    }
		//var e = eArgs ? eArgs : window.event;
		var item = e.parentNode.parentNode.parentNode;
		item.parentNode.removeChild(item);
		this.updateNum();
	},
	add:function(str){
		var tmpObj = document.getElementsByName('_'+this.dst.name+'[]');
		var tmpArray = new Array();
		if(tmpObj){
			for(var i =0;i<tmpObj.length;i++){
				tmpArray[i] = tmpObj[i].value;
			}
		}
		str = str.replace(/\s/ig,'');
		if(str=='')
			return;
		var len=this.dst.parentNode.getElementsByTagName('span').length;
		var max=this.dst.getAttribute('max');
		var isUnlimit=!(max==""||max==0);//限制人數的情況下
		if(isUnlimit&&len>=max){
			if (this.dst.getAttribute('issearch') != 1) {
				MC.showFailTips('最多只能同時發送'+this.dst.getAttribute('max')+'人').fadeTips();
				return;
			}
			MC.showFailTips('最多只能同時搜索'+this.dst.getAttribute('max')+'人的消息').fadeTips();
			return;
		}
		if(!tmpArray.length || (tmpArray.length && pw_search.inArray(str,tmpArray) < 0)){
			var item = document.createElement('span');
			item.innerHTML='<a href="javascript:void(0)" onclick="return false;"><i>'+str+'<input type="hidden" name="_'+this.dst.name+'[]" id="_'+this.dst.name+'[]" value="'+str+'"><del class="x">刪除</del></i></a>';
			var self=this;
			item.getElementsByTagName('del')[0].onclick=function(e){
				self.del(e);
				return false;
			}
			this.dst.parentNode.insertBefore(item, this.dst);
			this.updateNum();
		}else if(pw_search.inArray(str,tmpArray)>=0){
			MC.showFailTips('用戶名為'+str+'的已經在收件人列表中').fadeTips();
		}
		this.dst.value = '';
		
		return false;
	},
	//插件︰列出列表
	selectInit:function(e,win,url,data,offset,callback){
		if(callback){
			this.callback=callback;
		}
		if (window.event) //停止事件冒泡
			window.event.cancelBubble = true;
		else
			e.stopPropagation();
		this.dst = this.$(this.dstId);
		//設置按鈕樣式
		var btn = this.dst.parentNode.previousSibling;
		while(btn&&btn.nodeType!=1)
		{
			btn = btn.previousSibling;
		}
		if(btn.className=="input_up")//關閉
		{
			this.selDiv.style.display='none';
			btn.className='input_down';
			return;
		}
		if(!this.selDiv){//如果沒有打開過
			this.createSelDiv(win);
			offset=offset||0;
			var select = this.selDiv.getElementsByTagName('select')[0];
			//為@彈窗添加標題
			if(this.type=="post"){
				var title=document.createElement("div");
				title.style.cssText="text-align:left;font-size:12px;font-weight:normal;float:left;";
				select.style.margin="0";
				if(select.style.cssFloat!=undefined){
					select.style.cssFloat="right";	
				}else{
					select.style.styleFloat="right";
				}
				title.innerHTML="已選<span id='pwSearchPercent'>0</span>人";
				select.parentNode.insertBefore(title,select);
			}
			//end
			var _obj=this;
			
			//設置select
			select.onchange=function(){
				var val = select.value;
				if(val<0){
					if (val == -1){
						pw_search.cached = _obj.sel_list = pw_search.attention;
					} else if(val == -2){
						pw_search.cached = _obj.sel_list = pw_search.friend;
					}
					_obj.showFriends();
					_obj.selectFriends();
				}else
					ajax.send(url,data+'&gname='+val,function(){
						var str = ajax.request.responseText.toString();
						_obj.sel_list = str?str.split(_obj.separater):[];
						_obj.showFriends();
						_obj.selectFriends();
					});
			};
			//如果還沒下載數據
			if(!pw_search.hasData){
				ajax.send(url,data,function(){
					var str = ajax.request.responseText.toString();
					var json = JSONParse(str);
					
					//pw_search.cached = json.friend?json.friend.split(_obj.separater):[];
					//pw_search.group = json.group?json.group.split(_obj.separater):[];
					pw_search.friend = json.friend?json.friend.split(_obj.separater):[];
					pw_search.attention = json.attention?json.attention.split(_obj.separater):[];
					pw_search.cached = pw_search.attention;
					pw_search.hasData=true;
					_obj.sel_list = pw_search.cached;
					_obj.showFriends();
					_obj.getGroup();
				});
			}else{
				this.sel_list = pw_search.cached;
				this.showFriends();
				this.getGroup();
			}
		}
		this.selectFriends();
		//顯示窗口
		this.selDiv.style.display='';
		
		
		//更新彈窗位置  qianshan07-06
		var ele=btn;
        var dd = document.documentElement;
        var db = document.body;
        var stop = dd.scrollTop + db.scrollTop
        var sleft = dd.scrollLeft + db.scrollLeft;
        var cw = dd.clientWidth;
        var ch = dd.clientHeight;
        var bound = ele.getBoundingClientRect();
        var left = bound.left;
        var top = bound.top;
        var h = ele.offsetHeight;
        var w = ele.offsetWidth;
        var oh = this.selDiv.offsetHeight;
        var ow = this.selDiv.offsetWidth;
        this.selDiv.style.left = (left + ow) > cw ? (sleft + left + w - ow + "px") : (sleft + left-ow+18 + "px");
        this.selDiv.style.top = (top + oh + h) > ch ? (stop + top - oh-5 + "px") : (stop + top + h+4 + "px");
		//=============
		this.selDiv.style.zIndex = '1110';
		btn.className="input_up";
		document.onclick=function(){
			pwSearch.closeSel();
		};
		this.updateNum();
	},
	getGroup:function(){
		if(!pw_search.group){
			return false;
		}
		var select = this.selDiv.getElementsByTagName('select')[0];
		for(var i=pw_search.group.length-1;i>=0;i--){
			select.options.add( new Option(pw_search.group[i], pw_search.group[i]) ); 
		}
	},
	setFriends:function(e){//選擇好友
		var target;
		if (is_ie) {
			target = event.srcElement;
	    } else {
	    	target = e.target;
	    }
		//var e=e||event,input;
		//var target=e.srcElement;
		var len=this.dst.parentNode.getElementsByTagName('span').length;
		var max=this.dst.getAttribute('max');
		var isUnlimit=!(max==""||max==0);
		if(target.tagName!='INPUT'){
			input=target.getElementsByTagName('input')[0];
			if(!input.checked &&isUnlimit&&len>=max) {
				//this.closeSel();
				return;
			}
			input.checked=!input.checked;
		}else{
			input=target;
			if(input.checked&&isUnlimit&&len>=max){
				input.checked=!input.checked;
				//this.closeSel();
				return;
			}
		}
		input.parentNode.className=input.checked?'selected':'';
		if(!input.checked){//刪除
			var dataNodes = this.dst.parentNode.getElementsByTagName('i');
			for (var i=dataNodes.length-1; i>=0; i--){
				if(input.value==dataNodes[i].firstChild.nodeValue){
					var d=dataNodes[i].parentNode.parentNode;
					d.parentNode.removeChild(d);
				}
			}
		}else{
			var str=input.value;
			if(pw_search.inArray(str,pw_search.cached)<0){
				return false;
			}
			
			if (isUnlimit&&len>=max) {
				this.closeSel();
			}
			this.add(str);
			this.dst.focus();
		}
		this.updateNum();
	},
	updateNum:function(){
		
		//獲取已選擇數目帶給回調函數
		var eles=document.getElementsByName('_'+this.dst.name+'[]');
		var len=eles&&eles.length||0;
			if(this.callback!=null){
				this.callback(len);
			}
		//更新選擇人數
		var max=this.dst.getAttribute("max");
		var isUnlimit=!(max==""||max==0);//限制人數的情況下
		var percentEle=getObj("pwSearchPercent");
		if(percentEle){
			percentEle.innerHTML=isUnlimit?(len+"/"+max):len;
			if(len==max&&isUnlimit){
				percentEle.style.color="#f00";
			}else{
				percentEle.style.color="#080";
			}
		}
			
	},
	showFriends:function(){//顯示列表
		var ds = this.sel_list||[];
		var ul = this.selDiv.getElementsByTagName('ul')[0];
		if(!ul) return;
		str='';
		_obj = this;
		//判斷是否選中
		if(ds.toString().replace(/^\s*$/,'') == ''){
			str = '<li style="width:auto;height:auto;float:none;margin-top:60px;" class="tac f15">暫無好友，<a target="_blank" href="u.php?a=friend&type=find"><span style="color:#228B22">尋找我的好友</span></a></li>';
		}else{
			for (var i=ds.length-1; i>=0; i--){
				str+='<li onclick="_obj.setFriends(event)"><input type="checkbox" value="'+ds[i]+'" />'+ds[i]+'</li>';
			}
		}
		ul.innerHTML=str;
	},
	selectFriends:function(){
		var ds = this.sel_list||[];
		//收集
		var mdata = [];
		var dataNodes = this.dst.parentNode.getElementsByTagName('i');
		for (var i=dataNodes.length-1;i>=0;i--){
			mdata.push(dataNodes[i].firstChild.nodeValue);
		}
		var inputs = this.selDiv.getElementsByTagName('ul')[0].getElementsByTagName('input');
			if(!inputs) return;
		_obj = this;
		//判斷是否選中
		for (var i=0;i<ds.length; i++){
			if (typeof(inputs[i]) == 'undefined') continue;
			if(pw_search.inArray(inputs[i].value,mdata)>-1){
				inputs[i].checked="checked";
				inputs[i].parentNode.className = 'selected';
			}else{
				inputs[i].checked="";
				inputs[i].parentNode.className = '';
			}
		}
	},
	blur:function(){
		/*if(this.resultDiv && this.resultDiv.style.display!='none')
			return;*/	
		/*針對快速回復所做的擴展*/	
		var eles=document.getElementsByName('_'+this.dst.name+'[]');	
		if(eles.length<1&&this.dst.value.replace(/\s*/g,"")==""&&getObj("at_input_tip")){
			getObj("at_input_tip").style.display="";
		}	
		/*end*/
		var str=pwSearch.dst.value;
		if(this.type=="post"&&pw_search.inArray(str,pw_search.cached)<0){
			return false;
		}	
		this.timer = setTimeout('pwSearch.add("'+str+'")',15);
		
	},
	closeSel:function(){
		this.selDiv.style.display='none';
		var btn = this.dst.parentNode.previousSibling;
		while(btn&&btn.nodeType!=1)
		{
			btn = btn.previousSibling;
		}
		btn.className="input_down";
		document.onclick=null;
		if(getObj("showAt")){
			getObj("showAt").style.display="none";
		}
	},
	clear:function(){
		if(!this.dst){
			return false;
		}
		var tmpObj = this.dst.parentNode;
		var spans=tmpObj.getElementsByTagName("span");
		for(var i=0,len=spans.length;i<len;i++){
			var item=tmpObj.firstChild;
			tmpObj.removeChild(item)
		}
		this.updateNum();
	}
}
var pwSearch = new pw_search('usernames');