var gnc = function(){
	var win_terms;
	var win_help;
	var rowId=-1;
	var Class;
	var classDS;
	var countryDS;
	var areaDS;
	var schoolDS;
	var classForm;
	var contactForm;
	return {
		init : function(){
			
			Ext.QuickTips.init();
			Ext.form.Field.prototype.msgTarget = 'side';
			
			gnc.windows();
			
		},
		classesGrid : function() {
		
			classGrid=new Ext.grid.GridPanel({
				cls:'gridclasses',
				xtype:'grid',
				id:'grid_classes',
				store: classDS,
				columns: [
					{header: "Class name", width: 220, sortable: false, dataIndex: 'class_name',fixed:true,menuDisabled:true}
				],
				stripeRows: true,
				height:131,
				width:242,
				
				sm: new Ext.ux.SingleRowSelectionModel({
					singleSelect: true,
					listeners: {
						rowselect: function(sm, row, rec) {
							Ext.getCmp('btn_delete_class').setDisabled(false);
							Ext.getCmp("frmClasses").getForm().loadRecord(rec);
							Ext.getCmp('btn_add_class').setText('Update class');
							rowId=row;
						},
						selectionchange : function(sm, newIndex, newRecord, oldIndex, oldRecord) {
							Ext.getCmp('btn_delete_class').setDisabled(false);
							Ext.getCmp("frmClasses").getForm().loadRecord(newRecord);
							Ext.getCmp('btn_add_class').setText('Update class');
							rowId=newIndex;
						},
						rowdeselect : function(sm, row, rec) {
							Ext.getCmp('btn_delete_class').setDisabled(true);
							Ext.getCmp("frmClasses").getForm().reset();
							Ext.getCmp('btn_add_class').setText('Save class');
							rowId=-1;
						}
					}
				}),
				bbar:new Ext.Toolbar({
					items:['->',
						{
							text:'Add class',
							tooltip:'Add a new class',
							iconCls:'icon_new_class',
							handler:function() {
								Ext.getCmp("frmClasses").getForm().reset();
								Ext.getCmp('btn_add_class').setText('Add class');	
							}
						},{
							text:'Delete class',
							tooltip:'Delete selected class',
							id:'btn_delete_class',
							iconCls:'icon_delete_class',
							disabled:true,
							handler:function() {
								var classV = Ext.getCmp('grid_classes').getSelectionModel().getSelected();
								classDS.remove(classV);
								if (classDS.getCount()==0) {
									Ext.getCmp('btn_delete_class').setDisabled(true);
									Ext.getCmp("frmClasses").getForm().reset();
									Ext.getCmp('btn_add_class').setText('Add class');	
								}
							}
						}
					]
				})
			});
		},
		addClass : function() {
			
			var formPanelV = Ext.getCmp('frmClasses');
			if (formPanelV.getForm().isValid()) {
				
				var dupClassName=false;
				var dupClassPass=false;
				for (x=0;x<classDS.getCount();x++) {
					if (classDS.getAt(x).get('class_name')==Ext.getCmp('class_name').getValue()) {
						if (rowId==-1 || rowId!=-1 && rowId !=x) {
							dupClassName=true;	
							Ext.Msg.alert('Action', 'This class name is already taken. Try another.');
							break;
						}
					}
					if (classDS.getAt(x).get('class_password')==Ext.getCmp('class_password').getValue()) {
						if (rowId==-1 || rowId!=-1 && rowId !=x) {
							dupClassPass=true;		
							Ext.Msg.alert('Action', 'This class password is already taken. Try another.');
							break;
						}
					}
				}
				if (!dupClassName&&!dupClassPass) {
					var c = new Class({
						class_name: Ext.getCmp('class_name').getValue(),
						class_password: Ext.getCmp('class_password').getValue()
					});
					if (rowId!=-1) {
						var classv = Ext.getCmp('grid_classes').getSelectionModel().getSelected();
						index=rowId;
						classDS.remove(classv);	
					} else {
						index=0;	
					}
					classDS.insert(index, c);
					classForm.getForm().reset();
				}
			} else {
				Ext.Msg.alert('Action', 'Please fill in the required fields');
			}
		},
		completeRegistration : function() {
			var formPanel = Ext.getCmp('frmContactForm');
			if (formPanel.getForm().isValid()) {
				if (classDS.getCount()>0) {
					win_terms.show(this);
				} else {
					Ext.MessageBox.alert('Action', 'At least one class is required to enter Giving Nation Challenge.');	
				}
			} else {
				Ext.Msg.alert('Action', 'Please fill in the required fields and then click \'Setup my classes to continue\'.');
				Ext.getCmp('step2of3').expand(false);
				contactForm.doLayout();
			}	
		},
		windows : function() {
			//create terms window but hide
			if(!win_terms){
				win_terms = new Ext.Window({
					autoCreate	: true,
					layout		: 'fit',
					title		: 'Terms & Conditions',
					iconCls		: 'icon_terms',
					modal		: true,
					width       : 500,
					height      : 360,
					resizable	: false,
					closeAction :'hide',
					items		: [
						new Ext.form.FormPanel({
							bodyStyle:'padding:10px',
							id:'form_terms',
							border:false,
							items:[
								{	
									autoLoad:{url:'terms.cfm'},
									border:false,
									height:277,
									autoScroll:true
								}
							]
						})
					],
					buttons: [{
						text     : 'I agree to the terms and conditions ',
						id		 : 'btn_terms_accept',
						handler: function() {
							var maskingAjax = new Ext.data.Connection({
								listeners: {
									'beforerequest': {
										fn: function(con,opt) {
											Ext.get('p_register').mask('Registering school...');
										},
										scope: this
									}, 
									'requestcomplete': {
										fn: function(con,res,opt) {
											Ext.get('p_register').unmask();
										},
										scope: this
									},
									'requestexception': {
										fn: function(con,res,opt) {
											Ext.get('p_register').unmask();
										},
										scope: this
									}
								}
							});
							
		
							function CopyStoreToForm(store){
								var json = '';
								store.each(function(store){
									json += Ext.util.JSON.encode(store.data) + ',';
								});
								json = json.substring(0, json.length - 1);
								Ext.getCmp('storeClasses').setValue(json);
							};
							
							CopyStoreToForm(classDS);
		
							maskingAjax.request({
								url: 'rpc/json/?method=register.complete',
								success: function(response,request) {
									json = Ext.util.JSON.decode(response.responseText);
									result=Ext.util.JSON.decode(json.data);
									Ext.getDom('l_username').innerHTML=result.username;
									Ext.getDom('l_password').innerHTML=result.password;
									Ext.getDom('l_email').innerHTML=result.email;
									Ext.getDom('l_details').href='/challenge/file.cfm?docid='+result.pdf+'&doctypeid='+1;
									Ext.getDom('l_details2').href='/challenge/file.cfm?docid='+result.pdf+'&doctypeid='+1;
									Ext.getDom('l_bursar').href='/challenge/file.cfm?docid='+result.pdf+'&doctypeid='+2;
									
									Ext.getCmp('review').setDisabled(false);
									Ext.getCmp('step1of3').setDisabled(true);	
									Ext.getCmp('step2of3').setDisabled(true);	
									Ext.getCmp('step3of3').setDisabled(true);	
									Ext.getCmp('review').expand(false);	
									
									Ext.getDom('fpdisplay').innerHTML ='';
									
									Ext.Ajax.request({
										params:{JsonType:'custom'},
										url: 'rpc/json/?method=register.getProfileBox&'+new Date().getTime(),
										scope:this,
										callback: function(opts,suss,resp){
											pc = document.getElementById('pcontainer');
											var olddiv = document.getElementById('fpdisplay');
											pc.removeChild(olddiv);
											var olddiv = document.getElementById('login');
											pc.removeChild(olddiv);
											pc.innerHTML = resp.responseText;
										}
									});
								},
								//failure: submitFailed,
								params:{jsonType:'form',
										schoolid:Ext.getCmp('schoolid').getValue(),
										fullname:Ext.getCmp('fullname').getValue(),
										position:Ext.getCmp('position').getValue(),
										email:Ext.getCmp('email').getValue(),
										tel:Ext.getCmp('tel').getValue(),
										feedbackid:Ext.getCmp('feedbackid').getValue(),
										password:Ext.getCmp('teacher_password').getValue(),
										classes:Ext.getCmp('storeClasses').getValue()}
							});  
							win_terms.hide();
						}
					},{
						text     : 'Cancel',
						handler  : function(){
							win_terms.hide();
						}
					}]
				});
			}
			
			//create help window but hide
			if(!win_help){
				win_help = new Ext.Window({
					autoCreate	: true,
					layout		: 'fit',
					title		: 'Help',
					iconCls		: 'icon_help',
					width       : 370,
					height      : 284,
					modal		: true,
					resizable	: false,
					closeAction :'hide',
					items		: [
						new Ext.form.FormPanel({
							url:'rpc/json/?method=register.help',
							baseParams:{jsonType:'form',helpType:'register'},
							bodyStyle:'padding:10px;',
							id:'form_help',
							cls:'bodywhite',
							labelWidth:60,
							border:false,
							items:[
								{
									layout:'fit',
									border:false,
									bodyStyle:'padding-bottom:10px',
									html:'For help registering or editing your details for the Giving Nation Challenge, please enter your details below with the problems you are having and we\'ll get back to you as soon as possible.'
								},
								{	
									xtype:'textfield',
									fieldLabel:'Name',
									name:'h_fullname',
									id:'h_fullname',
									blankText:'Enter your fullname',
									emptyText:'Enter your fullname...',
									width:180,
									allowBlank:false,
									tabIndex:90
								},{	
									xtype:'textfield',
									fieldLabel:'Email',
									name:'h_email',
									id:'h_email',
									vtype:'email',
									blankText:'Enter a valid email address',
									emptyText:'Enter a valid email address...',
									width:180,
									allowBlank:false,
									tabIndex:91
								},{	
									xtype:'textarea',
									fieldLabel:'Message',
									name:'h_message',
									id:'h_message',
									blankText:'Enter your message',
									emptyText:'Enter your message...',
									width:250,
									height:100,
									allowBlank:false,
									tabIndex:92
								}
								
							]
						})
					],
					buttons: [{
						text     : 'Send',
						id		 : 'btn_help_send',
						tabIndex : 93,
						handler: function() {
							var helpFormValid = Ext.getCmp('form_help');
							if (helpFormValid.getForm().isValid()) {
								helpFormValid.getForm().submit();								
							} else {
								Ext.Msg.alert('Action', 'Please fill in the required fields');
							}	
						}
					},{
						text     : 'Close',
						id:	'btn_help_close',
						tabIndex : 94,
						handler  : function(){
							win_help.hide();
							var helpFormValid = Ext.getCmp('form_help');
							helpFormValid.getForm().reset();
						}
					}]
				});
				
				form_help_success=function(form,action) {
					// Only enable the submit button if the load worked
					if(action.type == 'submit'){
						win_help.hide();
						var helpFormValid = Ext.getCmp('form_help');
						helpFormValid.getForm().reset();
						Ext.Msg.alert('Action', 'Your message has been sent.');
					} 
				}
				Ext.getCmp('form_help').on("actioncomplete", form_help_success);
				
				
				
			}
			gnc.loadStores();
		},
		loadStores : function(){
			
			countryDS = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : 'rpc/json/?method=register.viewCountries'}),
				reader : new Ext.data.JsonReader({
					root: 'data',
					fields: [
						{name: 'countryid'},
						{name: 'country'}
					]
					}),
				remoteSort : false,
				autoLoad:true
			});	
			
			areaDS = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : 'rpc/json/?method=register.viewAreas'}),
				reader : new Ext.data.JsonReader({
					root: 'data',
					fields: [
						{name: 'areaid'},
						{name: 'area'}
					]
					}),
				remoteSort : false
			});	
			
			schoolDS = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : 'rpc/json/?method=register.viewSchools'}),
				reader : new Ext.data.JsonReader({
					root: 'data',
					fields: [
						{name: 'schoolid'},
						{name: 'school'}
					]
					}),
				remoteSort : false
			});	
			
			// this could be inline, but we want to define the Plant record
			// type so we can add records dynamically
			Class = Ext.data.Record.create([
				   // the "name" below matches the tag name to read, except "availDate"
				   // which is mapped to the tag "availability"
				   {name: 'class_name', type: 'string'},
				   {name: 'class_password', type: 'string'}
			]);	
			
			var myData = [
			];
			
			 // create the data store
			classDS = new Ext.data.SimpleStore({
				fields: [
				   {name: 'class_name'},
				   {name: 'class_password'}
				]
			});
			classDS.loadData(myData);
			
			gnc.main();
		
		},
		main : function() {	
			var combo_Countries=new Ext.form.ComboBox({
				listClass:'x-combo-list-small',
				fieldLabel: 'Country',
				xtype: 'combo',
				id:'countryid',
				name:'countryid',
				width:170,
				mode:'local',
				editable:false,
				triggerAction: 'all',
				store : countryDS,
				hiddenName: 'country',
				valueField: 'countryid',
				displayField: 'country',
				allowBlank:false,
				tabIndex:30,
				emptyText:'Select your country...',
				blankText:'Select your country...'
			});
			
			combo_Countries.on('select',function(){
				areaDS.load({params:{countryId:combo_Countries.getValue()}});	
				areaDS.on('load',function(){
					if(Ext.getDom('areaid')==null) {
						findSchool.add(combo_Areas);
						findSchool.doLayout();				
					} else {
						combo_Areas.reset();	
						combo_Schools.reset();	
					}
					if (areaDS.getTotalCount()==1) {
						rowRecord = areaDS.getAt(0);
						id = rowRecord.data['areaid'];
						combo_Areas.setValue(id);
						combo_Areas.fireEvent('select');
					}
					if (Ext.getCmp('areaid').getValue().length==0) {
						schoolDS.removeAll();
					}
				});
			});
			
			var combo_Areas=new Ext.form.ComboBox({
				listClass:'x-combo-list-small',
				fieldLabel: 'LA',
				xtype: 'combo',
				id:'areaid',
				name:'areaid',
				width:170,
				listWidth:250,
				maxHeight:200,
				mode:'local',
				editable:false,
				listClass :'shaun',
				triggerAction: 'all',
				store : areaDS,
				valueField: 'areaid',
				displayField: 'area',
				allowBlank:false,
				tabIndex:31,
				emptyText:'Select your area...',
				blankText:'Select your area'
			});
			
			combo_Areas.on('select',function(){
				schoolDS.load({params:{areaId:combo_Areas.getValue()}});	
				if(Ext.getDom('schoolid')==null) {
					findSchool.add(combo_Schools);
					findSchool.doLayout();	
				}else {
					combo_Schools.reset();	
				}
			});
			
			var combo_Schools=new Ext.form.ComboBox({
				listClass:'x-combo-list-small',
				fieldLabel: 'School',
				xtype: 'combo',
				id:'schoolid',
				name:'schoolid',
				width:170,
				listWidth:310,
				maxHeight:171,
				mode:'local',
				editable:false,
				triggerAction: 'all',
				store : schoolDS,
				hiddenName: 'school',
				valueField: 'schoolid',
				displayField: 'school',
				allowBlank:false,
				tabIndex:32,
				emptyText:'Select your school...',
				blankText:'Select your school...'
			});
			
			combo_Schools.on('select',function(){
				if(Ext.getDom('helptext_2')==null) {
					findSchool.add({layout:'fit',id:'helptext_2',cls:'helptext2',width:225,border:false,html:'To unlock your school, please combine your LA (i.e.123) and Establishment (i.e. 4567) school numbers below, (i.e. 1234567):'});
					findSchool.add(text_dcsf);
					findSchool.add({xtype:'button',id:'btn_finddetails',text:'Find my details',style:'margin-left:60px',tabIndex:34,handler:findDetails});
					findSchool.doLayout();
				}
			});
			
			findDetails=function() {
				var formPanel = Ext.getCmp('frmFindSchool');
				if (formPanel.getForm().isValid()) {
					var maskingAjax = new Ext.data.Connection({
						listeners: {
							'beforerequest': {
								fn: function(con,opt) {
									Ext.get('p_register').mask('Searching...');
								},
								scope: this
							}, 
							'requestcomplete': {
								fn: function(con,res,opt) {
									Ext.get('p_register').unmask();
								},
								scope: this
							},
							'requestexception': {
								fn: function(con,res,opt) {
									Ext.get('p_register').unmask();
								},
								scope: this
							}
						}
					});
					maskingAjax.request({
						url: 'rpc/json/?method=register.findSchool',
						success: function(response,request) {
							//alert(r.responseText);
							json = Ext.util.JSON.decode(response.responseText);
							result=Ext.util.JSON.decode(json.data);
							if (result.statusid!=1) {
								Ext.MessageBox.alert('Action', result.statusmessage);	
							} else {
								searchForm_p1(true);
								Ext.getCmp('statusmessage').show();
								Ext.getCmp('statusmessage').body.update('Your school has been found:<br /><br />'+result.address);
							}
						},
						//failure: submitFailed,
						params:{jsonType:'form',schoolid:Ext.getCmp('schoolid').getValue(),dcsf:Ext.getCmp('dcsf').getValue()}
					});  
				}
			}
			
			searchForm_p1 = function(b) {
				// disable form
				Ext.getCmp('countryid').setDisabled(b);
				Ext.getCmp('areaid').setDisabled(b);
				Ext.getCmp('schoolid').setDisabled(b);
				Ext.getCmp('dcsf').setDisabled(b);
				Ext.getCmp('btn_finddetails').setDisabled(b);	
				Ext.getCmp('btn_yes').show();
				Ext.getCmp('btn_no').show();
				if (!b) {
					Ext.getCmp('btn_yes').hide();
					Ext.getCmp('btn_no').hide();
					Ext.getCmp('statusmessage').body.update('');
					Ext.getCmp('statusmessage').hide();
					Ext.getCmp('step1of3').expand(true);
					Ext.getCmp('step2of3').setDisabled(true);
					Ext.getCmp('step3of3').setDisabled(true);
					classForm.getForm().reset();
					classDS.removeAll();
					passForm.getForm().reset();
					contactForm.getForm().reset();
				}
			}	
							 
			var findSchool = new Ext.FormPanel({
				url:'rpc/json/?method=usergroup.save&' + new Date().getTime(),
				frame:false,
				labelWidth:55,
				border:false,
				bodyStyle:'padding:10px 10px 0',
				width: 498,
				id:'frmFindSchool',
				items: [{
						columnWidth:.5,
						layout: 'form',
						border:false,
						items: [combo_Countries]
				}]
			});	 
			
			var text_dcsf = new Ext.form.TextField({
				fieldLabel:'DCSF',
				width:170,
				id:'dcsf',
				name:'dcsf',
				allowBlank:false,
				tabIndex:33
			});
			
			step2of3=function() {
				Ext.getCmp('step2of3').setDisabled(false);
				Ext.getCmp('step2of3').expand(false);
			}
			
			feedbackDS = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : 'rpc/json/?method=register.viewFeedbackTypes'}),
				reader : new Ext.data.JsonReader({
					root: 'data',
					fields: [
						{name: 'feedbacktypeid'},
						{name: 'feedback'}
					]
					}),
				remoteSort : false,
				autoLoad:true
			});	
			
			comboFeedback = new Ext.form.ComboBox({
				listClass:'x-combo-list-small',
				xtype:'combo',
				hideLabel:true,
				id:'feedbackid',
				name:'feedbackid',
				collapsed:false,
				lazyInit:false,
				width:231,
				maxHeight:114,
				mode:'local',
				editable:false,
				triggerAction: 'all',
				store : feedbackDS,
				hiddenName: 'feedback',
				valueField: 'feedbacktypeid',
				displayField: 'feedback',
				allowBlank:false,
				emptyText:'Select an option...',
				blankText:'Select an option...',
				tabIndex:41
			});
			
			
			
			contactForm = new Ext.FormPanel({
				url:'rpc/json/?method=usergroup.save&' + new Date().getTime(),
				frame:false,
				labelWidth:60,
				border:false,
				bodyStyle:'padding:10px 10px 0',
				width: '100%',
				id:'frmContactForm',
				items: [
						{
							xtype:'textfield',
							fieldLabel:'Full name',
							id:'fullname',
							name:'fullname',
							width:165,
							blankText:'Enter your full name',
							emptyText:'Enter your full name...',
							allowBlank:false,
							tabIndex:37
						},
						{
							xtype:'textfield',
							fieldLabel:'Position',
							id:'position',
							name:'position',
							width:165,
							blankText:'Enter your position',
							emptyText:'Enter your position...',
							allowBlank:false,
							tabIndex:38
						},
						{
							xtype:'textfield',
							fieldLabel:'Email',
							id:'email',
							name:'email',
							width:165,
							blankText:'Enter a valid email address',
							emptyText:'Enter a valid email address...',
							vtype:'email',
							allowBlank:false,
							tabIndex:39
						},
						{
							xtype:'textfield',
							fieldLabel:'Tel no.',
							id:'tel',
							name:'tel',
							width:165,
							blankText:'Enter your telephone no.',
							emptyText:'Enter your telephone no...',
							allowBlank:false,
							tabIndex:40
						},
						{layout:'fit',cls:'helptext4',border:false,html:'<b>How did you find out about us?:</b>'},
						comboFeedback
				]
			});	 
			
			gnc.classesGrid();
			
			var passForm = new Ext.FormPanel({
				frame:false,
				labelWidth:60,
				border:false,
				width: '100%',
				id:'frmPass',
				cls:'passboxbottom',
				items: [
				{
					xtype:'textfield',
					fieldLabel:'Password',
					id:'teacher_password',
					name:'teacher_password',
					width:137,
					blankText:'Enter a password',
					emptyText:'Enter a password...',
					minLengthText:'Enter a password between 4 and 16 characters long',
					maxLengthText:'Enter a password between 4 and 16 characters long',
					minLength:4,
					maxLength:16,
					tabIndex:42,
					vtype:'alphanum'
				}
				]
			});	
			
			setupClasses = function() {
				var formPanel = Ext.getCmp('frmContactForm');
				var passFormValid = Ext.getCmp('frmPass');
				if (formPanel.getForm().isValid() && passFormValid.getForm().isValid()) {
					Ext.getCmp('step3of3').setDisabled(false);
					Ext.getCmp('step3of3').expand(false);
				} else {
					Ext.Msg.alert('Action', 'Please fill in the required fields');
				}	
			}
			
			classForm = new Ext.FormPanel({
				frame:false,
				labelWidth:90,
				border:false,
				width: '100%',
				id:'frmClasses',
				bodyStyle:'margin:10px;margin-bottom:0',
				buttonAlign:'left',
				items: [
				{	
					xtype:'hidden',
					name: 'storeClasses',
					id:'storeClasses'
				},
				{
					xtype:'textfield',
					fieldLabel:'Class name',
					id:'class_name',
					name:'class_name',
					width:126,
					allowBlank:false,
					blankText:'Enter a class name',
					emptyText:'Enter a class name...',
					minLengthText:'Enter a class name between 2 and 35 characters long',
					maxLengthText:'Enter a class name between 2 and 35 characters long',
					minLength:2,
					maxLength:35,
					tabIndex:43
				},{
					xtype:'textfield',
					fieldLabel:'Class password',
					id:'class_password',
					name:'class_password',
					width:126,
					allowBlank:false,
					vtype:'alphanum',
					blankText:'Enter a class password',
					emptyText:'Enter a password...',
					minLengthText:'Enter a class password between 4 and 16 characters long',
					maxLengthText:'Enter a class name between 4 and 16 characters long',
					minLength:4,
					maxLength:16,
					tabIndex:44
				}
				],
				buttons:[
					{
						text:'Save class',
						style:'margin-left:97px',
						id:'btn_add_class',
						handler: gnc.addClass,
						tabIndex:45
					}
				]
			});	 	
				
			helpMe = function() {
				win_help.show();
			}
							 
			var accordion = new Ext.Panel({
				border:false,
				width:525,
				height:413,
				id:'p_register',
				layout:'accordion', 
				defaults: {
				},
				layoutConfig: {
					// layout-specific configs go here
					titleCollapse: true,
					animate: false
				},
				items: [{
					title: 'Step 1 of 3 : Find your school',
					id:'step1of3',
					iconCls:'icon_findschool',
					cls:'custombg',
					bodyStyle:'background-color:#FF0000',
					tools:[{
							id:'help',
							handler:helpMe,
							tooltip:'Click here for help'
						   }				   
					],
					items: [{		  
						border:false,
						layout:'column',
						items: [{
							columnWidth: .5,
							border:false,
							items:[
								   {layout:'fit',cls:'helptext',border:false,html:'Locate your school using the drop down menus below:'}
								   ,findSchool]
						},{
							columnWidth: .5,
							border:false,
							items:[
								{layout:'fit',cls:'helptext3',hidden:true,id:'statusmessage',border:false,html:''}
							],
							buttons:[{text:'YES this is my school',id:'btn_yes',hidden:true,handler:step2of3,tabIndex:35},{text:'NO, I need to try again',id:'btn_no',tabIndex:36,hidden:true,handler:function(){searchForm_p1(false);}}
									 
							]
						}]}
					]
				},{
					title: 'Step 2 of 3 : Add contact details',
					id:'step2of3',
					iconCls:'icon_contactdetails',
					cls:'custombg',
					disabled:true,
					tools:[{
							id:'help',
							handler:helpMe,
							tooltip:'Click here for help'
						   }				   
					],
					listeners:{
						render:function(o){
							o.doLayout();
							Ext.getDom('container_register').style.visibility='';
						}
					},
					items: [{		  
						border:false,
						layout:'column',
						items: [{
							columnWidth: .5,
							border:false,
							items:[
								   {layout:'fit',cls:'helptext',border:false,html:'Enter your contact information below:'},
								   contactForm
								   ]
						},{
							columnWidth: .5,
							border:false,
							items:[
								{
									layout:'fit',
									id:'statusmessage2',
									cls:'passboxtop',
									border:false,
									html:'<b>Change default password (Optional)</b><br /><br />You can update the default password by updating the password field below.'
								},
								passForm,
								{
									layout:'fit',
									id:'statusmessage3',
									cls:'helptext6',
									border:false,
									html:'<b>Finished entering your details?</b><br /><br />Click the button below to setup your classes.'
								}
							],
							buttons:[{text:'Setup my classes',id:'btn_nextstep',handler:setupClasses,tabIndex:42}]
						}]}
					]
				},{
					title: 'Step 3 of 3 : Setup your classes',
					id:'step3of3',
					iconCls:'icon_classes',
					cls:'custombg',
					tools:[{
							id:'help',
							handler:helpMe,
							tooltip:'Click here for help'
						   }				   
					],
					disabled:true,
					items: [{		  
						border:false,
						layout:'column',
						items: [{
							columnWidth: .5,
							border:false,
							items:[
								   {layout:'fit',cls:'helptext',border:false,html:'The box on the right is your class list.<br /><br /><b>Add a class:</b> Enter a class name and password in the fields below then click \'Save class\'.<br /><br /><b>Edit a class:</b> Select the class and edit the information in the fields below. <br /><br /><b>Deleting a class:</b> Select the class and click the \'delete\' button.<br /><br /><b>Please note:</b> Giving Nation will provide only <b>ONE</b> grant per school, so ensure you apply for the maximum number of classes needed to run the programme over a year group, even if you wish to trial it with a few classes first.'},
								   classForm
								   ]
						},{
							columnWidth: .5,
							border:false,
							items : [
								{layout:'fit',cls:'helptext',border:false,html:'<b>Your Classes:</b><br /><br /><b>Please note:</b> You can add up to <b>50</b> classes but the maximum bursary is <b>&pound;450</b>.'},
								classGrid,
								{layout:'fit',cls:'helptext5',border:false,html:'Once you have set up your classes click the \'I\'m finished\' button below to complete registration.'}
							],
							buttons:[{text:'I\'m finished.',id:'btn_nextstep',handler:gnc.completeRegistration}]
						}]}
					]
				},{
					title: 'Review Registration',
					id:'review',
					iconCls:'icon_review',
					cls:'custombg_review',
					disabled:true,
					hideCollapseTool:true,
					html:'<span class=\'orange_heading\'>Congratulations!</span> <span class=\'orange_small\'>you are now registered for Giving Nation Challenge!</span><br /><br />You have been automatically logged in to the Giving Nation Challenge, but next time you visit the website you will need to login with the details below:<br /><br ><b>Username:</b> <span id=\'l_username\'></span><br /><b>Password:</b> <span id=\'l_password\'></span><br /><br />A copy of your login/class details have been sent to <b><span id=\'l_email\'></span></b>, alternatively you can download all your login details from <a href=\'\' id=\'l_details\'>here</a>.<br /><br /><b>Next steps</b><br /><br /><ol><li><b>1.</b> <a href=\'\' id=\'l_bursar\'>Download your bursar form</a>, sign it and post it back to us.</li><li><b>2.</b> <a href=\'\' id=\'l_details2\'>Download your login/class details</a>, this document contains information on how to log in.</li><li><b>3.</b> <a href=\'/challenge/diaries/?contentid=280\'>Visit your Challenge Overview</a>, to get started!</li></ol>'
				}],
				renderTo:'container_register'
			});
		}
	}
}();
Ext.onReady(gnc.init);