ing(oSelection).length)
                    putInClipoard(oSelection, "text/unicode");
                else {
                    if (giOpenEntry) {
                        //Copy the opened entry
                        sSelection = getNodeText(oWindow, oWindow.document.getElementById(giOpenEntry).parentNode.parentNode);
                        putInClipoard(sSelection, "text/unicode");
                    }
                }
                break;
            case APP_ACTIVATOR:
                oWindow     = oConceptIframe.contentWindow;
                oWindow2    = oSectionIframe.contentWindow;
                oSelection  = oWindow.getSelection();
                oSelection2 = oWindow2.getSelection();

                if (oSelection.rangeCount == 0 && oSelection2.rangeCount == 0) {
                    sSelection = getFrameContent(oWindow) + getFrameContent(oWindow2);
                    putInClipoard(sSelection, "text/unicode");
                } else {
                    sSelection = oSelection.toString() + "\r\n" + oSelection2.toString();
                    putInClipoard(sSelection, "text/unicode");
                }
                break;
            case APP_EXAMCOACH:
                break;
            case APP_POPUPMODE:
                oWindow    = oPMIframe.contentWindow;
                oDocument  = oPMIframe.contentDocument;
                oBody      = oDocument.getElementsByTagName("body")[0];
                oSelection = oWindow.getSelection();

                //Copy the selected text
                if (oSelection.rangeCount > 0)
                    putInClipoard(oSelection, "text/unicode");
                else {
                    //Copy the opened entry
                    sSelection = getNodeText(oWindow, oBody);
                    putInClipoard(sSelection, "text/unicode");
                }
                break;
        }

        //Give the focus to the window to set the selection active
        if (oWindow)
            oWindow.focus();
    } catch (err) {
        //alert("ERROR function copyManager :\n" + err)
    }
    window.setCursor("auto");
}

//Function that put the given string into the specified data flavor of the clipboard
function putInClipoard(psSelection, psFlavor) {
    try {
        var oTransferable = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
        if (!oTransferable)
            return;

        var oUnicodeString = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        if (oUnicodeString) {
            oUnicodeString.data = psSelection;
            oTransferable.addDataFlavor(psFlavor);
            oTransferable.setTransferData(psFlavor, oUnicodeString, String(psSelection).length * 2); // double byte data
        }

        var oClipboard = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
        if (!oClipboard || !psSelection)
            return;
        oClipboard.emptyClipboard(oClipboard.kGlobalClipboard);
        oClipboard.setData(oTransferable, null, oClipboard.kGlobalClipboard);
    } catch (err) {
        //alert("ERROR function copySelection:\n" + err);
    }
}

//Function that return the text contains in the given node element
function getNodeText(poWindow, poNode) {
    try {
        var oChildNodeList = poNode.childNodes;
        var sClipboard = "";
        var sDisplay;
        for (var i=0; i<oChildNodeList.length; i++) {
            if (oChildNodeList[i].nodeType == 1) {
                sDisplay = poWindow.getComputedStyle(oChildNodeList[i], '').display;
                if (sDisplay == "block")
                    sClipboard += "\r\n";
                if (sDisplay != "none")
                    sClipboard += getNodeText(poWindow, oChildNodeList[i]);
                if (sDisplay == "block")
                    sClipboard += "\r\n";
            } else {
                sClipboard += oChildNodeList[i].data;
            }
        }
        while (sClipboard.search(/(\r\n)+(\s)*(\r\n)+/g) != -1)
            sClipboard = sClipboard.replace(/(\r\n)+(\s)*(\r\n)+/g, "\r\n");
        return sClipboard;
    } catch (err) {
        //alert("ERROR function getNodeText:\n" + err);
    }
}

//Function that returns the text contains in a document
function getFrameContent(poWindow) {
    try {
        var sCopy = getNodeText(poWindow, poWindow.document.getElementsByTagName("body")[0]);
        return sCopy;
    } catch (err) {
        //alert("ERROR function getFrameContent:\n" + err);
    }
}

//Function that return the slected text in a window
function getSelectionText(poWindow, psText) {
    try {
        // Tester si l on double-clicque bien sur un mot
        if(!psText) {
            var oSelection = poWindow.getSelection();
            var t = oSelection.toString().toLowerCase();

            //Fix a mozilla bug (it seems the selection is still there even after updating the content of the document - as the dblclick in the PM)
            oSelection.removeAllRanges();
            // bug 5437
            t = t.replace(/^.\'/g, "");
            t = t.replace(/^ +/,"");
            t = t.replace(/ +$/,"");
            t = t.split(/\s/)[0];
        } else
            t = psText;
        var myStr = "";
        var GoodChar = "-' " + String.fromCharCode(9);
        for(var i=0; i<t.length; i++) {
            var thisChar = t.charCodeAt(i); // this line necessary because of bug (?) (Mac only?)
            if ((thisChar >= 97 && thisChar <= 122) || (thisChar >= 224 && thisChar <=246)
                    || (thisChar >= 48 && thisChar <=57)||(GoodChar.indexOf(t.charAt(i)) >= 0))
            {
                myStr += t.charAt(i);
                continue;
            }
        }
        return myStr;
    } catch (err) {
        //alert("ERROR function getSelectionText:\n" + err);
    }
}
