﻿// http://ufku.com/personal/bbc2html
function bbc2html(g){if(g.indexOf("[")<0)return g;var e,i,p=RegExp("\\[([a-z][a-z0-9]*)(?:=([^\\]]+))?]((?:.|[\r\n])*?)\\[/\\1]","gi"),j=RegExp("^(\\d+)x(\\d+)$",void 0),h=function(d,a){for(e in a)d=d.replace(RegExp(e,"gi"),a[e]);return d},q={url:'href="',anchor:'name="',email:'href="mailto: '},r={google:"http://www.google.com/search?q=",wikipedia:"http://www.wikipedia.org/wiki/"},k={youtube:"http://www.youtube.com/v/",flash:""},l={row:"tr",r:"tr",header:"th",head:"th",h:"th",col:"td",c:"td"},f={notag:[{"\\[":"&#91;", "]":"&#93;"},"",""],code:[{"<":"&lt;"},"<code><pre>","</pre></code>"]},m={font:"font-family:$1",size:"font-size:$1px",color:"color:$1"},s={c:"circle",d:"disc",s:"square",1:"decimal",a:"lower-alpha",A:"upper-alpha",i:"lower-roman",I:"upper-roman"},n={},b={},t=function(d,a,b,c){c&&c.indexOf("[")>-1&&(c=o(c));i=a.toLowerCase();switch(i){case "url":case "anchor":case "email":return"<a "+q[a]+(b||c)+'">'+c+"</a>";case "img":return d=j.exec(b),'<img src="'+c+'"'+(d?' width="'+d[1]+'" height="'+d[2]+'"': "")+' alt="'+(d?"":b)+'" />';case "flash":case "youtube":return d=j.exec(b)||[0,425,366],'<object type="application/x-shockwave-flash" data="'+k[a]+c+'" width="'+d[1]+'" height="'+d[2]+'"><param name="movie" value="'+k[a]+c+'" /></object>';case "float":return'<span style="float: '+b+'">'+c+"</span>";case "left":case "right":case "center":case "justify":return'<div style="text-align: '+a+'">'+c+"</div>";case "google":case "wikipedia":return'<a href="'+r[a]+c+'">'+c+"</a>";case "b":case "i":case "u":case "B":case "I":case "U":case "s":case "sup":case "sub":case "h1":case "h2":case "h3":case "h4":case "h5":case "h6":case "table":case "tr":case "th":case "td":return"<"+ a+">"+c+"</"+a+">";case "row":case "r":case "header":case "head":case "h":case "col":case "c":return"<"+l[a]+">"+c+"</"+l[a]+">";case "acronym":case "abbr":return"<"+a+' title="'+b+'">'+c+"</"+a+">"}return"["+a+(b?"="+b:"")+"]"+c+"[/"+a+"]"},o=function(b){return b.replace(p,t)};f.php=[f.code[0],f.code[1]+"&lt;?php ","?>"+f.code[2]];for(e in f)n["\\[("+e+")]((?:.|[\r\n])*?)\\[/\\1]"]=function(b,a,e){return f[a][1]+h(e,f[a][0])+f[a][2]};for(e in m)b["\\["+e+"=([^\\]]+)]"]='<span style="'+m[e]+'">', b["\\[/"+e+"]"]="</span>";b["\\[list]"]="<ul>";b["\\[list=(\\w)]"]=function(b,a){return'<ul style="list-style-type: '+(s[a]||"disc")+'">'};b["\\[/list]"]="</ul>";b["\\[\\*]"]="<li>";b["\\[quote(?:=([^\\]]+))?]"]=function(b,a){return'<div class="bb-quote">'+(a?a+" wrote":"Quote")+":<blockquote>"};b["\\[/quote]"]="</blockquote></div>";b["\\[(hr|br)]"]="<$1 />";b["\\[sp]"]="&nbsp;";return o(h(h(g,n),b))};
$(function(){ $('.MessageBodyCell1').each(function(){ $(this).html(function(i,h){ return bbc2html(h); }); }); });
