var Mods={
	ComFile: function (){return LILIOS_ROOT_HTML+'system/mods/mod_mods/mod_mods_com.php';},
//////////////////////////////////////////////////////////////////////////////////////////////////
	startLocalReq	: function(id)	{  	WBID('CreateModTable_row_w_'+id,progress());	},
	stopLocalReq	: function(id)	{  	WBID('CreateModTable_row_w_'+id,'');			},
	startReq		: function ()	{	WBID('complexReq_w_Mods',progress());			},
	stopReq			: function ()	{ 	WBID('complexReq_w_Mods','');					},
/////Actions on users
	sendMail	: function(id){ 
		new Ajax.Request( this.ComFile(), { 
									asynchronous:true	, 
									method		:'post'	, 
									parameters	:'action=sendMail&id='+id ,
									onSuccess	:function(obj)	{ WBID( 'actionSendMail_'+id ,ajaxText(Mods.ComFile(),'action=lnk2EmailParam&id='+id) );	} ,
									onLoading	:function()		{ WBID( 'actionSendMail_'+id ,progress()); 	} 
								}
				);
	},
	unscreenRow	: function(obj){ 
		arr=obj.responseText.split('|');
		if(arr[1]=='ok')
		RBID( 'CreateModTable_row_'+arr[2])  ;
		else
		alert(arr[2]);
	},
	removeUser	: function(id,inTable){ 
		new Ajax.Request( this.ComFile(), { 
							asynchronous:true	, 
							method		:'post'	, 
							parameters	:'action=removeUser&id='+id,
							onSuccess	:function(obj)	{ 
								WBID( 'actionRemoveUser_'+id ,ajaxText(Mods.ComFile(),'action=lnk2RemoveUser&id='+id) );
									if (inTable)
										Mods.unscreenRow(obj);	
									else
									WBID( 'updateUserFormActions' ,ajaxText(Mods.ComFile(),'action=getMessage&i=40&type=noe') );
								} ,
							onLoading	:function()		{ WBID( 'actionRemoveUser_'+id ,progress()); 	} 
						}
		);

	},
	ChangeUserStatus	: function(id,newStatus){ 
		params = 'action=changeStatus&id='+id+'&status='+newStatus;
		new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
									parameters	: params ,
									onSuccess	:function(obj)	{ WBID( 'statusImg_w_'+id ,'');WBID( 'statusImg_'+id ,obj.responseText);	} ,
									onLoading	:function()		{ WBID( 'statusImg_w_'+id ,progress());	 	} 
								}
				);
	},
	ChangeUserMod	: function(value,modName,id){ 
		params = 'action=changeUserMod&modName='+modName+'&value='+value+'&idUser='+id;
			new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
								parameters	: params ,
								onSuccess	:function(obj)	{ WBID( 'statusMods_'+modName+'_w_'+id ,'');WBID( 'statusMods_'+modName+'_'+id ,obj.responseText);	} ,
								onLoading	:function()		{ WBID( 'statusMods_'+modName+'_w_'+id ,progress());	 	} 
							}
			);
	},
/////////////UpdateUser
screenUpdateUser	: function(id){ 
	params = 'action=screenUpdateUser&id='+id;
	new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
						   		parameters	: params ,
					   			onSuccess	:function(obj)	{	WBID( 'modsContent' ,obj.responseText);} ,
					   			onLoading	:function()		{	WBID('CreateModTable_row_r_'+id,progress()); 	} 
							}
			);
	},	
