var userWindow;
Ext.onReady( function() {
	Ext.QuickTips.init();
	var userField = new Ext.form.TextField( {
		id :'user',
		fieldLabel :'Email Address',
		name :'user',
		disabled :true
	});
	var checkHandler = function(button, event) {
		useridCheckForm.form.submit( {
			url :'success.txt',
			waitMsg :'Sending data...',
			failure : function(f, a) {
				Ext.MessageBox.alert('Error',
						'This email address has been used');
			},
			success : function(f, a) {

				registrationWindow.show();
				userField.setValue(Ext.get('userCheck').getValue());
				userWindow.hide();
			}
		});
	};
	var submitHandler = function(button, event) {

	};
	var useridCheckForm = new Ext.FormPanel( {
		labelWidth :100, // label settings here cascade unless overridden
		url :'success.txt',
		layout :'form',
		frame :true,

		width :320,
		defaults : {
			width :200
		},		
		defaultType :'textfield',
		xtype :'form',
		autoHeight :true,
		items : [ {
			id :'userCheck',
			fieldLabel :'Primary Email',
			name :'userCheck',
			vtype:'email',
			allowBlank :false
		} ],
		buttons : [ {
			text :'Check',
			handler :checkHandler
		} ]
	});

	userWindow = new Ext.Window( {
		title :'New Subscription',
		width :332,
		autoHeight :true,
		modal :true,
		border :false,
		closeAction:'hide',
		bodyStyle:'z-index:300001;',
		items :useridCheckForm
	});

	

	var registrationForm = new Ext.FormPanel( {
		labelWidth :80, // label settings here cascade unless overridden
		url :'success.txt',
		frame :true,
		width :590,
		xtype :'fieldset',
		autoHeight :true,
		
		items : [{
            layout: 'column',
            border: false,
            defaults: {
                columnWidth: '.5',
                border: false
            },
                       
            items:  [{
            	xtype:'fieldset',
            	bodyStyle: 'padding-right:0px;',
            	title: ' Personal Details',
            	autoHeight: true,
            	defaultType :'textfield',
            	defaults : {
        			width :150
        		},
                items:[ userField, {
        			fieldLabel :'First Name',
        			name :'firstname',
        			allowBlank :false

        		}, {
        			fieldLabel :'Last Name',
        			name :'firstname',
        			allowBlank :false

        		},{
                    xtype: 'radiogroup',
                    fieldLabel: 'Gender',
                    items: [
                        {boxLabel: 'Male',   name: 'gender', inputValue: 0,checked: true },
                        {boxLabel: 'Female', name: 'gender', inputValue: 1 }               
                    ]
                }, {
        			fieldLabel :'Country',
        			name :'country',
        			allowBlank :false

        		}, {
        			fieldLabel :'City',
        			name :'city',
        			allowBlank :false

        		}, {
        			fieldLabel :'State',
        			name :'state',
        			allowBlank :false
        		}]
                	
            },{
               xtype:'fieldset',
               bodyStyle: 'padding-right:0px;',
               title: ' Work Details',
               defaultType :'textfield',
               autoHeight: true,
               defaults : {
       			 width :150
       		   },
               items:[{
       			fieldLabel :'Company Name',
    			name :'company',
    			allowBlank :false
               }, {
    			fieldLabel :'Company Address',
    			name :'address',
    			xtype: 'textarea',
    			allowBlank :false
    		}, {
    			fieldLabel :'Postal Code',
    			name :'postal',
    			xtype: 'numberfield',
    			allowBlank :false
    		}, new Ext.form.ComboBox({
                store: jobList ,
                editable:false,
                name:'jobfunc',
                fieldLabel: 'Job Function',   
                displayField:'Job Function',
                allowBlank:false,
                typeAhead: true,
                triggerAction: 'all',
                emptyText:'Job Function...',        
                selectOnFocus:true
                   
            }), new Ext.form.ComboBox({
                store: positionList ,
                editable:false,
                name:'pos',
                fieldLabel: 'Position',   
                displayField:'Position',
                allowBlank:false,
                typeAhead: true,
                triggerAction: 'all',
                emptyText:'Position...',        
                selectOnFocus:true
                   
            }), {
    			fieldLabel :'Telephone (Office)',
    			name :'telephone',
    			xtype: 'numberfield',
    			allowBlank :false
    		}, {
    			fieldLabel :'Fax (Office)',
    			name :'fax',
    			xtype: 'numberfield',
    			allowBlank :false
    		}]
            	   
            }]
		},{
	            xtype:'fieldset',
	            checkboxToggle:true,
	            title: 'Change Subscription Selections',
	            autoHeight:true,
	            defaults: {width: 400},
	            defaultType: 'textfield',
	            collapsed: true,
	            items :[{ 
	            	xtype: 'checkboxgroup',
	  			  	fieldLabel: 'Subscriptions', itemCls: 'x-check-group-alt',
	  			  	columns: 2, 
	  			  	items: [ 
	  			  	    {boxLabel:'Bathroom&nbsp;+&nbsp;Kitchen&nbsp;Today', name: 'pub0', checked: true}, 
	  			  		{boxLabel:'Concrete&nbsp;Technology&nbsp;Today', name:'pub1', checked: true}, 
	  			  		{boxLabel:'Security&nbsp;Solutions&nbsp;Today', name: 'pub2', checked:true}, 
	  			  		{boxLabel: 'Landscape&nbsp;Today', name: 'pub3', checked: true}, 
	  			  		{boxLabel: 'Lighting&nbsp;Today', name: 'pub4', checked: true}, 
	  			  		{boxLabel: 'SEA&nbsp;Building&nbsp;Today', name: 'pub5', checked: true}, 
	  			  		{boxLabel: 'SEA&nbsp;Construction&nbsp;Today', name: 'pub6', checked: true}
	  			  	] 
	 			}]
		}],
		
			
	

		buttons : [ {
			text :'Submit',
			handler :submitHandler
		} ]
	});

	var registrationWindow = new Ext.Window( {
		title :'New Subscription',
		width :600,
		autoHeight :true,
		modal :true,
		border :false,
		resizable :false,
		items :registrationForm
	});

});
