// Generated from /library/proxy.phtml?showstub=true&objectname=LibraryFrontendController, DO NOT EDIT!
if(typeof(LibraryFrontendController) == 'undefined')
    LibraryFrontendController = new Object();

Object.extend(LibraryFrontendController,
{
    _callback4a9bc472825f8: "/library/proxy.phtml",

    _getJSON: function(r, j)
    {
        j = (j || r.headerJSON || r.responseJSON);
        if(j == null)
            return null;
        if(j.errors || j.failed)
        {
            var f = function(a, c)
            {
                var e = $(c);
                if(a.length > 0)
                {
                    var s = '<ul>';
                    $(a).each(function(e){ s += '<li>'+e+'</li>'; });
                    s += '</ul>';
                    if(e){ e.update(s); e.show(); }
                }
                else
                {
                    if(e){ e.hide(); }
                }
            }
            if(!j.errors)
            {
                j.errors = {error: [], warning: [], info: []}
                if(j.failed)
                    j.errors.error[0] = j.message;
            }

            f(j.errors.error, 'globuleError');
            f(j.errors.warning, 'globuleWarning');
            f(j.errors.info, 'globuleInfo');
        }
        return j;
    },

    _proxy: function(callbackurl, methodName, args, sync)
    {
        var targs = $H();
        for(var i = 0; i < args.length-1; i++){ targs.set('args[' + i + ']', args[i]); }
        callback = args[args.length-1];
        var ar = new Ajax.Request(callbackurl + '?method=' + methodName,
        {
            method: 'post',
            asynchronous: (!sync),
            parameters: targs,
            onComplete: (sync)?null:callback,
            onException: function(request, e){console.debug(request, e);}
        });
        if(sync)
            return new Ajax.Response(ar);
    },

    _getComments: function(){ this._proxy(this._callback4a9bc472825f8, '_getComments', arguments, false); },
    _getComments_sync: function(){ return this._proxy(this._callback4a9bc472825f8, '_getComments', arguments, true); },

    _t: ''
});
// End of generated code

Object.extend(LibraryFrontendController,
{
	getComments: function(formid,id,page,lang)
	{
			var formid = formid;
			var id = id;
			var page = page;
			
			this._getComments(formid, id, page, lang, function(r, j)
	        {
	            j = this._getJSON(r, j);
	            
	            if(!j || j.failed)
	                return;
	            
	            var out = j.out;
				var t = '';

				var style = '';
				for(var pg = 1; pg <= out.totalpage; pg++)
				{
					if (pg == page || (pg==1 && page==0))
						strClass = 'selected';
					else
						strClass = '';
					t+='<a class="'+strClass+'" href="#" onClick="LibraryFrontendController.getComments(\'comment-book-en\','+id+','+pg+');return false;">'+pg+'</a>';
				}
				Element.update('comments', out.content);
				Element.update('pagination', t);
	        }.bind(this));
		}
});		
