function RegistrationConfirmPageController(settings,rpcClientObject)
{
  this._construct(settings,rpcClientObject);
}
(function(){
  var _this= null;
  
  RegistrationConfirmPageController.prototype={
    data: {
      id: -1,
      emailKey: '',
      onCompetitorSuccess: '',
      onEmployerSuccess: ''
    },
    
    showError: null,
    showSuccessMsg: null,
    successLink: null,
    
    eventListeners: {},
    rpcClientObject: null,
    
    Events: {
    },

    addEventListener: function(customEvent,listener)
    {
      if (typeof(_this.eventListeners[customEvent])=='undefined')
        _this.eventListeners[customEvent]=[];
        
      _this.eventListeners[customEvent].push(listener);
      return false;
    },
    
    notifyListeners: function(evt,customEvent,customData)
    {
      if (typeof(_this.eventListeners)=='undefined' || typeof(_this.eventListeners[customEvent])=='undefined')
        return;
      var i=0;
      for (i=0;i<_this.eventListeners[customEvent].length;i++)
      {
        _this.eventListeners[customEvent][i](evt,customData);
      }
    },
    
    _construct: function(settings,rpcClientObject)
    {
      _this=this;
      _this.rpcClientObject=rpcClientObject;
    
      if (typeof(settings)!='undefined')
      {
        if (typeof(settings.onCompetitorSuccess)!='undefined') _this.data.onCompetitorSuccess=settings.onCompetitorSuccess;
        if (typeof(settings.onEmployerSuccess)!='undefined') _this.data.onEmployerSuccess=settings.onEmployerSuccess;
        if (typeof(settings.successLinkId)!='undefined') _this.successLink=document.getElementById(settings.successLinkId);

        if (typeof(settings.errorContainerId)!='undefined'){
          _this.showError=new Spry.Effect.Blind(settings.errorContainerId, {duration: 100, from: '0%', to: '100%', toggle: false});
          var hideError=new Spry.Effect.Blind(settings.errorContainerId, {duration: 1, from: '100%', to: '0%', toggle: false});
          hideError.start();
        }
        
        if (typeof(settings.successMsgContainerId)!='undefined'){
          _this.showSuccessMsg=new Spry.Effect.Blind(settings.successMsgContainerId, {duration: 100, from: '0%', to: '100%', toggle: false});
          var hideSuccessMsg=new Spry.Effect.Blind(settings.successMsgContainerId, {duration: 1, from: '100%', to: '0%', toggle: false});
          hideSuccessMsg.start();
        }
        
      }
      
      var params=Spry.Utils.getLocationParamsAsObject();
      
      if (params.id && params.key)
      {
        _this.data.id=params.id;
        _this.data.emailKey=params.key;
        
        _this.rpcClientObject.setData(_this.data,_this.onDataReady);
        _this.rpcClientObject.call('controllers_registration_form.activateAccount',5);
      }else{
        _this.showError.element.innerHTML='Введенная ссылка неверна.';
        _this.showError.start();
      }
//      alert(params.key);
    },
    
    onDataReady: function(response)
    {
      if (response.error)
      {
        _this.showError.element.innerHTML=response.error;
        _this.showError.start();
        
//        alert(response.error);
        return;
      }
      
      if (response.result.errors){
        _this.showError.element.innerHTML='';
        if (response.result.errors.EBadParams) _this.showError.element.innerHTML+=response.result.errors.EBadParams;
        if (response.result.errors.ENoSuchAccount) _this.showError.element.innerHTML+=response.result.errors.ENoSuchAccount;
        if (response.result.errors.EAccountAlreadyActivated) _this.showError.element.innerHTML+=response.result.errors.EAccountAlreadyActivated;
        if (response.result.errors.EAccountIsBanned) _this.showError.element.innerHTML+=response.result.errors.EAccountIsBanned;
        if (response.result.errors.EBadEmailKey) _this.showError.element.innerHTML+=response.result.errors.EBadEmailKey;
        _this.showError.start();
      }
      
      if (response.result.type){
         
  /*     
        var id = setTimeout("go()",5000);
        function go(){    
            switch (response.result.type){
            case 'competitor': _this.successLink.href=_this.data.onCompetitorSuccess; break;
            case 'employer': _this.successLink.href=_this.data.onEmployerSuccess; break;
            }
        }
     */
        _this.showSuccessMsg.start();
        
      }
    }
  }
})();