//表情列表
if (!window.ubbcode)var ubbcode={}

ubbcode.forum_id = 0;

//bbcode转换
ubbcode.bbscode=function(id,noimg,gp_lesser,rvrc,is_signature,tid,pid,aid)
{
var self = this
if (this.regexplock)
	window.setTimeout(function(){self.bbscode(id,noimg,gp_lesser,rvrc,is_signature,tid,pid,aid)},50);
else
	{
	this.regexplock = true;
	this.sRand.seed = this.genRandSeed(tid,pid,aid)
	if (id2e(id)) id2e(id).innerHTML = this.bbscode_core(this.secure_text(id2e(id).innerHTML),noimg,gp_lesser,rvrc,is_signature);
	this.regexplock = false;
	}
}
//fe
ubbcode.bbscode_core=function(c,noimg,gp_lesser,rvrc,is_signature,tid,pid,aid)
{

var self = this
c = c.replace(/\n/g,' ');

c = c.replace(/pallypower\s*\.\s*net/gi,'');
c = c.replace(/sig\.ngacn\.cc/gi,'wowsig.178.com');
c = c.replace(/www\.yxnpc\.com/gi,'');
c = c.replace(/www\.lonlife\.net/gi,'');

c = c.replace(/<br\s*\/?>\s*<br\s*\/?>/i,'<br/><span style="display:none"><br/>[::艾泽拉斯国家地理 BBS.NGACN.CC::]<br/></span><br/>');

var customachievecount = 0
c = c.replace(/\[customachieve\](.+?)\[\/customachieve\]/gi,
function($0,$1)
	{
	if (is_signature && customachievecount)
		return $0;
	customachievecount++;
	var i = $1.match(/\[img\](.+?)\[\/img\]/i);
	var t = $1.match(/\[title\](.{1,40}?)\[\/title\]/i);
	var x = $1.match(/\[txt\](.{1,100}?)\[\/txt\]/i);
	if (!i)
		i={0:0,1:__IMG_STYLE+'/achieve_default.jpg'};
	if (t && x)
		{
		return "<div style='width:512px;height:74px'>\
<div style='width:76px;height:74px;margin:0px 0px -74px 3px;background:#000 url("+i[1]+") 50% 50%'></div>\
<div style='width:512px;height:74px;background:url("+__IMG_STYLE+"/achieve_bg.png);font-size:12px;font-family:Microsoft Yahei, Verdana, Tahoma, Arial, sans-serif;text-align:center;overflow:hidden;color:#000'><div style='width:362px;margin:auto'>\
<h2 style='display:block;font-size:14px;line-height:22px;height:22px;color:#000;margin:0px 0px -23px 0px;padding:1px 1px 0px 0px'>"+t[1]+"</h2>\
<h2 style='display:block;font-size:14px;line-height:22px;height:22px;color:#fff;margin:0px 0px 5px 0px'>"+t[1]+"</h2>"+x[1]+"\
</div></div>\
</div>";
		}
	else
		{
		return $0;
		}
	}
);

c = this.bbscode_common(c,noimg)

c = c.replace(/\[quest\](.+?)\[\/quest\]/gi,function($0,$1){return(commonui.getquest($1))});//[wiki]

c = c.replace(/\[reqpg=\d{1,2}\]/i,'');//[reqpg]

//c = c.replace(/\[qfw\](.+?)\[\/qfw\]/gi,function($0,$1){var id = 'qfw'+Math.floor(Math.random()*10000);window.setTimeout("quotefromwiki_double_get('"+id+"','"+$1+"')",500);if(document.createStyleSheet){document.createStyleSheet('/image/nga_classic/css_wiki.css');var css=''}else{var css="<style type='text/css'>@import '/image/nga_classic/css_wiki.css';</style>"}
//return(css+"<div id='"+id+"' class='qfw'></div>")});

c = c.replace(/\[item(=[0-9]{1,20})?\]([^\[]{1,50})\[\/item\]/gi,function($0,$1,$2){
	if(!$1){
		$1=$2.replace("'",'&#39;').replace('"','&quot;');
		}
	else $1=$1.substr(1);
	$1=$1.replace(/^ | $/,'');
	if (isNaN(parseInt($1,10)))//name
		{
		return "<span class='silver b'>[[</span><span class='urltip silver' style='font-size:11px;padding:2px;text-align:center;line-height:15px'></span><a class='b' href='javascript:void(0)' onclick='wowdb_tooltip.search(this,\""+$1+"\",\"item\");'>"+$1+"</a><span class='silver b'>]]</span>"
		}
	else //id
		{
		return "<span class='silver b'>[</span><a class='b' href='http://db.ngacn.cc/cn/item/"+$1+".html' onmouseover='wowdb_tooltip.delay_get_item(\""+$1+"\");delay_showdscp(event,wowdb_tooltip.tip[\"tip\"],700);' onmousemove='movedscp(event,wowdb_tooltip.tip[\"tip\"])' onmouseout='wowdb_tooltip.clear()' target='_blank'>"+$2+"</a><span class='silver b'>]</span>";
		}
	});//[item]
c = c.replace(/\[wowdb\[([^\]]{2,20})\]\]/gi,function($0,$1){$1=$1.replace(/^ | $/,'');return "<span class='silver b'>[[</span><span class='urltip silver' style='font-size:11px;padding:2px;text-align:center;line-height:15px'></span><a class='b' href='javascript:void(0)' onclick='wowdb_tooltip.search(this,\""+$1+"\");'>"+$1+"</a><span class='silver b'>]]</span>"});//[db]

c = c.replace(/\[url\](bbs|www|db|ngacn)(\..+?)\[\/url\]/gi,function($0,$1,$2){return(self.writelink("http://"+$1+$2,"http://"+$1+$2))});//[url]

c = c.replace(/\[wiki\](.+?)\[\/wiki\]/gi,function($0,$1){return(self.writelink("http://wiki.ngacn.cc/index.php?title="+encodeURI($1),$1,'NGA Encyclopedia'))});//[wiki]
c = c.replace(/\[qfw\](.+?)\[\/qfw\]/gi,function($0,$1){return(self.writelink("http://wiki.ngacn.cc/index.php?title="+encodeURI($1),$1,'NGA Encyclopedia'))});//[wiki]

c = c.replace(/\[MURtopic (\d{1,11}) ?(\d{0,11})\]/i,function($0,$1,$2)
	{
	if(!$2)$2=0;
	var id=Math.random()*1000;
	window.setTimeout(function(){commonui.loadtopic_js($('topiclist'+id),Array('data/bbscache/load_topic_cache/mostuserrecommend_'+$1+'_'+$2+'.js?'+date.getDate()+date.getHours(),'nuke.php?func=loadtopic&f=mostuserrecommend&js=1&fid='+$1+'&day='+$2+'&timeout='+3600*1.1),3600*1.1)});
	return "<div class='topiclist' id='topiclist"+id+"' name='topiclist'></div>"
	});//[MURtopic]


var armory_limit = 5
var armory_count = 0
if (is_signature)
	{
	armory_limit = 1
	if (rvrc<1 && !gp_lesser)
		{
		armory_limit = 0
		}
	}
c = c.replace(/\[(us|cn|tw|eu)armory (.{1,50}?) ([^ ]{1,50}?)\s*\]/gi,function($0,$1,$2,$3){
	++armory_count
	if (armory_count>armory_limit)
		{
		return "<div></div><img src='about:blank' style='display:none' onerror='armory.get(\""+$2+"\",\""+$3+"\",this.previousSibling,\""+$1.toLowerCase()+"\",-1)'/>"
		}
	else
		{
		return "<div style='height:104px'></div><img src='about:blank' style='display:none' onerror='armory.get(\""+$2+"\",\""+$3+"\",this.previousSibling,\""+$1.toLowerCase()+"\")'/>"
		}
	});
	//[armory]

c = c.replace(/p_w_upload/gi,"attachment");//[img]

return c;
}
//fe

