                                                                                                                                                                                                                               
////
 var Languagestore1 = new Ext.data.ArrayStore({
           fields: ['lvalue','dvalue'],
	       data: [
					['gujarati', 'Gujarati'],
					['english', 'English']/*,
					['bengali', 'Bengali'],
					['devanagari', 'Devanagari'],
					['gurmukhi', 'Gurmukhi'],
					['kannada', 'Kannada'],
					['malayalam', 'Malayalam'],
					['oriya', 'Oriya'],
					['tamil', 'Tamil'],
					['telugu', 'Telugu']*/
				]
        });

 var popuplanguageCombo = new Ext.form.ComboBox({
		name:'sitelanguagespopup',
		id:'sitelanguagespopup',
		hiddenName:'languagepopup',
		store: Languagestore1,
		displayField: 'dvalue',
		valueField: 'lvalue',
		typeAhead: true,
		editable:false,
		mode: 'local',
		forceSelection: true,
		triggerAction: 'all',	
		selectOnFocus: true,	
		width:80
	});
 
   popuplanguageCombo.on({'select': {
	fn: function(combo, options){
	indicChangepopup(this.id ,combo.getValue());},
	scope: this}});
  
   var popuplanguageToolbar = new Ext.Toolbar({  
	 height:30,
 	 style:'padding:5px 5px 0 0;',
     items: [
	 			new Ext.Toolbar.Fill(), // <--- we fill the empty space  
				{xtype:'label',text:'Type In :'},
		        popuplanguageCombo
			]  
 	});

function indicChangepopup(id, script){
	Ext.getCmp('sitelanguagespopup').setValue(script.toLowerCase());
	Ext.getCmp('sitelanguagespopup').setRawValue(script.charAt(0).toUpperCase() + script.substr(1).toLowerCase());
	pphTextpopup.setGlobalScript(script);
}

function initIndicIME1(){	

	pphTextpopup  = new PramukhPhoneticHandler();
	lang= "english";
	pphTextpopup.convertPageToIndicIME(lang, indicChangepopup);	

	Ext.getCmp('sitelanguagespopup').setValue(lang.toLowerCase());
	Ext.getCmp('sitelanguagespopup').setRawValue(lang.charAt(0).toUpperCase() + lang.substr(1).toLowerCase());
	//alert(Ext.getCmp('sitelanguagespopup').getValue());
} 
	
////

var labelArray;
labelArray = [
			['Allowances Name :<span class="comp">*</span>'],
			['Allowances Type :<span class="comp">*</span>'],
			['Allowances Value :<span class="comp">*</span>']
	];
if(flgDelete == "true") flgDelete1 = true;
			 else flgDelete1 = false;
if(flgAdd == "true") flgAdd1 = true;
			 else flgAdd1 = false;
var allwancesFields = [{
        name:'school_id',
        type: 'int'
    },{
        name: 'allowances_id',
        type: 'int'
    }, {
        name: 'allowances_name',
        type: 'string'
    },{
        name: 'allowances_percentage',
        type: 'int'
    },{
        name: 'allowances_value',
        type: 'string'
    }]

var allowancesRecord = Ext.data.Record.create(allwancesFields);

var allowancesstore = new Ext.data.JsonStore({
    url:'data/getallowances.php',
    root: 'rowa',
	remoteSort: true,
    sortInfo: {
    	field: 'allowances_id',
        direction: 'ASC'
   	},
    fields: allwancesFields,
    idProperty: 'allowances_id',
	autoLoad: true,
    writer:new Ext.data.JsonWriter()
}); 

