var labelArray;
labelArray = [ 	['Item Name :<span class="comp">*</span>'],
				['Type :<span class="comp">*</span>'],
				['Address :<span class="comp">*</span>'],
				['Name :<span class="comp">*</span>'],
				['Phone :<span class="comp"></span>'],
				['Mobile :<span class="comp"></span>'],
				['Email :<span class="comp"></span>'],
				['Website :<span class="comp"></span>'],
				['Name :<span class="comp"></span>'],			
		
			];

var categorystore = new Ext.data.Store({
		url: 'data/getcategory.php', 
		totolProperty:'total',
		reader: new Ext.data.JsonReader({			
			fields: ['product_category'],
			root: 'rows'
		}),autoLoad:true
	}); 
			var customertypestore = new Ext.data.ArrayStore({
           fields: ['customer_type'],
	       data: [['Stockable'],['Non Stockable'],['Service'],['AMC']]
        });
		var warrantystore = new Ext.data.ArrayStore({
           fields: ['customer_type'],
	       data: [['Yes'],['No']]
        }); 
		var warrantytypestore = new Ext.data.ArrayStore({
           fields: ['customer_type'],
	       data: [['Vendor'],['Manufacturer']]
        });
		
		
		
	var encode = false;
	var local = false;
	var xg = Ext.grid;
	 
	 var sm2 = new xg.CheckboxSelectionModel({
        listeners: {
        selectionchange: function(sm) {
                if (sm.getCount()) {
                    prodgrid.removeButton.enable();
                } else {
                    prodgrid.removeButton.disable();
                }
            }
        }
    }); 
	var measurementstore = new Ext.data.Store({
		url: 'data/getmeasurement.php', 
		totolProperty:'total',
		reader: new Ext.data.JsonReader({			
			fields: ['measurement'],
			root: 'rows1'
		}),autoLoad:true
	}); 
	
	
//tax

 /*var Employee = Ext.data.Record.create([{
        name: 'tax_name',
        type: 'string'
    },/* {
        name: 'basedon',
        type: 'string'
    },*//*{
        name: 'amount',
        type: 'float'
    }]);


    // hideous function to generate employee data
  

    var producttaxstore = new Ext.data.GroupingStore({
		url: 'data/getproducttax.php',   
		reader: new Ext.data.JsonReader
		({
			
			fields:['tax_id','tax_name','amount'],
			root: 'result'
		})
		
	});
	var Taxtstore = new Ext.data.Store
	({
		reader: new Ext.data.JsonReader
		({
			id:'tax_id',
			fields:['tax_id','tax_name'],
			root: 'rows'
		}),
		proxy: new Ext.data.HttpProxy
		({
			url: 'data/gettax.php'
		}),autoLoad:true
		
	});
	var tax_combo = new Ext.form.ComboBox({
				name:'tax',
				id:'tax',
				displayField:'tax_name',
				valueField: 'tax_id',
				width:200,										
				tabIndex:10,
				allowBlank:false,
				triggerAction:'all',
				mode:'local',
				store: Taxtstore,
				editable:true,
				forceSelection:true,
				tabIndex:5,
	});

	var Taxbaseonstore = new Ext.data.ArrayStore({
           fields: ['basedon'],
	       data: [['Total Amount'],['Purchase'],['Sale']]
        });
		
	var Taxbaseon=	new Ext.form.ComboBox({
								name: 'taxbasedon',
								id:'taxbasedon',
								forceSelection:true,	
								displayField:'basedon',
								valueField:'basedon',
								width: 100,	
								selectOnFocus: true,	
								allowBlank:false,
								triggerAction:'all',
								mode:'local',
								editable:true,
								store: Taxbaseonstore
				});
	*/
	
   

   /* var Taxgrid = new Ext.grid.EditorGridPanel({
        store: producttaxstore,
		clicksToEdit: 1,
        width: 220,
		layout:'fit',
		height:150,
       // region:'center',
        //margins: '0 5 5 5',
		selModel:  new Ext.grid.RowSelectionModel({singleSelect: true}),
       /* //autoExpandColumn: 'tax_name',
        view: new Ext.grid.GroupingView({
            markDirty: false
        }),*//*
        tbar: [{
            iconCls: 'icon-add',
            text: 'Add Tax',
            handler: function(){
                var e = new Employee({
                    tax_id: '',
                    //basedon: '',
                    amount: ''
                });
                Taxgrid.stopEditing();
				var insert=(Taxgrid.store.getCount());
                producttaxstore.insert(insert, e);
                Taxgrid.getView().refresh();
                Taxgrid.getSelectionModel().selectRow(insert);
                Taxgrid.startEditing(insert,1);
            }
        },{
            ref: '../removeBtn',
            iconCls:'remove',
            text: 'Delete Tax',
            disabled: true,
            handler: function(){
                Taxgrid.stopEditing();
                var s = Taxgrid.getSelectionModel().getSelections();
                for(var i = 0, r; r = s[i]; i++){
                    producttaxstore.remove(r);
					
                }
				var remove=(Taxgrid.store.getCount()-1);
				if(remove!=-1)
				{
				Taxgrid.getSelectionModel().selectRow(remove);
				Taxgrid.startEditing(remove,1);
				}
            }
        }],

        columns: [
        new Ext.grid.RowNumberer(),
        {
            id: 'tax_name',
            header: 'Tax',
            dataIndex: 'tax_id',
            width: 120,
            sortable: true,
            editor: tax_combo,
			renderer: function(value)
			{
					var r = Taxtstore.getById(value);
					return r ? r.get('tax_name') : '';
			}
        },/*{
            header: 'Based On',
            dataIndex: 'basedon',
			id:'basedon',
            width: 90,
            sortable: true,
            editor: Taxbaseon
        },*//*{
            xtype: 'numbercolumn',
            header: '%',
            dataIndex:'amount',
			id:'amount',
            width: 50,
            sortable: true,
            editor: {
                xtype: 'numberfield',
                allowBlank: false,
                minValue: 1,
                maxValue: 100
            }
        }]
    });


    Taxgrid.getSelectionModel().on('selectionchange', function(sm){
        Taxgrid.removeBtn.setDisabled(sm.getCount() < 1);
    });*/
	
	//tax
	
	
