/**
 * @extends SyqComponent
 */
function SyqComponent_regform()
{
    this.names = new Array('logon','reg','remPass','error');

    this.tabsEnabled = true;

    this.afterLogonUrl = null;

    this.showTab = function(name)
    {
        for (var i=0;i<this.names.length;i++)
        {
            var nameI = this.names[i];
            if (nameI!='error') this.components[nameI+'_tab'].setActive(name==nameI);
            if (name==nameI) this.q('#'+nameI+'_content').show();
            else             this.q('#'+nameI+'_content').hide();
        }
    };

    this.getTab = function()
    {
        for (var i=0;i<this.names.length;i++)
        {
            if (this.names[i]!='error' && this.components[this.names[i]+'_tab'].isActive()) return this.names[i];
        }
        return '';
    };

    this.close_click = function() { if (this.tabsEnabled) this.show(false); else syquery.reload(); };

    this.logon_tab_click = function() { if (this.tabsEnabled) this.showTab('logon'); return false; };
    this.reg_tab_click = function() { if (this.tabsEnabled) this.showTab('reg'); return false; };
    this.remPass_tab_click = function() { if (this.tabsEnabled) this.showTab('remPass'); return false; };

    this.show = function(isShow)
    {
        var f = this.q('#regForm');
        if (isShow)
        {
            showMainShadow(true);
            f.show();
            f.center();
        }
        else
        {
            showMainShadow(false);
            f.fadeOut('fast');
        }
    };

    this.showError = function(text)
    {
        var prevTab = this.getTab();
        this.q('#error_content div p').html(text);
        this.showTab('error');
        var self = this;
        setTimeout(function(){self.showTab(prevTab);}, 2000);
    };

    this.showSuccessReg = function()
    {
        this.q('#error_content div p').css({ color:'#727258', fontSize: '13px', fontWeight: 'normal' }).html(
           "<b>" + this.q('#regLogin').val() + "</b>"
           +", Мы рады приветствовать Вас на нашем сайте StatusMania.ru, который посвящен статусам для аськи, вконтакте и одноклассников.<br><br>"
           +"<b>Здесь вы можете:</b><br>"
           +"- <a href='/add'>добавлять</a> свои статусы,<br>"
           +"- оценивать статусы других пользователей сайта,<br>"
           +"- выбрать и установить статус, который расскажет другим о ваших чувствах, мыслях и душевном состоянии!<br><br>"
           +"<div align='center'><a href='#' onclick='syquery.reload()' style='color: #FF114D'>Войти</a></div>"
        );
        this.showTab('error');
        
        var self = this;
        
        this.tabsEnabled = false;
    };

    this.showSuccessRemPass = function()
    {
        this.q('#error_content div p').html('Пользователь найден. Письмо с паролем выслано Вам на e-mail.');
        this.q('#error_content div p').css('color','#090');
        this.showTab('error');
        var self = this;
        setTimeout(function(){ self.show(false); }, 5000);
    };

    this.reg_click = function()
    {
        this.q('#regLogin').val(this.q('#regLogin').val().trim());
        if (this.q('#regLogin').val()=='')
        {
            this.q('#regLogin').focus();
            return false;
        }

        var loginRE = /^[a-zA-Zа-яА-Я][a-zA-Z0-9а-яА-Я]+$/;
        if (!loginRE.test(this.q('#regLogin').val()))
        {
            alert("Логин должен состоять из букв и цифр. Начинаться он должен с буквы и содержать не меньше двух символов.");
            this.q('#regLogin').focus();
            return false;
        }

        this.q('#regPassword').val(this.q('#regPassword').val().trim());
        if (this.q('#regPassword').val()=='')
        {
            this.q('#regPassword').focus();
            return false;
        }

        this.q('#regEmail').val(this.q('#regEmail').val().trim());
        var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(this.q('#regEmail').val()))
        {
            this.q('#regEmail').focus();
            return false;
        }

        return true;
    };

    this.logonSuccess = function()
    {
        if (this.afterLogonUrl) syquery.redirect(this.afterLogonUrl);
        else                    syquery.reload();
    };
};
SyqComponent_regform.prototype = new SyqComponent;

