﻿// JScript 文件
// JScript 文件
function JsUBB(str) 
{    
 str = htmldecode(str);
 
 var re=/\[i\](.[^\[]*)\[\/i\]/gi; 
 str=str.replace(re,"<i>$1</i>");   //斜体字 
 re=/\[b\](.[^\[]*)\[\/b\]/gi; 
 str=str.replace(re,"<b>$1</b>");   //粗体字 
 re=/\[u\](.[^\[]*)\[\/u\]/gi; 
 str=str.replace(re,"<u>$1</u>");  //下划线 
 re=/\[color=(.[^\[]*)\](.[^\[]*)\[\/color\]/gi; 
 str=str.replace(re,"<font color=$1>$2</font>");    //字体颜色 
 re=/\[size=([1-7])\](.[^\[]*)\[\/size\]/gi; 
 str=str.replace(re,"<font size=$1>$2</font>");     //字体大小 
 re=/\[face=(.[^\[]*)\](.[^\[]*)\[\/face\]/gi; 
 str=str.replace(re,"<font face=$1>$2</font>"); //字体 
 re=/\[font=(.[^\[]*)\](.[^\[]*)\[\/font\]/gi; 
 str=str.replace(re,"<font face=$1>$2</font>"); //字体 
 
 re=/\[face src=(.[^\[]*)\]\[\/face\]/gi; 
 str=str.replace(re,"<img src=/forum/face/$1 />"); //表情 
 
 re=/\[align=center\](.[^\[]*)\[\/align\]/gi; 
 str=str.replace(re,"<div align='center'>$1</div>");  //居中 
 re=/\[center\](.[^\[]*)\[\/center\]/gi; 
 str=str.replace(re,"<div align='center'>$1</div>");  //居中 
 re=/\[right\](.[^\[]*)\[\/right\]/gi; 
 str=str.replace(re,"<div align='right'>$1</div>");  //右对齐 
 re=/\[quote\](.[^\[]*)\[\/quote\]/gi;  //引用 
 str=str.replace(re,"<table bgcolor='#E6FFE6' width='90%' style='border:1px #009900 dotted' align='center'><tr><td class='td1'>$1</td></tr></table>"); 

 re=/\[fly\](.*)\[\/fly\]/gi; //飞行 
 str=str.replace(re,"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>"); 
 re=/\[move\](.*)\[\/move\]/gi; //移动 
 str=str.replace(re,"<MARQUEE scrollamount=3>$1</marquee>"); 
 re=/\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW]/gi; //阴影 
 str=str.replace(re,"<table width=$1><tr><td style='filter:shadow(color=$2, strength=$3)'>$4</td></tr></table>"); 
 re=/\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW]/gi; //外发光 
 str=str.replace(re,"<table width=$1 ><tr><td style='filter:glow(color=$2, strength=$3)'>$4</td></tr></table>") 
 
 re=/\[MP=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/MP]/gi;//视频
 str = str.replace(re, "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><param name=ShowStatusBar value=-1><param name=Filename value=$3><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$3  width=$1 height=$2></embed></object>");

 re=/\[URL\](.[^\[]*)\[\/URL\]/gi; 
 str=str.replace(re,"<a href='$1' target=_blank>$1</a>");  //超链接1 
 re=/\[URL=(.[^\[]*)\](.[^\[]*)\[\/URL\]/gi; 
 str=str.replace(re,"<a href='$1' target=_blank>$2</a>");  //超链接2 

 re=/\[EMAIL\]([\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+)\[\/EMAIL\]/gi; 
 str=str.replace(re,"<a href='mailto:$1'>$1</a>");  //电子邮件链接1 
 re=/\[EMAIL=([\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+)\](.[^\[]*)\[\/EMAIL\]/gi; 
 str=str.replace(re,"<a href='mailto:$1'>$4</a>");  //电子邮件链接2 

 re=/\[img\](.[^\[]*)\[\/img\]/gi; 
 str=str.replace(re,"<a href='$1' target=_blank><img src='$1' border='0' alt='单击在新窗口浏览'></a>");  //图片 
 re=/:em(\d{1,}):/gi; 
 str=str.replace(re,"<img src='emot/$1.gif' border='0'>"); //表情图标 
 	 
 re = /\[em(.[^\[]*)\]/gi;
 str = str.replace(re, "<img src=http://bbs.espnstar.com.cn/Skins/Default/emot/em$1.gif border=0 align=middle>");
 re = /\[rem(.[^\[]*)\]/gi;
 str = str.replace(re, "<img src=http://bbs.espnstar.com.cn/images/emot/em$1.gif border=0 align=middle>");
 
 re = /\[UPLOAD=(.[^\[]*)\](.[^\[]*)\[\/UPLOAD\]/gi; 
 str = str.replace(re, "<br><IMG SRC=http://bbs.espnstar.com.cn/images/filetype/$1.gif border=0>此主题相关图片如下：<br><A HREF=http://bbs.espnstar.com.cn/$2 TARGET=_blank><IMG SRC=http://bbs.espnstar.com.cn/$2 border=0 alt=按此在新窗口浏览图片 onload='javascript:if(this.width>screen.width-333)this.width=screen.width-333'></A>");
 
 //alert(htmldecode(str)); 
 
 return htmldecode(str); 
} 

function htmldecode(str)
{
    var re=/&amp;/gi;
    str = str.replace(re, "&");
    
    re=/&lt;/gi; 
    str = str.replace(re, "<");
    
    re=/&gt;/gi; 
    str = str.replace(re, ">");
    
    re=/&quot;/gi; 
    str = str.replace(re, "\"");
    
    re=/&nbsp;/gi; 
    str = str.replace(re, " ");//空格
    
    re=/\n/gi; 
    str = str.replace(re, "<br>");//回车

    return str; 
}