                                                                                                                                                                                                                               
/*var sectionstore_search = new Ext.data.ArrayStore({
	fields: ['section_id', 'section_name'],
	data: Ext.student.section
});

var stdstore_search = new Ext.data.ArrayStore({
	fields:['section_id','standard_id','standard_name'],
	data: Ext.student.standard
});

var divstore_search  = new Ext.data.ArrayStore({
	fields:['standard_id','standard_noofdiv'],
	data: Ext.student.division
});*/
 var branchstore1 = new Ext.data.ArrayStore({
		fields: ['branch_id', 'branch_name'],
		data: Ext.student.branch
  	}); 
	
  var semesterstore1 = new Ext.data.ArrayStore({
		fields: ['semester_id', 'semester_name'],
		data: Ext.student.semester
  	}); 
/*var BatchStore = new Ext.data.JsonStore({
    url:'../data/get-batch.php',
    root: 'data',
	remoteSort: true,
    fields: [{
        name:'batch_id',
        type: 'int'
    },{
        name: 'batch_name',
        type: 'string'
    }],autoLoad:true
});*/
var divisionstore = new Ext.data.ArrayStore({
    	fields:['division_id','division_name'],
		data: Ext.semester.division
	});	 
	
var booleanstore_search = new Ext.data.ArrayStore({
	fields: ['boolean','name'],
	data: [['1','Yes'],['0','No']]
}); 

var birthplacestore_search = new Ext.data.ArrayStore({
	fields:['student_birthplace'],
	data: Ext.student.birthplace
});	

var searchresultstore = new Ext.data.JsonStore({
	url:  '../library/data/getsearchresult.php',
	root: 'result',
	totalProperty: 'count',
	fields: [{ name: 'student_id' },{ name: 'semester_name' },{ name: 'semester_id' },{ name: 'branch_name' },{ name: 'branch_id' },{ name: 'division_id' },  { name: 'student_gturegno' },{ name: 'student_birthdate' },{ name: 'student_surname' },  { name: 'student_firstname' }, { name: 'student_lastname' },{ name: 'student_admdate' } ]
});

var searchresultgrid = new Ext.grid.GridPanel({
	store: searchresultstore,
	columns:[{ 
		header: "ID",
	    width: 30, 
		dataIndex: 'student_id',
		sortable: true,
		hidden:true
	},{   
		header: "Enrollment No",
        width: 15,
        dataIndex: 'student_gturegno',
        sortable: true
	},{ 
		header: "Surname",
		width: 20,
		dataIndex: 'student_surname',
		sortable: true
	},{   
		header: "First-Name",
		width: 20,
		dataIndex: 'student_firstname',
		sortable: true
	},{   
		header: "Last-Name",
		width: 20,
		dataIndex: 'student_lastname',
		sortable: true
	},{   
		header: "semester_id",
		width: 20,
		dataIndex: 'semester_id',
		sortable: true,
		hidden:true
	}
	],
    autoExpandColumn: 'title-col',
   	width: 565,
   	height: 230,
	title:'Search Result',
   	loadMask: true,
    columnLines: true,
    viewConfig:{ forceFit: true },
	bbar: new Ext.PagingToolbar({
		pageSize: 10,
		store: searchresultstore,
		displayInfo: true,
		displayMsg: 'Displaying data {0} - {1} of {2}',
		emptyMsg: "No Data found"
	})
});

searchresultstore.on({'beforeload':{
	fn: function(searchresultstore, options){
		options.params || (options.params = {}); //assert params
		Ext.apply(options.params, {
			pageNo: this.pageNumber,
				branchid:  searchform.getForm().findField('branch_id1').getValue(),
		gtuno: searchform.getForm().findField('grno_search').getValue() ,
		surname: searchform.getForm().findField('surname_search').getValue(),
		firstname: searchform.getForm().findField('firstname_search').getValue(),
		lastname: searchform.getForm().findField('lastname_search').getValue(),
		isstudying: searchform.getForm().findField('isstudying_search').getValue(), 
		semesterid: searchform.getForm().findField('semester_id1').getValue(), 
		division_id1: searchform.getForm().findField('division_id1').getValue(), 
//		standard: searchform.getForm().findField('std1_search').getValue(),
	//	division: searchform.getForm().findField('div1_search').getValue(),
	//	birthplace: searchform.getForm().findField('birthplace_search').getValue(),
		birthdate: searchform.getForm().findField('birthdate_search').getValue()
		});
	},
	scope: this
}});

