/*
 * Ext JS Library 2.0
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
Ext.onReady(function(){

    Ext.QuickTips.init();
    var el = Ext.get('testform');
    if (el != null) {
        el.setVisible(false, false);
        var openidForm = new Ext.form.FormPanel({
            border: false,
            labelWidth: 1,
            defaults: {
                autoHeight: true,
                bodyStyle: 'padding:3px'
            },
            width: 180,
            items: {
                xtype: 'tabpanel',
                activeTab: 0,
                defaults: {
                    autoHeight: true,
                    bodyStyle: 'padding:3px'
                },
                items: [{
                    title: 'OpenID',
                    id: 'openid_tab',
                    layout: 'form',
                    activeTab: 0,
                    layoutConfig: {
                        // layout-specific configs go here
                        labelSeparator: '',
                    },
                    defaults: {
                        autoHeight: true,
                        bodyStyle: 'padding:3px'
                    },
                    items: [{
                        xtype: 'textfield',
                        name: 'openid',
                        cls: 'openid-identifier',
                    },				
                    {
                      id: 'hidden_loginform_action',
            					xtype: 'hidden',
                      name: 'login',
            					value: 'Logout',
                    },],
                }, {
                    title: 'Password',
                    id: 'password_tab',
                    layout: 'form',
                    labelWidth: 0,
                    activeTab: 0,
                    disabled: true,
                    defaults: {
                        autoHeight: true,
                        bodyStyle: 'padding:3px',
                        width: 100
                    },
                    items: [{
                        xtype: 'textfield',
                        fieldLabel: 'UserID',
                        name: 'Username',
                    }, {
                        xtype: 'textfield',
                        fieldLabel: 'Password',
                        name: 'Password',
                        inputType: 'password',
                    }, {
                      id: 'hidden_loginform_action',
            					xtype: 'hidden',
                      name: 'login',
            					value: 'Logout',
                    },],
                }]
            },
            buttons: [{
                text: 'Log Me In',
                handler: function(){
                    openidForm.getForm().submit({
                        url: 'loginopenid_redirect.php',
                        waitMsg: 'Redirecting ...',
                        waitTitle: 'Redirect',
                        success: function(form, action){
                            var serverurl = action.result.data.openid_server_url;
                            var postparams = action.result.data.postParams;
                            el.update(postparams);
                            el.set({
                                action: serverurl
                            });
                            el.dom.submit();
                        },
                        failure: function(form, action){
                            alert(action.failureType);
                        }
                        
                    });
                }
            },
            {
                text: 'Log Out',
                handler: function(){
                    openidForm.getForm().getEl().dom.submit();
                }
            }]
        });
        openidForm.render('openid_login');
    }
});

