HTMLArea.loadPlugin("TableOperations");
HTMLArea.loadPlugin("ContextMenu");

function initHTMLArea() {
	HTMLArea.agt = navigator.userAgent.toLowerCase();
	HTMLArea.is_ie	   = ((HTMLArea.agt.indexOf("msie") != -1) && (HTMLArea.agt.indexOf("opera") == -1) && (HTMLArea.agt.indexOf("mac") == -1));
	HTMLArea.is_opera  = (HTMLArea.agt.indexOf("opera") != -1);
	HTMLArea.is_mac	   = (HTMLArea.agt.indexOf("mac") != -1);
	HTMLArea.is_mac_ie = (HTMLArea.is_ie && HTMLArea.is_mac);
	HTMLArea.is_win_ie = (HTMLArea.is_ie && !HTMLArea.is_mac);
	HTMLArea.is_gecko  = (HTMLArea.agt.indexOf('gecko') != -1 && HTMLArea.agt.indexOf('safari') == -1);
	HTMLArea.is_gecko  = (HTMLArea.agt.indexOf('gecko') != -1 && HTMLArea.agt.indexOf('icab') == -1);
      
        var config = null;
        config = new HTMLArea.Config();
        config.toolbar = [
        ["formatblock","fontsize","bold","italic","underline","separator", 
        "justifyleft", "justifycenter","justifyright","separator",
        "insertunorderedlist", "insertorderedlist","separator", 
        "forecolor","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 = {
                "Small":  "1",
                "Normal": "2",
                "Large": "3"
        };

	config.formatblock = {
		"Normal": "p",		
		"Staff Title": "h1",
		"Header": "h3",
		"Sub-Header": "h2",
		"Note": "h4",
		"Alert": "h5"

	};

//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.

	if (HTMLArea.is_ie) {
		config.pageStyle = document.styleSheets[0].cssText;
	}
	else if (HTMLArea.is_gecko) {
		var geckoPageStyle = null;
		geckoPageStyle="body{background-color:#FFFFFF;color:#003366;font-size: 10px;font-family:Verdana,Arial,Helvetica,sans-serif;padding:10px 0px;margin:0px;}";
		geckoPageStyle=geckoPageStyle + "h1{font-family:Verdana,Arial,Helvetica,sans-serif;font-weight:bold;font-size:.9em;color: #990000;display:inline}";
		geckoPageStyle=geckoPageStyle + "h2 {font-family:Verdana,Arial,Helvetica,sans-serif;font-weight:bold;font-size:12px;color:#003366;}";
		geckoPageStyle=geckoPageStyle + "h3 {font-family:Verdana,Arial,Helvetica,sans-serif;font-weight:bold;font-size:14px;color:#003366;}";
		geckoPageStyle=geckoPageStyle + "h4 {font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;font-style:italic;font-weight:normal;color:#003366;}";
		geckoPageStyle=geckoPageStyle + "h5 {font-family:Verdana,Arial,Helvetica,sans-serif;font-size:14px;font-weight:bold;color:#990000;}";
		config.pageStyle=geckoPageStyle
		//config.pageStyle=document.styleSheets[0].cssRules;
	}
      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();
                }
        }
}