<!--
/*
'' ============================================================================================
'' 项目名称：{fyp_title}
'' 项目版本：{fyp_version}
'' 项目描述：{fyp_description}
'' 文件名称：js/js_string.js
'' 文件描述：[JavaScript] 字符串处理函数库
'' 公司名称：{fyp_company}
'' 开发人员：{fyp_designer}
'' 创建日期：{fyp_created_date}
'' 修订日期：{system_date_time format="yyyy-MM-dd hh:mm:ss"}
'' 版权信息：{fyp_copyright}

'' 项目升级时需读取以下生成工具的版权信息
'' 生成工具：{fysoft_name}
'' 当前版本：{fysoft_version}
'' 官方网站：{fysoft_website}
'' ============================================================================================
*/

// ---------------------------------------------------
// 判断字符串是否空值，为空返回true
function IsEmptyStr(strIn)
{
    var bValue = false;
    if (strIn == null || strIn == undefined)
        bValue = true;
    else if (strIn.length == 0)
        bValue = true;
    return bValue;
}
// ---------------------------------------------------

// ---------------------------------------------------
// 去除前后空格
function Trim(str)
{
    return str.replace(/^[\s]*(.*?)[\s]*$/g, '$1');
}
// ---------------------------------------------------

// ---------------------------------------------------
// 删除字符串开始处指定字符（串）
function TrimLeft(strIn, strTrim)
{
    return RegExpReplace("^(" + strTrim + ")+(.*)$", strIn, "$2");
}
// ---------------------------------------------------

// ---------------------------------------------------
// 删除字符串末尾处指定字符（串）
function TrimRight(strIn, strTrim)
{
    return RegExpReplace("^(.*?)(" + strTrim + ")+$", strIn, "$1");
}
// ---------------------------------------------------

// ---------------------------------------------------
// 删除字符串开始/末尾处指定字符（串）
function TrimLeftRight(strIn, strTrim)
{
    strOut = strIn;
    strOut = TrimLeft(strOut, strTrim);
    strOut = TrimRight(strOut, strTrim);
    return strOut;
}
// ---------------------------------------------------

// ---------------------------------------------------
// Left函数，返回指定数目的从字符串的左边算起的字符。
function Left(strIn, iLength)
{
    if (strIn.length > iLength)
    {
        strIn = strIn.substr(0, iLength);
    }
    return strIn;
}
// ---------------------------------------------------

// ---------------------------------------------------
// Right函数。从字符串右边返回指定数目的字符。
function Right(strIn, iLength)
{
    if (strIn.length > iLength)
    {
        var iIndex = strIn.length - iLength;
        strIn = strIn.substr(iIndex, iLength);
    }
    return strIn;
}
// ---------------------------------------------------

// ---------------------------------------------------
// 获取字符串的字节长度，一个汉字2个字节
// strIn: 要判断的字符串
function GetWordsLenth(strIn)
{
    // 将双字节字符替换为2个单字节字符，再统计长度
    return strIn.replace(/[^\x00-\xff]/g, "00").length;
}
// ---------------------------------------------------

// ---------------------------------------------------
// 将指定strIn字符（串）重复iCount次
function CharRepeat(strIn, iCount)
{
    var strValue = "";
    if (IsEmptyStr(strIn) == false)
    {
        for (var iCharRepeatCount = 0; iCharRepeatCount < iCount; iCharRepeatCount++)
        {
            strValue += strIn;
        }
    }
    return strValue;
}
// ---------------------------------------------------

// ---------------------------------------------------
// 根据最大数为iNumMax的长度，在指定的数字（iNumIn）前补零
// 如，输入：2,100，返回：002
function FillZeroBeforeNum(iNumIn, iNumMax)
{
    var strValue = "";
    var iLen = iNumMax.toString().length;
    strValue = CharRepeat("0", iLen - 1) + iNumIn.toString();
    strValue = Right(strValue, iLen);
    return strValue;
}
// ---------------------------------------------------

// --------------------------------------
// 显示UBB编码的批量上载图片信息并对全部输入信息UBB编码
// strIn：需编码的文本, strPics：包括多文件路径的字符串(用, 分开)
function UbbEncodePicStr(strIn, strPics)
{
    var strOut = UbbEncodeStr(strIn);
    var arrPics = strPics.split(", ");
    for (var i = 0; i < arrPics.length; i++)
    {
        strOut = RegExpReplace("(\\[UPLOAD_FILE\\])(" + (i + 1).toString() + ")(\[/UPLOAD_FILE\])", strOut, "<img src=\"" + arrPics[i] + "\"></img>");
    }
    return strOut;
}
// --------------------------------------

