Ext.onReady(function(){

    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';
    Ext.namespace('Ext.ArClassYears');
    Ext.ArClassYears.page = [
        ['1980', '1980 MAHARLIKA'],['1981', '1981 MATATAG'],['1982', '1982 MASIGASIG'],['1983', '1983 MAGITING'],['1984', '1984 MAKATARUNGAN'],['1985', '1985 MAKATAO'],['1986', '1986 TAGAPAGTANGGOL'],['1987', '1987 TAGAPAGLINGKOD'],['1988', '1988 TAGAPAGTAGUYOD'],['1989', '1989 TAGAPAGBUKLOD'],['1990', '1990 TAGAPAMAYAPA'],['1991', '1991 TAGAPAGKALINGA'],['1992', '1992 TAGAPAGPATUPAD'],['1993', '1993 TAGAPAGLUNSAD'],['1994', '1994 SANDIGAN'],['1995', '1995 PATNUBAY'],['1996', '1996 KAAGAPAY'],['1997', '1997 KAPANALIG '],['1998', '1998 KABALIKAT '],['1999', '1999 TANGLAW-LAHI '],['2000', '2000 MAGILAS '],['2001', '2001 BUKLOD-DIWA '],['2002', '2002 SINAG-LAYA '],['2003', '2003 SAMBIGKIS '],['2004', '2004 TAGAPAGSANGGALANG '],['2005', '2005 MARANGAL '],['2006', '2006 BAGSAY-LAHI '],['2007', '2007 SANSINIRANGAN '],['2008', '2008 OMAN SILANG '],['2009', '2009 KAISANG BISIG '],['2010', '2010 MABIKAS '],['2011', '2011 MASALIGAN ']	];
	var msgAction = Ext.get('actionOperation');
	 var classGrad_combo = new Ext.form.ComboBox({
		store: Ext.ArClassYears.page,
		displayField:'state',
		id: 'value_blgClassGradYear',
		name: 'value_blgClassGradYear',
		fieldLabel:'Class Name', 
		mode: 'local',
		triggerAction: 'all',
		allowBlank:false, 
		labelStyle: 'font-size: 16px; ',
		emptyText:'Select Your Class',
		editable: false,
		selectOnFocus:true,
		onSelect: function(record){ 
			var elti =  record['json'][1];
			var demo =  record['json'][0];
			var sara = Ext.urlEncode(record);
			Ext.getCmp('value_blgClassGradYear').setValue(    demo   );
			this.setValue(demo);
			this.collapse();
		}, 
		onCollapse: function() {
			this.collapse();
		}
	 });
	 var tabs = new Ext.FormPanel({
        labelWidth: 120,
        border:false,
        width: 530,
		  monitorValid:true,
		  bodyStyle: 'background:none;',
		  frame: false,
		  items: {
            xtype:'fieldset',
            layout:'form',
            autoHeight:true,
            border: false,
            defaults: {width: 230, height: 35},
            
				defaults:{ bodyStyle:'background: #ffffff url("http://pnpaaai.org/blog/assets/images/ads.png") no-repeat scroll right center transparent;  min-height: 230px; padding:10px; font-size: 60px !important; font-weight: bold '}, 
            items:[{
                title:'Section 1: Member Profile',
                layout:'form',
                defaults: {width: 230, height: 25},
                defaultType: 'textfield',
                items: [{
                	fieldLabel: 'First Name',
                	labelStyle: 'font-size: 16px; ',
                	emptyText:'Required to put your First Name',
						name: 'ab1',
                  allowBlank:false
                },{
                	fieldLabel: 'Middle Name',
                  name: 'ab2',
                  emptyText:'Required to put your Middle Name',
                  labelStyle: 'font-size: 16px; ',
                  allowBlank:false
                },{
                	fieldLabel: 'Last Name',
                  name: 'ab3',
                  emptyText:'Required to put your Last Name',
                  labelStyle: 'font-size: 16px; ',
                  allowBlank:false
                }, 
                classGrad_combo
            	 ],
				},{
            	autoHeight:true,
            	title:'Section 2: Contact Details',
            	layout:'form',
            	border: false,
            	defaults: {width: 230, height: 25},
            	defaultType: 'textfield',
					items: [{
               	fieldLabel: 'Email',
                  labelStyle: 'font-size: 16px; ',
                  emptyText:'Provide your complete Email Address',
                  allowBlank:false,
                  vtype: 'email',
                  name: 'ab4'
                },{
                	fieldLabel: 'Mobile No.',
                  name: 'ab5',
                  labelStyle: 'font-size: 16px; '
                },{
                	fieldLabel: 'Cadet Serial No.',
                  allowBlank:false,
                  emptyText:'Used to recover lost passwords',
                  labelStyle: 'font-size: 16px; ',
                  name: 'ab6'
                }]
            }]
        },
		  buttons: [
						{
							text: 'Reset Form',
							iconCls: 'blist',
							handler: function() {
								tabs.getForm().reset();
							}
						},{
							text: 'Validate and Submit',
							iconCls: 'bsaform',
							width: 200,
							formBind: true,
			            handler: function() {
			        			tabs.getForm().submit( {
										method:'POST', 
										waitTitle:'Awaiting Server Response', 
										waitMsg:'Validating data, please wait...',
										url: "./v2_apply/send_apcontent",
										success:function(form, action) {
											
										if (action.result.haru == 'fail') {
											Ext.Msg.show({
												title: 'Server Response',
											   msg: " "+action.result.meseji ,
											   buttons: Ext.MessageBox.OK,
											   icon: Ext.MessageBox.ERROR
											});
										} else {
											Ext.Msg.show({
												title: 'Server Response',
											   msg: " "+action.result.meseji + " ",
											   buttons: Ext.Msg.YESNO,
											   fn: function(btn, text){
													if (btn == 'yes')
													{
													 msgAction.load({
													 method:'POST', 
													 params: 'event_cmd=toggle_ext',
													 waitTitle:'Connecting to the Server', 
													 waitMsg:'Please wait as the database is being sync...',
														url:'./v2_apply/accept_user/'
													 });		
													 	tabs.body.update("&nbsp;");
														tabs.getForm().reset();
													}
												},
											   icon: Ext.MessageBox.INFO
											});
										}
 
										},
										failure:function(  ){
											 
												Ext.Msg.alert('Warning!' , 'An error has occured, please contact admin.'  ); 
										}
							 	});
			            }
					}]
    });
    tabs.render("form_rtp2");


});