var semester_id1 = new Ext.form.ComboBox({
	name: 'semester_id1',
				hiddenName: 'semester_hidden1',
				id:'semester_id1',
				labelSeparator:'',	
				fieldLabel :'Semester :<span class="comp">*</span>' ,
				forceSelection:true,				
				displayField:'semester_name',
				valueField: 'semester_id'
				
				,triggerAction:'all'
				,mode:'local'
				
				,store: semesterstore1
				,width:190
				,selectOnFocus: true
     			,listeners: {'select': function(cmb, rec, idx){
				
		
			//Ext.getCmp('division_id1').reset();
			/*studentstore.load({params: {'branch_id': Ext.getCmp('branch_id').getValue(),'semester_id': Ext.getCmp('semester_id').getValue(),'division_id': Ext.getCmp('division_id').getValue()}});*/
			var branch1=Ext.getCmp('branch_id1').getValue();
			divisionstore.filter('division_id',branch1+cmb.getValue(),false,true,true);
			var cnt=divisionstore.getCount();
			if(cnt==1)
			{
					Ext.getCmp('division_id1').setValue('A');
			}
			
		
  	}}
				
				 

});			
var division_id1 = new Ext.form.ComboBox({
	name: 'division_id1',
	hiddenName: 'batch_idhidden1',
	id:'division_id1',
	
	fieldLabel: 'Division :',
	forceSelection:true,
	tabIndex:5,
	labelSeparator:'',	
	displayField:'division_name',
	valueField: 'division_name',
	width:190,
	
	triggerAction:'all',
	mode:'local',
	store: divisionstore 
	 
});				
var branch_search = new Ext.form.ComboBox({
	name: 'branch_id1',
	hiddenName: 'branch_hidden1',
	id:'branch_id1',
	labelSeparator:'',	
	fieldLabel :'Branch :<span class="comp">*</span>' ,
	forceSelection:true,				
	displayField:'branch_name',
	valueField: 'branch_id'
	
	,triggerAction:'all'
	,mode:'local'
	,store: branchstore1
	,width:190
	
	,selectOnFocus: true
	
});

var grno_search = new Ext.form.NumberField({
	name: 'grno_search',
	id:'grno_search',
	fieldLabel: 'Enrollment No.',
	allowNegative: false,
	allowDecimals: false,
	autoCreate: {tag: 'input', type: 'text',  maxlength: '10'}
});

var surname_search = new Ext.form.TextField({
	id: 'surname_search',
	name: 'surname_search',
	width:90,
	emptyText:'Sur-Name',
	fieldLabel:'Name'
});				

var firstname_search = new Ext.form.TextField({
	id: 'firstname_search',
	name: 'firstname_search',
	width:90,
	emptyText:'First-Name'
});				

var lastname_search = new Ext.form.TextField({
	id: 'lastname_search',
	name: 'lastname_search',
	width:90,
	emptyText:'Last-Name'
});	

var name_search = {
	layout:'column',
	items:[{ 
		columnWidth:0.33,
		layout:'form',
		items:[surname_search]
	},{ 
		columnWidth:0.185,
		layout:'form',
		labelWidth:1,
		items:[firstname_search]
	},{ 
		columnWidth:0.3,
		layout:'form',
		labelWidth:1,
		items:[lastname_search]
	}]
}

var birthdate_search =  new Ext.form.DateField({
	id: 'birthdate_search',
	fieldLabel:'Birth-Date',
	name: 'birthdate_search'						  
});		

