var PageUserRegister = Class.create({},
{
  init: function()
  {
    this.allowRegister = true;
    $('#regForm').submit(this.getHandler(this, 'checkRegistrationForm'));  
    this.postURL = location.href.toString();
    if (this._controls.captcha)
      this._controls.captcha.addEventListener('captchaResult', this.getHandler(this, 'checkRegistrationForm2'));
  },
  
  checkRegistrationForm: function()
  {
    if (this.allowRegister)
    {
      this.allowRegister = false;      
      
      this._controls.captcha.checkCaptcha();
    }
    return false;
  },
  
  checkRegistrationForm2: function(result)
  {
    if (result)
    {
      var e = document.forms["registration"].elements;  
      if (!(
            checkUserName(e["userName"].value, new Array(4, 32), this._serverData.blockNames, this.postURL) &&
            checkPassword(e["password1"].value, e["password2"].value, new Array(6, 32)) &&
            checkEmail(e["eMail"].value, this.postURL)
            )
         )
      {
        this.allowRegister = true;
      }
      else
      {
        $('#regForm').unbind('submit');
        $('#regForm').submit();
      }
    }
    else
    {
      this.allowRegister = true;
      this.showError('Security code is wrong! Please try again!');
    }
  },
  showError: function(message)
  {
    alert(message);
  }
}, [Page]);