function draw_allot_grid()
{
	function check_render(v, p, record, rowIndex, colIndex, store)
	{
		var checkState = (v) ? '-on' : '';
		p.css += ' x-grid3-check-col-td'; 
		return '<div class="x-grid3-check-col'+ checkState +' x-grid3-cc-'+this.id+'"> </div>';
	}
	function majo_render(v, p, record, rowIndex, colIndex, store)
	{
		return (v==''?'n/a':v+'%')
	}
	function option_render(v, p, record, rowIndex, colIndex, store)
	{
		return (v==''?'n/a':v+'j')
	}
	var cm;
	var ds;
	var grid;
	var getGrid;
	Ext.Ajax.request({
		url:'admin/php/commercialisateurs.php',
		params:{
			xaction:'read'
		},
		success:function(data){
			var expander = new Ext.ux.grid.RowExpander({
				tpl              : '<div class="ux-row-expander-box"></div>',
				actAsTree        : true,
				treeLeafProperty : 'is_leaf',
				listeners        : {
					expand : function( expander, record, body, rowIndex) {
						getGrid( record.id, Ext.get( grid.getView().getRow( rowIndex)).child( '.ux-row-expander-box'));
						//alert( Ext.ComponentMgr.all.length);
					}
				}
			});
			
			var cm_conf=[
				expander,
				{header:'Projet',width:230,dataIndex: 'pnom'}
				];
			var ncm_conf=[
				{header:'Lot',width:229,dataIndex: 'num_lot',editable:false}
				];
			var ds_conf=[
				{name:'pnom',type:'string'},
				{name:'pid',type:'int'}];
			var nds_conf=[
				{name:'num_lot',type:'string'},
				{name:'id',type:'int'}];
			var header_conf=[{header:' ',colspan:2}];
			var response=Ext.util.JSON.decode(data.responseText);
			if(response.commercialisateurs!=undefined)
				var width=(800-280)/(2*response.commercialisateurs.length);
			if (width<50) width=50;
			var fm = Ext.form;
			var ccolor=["#ddd","#eee"];
			var checkList=new Array;
			if(response.commercialisateurs!=undefined)
			for(var i=0;i<response.commercialisateurs.length;i++){
		//		var css="background-color:"+ccolor[i%2]+";";
				var css="";
				var comm=response.commercialisateurs[i];
				cm_conf.push({header:'Commission',width:width,dataIndex:'commission-'+comm.id,align:"center",editor:new fm.TextField(),renderer:majo_render,css:css});
				ds_conf.push({name:'commission-'+comm.id,type:'string'});
				cm_conf.push({header:'Option',width:width,dataIndex:'option_len-'+comm.id,align:"center",editor:new fm.TextField(),renderer:option_render,css:css});
				ds_conf.push({name:'option_len-'+comm.id,type:'string'});
				header_conf.push({header:comm.pnom, colspan: 2, align: 'center'})
				checkList.push(new Ext.grid.CheckColumn({
					header:comm.pnom,width:2*width,dataIndex:'comm_'+comm.id}));
				nds_conf.push({name:'comm_'+comm.id,type:'boolean'});
			}
			ncm_conf=ncm_conf.concat(checkList);
			getGrid=function(id,element){
				var ds=new Ext.data.JsonStore({
					url:'admin/php/ajax.php',
					method: 'GET',
					baseParams:{action: "getAllotGrid", projet_id:id},
					root: 'results',
					totalProperty: 'total',
					idProperty: 'id',
					fields:nds_conf,
					writer: new Ext.data.JsonWriter({
						encode: true,
						// writeAllFields: true 
					})
				});
				ds.load();
				var cm=new Ext.grid.ColumnModel({columns:ncm_conf,defaults:{resizable: false}});
				var grid = new Ext.grid.EditorGridPanel({
					store:ds,
					cm:cm,
					plugins:checkList,
					sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
					viewConfig:{headersDisabled :true},
					stripeRows: true,
					border: false,
					autoHeight: true
				});
				grid.on('render', function() {
					grid.tip = new Ext.ToolTip({
						showDelay : 0,
						view: grid.getView(),
						target: grid.getView().mainBody,
						delegate: '.x-grid3-row',
						trackMouse: true,
						renderTo: document.body,
						listeners: {
							beforeshow: function updateTipBody(tip) {
								var record=tip.view.ds.data.items[tip.view.findRowIndex(tip.triggerElement)];
								tip.body.dom.innerHTML = record.data.num_lot;
							}
						}
					});
				});
				element && grid.render( element);
				var gridHead = grid.getGridEl().child('div[class=x-grid3-header]');
				gridHead.setStyle('display', 'none');
				return grid;

			}
			ds=new Ext.data.JsonStore({
				url:'admin/php/proj_comm_rel.php',
				baseParams:{xaction: "read"},
				root: 'results',
				totalProperty: 'total',
				id: 'pid',
				fields:ds_conf,
				autoLoad: true,
				writer: new Ext.data.JsonWriter({
					encode: true,
					writeAllFields: false // write all fields, not just those that changed
					})
				});
			cm=new Ext.grid.ColumnModel({columns:cm_conf,defaults:{resizable:false}});
		
			grid = new Ext.grid.EditorGridPanel({
				store:ds,
				cm:cm,
				sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
				height:300,
				clicksToEdit: 1,
				viewConfig:{headersDisabled :true},
				enableColumnMove:false,
				plugins: [
					expander, 
					new Ext.ux.plugins.GroupHeaderGrid({
						rows: [header_conf]
					})
				]
			});
			
			var panel=new Ext.Panel(
			{
				title:"Récapitulatif de l'allotement",
				renderTo:'content',
				style:{margin:'auto'},
				width: 'auto',
				items:[
					grid,
					{
						xtype:'fieldset', 
						items:{
							xtype: 'box',
							autoEl: { 
								tag: 'div',
								cls:'aide',
								html: '<img src="admin/images/info_icon.png"/>Accédez au détail des transactions réalisées sur les espaces de vente <b>EVimmo3d</b> et mettez à jour votre systême de gestion de stock.<a href="javascript:video_help(\'saisieVentes\')" style="float:right">Plus d\'aide ici</a>'
							}
						}
					}
				]
			});
		}
	});	
	// recup datastore
	// contruction columnModel
}
