var ajax_responder = Class.create({
    result:null,
    id_form:null,
    field_class:'field',
    initialize:function(result, id_form)
    {
        if (!id_form)
        {
            id_form = null;
        }
        try
        {
            this.result = eval("("+result+")");
            if (!this.success())
            {
                if (this.result.datas.logged_out === true)
                {
                    if (user_logout)
                    {
                        user_logout.show_popin();
                    }
                    else
                    {
                        alert("Session expired");
                    }
                }
                this.error();
            }
        }
        catch (err)
        {
            this.parsing_json_error(err, result);
        }
        this.id_form = id_form;
        this.exec_script_before();
    },
    success:function()
    {
        return (this.result.status);
    },    
    error:function()
    {
        pdt_console.log("Server said : failed - (it's not a code error, it's a control error)");
    },
    parsing_json_error:function(err, json_str)
    {
      pdt_console.log('Parsing json error:\n' + json_str);
    },
    get_obj:function()
    {
        return (this.result);
    },
    exec_script_before:function(options)
    {
        if (this.result && this.result.datas && this.result.datas.script_before)
        {
            eval(this.result.datas.script_before);
        }
    },
    exec_script_after:function(options)
    {
        if (this.result && this.result.datas && this.result.datas.script_after)
        {
            eval(this.result.datas.script_after);
        }        
    }
});