var picFiles = {
		columnWidth: .65,
		layout: 'form',
		labelAlign:'top',
		items: [
			{
				xtype: 'textfield',
				fieldLabel: 'Current',
				labelSeparator: '',
				name: 'currPic',
				id:'currPic',
				readOnly: true,
				disabled:true
			},
			{
				xtype: 'textfield',
				fieldLabel: 'New (JPG or JPEG only)',
				labelSeparator: '',
				name: 'newPic',
				id:'newPic',
				style:'width: 200px',
				inputType: 'file',
				allowBlank: false
			}
		]}
	
	var pictUploadForm = new Ext.FormPanel({
		   frame: true,
		   bodyStyle: 'padding:5px',		  
		   layout: 'column',
		   url:'productphotoupload.php',
		   method: 'POST',
		   fileUpload: true,
		   items: [picFiles],	
		   buttons: [{
			  text: 'Upload Picture',
			  handler: function() {
				 var theForm = pictUploadForm.getForm();
				 if (!theForm.isValid()) {
					 Ext.MessageBox.show({
										   title: 'Change Picture',
										   msg: 'Please select a picture!',
										   buttons: Ext.MessageBox.OK,
										   icon:Ext.MessageBox.ERROR
										  });
					
					return;
				 }
				 if (!validateFileExtension(Ext.getDom('newPic').value)) {
					   Ext.MessageBox.show({
										   title: 'Change Picture',
										   msg: 'Only JPG or JPEG, please.!',
										   buttons: Ext.MessageBox.OK,
										   icon:Ext.MessageBox.ERROR
										  });
					
					return;
				 }
				 theForm.submit({		 
					params: { act:'setPicture'}
				 });
			   }
			},
			{
			  text: 'Reset',
			  handler: function () {
						pictUploadForm.getForm().reset();
					}
			}
			]
	});
	
	var win = new Ext.Window({
				title: 'Change Picture',
				height: 200,
				width: 420,
				layout: 'fit',
				modal:true,
				closeAction:'close',
				autoDestroy :true,
				items: pictUploadForm
			});

    pictUploadForm.on({
    actioncomplete: function(form, action) {
					if (action.type == 'load') {
						var varpic = action.result.data;	
							
						Ext.getDom('pic').src = varpic.file;
						Ext.getCmp('currPic').setValue(varpic.file);
					}
					if (action.type == 'submit') {
						var varpic = action.result.data;
						Ext.getDom('pic').src = varpic.file;
						Ext.getCmp("ProductgridForm").getForm().findField('product_photo').setValue(varpic.photoname);
						Ext.getCmp('currPic').setValue(varpic.file);
						Ext.getDom('newPic').value ='';
						win.hide();
					}
			}
	});
	pictUploadForm.getForm().load({ 
						  	 params:{ act:'getPicture',id:1}
						  });	
	
