// FROM http://xpertize.gb.int/_ajax/contact.php?showstub=true&objectname=ContactsController
if(typeof(ContactsController) == 'undefined')
  ContactsController = new Object();

Object.extend(ContactsController,
{
  _callback471f40d6ec215: "/_ajax/contact.php",

  _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);
  },

  editContact: function(){ this._proxy(this._callback471f40d6ec215, 'editContact', arguments, false); },
  editContact_sync: function(){ return this._proxy(this._callback471f40d6ec215, 'editContact', arguments, true); },

  _loadContacts: function(){ this._proxy(this._callback471f40d6ec215, '_loadContacts', arguments, false); },
  _loadContacts_sync: function(){ return this._proxy(this._callback471f40d6ec215, '_loadContacts', arguments, true); },

  forwardMission: function(){ this._proxy(this._callback471f40d6ec215, 'forwardMission', arguments, false); },
  forwardMission_sync: function(){ return this._proxy(this._callback471f40d6ec215, 'forwardMission', arguments, true); },
  
  _searchContacts: function(){ this._proxy(this._callback471f40d6ec215, '_searchContacts', arguments, false); },
  _searchContacts_sync: function(){ return this._proxy(this._callback471f40d6ec215, '_searchContacts', arguments, true); },
 	
  _t: ''
});
// END OF GENERATED CODE

Object.extend(ContactsController,
{
    loadContacts: function(letter, container, template)
    {
        this._loadContacts(letter, this._contactsLoaded.bind(this, container, template));
    },
	_contactsLoaded: function(container, template, transport)
    {
        var json = transport.responseJSON;
        if(json && !json.failed)
        {
            container = $(container);
            container.update('');
            $A(json.out).each(function(contact){
                container.insert(template.evaluate(contact));
            });
        }
        else
        {
            new AlertBox(json.message, {alertType: 'Error', okButtonClass: 'button'});
        }
    },
    searchContacts:  function(lastName,firstName, container, template) 
    {
    	this._searchContacts(lastName,firstName, this._contactsFound.bind(this, container, template));
    },
    _contactsFound: function(container, template, transport)
    {
        var json = transport.responseJSON;
        if(json && !json.failed)
        {
            container = $(container);
            container.update('');
            $A(json.out).each(function(contact){
                container.insert(template.evaluate(contact));
            });
        }
        else
        {
            new AlertBox(json.message, {alertType: 'Error', okButtonClass: 'button'});
        }
    }
});