updateUserValidate	: function(id){ 	

	var email=$id('updateUserForm_email').value;
	var currentemail=$id('updateUserForm_currentemail').value;
	var username=$id('updateUserForm_username').value;
	var currentusername=$id('updateUserForm_currentusername').value;
	var password=$id('updateUserForm_password').value;
	var currentpassword=$id('updateUserForm_currentpassword').value;
	var rpassword=$id('updateUserForm_rpassword').value;

	if (email==currentemail){
			WBID( 'updateUserForm_email_r' ,ajaxText(Mods.ComFile(),'action=getMessage&i=50&type=inf') );
	}else{
		if(!email.isEmail()){ 
			WBID('updateUserForm_email_r', ajaxText(this.ComFile(),'action=getMessage&i=10&type=err'));
		}else{ 
			params = 'action=emailNotInDb&email='+email;
			var arrayResponse = ajaxText( this.ComFile() , params).split('|') ;
			if (arrayResponse[1] != 'ok' ){
				WBID('updateUserForm_email_r', ajaxText(this.ComFile(),'action=getMessage&i=11&type=err'));
			}else{
				var verif_email = true;
			}
		}
	}
	if (username==currentusername){
			WBID( 'updateUserForm_username_r' ,ajaxText(Mods.ComFile(),'action=getMessage&i=51&type=inf') );
	}else{
		if(!username.isAlphaNum()){ 
			WBID('updateUserForm_username_r', ajaxText(this.ComFile(),'action=getMessage&i=20&type=err'));
		}else{ 
			params = 'action=usernameNotInDb&username='+username;
			var arrayResponse = ajaxText( this.ComFile() , params).split('|') ;
			if (arrayResponse[1] != 'ok' ){
				WBID('updateUserForm_username_r', ajaxText(this.ComFile(),'action=getMessage&i=21&type=err'));
			}else{
				var verif_username = true;
			}
		}
	}
	if (password==currentpassword){
			WBID( 'updateUserForm_passwords_r' ,ajaxText(Mods.ComFile(),'action=getMessage&i=52&type=inf') );
	}else{
		if(!password.isAlphaNum()){ 
				WBID('updateUserForm_passwords_r', ajaxText(this.ComFile(),'action=getMessage&i=30&type=err'));
		}else{ 
			if(password!=rpassword){
				WBID('updateUserForm_passwords_r', ajaxText(this.ComFile(),'action=getMessage&i=31&type=err'));
			}else{
				var verif_passwords = true;
			}
		}
	}


	if ( verif_email ){
		new Ajax.Request( this.ComFile(), { 
							asynchronous:true	, 
							method		:'post'	, 
							parameters	:'action=updateUser&id='+id+'&param=email&value='+email,
							onSuccess	:function(obj)	{ WBID('updateUserForm_email_r', ajaxText(Mods.ComFile(),'action=getMessage&i=53&type=noe'));	} ,
							onLoading	:function()		{ WBID('updateUserForm_email_r', progress()); 	} 
						}
		);
		
	}
	if ( verif_username ){
		new Ajax.Request( this.ComFile(), { 
							asynchronous:true	, 
							method		:'post'	, 
							parameters	:'action=updateUser&id='+id+'&param=username&value='+username,
							onSuccess	:function(obj)	{ WBID('updateUserForm_username_r', ajaxText(Mods.ComFile(),'action=getMessage&i=54&type=noe'));	} ,
							onLoading	:function()		{ WBID('updateUserForm_username_r', progress()); 	} 
						}
		);		
	}
	if ( verif_passwords ){
		new Ajax.Request( this.ComFile(), { 
							asynchronous:true	, 
							method		:'post'	, 
							parameters	:'action=updateUser&id='+id+'&param=password&value='+password,
							onSuccess	:function(obj)	{ WBID('updateUserForm_passwords_r', ajaxText(Mods.ComFile(),'action=getMessage&i=55&type=noe'));	} ,
							onLoading	:function()		{ WBID('updateUserForm_passwords_r', progress()); 	} 
						}
		);
	}
	
	if ( $id('createUserSendMail').checked){var mail='yes';}else{var mail='no';}
	if (mail=='yes' && ( verif_passwords || verif_username || verif_email )   ){
		new Ajax.Request( this.ComFile(), { 
									asynchronous:true	, 
									method		:'post'	, 
									parameters	:'action=sendMail&id='+id ,
									onSuccess	:function()  	{ WBID( 'updateUserForm_w' ,'');	} ,
									onLoading	:function()		{ WBID( 'updateUserForm_w' ,progress()); 	} 
								}
				);
	}
},

