var badwords='';

function UBBcode(temp) {
	if (badwords!=''){    //过滤敏感字
		var badword= badwords.split ('|'); 
		for(i=0;i<badword.length;i=i+1) {
			if (badword[i] !=''){temp = temp.replace(badword[i],'****');}
		}
	}

	if (getCookie('UBBcode')!='0'){ //是否打开UBB代码
		temp = temp.replace(/&amp;/ig,'&');
		temp = temp.replace(/  /ig,'　');
		temp = temp.replace(/\[modify\]/ig,'<div style="text-align:right; color:#777777">');
		temp = temp.replace(/\[\/modify\]/ig,'</div>');
		temp = temp.replace(/\[modifz\]/ig,'<div style="text-align:right; color:#EEEEEE">');
		temp = temp.replace(/\[\/modifz\]/ig,'</div>');
		temp = temp.replace(/\[b\]/ig,'<b>');
		temp = temp.replace(/\[\/b\]/ig,'<\/b>');
		temp = temp.replace(/\[i\]/ig,'<i>');
		temp = temp.replace(/\[\/i\]/ig,'<\/i>');
		temp = temp.replace(/\[u\]/ig,'<u>');
		temp = temp.replace(/\[\/u\]/ig,'<\/u>');
		temp = temp.replace(/\[strike\]/ig,'<strike>');
		temp = temp.replace(/\[\/strike\]/ig,'<\/strike>');
		temp = temp.replace(/\[left\]/ig,'<div style="text-align:left">');
		temp = temp.replace(/\[\/left\]/ig,'<\/div>');
		temp = temp.replace(/\[right\]/ig,'<div style="text-align:right">');
		temp = temp.replace(/\[\/right\]/ig,'<\/div>');
		temp = temp.replace(/\[center\]/ig,'<center>');
		temp = temp.replace(/\[\/center\]/ig,'<\/center>');
		temp = temp.replace(/\[marquee\]/ig,'<marquee>');
		temp = temp.replace(/\[\/marquee\]/ig,'<\/marquee>');
		temp = temp.replace(/(\[font=)([^.:;`'"=\]]*)(\])/ig,'<font face="$2">');
		temp = temp.replace(/\[\/font\]/ig,'<\/font>');
		temp = temp.replace(/(\[size=)([^.:;`'"=\]]*)(\])/ig,'<font size="$2">');
		temp = temp.replace(/\[\/size\]/ig,'<\/font>');
		temp = temp.replace(/(\[color=)([^.:;`'"=\]]*)(\])/ig,'<font color="$2">');
		temp = temp.replace(/\[\/color\]/ig,'<\/font>');
		temp = temp.replace(/(\[url\])([^]]*)(\[\/URL\])/ig,'<a target=_blank href="$2">$2</a>');
		temp = temp.replace(/(\[url=)([^]]*)(\])/ig,'<a target=_blank href="$2">');
		temp = temp.replace(/\[\/url\]/ig,'<\/a>');
		temp = temp.replace(/(\[email\])(\S+\@[^]]*)(\[\/email\])/ig,'<a href=mailto:$2>$2</a>');
		temp = temp.replace(/(\[code\])([^]]*)(\[\/code\])/ig,'<blockquote><strong>代码</strong>：<hr size=1>$2<hr size=1><\/blockquote>');
		temp = temp.replace(/(\[quote\])(.*)(\[\/quote\])/ig,'<blockquote><strong>引用</strong>：<hr size=1>$2<hr size=1><\/blockquote>');
		temp = temp.replace(/\[rm\]([^]]*)\[\/rm\]/ig,'<object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA width=500 height=375><param name=SRC value=$1><param name=CONSOLE value=Clip1><param name=CONTROLS value=imagewindow><param name=AUTOSTART value=true><\/object><br><object classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=60 width=500><param name=SRC value=$1><param name=CONTROLS value=ControlPanel,StatusBar><param name=CONSOLE value=Clip1><\/object>');
		temp = temp.replace(/(\[mp\])([^]]*)(\[\/mp\])/ig,'<object classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 width=500 height=420><param name=ShowStatusBar value=-1><param name=Filename value=$2><\/object>');
	}

	if (getCookie('UBBflash')!='0'){  //是否打开[FLASH]代码
		temp = temp.replace(/(\[flash\])([^]]*)(\[\/flash\])/ig,'<embed src="$2" width=500 height=375 wmode=transparent>');
	}

	if (getCookie('UBBimg')!='0'){  //是否打开[IMG]代码
		temp = temp.replace(/(\[img\])([^]]*)(\[\/IMG\])/ig,'<img border=0 src="$2" onmousewheel="return ImgWheel(this)" onload="ImgResize(this)" onclick="ImgClick(this)" alt="按此在新窗口浏览图片"> ');
	}

	if (getCookie('UBBbrow')!='0'){  //是否打开表情代码
		temp = temp.replace(/(\[em)([0-9]*)(\])/ig,'<img border=0 src='+gsPathImages+'emot/em$2.gif> ');
		temp = temp.replace(/(\[bz)([0-9]*)(\])/ig,'<img border=0 src='+gsPathImages+'baozi/$2.gif> ');
	}

//自动识别URL
	temp = temp.replace(/([^]='])(| |<br>)((http|ftp|rtsp|mms):(\/\/|\\\\)[^< 　]+)(| |<br>)/ig,'$1$2<a target=_blank href="$3">$3</a>');
	temp = temp.replace(/\[\]/ig,'[');

	return (temp);
}


//读取COOKIE
function getCookie (CookieName) { 
	var CookieString = document.cookie; 
	var CookieSet = CookieString.split (';'); 
	var SetSize = CookieSet.length; 
	var CookiePieces 
	var ReturnValue = ""; 
	var x = 0; 
	for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) { 
		CookiePieces = CookieSet[x].split ('='); 
		if (CookiePieces[0].substring (0,1) == ' ') { 
			CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length); 
		}
		if (CookiePieces[0] == CookieName) {
			ReturnValue = CookiePieces[1];
			var value =ReturnValue
		}
	}
	return value;
}


function UBBFace(nf){
	return '<img src="' + gsPathImages + 'face/face' + nf + '.gif" width="20" height="20" border="0">';
}

function ImgResize(img)
{
	if(img.width>900) img.style.width=900;
}

function ImgClick(img)
{
	window.open(img.src,'_blank');
}


function ImgWheel(img) {
//	var img = event.srcElement;
	if ('IMG' == img.tagName)
	{
		var zoom = parseInt(img.style.zoom, 10) || 100;
		zoom += event.wheelDelta / 12;
		if (zoom > 0) img.style.zoom = zoom + '%';
		return false;
	}
}


function GuestCode(txt){
	var i,n,s;
	s = '';
	n = txt.length;
	return txt.substring(0,n/3) + '...<br><font color="red" style="text-align:right;width:100%">登录后才能显示全部内容</font>';
}

function UBBTD(img,t){
	var tr = img.parentElement.parentElement;
	var table = tr.parentElement;
	var td = table.rows(tr.rowIndex-1).cells(0);

	td.parentElement.style.display = 'block';
	if (0 > USERID)
	{
		td.innerHTML=GuestCode(td.innerHTML);
		img.parentElement.innerHTML = '<center><b>您还没有登录，只能显示1/3的内容。</b></center>';
		return false;
	}
	if (t)
	{
		td.innerHTML=UBBcode(td.innerHTML);
	}
	tr.style.display = 'none';
}
