
Ext.onReady(function() {

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var top = new Ext.FormPanel({
        labelAlign : 'top',
        frame : true,
        title : 'Enquiry Details',
        bodyStyle : 'padding:5px 5px 0',
        width : 450,
        monitorValid : true,
        url : "registerviewer.php",

        items : [{
                    layout : 'column',
                    items : [{
                                columnWidth : .5,
                                layout : 'form',
                                items : [{
                                            xtype : 'textfield',
                                            fieldLabel : 'First Name',
                                            name : 'first',
                                            allowBlank : false,
                                            anchor : '90%',
                                            tabIndex : 1
                                        }, {
                                            xtype : 'textfield',
                                            fieldLabel : 'Company',
                                            name : 'company',
                                            allowBlank : false,
                                            anchor : '90%',
                                            tabIndex : 3
                                        }]
                            }, {
                                columnWidth : .5,
                                layout : 'form',
                                items : [{
                                            xtype : 'textfield',
                                            fieldLabel : 'Last Name',
                                            name : 'last',
                                            allowBlank : false,
                                            anchor : '90%',
                                            tabIndex : 2
                                        }, {
                                            xtype : 'textfield',
                                            fieldLabel : 'Email',
                                            name : 'email',
                                            allowBlank : false,
                                            vtype : 'email',
                                            anchor : '90%',
                                            tabIndex : 4
                                        }]
                            }]
                }, {
                    xtype : 'textfield',
                    fieldLabel : 'Additonal Comments',
                    allowBlank : true,
                    height : 150,
                    name : 'comment',
                    anchor : '95%',
                    tabIndex : 7
                }],

        buttons : [{
            text : 'Submit',
            formBind : true,
            handler : function() {
                top.getForm().submit({
                    params : {
                        ip : ip
                    },
                    success : function(form, action) {
                      
                                            window.location = "register.php"
                                        
                    },
                    failure : function(form, action) {
                        switch (action.failureType) {
                            case Ext.form.Action.CLIENT_INVALID :
                                Ext.Msg
                                        .alert("Failure",
                                                "Form fields may not be submitted with invalid values");
                                break;
                            case Ext.form.Action.CONNECT_FAILURE :
                                Ext.Msg.alert("Failure",
                                        "Ajax communication failed");
                                break;
                            case Ext.form.Action.SERVER_INVALID :
                                Ext.Msg.alert("Failure", action.result.msg);
                        }
                    }
                });
            }
        }]
    });

    top.render('inputform');

})