/////////////CreateUser	
createUser	: function(prevText){ 
 if (!prevText){ var prevText=''; 	 }

	params = 'action=screenAddUser';
	new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
						   		parameters	: params ,
					   			onSuccess	:function(obj)	{	WBID( 'modsContent' , '<div id="prevCreateUser">'+prevText + '</div>'+ obj.responseText)  ;	RBID('modsInfos');		} ,
					   			onLoading	:function()		{	ABID('modsToolbox','<span id="modsInfos">'+progress()+'</span>'); 	} 
							}
			);
	},	
	

createUserValidate	: function(){ 	
	var email		= $id('addUserForm_email').value;
	var username	= $id('addUserForm_username').value ;
	var password	= $id('addUserForm_password').value;
	var rpassword	= $id('addUserForm_rpassword').value;
	var status 		= $id('AddUserInitStatus').options[$id('AddUserInitStatus').selectedIndex].value;
	if ( $id('createUserSendMail').checked){var mail='yes';}else{var mail='no';}
	RBID('prevCreateUser');
	////////////EMAIL
	if(!email.isEmail()){ 
		WBID('addUserForm_email_r', ajaxText(this.ComFile(),'action=getMessage&i=10&type=err'));
	}else{ 
		params = 'action=emailNotInDb&email='+email;
		var arrayResponse = ajaxText( this.ComFile() , params).split('|') ;
		if (arrayResponse[1] != 'ok' ){
			WBID('addUserForm_email_r', ajaxText(this.ComFile(),'action=getMessage&i=11&type=err'));
		}else{
			var verif_email = true;
			WBID('addUserForm_email_r', ajaxText(this.ComFile(),'action=getMessage&i=12&type=noe'));
		}
	}
	////////////USERNAME
	if(!username.isAlphaNum()){ 
		WBID('addUserForm_username_r', ajaxText(this.ComFile(),'action=getMessage&i=20&type=err'));
	}else{ 
		params = 'action=usernameNotInDb&username='+username;
		var arrayResponse = ajaxText( this.ComFile() , params).split('|') ;
		if (arrayResponse[1] != 'ok' ){
			WBID('addUserForm_username_r', ajaxText(this.ComFile(),'action=getMessage&i=21&type=err'));
		}else{
			var verif_username = true;
			WBID('addUserForm_username_r', ajaxText(this.ComFile(),'action=getMessage&i=22&type=noe'));
		}
	}
	////////////PASSWORDS
	if(!password.isAlphaNum()){ 
			WBID('addUserForm_passwords_r', ajaxText(this.ComFile(),'action=getMessage&i=30&type=err'));
	}else{ 
		if(password!=rpassword){
			WBID('addUserForm_passwords_r', ajaxText(this.ComFile(),'action=getMessage&i=31&type=err'));
		}else{
			var verif_passwords = true;
			WBID('addUserForm_passwords_r', ajaxText(this.ComFile(),'action=getMessage&i=32&type=noe'));
		}
	}
	
	if ( verif_passwords && verif_username && verif_email){
	params = 'action=addUser&email='+email+'&username='+username+'&password='+password+'&status='+status+'&mail='+mail;
		if($id('ActionAfterAddUser_add').checked){ //lancer  createUser()JS
			new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
										parameters	: params ,
										onSuccess	:function(obj)	{	WBID('addUserForm_w','');Mods.createUser(obj.responseText)	; } ,
										onLoading	:function()		{	WBID('addUserForm_w',progress()); 	} 
									}
					);
		}else{
			new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
										parameters	: params ,
										onSuccess	:function(obj)	{	WBID('addUserForm_w','');Mods.screenModsTable()	; } ,
										onLoading	:function()		{	WBID('addUserForm_w',progress()); 	} 
									}
					);
		}
	}
},
/////////////!CreateUser	
	screenModsTable: function(){ 
		params = 'action=screenModsTable';
		new Ajax.Request( this.ComFile(), { asynchronous: true, method: 'post', 
						   		parameters	: params ,
					   			onSuccess	:function(obj)	{	RBID('modsInfos','');WBID('modsContent',obj.responseText);} ,
					   			onLoading	:function()		{	ABID('modsToolbox','<span id="modsInfos">'+progress()+'</span>'); } 
							}
			);
	},
/////////////////CompositeRequest
	screenCompositeReq: function (obj){
		WBID('modsContent',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});
	}	
}