<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="{{ app['locale'] }}">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>{{ app['conf'].get(['registry', 'general', 'title']) }} - {{ 'phraseanet:: thesaurus' | trans }}</title>
        <style id="STYLES">
            DIV.glossaire DIV.r1_
            {
                display: none;
            }
        </style>
        <link type="text/css" rel="stylesheet" href="/assets/vendors/jquery-ui/css/ui-lightness{% if not app.debug %}.min{% endif %}.css">
        <link type="text/css" rel="stylesheet" href="/assets/thesaurus/css/thesaurus{% if not app.debug %}.min{% endif %}.css" />
        <script type="text/javascript">
            var p4 = {};
        </script>

        <link rel="shortcut icon" type="image/x-icon" href="/assets/thesaurus/images/favicon.ico">
        <script type="text/javascript" src="/assets/vendors/jquery/jquery{% if not app.debug %}.min{% endif %}.js"></script>
        <script type="text/javascript" src="/assets/vendors/jquery-ui/jquery-ui{% if not app.debug %}.min{% endif %}.js"></script>
        <script type="text/javascript" src="/assets/common/js/common{% if not app.debug %}.min{% endif %}.js"></script>
        <script type="text/javascript" src="/assets/thesaurus/js/thesaurus{% if not app.debug %}.min{% endif %}.js"></script>
        <script type="text/javascript">

            var currentBaseName = "";
            var currentBaseId = null;
            var thesaurusChanged = false;

            // le lanceur nous passe la fenetre du client
            var wClient = null;
            function catchClient(w)
            {
                wClient = w;
            }

            // recharger tout
            function reload()
            {
                self.location.replace("thesaurus.php?piv={{ piv }}&bid={{ bid }}") ;
            }

            function inputChanged() {
                if ($("[name=term]").val().length > 0) {
                    $("[name=term]").css('border-color', '');
                } else {
                    $("[name=term]").css('border-color', '#F00');
                }
            }

            function test(div)
            {
                t = document.getElementById(div).innerHTML;
                t = t.replace(/&/g, "&amp;");
                t = t.replace(/</g, "&lt;");
                t = t.replace(/>/g, "&gt;");
                // t = escape(t);
                w = window.open("about:blank", div+"wSRC", "left=2, top=2, directories=yes, width=1000, height=800, location=yes, menubar=yes, toolbar=yes, help=yes, status=yes, resizable=yes, scrollbars=yes", true);
                w.document.write("<pre>"+t+"</pre>");
                w.document.close();
            }

            var o_thbox_bck = null;
            var o_TabT0 = null;
            var o_TabT0k = null;
            var o_TabT1 = null;
            var o_TabT1k = null;
            function loaded()
            {
                o_thbox_bck = document.getElementById("id_thbox_bck");
                o_TabT0     = document.getElementById("TabT0") ;
                o_TabT0k    = document.getElementById("TabT0k") ;
                o_TabT1     = document.getElementById("TabT1") ;
                o_TabT1k    = document.getElementById("TabT1k") ;

                f = document.forms["fBase"];

                document.getElementById("T0").innerHTML = document.getElementById("T1").innerHTML = "{{ 'phraseanet::chargement' | trans }}";

                f.target = "IFR0";
                f.submit();

                $("#SEARCH_DLG").dialog({
                    modal: true,
                    title: "{{ 'Chercher' | trans }}",
                    autoOpen:false
                });
                $("#NEWSY_DLG").dialog({
                    modal: true,
                    title: "???",
                    autoOpen:false,
                    width: 400,
                    open: function () {
                        $("#NEWSY_DLG input[type=\"text\"]").on('click', function () {
                            $(this).focus();
                        });
                    }
                });
            }

            function chgCkShowRejected()
            {
                // document.styleSheets("STYLES", 0).rules[0].style.display  = document.forms["fTh"].ckShowRejected.checked ? "" : "none";
                var rules = document.styleSheets[0].cssRules ? document.styleSheets[0].cssRules : document.styleSheets[0].rules;
                rules[0].style.display  = document.forms["fTh"].ckShowRejected.checked ? "" : "none";

                return(true);
            }


            var timer_scrolling = null;
            function evtScrollBody()
            {
                if(timer_scrolling)
                {
                    window.clearTimeout(timer_scrolling);
                    timer_scrolling = null;
                }
                timer_scrolling = window.setTimeout("scrollEnd(0);", 50);
            }

            function scrollEnd(n)
            {
                document.getElementById("desktop").scrollTop = 0;
            }

            var xhr_object;
            function pollNotifications(){
                $.ajax({
                    type: "POST",
                    url: "/session/notifications/",
                    dataType: 'json',
                    data: {
                        module : 5,
                        usr : {{ app.getAuthenticatedUser().getId() }}
                    },
                    error: function(){
                        window.setTimeout("pollNotifications();", 10000);
                    },
                    timeout: function(){
                        window.setTimeout("pollNotifications();", 10000);
                    },
                    success: function(data){
                        if(data && typeof(data.status) && data.status == "disconnected") {
                            alert("{{ 'phraseanet::erreur: Votre session est fermee, veuillez vous re-authentifier' | trans }}");
                            self.location.replace(self.location.href);
                        }
                        window.setTimeout("pollNotifications();", 10000);

                        return;
                    }
                })
            };

            window.setTimeout("pollNotifications();", 10000);
        </script>

    </head>

    <body id="desktop" style="background-color:#808080; overflow:hidden" onload="loaded();" onscroll="evtScrollBody();" >

        <div class="menu" id="flagsMenu" style="z-index:50">
            {% for code, language in flags %}
                <img id='flagMenu_{{ code }}' src='/assets/common/images/lng/{{ code }}_flag_18.gif' />
            {% endfor %}
        </div>
        <div class="menu" id="kctermMenu" style="z-index:50; width:240px;">
            <a href="javascript:void(0)" class=""         id="kcterm_properties" style="font-weight:700">{{ 'thesaurus::menu: proprietes' | trans }}</a>
            <a href="javascript:void(0)" class=""         id="kcterm_reject">{{ 'thesaurus::menu: refuser' | trans }}</a>
            <a href="javascript:void(0)" class="disabled" id="kcterm_accept">{{ 'thesaurus::menu: accepter' | trans }}</a>
            <div class="line"></div>
            <a href="javascript:void(0)" class=""         id="kcterm_delete">{{ 'thesaurus::menu: supprimer' | trans }}</a>
            <div class="line"></div>
            <a href="javascript:void(0)" class=""         id="kcterm_search">{{ 'thesaurus::menu: chercher' | trans }}</a>
            <a href="javascript:void(0)" class=""         id="kcterm_export">{{ 'thesaurus::menu: exporter' | trans }}</a>
        </div>

        <div class="menu" id="kThMenu" style="z-index:50; width:200px;">
            <a href="javascript:void(0)" class="" id="kth_import">{{ 'thesaurus::menu: importer' | trans }}</a>
        </div>

        <div class="menu" id="ktermMenu" style="z-index:50; width:200px;">
            <a href="javascript:void(0)" class="" id="kterm_properties" style="font-weight:700">{{ 'thesaurus::menu: proprietes' | trans }}</a>
            <a href="javascript:void(0)" class="" id="kterm_newts">{{ 'thesaurus::menu: Nouveau terme' | trans }}</a>
            <a href="javascript:void(0)" class="" id="kterm_newsy">{{ 'thesaurus::menu: Nouveau synonyme' | trans }}</a>
            <a href="javascript:void(0)" class="" id="kterm_delete">{{ 'thesaurus::menu: supprimer' | trans }}</a>
            <div class="line"></div>
            <a href="javascript:void(0)" class="" id="kterm_search">{{ 'thesaurus::menu: chercher' | trans }}</a>
            <a href="javascript:void(0)" class="" id="kterm_export">{{ 'thesaurus::menu: exporter' | trans }}</a>
            <a href="javascript:void(0)" class="" id="kterm_topics">{{ 'thesaurus::menu: export topics' | trans }}</a>
            <div class="line"></div>
            <a href="javascript:void(0)" class="" id="kterm_link">{{ 'thesaurus::menu: lier au champ' | trans }}</a>
        </div>

        <form name="fBase" action="{{ path('thesaurus_loadth') }}" method="post" target="?">
            <input type="hidden" name="bid" value="{{ bid }}" />
            <input type="hidden" name="piv" value="{{ piv }}" />
            <input type="hidden" name="repair" value="" />
        </form>

        <!--
        Seems obsolete
        <form name="fSave" action="/thesaurus/savethesaurus1.php" method="post">
            <input type="hidden" name="bid" value="?" />
            <input type="hidden" name="th" value="?" />
            <input type="hidden" name="ch" value="?" />
        </form>
        -->

        <form name="fTh" style="position:absolute; top:0px; left:0px; right:0px; bottom:0px;">

            <br/>
            <br/>
            <div id="id_thbox_bck" class="thbox" style="position:absolute; top:28px; left:8px; right:8px; bottom:8px; background-color:#f4f4f4; xoverflow:hidden">

                <div class="onglet" style="background-color:#f0f0f0; border-bottom:1px solid #f4f4f4">
                    <span id="baseName">{{ 'phraseanet:: thesaurus' | trans }}</span>
                    <a href="#" onclick="fixTh();return(false);" style="visibility:hidden;">X</a>
                </div>


                <div id="TabT0" style="position:absolute; top:28px; left:0px; bottom:0px; width:40%;">

                    <div class="thbox" style="position:absolute; top:0px; bottom:8px; left:6px; right:3px;">
                        <div class="onglet">{{ 'thesaurus:: onglet stock' | trans }} <a href="#" onclick="test('T0');return(false);" style="visibility:hidden;">X</a>
                        </div>
                        <div style="width:100%; overflow:hidden">
                            <input type="checkbox" name="ckShowRejected" onClick="return(chgCkShowRejected());" /><span style="white-space:nowrap; overflow:hidden">{{ 'thesaurus:: afficher les termes refuses' | trans }}</span>
                        </div>
                        <div id="TabT0k" style="position:absolute; top:20px; bottom:0px; left:0px; right:0px; overflow:scroll; border:0px #000000 none">
                            <div id="T0" style="position:absolute; top:0px; left:0px;">
                            </div>
                        </div>
                    </div>
                </div>

                <div id="TabT1" style="position:absolute; top:28px; right:0px; bottom:0px; width:60%;">
                    <div class="thbox"  style="position:absolute; top:0px; bottom:8px; left:3px; right:6px;">
                        <div class="onglet"><span id='TabT1Title' style="cursor:pointer">{{ 'thesaurus:: onglet thesaurus' | trans }}</span>
                            &nbsp;
                            <a href="#" onclick="test('T1');return(false);" style="visibility:hidden;">X</a>
                        </div>
                        <div id="TabT1k" style="position:absolute; top:0px; bottom:0px; left:0px; right:0px; overflow:scroll; border:0px #000000 none">
                            <div id="T1" style="position:absolute; top:0px; left:0px;">
                            </div>
                        </div>
                    </div>
                </div>

                <!-- ------------------------------ the "search" dialog --------------------------- -->
                <div id="SEARCH_DLG">
                    <form>
                        <table>
                            <tr>
                                <td>{{ 'thesaurus:: le terme' | trans }}</td>
                                <td><input type="radio" name="m" value="equal">{{ 'thesaurus:: est egal a ' | trans }}</td>
                            </tr>
                            <tr>
                                <td />
                                <td><input type="radio" checked name="m" value="begins">{{ 'thesaurus:: commence par' | trans }}</td>
                            </tr>
                            <tr>
                                <td />
                                <td><input type="radio" name="m" value="contains">{{ 'thesaurus:: contient' | trans }}</td>
                            </tr>
                        </table>
                        <br/>
                        <input type="text" name="t" value="" style="width:200px;" autofocus>
                    </form>
                </div>
                <!-- ------------------------------ end "search" dialog --------------------------- -->

                <!-- ------------------------ the "new term/synonym" dialog ----------------------- -->
                <div id="NEWSY_DLG">
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td style="text-align:right; width:80px;"><span class="label"></span> :&nbsp;</td>
                            <td></td>
                            <td><input type="text" style="width:250px;" name="term"
                                       onkeyup="inputChanged();return(false);"></td>
                        </tr>
                        <tr>
                            <td style="text-align:right">{{ 'thesaurus:: contexte'  | trans }} : </td>
                            <td><b>(</b>&nbsp;</td>
                            <td><input type="text" style="width:250px;" name="context">&nbsp;<b>)</b></td>
                        </tr>
                        <tr>
                            <td valign="bottom" style="text-align:right">{{ 'phraseanet:: language' | trans }} :&nbsp;</td>
                            <td></td>
                            <td valign="bottom">
                                {% for code, language in flags %}
                                    <span style="display:inline-block">
                                    <input type="radio" {% if code == piv %}checked{% endif %} name="lng" value="{{ code }}" id="lng_{{ code }}">
                                    <label for="lng_{{ code }}"><img src="/assets/common/images/lng/{{ code }}_flag_18.gif" />({{ language }})</label>
                                </span>
                                    &nbsp;&nbsp;
                                {% endfor %}
                            </td>
                        </tr>
                    </table>
                </div>
                <!-- ------------------------- end "new term/synonym" dialog ---------------------- -->

            </div>

            <br/>

        </form>

        <div id="clipboard" style="position:absolute; top:0px; left:0px; z-index:99">&nbsp;</div>



        <iframe src="about:blank" name="IFRsave" id="IFRsave" style="visibility:hidden; ; position:absolute; top:0px; left:5px;   height:50px; width:50px; overflow:scroll"></iframe>
        <iframe src="about:blank" name="IFR0"    id="IFR0"    style="visibility:hidden; ; position:absolute; top:0px; left:400px; height:50px; width:50px; overflow:scroll"></iframe>

        <script type="text/javascript">


        document.body.oncontextmenu = function(){
            return false;
        }

        tFlags = {{ jsFlags | raw }};

        myGUI = new GUI("myGUI", "desktop", "FR");

        var selectedObject = null;        // l'object selectionné dans l'interface

        var selectedThesaurusItem = null;    // le thesaurus item en cours d'édition

        function buidTermBalloon(xmlobj)
        {
            var html = "";
            var syl = xmlobj.getElementsByTagName("sy_list");
            if(syl.length==1)
            {
                html = "<table>";
                for(var sy=syl.item(0).firstChild; sy; sy=sy.nextSibling )
                {
                    var lng = sy.getAttribute("lng");
                    var v = escapeHtmlDataFromXML(sy.getAttribute("v"));

                    html += "<tr>";
                    if(lng)
                        if(tFlags[lng])
                            html += "<td><img width='"+tFlags[lng].w+"' height='"+tFlags[lng].h+"' src='/assets/common/images/lng/"+lng+"_flag_18.gif'></td>";
                    else
                        html += "<td><span style='background-color:#cccccc'>&nbsp;"+lng+"&nbsp;</span></td>";
                    else
                        html += "<td><span style='background-color:#cccccc'>&nbsp;?&nbsp;</span></td>";

                    html += "<td>&nbsp;"+ v +"</td>";

                    var hits = 0+sy.getAttribute("hits");
                    if(hits == 1)
                        html += "<td>&nbsp;&nbsp;<i>"+sy.getAttribute("hits")+" hit</i></td></tr>";
                    else
                        html += "<td>&nbsp;&nbsp;<i>"+sy.getAttribute("hits")+" hits</i></td></tr>";
                }
                html += "</table>";
            }

            return(html);
        }

        // Let the browser to do it
        function escapeHtmlDataFromXML(data){
            var d = document.createElement('div');
            d.appendChild(document.createTextNode(data));
            return d.innerHTML;
        }

        // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //     T0
        //
        // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // gui callback du menu contextuel sur terme candidat
        function cbME_kcterm(action, cbParm, menuelem_id)
        {
            // alert("id=" + cbParm.id + "menuelem_id='" + menuelem_id + "'");
            // alert("cbParm.obj={obj:'" + cbParm.obj + "', id:'" + cbParm.id + "'} ; menuelem_id='" + menuelem_id + "'");
            var o = null;
            var om;
            //  o = document.getElementById(cbParm);
            o = cbParm;
            switch(action)
            {
                case "INIT":
                    // last chance to change menu content
                    switch(o.id.substr(0, 4))
                    {
                        case "TCE_":    // racine (STOCK) ou premier niveau (champ ou [trash])
                            //       alert(o.id);
                            if(om=document.getElementById("kcterm_reject"))
                                om.className = "disabled";
                            if(om=document.getElementById("kcterm_accept"))
                                om.className = "disabled";
                            if(om=document.getElementById("kcterm_delete"))
                                om.className = "disabled";
                            if(om=document.getElementById("kcterm_properties"))
                                om.className = "disabled";
                            // if(om=document.getElementById("kcterm_candidate"))
                            //  om.className = "disabled";
                            if(om=document.getElementById("kcterm_search"))
                                om.className = "";
                            break;
                        case "THE_":    // terme candidat
                            //          alert("id: "+o.id+" ; p: "+o.parentNode.id);
                            if(o.id.substr(4, 1)=="R")
                            {
                                if(om=document.getElementById("kcterm_reject"))
                                    om.className = "disabled";
                                if(om=document.getElementById("kcterm_delete"))
                                    om.className = "";
                                if(o.parentNode.id.indexOf(".") == -1)
                                {
                                    // terme de premier niveau sous un champ : on peut retablir
                                    if(om=document.getElementById("kcterm_accept"))
                                        om.className = "";
                                }
                                else
                                {
                                    // terme 'profond' (dans deleted) : on peut pas retablir
                                    if(om=document.getElementById("kcterm_accept"))
                                        om.className = "disabled";
                                }
                            }
                            else
                            {
                                if(om=document.getElementById("kcterm_accept"))
                                    om.className = "disabled";
                                if(om=document.getElementById("kcterm_delete"))
                                    om.className = "";
                                if(o.parentNode.id.indexOf(".") == -1)
                                {
                                    // terme de premier niveau sous un champ : on peut refuser
                                    if(om=document.getElementById("kcterm_reject"))
                                        om.className = "";
                                }
                                else
                                {
                                    // terme 'profond' (dans deleted) : on peut pas refuser
                                    if(om=document.getElementById("kcterm_reject"))
                                        om.className = "disabled";
                                }
                            }
                            if(om=document.getElementById("kcterm_properties"))
                                om.className = "";

                            // document.getElementById("kcterm_replace").className = "";
                            if(om = document.getElementById("kcterm_replace"))
                                om.className = ""; // "disabled";

                            if(o.firstChild.className == "nots")  // carre en face du terme (+- ; balise 'U') == grise ?
                            {
                                if(om = document.getElementById("kcterm_search"))
                                    om.className = "disabled";  // carre grise
                            }
                            else
                            {
                                if(om=document.getElementById("kcterm_search"))
                                    om.className = "";
                            }
                            break;
                    }
                    // alert(o.id);
                    break;
                case "SELECT":
                    switch(menuelem_id)
                    {
                        case "kcterm_delete":
                            url  = "xmlhttp/getterm.x.php";
                            url += "?bid={{ bid }}";
                            url += "&id=" + o.id.substr(4);
                            url += "&typ=CT";

                            // alert(url);

                            ret = loadXMLDoc(url, null, true);

                            msg = "{{ 'thesaurus:: Supprimer cette branche ?&#10;(les termes concernes remonteront en candidats a la prochaine indexation)' | trans }}";

                            if(confirm(msg))
                            {
                                var myObj = { "win":window };
                                url  = "/thesaurus/xmlhttp/killterm.x.php";
                                url += "?bid={{ bid }}";
                                url += "&piv={{ piv }}";
                                url += "&id=" + o.id.substr(4);
                                // url += "&typ=CT";

                                // alert(url);

                                ret = loadXMLDoc(url, parms, true);

                                refresh = ret.getElementsByTagName("refresh");
                                for(i=0; i<refresh.length; i++)
                                {
                                    switch(refresh.item(i).getAttribute("type"))
                                    {
                                        case "CT":
                                            reloadCtermsBranch(refresh.item(i).getAttribute("id"));
                                            break;
                                        case "TH":
                                            reloadThesaurusBranch(refresh.item(i).getAttribute("id"));
                                            break;
                                    }
                                }
                            }
                            break;

                        case "kcterm_reject":
                            var myObj = { "win":window };
                            url  = "/thesaurus/xmlhttp/reject.x.php";
                            url += "?bid={{ bid }}";
                            url += "&piv={{ piv }}";
                            url += "&id=" + o.id.substr(4);
                            // url += "&typ=CT";

                            // alert(url);

                            ret = loadXMLDoc(url, parms, true);

                            refresh = ret.getElementsByTagName("refresh");
                            for(i=0; i<refresh.length; i++)
                            {
                                switch(refresh.item(i).getAttribute("type"))
                                {
                                    case "CT":
                                        reloadCtermsBranch(refresh.item(i).getAttribute("id"));
                                        break;
                                    case "TH":
                                        reloadThesaurusBranch(refresh.item(i).getAttribute("id"));
                                        break;
                                }
                            }
                            break;
                        case "kcterm_accept":
                            var myObj = { "win":window };
                            url  = "/thesaurus/xmlhttp/accept.x.php";
                            url += "?bid={{ bid }}";
                            url += "&piv={{ piv }}";
                            url += "&id=" + o.id.substr(4);
                            // url += "&typ=CT";

                            //    alert(url);

                            ret = loadXMLDoc(url, parms, true);

                            refresh = ret.getElementsByTagName("refresh");
                            for(i=0; i<refresh.length; i++)
                            {
                                switch(refresh.item(i).getAttribute("type"))
                                {
                                    case "CT":
                                        reloadCtermsBranch(refresh.item(i).getAttribute("id"));
                                        break;
                                    case "TH":
                                        reloadThesaurusBranch(refresh.item(i).getAttribute("id"));
                                        break;
                                }
                            }
                            break;
                        case "kcterm_candidate":
                            if( o )
                            {
                                o.className = o.className.replace("R_", "r_");
                                if(!o.oldid)
                                {
                                    o.setAttribute("oldid", o.id.substr(4) );
                                }
                                o.id = "TCE_C" + o.id.substr(5);
                            }
                            break;
                        case "kcterm_properties":
                            var myObj = { "win":window };
                            url  = "properties.php";
                            url += "?bid={{ bid }}";
                            url += "&piv={{ piv }}";
                            url += "&id=" + o.id.substr(4);
                            url += "&typ=CT";

                            w = window.open(url, "PROPERTIES", "directories=no, height=340, width=500, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                            break;
                        case "kcterm_search":
                            $("#SEARCH_DLG").dialog("option", "buttons",
                                [
                                    {
                                        text:"{{ 'boutton::annuler' | trans }}",
                                        click: function() {
                                            $(this).dialog("close");
                                        }
                                    } ,
                                    {
                                        text:"{{ 'boutton::chercher'| trans }}",
                                        click:function() {
                                            var zdialog = $(this);
                                            var nid = cbParm.id.substr(4).replace(".", "\\.", "g");
                                            $("#THB_" + nid).empty();
                                            $.get(
                                                    "/thesaurus/xmlhttp/openbranches.j.php",
                                                    {
                                                        bid: {{ bid }},
                                                        id: cbParm.id.substr(4),
                                                        typ: "CT",
                                                        method: zdialog.find("[name=m]:checked").val(),
                                                        t: zdialog.find("[name=t]").val()
                                                    },
                                                    function(data, textStatus, jqXHR) {
                                                        var ts = data.result.html;
                                                        $("#THB_" + nid).html(ts).removeClass().addClass("hb");
                                                        $("#THP_" + nid).text("...");
                                                        zdialog.dialog("close");
                                                    },
                                                    "json"
                                            );
                                        }
                                    }
                                ]
                            );
                            $("#SEARCH_DLG").dialog("open");
                            break;
                        case "kcterm_export":
                            var myObj = { "win":window };
                            url  = "export_text_dlg.php";
                            url += "?bid={{ bid }}";
                            url += "&piv={{ piv }}";
                            url += "&id=" + o.id.substr(4);
                            url += "&typ=CT";
                            w = window.open(url, "EXPORT", "directories=no, height=300, width=700, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no");
                            break;
                            break;
                        }
                        break;
                    }
                }

                function cbDD_T0(event, type, eventObj)
                {
                    ret = true;
                    switch(type)
                    {
                        case "RMOUSEDOWN":
                            if(o = eventObj.Src0)
                            {
                                // alert(o.id.substr(0, 4));
                                switch(o.id.substr(0, 4))
                                {
                                    case "TCE_":    // une branche (champ) de candidats
                                        myGUI.select(o);
                                        document.getElementById("kctermMenu").runAsMenu( event, o );
                                        break;
                                    case "THE_":    // le terme candidat
                                        myGUI.select(o);
                                        document.getElementById("kctermMenu").runAsMenu( event, o );
                                        break;
                                }
                            }
                            break;
                        /*
            case "CONTEXTMENU":
              if(o = eventObj.Src0)
              {
                // alert(o.id.substr(0, 4));
                switch(o.id.substr(0, 4))
                {
                  case "TCE_":    // une branche (champ) de candidats
                  case "THE_":    // le terme candidat
                    myGUI.select(o);
                    // document.getElementById("kctermMenu").runAsMenu( event, o );
                    self.setTimeout('document.getElementById("kctermMenu").runAsMenu( event, o.id );', 3000);
                    break;
                }
              }
              break;
                         */
                    case "DBLCLICK":
                        if(o = eventObj.Src0)
                        {
                            switch(o.id.substr(0, 4))
                            {
                                case "THE_":    // terme candidat
                                    if(o.id.indexOf(".") != -1)
                                    {
                                        var myObj = { "win":window };
                                        url  = "properties.php";
                                        url += "?bid={{ bid }}";
                                        url += "&piv={{ piv }}";
                                        url += "&id=" + o.id.substr(4);
                                        url += "&typ=CT";

                                        w = window.open(url, "PROPERTIES", "directories=no, height=340, width=500, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                                    }
                                    break;
                                }
                            }
                            break;
                        case "MOUSEDOWN":
                            if(o = eventObj.Src0)
                            {
                                // alert(o.id);
                                switch(o.id.substr(0, 4))
                                {
                                    case "THP_":  // + ou - devant un terme
                                        thid = o.id.substr(4);
                                        if(tce = document.getElementById("TCE_"+thid))
                                            myGUI.select(tce);
                                        else
                                            if(the = document.getElementById("THE_"+thid))
                                                myGUI.select(the);
                                        if(o.className=="" && (thb = document.getElementById("THB_"+thid)))
                                        {
                                            // alert(thb.className);
                                            // alert(thb.className + " " + thb.className.indexOf("OB"));
                                            /*
                      if(thb.className.indexOf("OB") != -1)
                      {
                        eventObj.Src0.innerHTML = "+";

                        // thb.className = "ob";
                        thb.className = thb.className.replace(/OB/, "ob");
                      }
                      else
                      {
                        new_thb = reloadbranch(thb, thid, "CT");

                        eventObj.Src0.innerHTML = "-";
                        new_thb.className = new_thb.className.replace(/ob/, "OB");
                        //new_thb.className = "OB";
                        //alert(new_thb.className);
                      }
                                             */
                                            if(thb.className == "ob")
                                            {
                                                new_thb = reloadbranch(thb, thid, "CT");

                                                eventObj.Src0.innerHTML = "-";
                                                new_thb.className = "OB";
                                            }
                                            else
                                            {
                                                eventObj.Src0.innerHTML = "+";

                                                // thb.className = "ob";
                                                thb.className = "ob";
                                            }
                                            // document.getElementById("THE_").style.display = "none";
                                            // document.getElementById("THE_").style.display = "";
                                        }
                                        ret = false;  // empêchera le drag/drop à partir du +-
                                        break;
                                    case "THE_":    // le terme candidat
                                        myGUI.select(o);
                                        if(o.id.substr(4, 1) != "C")  // on ne peut pas draguer que les candidats, pas les refuses ---
                                        {
                                            ret = false;
                                        }
                                        break;
                                    case "TCE_":    // le nom de champ
                                        myGUI.select(o);
                                        // if(o.id.substr(4, 1) != "C")  // on ne peut pas draguer que les candidats, pas les refuses ---
                                        //{
                                        ret = false;
                                        // }
                                        break;
                                }
                            }
                            break;
                        case "DRAGSTART":
                            if(o = eventObj.Src0)
                            {
                                if(o.id.substr(0, 4)=="THE_")
                                {
                                    myGUI.select(null);
                                    cp = document.getElementById("clipboard");
                                    //          if(cp = document.getElementById("clipboard"))
                                    //          {

                                    // o.style.position = "absolute";
                                    //    cp.style.pixelLeft = eventObj.X+10;
                                    //    cp.style.pixelTop = eventObj.Y+10;

                                    o2 = o.cloneNode(true);
                                    //o2.style.position = "absolute";
                                    //o2.style.pixelLeft = 0;
                                    //o2.style.pixelTop = 0;
                                    o2.style.backgroundColor = "#ffff00";
                                    //o2.style.zIndex = 2;

                                    //    o.style.display = "none";
                                    if(pp = document.getElementById("clipboard"))
                                    {
                                        pp.replaceChild(o2, pp.firstChild);
                                        pp.style.visibility = "visible";
                                        myGUI.setDragObj(pp);
                                    }
                                    //          }
                                }
                                else
                                {
                                    ret = false;
                                }
                            }
                            break;
                        case "BALLOON":
                            if(o = eventObj.Src0)
                            {
                                if(o.id.substr(0, 4)=="THE_") // && o.id.substr(4)!="T")
                                {
                                    var url   = "xmlhttp/getterm.x.php";
                                    var parms = "bid={{ bid }}";
                                    parms    += "&piv={{ piv }}";
                                    parms    += "&sortsy=0";
                                    parms    += "&id=" + o.id.substr(4);
                                    parms    += "&typ=CT";
                                    parms    += "&nots=1";
                                    // alert(url);

                                    var ret = loadXMLDoc(url, parms, true);
                                    var html = buidTermBalloon(ret);
                                    if(html)
                                        myGUI.showBalloon(html);
                                }
                            }
                            break;
                        }

                        return(ret);
                    }


                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //
                    //     T1
                    //
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    function reloadbranch(thb, thid, typ)
                    {
                        // alert(thb.id);
                        new_thb = null;
                        url = "xmlhttp/getterm.x.php";
                        parms  = "bid={{ bid }}";
                        parms += "&piv={{ piv }}";
                        parms += "&sortsy=1";
                        parms += "&id=" + thid;
                        parms += "&typ=" + typ;
                        ret = loadXMLDoc(url, parms, true);
                        ts = ret.getElementsByTagName("ts_list");
                        // alert(url+"?"+parms);
                        if(ts.length==1)
                        {
                            new_thb = document.createElement("DIV");
                            new_thb.setAttribute("id", "THB_" + thid);
                            nts = 0;
                            for(n=ts.item(0).firstChild; n; n=n.nextSibling)
                            {
                                div = new_thb.appendChild(document.createElement("div"));
                                id = n.getAttribute("id");
                                if(id.substr(0,1) == "R")
                                    div.className = "s_ r1_";
                                else
                                    div.className = "s_ r0_";
                                div.setAttribute("id", "THE_" + n.getAttribute("id"));

                                u = div.appendChild(document.createElement("u"));
                                u.setAttribute("id", "THP_" + n.getAttribute("id"));
                                if(n.firstChild)
                                    txt = div.appendChild(document.createTextNode(n.firstChild.nodeValue));
                                else
                                    txt = div.appendChild(document.createTextNode(""));
                                if(n.getAttribute("nts") > 0)
                                {
                                    u.appendChild(document.createTextNode("+"));
                                }
                                else
                                {
                                    u.className = "nots";
                                    u.appendChild(document.createTextNode(""));
                                }
                                new_thb2 = new_thb.appendChild(document.createElement("DIV"));
                                //  new_thb2.className = "ob r0_";
                                new_thb2.className = "ob";
                                new_thb2.setAttribute("id", "THB_" + n.getAttribute("id"));
                                nts++;
                            }
                            thb.parentNode.replaceChild(new_thb, thb);
                            thp = document.getElementById("THP_"+thid);

                            if(nts > 0)
                            {
                                //       alert("thb.className = "+thb.className);
                                new_thb.className = thb.className;
                                if(thid.substr(0,1) == "R")
                                {
                                    // new_thb.className = "ob r1_";
                                    new_thb.className = "ob";
                                }
                                else
                                {
                                    // new_thb.className = "ob r0_";
                                }
                                // alert(thid + " " + new_thb.className);
                                thp.className = "";
                                thp.innerText = thb.className=="ob"?"+":"-";
                            }
                            else
                            {
                                //      new_thb.className = "ob r1_";
                                new_thb.className = "ob";
                                thp.className = "nots";
                                thp.innerText = "";
                            }
                        }

                        return(new_thb);
                        // alert(ret.nodeFromID("tsid"));  // marche pas sur safari
                        // alert(ret.selectSingleNode("//te"));  // marche pas sur safari
                    }
                    function reloadCtermsBranch(cid)
                    {
                        // alert('reloadCtermsBranch('+cid+')');
                        return(reloadbranch(document.getElementById("THB_"+cid), cid, "CT"))
                    }
                    function reloadThesaurusBranch(tid)
                    {
                        if(tid=='')
                            tid='T';

                        return(reloadbranch(document.getElementById("THB_"+tid), tid, "TH"))
                    }


                    // gui callback du menu contextuel sur terme
                    function cbME_kterm(action, cbParm, menuelem_id)
                    {
                        // alert("id=" + cbParm.id + "menuelem_id='" + menuelem_id + "'");
                        // alert("cbParm.obj={obj:'" + cbParm.obj + "', id:'" + cbParm.id + "'} ; menuelem_id='" + menuelem_id + "'");
                        var o = null;
                        var om;
                        var ret;
                        if(cbParm.id)
                            o = document.getElementById(cbParm.id);
                        switch(action)
                        {
                            case "INIT":
                                // last chance to change menu content
                                if(o.id.substr(4) == "T")
                                {
                                    // menu contextuel e la racine du thesaurus
                                    // document.getElementById("kterm_replace").style.display = "none";
                                    if(om=document.getElementById("kterm_link"))
                                        om.className = "disabled";
                                    if(om=document.getElementById("kterm_delete"))
                                        om.className = "disabled";
                                    if(om=document.getElementById("kterm_newsy"))
                                        om.className = "disabled";
                                    if(om=document.getElementById("kterm_properties"))
                                        om.className = "disabled";
                                }
                                else
                                {
                                    // menu contextuel sur un terme du thesaurus
                                    // document.getElementById("kterm_replace").style.display = "";
                                    if(om=document.getElementById("kterm_link"))
                                        om.className = "";
                                    if(om=document.getElementById("kterm_delete"))
                                        om.className = "";
                                    if(om=document.getElementById("kterm_newsy"))
                                        om.className = "";
                                    if(om=document.getElementById("kterm_properties"))
                                        om.className = "";
                                }
                                break;
                            case "SELECT":
                                switch(menuelem_id)
                                {
                                    case "kterm_newts": // nouveau terme specifique
                                    case "kterm_newsy": // nouveau synonyme
                                        var typ = menuelem_id=="kterm_newts" ? "TS" : "SY";
                                        $("#NEWSY_DLG input[type=\"text\"]").val("");
                                        $("#NEWSY_DLG .label").html(
                                                typ=="TS" ? "{{ 'thesaurus:: terme'  | trans }}" : "{{ 'thesaurus:: synonyme'  | trans }}"
                                        );
                                        $("#NEWSY_DLG").dialog("option", "title", typ=="TS" ? "{{ 'thesaurus:: Nouveau terme'  | trans }}" : "{{ 'thesaurus:: Nouveau synonyme'  | trans }}");
                                        $("#NEWSY_DLG").dialog("option", "buttons",
                                                [
                                                    {
                                                        text:"{{ 'boutton::annuler'  | trans }}",
                                                        click: function() {
                                                            $(this).dialog("close");
                                                        }
                                                    } ,
                                                    {
                                                        text:"{{ 'boutton::valider'  | trans }}",
                                                        click:function() {
                                                            var zdialog = $(this);
                                                            var myObj = { "win":window };

                                                            var t = zdialog.find("[name=term]").val();
                                                            if (t.length == 0) {
                                                                zdialog.find("[name=term]").css('border-color', '#F00');
                                                                return;
                                                            }
                                                            var k = zdialog.find("[name=context]").val();
                                                            if(k != "") {
                                                                t += " (" + k + ")";
                                                            }
                                                            var lng = zdialog.find("[name=lng]:checked").val();

                                                            zdialog.dialog("close");

                                                            url  = "newterm.php";
                                                            url += "?bid={{ bid }}";
                                                            url += "&piv={{ piv }}";
                                                            url += "&pid=" + o.id.substr(4);
                                                            url += "&t=" + encodeURIComponent(t);
                                                            url += "&typ=" + typ;
                                                            url += "&sylng=" + encodeURIComponent(lng);

                                                            w = window.open(url, "NEWTERM", "directories=no, height=290, width=490, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no");
                                                        }
                                                    }
                                                ]
                                        );
                                        $("#NEWSY_DLG").dialog("open");
                                        break;

                                    case "kterm_delete":
                                        tid = o.id.substr(4);
                                        url = "/thesaurus/xmlhttp/getterm.x.php";
                                        url +=  "?bid={{ bid }}";
                                        url +=  "&piv={{ piv }}";
                                        url += "&id=" + tid;
                                        url += "&typ=TH";
                                        ret = loadXMLDoc(url, null, true);
                                        // alert(ret);
                                        fullpath = ret.getElementsByTagName("fullpath").item(0).firstChild.nodeValue;

                                        url = "xmlhttp/delts.x.php";
                                        parms  = "bid={{ bid }}";
                                        parms += "&piv={{ piv }}";
                                        parms += "&id=" + tid;

                                        if(confirm("{{ 'thesaurus:: deplacer le terme dans la corbeille ?' | trans | e('js') }}"+"\n\n"+fullpath+"\n\n"))
                                        {
                                            console.log(url);
                                            // xmlhttp/delts.x.php?bid=15&id=T1.629&debug=1
                                            // alert(url+"?"+parms);
                                            ret = loadXMLDoc(url, parms, true);
                                            // alert(ret);

                                            refresh = ret.getElementsByTagName("refresh");
                                            for(i=0; i<refresh.length; i++)
                                            {
                                                switch(refresh.item(i).getAttribute("type"))
                                                {
                                                    case "CT":
                                                        reloadCtermsBranch(refresh.item(i).getAttribute("id"));
                                                        break;
                                                    case "TH":
                                                        reloadThesaurusBranch(refresh.item(i).getAttribute("id"));
                                                        break;
                                                }
                                            }
                                        }
                                        break;
                                    case "kterm_replace":
                                        alert("todo...");
                                        break;
                                    case "kterm_link":
                                        var myObj = { "win":window };
                                        url = "linkfield.php";
                                        url +=  "?bid={{ bid }}";
                                        url +=  "&piv={{ piv }}";
                                        url += "&tid=" + o.id.substr(4);
                                        w = window.open(url, "LINK", "directories=no, height=340, width=500, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                                        break;
                                    case "kterm_properties":
                                        var myObj = { "win":window };
                                        url  = "properties.php";
                                        url += "?bid={{ bid }}";
                                        url += "&piv={{ piv }}";
                                        url += "&id=" + o.id.substr(4);
                                        url += "&typ=TH";

                                        w = window.open(url, "PROPERTIES", "directories=no, height=300, width=500, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                                        break;
                                    case "kterm_search":
                                        $("#SEARCH_DLG").dialog("option", "buttons",
                                            [
                                                {
                                                    text:"{{ 'boutton::annuler'  | trans }}",
                                                    click: function() {
                                                        $(this).dialog("close");
                                                    }
                                                } ,
                                                {
                                                    text:"{{ 'boutton::chercher'  | trans }}",
                                                    click:function() {
                                                        var zdialog = $(this);
                                                        var nid = cbParm.id.substr(4).replace(".", "\\.", "g");
                                                        $("#THB_" + nid).empty();
                                                        $.get(
                                                            "/thesaurus/xmlhttp/openbranches.j.php",
                                                            {
                                                                bid: {{ bid }},
                                                                id: cbParm.id.substr(4),
                                                                typ: "TH",
                                                                method: zdialog.find("[name=m]:checked").val(),
                                                                t: zdialog.find("[name=t]").val()
                                                            },
                                                            function(data, textStatus, jqXHR) {
                                                                var ts = data.result.html;
                                                                $("#THB_" + nid).html(ts).removeClass().addClass("hb");
                                                                $("#THP_" + nid).text("...");
                                                                zdialog.dialog("close");
                                                            },
                                                            "json"
                                                        );
                                                    }
                                                }
                                            ]
                                        );
                                        $("#SEARCH_DLG").dialog("open");
                                        break;
                                    case "kterm_export":
                                        var myObj = { "win":window };
                                        url  = "export_text_dlg.php";
                                        url += "?bid={{ bid }}";
                                        url += "&piv={{ piv }}";
                                        url += "&id=" + o.id.substr(4);
                                        url += "&typ=TH";
                                        w = window.open(url, "EXPORT", "directories=no, height=300, width=700, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no");
                                        break;
                                    case "kterm_topics":
                                        var myObj = { "win":window };
                                        url  = "export_topics_dlg.php";
                                        url += "?bid={{ bid }}";
                                        url += "&piv={{ piv }}";
                                        url += "&id=" + o.id.substr(4);
                                        url += "&typ=TH";
                                        url += "&obr=" + list_opened_branches(o.parentNode);
                                        w = window.open(url, "EXPORT", "directories=no, height=400, width=550, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no");
                                        break;
                                    }
                                    break;
                                }
                            }

                            function list_opened_branches(o, depth)
                            {
                                l = "";
                                if(o.nodeType==1)  // element
                                {
                                    if(o.id.substr(0,4)=="THB_" && o.className=="OB")
                                        l += o.id.substr(4) + ";";
                                    for(var oo=o.firstChild; oo; oo=oo.nextSibling)
                                        l += list_opened_branches(oo);
                                }

                                return(l);
                            }

                            function replaceContent(dstNode, newContent)
                            {
                                var n;
                                if(document.importNode)    // safari ?
                                {
                                    dstNode.innerHTML = "";
                                    for(n=newContent.firstChild; n; n=n.nextSibling)
                                        docImport(n, dstNode);  // assez rapide sous safari, tres tres lent sous explorer
                                }
                                else
                                {
                                    var t = "";
                                    for(n=newContent.firstChild; n; n=n.nextSibling)
                                        t += n.xml;    // marche pas sous safari...
                                    // IE fails to recognize <tag/> as a closed tag when using innerHTML, so replace it with <tag></tag>
                                    // except for br, img, and hr elements.
                                    var expr = new RegExp("<(?:(?!br|img|hr)([a-zA-Z]+))([^>]*)/>", "ig");
                                    t = t.replace(expr, "<$1$2></$1>");

                                    dstNode.innerHTML = t;  // rapide sous explorer, tres tres lent sous safari
                                }
                            }

                            function cbDD_T1(event, type, eventObj)
                            {
                                ret = true;
                                switch(type)
                                {
                                    case "RMOUSEDOWN":
                                        if(o = eventObj.Src0)
                                        {
                                            switch(o.id.substr(0, 4))
                                            {
                                                case "THE_":    // le terme
                                                    myGUI.select(o);
                                                    document.getElementById("ktermMenu").runAsMenu( event, {id:o.id} );
                                                    ret = false;
                                                    break;
                                            }
                                        }
                                        break;
                                    case "MOUSEDOWN":
                                        if(o = eventObj.Src0)
                                        {
                                            switch(o.id.substr(0, 4))
                                            {
                                                case "THP_":  // + ou - devant un terme
                                                    thid = o.id.substr(4);
                                                    if(the = document.getElementById("THE_"+thid))
                                                        myGUI.select(the);
                                                    if(o.className=="" && (thb = document.getElementById("THB_"+thid)))
                                                    {
                                                        if(thb.className == "ob")
                                                        {
                                                            new_thb = reloadbranch(thb, thid, "TH");
                                                            eventObj.Src0.innerHTML = "-";
                                                            new_thb.className = "OB";
                                                        }
                                                        else
                                                        {
                                                            eventObj.Src0.innerHTML = "+";
                                                            thb.className = "ob";
                                                        }
                                                    }
                                                    ret = false;  // empêchera le drag/drop à partir du +-
                                                    break;
                                                case "THE_":  // terme
                                                    myGUI.select(o);
                                                    break;
                                            }
                                        }
                                        break;
                                    case "DBLCLICK":
                                        if(o = eventObj.Src0)
                                        {
                                            if(o.id.substr(0, 4)=="THE_" && o.id.substr(4)!="T")
                                            {
                                                var myObj = { "win":window };
                                                url  = "properties.php";
                                                url += "?bid={{ bid }}";
                                                url += "&piv={{ piv }}";
                                                url += "&id=" + o.id.substr(4);
                                                url += "&typ=TH";
                                                w = window.open(url, "PROPERTIES", "directories=no, height=340, width=500, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                                            }
                                        }
                                        break;
                                    case "BALLOON":
                                        if(o = eventObj.Src0)
                                        {
                                            if(o.id.substr(0, 4)=="THE_") // && o.id.substr(4)!="T")
                                            {
                                                var url   = "xmlhttp/getterm.x.php";
                                                var parms = "bid={{ bid }}";
                                                parms    += "&piv={{ piv }}";
                                                parms    += "&sortsy=0";
                                                parms    += "&id=" + o.id.substr(4);
                                                parms    += "&typ=TH";
                                                parms    += "&nots=1";
                                                // alert(url);

                                                var ret = loadXMLDoc(url, parms, true);
                                                var syl = ret.getElementsByTagName("sy_list");
                                                var ret = loadXMLDoc(url, parms, true);
                                                var html = buidTermBalloon(ret);
                                                if(html)
                                                    myGUI.showBalloon(html);
                                            }
                                        }
                                        break;
                                    case "DRAGLEAVE":
                                        if(lo = eventObj.lastTarget0)
                                            lo.style.backgroundColor = ""; // eventObj.lastTarget0Style;
                                        break;
                                    case "DRAGOVER":
                                        //  if(cp = document.getElementById("clipboard"))
                                        {
                                            // o.style.position = "absolute";
                                            //    cp.style.pixelLeft = eventObj.X+10;
                                            //    cp.style.pixelTop = eventObj.Y+10;
                                            // o.style.backgroundColor = "#ffff00";
                                            // o.style.zIndex = 2;
                                            if(o = eventObj.Target0)
                                            {
                                                if(lo = eventObj.lastTarget0)
                                                {
                                                    lo.style.backgroundColor = ""; // eventObj.lastTarget0Style;
                                                    // lo.style.border = "1px none #ffff00"; // eventObj.lastTarget0Style;
                                                    //            lo.style.color="#ff00ff";
                                                }
                                                if(o.id.substr(0, 4) == "THE_") // && o.id != "THE_T")  // pas de drop e la racine du thesaurus
                                                {
                                                    // myGUI.select(o);
                                                    //eventObj.lastTarget0Style = o.style.borderBottom;
                                                    o.style.backgroundColor =  "#99a2d0";
                                                    // o.style.border = "1px solid #99a2d0";
                                                    //          o.style.color="#000000";
                                                    eventObj.lastTarget0 = o;
                                                }
                                            }
                                        }
                                        break;
                                    case "DROP":
                                        if(lo = eventObj.lastTarget0)
                                            lo.style.backgroundColor = "";

                                        if(cp = document.getElementById("clipboard").firstChild)
                                        {
                                            if(tgt0 = eventObj.Target0)
                                            {
                                                var myObj = { "win":window };
                                                url  = "accept.php";
                                                url += "?bid={{ bid }}";
                                                url += "&piv={{ piv }}";
                                                url += "&src=" + eventObj.Src0.id.substr(4);
                                                url += "&tgt=" + tgt0.id.substr(4);
                                                w = window.open(url, "ACCEPT", "directories=no, height=300, width=500, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                                            }
                                        }
                                        break;
                                    }

                                    return(ret);
                                }

                                function cbDD_TabT1(event, type, eventObj)
                                {
                                    ret = true;
                                    switch(type)
                                    {
                                        case "RMOUSEDOWN":
                                            document.getElementById("kThMenu").runAsMenu( event, null );
                                            break;
                                        case "MOUSEDOWN":
                                            break;
                                        case "DBLCLICK":
                                            break;
                                        case "DRAGLEAVE":
                                            break;
                                        case "DRAGOVER":
                                            break;
                                        case "DROP":
                                            break;
                                    }

                                    return(ret);
                                }



                                // gui callback du menu contextuel sur l'onglet 'thesaurus'
                                function cbME_kTh(action, cbParm, menuelem_id)
                                {
                                    // alert("id=" + cbParm.id + "menuelem_id='" + menuelem_id + "'");
                                    // alert("cbParm.obj={obj:'" + cbParm.obj + "', id:'" + cbParm.id + "'} ; menuelem_id='" + menuelem_id + "'");
                                    var om;
                                    switch(action)
                                    {
                                        case "INIT":
                                            // last chance to change menu content
                                            break;
                                        case "SELECT":
                                            switch(menuelem_id)
                                            {
                                                case "kth_import": // importer
                                                    var myObj = { "win":window };
                                                    url  = "import_dlg.php";
                                                    url += "?piv={{ piv }}";
                                                    url += "&bid={{ bid }}";
                                                    url += "&id=";
                                                    w = window.open(url, "IMPORT", "directories=no, height=400, width=600, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, toolbar=no");
                                                    break;
                                                }
                                                break;
                                            }
                                        }

                                        function docImport(src, dst)
                                        {
                                            var n, nn;
                                            // alert(src.nodeType);
                                            switch(src.nodeType)
                                            {
                                                case 1:  // element
                                                    // alert(src.nodeName);
                                                    nn = dst.appendChild(document.createElement(src.nodeName))
                                                    if(v = src.getAttribute("id"))
                                                        nn.id = v;
                                                    if(v = src.getAttribute("name"))
                                                        nn.name =  v;
                                                    if(v = src.getAttribute("class"))
                                                        nn.className =  v;
                                                    if(v = src.getAttribute("style"))
                                                        nn.setAttribute("style", v);
                                                    for(n=src.firstChild; n; n=n.nextSibling)
                                                        docImport(n, nn);
                                                    break;
                                                case 3: // text
                                                    // alert(src.nodeValue);
                                                    nn = dst.appendChild(document.createTextNode(src.nodeValue))
                                                    break;
                                            }
                                        }

                                        myGUI.setClickable("T0", cbDD_T0);

                                        myGUI.setDraggable("T0", cbDD_T0);


                                        myGUI.setClickable("TabT1Title", cbDD_TabT1);



                                        myGUI.setClickable("T1", cbDD_T1);

                                        myGUI.setDroppable("T1", cbDD_T1);

                                        // ttttttttttttttttttttttttttttttttttttttt
                                        // myGUI.setAsMenu("flagsMenu", cbME_flags);

                                        myGUI.setAsMenu("kctermMenu", cbME_kcterm);

                                        myGUI.setAsMenu("ktermMenu", cbME_kterm);

                                        myGUI.setAsMenu("kThMenu", cbME_kTh);
                                        /*
                                         */

        </script>

    </body>

</html>