productstore = new Ext.data.JsonStore({
       	autoDestroy: true,
        url:'data/product-grid-filter.php',
        remoteSort: true,
        sortInfo: {
            field: 'product_id',
            direction: 'ASC'
        },        
        idProperty: 'product_id',
        root: 'data',
        totalProperty: 'total',
        fields: [{
            name: 'product_id',
			type: 'int'
        }, {
            name: 'product_name'
        }, {
            name: 'product_category'
        }, {
            name: 'product_type'
			
        }, {
            name: 'product_warranty'
        }, {
            name: 'product_warrantytype'
        }, {
            name: 'product_measurement'
        },{
            name: 'product_reorder'
        }, {
            name: 'product_active'
        }, {
            name: 'product_photo'
        },{
            name: 'product_opnstock'
        },
		{
            name: 'product_description'
        }] 
    });
    var prodfilters = new Ext.ux.grid.GridFilters({
        encode: encode,
        local: false,                                      
		filters: [{
				  type: 'numeric',
            dataIndex: 'product_id',
			 phpMode: true
        }, {
			type: 'string',
            dataIndex: 'product_name',
			phpMode: true

        }, {
            dataIndex: 'product_category',
			type: 'string'
        }, {
            dataIndex: 'product_type',
			type: 'string'
        }, {
            dataIndex: 'product_warranty',
			type: 'string'
        }]
    });
	
