(function(){var k=/^<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,c=/^<\/(\w+)[^>]*>/,g=/(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;var f=b("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");var a=b("address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul");var i=b("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");var d=b("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");var j=b("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");var h=b("script,style");var e=this.HTMLParser=function(m,u){var p,q,n,r=[],s=m;r.last=function(){return this[this.length-1]};while(m){q=true;if(!r.last()||!h[r.last()]){if(m.indexOf("<!--")==0){p=m.indexOf("-->");if(p>=0){if(u.comment){u.comment(m.substring(4,p))}m=m.substring(p+3);q=false}}else{if(m.indexOf("</")==0){n=m.match(c);if(n){m=m.substring(n[0].length);n[0].replace(c,o);q=false}}else{if(m.indexOf("<")==0){n=m.match(k);if(n){m=m.substring(n[0].length);n[0].replace(k,l);q=false}}}}if(q){p=m.indexOf("<");var t=p<0?m:m.substring(0,p);m=p<0?"":m.substring(p);if(u.chars){u.chars(t)}}}else{m=m.replace(new RegExp("(.*)</"+r.last()+"[^>]*>"),function(v,w){w=w.replace(/<!--(.*?)-->/g,"$1").replace(/<!\[CDATA\[(.*?)]]>/g,"$1");if(u.chars){u.chars(w)}return""});o("",r.last())}if(m==s){throw"Parse Error: "+m}s=m}o();function l(v,y,z,w){if(a[y]){while(r.last()&&i[r.last()]){o("",r.last())}}if(d[y]&&r.last()==y){o("",y)}w=f[y]||!!w;if(!w){r.push(y)}if(u.start){var x=[];z.replace(g,function(B,A){var C=arguments[2]?arguments[2]:arguments[3]?arguments[3]:arguments[4]?arguments[4]:j[A]?A:"";x.push({name:A,value:C,escaped:C.replace(/(^|[^\\])"/g,'$1\\"')})});if(u.start){u.start(y,x,w)}}}function o(v,x){if(!x){var y=0}else{for(var y=r.length-1;y>=0;y--){if(r[y]==x){break}}}if(y>=0){for(var w=r.length-1;w>=y;w--){if(u.end){u.end(r[w])}}r.length=y}}};this.HTMLtoXML=function(m){var l="";e(m,{start:function(n,p,o){l+="<"+n;for(var q=0;q<p.length;q++){l+=" "+p[q].name+'="'+p[q].escaped+'"'}l+=(o?"/":"")+">"},end:function(n){l+="</"+n+">"},chars:function(n){l+=n},comment:function(n){l+="<!--"+n+"-->"}});return l};this.HTMLtoBBCode=function(q){var p="";var w=[];var l=0;var t={a:["color","style"],br:[],center:[],div:["class","color","style"],em:[],font:["class","color","style"],img:[],p:["class","color","style"],span:["class","color","style"],strike:[],strong:[],u:[]};var n={a:function(z,C,B){var A=u(C,"href");if(A){node={node:"url",str:"[url="+A.value+"]"}}else{node=false}return node},body:false,br:{node:"br",end:""},center:{node:"center"},div:false,em:{node:"i"},font:false,img:function(z,C,B){var E=u(C,"src");var A=u(C,"width");var D=u(C,"height");if(E){if(A&&D){node={node:"img",str:"[img="+A.escaped+"x"+D.escaped+"]"}}else{node={node:"img",str:"[img]"}}node.str+=E.escaped}return node},p:{node:"p",str:"",end:"[br][br]"},span:false,strike:{node:"s"},strong:{node:"b"},u:{node:"u"}};function r(z){if(z.match(/[0-9.]+pt/i)){return Math.round(z.replace(/^([0-9.]+)pt/i,"$1"))}if(z.match(/[0-9.]+px/i)){return Math.round((z.replace(/^([0-9.]+)px/i,"$1"))*0.75)}if(z.match(/[0-9.]+em/i)){return Math.round((z.replace(/^([0-9.]+)em/i,"$1"))*12)}if(z.match(/[0-9.]+%/i)){return Math.round((z.replace(/^([0-9.]+)%/i,"$1"))/100*12)}var A={xxsmall:8,xsmall:10,small:12,medium:14,large:18,xlarge:24,xxlarge:36};if(A[z.replace(/[^a-zA-Z]/g,"")]){return A[z.replace(/[^a-zA-Z]/g,"")]}return 12}function v(D){var z=[];var C=D.split(";");for(var B=0;B<C.length;B++){var A=C[B].replace(/^([^:]*):(.*)/,"$1").trim();var E=C[B].replace(/^([^:]*):(.*)/,"$2").trim();switch(A){case"font-size":z.push({node:"size",str:"[size="+r(E)+"]"});break;case"font-weight":if(E=="bold"||E=="bolder"||E>=700){z.push({node:"b"})}break;case"color":z.push({node:"color",str:"[color="+E+"]"});break;case"text-align":if(E=="center"||E=="left"||E=="right"||E=="justify"){z.push({node:E})}break;case"text-decoration":if(E=="underline"){z.push({node:"u"})}if(E=="line-through"){z.push({node:"s"})}}}return z}function x(z,B){var A=[];for(var C=0;C<B.length;C++){if(!t[z]){return}if(!y(B[C].name,t[z])){return}switch(B[C].name){case"class":break;case"color":A.push({node:"color",str:"[color="+B[C].value+"]"});break;case"style":A=A.concat(v(B[C].value));break}}return A}function m(z,B,A){switch(typeof n[z]){case"boolean":return false;case"function":return n[z](z,B,A);case"object":return n[z];case"undefined":return{node:"undefined",str:z}}}function y(B,A){var z;for(z in A){if(A[z]==B){return true}}return false}function o(A,z){if(!z){w.push(A)}for(var B=0;B<A.length;B++){if(A[B].node=="undefined"){console.log("Found undefined node [ "+A[B].str+" ]... :(")}else{if(A[B].node=="ignored"){}else{if(typeof A[B].str!="undefined"){p+=A[B].str}else{p+="["+A[B].node+"]"}if(z){if(typeof A[B].end!="undefined"){p+=A[B].end}else{p+="[/"+A[B].node+"]"}}}}}}function s(){var A=w.pop();A.reverse();for(var z=0;z<A.length;z++){if(A[z].node!="undefined"&&A[z].node!="ignored"){if(typeof A[z].end!="undefined"){p+=A[z].end}else{p+="[/"+A[z].node+"]"}}}}function u(A,z){for(var B=0;B<A.length;B++){if(A[B].name==z){return A[B]}}return false}e(q,{start:function(A,D,C){var B=x(A,D);var E=m(A,D,C);var z=[];if(B){z=z.concat(B)}if(!E){E={node:"ignored",str:A}}z=z.concat(E);o(z,C)},end:function(z){s()},chars:function(z){p+=z},comment:function(z){}});while(w.length>0){s()}return p};this.HTMLtoDOM=function(p,s){var o=b("html,head,body,title");var l={link:"head",base:"head"};if(!s){if(typeof DOMDocument!="undefined"){s=new DOMDocument()}else{if(typeof document!="undefined"&&document.implementation&&document.implementation.createDocument){s=document.implementation.createDocument("","",null)}else{if(typeof ActiveX!="undefined"){s=new ActiveXObject("Msxml.DOMDocument")}}}}else{s=s.ownerDocument||s.getOwnerDocument&&s.getOwnerDocument()||s}var m=[],r=s.documentElement||s.getDocumentElement&&s.getDocumentElement();if(!r&&s.createElement){(function(){var u=s.createElement("html");var t=s.createElement("head");t.appendChild(s.createElement("title"));u.appendChild(t);u.appendChild(s.createElement("body"));s.appendChild(u)})()}if(s.getElementsByTagName){for(var n in o){o[n]=s.getElementsByTagName(n)[0]}}var q=o.body;e(p,{start:function(w,v,u){if(o[w]){q=o[w];return}var x=s.createElement(w);for(var t in v){x.setAttribute(v[t].name,v[t].value)}if(l[w]&&typeof o[l[w]]!="boolean"){o[l[w]].appendChild(x)}else{if(q&&q.appendChild){q.appendChild(x)}}if(!u){m.push(x);q=x}},end:function(t){m.length-=1;q=m[m.length-1]},chars:function(t){q.appendChild(s.createTextNode(t))},comment:function(t){}});return s};function b(o){var n={},l=o.split(",");for(var m=0;m<l.length;m++){n[l[m]]=true}return n}})();
