function FbHtmlHelper(b){var c=this;c.target_textarea=document.getElementById(b.textarea);c.target_div=document.getElementById(b.div);c.target_popup=document.getElementById(b.popup);c.show_link=document.getElementById(b.link);c.show_link.onclick=function(){c.show();return false};this.get_selection=function(){var h=c.target_textarea;return h.value.substring(h.selectionStart,h.selectionEnd)};if(document.selection){this.get_selection=function(){return document.selection.createRange().text}}this.hide=function(){slide_elt(c.target_div.id,false);c.show_link.onclick=function(){c.show();return false}};this.show=function(){slide_elt(c.target_div.id,true);c.show_link.onclick=function(){c.hide();return false}};this.replace_with=function(i,h){var j=c.target_textarea.value;if((i=="")||(j.lastIndexOf(i)==-1)){alert("No editable text selected; can't alter!");return false}c.target_textarea.value=j.replace(i,h)};this.pop_prompt=function(h,s){var j=c.target_popup;if((j.childNodes)&&(j.childNodes.length>0)){var o=0;for(o=j.childNodes.length;o>0;o--){j.removeChild(j.childNodes[o-1])}}var r=document.createElement("div");var q=document.createElement("form");var n=document.createElement("input");n.setAttribute("type","text");n.setAttribute("id","hhpp_input");var m=document.createElement("label");m.setAttribute("for","hhpp_input");m.innerHTML=h;var k=document.createElement("input");k.setAttribute("type","submit");k.setAttribute("id","hhpp_submit");k.setAttribute("value","OK");q.appendChild(m);q.appendChild(n);q.appendChild(k);q.onsubmit=s;r.appendChild(q);j.appendChild(r);j.className="popped";j.style.opacity=0;j.style.display="";fade_to(c.target_popup.id,40,0.2,1)};this.fade_prompt=function(){var h=c.target_popup;h.style.display="none";h.className="";fade_to("main",75,0.2,1)};this.make_bold=function(){var h=c.get_selection();c.replace_with(h,"<strong>"+h+"</strong>")};this.make_italic=function(){var h=c.get_selection();c.replace_with(h,"<em>"+h+"</em>")};this.make_underline=function(){var h=c.get_selection();c.replace_with(h,"<u>"+h+"</u>")};this.make_spoiler=function(){var h=c.get_selection();c.replace_with(h,"<spoiler>"+h+"</spoiler>")};this.make_link=function(i,j){var h=c.get_selection();if((!i)&&(!h.match(/http/))){c.pop_prompt("URL?",function(){var k=document.getElementById("hhpp_input");if(!k.value.match(/http/)){alert("Invalid URL, please try again");return false}else{c.fade_prompt();c.make_link(k.value)}return false});return false}else{if(!i){i=h}}if((!j)&&((h=="")||(h==i))){c.pop_prompt("Link text?",function(){var k=document.getElementById("hhpp_input");c.fade_prompt();c.make_link(i,k.value);return false});return false}else{if(!j){j=h}}if(j==""){j=i}if(i.indexOf('"')!=-1){i=i.replace('"','\\"')}if(h==""){c.target_textarea.value=c.target_textarea.value+'<a href="'+i+'">'+j+"</a>"}else{c.replace_with(h,'<a href="'+i+'">'+j+"</a>")}return false};c.target_div.style.display="none";var e=document.createElement("input");e.setAttribute("type","button");e.setAttribute("style","font-weight: bold;");e.onclick=function(){c.make_bold();return false};e.setAttribute("value","embolden");var g=document.createElement("input");g.setAttribute("style","font-style: italic;");g.setAttribute("type","button");g.onclick=function(){c.make_italic();return false};g.setAttribute("value","italicize");var f=document.createElement("input");f.setAttribute("style","text-decoration: underline;");f.setAttribute("type","button");f.onclick=function(){c.make_underline();return false};f.setAttribute("value","underline");var d=document.createElement("input");d.setAttribute("style","font: monospace;");d.setAttribute("type","button");d.onclick=function(){c.make_link();return false};d.setAttribute("value","linkify");var a=document.createElement("input");a.setAttribute("style","");a.setAttribute("type","button");a.onclick=function(){c.make_spoiler();return false};a.setAttribute("value","mark spoiler");c.target_div.appendChild(e);c.target_div.appendChild(document.createTextNode(" - "));c.target_div.appendChild(g);c.target_div.appendChild(document.createTextNode(" - "));c.target_div.appendChild(f);c.target_div.appendChild(document.createTextNode(" - "));c.target_div.appendChild(d);c.target_div.appendChild(document.createTextNode(" - "));c.target_div.appendChild(a);c.target_div.className="htmlhelper"}function make_htmlhelper(b,a){window.ferretbrain.htmlhelper=new FbHtmlHelper(b,a);window.ferretbrain.htmlhelper.show();return false};