ubbcode.getForumid=function()
{
if (!this.forum_id) this.forum_id = id2e('forum_id').value
return (this.forum_id);
}
//fe

var bbscodesmiles = ubbcode.smiles;
function bbscode(id,noimg,gp_lesser,rvrc,is_signature,tid,pid,aid){
ubbcode.bbscode(id,noimg,gp_lesser,rvrc,is_signature,tid,pid,aid)
}//fe
function getForumid(){
return ubbcode.getForumid()
}//fe
function checklink(u,nocookie,tbl){
return ubbcode.checklink(u,nocookie,tbl)
}//fe
writelink = null

//----------------------------------------
//
//
//
//
//
//----------------------------------------

commonui.load_post_s = function(c,noimg,gp_lesser,rvrc,is_signature){
if (!cookieFuncs.getMiscCookie('simplemode'))
	{
	 bbscode_core(c,noimg,gp_lesser,rvrc,is_signature)
	}
}
//fe

commonui.load_post_p = function(p,o){
if (!cookieFuncs.getMiscCookie('simplemode'))
	{
	w_i(p,o)
	}
}
//fe


commonui.getquest = function(id)
{
document.domain = __AJAX_DOMAIN;
return("<span id='questget"+id+"'>loading...<iframe src='http://ngacn.cc/main.php?func=185&sc_cval=,,"+id+"' style='display:none'></iframe></span>")
}
//fe

