
Ext.onReady(function(){

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

    var regJobSeeker = new Ext.FormPanel({
        labelAlign: 'side',        
        buttonAlign: 'right',
        id : 'regJobSeeker',
        bodyBorder:false,
        border:false,
        frame:false,
        hideBorders:true,
        bodyStyle: '',
        monitorValid:true,
        width: 400,
        labelWidth: 125,
	layout: 'form',
	fileUpload: true,

        items: [{
                    xtype:'textfield',
                    fieldLabel: 'First Name',
                    name: 'firstname',
                    allowBlank: false,
		    blankText: 'First name cannot be blank',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Last Name',
                    name: 'lastname',
                    allowBlank: false,
		    blankText: 'Last name cannot be blank',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Address',
                    name: 'address1',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    name: 'address2',
                    labelSeparator: '',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    name: 'address3',
                    labelSeparator: '',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'State',
                    name: 'state',
                    anchor:'95%'
                }, new Ext.form.ComboBox({
						store: countries,
					     	fieldLabel: 'Country',
					        displayField:'country',
					        typeAhead: true,
					        mode: 'local',
					        forceSelection: true,
					        triggerAction: 'all',
					        emptyText:'Select a country...',
					        selectOnFocus:true,
					        name: 'country',
						editable: true,
					        width:250
				    }),
		{
                    xtype:'textfield',
                    fieldLabel: 'Phone Number',
                    allowBlank: false,
		    blankText: 'Phone number cannot be blank',
                    name: 'phone',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Email',
                    allowBlank: false,
		    blankText: 'Email cannot be blank',
                    name: 'email',
                    vtype:'email',
                    anchor:'95%'
                },{
                	xtype:'textfield',
                	allowBlank: false,
			blankText: 'Password cannot be blank',
                    	fieldLabel: 'Password',
			name: 'password',
                    	inputType: 'password',
                    	anchor:'95%',
			id: 'pass'
		},{
		      	xtype:'textfield',
		      	allowBlank: false,
		        fieldLabel: 'Confirm Password',
			blankText: 'You must confirm your password',
		        name: 'pass-cfrm',
		        inputType: 'password',
		        vtype: 'password',
		        anchor:'95%',
		        initialPassField: 'pass' // id of the initial password field
		}, new Ext.form.ComboBox({
		        store: sectors,
		     	fieldLabel: 'Sector',
		        displayField:'sector',
		        typeAhead: true,
		        mode: 'local',
		        forceSelection: true,
		        triggerAction: 'all',
		        emptyText:'Select a sector...',
		        selectOnFocus:true,
		        width:250
		}),
		{
			xtype: 'fileuploadfield',
	                id: 'form-file',
	                emptyText: 'Select cv location...',
	                fieldLabel: 'Upload CV',
	                name: 'cv',
	                anchor:'95%'
        	}
            ],

	bbar: new Ext.StatusBar({
            id: 'form-statusbar',
            defaultText: 'Ready',
            plugins: new Ext.ux.ValidationStatus({form:'regJobSeeker'})
        }),

        buttons: [{
	    formBind : true,
            text: 'Register',
            handler: function()
            		{
            			regJobSeeker.getForm().submit({
            									clientValidation: true,
							                    url: 'regcv.php',
							                    success: function(form, action) {
																			    	document.location = 'jobseeker.php';   
																			    },
											    failure: function(form, action) {
																if (action.result.msg == 'Already Registered')
																{
																	Ext.Msg.alert("Failure", 'This email address is already registered with us as a jobseeker.');
																}		        
															}

							                });
            			
            		}
        },{
            text: 'Cancel',
            handler: function()
            		{
            			document.location = 'index.php';
            		}
        }]
    });

    regJobSeeker.render('right');
    regJobSeeker.form.isValid(); 
});

