﻿//
//  AGENTSTORY - ELEMENT  EDITOR
//
function StoryElementEditor(aID,aGUID,aSrcTxt)
{
    var _id = aID;
    var _guid = aGUID;
    
    var _srcTxt = aSrcTxt;
    
    //var _txtDesc = document.createTextNode(aGUID);
    //var _txtLabel = document.createElement("DIV");
    //_txtLabel.appendChild(_txtDesc);
    
    var _txtArea = TheUte().getTextArea("","mainEditor",null,null,null);
    _txtArea.value = aSrcTxt.value;
    
    this.id = _id;
    this.GUID = aGUID;
    this.srcTXT = _srcTxt;
    
    var _container = document.createElement("DIV");
    
    this.getContainer = function()
    {
        return _container;
    }
    
    this.focus = function()
    {
        try
        {
            _txtArea.focus();
        }
        catch(e)
        {
            //too bad
        }
    }
    
    this.init = function(dvAttachPoint)
    {
        _container.className = "clsSEE";

//        _container.appendChild(_txtLabel);
       
        
        var cmdSave = TheUte().getButton("cmdSave","Save","save",null,"clsActionButton");
        _container.appendChild(cmdSave);
        
        cmdSave.onclick = function ()
        {
         
            var editorContent = tinyMCE.get('mainEditor').getContent();
           _srcTxt.value = editorContent;
           storyView.saveCurrentElement();
           storyView.unHaze();
           
        }
        
        var cmdCancel = TheUte().getButton("cmdCxl","Cancel","cancel",null,"clsActionButton");
        _container.appendChild(cmdCancel);
        
         
        
        cmdCancel.onclick = function ()
        {
           storyView.unHaze();
        }
        
        _container.appendChild(_txtArea);
        dvAttachPoint.appendChild( _container );
        
          try
         {     
               tinyMCE.init({
		        mode : "exact",
		        elements:"mainEditor",
		        theme : "advanced",
		        //auto_resize: true,
		        width: 640,
		        height: 480
	            });
	    }
	    catch(e)
	    {
	        alert("tinyMCE error: " + e.description);
	    }
	    
   }
}