//----------------------------------------
//
//
//
//
//
//----------------------------------------

wowdb_tooltip = new Object
wowdb_tooltip.tip = new Array;
wowdb_tooltip.icon_path = 'http://wowdb.178.com/icons/m/';
wowdb_tooltip.no_icon = wowdb_tooltip.icon_path+'inv_misc_questionmark.jpg';
wowdb_tooltip.init_tip = function()
{
if (this.tip['tip']) return;
var style = document.createElement('link');
style.href = 'http://wowdb.178.com/css/out.css';
style.rel = 'stylesheet'
style.type = 'text/css';
document.getElementsByTagName('HEAD')[0].appendChild(style);
var style = document.createElement('link');
style.href = 'http://wowdb.178.com/atlas/widget/3.css';
style.rel = 'stylesheet'
style.type = 'text/css';
document.getElementsByTagName('HEAD')[0].appendChild(style);
this.tip = new Array;
this.tip['tip'] = document.createElement('div');
this.tip['tip'].id = 'wowdb_tooltip'
this.tip['tip'].style.position = 'absolute'
this.tip['tip'].style.display = 'none'
document.body.appendChild(this.tip['tip']);
this.tip['tip'].innerHTML = "\
<table border='0' cellpadding='0' cellspacing='0' class='wowdbtooltip'>\
<tr><td class='b3_tl b3s'></td><td class='b3_t'></td><td class='b3_tr b3s'></td><td rowspan=3 class='img'><div class='bg'><img src='"+this.no_icon+"' onerror='this.src=\""+this.no_icon+"\"'/></div></td></tr>\
<tr><td class='b3_l'></td><td class='b3_c ttipcontent s7'></td><td class='b3_r'></td></tr>\
<tr><td class='b3_bl b3s'></td><td class='b3_b'></td><td class='b3_br b3s'></td></tr>\
</table>"

this.tip['content'] = this.tip['tip'].getElementsByTagName('td')[5];
this.tip['icon'] = this.tip['tip'].getElementsByTagName('img')[0];
//this.tip['edit'] =  this.tip['tip'].getElementsByTagName('div')[2];
//this.tip['editlink'] =  this.tip['tip'].getElementsByTagName('a')[0];
}
//fe
wowdb_tooltip.clear = function()
{
this.init_tip()
tTip.hidedscp(null,this.tip['tip'])
window.clearTimeout(this.delay_getting);
this.delay_getting = null;
}
//fe
wowdb_tooltip.delay_get_item = function(i,t,host)
{
var self = this
this.init_tip()
if (this.delay_getting) this.clear();
if (this.tip['content'])
	{
	this.tip['content'].innerHTML="<div class='spacer'>loading ...</div>";
	this.tip['content'].style.width='auto';
	this.tip['content'].style.display=''
	//this.tip['edit'].style.display='none'
	//this.tip['editlink'].style.display='none'
	}
this.delay_getting = window.setTimeout(function(){self.get_item(i,t,host)},1000);
}
//fe
wowdb_tooltip.get_item = function(i,t,host)
{
this.init_tip()
this.tip['content'].innerHTML="<div class='spacer'>loading ...</div>";
this.tip['content'].style.width='auto';
this.tip['icon'].style.display='none';
var self = this
//var d = new Date
if (!isNaN(parseInt(i,10)))
	i={'id':i}
if (!t)
	t = 'item'
if (!host)
	host='cn'

var tooltipstyle='class="tooltip"';

switch (host)
	{
	case 'cn':
		host = 'http://db.178.com/wow/cn'
		break
	case 'tw':
	case 'us':
	case 'eu':
		host = 'http://db.178.com/twwow/tw'
	}

var u = new Array(host+"/a/"+t+"/"+i.id+".js");

if (t == 'item')
	if (parseInt(i.gem0Id,10) || parseInt(i.gem1Id,10) || parseInt(i.gem2Id,10))
		{
		tooltipstyle = 'id="atlasoline_iTTc"'
		var u = new Array("http://www.atlas-o-line.com/tooltip/?item="+i.id+"&enchant=0&gem="+i.gem0Id+","+i.gem1Id+","+i.gem2Id);
		}

httpDataGetter.script_muti_get(u,
	function(x){
		if (!x)
			{
			return false;
			}
		else if (x=='not exists')
			{
			//self.tip['edit'].getElementsByTagName('input')[0].value=i;
			//self.tip['editlink'].style.display='';
			self.tip['content'].innerHTML='无此条目'
			return true
			}
		else
			{
			if (x.icon)
				{
				self.tip['icon'].src=wowdb_tooltip.icon_path+x.icon.toLowerCase()+".jpg"
				self.tip['icon'].style.display='';
				}
			//self.tip['edit'].getElementsByTagName('input')[0].value=x['0']['name'];
			self.tip['content'].innerHTML='<span '+tooltipstyle+'>'+x.tip+'<span>';
			if (self.tip['content'].offsetWidth<300)
				self.tip['content'].style.width='auto';
			else
				self.tip['content'].style.width='300px';
			window.setTimeout(function(){if (self.tip['content'].offsetWidth<300)self.tip['content'].style.width='auto';else self.tip['content'].style.width='300px';},50);
			return true
			}
		},
	function(){
		self.tip['content'].innerHTML='无此条目'},
	'utf-8'
	)

}//fe

