var UBB = 
{
	codecount : '-1',
	codehtml : [],
	/**
	*  匹配模式替换
	**/
	preg_replace : function(search, replace, str) 
	{
		var len = search.length;
		for(var i = 0; i < len; i++) 
		{
			re = new RegExp(search[i], "ig");
			str = str.replace(re, typeof replace == 'string' ? replace : (replace[i] ? replace[i] : replace[0]));
		}
		return str;
	},
	/**
	*	根据tagname标签查找标签内的文字text，dofunction为处理找到后的处理方式,extraargs为对应的标签或者属性
	**/
	recursion : function(tagname, text, dofunction, extraargs) 
	{
		if(extraargs == null) 
		{
			extraargs = '';
		}
		tagname = tagname.toLowerCase();

		var open_tag = '<' + tagname;
		var open_tag_len = open_tag.length;
		var close_tag = '</' + tagname + '>';
		var close_tag_len = close_tag.length;
		var beginsearchpos = 0;

		do {
			var textlower = text.toLowerCase();
			var tagbegin = textlower.indexOf(open_tag, beginsearchpos);
			if(tagbegin == -1) 
			{
				break;
			}

			var strlen = text.length;

			var inquote = '';
			var found = false;
			var tagnameend = false;
			var optionend = 0;
			var t_char = '';

			for(optionend = tagbegin; optionend <= strlen; optionend++) 
			{
				t_char = text.charAt(optionend);
				if((t_char == '"' || t_char == "'") && inquote == '') 
				{
					inquote = t_char;
				} else if((t_char == '"' || t_char == "'") && inquote == t_char) 
				{
					inquote = '';
				} else if(t_char == '>' && !inquote) 
				{
					found = true;
					break;
				} else if((t_char == '=' || t_char == ' ') && !tagnameend) 
				{
					tagnameend = optionend;
				}
			}

			if(!found) 
			{
				break;
			}
			if(!tagnameend)
			{
				tagnameend = optionend;
			}

			var offset = optionend - (tagbegin + open_tag_len);
			var tagoptions = text.substr(tagbegin + open_tag_len, offset)
			var acttagname = textlower.substr(tagbegin * 1 + 1, tagnameend - tagbegin - 1);

			if(acttagname != tagname) 
			{
				beginsearchpos = optionend;
				continue;
			}

			var tagend = textlower.indexOf(close_tag, optionend);
			if(tagend == -1) 
			{
				break;
			}

			var nestedopenpos = textlower.indexOf(open_tag, optionend);
			while(nestedopenpos != -1 && tagend != -1) 
			{
				if(nestedopenpos > tagend)
				{
					break;
				}
				tagend = textlower.indexOf(close_tag, tagend + close_tag_len);
				nestedopenpos = textlower.indexOf(open_tag, nestedopenpos + open_tag_len);
			}

			if(tagend == -1) 
			{
				beginsearchpos = optionend;
				continue;
			}

			var localbegin = optionend + 1;
			var localtext = eval(dofunction)(tagoptions, text.substr(localbegin, tagend - localbegin), tagname, extraargs);

			text = text.substring(0, tagbegin) + localtext + text.substring(tagend + close_tag_len);

			beginsearchpos = tagbegin + localtext.length;

		} while(tagbegin != -1);

		return text;
	},
	/**
	*  字符串查找
	**/
	strpos : function(haystack, needle, offset) 
	{
		if(typeof offset == "undefined")
		{
			offset = 0;
		}	
		index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);	
		return index == -1 ? false : index;
	},
	/**
	*  编码
	**/
	html_ubb : function(str)
	{  	
		str = str.replace(/<wbr(\s*?)(\/*?)>/ig,"[wbr]");
		str = str.replace(/(<div(.*?)type=["']quote["'](.*?)>(.*?)<\/div>)/ig,"[quote]$1[/quote]");
		str = str.replace(/\[quote\](<div(.*?)time=["'](.*?)['"](.*?)>(.*?)<\/div>)\[\/quote\]/ig,"[quote $3]$1[/quote]");
		str = str.replace(/\[quote (.*?) (.*?)\](<div(.*?)from=["'](.*?)['"](.*?)>(.*?)<\/div>)\[\/quote\]/ig,"[quote $1 $2 $5]$3[/quote]");
		str = str.replace(/\[quote (.*?) (.*?) (.*?)\](<div(.*?)value=["'](.*?)['"](.*?)>(.*?)<\/div>)\[\/quote\]/ig,"[quote $1 $2  $3]$6[/quote]"); 
		str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");			
		str = str.replace(/(<script.*?>.*?<\/script>)/ig,"");

		/*if(Prototype.Browser.Gecko)
		{					
			str = str.replace(/<img.*?style=\".*?width: (\d*?)px;.*?height: (\d*)px;.*?\" title=\"src:(.*?)\".*?>/ig,"[flash,$1,$2]$3[/flash]");
		}else if(Prototype.Browser.IE)
		{  			
			str = str.replace(/<img.*?title=src:(.*?) style=\".*?width: (\d*?)px;.*?height: (\d*)px;.*?\".*?>/ig,"[flash,$2,$3]$1[/flash]");
		}
		  */
		str = UBB.preg_replace(['<style.*?>[\\\s\\\S]*?<\/style>', '<script.*?>[\\\s\\\S]*?<\/script>', '<noscript.*?>[\\\s\\\S]*?<\/noscript>', '<select.*?>[\s\S]*?<\/select>', '<object.*?>[\s\S]*?<\/object>', '<!--[\\\s\\\S]*?-->', ' on[a-zA-Z]{3,16}\\\s?=\\\s?"[\\\s\\\S]*?"'], '', str);

		str= str.replace(/(\r\n|\n|\r)/ig, '');

		str= UBB.trim(str.replace(/&((#(32|127|160|173))|shy|nbsp);/ig, ' '));

		//if(!fetchCheckbox('parseurloff')) 
		{
			//str = parseurl(str, 'bbcode', false);
		}

		str = str.replace(/<br\s+?style=(["']?)clear: both;?(\1)[^\>]*>/ig, '');
		str = str.replace(/<br[^\>]*>/ig, "[br]");

		//if(!fetchCheckbox('bbcodeoff') && allowbbcode) 
		{
			str = UBB.preg_replace(['<table([^>]*(width|background|background-color|bgcolor)[^>]*)>', '<table[^>]*>', '<tr[^>]*(?:background|background-color|bgcolor)[:=]\\\s*(["\']?)([\(\)%,#\\\w]+)(\\1)[^>]*>', '<tr[^>]*>', '<t[dh]([^>]*(width|colspan|rowspan)[^>]*)>', '<t[dh][^>]*>', '<\/t[dh]>', '<\/tr>', '<\/table>'], [function($1, $2) {return UBB.tabletag($2);}, '[table]', function($1, $2, $3) {return '[tr=' + $3 + ']';}, '[tr]', function($1, $2) {return UBB.tdtag($2);}, '[td]', '[/td]', '[/tr]', '[/table]'], str);

			str = str.replace(/<h([0-9]+)[^>]*>(.*)<\/h\\1>/ig, "[size=$1]$2[/size]\n\n");
			str = str.replace(/<img[^>]+smilieid=(["']?)(\d+)(\1)[^>]*>/ig, function($1, $2, $3) {return smilies[$3]['code'];});
			str = str.replace(/<img([^>]*src[^>]*)>/ig, function($1, $2) {return UBB.imgtag($2);});
			str = str.replace(/<a\s+?name=(["']?)(.+?)(\1)[\s\S]*?>([\s\S]*?)<\/a>/ig, '$4');
			//str = str.replace(/<<\/p>/ig,"<br>")
			str = UBB.recursion('b', str, 'UBB.simpletag', 'b');
			str = UBB.recursion('strong', str, 'UBB.simpletag', 'b');
			str = UBB.recursion('i', str, 'UBB.simpletag', 'i');
			str = UBB.recursion('em', str, 'UBB.simpletag', 'i');
			str = UBB.recursion('u', str, 'UBB.simpletag', 'u');
			str = UBB.recursion('a', str, 'UBB.atag');
			str = UBB.recursion('font', str, 'UBB.fonttag');
			str = UBB.recursion('blockquote', str, 'UBB.simpletag', 'indent');
			str = UBB.recursion('ol', str, 'UBB.listtag');
			str = UBB.recursion('ul', str, 'UBB.listtag');
			str = UBB.recursion('div', str, 'UBB.dpstag');
			str = UBB.recursion('p', str, 'UBB.dpstag');
			str = UBB.recursion('span', str, 'UBB.dpstag');
		}	 
		str = str.replace(/<[\/\!]*?[^<>]*?>/ig, '');		
		str = str.replace("(\r|\n)+","");

		return UBB.preg_replace(['&nbsp;', '&lt;', '&gt;', '&amp;'], [' ', '<', '>', '&'], str);
	},
	/**
	*  去吃字符串前后的空格
	**/
	trim:function (str) 
	{ 
		return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, ''); 
	},
	/**
	*  添加简单color，font，size标签
	**/
	simpletag : function (options, text, tagname, parseto) 
	{
		if(UBB.trim(text) == '') 
		{
			return '';
		}
		text = UBB.recursion(tagname, text, 'UBB.simpletag', parseto);
		return '[' + parseto + ']' + text + '[/' + parseto + ']';
	},
	/**
	*	查找style属性的内容，包括字体，字号，颜色，对切的一些属性
	**/	
	parsestyle : function (tagoptions, prepend, append) 
	{
		var searchlist = [
			['align', true, 'text-align:\\s*(left|center|right);?', 1],
			['float', true, 'float:\\s*(left|right);?', 1],
			['color', true, '^(?:\\s|)color:\\s*([^;]+);?', 1],
			['font', true, 'font-family:\\s*([^;]+);?', 1],
			['size', true, 'font-size:\\s*(\\d+(\\.\\d+)?(px|pt|in|cm|mm|pc|em|ex|%|));?', 1],
			['b', false, 'font-weight:\\s*(bold);?'],
			['i', false, 'font-style:\\s*(italic);?'],
			['u', false, 'text-decoration:\\s*(underline);?']
		];
		var style = UBB.getoptionvalue('style', tagoptions);
		re = /^(?:\s|)color:\s*rgb\((\d+),\s*(\d+),\s*(\d+)\)(;?)/ig;
		style = style.replace(re, function($1, $2, $3, $4, $5) {return("color:#" + parseInt($2).toString(16) + parseInt($3).toString(16) + parseInt($4).toString(16) + $5);});
		var len = searchlist.length;
		for(var i = 0; i < len; i++) 
		{
			re = new RegExp(searchlist[i][2], "ig");
			match = re.exec(style);
			if(match != null)
			{
				opnvalue = match[searchlist[i][3]];
				prepend += '[' + searchlist[i][0] + (searchlist[i][1] == true ? '=' + opnvalue + ']' : ']');
				append = '[/' + searchlist[i][0] + ']' + append;
			}
		}
		return {'prepend' : prepend, 'append' : append};
	},
	 /**
	*	查找属性对应的字符串
	**/	
	getoptionvalue:function (option, text) 
	{
		re = new RegExp(option + "(\s+?)?\=(\s+?)?[\"']?(.+?)([\"']|$|>)", "ig");
		var matches = re.exec(text);
		if(matches != null) {
			return UBB.trim(matches[3]);
		}
		return '';
	},
	/**
	*  处理图片
	**/
	imgtag:function (attributes)
	{
		var width = '';
		var height = '';
		var src = '';

		re = /src=(["']?)([\s\S]*?)(\1)/i;
		var matches = re.exec(attributes);
		if(matches != null) {
			src = matches[2];
		} else {
			return '';
		}

		var title = '';
		re = /title=(["']?)src:(.*)(\1)/i; 		
		var matches = re.exec(attributes);			
		if(matches != null) {
			title = matches[2];
		}

		re = /width\s?:\s?(\d{1,4})(px)?/ig;
		var matches = re.exec(attributes);
		if(matches != null) {
			width = matches[1];
		}

		re = /height\s?:\s?(\d{1,4})(px)?/ig;
		var matches = re.exec(attributes);
		if(matches != null) {
			height = matches[1];
		}

		if(!width || !height) {
			re = /width=(["']?)(\d+)(\1)/i;
			var matches = re.exec(attributes);
			if(matches != null) {
				width = matches[2];
			}

			re = /height=(["']?)(\d+)(\1)/i;
			var matches = re.exec(attributes);
			if(matches != null) {
				height = matches[2];
			}
		}

		re = /aid=(["']?)attach_(\d+)(\1)/i;
		var matches = re.exec(attributes);
		var imgtag = 'img';
		if(matches != null) {
			imgtag = 'localimg';
			src = matches[2];
		}

		
		if(title != "")
		{	  			
			return "[flash," + width + "," + height + "]" + title + "[/flash]";
			
		}
		var yct =  /(.*?\/bq\/)(\S*?)\.gif/ig;
		var fface   =  /(.*?\/Face2\/)(\d*?)\.gif/ig;
		if(fface.test(src))
		{
			return src.replace(fface,"[:$2]");
		}
		if(yct.test(src))
		{
			return src.replace(yct,"[yct]$2[/yct]");
		}
		re = /aid=(["']?)attachimg_(\d+)(\1)/i;
		var matches = re.exec(attributes);
		if(matches != null) {
			return '[attachimg]' + matches[2] + '[/attachimg]';
		}
		return width > 0 && height > 0 ?
			'[img=' + width + ',' + height + ']' + src + '[/img]' :
			'[img]' + src + '[/img]';
	},
	/**
	*	处理列表
	**/
	listtag:function (listoptions, text, tagname) 
	{
		text = text.replace(/<li>(([\s\S](?!<\/li))*?)(?=<\/?ol|<\/?ul|<li|\[list|\[\/list)/ig, '<li>$1</li>');
		text = UBB.recursion('li', text, 'UBB.litag');
		var opentag = '[list]';
		var listtype = UBB.fetchoptionvalue('type=', listoptions);
		listtype = listtype != '' ? listtype : (tagname == 'ol' ? '1' : '');
		if(UBB.in_array(listtype, ['1', 'a', 'A'])) {
			opentag = '[list=' + listtype + ']';
		}
		return text ? opentag + UBB.recursion(tagname, text, 'UBB.listtag') + '[/list]' : '';
	} ,
	/**
	*  处理LI
	**/
	litag:function (listoptions, text) 
	{
		return '[*]' + text.replace(/(\s+)$/g, '');
	},
	/**
	*	处理table
	**/
	parsetable:function (width, bgcolor, str)
	{

		if(typeof width == "undefined") {
			var width = '';
		} else {
			width = width.substr(width.length - 1, width.length) == '%' ? (width.substr(0, width.length - 1) <= 98 ? width : '98%') : (width <= 560 ? width : '98%');
		}

		str = str.replace(/\[tr(?:=([\(\)%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ig, function($1, $2, $3, $4, $5) {
			return '<tr' + ($2 ? ' style="background: ' + $2 + '"' : '') + '><td' + ($3 ? ' colspan="' + $3 + '"' : '') + ($4 ? ' rowspan="' + $4 + '"' : '') + ($5 ? ' width="' + $5 + '"' : '') + '>';
		});
		str = str.replace(/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ig, function($1, $2, $3, $4) {
			return '</td><td' + ($2 ? ' colspan="' + $2 + '"' : '') + ($3 ? ' rowspan="' + $3 + '"' : '') + ($4 ? ' width="' + $4 + '"' : '') + '>';
		});
		str = str.replace(/\[\/td\]\s*\[\/tr\]/ig, '</td></tr>');

		return '<table ' + (width == '' ? '' : 'width="' + width + '" ') + 'class="t_table"' + ((typeof bgcolor == "undefined") ? '' : ' style="background: ' + bgcolor + '"') + '>' + str + '</table>';
	},
	/**
	*  处理table的属性
	**/
	tabletag:function (attributes) 
	{
		var width = '';
		re = /width=(["']?)(\d{1,4}%?)(\1)/i;
		var matches = re.exec(attributes);

		if(matches != null) {
			width = matches[2].substr(matches[2].length - 1, matches[2].length) == '%' ?
				(matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') :
				(matches[2] <= 560 ? matches[2] : '98%');
		} else {
			re = /width\s?:\s?(\d{1,4})([px|%])/ig;
			var matches = re.exec(attributes);
			if(matches != null) {
				width = matches[2] == '%' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '98%');
			}
		}

		var bgcolor = '';
		re = /(?:background|background-color|bgcolor)[:=]\s*(["']?)((rgb\(\d{1,3}%?,\s*\d{1,3}%?,\s*\d{1,3}%?\))|(#[0-9a-fA-F]{3,6})|([a-zA-Z]{1,20}))(\1)/i;
		var matches = re.exec(attributes);
		if(matches != null) {
			bgcolor = matches[2];
			width = width ? width : '98%';
		}

		return bgcolor ? '[table=' + width + ',' + bgcolor + ']' : (width ? '[table=' + width + ']' : '[table]');
	},
	/**
	*  处理td标签
	**/
	tdtag:function (attributes) 
	{

		var colspan = 1;
		var rowspan = 1;
		var width = '';

		re = /colspan=(["']?)(\d{1,2})(\1)/ig;
		var matches = re.exec(attributes);
		if(matches != null) {
			colspan = matches[2];
		}

		re = /rowspan=(["']?)(\d{1,2})(\1)/ig;
		var matches = re.exec(attributes);
		if(matches != null) {
			rowspan = matches[2];
		}

		re = /width=(["']?)(\d{1,4}%?)(\1)/ig;
		var matches = re.exec(attributes);
		if(matches != null) {
			width = matches[2];
		}

		return UBB.in_array(width, ['', '0', '100%']) ?
			(colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') :
			'[td=' + colspan + ',' + rowspan + ',' + width + ']';
	},
	/**
	*  ubb到html的转化
	**/
	ubb_html:function (str,isPage) 
	{

		str = UBB.trim(str);  
		if(str == '') 
		{
			return '';
		}
		
		if(isPage)
		{	  				
			str = str.replace(/\[flash,(.*?),(.*?)\](.*?)\[\/flash\]/ig,"<object wmode=\"transparent\"><embed width=$1 height=$2 src=$3 type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed></object>");
			str = str.replace(/(\[flash\](\S*?)\[\/flash\])/ig,"<object wmode=\"transparent\"><embed $3 $4 src=\"$6\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed></object>");
		}else
		{ 		
			str = str.replace(/\[flash,(.*?),(.*?)\](.*?)\[\/flash\]/ig,'<img style="border: 1px solid rgb(255, 0, 0); background-color: rgb(255, 255, 204); width: $1px; height: $2px; background-image: url(flash.gif); background-repeat: no-repeat; background-position-x:center;background-position-y:50%;" title="src:$3" src="http://ghf.com/tinymce/jscripts/tiny_mce/plugins/media/img/trans.gif">');
		}
		str = str.replace(/\[wbr\]/ig,"<wbr>");
	    str = str.replace(/\[:(\d+)\]/ig,"<img src='/images/Face2/$1.gif' class='face' />");
	    str = str.replace(/\[yct\](.*?)\[\/yct\]/ig,"<img src='/images/bq/$1.gif'/>");  
	    str = str.replace(/(\[quote (.*?) (.*?) (.*?)\](.*)\[\/quote\])/ig,"<div type='quote' time='$2 $3' frome='$4' value='$5' style='border:#B1E2AE dotted 1px;padding:8px; background:#F6FDF5' type='rel'><span style='color:#666;'>原帖由$4发表于$2 $3</span><br>$5</div>");
		str = str.replace(/\[url\]\s*(www.|https?:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|telnet:\/\/|rtsp:\/\/|mms:\/\/|callto:\/\/|bctp:\/\/|ed2k:\/\/){1}([^\[\"']+?)\s*\[\/url\]/ig, function($1, $2, $3) {return cuturl($2 + $3);});
		str.replace(/\[url\]\s*(www.|https?:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|telnet:\/\/|rtsp:\/\/|mms:\/\/|callto:\/\/|bctp:\/\/|ed2k:\/\/){1}([^\[\"']+?)\s*\[\/url\]/ig, function($1, $2, $3) {return '<a href="' + $2 + $3 + '">' + $2 + $3 + '</a>';});
		str = str.replace(/\[url=www.([^\[\"']+?)\](.+?)\[\/url\]/ig, '<a href="http://www.$1" target="_blank">$2</a>');
		str = str.replace(/\[url=(https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k){1}:\/\/([^\[\"']+?)\]([\s\S]+?)\[\/url\]/ig, '<a href="$1://$2" target="_blank">$3</a>');
		str = str.replace(/\[url=(\S*?)\](.+?)\[\/url\]/ig,"<a href=$1>$2</a>")
		str = str.replace(/\[email\](.*?)\[\/email\]/ig, '<a href="mailto:$1">$1</a>');
		str = str.replace(/\[email=(.[^\[]*)\](.*?)\[\/email\]/ig, '<a href="mailto:$1" target="_blank">$2</a>');
		str = str.replace(/\[color=([^\[\<]+?)\]/ig, '<font color="$1">');
		str = str.replace(/\[size=(\d+?)\]/ig, '<font size="$1">');
		str = str.replace(/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/ig, '<font style="font-size: $1">');
		str = str.replace(/\[font=([^\[\<]+?)\]/ig, '<font face="$1">');
		str = str.replace(/\[face=([^\[\<]+?)\]/ig, '<font face="$1">');
		str = str.replace(/\[align=([^\[\<]+?)\]/ig, '<p align="$1">');
		str = str.replace(/\[float=([^\[\<]+?)\]/ig, '<br style="clear: both"><span style="float: $1;">');
		str = str.replace(/\[embed\](.*?)\[\/embed\]/ig,"<embed wmode=\"transparent\" src=$1></embed>");
		//str = str.replace(/\[embed (.*?),(.*?)\](.*?)\[\/embed\]/ig,"<embed wmode=\"transparent\" src=$3 width=$1 height=$2></embed>");
		str = str.replace(/(\[embed (.*?),(.*?)\](.*?)\[\/embed\])/ig,function($1,$2,$3,$4,$5){	  	
			return "<embed wmode=\"transparent\" src=" + $5 + " width=" + ($3>540 ? 540 : $3)  + " height=" + $4 + "></embed>";
		});
		str = str.replace(/\[embed(.*?)\](.*?)\[\/embed\]/ig,"<embed wmode=\"transparent\" $1>$2</embed>");
		str = str.replace(/\[size=(.*?)\]/ig,"<font size=$1>");
		str = str.replace(/\[\/size=(.*?)\]/ig,"</font>");
		
		
		re = /\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*([\s\S]+?)\s*\[\/table\]/ig;
		for (i = 0; i < 4; i++) {
			str = str.replace(re, function($1, $2, $3, $4) {return UBB.parsetable($2, $3, $4);});
		}

		str = UBB.preg_replace([
			'\\\[\\\/color\\\]','\\\[\\\/face\\\]', '\\\[\\\/size\\\]', '\\\[\\\/font\\\]', '\\\[\\\/align\\\]', '\\\[b\\\]', '\\\[\\\/b\\\]',
			'\\\[i\\\]', '\\\[\\\/i\\\]', '\\\[u\\\]', '\\\[\\\/u\\\]', '\\\[list\\\]', '\\\[list=1\\\]', '\\\[list=a\\\]',
			'\\\[list=A\\\]', '\\\[\\\*\\\]', '\\\[\\\/list\\\]', '\\\[indent\\\]', '\\\[\\\/indent\\\]', '\\\[\\\/float\\\]'
			], [
			'</font>','</font>', '</font>', '</font>', '</p>', '<b>', '</b>', '<i>',
			'</i>', '<u>', '</u>', '<ul>', '<ul type=1>', '<ul type=a>',
			'<ul type=A>', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
			], str);
			str = str.replace(/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ig, '<img src="$1" />');
			str = str.replace(/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ig, '<img src="$3" width="$1" height="$2" />');
			
		
		str = UBB.preg_replace(['\t', '   ', '  ', '(\r\n|\n|\r)'], ['&nbsp; &nbsp; &nbsp; &nbsp; ', '&nbsp; &nbsp;', '&nbsp;&nbsp;', '<br />'], str);
		str = str.replace(/\[br\]/ig,"<br />");
		return str;
	},
	dpstag : function (options, text, tagname) 
	{
		if(UBB.trim(text) == '') {
			if(Prototype.Browser.IE)
			{
				return '[br]';
			}else
			{
				return "\n";
			}
		}
		var pend = UBB.parsestyle(options, '', '');
		var prepend = pend['prepend'];
		var append = pend['append'];
		if(UBB.in_array(tagname, ['div', 'p'])) {
			align = UBB.getoptionvalue('align', options);
			if(UBB.in_array(align, ['left', 'center', 'right'])) {
				prepend = '[align=' + align + ']' + prepend;
				append += '[/align]';
			} else {
				if(Prototype.Browser.IE)
				{
					append += '[br]';
				}else
				{
					append += '\n';
				}
				
			}
		}
		return prepend + UBB.recursion(tagname, text, 'UBB.dpstag') + append;
	},
	/**
	*  判断元素是否在数组中
	**/
	in_array:function (needle, haystack)
	{

		if(typeof needle == 'string' || typeof needle == 'number') {

			for(var i in haystack) {

				if(haystack[i] == needle) {	
						return true;
				} 
			} 
		} 
		return false;  
	},
	/**
	*	处理a标签
	**/
	atag:function (aoptions, text)
	{
		if(UBB.trim(text) == '') {
			return '';
		}

		href = UBB.getoptionvalue('href', aoptions);

		if(href.substr(0, 11) == 'javascript:') {
			return UBB.trim(UBB.recursion('a', text, 'atag'));
		} else if(href.substr(0, 7) == 'mailto:') {
			tag = 'email';
			href = href.substr(7);
		} else {
			tag = 'url';
		}

		return '[' + tag + '=' + href + ']' + UBB.trim(UBB.recursion('a', text, 'atag')) + '[/' + tag + ']';
	},
	fetchoptionvalue:function (option, text) 
	{
		if((position = UBB.strpos(text, option)) !== false) {
			delimiter = position + option.length;
			if(text.charAt(delimiter) == '"') {
				delimchar = '"';
			} else if(text.charAt(delimiter) == '\'') {
				delimchar = '\'';
			} else {
				delimchar = ' ';
			}
			delimloc = UBB.strpos(text, delimchar, delimiter + 1);
			if(delimloc === false) {
				delimloc = text.length;
			} else if(delimchar == '"' || delimchar == '\'') {
				delimiter++;
			}
			return UBB.trim(text.substr(delimiter, delimloc - delimiter));
		} else {
			return '';
		}
	},
	ubb_text : function(str)
	{
		str = str.replace(/&nbsp;/ig,"");
		str = str.replace(/(\[quote (.*?) (.*?) (.*?)\](.*)\[\/quote\])/ig,"");
		str = str.replace(/(\[img\](.*?)\[\/img\])/ig,"[图]");
		str = str.replace(/(\[img(.*?)\](.*?)\[\/img\])/ig,"[图]");
		str = str.replace(/(\[flash(.*?)\](.*?)\[\/flash\])/ig,"[FLASH]");
		str = str.replace(/(\[:\d+\])/ig,"[表情]");
		str = str.replace(/\[yct\](.*?)\[\/yct\]/ig,"[洋葱头表情]");
		str = str.replace(/(\[rm\](.*?)\[\/rm\])/ig,"[视频]");
		str = str.replace(/(\[rm(.*?)\](.*?)\[\/rm\])/ig,"[视频]");
		str = str.replace(/(\[mp3\](.*?)\[\/mp3\])/ig,"[音频]");
		str = str.replace(/(\[mp3(.*?)\](.*?)\[\/mp3\])/ig,"[音频]");
		str = str.replace(/(\[(embed)(.*?)\](.*?)\[\/(embed)\])/ig,"[影音]");
		str = str.replace(/(\[br])/ig,"");
		
		str = str.replace(/(\[[\/]?(size|face|color|i|u|b|em|font|align)(.*?)\])/ig,""); 		
		
		/*
		str = str.replace(/(\[(i|u|b|em)\](.*?)\[\/(u|i|b|em)\])/ig,"$3");
		str = str.replace(/(\[(size|face|color)(.*?)\](.*?)\[\/(size|face|color)\])/ig,"$4");
		str = str.replace(/(\[(size|face|color)(.*?)\](.*?)\[\/(size|face|color)\])/ig,"$4");
		str = str.replace(/(\[(size|face|color)(.*?)\](.*?)\[\/(size|face|color)\])/ig,"$4");
		str = str.replace(/(\[(size|face|color)(.*?)\](.*?)\[\/(size|face|color)\])/ig,"$4");
		 */
		str = str.replace(/(\[br\])/ig,"");
		str = str.replace(/(\[pbr\])/ig,"");
		str = str.replace(/(\[table])/ig,"");
		str = str.replace(/(\[\/table])/ig,"");
		str = str.replace(/(\[tr])/ig,"");
		str = str.replace(/(\[\/tr])/ig,"");
		str = str.replace(/(\[td])/ig,"");
		str = str.replace(/(\[\/td])/ig,"");
		str = str.replace(/(\[tbody])/ig,"");
		str = str.replace(/(\[\/tbody])/ig,"");
		//str = str.replace(/(\[(.*?)\](.*?)\[\/(.*?)\])/ig,"$3");
		str = str.substring(0,str.length > 100 ? 100 : str.length);
		return str;
	},
	fonttag : function (fontoptions, text) 
	{
		var prepend = '';
		var append = '';
		var tags = new Array();
		tags = {'font' : 'face=', 'size' : 'size=', 'color' : 'color='};
		for(bbcode in tags) {
			optionvalue = UBB.fetchoptionvalue(tags[bbcode], fontoptions);
			if(optionvalue) {
				prepend += '[' + bbcode + '=' + optionvalue + ']';
				append = '[/' + bbcode + ']' + append;
			}
		}

		var pend = UBB.parsestyle(fontoptions, prepend, append);
		return pend['prepend'] + UBB.recursion('font', text, 'UBB.fonttag') + pend['append'];
	}

};
function ubb2text(str)
{
	return UBB.ubb_text(str);
}
function html_ubb(str)
{
	return UBB.html_ubb(str);
}
function ubb_html(str,isedit)
{
	return UBB.ubb_html(str,true);
}