// JavaScript Document

$(document).ready( function(){

$('#trigger_mail').click( 
									   			   			   
			function ()  
			{					
					var page =  '/lab/ajax/_send_mail_user' ; 					
					conteneur =  $(this).parent("*");
					var margin = true;
					if($(this).hasClass('nomargin')) margin=false;
					var fade = true;
					if($(this).hasClass('nofade')) fade=false;
	                cible_message_id =  $(this).attr('cible_message') ;

					info = new Object();
					if( typeof($(this).attr('action'))  == 'undefined' ) { var action = 'key' } else { var action =  $(this).attr('action') ; } 
					info.trigger = action ;
					info.complement = 'id';
					
					if(cible_message_id == 'tag_send_id'){info.complement = 'retrieve_id';}
					  
					if(   typeof($(this).attr('action')) != 'undefined' ) { info.trigger = $(this).attr('action') ;}
					if(  (typeof($(this).attr('alt')) != 'undefined') && (  $(this).attr('alt') != ''   )  ) { info.trigger = $(this).attr('alt') ;}
					
						   
					$.post(   page , info ,
					
					function(response)  
					{ 		  
					if(response.statut == true)
					{																													
					switch(info.trigger)
					{
					case  'key':
					var message_confirm = "Un nouveau lien de validation vous a été envoyé à <span class='fuschia_text bold'>" + response.email + "</span>.<br/> Merci de vérifier votre boîte mail." ;																		
					break;
					
					case 'id':
					var message_confirm = "Vos identifiants ont été envoyés à <span class='fuschia_text'>" + response.email + "</span>.<br/> Merci de vérifiez votre boîte mail." ;
					
					if(cible_message_id == 'tag_send_id') // appel dans identifiant.php,=> message plus long
					{
					 var message_confirm = "Un email contenant vos identifiants a été envoyé à <span class='pink1 bold'>" + response.email + "</span>.<br/> Merci de vérifiez votre boîte mail." ;
					}
					
					break ;
					}
					

					if(typeof(cible_message_id) == 'undefined') 
					{
					cible_message = conteneur ;
					} else {
					cible_message = $('#' +cible_message_id) ;
					}
					
					// cible_message.css("opacity",0).html(message_confirm).animate({ opacity: 1 },600) ; 
					cible_message.fadeOut(450 , function(){ 
					$(this).html(message_confirm);
					$(this).fadeIn(550);
					
					
					// alert(cible_message_id);
					
					
					if(cible_message_id == 'tag_send_id') // appel dans identifiant.php,=> message plus long
					{
						if(fade){
							 $("#trigger_mail").fadeOut(400 , function(){$(this).remove(); });
							 if(margin){
								 margin_animate = 370 ;
								 if($.browser.msie == true) {margin_animate = 145}
								 $(this).addClass('back_action_confirm');
								 $(this).delay(400).animate({'margin-right' :margin_animate + 'px' }, 800 );
							 } //else console.log($('#identifiant .col_right .identifiant_wrapper .content_body .div_content #tag_send_id'));
						} else $("#trigger_mail").remove();
					 $("#trigger_mail").unbind('click');
					 
					 
					 
					}

														   });
					
					}		
					
					
					}
					
					, "json"
					
					);

			}	
			
	);

												
							
}); // End Document Ready

