function doLogin()
{

    var username = document.getElementById('login-username').value;
    var password = document.getElementById('login-password').value;
    var rememberme = document.getElementById('login-rememberme').value;

    Ext.Ajax.request({
        url: '/connectors/security/login.php',
        params: {
            login_context: 'web',
            username: username,
            password: password,
            rememberme: rememberme
        },
        success: function(o){
            result = Ext.util.JSON.decode( o.responseText );
            location.href = (result.object.id !== undefined) ? './index.php?id=' + result.object.id : './';
        }
    });
}



function sendForm( form, doit )
{

    var fields = form.getElementsByTagName('input');
    var params = {};
    for( var i = 0; i < fields.length; i++ )
    {
        if( fields[i].name == '' ) continue;
        if( fields[i].value == '' ) continue;
        params[fields[i].name] = fields[i].value;
    }

    Ext.Ajax.request({
        url: form.action,
        params: params,
        success: function(o){
            result = Ext.util.JSON.decode( o.responseText );
            if( result.success ) {
                if( typeof result.data.location != 'undefined' ) {
                    location.href = result.data.location;
                } else if( typeof result.data.message != 'undefined' ) {
                    Ext.Msg.show({
                        title: 'Сообщение',
                        msg: result.data.message,
                        icon: Ext.MessageBox.INFO,
                        buttons: Ext.MessageBox.OK
                    });
                }
            }
            else
            {
                Ext.Msg.show({
                    title: 'Ошибка',
                    msg: result.data.message,
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.MessageBox.OK
                });
                if( typeof doit != 'undefined' )
                {
                    eval( doit );
                }
            }
        }
    });

    return false;
}



function reshowCaptcha()
{
    var ca = document.getElementById('captchaImg');
    ca.src = '/captcha.png?rnd=' + Math.random()*1000;
}



function print_r(data)
{
    var str = '';
    for( n in data )
    {
        if( typeof data[n] == 'function' ) continue;
        str += n + ' = ' + data[n] + "\n";
    }
    alert(str);
}