wowdb_tooltip.search = function (o,key,type)
{
o = o.previousSibling;
if (o.innerHTML)
	{
	o.style.display='inline';
	return;
	}
if (!hex_md5)
	{
	var s = document.createElement( "script");
	s.src = 'http://img.ngacn.cc/web/res/js_md5.js';
	document.getElementsByTagName("head")[0].appendChild(s);
	}
if (!type)
	{
	type='';
	}
var c=hex_md5(encodeURIComponent(key)+type);
var u = new Array(
	"http://db.ngacn.cc/tips/cache/"+c.substr(0,2)+"/"+c.substr(2,2)+"/"+c+".js",
	"http://db.ngacn.cc/tips/index.php?key="+encodeURIComponent(key)+"&type="+type
	);
httpDataGetter.script_muti_get(u,
		function(x){
			if (!x)
				{
				return false;
				}
			var time = String(x[0]);
			time = time.split(',');
			var d = new Date;
			if (d.getTime/1000-time[0]>3600*24*10)
				{
				return false;
				}
			var i = 0;
			for (var k in x)
				{
				if (k!=0 && x[k])
					{
					if (x[k]=='+')
						{
						o.innerHTML+="<a href='http://db.ngacn.cc/s.php?lang=cn&sitems=on&squests=on&snpcs=on&sobjects=on&sachievements=on&na="+encodeURIComponent(key)+"' target='_blank'>更多...</a><br/>";
						}
					else
						{
						i++;
						var t = '';
						var h = '';
						var name = x[k].name_en;
						var host = 'http://db.178.com/wow/cn'
						if (x[k].name_cn)
							{
							name = x[k].name_cn;
							host = 'http://db.178.com/wow/cn'
							}
						else if (x[k].name_tw)
							{
							name = x[k].name_tw;
							host = 'http://db.178.com/twwow/tw'
							}
						switch (x[k].type)
							{
							case 'item':
								t = 'item';
								h = host+"/"+t+"/"+x[k].id+".html";
								break;
							case 'quest':
								t = 'quest';
								h = host+"/"+t+"/"+x[k].id+".html";
								break;
							case 'npc':
								t = 'npc';
								h = host+"/"+t+"/"+x[k].id+".html";
								break;
							case 'spell':
								t = 'spell';
								h = host+"/"+t+"/"+x[k].id+".html";
								break;
							case 'achieve':
								t = 'achievement';
								h = host+"/"+t+"/"+x[k].id+".html";
								break;
							}
						o.innerHTML+="<a href='"+h+"' onmouseover='wowdb_tooltip.delay_get_item(\""+x[k].id+"\",\""+t+"\",\""+host+"\");delay_showdscp(event,wowdb_tooltip.tip[\"tip\"],700);' onmousemove='movedscp(event,wowdb_tooltip.tip[\"tip\"])' onmouseout='wowdb_tooltip.clear()' target='_blank'>"+name+"</a><span style='font-size:70%' class='gray'>("+x[k].type.toUpperCase()+")</span><br/>";
						}
					}
				}
			if (!i)
				{
				o.innerHTML+="找不到符合的条目<br/>";
				}
			d.setTime(time[0]*1000);
			o.innerHTML+="<span style='font-size:70%' class='gray'>"+d.getFullYear()+'/'+(d.getMonth()+1)+'/'+d.getDate()+' '+d.getHours()+':'+d.getMinutes ()+'</span><br/>';
			if (time[1])
				{
				o.innerHTML+="<span style='font-size:70%' class='gray'>"+time[1]+' SEC</span><br/>';
				}
			o.style.display='inline';
			o.onmouseout = function(e){
				if (!e) var e = window.event;
				var to = (e.relatedTarget) ? e.relatedTarget : e.toElement;
				if (to!=this && to.parentNode!=this && to.parentNode.parentNode!=this)
					{
					this.style.display='none'
					}
			}
			return true;
			},
		function(){
			window.alert='找不到符合的条目';
			},
		'utf-8'
	);
}//fe
//------------------------
if (! window.$atlasolinePower) $atlasolinePower={};
$atlasolinePower.regItem=function(id,name,q,icon,tip){httpDataGetter.script_muti_get_set_costom_value({'id':id,'name':name,'quality':q,'icon':icon,'tip':tip})};

