/* We need the idw namespace to be set up and everything the feedback does goes
into the user_feedback sub-namespace. */
idw.indexpage = {};

idw.indexpage.updateprlist_entries_callback = function(data_in, status, xmlrequest)
{
    var data = data_in['data'];
   $('#listareao_' + data.target).hide();
   $('#listareac_' + data.target).html(data.html);
   $('#listareac_' + data.target).show();
   //$(".inlinepr").click(function() {
   //     idw.indexpage.display_inline_pr(this.id);
   // });
    $(".inlineprdivextend").html("&#x25BC;").css('padding','5px').css('cursor', 'pointer').css('font-weight', 'bold');
};

idw.indexpage.get_section = function(section_id)
{
    var ud_dict = {
        'document_type': 'index_press_release_list',
        'document_id': section_id,
        'lang': idw.lang,
        'target': section_id
        };

    $.post("/objects/document_access/get_data", JSON.stringify(ud_dict),
        idw.indexpage.updateprlist_entries_callback, "json");
};


idw.indexpage.next_sortorder_callback = function(data_in)
{
    location.reload();
};

idw.indexpage.next_sortorder = function(current_sortorder, dir)
{
    var ud_dict = {
        'document_type': 'usersubscription',
        'current_sortorder': current_sortorder,
        'lang': idw.lang,
        'direction': dir,
        };

    $.post("/objects/usersubscription/next_sortorder", JSON.stringify(ud_dict),
        idw.indexpage.next_sortorder_callback, "json");
};

idw.indexpage.my_idw_menu_datahandlercallback = function(data_in, status, xmlrequest)
{
    var data = data_in['data'];
    
    //alert(JSON.stringify(data.form_field.form_field));
    var pos = $("#sortorderdiv").position();;
    var buttonobjectp = {};
    buttonobjectp[idw.translations.inplaceedit.messages[idw.lang].formfieldpanelokbutton] =  function()
                {
                $(this).dialog('close');
                };
    idw.indexpage.myidwdialog = $("<div></div>").dialog({
            autoOpen:true, 
            title: idw.translations.indexpage.messages[idw.lang].my_idw + data.form_field.field_name,
            position: [pos.left - 630, pos.top - 20],
            close: function(event, ui){location.reload();},
            buttons: buttonobjectp,
            width: 650}).html(data.form_field.form_field);
    
}

idw.indexpage.display_my_idw_menu = function(formelem)
{
    if (formelem != 'time')
    {
        /* this dictionary is the data for the RPC-style request and is transmitted 
           to the server in JSON encoding */
        var ud_dict = {
            'name': formelem,
            'value': formelem,
            'lang': idw.lang
            };
        /* send the request and hook the callback to get_form_field_callback_p */
        $.post("/objects/usersubscription/get_form_field", JSON.stringify(ud_dict), idw.indexpage.my_idw_menu_datahandlercallback,
            "json");
    };
};

idw.indexpage.init = function()
{
    $(".extendlist").html("&#x25BC;").css('text-align', 'center').css('cursor', 'pointer').css('font-weight', 'bold').css('font-size', 'large').click(function() {
        if ($('#listareao_' + this.id).is(':hidden'))
        {
            $('#listareao_' + this.id).show();
            $('#listareac_' + this.id).hide();
            $(this).html("&#x25BC;");//BLACK DOWN-POINTING TRIANGLE
        }
        else
        {
            idw.indexpage.get_section(this.id);
            $(this).html("&#x25B2;");//BLACK UP-POINTING TRIANGLE
        }
    });
    
};

$(document).ready(idw.indexpage.init)

