var Fse; if (!Fse) Fse = {};

if( !Fse.Cms ) Fse.Cms = {};

Fse.Cms.editContent = function ( sTextToEditId ) {
    
    var oDiv = document.getElementById( sTextToEditId );
    var sBasePath = document.location.pathname.substring(0,document.location.pathname.lastIndexOf("apps/")) + "portal/scripts/fckeditor/";
    
    var oFCKeditor = new FCKeditor( sTextToEditId ) ;
    oFCKeditor.BasePath	= sBasePath;
    oFCKeditor.Config["CustomConfigurationsPath"] = "../fse.js";
    oFCKeditor.DocType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    /*
    var aCSSResources = [
      "/fse/salesteamportal/customculinary/resources/core/css/stylesheet.css" ,
      "/fse/salesteamportal/customculinary/resources/custom/css/stylesheet.css"
    ];
    oFCKeditor.Config["EditorAreaCSS"] = aCSSResources; // this doesn't seem to have the desired effect
    */
    oFCKeditor.Config["EditorAreaCSS"] = "/fse/salesteamportal/customculinary/resources/custom/css/stylesheet.css"; // other style sheets must be imported into this one
    oFCKeditor.ToolbarSet = "FSE";
    oFCKeditor.Value = oDiv.innerHTML;
    oFCKeditor.Height = 700;
    oDiv.innerHTML = oFCKeditor.CreateHtml();

    var fnSaveContent = function () { Fse.Cms.saveContent( sTextToEditId ); };

    var oButton = document.getElementById( sTextToEditId + "-button" );
    
    oButton.onclick = fnSaveContent;
    oButton.value = "Save Changes";

};

Fse.Cms.saveContent = function ( sTextToEditId, sSaveButtonId ) {
    var oButton = document.getElementById( sSaveButtonId );
    oButton.onclick = function() { Fse.Cms.editContent( sTextToEditId ); };
    oButton.value = "Edit Content";
    var oDiv = document.getElementById( sTextToEditId );
    var oEditor = FCKeditorAPI.GetInstance( sTextToEditId );
    oDiv.innerHTML = oEditor.GetXHTML( false );
};


Fse.Cms.editContent = function ( sTextToEditId, sScriptURLBase, sStylesheetURL, sSaveButtonId ) {
    
    var oDiv = document.getElementById( sTextToEditId );
    var sBasePath = sScriptURLBase + "/_js/lib/fckeditor/";
    
    var oFCKeditor = new FCKeditor( sTextToEditId ) ;
    oFCKeditor.BasePath	= sBasePath;
    oFCKeditor.DocType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    oFCKeditor.Config["EditorAreaCSS"] = sStylesheetURL; // other style sheets must be imported into this one
    oFCKeditor.ToolbarSet = "FSEProfileEdit";
    oFCKeditor.Value = oDiv.innerHTML;
    oFCKeditor.Height = 700;
    oDiv.innerHTML = oFCKeditor.CreateHtml();

    var fnSaveContent = function () { Fse.Cms.saveContent( sTextToEditId, sSaveButtonId ); };

    var oButton = document.getElementById( sSaveButtonId );
    
    oButton.onclick = fnSaveContent;
    oButton.value = "Save Changes";

};