if (! window.$178DB) $178DB = {};
$178DB.regstItem=$178DB.regstQuest=$178DB.regstSpell=$178DB.regstAchievement=$178DB.regstNpc=function(v){httpDataGetter.script_muti_get_set_costom_value(v)};

//----------------------------------------
//
//
//
//
//
//----------------------------------------

commonui.loadmostuserrecommendbyfid = function (x,fid,day,nocache){
commonui.loadtopic_js(x,Array('data/bbscache/load_topic_cache/mostuserrecommend_'+fid+'_'+day+'.js?'+date.getDate()+date.getHours(),'nuke.php?func=loadtopic&js=1&f=mostuserrecommend&fid='+fid+'&day='+day+'&timeout='+3600*2.1),3600*2.1);
}

commonui.loadhotbyfid = function (x,fid,nocache){
commonui.loadtopic_js(x,Array('data/bbscache/load_topic_cache/hot_'+fid+'_.js?'+date.getDate()+date.getHours(),'nuke.php?func=loadtopic&js=1&f=hot&fid='+fid+'&timeout='+3600*2.1),3600*2.1);
}

commonui.loadtodaydelbyfid = function (x,fid,nocache){
commonui.loadtopic_js(x,Array('data/bbscache/load_topic_cache/todaydel_'+fid+'_.js?'+date.getDate()+date.getHours(),'nuke.php?func=loadtopic&js=1&f=todaydel&fid='+fid+'&timeout='+3600*1.1),3600*1.1,false);
}