var createColModel = function (finish, start) {
        var columns = [
		sm2,
		{
            dataIndex: 'product_id',
			header: 'product ID',
			hidden:true,
			filterable: true
        }, {
            dataIndex: 'product_name',
			header: 'Product Name',
			filterable: true,
			width: 140
			
        }, {
            dataIndex: 'product_category',
			header: 'Category',
			hidden:true
        }, {
            dataIndex: 'product_type',
			header: 'Type',
			width: 110
			
        }, {
            dataIndex: 'product_warranty',
			header: 'Warranty',
			hidden:true
        }];
		return new Ext.grid.ColumnModel({
            columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    };
	
var prodgrid = new Ext.grid.GridPanel({
        store: productstore,
        colModel: createColModel(40), 
        loadMask: true,
		frame: true,
		enableColLock:false,
		height: 500,    
        width: 300,
        layout: 'fit',
		columnLines:true,
		selModel:  new Ext.grid.RowSelectionModel({
		singleSelect: true,
		listeners: {
			rowselect: function(sm, row, rec) {
				Ext.getCmp("ProductgridForm").getForm().loadRecord(rec);
				
				var photoname = Ext.getCmp('product_photo').getValue();
				pictUploadForm.getForm().load({ 
						  	 params:{ act:'getPicture',id:1,photoname:photoname}
				 });		
				/*producttaxstore.load({ params:
				{
				 product_id:  Ext.getCmp('product_id').getValue(),
				}
				});	*/
				 prodgrid.removeButton.enable();
				 
				 if( Ext.getCmp('product_warranty').getValue()=='Yes')
				 {
						Ext.getCmp('product_warrantytype').enable();
						
				 }else
				 {
					  Ext.getCmp('product_warrantytype').reset();
					 Ext.getCmp('product_warrantytype').disable();
				}
				if(Ext.getCmp('product_type').getValue()=='Stockable')
				{
					Ext.getCmp('product_reorder').enable();
					
				}
				else
				{
					Ext.getCmp('product_reorder').reset();
					Ext.getCmp('product_reorder').disable();
				}
				
												
				//Discription Replace<br\>
				var str_remark= Ext.getCmp('product_description').getValue();
				str_remark = str_remark.replace(/<br\/>/g,"\r\n");
				Ext.getCmp('product_description').setValue(str_remark);
			}
		 }
		}),
        plugins: [prodfilters],
        listeners: {
            render: {
                fn: function(g){
					 productstore.reload({
                        params: {
                            start: 0,
                            limit: 20  
                        }
                    });
					 g.getSelectionModel().selectRow(0);
                   
                   
                }
            }
        }  ,
		tbar:[
         { 
		    	iconCls: 'icon-add',
           		text: 'Add Product',
				ref: '../removeButton',
				tabindex:11,
            	handler: function() {
					
					Ext.getCmp("ProductgridForm").getForm().reset();
					prodgrid.getSelectionModel().clearSelections();
					prodgrid.removeButton.disable();

					//Taxgrid.store.removeAll();
					pictUploadForm.getForm().load({ 
						 params:{ act:'getPicture',id:1}
						 
					  });
               
			    }
              
		            
      		},'-',
			{text: 'Delete Product',
            handler: confirmdeleteproduct,  
            iconCls:'remove',
			ref: '../removeButton',
			disabled: true
			}
	  ], 
        bbar: new Ext.PagingToolbar({
            store: productstore,
            pageSize: 20,
			displayInfo: true,
            plugins: [prodfilters]
        })
    });

    prodgrid.getBottomToolbar().add([
        '->',
      {
            text: 'Clear Filter Data',
            handler: function () {
                prodgrid.prodfilters.clearFilters();
            } 
        }    
    ]);
	
	productstore.on({
		'beforeload': {
    		fn: function(store, options){
            	options.params || (options.params = {}); 
            	Ext.apply(options.params, {
            		pageNo: this.pageNumber
            	});
        	},
        	scope: this
    	}
	});
		
function confirmdeleteproduct(){
		if(prodgrid.selModel.getCount() == 1)
		{
		  Ext.MessageBox.confirm('Confirmation','You are about to delete a Product. Continue?', deleteproduct);
		} else if(prodgrid.selModel.getCount() > 1){
		  Ext.MessageBox.confirm('Confirmation','Delete these Product(s)?', deleteproduct);
		} 
  } 
function deleteproduct(btn){
    if(btn=='yes'){
         var selections = prodgrid.selModel.getSelections();
         var prez = [];
         for(i = 0; i< prodgrid.selModel.getCount(); i++){
          prez.push(selections[i].json.product_id);
         }
         var encoded_array = Ext.encode(prez);
		
         Ext.Ajax.request({  
            waitMsg: 'Please Wait',
            url:'data/product-grid-delete.php', 
            params: { 
               task: "DELETEEMP", 
               ids:  encoded_array
			   }, 
            success: function(response){
              var result=eval(response.responseText);
              switch(result){
              case 1: 
			  	
				Ext.getCmp("ProductgridForm").getForm().reset();
				//Taxgrid.store.removeAll();
				productstore.load();
				prodgrid.getSelectionModel().clearSelections();
				prodgrid.removeButton.disable();
				pictUploadForm.getForm().load({ 
					 params:{ act:'getPicture',id:1}
					 
				  });
                break;
              default:
                Ext.MessageBox.alert('Warning','Could not delete the entire selection.');
                break;
              }
            },
            failure: function(response){
              var result=response.responseText;
              Ext.MessageBox.alert('error','could not connect to the database. retry later');      
              }
         });
      }  
  }


	
	
	//tab2 code
	
var flgalert = 0;
var tabCfg = {
        xtype: 'tabpanel',
        activeTab: 0,
        width: 700,
        height: 498,
		plain: true,
		bodyStyle: {
            'background-color': '#DfE8f6'
			
        },
        items: [{
            title: 'Product Information',
			layout: 'column', 
			 defaults: {
            bodyStyle: 'padding:8px;'
        },
			items: [{
				columnWidth: 0.5,
				labelWidth:90,
				layout: 'form',
				items:[{
							xtype: 'label',
							text: 'Basic',
							style: 'padding:0px 0px',
							cls: 'x-form-item myBold'	
					 },
					 {
							xtype: 'textfield',
							name: 'product_name',
							id:'product_name',
							 tabIndex:1,
							labelSeparator:'',	
							fieldLabel :labelArray[0] ,
							width:200,
							allowBlank:false
					},{
							   xtype: 'combo',
							   name: 'product_category',
							   id:'product_category',
							   tabIndex:2,
							   fieldLabel :'Category',
							   displayField:'product_category',
							   valueField: 'product_category',
							   width: 200,
							   allowBlank:false,
							   triggerAction:'all',
							   mode:'local',			
							   selectOnFocus: true,	
							   store: categorystore,
							   editable:true
					},{
								xtype: 'combo',
								name: 'product_type',
								id:'product_type',
								labelSeparator:'',	
								fieldLabel :labelArray[1] ,
								forceSelection:true,	
								tabIndex:3,			
								displayField:'customer_type',
								valueField:'customer_type',
								width: 200,	
								selectOnFocus: true,	
								allowBlank:false,
								triggerAction:'all',
								mode:'local',
								editable:true,
								store: customertypestore,
								listeners:{select:{fn:function(combo, value) 
								{
									if(combo.getValue()=='Stockable')
									{
										Ext.getCmp('product_reorder').enable();
										
									}
									else
									{
										Ext.getCmp('product_reorder').reset();
										Ext.getCmp('product_reorder').disable();
									}
								}	
								}}
				  },{
							xtype: 'textfield',
							name: 'product_opnstock',
							id:'product_opnstock',
							 tabIndex:4,
							fieldLabel :'Opening Stock' ,
							width:150,
							allowBlank:false
					},{ 
					 		height:30
						},{
							xtype: 'label',
							text: 'Warranty Info',
							style: 'padding:0px 0px',
							cls: 'x-form-item myBold'	
					 },{
								xtype: 'combo',
								name: 'product_warranty',
								id:'product_warranty',
								fieldLabel :'Warranty',
								forceSelection:true,	
								tabIndex:6,			
								displayField:'customer_type',
								valueField:'customer_type',
								width: 100,	
								selectOnFocus: true,	
								allowBlank:false,
								triggerAction:'all',
								mode:'local',
								editable:true,
								store: warrantystore,
								listeners:{select:{fn:function(combo, value) 
								{
									if(combo.getValue()=='Yes')
									{
										Ext.getCmp('product_warrantytype').enable();
										
									}
									else
									{
										Ext.getCmp('product_warrantytype').reset();
										Ext.getCmp('product_warrantytype').disable();
									}
								}	
								}}
				  			},{
								xtype: 'combo',
								name: 'product_warrantytype',
								id:'product_warrantytype',
								fieldLabel :'Warranty Type',
								forceSelection:true,	
								tabIndex:7,			
								displayField:'customer_type',
								valueField:'customer_type',
								width: 100,	
								selectOnFocus: true,	
								allowBlank:false,
								triggerAction:'all',
								disabled:true,
								mode:'local',
								editable:true,
								store: warrantytypestore
				  },{ 
					 		height:20
						},{
							xtype: 'label',
							text: 'Description',
							style: 'padding:0px 0px',
							cls: 'x-form-item myBold'	
					 },{ 
						xtype: 'textarea',
						name: 'product_description',
						id:'product_description',
						style:'padding:0px 0px 0px 0px',
					    width:200,
						tabIndex:11,
						height:150,
						allowBlank:true
				}]
			},{	
            columnWidth: 0.5,
			layout: 'form',
			labelWidth:90,
			items: [{
							xtype: 'label',
							text: 'Picture',
							cls: 'x-form-item myBold'	
					 },{
										 style: 'padding:0px 0px 0px 0px',
										 items:[{ xtype: 'box',
												  autoEl: { tag: 'div',
															html: '<img id="pic" src="photo.gif" alt="photograph" class="img-contact" width=150" height="100"/>'
														  }
												},
												{
													style: 'padding:0px 0px 0px 0px',
													xtype: 'button',
													text: 'Upload',
													width:150,
													tabIndex:5,	
													handler:function() 
													{
															win.show();
															Ext.getDom('newPic').size = 30;
													}
												}]
										},{ 
					 		height:14
						},{
							xtype: 'label',
							text: 'Custome Info',
							style: 'padding:0px 0px',
							cls: 'x-form-item myBold'	
					 },{
								xtype: 'combo',
								name: 'product_measurement',
								id:'product_measurement',
								fieldLabel :'Mesure' ,
								displayField:'measurement',
								valueField: 'measurement',
								allowBlank:false,
								width:100,
								triggerAction:'all',
								editable:true,
								mode:'local',
								store: measurementstore,
								tabIndex:8
							},{
							xtype: 'textfield',
							name: 'product_reorder',
							id:'product_reorder',
							fieldLabel :'Min order Level',
							width:100,
							disabled:true,
							allowBlank:true,
							tabIndex:9
							
    				 },{
								xtype:'checkbox',
								name: 'product_active',
								fieldLabel: 'Active',
								tabIndex:10,
								checked :false
							},{ 
					 		height:18
					},/*{
							xtype: 'label',
							text: 'Tax Info',
							style: 'padding:0px 0px',
							cls: 'x-form-item myBold',	
					 }, Taxgrid,*/{
							xtype: 'textfield',
							name: 'product_id',
							id:'product_id',
							hidden:true
					 },
					 {
							xtype: 'textfield',
							name: 'product_photo',
							id:'product_photo',
							hidden:true
					 }]
			}],
			buttonAlign: 'center',
		    buttons:[
		  {
            	text: 'Save',
				iconCls: 'icon-save',
				tabIndex:12,
				handler: function () {
					var taxids = new Array();	
					var taxamount = new Array();	
					var m=0;
					var cnt=0;
					/*for(var i = 0, len = Taxgrid.store.getCount(); i < len; i++){
										record = Taxgrid.store.getAt(i);
										tax = record.data.tax_id;
										amount = record.data.amount;
										if(tax!="" && amount!=""  )
										{
											taxids[m] =  tax;
											taxamount[m]=amount;
											m++;
										}else
										{
											cnt=1;	
										}
										
										
									}
					if(cnt==1)
					{
						alert("Please Enter value for Tax");
					}
					else
					{*/
						ProductgridForm.getForm().submit({
						waitMsg: 'Saving...',	
						/*params:{
								taxid: Ext.util.JSON.encode(taxids),
								taxamount: Ext.util.JSON.encode(taxamount)
							},
*/						success: function () {
										
								  Ext.MessageBox.show({
										   title: 'Message',
										   msg: 'Data has been saved',
										   buttons: Ext.MessageBox.OK,
										   icon:Ext.MessageBox.INFO
										  });	
										productstore.load();
										ProductgridForm.getForm().reset();
										//Taxgrid.store.removeAll();
										prodgrid.getSelectionModel().clearSelections();
										prodgrid.removeButton.disable();
										pictUploadForm.getForm().load({ 
											 params:{ act:'getPicture',id:1} 
											 
										  });
							
												 							    							 
						},
						failure: function () {		
							Ext.MessageBox.show({
										   title: 'Error',
										   msg: 'Please fill complete form.',
										   buttons: Ext.MessageBox.OK,
										   icon:Ext.MessageBox.ERROR
										  });
						}
					});
						
					//}
				}
          	},
			{
		    	text: 'Reset',
				iconCls: 'icon-reset',
				tabIndex:13,
				handler: function () {
						ProductgridForm.getForm().reset();
					//	Taxgrid.store.removeAll();
						prodgrid.getSelectionModel().clearSelections();
						prodgrid.removeButton.disable();
						pictUploadForm.getForm().load({ 
						  	 params:{ act:'getPicture',id:1}
						   });

						
				}	
        	},
			{
            	text: 'Close',
				iconCls: 'icon-close',
				tabIndex:14,
				handler: function(){
					ProductWindow.hide();
					
					
				}
        	}
		]
			     
        }]
    };
 var ProductgridForm = new Ext.FormPanel({
        id: 'ProductgridForm',
        frame: true,
		url:'save-product.php',
        bodyStyle:'padding:5px',
        layout: 'column', 
        items: [{
            columnWidth: 0.3,
            layout: 'fit',
            items:[prodgrid]
        },{
            columnWidth: 0.7,
            xtype: 'fieldset',
			defaults: {border:false},
            autoHeight: true,
			bodyStyle: Ext.isIE ? 'padding:0 0 5px 15px;' : 'padding:0px 0px;',
            items: [tabCfg]}
        ]
    });
	
 prodgrid.on('render', function() {
   prodgrid.tip = new Ext.ToolTip({
    view: prodgrid.getView(),
    target: prodgrid.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 record.";
     }
    }
   });
  });
  
  ProductgridForm.getForm().findField('product_name').on('blur',function (){
		var productname=ProductgridForm.getForm().findField('product_name').getValue();
		var productid=ProductgridForm.getForm().findField('product_id').getValue();	
		var resbool="";		
		if(productname!="")
		{			
			Ext.Ajax.request({
					  loadMask: true,
					  sync : true,
					  url: 'data/productrepeat-entry.php',
					  params: {productname: productname,productid:productid},
					  success: function(resp) {
						resbool=Ext.decode(resp.responseText).success;	
								if(resbool=='false')
								{
									Ext.MessageBox.show({
									   title: 'Error',
									   msg: 'Product Name already exists!',
									   buttons: Ext.MessageBox.OK,
									   icon:Ext.MessageBox.ERROR
									});
								
									ProductgridForm.getForm().findField('product_name').reset();											
									Ext.getCmp('product_name').focus('', 10);
									}
										
					  }				
					});		
		}

	});	 
 
 	var ProductWindow = new Ext.Window({
        title: 'Product Information',
		width:1000,		
		height:550,	
        frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'hide',
		
		collapsible:true,
		items: ProductgridForm
		

	});
	
	
	var varWidth =  (screen.width - ProductWindow.width)/5;
	ProductWindow.setPosition(varWidth,((screen.height/4)-110));
	
	Ext.getCmp('product_name').focus(true,500);
