var Commandes ={
	ComFile: function (){return LILIOS_ROOT_HTML+'system/mods/mod_commandes/mod_commandes_com.php';},
//////////////////////////////////////////////////////////////////////////////////////////////////
	startLocalReq	: function(id)	{  	WBID('CreateCommandeTable_row_w_'+id,progress());	},
	stopLocalReq	: function(id)	{  	WBID('CreateCommandeTable_row_w_'+id,'');			},
	startReq		: function ()	{	WBID('complexReq_w_Commandes',progress());		},
	stopReq			: function ()	{ 	WBID('complexReq_w_Commandes','');				},
///////////////////
showCommande: function (id){
	new Ajax.Request( this.ComFile(), { 
							asynchronous:true	, 
							method		:'post'	, 
							parameters	:'action=showCommande&id='+id,
							onSuccess	:function(obj)	{ Commandes.stopLocalReq(id); 	WBID('commandesContent',obj.responseText);	} ,
							onLoading	:function()		{ Commandes.startLocalReq(id); 	} 
						}
		);
},
///////////////// ACTION IN COMMANDES
unscreenRow	: function(obj){ 
	var arr = obj.responseText.split('|');
	RBID( 'CreateCommandeTable_row_'+arr[1])  ;
},
removeCommande : function(id,inTable){ 
		new Ajax.Request( this.ComFile(), { 
							asynchronous:true	, 
							method		:'post'	, 
							parameters	:'action=removeCommande&idCommande='+id,
							onSuccess	:function(obj)	{ 
								//WBID( 'actionRemoveCommande_'+id ,ajaxText(Commandes.ComFile(),'action=lnk2RemoveCommande&id='+id) );
									if (inTable)
										Commandes.unscreenRow(obj);	
									//else
									//WBID( 'updateUserFormActions' ,ajaxText(Mods.ComFile(),'action=getMessage&i=40&type=noe') );
								} ,
							onLoading	:function()		{ WBID( 'actionRemoveCommande_'+id ,progress()); 	} 
						}
		);

},
/////////////////// NEW COMMANDE
newCommandeFormReset	: function(){ 	$id('newCommandeForm').reset(); },
screenNewCommandeForm : function (){
	if(Attachements) // Si l'objet Attachements existe
		Attachements.EmptyList();
	textEditorInit();
	new Ajax.Request( this.ComFile(), { 
				asynchronous:true	, method:'post'	, 
				parameters	:'action=getNewCommandeForm',
				onSuccess	:function(obj)	{  	
					RBID('commandesInfos');
					WBID('commandesContent', obj.responseText);
					
					textEditorManage('newCommandeForm_desc');
				} ,
				onLoading	:function()		{ 	ABID('commandesToolbox','<span id="commandesInfos">'+progress()+'</span>');	}
				
				}
		);		
},
newCommandeFormValidate : function(nbrFile){	
	var title =  $id('newCommandeForm_title').value  ;
	if ( title == '' ){
		WBID('newCommandeForm_title_r',ajaxText(this.ComFile(),'action=getMessage&i=0&type=err'));
	}else{ 
		var title 		= $id('newCommandeForm_title').value;
		var dateOfEnd 	= $id('newCommandeForm_date').value;
		var desc =  $id('newCommandeForm_desc').value  ;
		var desc = escape(textEditorText('newCommandeForm_desc'));
		if(Attachements) // Si l'objet Attachements existe
		var listOfAttachement = Attachements.SetList();
		new Ajax.Request( this.ComFile(), { 
						asynchronous:true	, method:'post'	, 
						parameters	:"action=newCommande&files="+listOfAttachement+"&title="+title+"&desc="+desc+"&dateOfEnd="+dateOfEnd,
						onSuccess	:function(obj)	{  	
							WBID('newCommandeForm_r' ,obj.responseText);
							WBID('newCommandeForm_a' ,ajaxText(Commandes.ComFile(),'action=lnk2ActionAddCommande'));
							DisableEnableForm($id('newCommandeForm'),false);
							$id('newCommandeForm').reset();
							} ,
						onLoading	:function()		{ 	DisableEnableForm($id('newCommandeForm'),true); WBID('newCommandeForm_a' ,progress());	} 
						}
		);		

	}
},
screenUpdateCommande: function(idCommande){ 
	textEditorInit();
	new Ajax.Request( this.ComFile(), { 
				asynchronous:true	, method:'post'	, 
				parameters	:'action=getUpdateCommandeForm&idCommande='+idCommande,
				onSuccess	:function(obj)	{  	
					RBID('commandesInfos');
					WBID('commandesContent', obj.responseText);
						if(Attachements) // Si l'objet Attachements existe
							Attachements.InitList();
							
					textEditorManage('updateCommandeForm_desc');
				} ,
				onLoading	:function()		{ 	ABID('commandesToolbox','<span id="commandesInfos">'+progress()+'</span>');	}
				
				}
		);		
},
updateCommandeFormValidate : function(idCommande){	
		var dateOfEnd 	= $id('updateCommandeForm_date').value;
		var desc =  $id('updateCommandeForm').value  ;
		var desc = escape(textEditorText('updateCommandeForm_desc'));
		if(Attachements) // Si l'objet Attachements existe
		var listOfAttachement = Attachements.SetList();
		new Ajax.Request( this.ComFile(), { 
						asynchronous:true	, method:'post'	, 
						parameters	:"action=updateCommande&idCommande="+idCommande+"&files="+listOfAttachement+"&desc="+desc+"&dateOfEnd="+dateOfEnd,
						onSuccess	:function(obj)	{
							DisableEnableForm($id('updateCommandeForm'),false);
							WBID('updateCommandeForm_r' ,obj.responseText);
							WBID('updateCommandeForm_a' ,ajaxText(Commandes.ComFile(),'action=lnk2ActionAddCommande'));
							} ,
						onLoading	:function()		{ 	
							DisableEnableForm($id('updateCommandeForm'),true); 
							WBID('updateCommandeForm_a' ,progress());	
						} 
						}
		);		

},
////////////////////COMPOSITE REQ
screenCommandesTable: function(){ 
		params = 'action=screenCommandesTable';
		new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
								parameters	: params ,
								onSuccess	:function(obj)	{	RBID('commandesInfos','');WBID('commandesContent',obj.responseText);} ,
								onLoading	:function()		{	ABID('commandesToolbox','<span id="commandesInfos">'+progress()+'</span>'); } 
							}
			);
},


	screenCompositeReq: function (obj){
		WBID('commandesContent',obj.responseText);
		this.stopReq();
	},
	filterDirect: function (col,val,str_where){
		this.startReq();
		params = "action=reqFilterDirect&col="+col+"&val="+val+"&str_where="+str_where;
		new Ajax.Request( this.ComFile(), {asynchronous: true, method: 'post', parameters: params , onSuccess:this.screenCompositeReq});
	},
	filterIndirect: function (col,val,str_where){
		this.startReq();
		params = "action=reqFilterDirect&col="+col+"&val="+val+"&str_where="+str_where;
		new Ajax.Request(  this.ComFile(), {asynchronous: true, method: 'post', parameters: params , onSuccess:this.screenCompositeReq});
	},
	setLimit: function (ser_arrayWhere,start,length,order,orderWay){
		this.startReq();
		params = "action=reqSet&ser_arrayWhere="+ser_arrayWhere+"&start="+start+"&length="+length+"&order="+order+"&orderWay="+orderWay;
		new Ajax.Request(  this.ComFile(), {asynchronous: true, method: 'post', parameters: params ,onSuccess:this.screenCompositeReq});
	},
	setLimitByStep: function (way,ser_arrayWhere,start,length,order,orderWay){
		this.startReq();
		if(way=='inc'){start=length+start;}else{start=start-length;}
		params = "action=reqSet&ser_arrayWhere="+ser_arrayWhere+"&start="+start+"&length="+length+"&order="+order+"&orderWay="+orderWay;
		new Ajax.Request(  this.ComFile(), {asynchronous: true, method: 'post', parameters: params , onSuccess:this.screenCompositeReq});		
	},
	setOrder: function (ser_arrayWhere,start,length,order,orderWay){
		this.startReq();
		params = "action=reqSet&ser_arrayWhere="+ser_arrayWhere+"&start="+start+"&length="+length+"&order="+order+"&orderWay="+orderWay;
		new Ajax.Request(  this.ComFile(), {asynchronous: true, method: 'post', parameters: params , onSuccess:this.screenCompositeReq});
	}
}