var allowancescolmodel = new Ext.grid.ColumnModel([
	
	{ 
		header: "Allowances ID", 
		dataIndex: 'allowances_id',
		sortable: true, 
		hidden: true 
	},
	{ 
		id: 'allowances_name',
		header: "Allowances Name",
		width: 100,
		dataIndex: 'allowances_name',
		align: 'left',
		sortable: true
	},
	{
		dataIndex: 'allowances_value',
		header: 'Allowances Value',
		sortable: true,
		align: 'left',
		width: 100
	},
	{
		dataIndex: 'allowances_percentage',
		header: 'Allowances Type',
		renderer: allowancetypeconver,
		sortable: true,
		align: 'left',
		width: 100
	}
]);
var flgalert = 0;
var grid = new Ext.grid.GridPanel({
					xtype: 'grid',
					ds: allowancesstore,
					cm: allowancescolmodel,
					sm: new Ext.grid.RowSelectionModel({
						
						listeners: {
							rowselect: function(sm, row, rec) {
								
								Ext.getCmp("company-form").getForm().loadRecord(rec);
								  
									if(allowancesform.getForm().findField('allowances_percentage').getValue() == '0')
									{
										
										allowancesform.getForm().findField('r2').checked=false;
										allowancesform.getForm().findField('r1').checked=true;
										Ext.getCmp('per').setText('%');	 
									}
									if(allowancesform.getForm().findField('allowances_percentage').getValue() == '1')
									{
										
										allowancesform.getForm().findField('r2').checked=true;
										allowancesform.getForm().findField('r1').checked=false;
										Ext.getCmp('per').setText('Rs.');	 
									}
									if(flgEdit == "true")
									{
										Ext.getCmp('btnallowancesSave').enable();
										allowancesform.getForm().findField('allowances_name').enable();
										allowancesform.getForm().findField('r1').enable();
										allowancesform.getForm().findField('r2').enable();
										
										allowancesform.getForm().findField('allowances_value').enable();
									}
									else
									{
											if(flgalert == 0)
											{
												alert("You do not have access to edit the record.");
												flgalert = 1;
											}
									}
									if(flgDelete == "true"){
										Ext.getCmp('btnallowancesDel').enable();
									}
									if(flgAdd == "true"){
										Ext.getCmp('btnallowancesAdd').enable();
									}
							}
						}
					}),
					autoExpandColumn: 'allowances_name',
					height: 250,
					border: true
				});
	grid.on('render', function() {
   grid.tip = new Ext.ToolTip({
    view: grid.getView(),
    target: grid.getView().mainBody,
    delegate: '.x-grid3-row',
    trackMouse: true,
    renderTo: document.body,
    listeners: {
     beforeshow: function updateTipBody(tip) {
      tip.body.dom.innerHTML = "Please Click Here To Edit Or Delete Records.";
     }
    }
   });
  });
var allowancesform = new Ext.FormPanel({	
	id: 'company-form',
	frame: true,
	url:'save-allowances.php',
	labelAlign: 'left',
	
	bodyStyle:'padding:5px',
	
	layout: 'column',
	items: [{
				columnWidth: 1,
				layout: 'fit',
				items:[grid]
			},
			{
			columnWidth: 1,
			xtype: 'fieldset',
			defaults: {border:false},           
			
			width: 126,
			bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:10px 15px;',
			border: false,          
			labelWidth: 80,
			items: [
				{
					xtype       : 'container',
					autoEl      : {},
					border      : false,
					layout      : 'column',
					defaultType : 'field',
					items       : [{
									xtype  : 'container',
									autoEl : {},
									layout : 'form',
									columnWidth : 0.7,
									items  : [{	
												xtype: 'textfield',
												name: 'allowances_name',
												id:'allowances_name',
												labelSeparator:'',	
												fieldLabel :labelArray[0] ,
												disabled:true,
												allowBlank:false,
												autoCreate: {tag: 'input', type: 'text',  maxlength: '50'}
											}]
								
								 }]	
							   
				},				
				{
					xtype       : 'container',
					autoEl      : {},
					border      : false,
					layout      : 'column',
					defaultType : 'field',
					items       : [{
									xtype  : 'container',
									autoEl : {},
									layout : 'form',
									columnWidth : 0.67,
									items  : [{
												  xtype: 'radio',
												  fieldLabel: 'Allowances Type',
												  name: 'allowances_percentage',
												  id:'r1',
												  disabled: true,
												  checked:true,
												  inputValue: '1',												  
												  boxLabel: "%",
												  handler:function(){
													  if(this.checked) {
														Ext.getCmp('per').setText('%');	  
														
													
													 }													  	
												  }												  
											 }]
								   
								   },
								   {
									xtype       : 'container',
									autoEl      : {},
									layout      : 'form',
									columnWidth :0.3,
									items       : [{ 
													  xtype: 'radio',
													  hideLabel: true,
													  name: 'allowances_percentage',
													  id:'r2',
													  disabled: true,
													  inputValue: '0',
													  boxLabel: 'Rupees',
													  handler:function(){
														if(this.checked) {
															Ext.getCmp('per').setText('Rs.');	  
														  }	
													}	
												}]
								   }]
				},
				{
				xtype       : 'container',
				autoEl      : {},
				border      : false,
				layout      : 'column',
				defaultType : 'field',
				items       : [{
								xtype  : 'container',
								autoEl : {},
								layout : 'form',
								columnWidth : 0.67,
								items  : [{
											xtype: 'numberfield',
											labelSeparator:'',	
											fieldLabel :labelArray[2] ,
											name: 'allowances_value',
											id:'allowances_value',
											disabled: true,
											allowBlank:false,
											autoCreate: {tag: 'input', type: 'text',  maxlength: '5'}
										  }]
							   },
							   {
								xtype  : 'container',
								autoEl : {},
								layout : 'form',
								columnWidth :0.3,
								items  : [{  
											xtype: 'label',
											text:"%",
											name: 'per',											
											id:'per'
										 }]
							   }]
				 },			
				{
					xtype: 'numberfield',
					name: 'allowances_id',
					id:'allowances_id',
					hidden:true
			
				},
				{
					xtype: 'textfield',
					name: 'mode',
					id:'mode',
					value:'edit',
					hidden:true
			
				}
			]
			}
		]
});

