function awebitor(B,D){var A=this;A.doc=document;A.win=window;if(!B){return false}if(typeof (B)=="string"){A.textarea=A.doc.getElementById(B);if(!A.textarea){return false}}else{A.textarea=B}if(A.textarea.tagName.toLowerCase()!="textarea"){return false}A.name="Awebitor";A.version=1.51;A.build=20080827;A.prefixes={"class":"awebitor-",uid:"awebitor-",createprompt:"prompt-"};A.path_base="/files/mihai-projects/awebitor";A.messages={"unsupported-confirmation":"The web browser you use does not seem capable of advanced page editing!\n\nWould you like to try to activate WYSIWYG editing?","feature-not-supported":"was not found","loadInterface-error":"Failure while trying to load the interface. Maybe there is no support for XMLHttpRequest.","xhrStatus-error":"The interface could not be loaded (status error).","exception-error":"Fatal error! Will try to revert back to the initial state.","responseXML-error":"No responseXML found after loading the interface!","interfaceElements-error":"An element was not found in the editor interface.","execCommand-error":"This command does not work in this web browser.","importNode-error":"Error while importing the interface into this document.","prompt-createlink":"Type in the address for the link:","prompt-addimage-url":"Type in the address of the image:","prompt-addimage-alt":"(Optional) Type in the alternative text of the image:","prompt-addimage-float":"(Optional) Image alignment:\n1 - Left\n2 - Right","prompt-addimage-link":"(Optional) If you want to link this image to a page, type the address:","createtable-cols":"Create table. The number of columns:","createtable-rows":"Create table. The number of rows:","error-noiframe":"The editor cannot find the iframe. Trying to revert back to the initial state.","addimage-url-required":"The image cannot be added. The address is required!","iframe-timeout":"The editor frame failed to initialize within the allowed time interval.","iframe-timeout-recovery":"The editor frame failed to continue the initialization within the allowed time interval. Initialization will now manually continue."};A.config={"interface":A.path_base+"/interface.xhtml",unsupported:3,verbose:true,css:A.path_base+"/interface.css",init_delay:1000,autofocus:true,iframe_file:false,iframe_id:false,iframe_timeout:10000,iframe_recovery:true,"colorpicker-row":"tr","colorpicker-col":"td","colorpicker-nrcols":10,"colorpicker-list":["#ffffff","#ffcccc","#ffcc99","#ffff99","#ffffcc","#90ff99","#99ffff","#ccffff","#ccccff","#ffccff","#cccccc","#ff6666","#ff9966","#ffff66","#ffff33","#66ff99","#33ffff","#66ffff","#9999ff","#ff99ff","#c0c0c0","#ff0000","#ff9900","#ffcc66","#ffff00","#33ff33","#66cccc","#33ccff","#6666cc","#cc66cc","#999999","#cc0000","#ff6600","#ffcc33","#ffcc00","#33cc00","#00cccc","#3366ff","#6633ff","#cc33cc","#666666","#990000","#cc6600","#cc9933","#999900","#009900","#339999","#3333ff","#6600cc","#993399","#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366","#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"]};A.failure=false;A.loaded=false;A.xmlhttp=false;A.supported=false;A.iframe=false;A.ifdoc=false;A.ifwin=false;A.container=false;A.rdoc=false;A.elems={};A.recovery_rem_elems={};A.customFunctions={};A.customFunctions.postInitIframe={colorpicker:function(J){if(!J||!J.ids.colorpicker||!J.ids.colorpicker["elem"]){return false}var I=J.ids.colorpicker["elem"],E,H,K,G,F;for(H in J.config["colorpicker-list"]){F=J.config["colorpicker-list"][H];if(!K||E==J.config["colorpicker-nrcols"]){E=0;K=J.doc.createElement(J.config["colorpicker-row"]);I.appendChild(K)}G=J.doc.createElement(J.config["colorpicker-col"]);G.title=F;G.style.backgroundColor=F;G.addEventListener("click",J.actions.changecolor,false);K.appendChild(G);E++}return true}};A.init=function(){if(!A.textarea){return false}if(!A.textarea.id){var J=new Date();var F=J.getMilliseconds()+Math.round(Math.random()*20);if(A.doc.getElementById(A.prefixes.uid+F)){F++}A.textarea.id=A.prefixes.uid+F+"-ta";A.prefixes.id=A.prefixes.uid+F+"-"}else{A.prefixes.id=A.prefixes.uid+A.textarea.id+"-"}if(A.config.unsupported!=0){A.supported=A.check_support();if(A.supported==false&&A.config.unsupported==2){A.failure=true;return false}if(A.supported==false&&A.config.unsupported==3){var I=A.messages["unsupported-confirmation"];if(A.config.verbose){var H=A.unsupported.length;I+="\n";for(var G=0;G<H;G++){I+="\n"+A.unsupported[G]+": "+A.messages["feature-not-supported"]}}if(!confirm(I)){A.failure=true;return false}}}A.elems.css=A.doc.getElementById(A.prefixes.uid+"css");if(A.config.css&&!A.elems.css){var E=A.doc.getElementsByTagName("head")[0];A.elems.css=A.doc.createElement("link");A.elems.css.id=A.prefixes.uid+"css";A.elems.css.setAttribute("rel","stylesheet");A.elems.css.setAttribute("href",A.config.css);A.elems.css.setAttribute("type","text/css");E.appendChild(A.elems.css);A.recovery_rem_elems.css=A.elems.css}var K=A.loadInterface();if(!K){A.recoverError(1,A.messages["loadInterface-error"]);return false}A.textarea._awebitorObj=A;return true};A.loadInterface=function(){try{A.xmlhttp=new XMLHttpRequest()}catch(E){return false}A.xmlhttp.onreadystatechange=A.interfaceReady;try{A.xmlhttp.open("GET",A.config["interface"]);A.xmlhttp.send("")}catch(E){return false}return true};A.interfaceReady=function(){if(A.failure||A.xmlhttp.readyState!=4){return false}if(A.xmlhttp.status!=200){if(A.config.verbose){alert(A.messages["xhrStatus-error"])}return false}A.rdoc=A.xmlhttp.responseXML;if(!A.rdoc||!A.rdoc.getElementById){A.recoverError(1,A.messages["responseXML-error"]);return false}A.container=A.doc.createElement("div");A.container.id=A.prefixes.id+"container";A.container.className=A.prefixes["class"]+"container";try{A.init_elems()}catch(E){A.recoverError(1,E);return false}if(A.failure){return false}A.iframe._awebitorObj=A;if(A.config.iframe_file){if(A.config.iframe_id&&A.textarea.id){A.iframe.src=A.config.iframe_file+A.textarea.id}else{A.iframe.src=A.config.iframe_file}}A.textarea.style.display="none";A.container=A.textarea.parentNode.insertBefore(A.container,A.textarea);A.recovery_rem_elems.container=A.container;if(!A.config.iframe_file){setTimeout(A.init_iframe,A.config.init_delay)}else{setTimeout(A.check_init_iframe,A.config.iframe_timeout)}return true};A.init_elems=function(){if(A.failure||!A.rdoc){return false}A.runCustomFunctions("preInitElems");var J,H,F=A.rdoc.documentElement;for(J in A.ids){A.ids[J]=A.populate_obj(A.default_id_params,A.ids[J])}for(J in A.ids){H=A.rdoc.getElementById(J);if(!H){A.recoverError(1,A.messages["interfaceElements-error"]);return false}H.id=A.prefixes.id+J;if(A.ids[J]["genClass"]){A.classNameAdd(H,J)}if(A.ids[J]["genTitle"]){H.title=H.textContent}}var G,E=F.childNodes.length,I=A.prefixes.id+"iframe";for(G=0;G<E;G++){H=A.doc.importNode(F.childNodes.item(G),true);if(!H){A.recoverError(1,A.messages["importNode-error"]);return false}if(H.id==I){A.iframe=A.container.appendChild(H)}else{A.container.appendChild(H)}}return true};A.init_iframe=function(){if(A.failure){return false}if(!A.iframe||!A.iframe.contentWindow||!A.iframe.contentWindow.document){A.recoverError(1,A.messages["error-noiframe"]);return false}A.ifwin=A.iframe.contentWindow;A.ifdoc=A.ifwin.document;A.ifwin._awebitorObj=A;if(!A.config.iframe_file){try{A.ifdoc.body.innerHTML=A.textarea.value;A.ifdoc.designMode="on"}catch(G){A.recoverError(1,G);return false}A.ifwin._awebitorFunctions={getSource:function(){return A.ifdoc.body.innerHTML},setSource:function(I){A.ifdoc.body.innerHTML=I;return true}}}var H,F,E;for(H in A.ids){F=A.doc.getElementById(A.prefixes.id+H);if(!F){A.recoverError(1,A.messages["interfaceElements-error"]+"\n init_iframe \n"+H);return false}F._awebitorAction=H;A.ids[H]["elem"]=F;if(!A.ids[H]["keepID"]){F.removeAttribute("id")}if(A.ids[H]["actions"]){for(E in A.ids[H]["actions"]){if(A.ids[H]["actions"][E]){F.addEventListener(E,A.ids[H]["actions"][E],false)}}}}if(A.textarea.form){A.textarea.form.addEventListener("submit",A.formSubmit,false)}A.runCustomFunctions("postInitIframe");if(A.config.autofocus){A.ifwin.focus()}A.loaded=true;A.rdoc=null;A.xmlhttp=null;delete A.rdoc;delete A.xmlhttp;return true};A.check_init_iframe=function(){if(!A.loaded&&A.config.iframe_file&&!A.failure){if(A.config.iframe_recovery){if(A.config.verbose){alert(A.messages["iframe-timeout-recovery"])}A.config.iframe_file=false;A.init_iframe()}else{A.recoverError(1,A.messages["iframe-timeout"])}return false}return true};A.runCustomFunctions=function(G){var F,E;if(A.customFunctions[G]){for(F in A.customFunctions[G]){E=A.customFunctions[G][F];E(A)}}return true};A.populate_obj=function(G,E){var F;for(F in G){if(E[F]==undefined){E[F]=G[F]}else{if(typeof (E[F])=="object"&&typeof (G[F])=="object"){E[F]=A.populate_obj(G[F],E[F])}}}return E};A.formSubmit=function(){if(A.failure||!A.loaded){return false}if(A.actions&&A.actions.viewsource&&A.actions.viewsource.enabled){A.actions.viewsource()}A.textarea.value=A.ifwin._awebitorFunctions.getSource()};A.check_support=function(){var F=14,H=0,G=[],E=0;if(window.XMLHttpRequest){H++}else{G[E++]="XMLHttpRequest"}if(document.appendChild){H++}else{G[E++]="appendChild"}if(document.createElement){H++}else{G[E++]="createElement"}if(document.createTextNode){H++}else{G[E++]="createTextNode"}if(document.importNode){H++}else{G[E++]="importNode"}if(document.designMode){H++}else{G[E++]="designMode"}if(window.getComputedStyle){H++}else{G[E++]="getComputedStyle"}if(document.childNodes){H++}else{G[E++]="childNodes"}if(document.body.setAttribute){H++}else{G[E++]="setAttribute"}if(document.body.getAttribute){H++}else{G[E++]="getAttribute"}if(document.execCommand){H++}else{G[E++]="execCommand"}if(window.setTimeout){H++}else{G[E++]="setTimeout"}if(document.getElementsByTagName){H++}else{G[E++]="getElementsByTagName"}if(document.documentElement.innerHTML){H++}else{G[E++]="innerHTML"}A.capabilitiesMax=F;A.capabilities=H;A.unsupported=G;if(H>=F){return true}else{return false}};A.recoverError=function(I,H){if(A.failure||A.loaded){return false}if(A.config.verbose&&I&&H){alert(A.messages["exception-error"]+"\n\n"+H)}A.failure=true;var F,E,G;if(I==1){if(A.textarea){A.textarea.style.display=""}for(F in A.recovery_rem_elems){E=A.recovery_rem_elems[F];if(E.style){E.style.display="none"}G=E.parentNode;if(G&&G.removeChild){G.removeChild(E)}}delete A.textarea._awebitorObj}return true};A.str2html=function(E){if(!E){return E}E=E.replace(/\"/g,"&quot;");E=E.replace(/&/g,"&amp;");E=E.replace(/\'/g,"&#039;");E=E.replace(/</g,"&lt;");E=E.replace(/>/g,"&gt;");return E};A.trim=function(E){if(!E||!E.replace){return E}return E.replace(/^\s+/,"").replace(/\s+$/,"")};A.classNameAdd=function(H,F){if(!H||!F){return false}if(typeof F=="string"){F=[F]}if(!F.length||!(F instanceof Array)){return false}if(!H.className){H.className=A.prefixes["class"]+F.join(" "+A.prefixes["class"]);return true}var L=H.className.split(/\s+/),J,G,I,M,K=false,E="";if(!L){return false}I=L.length;G=F.length;for(J=0;J<G;J++){K=false;F[J]=A.prefixes["class"]+F[J];for(M=0;M<I;M++){if(L[M]==F[J]){K=true;break}}if(!K){E+=" "+F[J]}}if(E!=""){E=A.trim(H.className)+" "+A.trim(E)}H.className=E.replace(/\s+/," ");return true};A.classNameRemove=function(G,H){if(!G||!H){return false}if(typeof H=="string"){H=[H]}if(!H.length||!(H instanceof Array)){return false}var E=new RegExp("(^|\\s)("+A.prefixes["class"]+H.join("|"+A.prefixes["class"])+")(\\s|$)","ig");var F=A.trim(G.className.replace(E," ")).replace(/\s+/," ");G.className=F;return true};A.toString=function(){return A.name+" "+A.version+" ("+A.build+") by ROBO Design. See http://www.robodesign.ro for more information."};A.actions={mousedown:function(E){if(A.actions.mousedown.target){A.classNameRemove(A.actions.mousedown.target,"mousedown")}if(!A||this.disabled){A.actions.mousedown.target=false;return false}A.actions.mousedown.target=this;A.classNameAdd(this,"mousedown");return true},mouseup:function(E){if(A.actions.mousedown.target){A.classNameRemove(A.actions.mousedown.target,"mousedown")}A.actions.mousedown.target=false;if(!A||this.disabled){return false}A.classNameRemove(this,"mousedown");return true},mouseover:function(){if(!A||this.disabled||!this.title||!A.ids.tooltiptext||!A.ids.tooltiptext["elem"]){return false}var E=A.ids.tooltiptext["elem"];A.tooltiptext=E.textContent;if(E.firstChild){E.removeChild(E.firstChild)}E.appendChild(A.doc.createTextNode(this.title));return true},mouseout:function(){if(!A||this.disabled){return false}var E=A.ids.tooltiptext["elem"];if(E.firstChild){E.removeChild(E.firstChild)}if(!A.tooltiptext||A.tooltiptext=="undefined"){A.tooltiptext="."}E.appendChild(A.doc.createTextNode(A.tooltiptext));return true},execCommand:function(){if(this.disabled||!this._awebitorAction||!A.ids[this._awebitorAction]||!A.ids[this._awebitorAction]["execCommand"]){return false}try{A.ifdoc.execCommand(A.ids[this._awebitorAction]["execCommand"],false,null)}catch(E){if(A.config.verbose){alert(A.messages["execCommand-error"])}return false}A.ifwin.focus();return true},addimage:function(){if(this.disabled||!A||!A.ids||!A.elems){return false}var F=prompt(A.messages["prompt-addimage-url"],"http://");if(!F||F.length<2||F.toLowerCase()=="http://"){return false}var I=prompt(A.messages["prompt-addimage-alt"]),E=parseInt(prompt(A.messages["prompt-addimage-float"])),J=prompt(A.messages["prompt-addimage-link"]);var G='<img src="'+F+'"';if(I){G+=' alt="'+A.str2html(I)+'"'}if(E&&(E==1||E==2)){if(E==1){E="left"}else{E="right"}G+=' style="float: '+E+'"'}G+=">";if(J){G='<a href="'+A.str2html(J)+'">'+G+"</a>"}try{A.ifdoc.execCommand("inserthtml",false,G)}catch(H){if(A.config.verbose){alert(A.messages["execCommand-error"])}return false}return true},createprompt:function(){if(this.disabled||!this._awebitorAction||!A.ids[this._awebitorAction]){return false}var E=A.ids[this._awebitorAction]["execCommand"],H=A.ids[this._awebitorAction]["defaultValue"];if(!E||!H){return false}var G=prompt(A.messages[A.prefixes.createprompt+E],H);if(G!=null&&G!=""&&G!=H){try{A.ifdoc.execCommand(E,false,G)}catch(F){if(A.config.verbose){alert(A.messages["execCommand-error"])}return false}}A.ifwin.focus();return true},selectchange:function(){if(this.disabled||!this._awebitorAction||!A.ids[this._awebitorAction]||this.nodeType!=1||this.nodeName!="select"){return false}var G=A.ids[this._awebitorAction]["execCommand"],F=this.selectedIndex;var E=this.options[F];if(!E||E.disabled){return false}try{A.ifdoc.execCommand(G,false,E.value);this.selectedIndex=0}catch(H){if(A.config.verbose){alert(A.messages["execCommand-error"])}return false}A.ifwin.focus();return true},viewsource:function(){var H,F,E=A.iframe.parentNode,G=A.actions.viewsource;if(G.enabled){A.ifwin._awebitorFunctions.setSource(G.enabled.value);E.removeChild(G.enabled);G.enabled=false;A.iframe.style.display="block";A.ifwin.focus()}else{G.enabled=A.doc.createElement("textarea");G.enabled.value=A.ifwin._awebitorFunctions.getSource();G.enabled.className=A.prefixes["class"]+"src";E.insertBefore(G.enabled,A.iframe);A.iframe.style.display="none";if(A.ids.colorpicker&&A.ids.colorpicker["elem"]){F=A.ids.colorpicker["elem"];F.style.display="none";if(F._awebitorColorPickerElem){H=A.ids[F._awebitorColorPickerElem];if(H&&H.elem){A.classNameRemove(H.elem,"button-active")}}}if(A.elems["addImgBox-cancel"]&&A.elems["addImgBox-cancel"]._awebitorCallback){A.elems["addImgBox-cancel"]._awebitorCallback()}G.enabled.focus()}for(H in A.ids){F=A.ids[H]["elem"];if(!F||A.ids[H]["type"]!="button"){continue}if(H=="vsource"){if(G.enabled){A.classNameAdd(F,"button-active")}else{A.classNameRemove(F,"button-active")}continue}F.disabled=G.enabled?true:false;if(G.enabled){A.classNameAdd(F,"button-disabled")}else{A.classNameRemove(F,"button-disabled")}}return true},colorpicker:function(){if(this.disabled||!this._awebitorAction||!A.ids[this._awebitorAction]||!A.ids.colorpicker||!A.ids.colorpicker["elem"]){return false}var F=A.ids.colorpicker["elem"];if(F._awebitorColorPickerElem){var E=A.ids[F._awebitorColorPickerElem];if(E&&E.elem){A.classNameRemove(E.elem,"button-active")}}if(F.style.display!="none"&&F._awebitorColorPicker==A.ids[this._awebitorAction]["execCommand"]){F.style.display="none";A.classNameRemove(this,"button-active");return true}A.classNameAdd(this,"button-active");F.style.top=(this.offsetHeight+this.parentNode.offsetHeight)+"px";F.style.left=this.offsetLeft+"px";F.style.display="table";F._awebitorColorPicker=A.ids[this._awebitorAction]["execCommand"];F._awebitorColorPickerElem=this._awebitorAction;return true},changecolor:function(){if(!this.title||!A.ids.colorpicker||!A.ids.colorpicker["elem"]){return false}var F=A.ids.colorpicker["elem"],I=this.title;if(!F._awebitorColorPicker||!I||F.disabled|!F._awebitorColorPickerElem){return false}var E=A.ids[F._awebitorColorPickerElem];if(E&&E.elem){A.classNameRemove(E.elem,"button-active")}var G=F._awebitorColorPicker;F.style.display="none";try{A.ifdoc.execCommand(G,false,I)}catch(H){if(A.config.verbose){alert(A.messages["execCommand-error"])}return false}A.ifwin.focus()},createtable:function(){if(this.disabled){return false}var I=parseInt(prompt(A.messages["createtable-cols"]));if(!I){return false}var G=parseInt(prompt(A.messages["createtable-rows"])),F='<table border="1">',J,E;if(!G||isNaN(I)||isNaN(G)||I<1||G<1){return false}for(E=0;E<G;E++){F+="<tr>";for(J=0;J<I;J++){F+="<td>&nbsp;</td>"}F+="</tr>"}try{A.ifdoc.execCommand("inserthtml",false,F)}catch(H){if(A.config.verbose){alert(A.messages["execCommand-error"])}return false}A.ifwin.focus();return true}};A.default_id_params={genClass:true,genTitle:true,keepID:false,type:"button",actions:{mousedown:A.actions.mousedown,mouseup:A.actions.mouseup,mouseover:A.actions.mouseover,mouseout:A.actions.mouseout,click:A.actions.execCommand}};A.ids={iframe:{genTitle:false,actions:false,keepID:true,type:"misc"},colorpicker:{genTitle:false,actions:false,type:"misc"},tooltiptext:{genTitle:false,actions:false,type:"misc"},vsource:{actions:{click:A.actions.viewsource}},undo:{execCommand:"undo"},redo:{execCommand:"redo"},link:{execCommand:"createlink",defaultValue:"http://",actions:{click:A.actions.createprompt}},unlink:{execCommand:"unlink"},remformat:{execCommand:"removeformat"},hr:{execCommand:"inserthorizontalrule"},image:{actions:{click:A.actions.addimage}},table:{actions:{click:A.actions.createtable}},style:{genTitle:false,genClass:false,execCommand:"formatblock",actions:{mousedown:false,mouseup:false,click:false,change:A.actions.selectchange}},font:{genTitle:false,genClass:false,execCommand:"fontname",actions:{mousedown:false,mouseup:false,click:false,change:A.actions.selectchange}},fontSize:{genTitle:false,genClass:false,execCommand:"fontsize",actions:{mousedown:false,mouseup:false,click:false,change:A.actions.selectchange}},strong:{execCommand:"bold"},emphasize:{execCommand:"italic"},underline:{execCommand:"underline"},strikethrough:{execCommand:"strikethrough"},superscript:{execCommand:"superscript"},subscript:{execCommand:"subscript"},textColor:{execCommand:"forecolor",actions:{click:A.actions.colorpicker}},bgrColor:{execCommand:"hilitecolor",actions:{click:A.actions.colorpicker}},aLeft:{execCommand:"justifyleft"},aCenter:{execCommand:"justifycenter"},aRight:{execCommand:"justifyright"},aJustify:{execCommand:"justifyfull"},OL:{execCommand:"insertorderedlist"},UL:{execCommand:"insertunorderedlist"},outdent:{execCommand:"outdent"},indent:{execCommand:"indent"}};if(D){try{return A.init()}catch(C){A.recoverError(1,C);return false}}}window.addEventListener("load",function(){new awebitor("awebitorta",true)},false);
