Direct data into texteditor?!?

I have found a texteditor script on the net (SimpleTextEditor) which is working just great allthough I want to develop an upload form for images instead of just inserting an imageurl, but am banging my head to a problem…

The edited script here:

<script type="text/javascript">

function ReturnValueFromPopup(returnValue)
{
    var imageURL = 'billede.png';
}

function SimpleTextEditor(id, objectId) {
    if (!id || !objectId) { alert("SimpleTextEditor.constructor(id, objectId) failed, two arguments are required"); }
    var self = this;
    this.id = id;
    this.objectId = objectId;
    this.frame;
    this.viewSource = false;
    
    this.path = ""; // with slash at the end
    this.cssFile = "";
    this.charset = "iso-8859-1";

    this.editorHtml = "";
    this.frameHtml = "";

    this.textareaValue = "";

    this.browser = {
        "ie": Boolean(document.body.currentStyle),
        "gecko" : (navigator.userAgent.toLowerCase().indexOf("gecko") != -1)
    };

    this.init = function() {
        if (document.getElementById && document.createElement && document.designMode && (this.browser.ie || this.browser.gecko)) {
            // EDITOR
            if (!document.getElementById(this.id)) { alert("SimpleTextEditor "+this.objectId+".init() failed, element '"+this.id+"' does not exist"); return; }
            this.textareaValue = document.getElementById(this.id).value;
            var ste = document.createElement("div");
            document.getElementById(this.id).parentNode.replaceChild(ste, document.getElementById(this.id));
            ste.id = this.id+"-ste";
            ste.innerHTML = this.editorHtml ? this.editorHtml : this.getEditorHtml();
            // FRAME
            if (this.browser.ie) {
                this.frame = frames[this.id+"-frame"];
            } else if (this.browser.gecko) {
                this.frame = document.getElementById(this.id+"-frame").contentWindow;
            }
            this.frame.document.designMode = "on";
            this.frame.document.open();
            this.frame.document.write(this.frameHtml ? this.frameHtml : this.getFrameHtml());
            this.frame.document.close();
            insertHtmlFromTextarea();
        }
    };

    function lockUrls(s) {
        if (self.browser.gecko) { return s; }
        return s.replace(/href=["']([^"']*)["']/g, 'href="simpletexteditor://simpletexteditor/$1"');
    }

    function unlockUrls(s) {
        if (self.browser.gecko) { return s; }
        return s.replace(/href=["']simpletexteditor:\\/\\/simpletexteditor\\/([^"']*)["']/g, 'href="$1"');
    }

    function insertHtmlFromTextarea() {
        try { self.frame.document.body.innerHTML = lockUrls(self.textareaValue); } catch (e) { setTimeout(insertHtmlFromTextarea, 10); }
    }
	
    this.getEditorHtml = function() {
        var html = "";
        html += '<iframe id="'+this.id+'-frame" frameborder="0"></iframe>';
        return html;
    };

    this.getFrameHtml = function() {
        var html = "";
        html += '<html><head></head><body></body></html>';
        return html;
    };

    this.execCommand = function(cmd, value) {
        if (cmd == "insertimage" && !value) {
			//var imageUrl = prompt("Enter Image URL:", "");
			window.displayWindow();
        } 
		else if(cmd == "imageURL" && value){
			alert(value);
			this.frame.focus();
            this.frame.document.execCommand(cmd, false, value);
            this.frame.focus();
		}
		
    };
	
    this.isOn = function() {
        return Boolean(this.frame);
    };

    this.getContent = function() {
        try { return unlockUrls(this.frame.document.body.innerHTML); } catch(e) { alert("SimpleTextEditor "+this.objectId+".getContent() failed"); }
    };

    this.submit = function() {
        if (this.isOn()) {
            if (this.viewSource) { this.toggleSource(); }
            document.getElementById(this.id).value = this.getContent();
        }
    };
}

</script>

<textarea id="myfield" name="myfield" style="font-family:Arial;font-size:12px;"></textarea>

<script type="text/javascript">
	var ste = new SimpleTextEditor("myfield", "ste");
	ste.init();
</script>

<script type="text/javascript">
	function insertimage(){
		var imgURL = document.getElementById('imageurl').value;
  		ste.execCommand("imageURL", imgURL);
	}
	
	function CallWindowOpener(returnValue){
			if (typeof ReturnValueFromPopup == 'function'){
				ReturnValueFromPopup(returnValue);
			}
	}
</script>

<input name="imageurl" id="imageurl" type="text" />
<input name="Submit" type="button" onClick="insertimage();" value="Submit Image Url"/>

If I insert anything in the field in the bottom and click submit I first get an alert just to see if things is passed but then get an error from this part:

this.frame.document.execCommand(cmd, false, value);

Can anybody tell me where I go wrong… Thanks in advance…

Still looking for help… Please!