allowancesform.getForm().findField('allowances_name').on('blur',function (){
		
	var allowances_name=allowancesform.getForm().findField('allowances_name').getValue();			
	var allowances_id=allowancesform.getForm().findField('allowances_id').getValue();			
		
		if(allowances_id == '')
		{
			allowances_id = 0;
		}
		var resbool="";		
				
		if(allowances_name!="")
		{			
					Ext.Ajax.request({
							  loadMask: true,
							  sync : true,
							  url: 'data/checkallowancesname.php',
							  params: {allowancesname: allowances_name,allowances_id: allowances_id},
							  success: function(resp) {
								// resp is the XmlHttpRequest object
								resbool=Ext.decode(resp.responseText).success;			                     
										if(resbool=='false')
										{
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Allowances name already exist.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});
											allowancesform.getForm().findField('allowances_name').reset();
										}	 			
							  }				
							});		
		}
	}); //allowances_name blur event

allowancesform.getForm().findField('allowances_value').on('focus',function (){
	
		pphTextpopup.setGlobalScript("english");
    });
allowancesform.getForm().findField('allowances_value').on('blur',function (){

	      pphTextpopup.setGlobalScript(document.getElementById('languagepopup').value);
    });
	
var AllowancesWindow = new Ext.Window({
	tbar: popuplanguageToolbar, 
	title: 'Allowances Information',
	width:490,		
	height:500,	
	border: false,
	layout: 'fit',
	modal:true,
	closeAction:'hide',
	collapsible:true,
	items: allowancesform,
	buttonAlign: 'center',
	buttons: [
					{
					text: 'Add New',
					name:'btnallowancesAdd',
					iconCls: 'icon-add',
					id:'btnallowancesAdd',disabled : !flgAdd1,
						handler: function (){
								
									
									allowancesform.getForm().findField('allowances_id').setValue(0);
									allowancesform.getForm().findField('allowances_name').enable();
									allowancesform.getForm().findField('r1').enable();
									allowancesform.getForm().findField('r2').enable();
									allowancesform.getForm().findField('allowances_value').enable();
									allowancesform.getForm().findField('allowances_name').reset();
									allowancesform.getForm().findField('allowances_percentage').reset();
									allowancesform.getForm().findField('allowances_value').reset();
									
									
									
									
									
									Ext.getCmp('btnallowancesSave').enable();
									Ext.getCmp('btnallowancesDel').disable();
									Ext.getCmp('btnallowancesAdd').disable();
								
						}
					},
					{text: 'Save', name:'btnallowancesSave',id:'btnallowancesSave',disabled: true,
					 handler: function (){
							allowancesform.getForm().submit({
								waitMsg: 'Saving...',
								success: function () {
									allowancesform.getForm().reset();
									allowancesform.getForm().findField('allowances_name').disable();
									allowancesform.getForm().findField('r1').disable();
									allowancesform.getForm().findField('r2').disable();
									
									allowancesform.getForm().findField('allowances_value').disable();
									Ext.getCmp('btnallowancesSave').disable();
									Ext.getCmp('btnallowancesDel').disable();
									grid.getSelectionModel().clearSelections();
								if(flgAdd == "true"){
									Ext.getCmp('btnallowancesAdd').enable();
								}
								allowancesstore.load();	
								
								
								},
								failure: function () {
										 Ext.MessageBox.show({
										   title: 'Error',
										   msg: 'Please fill up complete form.',
										   buttons: Ext.MessageBox.OK,
										   icon:Ext.MessageBox.ERROR
										  });									
								}
							});							
						}						 
					},
					{
					text: 'Delete',
					name:'btnallowancesDel',
					iconCls:'remove',
					id:'btnallowancesDel',
					disabled: true,
					 handler: function (){
							allowancesform.getForm().findField('mode').setValue('delete');
							if(allowancesform.getForm().findField('allowances_name').getValue() =='')
							{
								 Ext.MessageBox.show({
											   title: 'Error',
											   msg: 'Please select a record.',
											   buttons: Ext.MessageBox.OK,
											   icon:Ext.MessageBox.ERROR
											  });	
							}
							else
							{
							Ext.MessageBox.confirm('Confirmation', 'Do u want to Delete this record?',deleteallowances);
							}
						}	
					},
					{text: 'Reset', name:'btnallowancesReset',id:'btnallowancesReset',
					handler: function (){
									allowancesform.getForm().reset();
									allowancesform.getForm().findField('allowances_name').disable();
									allowancesform.getForm().findField('r1').disable();
									allowancesform.getForm().findField('r2').disable();
									
									allowancesform.getForm().findField('allowances_value').disable();
									Ext.getCmp('btnallowancesSave').disable();
									Ext.getCmp('btnallowancesDel').disable();
									grid.getSelectionModel().clearSelections();
								if(flgAdd == "true"){
									Ext.getCmp('btnallowancesAdd').enable();
								}
						}
									
					},
					{text: 'Close', name:'btnallowancesClose',id:'btnallowancesClose',
					handler: function (){
									
									AllowancesWindow.close();
								}
					}]

});
var varWidth =  (screen.width - AllowancesWindow.width)/2;
AllowancesWindow.setPosition(varWidth,((screen.height/4)-150));



function allowancetypeconver(v) {
        if (v == 0) return "Rupees"
        if (v == 1) return "Percentage"
    }
	
function deleteallowances(btn){
									if(btn=='yes')
									{			  			
										allowancesform.getForm().submit({
										waitMsg: 'Loading...',
										success: function () {
												allowancesform.getForm().reset();
									allowancesform.getForm().findField('allowances_name').disable();
									allowancesform.getForm().findField('r1').disable();
									allowancesform.getForm().findField('r2').disable();
									
									allowancesform.getForm().findField('allowances_value').disable();
									Ext.getCmp('btnallowancesSave').disable();
									Ext.getCmp('btnallowancesDel').disable();
									grid.getSelectionModel().clearSelections();
								if(flgAdd == "true"){
									Ext.getCmp('btnallowancesAdd').enable();
								}
								allowancesstore.load();	
										},
										failure: function () {
												 Ext.MessageBox.show({
												   title: 'Error',
												   msg: 'Please fill up complete form.',
												   buttons: Ext.MessageBox.OK,
												   icon:Ext.MessageBox.ERROR
												  });									
										}
									});
									}
									else
									{
										allowancesform.getForm().reset();
									}

								}