${add_js_home_local('tools.js', 'admin')}
<%

choose=''

%>
<div id="languages_form">
<%def name="select_lang(i18n, lang_selected)">
    % if i18n==lang_selected: 
        <%
        return "choose_flag"
        %>
    % else: 
        <%
        return "no_choose_flag"
        %>
    % endif 
</%def>
<%def name="hide_lang(i18n, lang_selected)">
    % if i18n!=lang_selected:
        style="display:none;"
    % endif
</%def>
<input type="hidden" name="${real_name_form}" id="${name_form}_i18n_value" value="" />
% if lang_selected!=None:
    % for i18n in arr_i18n:
        
        ${form.change_name(name_form+'_'+i18n)}
        <%
        form.default_value=default_value[i18n]
        %>
        <span id="${name_form}_${i18n}_switch" class="${name_form}_i18n_form">${form.form()|n}</span>        <a class="choose_flag ${name_form}_i18n_flag lang_form" id="${name_form}_${i18n}_element" href="#"><img src="${make_media_url_module('images/languages/'+i18n+'.png', 'admin')}" alt="${name_form}_${i18n}"/></a> 
    % endfor 
% endif
</div>

<script>

//In submit convert in json

$(".${name_form}_i18n_flag").closest('form').submit( function () {

    arr_i18n={}

    $(".${name_form}_i18n_form").each(function () {
    
        var lang=$(this).attr('id').replace('${name_form}_','').replace('_switch', '');
        
        var child_input=$('#${name_form}_'+lang+'_form');

        arr_i18n[lang]=child_input.val();

    });

    document.getElementById("${name_form}_i18n_value").value=JSON.stringify(arr_i18n);

    return true;

});

</script>
