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


Object.extend(ShareController,
{
    shareJob: function(missionId)
    {
        try
        {
            userControler.callAction(this._shareJob.bind(this, missionId));
        }
        catch(e)
        {
            console.debug(e);
        }
        return false;
    },
     _shareJob: function(missionId, fromLogin)
    {
        if(fromLogin)
        {
            this._reload = true;
            myLightWindow.openWindow($('share_'+missionId));
        }
        else
            myLightWindow.activate(null, $('share_'+missionId));
    }
});

if(typeof(Share2Controller) == 'undefined')
  Share2Controller = new Object();
Object.extend(Share2Controller,
{
  _callbackShare: "/_ajax/users.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);
  },

  _getShareUrl: function(){ this._proxy(this._callbackShare, '_getShareUrl', arguments, false); },
  _getShareUrl_sync: function(){ return this._proxy(this._callbackShare, '_getShareUrl', arguments, true); },


  _t: ''
});

Object.extend(Share2Controller,
{
    shareJob: function(mid,service)
    {
       
       userControler.callAction(
        		function(e)
          		{
          			Share2Controller._getShareUrl(mid, service,Share2Controller._urlReceived.bind(this));
          				
          				
          		});
       return false;
    },
    _urlReceived : function(transport)
    {
   		if(!transport.responseJSON.failed)
        {
            window.open (transport.responseJSON.out);
            myLightWindow.deactivate();
        }
        else
        {
            myLightWindow.deactivate();
        }
    
    }
    
});
