HTMLArea.loadPlugin("TableOperations");
HTMLArea.loadPlugin("ContextMenu");

function initHTMLArea() {         
        var config = null;
        config = new HTMLArea.Config();
        config.toolbar = [
        ["fontname","fontsize","bold","italic","underline","separator", 
        "justifyleft", "justifycenter","justifyright","separator",
        "insertunorderedlist", "insertorderedlist","separator", 
        "forecolor","hilitecolor","separator",
        "createlink","inserttable","htmlmode","separator",
        "undo","redo","separator",
        "popupeditor"]];

        config.fontname = {
                "Arial":           'arial,helvetica,sans-serif',
                "Courier New":     'courier new,courier,monospace',
                "Times New Roman": 'times new roman,times,serif',
                "Verdana":         'verdana,arial,helvetica,sans-serif'
        };

        config.fontsize = {
                "1 (8 pt)":  "1",
                "2 (10 pt)": "2",
                "3 (12 pt)": "3",
                "4 (14 pt)": "4",
                "5 (18 pt)": "5"
        };

//If you want the style/layout to be the same as in your stylesheet for your theme...
//Make shure your index is 0 (the first loaded stylesheet?) or use an id.
//        config.pageStyle = document.styleSheets(0).cssText;
        config.pageStyle = "body { background-color: #FFFFFF; font-family: times new roman; font-size:10pt}";
        config.TDStyle = 'font-family: "times new roman"; font-size: "10pt";';
        
//mimic the replaceAll function of htmlArea.
//Reason: The replace all function doesnt work when using plugins, might change in release version
        var mytas = null;
        mytas = document.getElementsByTagName("textarea"); 
        var pluginregistered=new Boolean;
        for (var i = 0; i < mytas.length; i++) { 
                
                if(mytas[i].name.indexOf("lng_edit")<0){ //leave out language edit textbox
//First, check the number of rows. If less than 10 there will be almost nowhere to write
//Dependent on how many rows your toolbar is (3 in this case).
                                if(mytas[i].rows<10){
                                        mytas[i].rows=10;}
                        editor = new HTMLArea(mytas[i], config); 
                        if(pluginregistered==false){ 
//We can only register once, else it appears multiple times, might be due to a bug in htmlarea
//or by design, might change later in release version. Only applies to TableOperations!
                                editor.registerPlugin(TableOperations);

                                pluginregistered=true;
                        } 
                        editor.registerPlugin(ContextMenu); //Must be registered for each htmlarea
                        editor.generate();
                }
        }
}

