/*global Ext, AJAX_ACTION, f */
var f;

function doSignUpValidate(){
    if(f.form.isValid()){
        f.form.submit({
            url: AJAX_ACTION,
            params: {action: 'sign_up', vals: f.getForm().getValues()},
            waitMsg: 'Saving, please wait...',
            success: function(){
                //alert('success');
                Ext.MessageBox.show({ 
                    title: 'Success',
                    msg: 'Account details were saved. Please check your mailbox in the next few moments.',
                    buttons: Ext.Msg.OK,
                    icon: Ext.MessageBox.INFO 
                });
                f.getForm().reset();    
            },
            failure: function(){
                alert('Seems to have been an error. Try again');
            }
        });
    }

}

Ext.onReady(function(){


f = new Ext.FormPanel({
    //title: 'Sign up',
    frame: true,
    border: false,
    bodyStyle: 'padding: 10px',
    renderTo: 'sign-up-form-div',
    labelAlign: 'right',
    labelWidth: 150,
    buttonAlign: 'right',
    items:[     {xtype: 'fieldset', 
                    title: 'Company Details',
                    autoHeight: true,
                    items:[ {xtype: 'textfield', 
                            name: 'company',
                            fieldLabel: 'Company Name',
                            allowBlank: false, minLength: 3,
                            msgTarget: 'side',
                            width: '70%'
                            },
                            {xtype: 'textarea', 
                            name: 'address',
                            fieldLabel: 'Address',
                            allowBlank: false, minLength: 3,
                            msgTarget: 'side',
                            width: '70%'
                            },
                        {xtype: 'textfield', 
                            name: 'postcode',
                            fieldLabel: 'Postcode',
                            allowBlank: true, minLength: 3,
                            msgTarget: 'side',
                            width: '40%'
                            },
                        {xtype: 'textfield', 
                            name: 'tel',
                            fieldLabel: 'Telephone',
                            allowBlank: true, minLength: 3,
                            msgTarget: 'side',
                            width: '60%'
                            },
                        {xtype: 'textfield', 
                            name: 'fax',
                            fieldLabel: 'Fax',
                            allowBlank: true, minLength: 3,
                            msgTarget: 'side',
                            width: '60%'
                            }
                    ]
                },
                {xtype: 'fieldset', 
                    title: 'Contact Details',
                    autoHeight: true,
                    items:[ {xtype: 'textfield', 
                            name: 'name',
                            fieldLabel: 'Your Name',
                            allowBlank: false, minLength: 3,
                            msgTarget: 'side',
                            width: '70%'
                            },
                            {xtype: 'textfield', 
                            name: 'title',
                            fieldLabel: 'Title/Position',
                            msgTarget: 'side',
                            width: '70%'
                            },
                            {xtype: 'textfield', 
                            name: 'email',
                            fieldLabel: 'Email',
                            allowBlank: false, 
                            msgTarget: 'side',
                            width: '90%',
                            vtype: 'email'
                            },
                        {xtype: 'textfield', 
                            name: 'mobile',
                            fieldLabel: 'Mobile',
                            minLength: 3,
                            msgTarget: 'side',
                            width: '50%'
                            }
                    ]
                }
    ],
    buttons:[   {text: 'Sign Up' , 
                handler: doSignUpValidate
                }]
    

});

});

