/*

This file is part of Ext JS 4

Copyright (c) 2011 Sencha Inc

Contact:  http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.

*/
Ext.require([
    'Ext.form.*',
    'Ext.Img',
    'Ext.tip.QuickTipManager'
]);

Ext.onReady(function() {
    Ext.tip.QuickTipManager.init();

    var formPanel = Ext.widget('form', {
    url: '/',
    method: 'POST',
//baseParams: {},
renderTo: 'signup',
        frame: true,
        width: 360,
// height: 400,
        bodyPadding: 7,
        bodyBorder: true,
        title: 'Registration is FREE',

                xtype: 'fieldset',
                defaults: {
                    labelWidth: 110,
                    anchor: '100%',
                    layout: {
                        type: 'hbox',
                        defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                    }
                },

        items: [
                    {
                        xtype : 'fieldcontainer',
                        combineErrors: true,
//msgTarget: 'side',
                        fieldLabel: 'Full Name',
                        defaults: {
                            hideLabel: true
                        },
                        items : [
                            {
                                xtype: 'textfield',
                                flex : 1,
                                name : 'firstName',
                                fieldLabel: 'First name',
                                allowBlank: false
                            },
                            {
                                xtype: 'textfield',
                                flex : 1,
                                name : 'lastName',
                                fieldLabel: 'Last name',
                                allowBlank: false,
                                margins: '0'
                            }
                        ]
                    }
, 
                    
             {
                        xtype: 'fieldcontainer',
                        fieldLabel: 'Telephone number',
                        combineErrors: true,
                        defaults: {
                            hideLabel: true
                        },
                        items: [
                            {xtype: 'displayfield', value: '+('},
                            {xtype: 'textfield',    fieldLabel: 'Country code', name: 'phone-1a', width: 29, allowBlank: false},
                            {xtype: 'displayfield', value: ')'},
                            {xtype: 'textfield',    fieldLabel: 'Area code', name: 'phone-2a', width: 29, allowBlank: false, margins: '0 5 0 0'},
                            {xtype: 'displayfield', value: '-'},
                            {xtype: 'textfield',    fieldLabel: 'Number', name: 'phone-3a', flex: 1, allowBlank: false}
                        ]
                    }
,
{
            xtype: 'textfield',
            name: 'email',
            fieldLabel: 'Email Address',
            vtype: 'email',
            style: 'margin-bottom:0px',

            allowBlank: false
        }, 
          {
            xtype: 'displayfield',
            fieldLabel: '',
            value: '( user name = email address )',
style: 'margin:0 0 10px 134px;'
        }, 
          {
            xtype: 'textfield',
            name: 'password1',
            fieldLabel: 'Password',
            inputType: 'password',
            allowBlank: false,
            minLength: 8
        }, 
{
            xtype: 'textfield',
            name: 'password2',
            fieldLabel: 'Repeat Password',
            inputType: 'password',
            allowBlank: false,
            /**
             * Custom validator implementation - checks that the value matches what was entered into
             * the password1 field.
             */
            validator: function(value) {
                var password1 = this.previousSibling('[name=password1]');
                return (value === password1.getValue()) ? true : 'Passwords do not match.'
            }
        },

                    {
                        xtype : 'fieldcontainer',
                        combineErrors: true,
//msgTarget: 'side',
                        fieldLabel: 'Advertiser type',
                        defaults: {
                            hideLabel: true
                        },
                        items : [
{
            xtype: 'radiofield',
            name: 'type',
            inputValue: '1',
checked: true,
            fieldLabel: '',
flex: 1,
            boxLabel: 'Private owner'
        }, {
            xtype: 'radiofield',
            name: 'type',
            inputValue: '2',
            fieldLabel: '',
            labelSeparator: '',
            hideEmptyLabel: false,
flex: 1,
            boxLabel: 'Rental agent',
margins: '0'
        }
                        ]
                    }

,


                    {
                        xtype : 'fieldcontainer',
                        combineErrors: true,
//msgTarget: 'side',
                        fieldLabel: 'Preferred Method<br>of Contact',
                        defaults: {
                            hideLabel: true
                        },
                        items : [
{
            xtype: 'radiofield',
            name: 'contact',
            inputValue: 'phone',
checked: true, 
            fieldLabel: '',
flex: 1,
            boxLabel: 'Phone'
        }, {
            xtype: 'radiofield',
            name: 'contact',
            inputValue: 'email',
            fieldLabel: '',
            labelSeparator: '',
            hideEmptyLabel: false,
flex: 1,
            boxLabel: 'Email',
margins: '0'
        }
                        ]
                    }

,


        {
            xtype: 'checkboxfield',
            name: 'acceptTerms',
            fieldLabel: 'Terms of Use',
            hideLabel: true,
            style: 'margin-top:5px',
boxLabel: 'I have read and accept the <a target="_blank" href="//www.holidayrentalweb.com/terms_and_conditions">Terms of Use</a>.',

            // Custom validation logic - requires the checkbox to be checked
            getErrors: function() {
                return this.getValue() ? [] : ['You must accept the Terms of Use']
            }
        }],

        dockedItems: [{
            xtype: 'container',
            dock: 'bottom',
            layout: {
                type: 'hbox',
                align: 'middle'
            },
            padding: '0 10 0',

            items: [{
                xtype: 'displayfield',
value: '<a target="_blank" href="https://trustsealinfo.verisign.com/splash?form_file=fdf/splash.fdf&amp;dn=www.holidayrentalweb.com&amp;lang=enWordpress"  id="ext-gen1176"><img style="width: 130px; height: 88px;" src="/verisign.gif" alt="" id="ext-gen1134"></a>', 

                flex: 1
            }, {
                xtype: 'button',
//icon: 'http://www.letmyhome.holidayrentalweb.com/images/botton_signup.gif',
                formBind: true,
//disabled: true,
type: 'submit',
//fieldLabel: 'xxxx',
text: '<span style="font-size:24px;">Register Now</span>',
                width: 184,
                height: 43,
                handler: function() {
                    var form = this.up('form').getForm();

                    form.submit({
//clientValidation: true,
url: '/',
                        success: function(form, action) {
                           //...
//alert(action.result.user_id);
location.href = 'https://www.holidayrentalweb.com/signin?id=' + action.result.user_id;
                        },
                        failure: function(form, action) {
                            //...
alert('Failure, may be user exists, check email!');
                        }
                    });

                    if (form.isValid()) {
//Ext.Msg.alert('Submitted Values', form.getValues(true));
                    }
                }
            }]
        }]
    });

});

