{% if dlg is not none %}
    {% set opener = "window.dialogArguments.win" %}
{% else %}
    {% set opener = "opener" %}
{% endif %}
<!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>{{ 'thesaurus:: Proprietes' | trans }}</title>
        <link type="text/css" rel="stylesheet" href="/assets/thesaurus/css/thesaurus{% if not app.debug %}.min{% endif %}.css" />
        <style type="text/css">
            a
            {
                text-decoration:none;
                font-size: 10px;
            }
            .path_separator
            {
                color:#ffff00;
            }
            .main_term
            {
                font-weight:900;
            }
        </style>
        <script type="text/javascript" src="/assets/vendors/jquery/jquery{% 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">
            function loaded()
            {
                window.name="PROPERTIES";
                self.focus();
            }
        </script>
    </head>
    <body id="desktop" onload="loaded();" class="dialog">
        <div class="menu" id="flagsMenu" style="z-index:50">
            {% for code, language in languages %}
                <a id='flagMenu_{{ code }}' href='javascript:void(0)' class=''>
                <img src='/assets/common/images/lng/{{ code }}_flag_18.gif' />{{ language }}</a>
            {% endfor %}
        </div>
        <div class="menu" id="syMenu" style="z-index:50">
            <a href="javascript:void(0)" id="delete_sy">{{ 'thesaurus::menu: supprimer' | trans }}</a>
        </div>

        <div style='text-align:right'>
            <b>id:</b>&nbsp;{{ id }}
        </div>
        <H4>{{ fullpath | raw }}</H4><br/>
        {% if typ == "CT" %}
            <br/>
        {% elseif typ == "TH" %}
            {% trans with {'%hits%' : hits} %}thesaurus:: %hits% reponses retournees{% endtrans %}
            <br/>
            <br/>
        {% endif %}
        <div id="TSY" class="tableContainer" style="margin:10px; position:relative; top:0px; left:0px">
            <div>
                <table border="0" cellpadding="0" cellspacing="0" style="width:100%; ">
                    <col style="width:40px;" />
                    <col style="width:30px;" />
                    <col style="width:auto;" />
                    <col style="width:40px;" />
                    <col style="width:140px;" />
                    <col style="width:14px;" />
                    <thead>
                        <tr>
                            <th>&nbsp;</th>
                            <th>&nbsp;</th>
                            <th>{{ 'thesaurus:: synonymes' | trans }}</th>
                            <th>{{ 'thesaurus:: hits' | trans }}</th>
                            <th>{{ 'thesaurus:: ids' | trans }}</th>
                            <th></th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div style="position:relative; height:150px; overflow:scroll">
                <div style="position:relative; height:150px; ">
                    <table border="0" cellpadding="0" cellspacing="0" style="width:100%;">
                        <col style="width:40px;" />
                        <col style="width:30px;" />
                        <col style="width:auto;" />
                        <col style="width:40px;" />
                        <col style="width:140px;" />
                        <tbody id="LSY" style="">

                        {% for data in synonyms %}
                            <tr class='s_' id='SYN_{{ data['id'] }}' hits='{{ data['hits'] }}'>
                                <td style='text-align:center;'>
                                {% if loop.index > 0 %}
                                    <img id="BTNU_{{ data['id'] }}" src="/assets/thesaurus/images/up.gif" />
                                {% endif %}
                                {% if not loop.last %}
                                    <img id="BTND_{{ data['id'] }}" src="/assets/thesaurus/images/down.gif" />
                                {% endif %}
                                </td>
                                {% if data['lng'] %}
                                    <td id='FLG_{{ data['id'] }}'><img src='/assets/common/images/lng/{{ data['lng'] }}_flag_18.gif' /></td>
                                {% else %}
                                    <td id='FLG_{{ data['id'] }}'><img src='/assets/thesaurus/images/noflag.gif' /></td>
                                {% endif %}
                                <td>{{ data['t'] }}</td>
                                <td>{{ data['hits'] }}</td>
                                <td>{{ data['id'] }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    <center>
        <form onsubmit="return(false);">
            <input style="position:relative; z-index:2" type="button" id="close_button" value="{{ 'boutton::fermer' | trans }}" onclick="self.close();">
        </form>
    </center>
    <script type="text/javascript">
        // gui callback du menu des drapeaux
        var nsy = {{ synonyms | length }};

        function cbME_flags(action, cbParm, menuelem_id)
        {
            if(action != "SELECT" || !menuelem_id) {
                return;
            }
            lng = menuelem_id.substr(9,2);

            url = "xmlhttp/changesylng.x.php";
            parms  = "bid={{ bid | url_encode }}";
            parms += "&typ={{ typ | url_encode }}";
            parms += "&piv={{ piv | url_encode }}";
            parms += "&id=" + cbParm.id.substr(4);
            parms += "&newlng=" + encodeURIComponent(lng);

            ret = loadXMLDoc(url, parms, true);
            sy_list = ret.getElementsByTagName("sy_list").item(0);

            refresh_sy(sy_list);

            refresh = ret.getElementsByTagName("refresh");

            for(i=0; i<refresh.length; i++)
            {
                switch(refresh.item(i).getAttribute("type"))
                {
                    case "CT":
                    {{ opener }}.reloadCtermsBranch(refresh.item(i).getAttribute("id"));
                    {{ opener }}.myGUI.select({{ opener }}.document.getElementById("THE_{{ id }}"));
                        break;
                    case "TH":
                    {{ opener }}.reloadThesaurusBranch(refresh.item(i).getAttribute("id"));
                    {{ opener }}.myGUI.select({{ opener }}.document.getElementById("THE_{{ id }}"));
                        break;
                }
            }
        }

        // gui callback du menu des synonymes
        function cbME_synonym(action, cbParm, menuelem_id)
        {
            if(action == "INIT")
            {
                if(nsy <= 1)
                {
                    // pas d'action possible s'il ne reste qu'un seul synonyme
                    // alert(nsy);
                    document.getElementById("delete_sy").className = "disabled";
                    // document.getElementById("reject_sy").className = "disabled";
                }
                else
                {
                    if(cbParm && cbParm.hits > 0)
                    {
                        // y'a des hits, on peut pas supprimer
                        // document.getElementById("reject_sy").className = "";
                        document.getElementById("delete_sy").className = "";
                    }
                    else
                    {
                        // pas de hits : on peut supprimer
                        // document.getElementById("reject_sy").className = "";
                        document.getElementById("delete_sy").className = "";
                    }
                }
                return;
            }

            if(action != "SELECT" || !menuelem_id) {
                return;      // pas d'option de menu : on est sorti du menu sans cliquer
            }

            switch(menuelem_id)
            {
                case "delete_sy":    // cbParm = objet 'TR'
                    url = "xmlhttp/getsy.x.php";
                    url +=  "?bid={{ bid | url_encode }}";
                    url += "&id=" + cbParm.id.substr(4);
                    url += "&typ={{ typ | url_encode }}";
                    ret = loadXMLDoc(url, null, true);
                    // alert(ret);
                    fullpath = ret.getElementsByTagName("fullpath").item(0).firstChild.nodeValue;
                    //alert("delete : cbParm.obj={id:'" + cbParm.id + "'} ; menuelem_id='" + menuelem_id + "'");

                    url = "xmlhttp/delsy.x.php";
                    parms  = "bid={{ bid | url_encode }}";
                    parms += "&piv={{ piv | url_encode }}";
                    parms += "&typ={{ typ | url_encode }}";
                    parms += "&id=" + cbParm.id.substr(4);

                    if(confirm($.sprintf("{{ 'thesaurus:: Confirmer la suppression du terme %s' | trans | e('js') }}","\n\n"+fullpath+"\n\n")))
                    {
                        ret = loadXMLDoc(url, parms, true);

                        sy_list = ret.getElementsByTagName("sy_list").item(0);
                        refresh_sy(sy_list);

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

        function refresh_sy(sy_list)
        {
            oldtbody = document.getElementById("LSY");
            tbody = document.createElement("tbody");
            tbody.setAttribute("id", "LSY");

            for(nsy=0, n=sy_list.firstChild; n; n=n.nextSibling, nsy++)
            {
                tr = tbody.appendChild(document.createElement("tr"));
                // tr.className = n.getAttribute("sel") ? "S_" : "s_";
                tr.className = "s_";
                tr.id = "SYN_" + (id=n.getAttribute("id"));

                td = tr.appendChild(document.createElement("td"));
                td.style.textAlign = "center";
                if(nsy > 0)
                {
                    img = td.appendChild(document.createElement("img"));
                    img.id = "BTNU_" + id;
                    img.src = "/assets/thesaurus/images/up.gif";
                    if(n.nextSibling)
                    {
                        td.appendChild(document.createTextNode(" "));
                    }
                }
                if(n.nextSibling)
                {
                    img = td.appendChild(document.createElement("img"));
                    img.id = "BTND_" + id;
                    img.src = "/assets/thesaurus/images/down.gif";
                }

                td = tr.appendChild(document.createElement("td"));
                td.id = "FLG_"+(nsy+1);
                // td.innerText = n.getAttribute("lng");
                img = td.appendChild(document.createElement("img"));
                img.setAttribute("src", "/assets/common/images/lng/"+n.getAttribute("lng")+"_flag_18.gif");

                td = tr.appendChild(document.createElement("td"));
                // td.colSpan = "2";
                // td.setAttribute("colSpan", "3");          // attention au 'S' majuscule !!!
                td.innerHTML = n.getAttribute("t");

                td = tr.appendChild(document.createElement("td"));
                td.innerHTML = n.getAttribute("hits");

                td = tr.appendChild(document.createElement("td"));
                td.innerHTML = n.getAttribute("id");

                if(n.getAttribute("sel")) {
                    myGUI.select(tr);
                }
            }

            newtbody = oldtbody.parentNode.replaceChild(tbody, oldtbody);
        }


        function cbDD_TSY(evt, type, eventObj)
        {
            ret = true;
            switch(type)
            {
                case "RMOUSEDOWN":
                    if(o = eventObj.Src0)
                    {
                        for(tr=o; tr && (tr.nodeName!="TR" || !tr.id || tr.id.substr(0, 4)!="SYN_"); tr=tr.parentNode)
                            ;
                        if(tr)
                            myGUI.select(tr);
                        switch(o.id.substr(0, 4))
                        {
                            case "FLG_":    // le drapeau
                                document.getElementById("flagsMenu").runAsMenu( evt, tr );
                                break;
                            case "SYN_":    // le synonyme
                                document.getElementById("syMenu").runAsMenu( evt, tr );
                                break;
                        }
                    }
                    break;
                case "MOUSEDOWN":
                    if(o = eventObj.Src0)
                    {
                        for(tr=o; tr && (tr.nodeName!="TR" || !tr.id || tr.id.substr(0, 4)!="SYN_"); tr=tr.parentNode)
                            ;
                        if(tr)
                            myGUI.select(tr);
                        switch(o.id.substr(0, 5))
                        {
                            case "BTNU_":
                                syChgPos(1);
                                break;
                            case "BTND_":
                                syChgPos(-1);
                                break;
                        }
                    }
                    break;
                case "DBLCLICK":
                    break;
            }

            return(ret);
        }

        function syChgPos(dir)
        {
            if(!myGUI.selectedObject || myGUI.selectedObject.id.substr(0, 4)!="SYN_") {
                return;
            }

            url = "xmlhttp/changesypos.x.php";
            parms  = "bid={{ bid | url_encode }}";
            parms += "&piv={{ piv | url_encode }}";
            parms += "&typ={{ typ | url_encode }}";
            parms += "&id=" + myGUI.selectedObject.id.substr(4);
            parms += "&dir=" + dir;

            ret = loadXMLDoc(url, parms, true);

            sy_list = ret.getElementsByTagName("sy_list").item(0);
            refresh_sy(sy_list);

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

        myGUI = new GUI("myGUI", "desktop", "FR");
        myGUI.setClickable("TSY", cbDD_TSY);
        myGUI.setAsMenu("flagsMenu", cbME_flags);
        myGUI.setAsMenu("syMenu", cbME_synonym);

    </script>
    </body>
</html>