// --------------------------------------
// 转换为HTML编码字符，用于页面输出文字显示
function HtmEncodeStr(strIn)
{
    var strOut = strIn;
    if (IsEmptyStr(strOut) == false);
    {
        //escape将会把汉字也编码
        //strOut = escape(strOut);
        strOut = strOut.replace(/&/g, "&amp;");
        strOut = strOut.replace(/</g, "&lt;");
        strOut = strOut.replace(/>/g, "&gt;");
        strOut = strOut.replace(/"/g, "&quot;");
        strOut = strOut.replace(/\r\n/g, "<br>");
        strOut = strOut.replace(/\r/g, "<br>");
        strOut = strOut.replace(/\n/g, "<br>");
        strOut = strOut.replace(/[ \t]/gmi, "&nbsp;");
        strOut = strOut.replace(/'/g, "&#39;");
        //避免在td中连续的&nbsp;导致不换行;
        strOut = RegExpReplace("([^;])(&nbsp;)", strOut, "$1 ");
        //strOut = RegExpReplace("(&nbsp;)((&nbsp;)+)", strOut, " $2");
        strOut = RegExpReplace("&nbsp;&nbsp;&nbsp;", strOut, "&nbsp; &nbsp;");
    }

    return strOut;
}
// --------------------------------------

// --------------------------------------
// 显示Ubb编码的字符串
function UbbEncodeStr(strIn)
{
    var strOut = strIn;
    strOut = RegExpReplace("(\\[em([^\\[]*)\\])", strOut, "<img src=\"images/pic/em$2.gif\" border=0 align=middle>");

    //用replace保证多重嵌套的UBB标识被替换;
    strOut = strOut.replace(/\[B\]/g, "<b>");
    strOut = strOut.replace(/\[\/B\]/g, "</b>");
    strOut = RegExpReplace("(\\[B\\])([\\s\\S]*?)(\\[/B\\])", strOut, "<b>$2</b>");

    strOut = strOut.replace(/\[I\]/g, "<i>");
    strOut = strOut.replace(/\[\/I\]/g, "</i>");
    strOut = RegExpReplace("(\\[I\\])([\\s\\S]*?)(\\[/I\\])", strOut, "<i>$2</i>");

    strOut = strOut.replace(/\[U\]/g, "<u>");
    strOut = strOut.replace(/\[\/U\]/g, "</u>");
    strOut = RegExpReplace("(\\[U\\])([\\s\\S]*?)(\\[/U\\])", strOut, "<u>$2</u>");

    strOut = strOut.replace(/\[LI\]/g, "<li>");
    strOut = strOut.replace(/\[\/LI\]/g, "</li>");
    strOut = RegExpReplace("(\\[LI\\])([\\s\\S]*?)(\\[/LI\\])", strOut, "<li>$2</li>");

    strOut = strOut.replace(/\[FLY\]/g, "<marquee width=90% behavior=alternate scrollamount=3>");
    strOut = strOut.replace(/\[\/FLY\]/g, "</marquee>");
    strOut = RegExpReplace("(\\[FLY\\])([\\s\\S]*?)(\\[/FLY\\])", strOut, "<marquee width=90% behavior=alternate scrollamount=3>$2</marquee>");

    strOut = RegExpReplace("\\[SIZE=([1-6]+)\\]([\\s\\S]*?)\\[/SIZE\\]", strOut, "<font size='$1'>$2</font>");
    strOut = RegExpReplace("\\[FACE=([^\\]]*)\\]([\\s\\S]*?)\\[/FACE\\]", strOut, "<font face='$1'>$2</font>");
    strOut = RegExpReplace("\\[COLOR=([^\\]]*)\\]([\\s\\S]*?)\\[/COLOR\\]", strOut, "<font color='$1'>$2</font>");

    strOut = strOut.replace(/\[MOVE\]/g, "<marquee scrollamount=2 direction='up'>");
    strOut = strOut.replace(/\[\/MOVE\]/g, "</marquee>");
    strOut = RegExpReplace("(\\[MOVE\\])([\\s\\S]*?)(\\[/MOVE\\])", strOut, "<marquee scrollamount=2 direction='up'>$2</marquee>");

    strOut = RegExpReplace("\\[GLOW=*(\\d*),*(#*[a-zA-Z\\d]*),*(\\d*)\\]([\\s\\S]*?)\\[\\/GLOW]", strOut, "<table width=$1 style=\"filter:glow(color=$2, strength=$3)\">$4</table>");

    strOut = RegExpReplace("\\[SHADOW=*(\\d*),*(#*[a-zA-Z\\d]*),*(\\d*)\\]([\\s\\S]*?)\\[\\/SHADOW]", strOut, "<table width=$1 style=\"filter:shadow(color=$2, strength=$3)\">$4</table>");

    strOut = strOut.replace(/\[LEFT\]/g, "<div align='left'>");
    strOut = strOut.replace(/\[\/LEFT\]/g, "</div>");
    strOut = RegExpReplace("(\\[LEFT])([\\s\\S]*?)(\\[/LEFT])", strOut, "<div align='left'>$2</div>");

    strOut = strOut.replace(/\[CENTER\]/g, "<center>");
    strOut = strOut.replace(/\[\/CENTER\]/g, "</center>");
    strOut = RegExpReplace("(\\[CENTER])([\\s\\S]*?)(\\[/CENTER])", strOut, "<center>$2</center>");

    strOut = strOut.replace(/\[RIGHT\]/g, "<div align='right'>");
    strOut = strOut.replace(/\[\/RIGHT\]/g, "</div>");
    strOut = RegExpReplace("(\\[RIGHT])([\\s\\S]*?)(\\[/RIGHT])", strOut, "<div align='right'>$2</div>");

    strOut = strOut.replace(/\[QUOTE\]/g, "<table cellpadding=0 cellspacing=8 border=1 WIDTH=95% align=center style='border-collapse:collapse;border:1px solid #f39a05;background-color:#F1F1F1;'><tr><td>");
    strOut = strOut.replace(/\[\/QUOTE\]/g, "</td></tr></table><br>");
    strOut = RegExpReplace("(\\[QUOTE])([\\s\\S]*?)(\\[/QUOTE])", strOut, "<table cellpadding=0 cellspacing=8 border=1 WIDTH=95% align=center style='border-collapse:collapse;border:1px solid #f39a05;background-color:#F1F1F1;'><tr><td>$2</td></tr></table><br>");

    strOut = RegExpReplace("(\\[URL=([^\\]]*)\\])([\\s\\S]*?)(\\[/URL\\])", strOut, "<a href=\"$2\" target='_blank'>$3</a>");
    strOut = RegExpReplace("(\\[URL\\])([\\s\\S]*?)(\\[/URL\\])", strOut, "<a href=\"$2\" target='_blank'>$2</a>");

    strOut = RegExpReplace("(\\[EMAIL=([^\\]]*)\\])([\\s\\S]*?)(\\[/EMAIL\\])", strOut, "<a href=\"mailto:$2\" target='_blank'>$3</a>");
    strOut = RegExpReplace("(\\[EMAIL\\])([\\s\\S]*?)(\\[/EMAIL\\])", strOut, "<a href=\"mailto:$2\" target='_blank'>$2</a>");

    strOut = RegExpReplace("(\\[IMG\\])([\\s\\S]*?)(\\[/IMG\\])", strOut, "<img src=\"$2\">");
    strOut = RegExpReplace("\\[IMG=*(\\d*),*(\\d*)\\]([\\s\\S]*?)\\[\\/IMG]", strOut, "<img src=\"$3\" width=\"$1\" height=\"$2\">");

    strOut = RegExpReplace("(\\[FLASH\\])([\\s\\S]*?)(\\[/FLASH\\])", strOut, "<embed src=\"$2\" width=\"500\"></embed>");
    strOut = RegExpReplace("\\[FLASH=*(\\d*),*(\\d*)\\]([\\s\\S]*?)\\[\\/FLASH]", strOut, "<embed src=\"$3\" width=\"$1\" height=\"$2\"></embed>");

    strOut = RegExpReplace("(\\[DIR\\])([\\s\\S]*?)(\\[/DIR\\])", strOut, "<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=500 height=400><param name=src value=$2><embed src=$2 pluginspage=http://www.macromedia.com/shockwave/download/ width=500 height=400></embed></object>");
    strOut = RegExpReplace("\\[DIR=*(\\d*),*(\\d*)\\]([\\s\\S]*?)\\[\\/DIR]", strOut, "<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=$1 height=$2><param name=src value=$3><embed src=$3 pluginspage=http://www.macromedia.com/shockwave/download/ width=$1 height=$2></embed></object>");

    strOut = RegExpReplace("(\\[RM\\])([\\s\\S]*?)(\\[/RM\\])", strOut, "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=500 height=400><PARAM NAME=SRC VALUE=$2><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=32 id=video2 width=500 height=400><PARAM NAME=SRC VALUE=$2><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>");
    strOut = RegExpReplace("\\[RM=*(\\d*),*(\\d*)\\]([\\s\\S]*?)\\[\\/RM]", strOut, "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$3><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 id=video2 width=$1 height=$2><PARAM NAME=SRC VALUE=$3><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>");

    strOut = RegExpReplace("(\\[MP\\])([\\s\\S]*?)(\\[/MP\\])", strOut, "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=500 height=400><param name=ShowStatusBar value=-1><param name=Filename value=$2><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$2 width=500 height=400></embed></object>");
    strOut = RegExpReplace("\\[MP=*(\\d*),*(\\d*)\\]([\\s\\S]*?)\\[\\/MP]", strOut, "<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>");

    strOut = RegExpReplace("(\\[QT\\])([\\s\\S]*?)(\\[/QT\\])", strOut, "<embed src=$2 width=500 height=400 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>");
    strOut = RegExpReplace("\\[QT=*(\\d*),*(\\d*)\\]([\\s\\S]*?)\\[\\/QT]", strOut, "<embed src=$3 width=$1 height=$2 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>");

    return strOut;
}
-->