commonui.loadtopic = function (x,cacheurl,url,nocache,timeout)
{
var self=this;
if(typeof(x)=='string')x=$(x)
if (x.innerHTML=='')
	{
	var onstart = function(){x.innerHTML=='Loading ...'}
	var onsucc = function(y,h){
		if (h)
			{
			h = h.match(/Last-Modified: (.+)/i)
			if (h && h[1])
				{
				if ((date.getTime()-Date.parse(h[1]))>timeout*1000 && !nocache)
					{
					commonui.loadtopicbyfid(x,cacheurl,url,1,timeout)
					return
					}
				}
			}
		y=y.replace(/^<\?php\s*\$write='(.+?)';\s*\?>$/i,'$1').replace(/\\'/g,"'");
		y = y.match(/(<li.+?<\/li>)/g);
		y = y.sort(function(){return Math.random()-0.5});
		var liclass = "class='b1'";
		for (var i=0; i<y.length; i++)
			{
				if (liclass=="class='b1'") liclass = "class='b2'";
				else liclass = "class='b1'";
				y[i] = y[i].replace(/class='b\d'/,liclass)
			}
		y = '<ul>'+y.join('')+'</ul>';
		x.innerHTML=y;
		}
	var onfail = function(){x.innerHTML=='Load error ...'}
	var q = new Array;
	if (!nocache)
		{
		q.push(cacheurl);
		}
	q.push(url);
	httpDataGetter.muti_get(q,onstart,onsucc,onfail);
	}
}

commonui.loadtopic_js = function (x,url,timeout,randomorder,subjectlimit)
{
if (typeof(randomorder)=='undefined') randomorder=true;
if (!subjectlimit) subjectlimit=21;
var self=this;
if(typeof(x)=='string')x=$(x)
if (x.innerHTML=='')
	{
	var date = new Date;
	if(typeof(url)=='string')url = Array(url)
	if(!url[1])timeout=0;
	httpDataGetter.script_muti_get(
		url,
		function(data)
			{
			if (!data)
				{
				return false;
				}
			if (timeout && (__NOW-data.time)>timeout)
				{
				return false;
				}
			var html=new Array;
			var liclass = "class='b1'";
			var hot='';
			var tid=0;
			var title='';
			var d=new Array;
			for (var k in data.data) d.push(data.data[k])
			if (randomorder) d = d.sort(function(){return Math.random()-0.5});
			for (var k=0;k<d.length;k++)
				{
				if (!d[k]) continue;
				if (liclass=="class='b1'") liclass = "class='b2'";
				else liclass = "class='b1'";
				if(d[k].hot)hot=d[k].hot;
				if(d[k].quote_from)tid=d[k].quote_from; else tid=d[k].tid;
				if(d[k].subject.length>21)
					{
					title=d[k].subject;
					d[k].subject=d[k].subject.substr(0,subjectlimit)+'...';
					}
				else title='';
				html.push("<li "+liclass+"><span class='subinfo'>"+hot+" "+commonui.time2shortdate(d[k].postdate)+"</span><a href='/read.php?tid="+tid+"' title='"+title+"'>"+d[k].subject+"</a></li>");
				}
			x.innerHTML='<ul>'+html.join('')+'</ul>';
			return true;
			},
		function()
			{
			x.innerHTML='读取错误';
			},
		'gbk'
		);
	}
}