/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

    Ext.QuickTips.init();
    
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var bd = Ext.getBody();	
    
    var regEmployer = new Ext.FormPanel({
        labelAlign: 'side',        
        buttonAlign: 'right',
        id: 'regEmployer',
        bodyBorder:false,
        border:false,
        frame:false,
        hideBorders:true,
        bodyStyle: '',
        monitorValid:true,
        width: 400,
        labelWidth: 125,
        items: [{
            layout:'column',
            items:[{
                columnWidth:1,
                layout: 'form',
                items: [
                new Ext.form.ComboBox({
								        store: ['Mr', 'Mrs.', 'Miss', 'Ms.', 'Dr.', 'Prof.'],
								        fieldLabel: 'Title',
								        typeAhead: true,
								        forceSelection: true,
								        triggerAction: 'all',
								        emptyText:'Select a title...',
								        selectOnFocus:true,
								        name:'title',
								        width:120
								    }),
				{
                    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: 'Company Name',
                    allowBlank: false,
		    blankText: 'Company name cannot be blank',
                    name: 'company',
                    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: 'Suburb',
                    name: 'suburb',
                    anchor:'95%'
                },
                {
                    xtype:'textfield',
                    fieldLabel: 'Postcode',
                    name: 'postcode',
                    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: 'Department',
                    name: 'department',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Position',
                    name: 'position',
                    anchor:'95%'
                },{
                    xtype:'textfield',
                    fieldLabel: 'Phone Number',
                    allowBlank: false,
		    blankText: 'Phone number cannot be blank',
                    name: 'phone',
                    vtype:'PhoneNum',
                    anchor:'95%'
                }, {
                    xtype:'textfield',
                    fieldLabel: 'Email',
                    allowBlank: false,
		    blankText: 'Email cannot be blank',
                    name: 'email',
                    vtype:'email',
                    anchor:'95%'
                },{
                	xtype:'textfield',
                	allowBlank: false,
			blankText: 'A password is required',
                    fieldLabel: 'Password',
			        name: 'password',
                    inputType: 'password',
                    anchor:'95%',
			        id: 'pass'
			      },{
			      	xtype:'textfield',
			      	allowBlank: false,
			        blankText: 'Please confirm your password',
			        fieldLabel: 'Confirm Password',
			        name: 'pass-cfrm',
			        inputType: 'password',
			        vtype: 'password',
			        anchor:'95%',
			        initialPassField: 'pass' // id of the initial password field
			      }]
            }]
        }],

	bbar: new Ext.StatusBar({
            id: 'form-statusbar',
            defaultText: 'Ready',
            plugins: new Ext.ux.ValidationStatus({form:'regEmployer'})
        }),

        buttons: [{
	    formBind : true,
            text: 'Register',
            handler: function()
            		{
            			regEmployer.getForm().submit({
            									clientValidation: true,
							                    url: 'reg_employer.php',
							                    success: function(form, action) {
																			    	document.location = 'employer.php';   
																			    },
											    failure: function(form, action) {
																if (action.result.msg == 'Already Registered')
																{
																	Ext.Msg.alert("Failure", 'This email address is already registered with us as an employer.');
																}
																}

							                });
            			
            		}
        },{
            text: 'Cancel',
            handler: function()
            		{
            			document.location = 'index.php';
            		}
        }]
    });
    
    regEmployer.render('right');
    regEmployer.form.isValid();
});