var isstudying_search = new Ext.form.ComboBox({
	name: 'isstudying_search',
	id:'isstudying_search',
	fieldLabel: 'Is Studying',
	forceSelection:true,				
	displayField:'name',
	valueField: 'boolean',
	emptyText:'',
	editable:false,
	triggerAction:'all',
	mode:'local',
	store: booleanstore_search,
	width:80							
});	
	
/*var birthplace_search = new Ext.form.ComboBox({
	name: 'birthplace_search',
	id:'birthplace_search',
	fieldLabel: 'Birth-Place',
	displayField:'student_birthplace',
	valueField: 'student_birthplace',
	width: 127,
	emptyText:'',
	triggerAction:'all',
	mode:'local',
	store: birthplacestore_search,
	forceSelection:true,
	editable: true
});	*/
/*	
var std1_search = new Ext.form.ComboBox({
	name: 'std1_hidden_search',
	id:'std1_search',
	hiddenName:'std1_hidden_search',
	fieldLabel:'Standard',
	forceSelection:true,				
	displayField:'standard_name',
	valueField: 'standard_id',
	width: 80,
	emptyText:'',
	lastQuery:'',
	editable:false,
	triggerAction:'all',
	mode:'local',
	allowBlank:false,
	store: stdstore_search,
	listeners:{select:{fn:function(combo, value){
		Ext.getCmp('div1_search').enable();
		Ext.getCmp('div1_search').clearValue();
		Ext.getCmp('div1_search').store.filter('standard_id', combo.getValue());
		//tabs.getForm().findField('standerd_name').setValue(combo.getRawValue());					
		//studentform.getForm().findField('standerd_name').setValue(combo.getRawValue());
	}}}
});*/

/*var div1_search = new Ext.form.ComboBox({
	name: 'div1_search',
	id:'div1_search',
	allowBlank:false,
	fieldLabel: 'Division',
	forceSelection:true,				
	displayField:'standard_noofdiv',
	valueField: 'standard_noofdiv',
	width: 50,
	emptyText:'',
	lastQuery:'',
	triggerAction:'all',
	mode:'local',
	store: divstore_search,
	editable:false
});
*/
var searchitems = { 
    xtype: 'fieldset',
    labelWidth: 80,
	border: false,
    defaults: { width: 260 }, 
    autoHeight: true,
	width:584,
    bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
    layout:'column',
	items: [    
		{ columnWidth:1,   layout:'form', items:[branch_search] 	},
     	{ columnWidth:1,   layout:'form', items:[semester_id1] 	},
		{ columnWidth:1,   layout:'form', items:[division_id1] 	},			
		{ columnWidth:1,   layout:'form', items:[isstudying_search] },
	//	{ columnWidth:0.5, layout:'form', items:[std1_search] 		},
		//{ columnWidth:0.5, layout:'form', items:[div1_search] 		},
		{ columnWidth:1,   layout:'form', items:[grno_search] 		},
		{ columnWidth:1,   layout:'form', items:[name_search] 		},
	    { columnWidth:0.5, layout:'form', items:[birthdate_search] 	},
		
		{ 
			columnWidth:0.99,
			layout:'form', 
			items:[{ buttons:[{ 
				text: 'Search',
				style:{margin:'0px 0px 0px 0px',padding:'0px 0px 0px 380px'},	 
				handler: function(){	 
				
					load_grid(); 
				}
			},{
				text: 'Reset',
				id:'reset1',
				handler: function(){ 
					reset_thisform();
					Ext.getCmp('batch_id').setValue(0);
                 	Ext.getCmp('batch_id').setRawValue('All');
				}
			}]}]
		}   
	]
}
	  
var searchform = new Ext.FormPanel({
	id: 'searchform',
    frame: true,
    labelAlign: 'left',
    bodyStyle: 'padding:5px',
    draggable: false,
	layout:'column',
	items:[searchitems,searchresultgrid]
});

