<!--
    // store all richeditors in an array
    var richeditors = new Array(10);
    var richeditors_index = 0;

    // keep track of the currently active richeditor
    var current_richeditor;

    // constructor
    function richEditor(id, text, css, includepath)
    {
        this.id = id;
        this.text = text;
        this.css = css;
        this.includepath = includepath;
    }

    // init a new richeditor
    function initRicheditor(id, text, css, includepath)
    {
        // create new instance
        richeditors[richeditors_index] = new richEditor(id, text, css, includepath);
        richeditors_index++;

    	// set iframe html
    	var frameHtml = "<html id=\"rte_" + id + "_html\">\n";
    	frameHtml += "<head>\n";

    	// stylesheet

    	// use custom stylesheet?
    	if (css.length > 0)
    	{
    	    // filter out newline as added in cls_cricheditor.php
    	    css = myStrReplace(css, "_newline_", "\n");

    	    frameHtml += "<style>\n";
    		frameHtml += css + "\n\n";
    		frameHtml += "</style>\n";
    	}
        // default style
    	else
    	{
    		frameHtml += "<style>\n";
    		frameHtml += "body {\n";
    		frameHtml += "	background: #FFFFFF;\n";
    		frameHtml += "	margin: 0px;\n";
    		frameHtml += "	padding: 0px;\n";
    		frameHtml += "}\n";
    		frameHtml += "</style>\n";
    	}
    	frameHtml += "</head>\n";
    	frameHtml += "<body>\n";
    	frameHtml += text + "\n";
    	frameHtml += "</body>\n";
    	frameHtml += "</html>";

        // ie
        if (document.all)
        {
    		var oFrameDocument = document.frames['rte_' + id + '_frame'].document;
    		oFrameDocument.open();
    		oFrameDocument.write(frameHtml);
    		oFrameDocument.close();

            // set iframe designmode property
            rteEnableDesignMode(id);
        }
        // firefox
        else
        {
        	try
        	{
                // set iframe designmode property
                rteEnableDesignMode(id);

        		try
        		{
            	    var oFrameDocument = document.getElementById('rte_' + id + '_frame').contentWindow.document;
            		oFrameDocument.open();
            		oFrameDocument.write(frameHtml);
            		oFrameDocument.close();

        			// attach a keyboard handler for gecko browsers to make keyboard shortcuts work
        			if (gecko) oFrameDocument.addEventListener("keypress", geckoKeyPress, true);
        		}
        		catch (e)
        		{
        		    alert("Error preloading content.");
        		}
        	}
    		// gecko may take some time to enable design mode.
    		// keep looping until able to set.
    		// otherwise return false
    		catch (e)
    		{
    			if (gecko) setTimeout("rteEnableDesignMode('" + id + "');", 10);
    			else return false;
    		}
        }

        // add styles to buttons in IE
    	if (ie)
    	{
    		document.onmouseover = rteRaiseButton;
    		document.onmouseout  = rteNormalButton;
    		document.onmousedown = rteLowerButton;
    		document.onmouseup   = rteRaiseButton;
    	}
    	
    	// set hidden field
    	rteUpdateHiddenField(id);
    }

    function rteEnableDesignMode(id)
    {
        // ie
        if (document.all)
        {
    		var oFrameDocument = document.frames['rte_' + id + '_frame'].document;
            oFrameDocument.designMode = 'On';
        }
        // firefox
        else
        {
            document.getElementById('rte_' + id + '_frame').contentDocument.designMode = "on";
        }
    }

    // function to perform command
    function rteCommand(id, command, option)
    {
    	// retrieve handle to content frame
    	var oRTE;
    	if (document.all)
    		oRTE = document.frames['rte_' + id + '_frame'];
    	else
    		oRTE = document.getElementById('rte_' + id + '_frame').contentWindow;

    	// execute command
    	oRTE.focus();
      	oRTE.document.execCommand(command, false, option);
    	oRTE.focus();
    }

    // retrieve handle to specified JavaScript richeditor object
    function getRicheditor(id)
    {
        for (var i=0; i < richeditors.length; i++)
        {
            if (richeditors[i].id==id) return richeditors[i];
        }
        return false;
    }

    // make sure the actual text instead of the HTML source is displayed before submitting
    function rteSubmit(id)
    {
        // if the HTML source is being displayed
        if (document.getElementById('rte_' + id + '_togglehtml').checked)
        {
            rteDisplayText(id);
            rteUpdateHiddenField(id);
            document.getElementById('rte_' + id + '_togglehtml').checked = false;
        }
        else
        {
            rteUpdateHiddenField(id);
        }
    }

    // switch between plain text and html source
    function rteToggleHTML(id)
    {
        // update hidden field to contain the current frame content
        rteUpdateHiddenField(id);

        // display the HTML source?
        if (document.getElementById('rte_' + id + '_togglehtml').checked)
        {
            rteDisplayHTML(id);
        }
        // or display the actual text?
        else
        {
            rteDisplayText(id);
        }
    }

    // display plain text
    function rteDisplayHTML(id)
    {
        // retrieve handle to hidden field
        var oHdnField = document.getElementById('rte_' + id + '_hidden');

        // ie
        if (document.all)
        {
    	    document.frames['rte_' + id + '_frame'].document.body.innerText	= oHdnField.value;
        }
        // firefox
        else
        {
			var oFrameDocument = document.getElementById('rte_' + id + '_frame').contentWindow.document;
			var htmlSrc = oFrameDocument.createTextNode(oHdnField.value);
			oFrameDocument.body.innerHTML = "";
			oFrameDocument.body.appendChild(htmlSrc);
        }
    }

    // display html source
    function rteDisplayText(id)
    {
        // retrieve handle to hidden field
        var oHdnField = document.getElementById('rte_' + id + '_hidden');

        // ie
        if (document.all)
        {
			// fix for IE
			var output = escape(document.frames['rte_' + id + '_frame'].document.body.innerText);
			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
			document.frames['rte_' + id + '_frame'].document.body.innerHTML = unescape(output);
        }
        // firefox
        else
        {
			var oFrameDocument = document.getElementById('rte_' + id + '_frame').contentWindow.document;
			var htmlSrc = oFrameDocument.body.ownerDocument.createRange();
			htmlSrc.selectNodeContents(oFrameDocument.body);
			oFrameDocument.body.innerHTML = htmlSrc.toString();
        }
    }

    // store the contents of the richeditor in the hidden form field
    function rteUpdateHiddenField(id)
    {
        // retrieve handle to hidden field
        var oHdnField = document.getElementById('rte_' + id + '_hidden');

    	// set hidden form field
    	if (oHdnField.value == null) oHdnField.value = "";
    	if (document.all)
    	{
    	    if (document.frames['rte_' + id + '_frame'].document.body)
    	        oHdnField.value = document.frames['rte_' + id + '_frame'].document.body.innerHTML;
    	    else
    	        oHdnField.value = "";
    	}
    	else
    	{
    	    if (document.getElementById('rte_' + id + '_frame').contentWindow.document.body)
    	        oHdnField.value = document.getElementById('rte_' + id + '_frame').contentWindow.document.body.innerHTML;
    	    else
                oHdnField.value = "";
    	}

    	// if there is no content (other than formatting) set value to nothing
    	if (stripHTML(oHdnField.value.replace("&nbsp;", " ")) == "" && oHdnField.value.toLowerCase().search("<hr") == -1 && oHdnField.value.toLowerCase().search("<img") == -1) oHdnField.value = "";
    }

    // function to strip all html from a string
    function stripHTML(oldString)
    {
    	// remove all info between '<' and '>'
    	var newString = oldString.replace(/(<([^>]+)>)/ig,"");

        // replace carriage returns and line feeds with spaces
        newString = newString.replace(/\r\n/g," ");
        newString = newString.replace(/\n/g," ");
        newString = newString.replace(/\r/g," ");

    	// trim string
    	newString = trim(newString);

        // done
    	return newString;
    }

    // Removes leading and trailing spaces from the passed string. Also removes
    // consecutive spaces and replaces it with one space. If something besides
    // a string is passed in (null, custom object, etc.) then return the input.
    function trim(inputString)
    {
       if (typeof inputString != "string") return inputString;
       var retValue = inputString;
       var ch = retValue.substring(0, 1);

       // Check for spaces at the beginning of the string
       while (ch == " ")
       {
          retValue = retValue.substring(1, retValue.length);
          ch = retValue.substring(0, 1);
       }
       ch = retValue.substring(retValue.length - 1, retValue.length);

       // Check for spaces at the end of the string
       while (ch == " ")
       {
          retValue = retValue.substring(0, retValue.length - 1);
          ch = retValue.substring(retValue.length - 1, retValue.length);
       }

    	// Note that there are two spaces in the string - look for multiple spaces within the string
       while (retValue.indexOf("  ") != -1)
       {
    	  // Again, there are two spaces in each of the strings
          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
       }

        // Return the trimmed string back to the user
       return retValue;
    }

    // function to store range of current selection
    function rteSetRange(id)
    {
    	var oRTE;
    	if (document.all)
    	{
    		oRTE = document.frames['rte_' + id + '_frame'];
    		var selection = oRTE.document.selection;
    		if (selection != null) rng = selection.createRange();
    	}
    	else
    	{
    		oRTE = document.getElementById('rte_' + id + '_frame').contentWindow;
    		var selection = oRTE.getSelection();
    		rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    	}
    	return rng;
    }

    function rteRaiseButton(e)
    {
    	var el = window.event.srcElement;

    	className = el.className;
    	if (className == 'rteImage' || className == 'rteImageLowered')
    	{
    		el.className = 'rteImageRaised';
    	}
    }

    function rteNormalButton(e)
    {
    	var el = window.event.srcElement;

    	className = el.className;
    	if (className == 'rteImageRaised' || className == 'rteImageLowered')
    	{
    		el.className = 'rteImage';
    	}
    }

    function rteLowerButton(e)
    {
    	var el = window.event.srcElement;

    	className = el.className;
    	if (className == 'rteImage' || className == 'rteImageRaised')
    	{
    		el.className = 'rteImageLowered';
    	}
    }

    // function setting the current font properties used
    function selectFont(id, selectname)
    {
    	// determine selection
    	var idx = document.getElementById(selectname).selectedIndex;

    	// first one is always a label
    	if (idx != 0)
    	{
    		var selected = document.getElementById(selectname).options[idx].value;
    		var cmd = selectname.replace('_' + id, '');
    		rteCommand(id, cmd, selected);
    		document.getElementById(selectname).selectedIndex = 0;
    	}
    }

    // function setting the color of the current selection
    function rteSetColor(color)
    {
    	// function to set color
    	var parentCommand = parent.command;
    	if (document.all)
    	{
    		if (parentCommand == "hilitecolor") parentCommand = "backcolor";

    		// retrieve selected range
    		rng = rteSetRange(current_richeditor);
    		rng.select();
    	}

    	// execute command
    	rteCommand(current_richeditor, parentCommand, color);
    }

    // function to open/close insert image dialog
    function rteInsertImage(id, command, popupURL)
    {
        // handle to JavaScript richeditor object
        var oRicheditor = getRicheditor(id);

    	// save current values
    	parent.command = command;
    	current_richeditor = id;
    	InsertImage = rtePopUp(popupURL, 'InsertImage', 590, 210, '');
    }

    // function to open/close insert link dialog
    function rteInsertLink(id, command, popupURL)
    {
        // handle to JavaScript richeditor object
        var oRicheditor = getRicheditor(id);

    	// save current values
    	parent.command = command;
    	current_richeditor = id;
    	InsertLink = rtePopUp(popupURL, 'InsertLink', 440, 200, '');

    	// get currently highlighted text and set link text value
    	rng = rteSetRange(id);
    	var linkText = '';
    	if (ie)
    		linkText = stripHTML(rng.htmlText);
    	else
    		linkText = stripHTML(rng.toString());

    	// update dialog form field value
    	rteSetLinkText(linkText);
    }


    // set link text value in insert link dialog
    function rteSetLinkText(linkText)
    {
    	try
    	{
    		window.InsertLink.document.linkForm.linkText.value = linkText;
    	}
    	catch (e)
    	{
    		// may take some time to create dialog window.
    		// keep looping until able to set.
    		setTimeout("rteSetLinkText('" + linkText + "');", 10);
    	}
    }


    function rteColorPalette(id, command, popupURL)
    {
        // handle to JavaScript richeditor object
        var oRicheditor = getRicheditor(id);

    	// save current values
    	parent.command = command;
    	current_richeditor = id;

    	// show popup
    	ColorPalette = rtePopUp(popupURL, 'ColorPalette', 360, 220, '');
    }

    // open richeditor dialog popup
    function rtePopUp(url, win, width, height, options)
    {
    	var leftPos = (screen.availWidth - width) / 2;
    	var topPos = (screen.availHeight - height) / 2;
    	options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
    	return window.open(url, win, options);
    }

    // strip html
    function rteStripTags(id)
    {
        // ie
        if (document.all)
        {
			// fix for IE
			var output = (document.frames['rte_' + id + '_frame'].document.body.innerText).replace(/<\/?[^>]+>/gi, '');
			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
			document.frames['rte_' + id + '_frame'].document.body.innerHTML = unescape(output);
        }
        // firefox
        else
        {
			var oFrameDocument = document.getElementById('rte_' + id + '_frame').contentWindow.document;
			var htmlSrc = oFrameDocument.body.ownerDocument.createRange();
			htmlSrc.selectNodeContents(oFrameDocument.body);
			oFrameDocument.body.innerHTML = (htmlSrc.toString()).replace(/<\/?[^>]+>/gi, '');
        }
    }
    
    // function to add HTML
    function rteInsertHTML(html)
    {
    	var rte = current_richeditor;

    	var oRTE;
    	if (document.all)
    		oRTE = document.frames('rte_' + rte + '_frame');
        else
    		oRTE = document.getElementById('rte_' + rte + '_frame').contentWindow;

    	oRTE.focus();
    	if (document.all)
    	{
    		var oRng = oRTE.document.selection.createRange();
    		oRng.pasteHTML(html);
    		oRng.collapse(false);
    		oRng.select();
    	}
    	else
    	{
    		oRTE.document.execCommand('insertHTML', false, html);
    	}
    }

    // function to add bold, italic, and underline shortcut commands to gecko RTEs
    function geckoKeyPress(evt)
    {
        // determine rte id
    	var rte = evt.target.id;
    	var rte = rte.substring(4,rte.indexOf('_html'));

    	// if the CTRL-key is pressed
    	if (evt.ctrlKey)
    	{
    		var key = String.fromCharCode(evt.charCode).toLowerCase();
    		var cmd = '';

    		// determine the letter pressed
    		switch (key)
    		{
    			case 'b': cmd = "bold"; break;
    			case 'i': cmd = "italic"; break;
    			case 'u': cmd = "underline"; break;
    		};

    		// make bold, italic or underline?
    		if (cmd)
    		{
    			rteCommand(rte, cmd, null);

    			// stop the event bubble
    			evt.preventDefault();
    			evt.stopPropagation();
    		}
     	}
    }
-->