Ext.getCmp('birthdate_search').on('focus',function (){
	pphText.setGlobalScript("english");
});
Ext.getCmp('birthdate_search').on('blur',function (){
	pphText.setGlobalScript(document.getElementById('sitelanguages').value);
});

/*Ext.getCmp('birthplace_search').on('focus',function (){
	pphText.setGlobalScript("english");
});
Ext.getCmp('birthplace_search').on('blur',function (){
	pphText.setGlobalScript(document.getElementById('sitelanguages').value);
});
*/
Ext.getCmp('grno_search').on('focus',function (){
	pphText.setGlobalScript("english");
});
Ext.getCmp('grno_search').on('blur',function (){
	pphText.setGlobalScript(document.getElementById('sitelanguages').value);
});

function reset_thisform(){
	searchform.getForm().reset();
  	searchresultstore.removeAll();	
}

function load_grid(){
	searchresultstore.load({params:{
		branchid:  searchform.getForm().findField('branch_id1').getValue(),
		gtuno: searchform.getForm().findField('grno_search').getValue() ,
		surname: searchform.getForm().findField('surname_search').getValue(),
		firstname: searchform.getForm().findField('firstname_search').getValue(),
		lastname: searchform.getForm().findField('lastname_search').getValue(),
		isstudying: searchform.getForm().findField('isstudying_search').getValue(), 
		semesterid: searchform.getForm().findField('semester_id1').getValue(), 
		division_id1: searchform.getForm().findField('division_id1').getValue(), 
//		standard: searchform.getForm().findField('std1_search').getValue(),
	//	division: searchform.getForm().findField('div1_search').getValue(),
	//	birthplace: searchform.getForm().findField('birthplace_search').getValue(),
		birthdate: searchform.getForm().findField('birthdate_search').getValue(),start: 0
	}});	
	searchresultstore.removeAll();
}

/*searchform.getForm().findField('section_search').on('select',function (){
	Ext.getCmp('std1_search').reset();
	Ext.getCmp('div1_search').reset();
	Ext.getCmp('std1_search').enable();
	Ext.getCmp('std1_search').clearValue();
	Ext.getCmp('std1_search').store.filter('section_id', Ext.getCmp('section_search').getValue());
	//stdstore_search.load({params:{section_id: this.getValue()}});
	//stdstore_search.removeAll(); 
}); 
*/
//searchform.getForm().findField('std1_search').disable();
//searchform.getForm().findField('div1_search').disable();
searchform.getForm().findField('isstudying_search').on('select',function (){ 			
	var active = searchform.getForm().findField('isstudying_search').getValue();
	if(active=="Yes"){ 
	//	searchform.getForm().findField('std1_search').enable();
		//searchform.getForm().findField('div1_search').enable();
	} else{
		//searchform.getForm().findField('std1_search').reset();
		//searchform.getForm().findField('div1_search').reset();
		//searchform.getForm().findField('std1_search').disable();
		//searchform.getForm().findField('div1_search').disable();
	}
});

/*searchform.getForm().findField('std1_search').on('select',function (){ 			
	Ext.getCmp('div1_search').reset();
	Ext.getCmp('div1_search').enable();
	Ext.getCmp('div1_search').clearValue();
	Ext.getCmp('div1_search').store.filter('standard_id', Ext.getCmp('std1_search').getValue());
});*/ 

function Student_KeyCheck(e){  
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if(KeyID=='13'){
		load_grid();
    }
   	if(KeyID=='46'){
		reset_thisform();
 	}
}

var win_search = new Ext.Window({
	tbar: languageToolbar, 
	title: 'General Search' ,
	height:525,
	width:600,		
	layout: 'fit',
	border: false,
	modal:true,
	closeAction:'hide',
	autoDestroy :true,
	collapsible:true,
	items: searchform
})
var varWidth =  (screen.width - win_search.width)/2;
win_search.setPosition(varWidth,((screen.height/4)-160));
Ext.getCmp('division_id1').on('expand',function (){
	
	var branch1=Ext.getCmp('branch_id1').getValue();
			divisionstore.filter('division_id',branch1+Ext.getCmp('semester_id1').getValue(),false,true,true);
			var cnt=divisionstore.getCount();
			if(cnt==1)
			{
					Ext.getCmp('division_id1').setValue('A');
			}
	});

function set_grno(branchid,branchname){
	win_search.show();
	document.onkeyup = Student_KeyCheck; 
	initIndicIME();
 
	//sectionstore_search.removeAll();
	//sectionstore_search.load();
	Ext.getCmp('branch_id1').setValue(branchid);
	Ext.getCmp('branch_id1').setRawValue(branchname);
	searchresultstore.removeAll();
	//stdstore_search.removeAll();  
	//stdstore_search.load({params:{section_id: branchid}});
	searchresultgrid.getSelectionModel().on('rowselect', function(sm, rowIndex, record) {
		Ext.getCmp('txtgrno').setValue(record.data.student_grno);
		Ext.getCmp('txtgrno').focus();
		win_search.hide();
	});
}

function general_search(){
	reset_thisform();
	//birthplacestore_search.load();
	//sectionstore_search.removeAll();
	//sectionstore_search.load();  
	win_search.show();
	document.onkeyup = Student_KeyCheck;  
	initIndicIME();

}

function OpenStudentSearch(){
  	//birthplacestore_search.load();  
  	//sectionstore_search.removeAll();
  	//sectionstore_search.load();  
 	win_search.show();
  	document.onkeyup = Student_KeyCheck; 
	initIndicIME();
	//Ext.getCmp('batch_id1').setValue(0);
	//Ext.getCmp('batch_id1').setRawValue('All');
 
  	searchresultgrid.getSelectionModel().on('rowselect', function(sm, rowIndex, record) {
			
		Ext.getCmp('member_id').setValue(record.data.student_id);

       // Ext.getCmp('batch_id').setValue(record.data.batch_id);
     	Ext.getCmp('semester_id').setValue(record.data.semester_id);
		Ext.getCmp('branch_id').setValue(record.data.branch_id);
		Ext.getCmp('division_id').setValue(record.data.division_id);
		Ext.getCmp('txtgrno').setValue(record.data.student_gturegno);
		//Ext.getCmp('txtgrno').enable();
		Ext.getCmp('membername').setValue(record.data.student_surname+" "+record.data.student_firstname+" "+record.data.student_lastname);
		Ext.getCmp('membername').enable();
		//Ext.getCmp('student_section').setValue(record.data.section_id);
		Ext.getCmp('txttotalIssueablebook').enable();
		Ext.getCmp('txttotalissuedbook').enable();
		Ext.getCmp('txtbookregno').enable();
		Ext.getCmp('txtbookname').enable();
		Ext.getCmp('book_returndate').enable();
		Ext.getCmp('txtbookregno').focus();
		//searchresultstore.reload();
		Ext.getCmp('myFormPanel').getForm().load({
			params:{student_id:record.data.student_id,txtgrno: record.data.student_gturegno,category:  Ext.getCmp('membercategory').getValue()},
				url: 'data/getMemberData.php',
				waitMsg:'Loading',
				success: function() {			
					Ext.getCmp('txtbookregno').enable();
					Ext.getCmp('txtbookname').enable();
					Ext.getCmp('book_returndate').enable();
					Ext.getCmp('myFormPanel').getForm().findField('txtbookregno').focus(true,500);
				},
				failure: function() {
			    	Ext.MessageBox.show({
					   title: 'Error',
					   msg: 'Member is not available.',
					   buttons: Ext.MessageBox.OK,
					   icon:Ext.MessageBox.ERROR
					  });
					Ext.getCmp('txtgrno').reset();
					Ext.getCmp('membername').reset();
					Ext.getCmp('txttotalIssueablebook').reset();
					Ext.getCmp('txttotalissuedbook').reset();
				}});
		win_search.hide();
	});
}