function envoiePage()
{
	
  $(document).ready(function() { 
	  	
        $.blockUI({ message: $('#question'), css: { width: '737px',height: '450px' } }); 
 
        $('#no').click(function() {           
            $.unblockUI(); 
            return false;  
            }); 

    }); 	
}

function sendFormEnvoiePage()
{    
    msg = "";	
    
    var verif1 	= /^([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4})$/;
    var verif2 	= /^([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4})$/;
    
    var SendMail = document.getElementById("formSendMail").value;
    var MailDest = document.getElementById("formSendMailDest").value;    
    
	if(document.getElementById("formSendName").value == "")
	{
		msg += "- Votre nom est obligatoire\n";
	}
	
	if(document.getElementById("formSendFirstName").value == "")
	{
		msg += "- Votre prénom est obligatoire\n";
	}
	
	if(document.getElementById("formSendMail").value == "")
	{
		msg += "- Votre adresse mail est obligatoire\n";
	}
	else if(verif1.exec(SendMail) == null) msg += "- Votre adresse mail est incorrecte\n";

	if(document.getElementById("formSendMailDest").value == "")
	{
		msg += "- L'email du destinataire est obligatoire\n";
	}
	else if(verif2.exec(MailDest) == null) msg += "- L'email du destinataire mail est incorrecte\n";
		
	if(msg!="") alert(msg);			
	else  document.getElementById("formSend").submit();

}

function sendFormContact()
{    
    msg = "";	
    
    var verif1 	= /^([a-zA-Z0-9]+(([\.\-\_]?[a-zA-Z0-9]+)+)?)\@(([a-zA-Z0-9]+[\.\-\_])+[a-zA-Z]{2,4})$/;
    
    var SendMail = document.getElementById("formContactEmail").value;
    
	if(document.getElementById("formContactName").value == "")
	{
		msg += "- Votre nom est obligatoire\n";
	}
	
	if(document.getElementById("formContactSurname").value == "")
	{
		msg += "- Votre prénom est obligatoire\n";
	}
	
	if(document.getElementById("formContactEmail").value == "")
	{
		msg += "- Votre adresse mail est obligatoire\n";
	}
	else if(verif1.exec(SendMail) == null) msg += "- Votre adresse mail est incorrecte\n";

	if(document.getElementById("formContactTel").value == "")
	{
		msg += "- Votre téléphone est obligatoire\n";
	}
	if(document.getElementById("formContactTxt").value == "")
	{
		msg += "- Votre message est obligatoire\n";
	}

	if(msg!="") alert(msg);			
	else document.forms['formContact'].submit();	//envoie mail +callBack
}


/*function informer les Utilisateurs*/

var messageTexts = {
					"showLinks":"Les liens coch&eacute;s seront affich&eacute;s sur votre page d'accueil.",
					"messageSent":"Le message a bien &eacute;t&eacute; envoy&eacute;",
					"friendAdded":"Votre demande a bien &eacute;t&eacute; transmise &agrave;"
					};

function showMessage(msgType,friendName)
{
	var friendName = friendName || null;
	
	if($('#messageText'))
	{
		var messageText = messageTexts[msgType];
		if(friendName != null)
		{
			messageText = messageText+" "+"<b>"+friendName+".</b>";		
		}
			
		$('#messageText').html(messageText);
		$('#messageContainer').show();
		var hide = function(){	
		
			$('#messageContainer').fadeOut('slow');	
		};
		setTimeout(hide,3000);
	}
}




/*fonction genérique*/

function flashMessage(parentID,messageCntId,msg,secTime)
{
	if($("#"+parentID) && $("#"+messageCntId) && msg !="")
	{
		$("#"+messageCntId).html(msg);	
		$("#"+parentID).show();
		var hide = function(){
			$("#"+parentID).fadeOut('slow');		
		};
		var hTime = secTime||3000;
		setTimeout(hide,hTime);
	}
}






function closeBlockUI()
{
	$.unblockUI();   
}

function trim(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
} 
Array.prototype.unique = function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j])
          j = ++i;
      }
      a.push(this[i]);
    }
    return a;
  };

/*effacer Message*/
	function effacerMessage(type)
	{
		var message= "Etes-vous s&ucirc;r de vouloir supprimer ce(s) message(s).";
		var selectedMessages = $("input:checked");
		if(selectedMessages.length==0) return;
		confirmMessage(message,function(){delMessages(type);});	
	}
	
	function confirmMessage(message,callback)
	{
		
		$('#popup').html(message);
				$('#popup').dialog({
					title: 'Confirmation :',
					bgiframe: true,
					modal: true,
					buttons: {
						Annuler: function() {confirm = 1; $('#popup').dialog("destroy");},
						Ok: function() {callback();$('#popup').dialog("destroy");}
						 
					}
				});					
				$('#popup').dialog('open');
	}	
		
		
		
	function delMessages(type)
	{
		if(!type) return false;
		var selectedMessages = $("input:checked");
		
		var params = jQuery.param(selectedMessages);
		$.post(window.PATH_SITE+'ajax/deleteMessages.php', params+'&idAvocat='+window.idAvocat+'&delType='+type,
			function success(data){		
				//console.log(data);
				window.location.reload();		
			}
		
		);	
	}

/*Chargement de FCK pour la messagerie*/
	function loadFCK(id,width,height)
	{
			var basePath = 'http://'+document.domain;
			var oFCKeditor = new FCKeditor(id) ;
			oFCKeditor.ToolbarSet = "message";
			if(height=="")
					height="200px";
				if(width=="")
					width="50%";
			oFCKeditor.Height = height;
			oFCKeditor.Width = width;
			oFCKeditor.BasePath = basePath+"/fckeditor/";
			oFCKeditor.ReplaceTextarea();
			//$('div_'+id).style.display='none';
			//$(state).value = 'enabled';
		
	}

var destinataire = {

	findContacts: function(){
			if(this.checkRequest()) return;
			var data = $('#findContactForm').serializeArray();
			$("#loading").html("Chargement...");
			var dest = $.ajax({
		   	 type: 'post',
		   	 url: PATH_SITE+'ajax/findFriends.php',
		   	 data: data,
			  //async :true,
			 success: function(data){			 
			 	$("#loading").html('');
			 $("#friendsResultContainer").html(data);
			 }
		   });			
			return false;	
	},
	
	checkRequest: function(){
		var request = jQuery.trim($("#avocatName").val());
		var result = 0;
		if(request.length <2)
		{ 
			flashMessage('alertContainer','messageContainer','Deux caractères minimum.');	
			result = 1;
		}
		return result;	
	}	
	
}
function cancelMail()
{
	window.history.back();
}
function disableBtns()
{		
	$("#btnOk").unbind('click',validateFormMessage)
	$("#btnCancel").unbind('click',cancelMail)
	$("#btnOk").removeClass('btnSquarePink').addClass('btnSquareOff');
	$("#btnCancel").removeClass('btnSquarePink').addClass('btnSquareOff');		
}
function enableBtns()
{
	$("#btnOk").bind('click',validateFormMessage)
	$("#btnCancel").bind('click',cancelMail)
	$("#btnOk").removeClass('btnSquareOff').addClass('btnSquarePink');
	$("#btnCancel").removeClass('btnSquareOff').addClass('btnSquarePink');	
}
function addNewMessage(messageData)
{
 		var html = '<tr>';
  		
  		if(messageData.pic!=0)
  			html += '<td><img border="0" alt="'+messageData.dest+'" src="/getFile.php?ID='+messageData.pic+'&W=50&H=75"/></td>';
		else
		{
			if(messageData.gender==1)
				html += '<td><img alt="" src="http://recette.avocats92.com/img/dir_pix_gen_male01.gif"/></td>';
			else
				html += '<td><img alt="" src="http://recette.avocats92.com/img/dir_pix_gen_female01.gif"/></td>';
					
		}		
		if(messageData.MediaID !=0)
			html += '<td class="messageDataListTableColAttachmnt"><a title="Télécharger la(les) pièce(s) jointe(s)" href="/getAttachment.php?ID='+messageData.MediaID+'"><span>Pièce(s) jointe(s)</span></a></td>';
		else
			html += '<td class="messageDataListTableColAttachmnt"></td>';										
		if(messageData.important ==1)
			html += '<td class="messageDataListTableColFlag"><div title="Drapeau : important"><span>Drapeau : important</span></div></td>';
		else
			html += '<td class="messageDataListTableColFlag"></td>';
		html += '<td>'+messageData.date+'</td>';
		html += '<td>'+messageData.dest+'</td>';
		html += '<td class="messageDataListTableColTxt"><p><strong>'+messageData.objet+'</strong></p>'+messageData.texte+'</td></tr>';
		
		$("#messageBoardFrame tbody").append(html);		
}

lexBaseManager = {
	
	links : {
		'EF':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=6&Portail=NANTER', //edition fiscale
		'PG':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=7&Portail=NANTER',
		'EPUB':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=8&Portail=NANTER',
		'EPROF':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=34&Portail=NANTER',
		'LET_JUR':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=12&Portail=NANTER',
		'VE_JUR':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=11&Portail=NANTER',
		'ESOC':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=5&Portail=NANTER',
		
		'JUR':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=1&Portail=NANTER',
		'IND_TAUX':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=3&Portail=NANTER',
		'MOD_FORM':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=4&Portail=NANTER',
		'CONV_COL':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=2&Portail=NANTER',
		'CODE':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=9&Portail=NANTER',
		'LOIS':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=10&Portail=NANTER',	
		'CASS':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=13&Portail=NANTER',
		'CONS_ETAT':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=14&Portail=NANTER',		
		'COM_ARR':'http://lexbase.matoque92.com/lexbase/lbChIdentificationChannel.html?Entree=15&Portail=NANTER'
		},
	popupParam : 'toolbar=1, location=0, directories=0, status=0, scrollbars=1, resizable=1, copyhistory=0, menuBar=0, width=820, height=600',
	
	showLexBasePage : function(key,link){
		if(key=="" ||key=="undefined" ||key==null)
		 {
		 	
		 	if(link !="undefined") var url = link;
		 	else return false;
		 
		 }else
		 {
		 	var url  = this.links[key];		 
		 }
			window.open(url,'',this.popupParam);
		},
		
		manageLxLien : function(){
		$('.lxblien').bind('click',{self:this},function(e){
			e.preventDefault();
			var link = $(this).parent().get(0).href;			
			e.data.self.showLexBasePage(null,link);		
			return false;
		});		
		}
	


};

var groupe = {
	validateForm: function() {
		var valid_extension = ['.jpg','.jpeg','.jpe','.png','.gif'];
		eval('var reg_extensions = /(' + valid_extension.join("|") + ')$/i;');
	
		msg ="";
		
		if(jQuery.trim($('#nom').val()) == "") 	msg += "- Le champ nom est obligatoire.<br><br>";	
		if(jQuery.trim($('#description').val()) == "") msg += "- Le champ description est obligatoire.<br><br>";
		if(jQuery.trim($('#type option:selected').val()) == "") 	msg += "- Le champ type de groupe est obligatoire.<br><br>";
		if((jQuery.trim($('#avPic').val()) != "") && (!reg_extensions.test(jQuery.trim($('#avPic').val()))) && $('#newMediaFlag').val()=='1') {
			 	msg += "- L'extension du fichier image ne fait pas partie des valeurs autorisées (" + valid_extension.join(', ') + ").<br><br>";
		}
		
		if(msg!="") 
		{   
			$('#popup').html(msg);
			$('#popup').dialog({
				title: 'Erreur sur les informations<br>suivantes :',
				bgiframe: true,
				modal: true,
				resizable: false,
				buttons: {
					Ok: function() {
						$(this).dialog('destroy');
					}
				}
			});	
			
			$('#popup').dialog('open');
			
			return false;
		}
		else return true;
	},	
	
	updateMedia: function() {
		$('#newMediaFlag').val('1');
		$("#newMedia").css("display","block");
		$("#updateMedia").css("display","none");	
		$("#loadMedia").css("display","block");
		$("#deleteMedia").css("display","none");
	},
	
	loadMedia: function(mediaID) {
		$('#avPic').val('');
		$('#newMediaFlag').val('0');
		$("#newMedia").css("display","none");
		$("#updateMedia").css("display","block");	
		$("#loadMedia").css("display","none");
		$("#deleteMedia").css("display","none");
		$("input[name='MediaID']").val(mediaID);
	},
	
	deleteMedia: function() {
		$('#avPic').val('');
		$('#newMediaFlag').val('0');
		$("#newMedia").css("display","none");
		$("#updateMedia").css("display","none");	
		$("#loadMedia").css("display","none");
		$("#deleteMedia").css("display","block");
		$("input[name='MediaID']").val('');
	},

	rejoindre: function(GroupeID) {
		$('#popup').html("<br />Souhaitez-vous rejoindre ce groupe ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeRejoindre.php',
					   	 data: {GroupeID: GroupeID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
											location.reload(); 
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
								location.reload(); 
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	pas_rejoindre: function(GroupeID) {
		$('#popup').html("<br />Vous ne souhaitez pas rejoindre ce groupe ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeQuitter.php',
					   	 data: {GroupeID: GroupeID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
											location.reload(); 
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
								location.reload(); 
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	quitter: function(GroupeID) {
		$('#popup').html("<br />Souhaitez-vous quitter ce groupe ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeQuitter.php',
					   	 data: {GroupeID: GroupeID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
											location.reload(); 
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
								location.reload(); 
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	supprimer: function(GroupeID) {
		$('#popup').html("<br />Souhaitez-vous supprimer ce groupe ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeSupprimer.php',
					   	 data: {GroupeID: GroupeID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
											location.reload(); 
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
								location.reload(); 
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	inviter: function(GroupeID) {
		if($("#popupAmis").length==0)
			$("body").prepend('<div id="popupAmis"></div>');
		
		$("#doSearch").live('click',function(){groupe.findContacts(GroupeID);});
		
		$('#popupAmis').html($.ajax({
		   	 type: 'post',
		   	 url: PATH_SITE+'ajax/searchFriends.php',
		   	 data: "AvocatID=0",   	 	 
			 async :false
		}).responseText);
		
		$("#popupAmis").bind('keypress', {GroupeID: GroupeID}, groupe.handleEnter);
		$("#popupAmis").css("color","black");
		$('#popupAmis').dialog({
			title: "Inviter des personnes à rejoindre ce groupe",
			bgiframe: true,
			modal: true,
			resizable: false,
			width: 530,
			height: 530,			
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{	
					var dataIDs = [];
					jQuery.each($("#formAddAmisGroupe").serializeArray(),function(i,val){
						dataIDs.push(parseInt(val.value, 10));	 	
				 	});
					
					var popup = $(this);
					
					if (dataIDs.length>0) {
						$('#popup').html("<br />Souhaitez-vous valider votre sélection ?");
						$('#popup').dialog({
							title: 'Confirmation :',
							bgiframe: true,
							modal: true,
							resizable: false,
							buttons: {
								Annuler: function(){$(this).dialog('destroy');},
								Valider: function()
								{
									$(this).dialog('destroy');
									popup.dialog('destroy');
									$.ajax({
									   	 type: 'post',
									   	 url: PATH_SITE+'ajax/groupeInviter.php',
									   	 data: {GroupeID: GroupeID, 'AvocatIDs[]': dataIDs},
									   	 dataType: 'json',
										 async :false,
										 success: function(result) {
									   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
									   		
									   		$('#popup_alerte').dialog({
									   			title: ((!result.result)? 'Erreur :' : 'Confirmation :'),
												bgiframe: true,
												modal: true,
												resizable: false,
												buttons: {
													OK: function(){
									   					$(this).dialog('destroy');
									   				}
									   			}
									   		});
										}
									});
								}
							}
						});		
						$('#popup').dialog('open'); 
					}
				}
			}
		});		
		$('#popupAmis').dialog('open'); 
	},
	
	findContacts: function(GroupeID){
		if(this.checkRequest()) return;
		var data = {GroupeID: GroupeID, request: $("#avocatName").val()};
		$("#popupAmis #loading").html("Chargement...");
		var dest = $.ajax({
	   	 type: 'post',
	   	 url: PATH_SITE+'ajax/groupeMurFindFriends.php',
	   	 data: data,
		 success: function(data){			 
		 	$("#popupAmis #loading").html('');
		 	$("#popupAmis #friendsResultContainer").html(data);
		 }
	   });			
		return false;	
	},
	
	checkRequest: function(){
		var request = jQuery.trim($("#avocatName").val());
		var result = 0;
		if(request.length <2)
		{ 
			flashMessage('alertContainer','messageContainer','Deux caractères minimum.');	
			result = 1;
		}
		return result;	
	},
	
	handleEnter: function(e) {
		 if(e.keyCode==13){
			 e.preventDefault();
			 groupe.findContacts(e.data.GroupeID);
		}
	},

	membres: function(GroupeID) {
		if($("#popupMembres").length==0)
			$("body").prepend('<div id="popupMembres"></div>');
		
		var data = {GroupeID: GroupeID};
		$('#popupMembres').html($.ajax({
		   	 type: 'post',
		   	 url: PATH_SITE+'ajax/groupeGetMembers.php',
		   	 data: data,			   	 	 
			 async :false
		}).responseText);
		
		this.swapMembresTab(GroupeID, 'membre');
		
		$("#popupMembres").css("color","black");
		$('#popupMembres').dialog({
			bgiframe: true,
			modal: true,
			resizable: false,
			width: 600,
			height: 580,			
			buttons: {
				Fermer: function(){$(this).dialog('destroy');}
			}
		});		
		$('#popupMembres').dialog('open'); 
	},
	
	swapMembresTab: function(GroupeID, type) {
		var loadFrame;
		
		loadFrame=false;
		switch(type) {
			case 'membre':
				if (!$('#popinGuestMembreBtn').hasClass('wallOfFaceTabsBtnOn')) {
					$('#popinGuestMembreBtn').attr('class', 'wallOfFaceTabsBtnOn');
					$('#popinGuestInviteBtn').attr('class', '');
					$('#popinGuestPostulantBtn').attr('class', '');
				}
				loadFrame=true;
				
				break;
			
			case 'invite':
				if (!$('#popinGuestInviteBtn').hasClass('wallOfFaceTabsBtnOn')) {
					$('#popinGuestMembreBtn').attr('class', '');
					$('#popinGuestInviteBtn').attr('class', 'wallOfFaceTabsBtnOn');
					$('#popinGuestPostulantBtn').attr('class', '');
				}
				loadFrame=true;
				
				break;
				
			case 'postulant':
				if (!$('#popinGuestPostulantBtn').hasClass('wallOfFaceTabsBtnOn')) {
					$('#popinGuestMembreBtn').attr('class', '');
					$('#popinGuestInviteBtn').attr('class', '');
					$('#popinGuestPostulantBtn').attr('class', 'wallOfFaceTabsBtnOn');
				}
				loadFrame=true;
				
				break;
		}
		
		if (loadFrame) {
			$("#popupMembres #popinGuestBodyStatus").html("Chargement...");
			$("#popupMembres #popinGuestMembres").html('');
			var data = {GroupeID: GroupeID, type: type};
			var dest = $.ajax({
			   	 type: 'post',
			   	 url: PATH_SITE+'ajax/groupeGetMembers.php',
			   	 data: data,
			   	 dataType: 'json',
				 success: function(result){
					if (!result.result) {
						$("#popupMembres #popinGuestBodyStatus").html('');
					 	$("#popupMembres #popinGuestMembres").html('');
					 	
				   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
				   		$('#popup_alerte').dialog({
				   			title: 'Erreur :',
							bgiframe: true,
							modal: true,
							resizable: false,
							buttons: {
								OK: function(){
				   					$(this).dialog('destroy');
				   				}
				   			}
				   		});
			   		} else {
			   			$("#popupMembres #popinGuestBodyStatus").html(result.message);
					 	$("#popupMembres #popinGuestMembres").html(result.membres);
			   		}
				 }
		   });
		}
	},
	
	membresRevoquer: function(GroupeID, MembreID) {
		var thisGroupe = this;
		
		$('#popup').html("<br />Souhaitez-vous supprimer ce membre ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeRevoquer.php',
					   	 data: {GroupeID: GroupeID, MembreID: MembreID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
						   					this.swapMembresTab(GroupeID, 'membre');
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
					   			thisGroupe.swapMembresTab(GroupeID, 'membre');
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	membresAccepter: function(GroupeID, MembreID) {
		var thisGroupe = this;
		
		$('#popup').html("<br />Souhaitez-vous valider cette inscription ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeAccepter.php',
					   	 data: {GroupeID: GroupeID, MembreID: MembreID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
					   		
					   		$('#popup_alerte').dialog({
					   			title: ((!result.result)? 'Erreur :' : 'Confirmation :'),
								bgiframe: true,
								modal: true,
								resizable: false,
								buttons: {
									OK: function(){
					   					popup.dialog('destroy');
					   					$(this).dialog('destroy');
					   					thisGroupe.swapMembresTab(GroupeID, 'postulant');
					   				}
					   			}
					   		});
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	membresRefuser: function(GroupeID, MembreID) {
		var thisGroupe = this;
		
		$('#popup').html("<br />Souhaitez-vous refuser cette inscription ?");
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeRefuser.php',
					   	 data: {GroupeID: GroupeID, MembreID: MembreID},
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
					   		
					   		$('#popup_alerte').dialog({
					   			title: ((!result.result)? 'Erreur :' : 'Confirmation :'),
								bgiframe: true,
								modal: true,
								resizable: false,
								buttons: {
									OK: function(){
					   					popup.dialog('destroy');
					   					$(this).dialog('destroy');
					   					thisGroupe.swapMembresTab(GroupeID, 'postulant');
					   				}
					   			}
					   		});
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	}
}

var groupemur = {
	swapFrame: function(frameName) {	
		switch(frameName) {
			case 'wallOfFaceMessage':
				if (!$('#wallOfFaceMessageBtn').hasClass('wallOfFaceTabsBtnOn')) {
					$('#wallOfFaceMessageBtn').toggleClass('wallOfFaceTabsBtnOn');
					$('#wallOfFaceInfoBtn').toggleClass('wallOfFaceTabsBtnOn');
				}
				$('#wallOfFaceMessageFrame').show();
				$('#wallOfFaceInfoFrame').hide();
				break;
			
			case 'wallOfFaceInfo':
				if (!$('#wallOfFaceInfoBtn').hasClass('wallOfFaceTabsBtnOn')) {
					$('#wallOfFaceMessageBtn').toggleClass('wallOfFaceTabsBtnOn');
					$('#wallOfFaceInfoBtn').toggleClass('wallOfFaceTabsBtnOn');
				}
				$('#wallOfFaceMessageFrame').hide();
				$('#wallOfFaceInfoFrame').show();
				break;	
		}
	},
	
	getPost: function(GroupeID, GroupeMurID, topicPrefixElID, mainElId, insertDir) {
		$.ajax({
		   	 type: 'post',
		   	 url: PATH_SITE+'ajax/groupeMurGetPost.php',
		   	 data: {
				'GroupeID': GroupeID,
				'GroupeMurID': GroupeMurID
			  },
		   	 dataType: 'json',
			 async :false,
			 success: function(result) {
				  if (!result.result) {
				   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
				   		$('#popup_alerte').dialog({
				   			title: 'Erreur :',
							bgiframe: true,
							modal: true,
							resizable: false,
							buttons: {
								OK: function(){
				   					$(this).dialog('destroy');
				   				}
				   			}
				   		});
			   		} else {
			   			jQuery.each(result.post, function(key, val) {
                            if ($('#' + topicPrefixElID + "_" + key).length == 0) {
                            	if (insertDir=='preprend')
                            		$('#' + mainElId).prepend(val);
                            	else if (insertDir=='append')
                            		$('#' + mainElId).append(val);
                            	else
                            		$('#' + mainElId).append(val);
                            }
                        });
			   			
			   			groupemur.reset();
			   		}
			}
		});
	},
	
	load: function(GroupeID) {
		groupemur.getPost(GroupeID, 0, 'wallOfFaceMessageMainTopic', 'wallOfFaceMessageMain', 'preprend');
	},
	
	reset: function() {
		groupemurpost_MessagePieceJointe.reset('wofMainMessage');
		jQuery.each($('div:visible[id^="wallOfFaceMessageFeedCommentForm_"]'), function() {
			groupemurpost_Commentaire.reset($(this).attr('id'));
		});
	}
}

var groupemurpost_MessagePieceJointe = {
	post: function(elID, GroupeID) {
		if (jQuery.trim($('#' + elID + ' [name="groupemur_message"]').val()).length>0) {
			$('#' + elID + ' :file[name="groupemur_file"]').ajaxFileUpload({
		    		url:PATH_SITE+'ajax/groupeMurPost.php',
		    		data: {
							'type': 'GroupeMurPost_MessagePieceJointe',
							'GroupeID': GroupeID,
							'groupemur_message' : jQuery.trim($('#' + elID + ' [name="groupemur_message"]').val())
					},
		    		dataType: 'json',
		    		success: function(result, status) {
					  if (!result.result) {
					   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
					   		$('#popup_alerte').dialog({
					   			title: 'Erreur :',
								bgiframe: true,
								modal: true,
								resizable: false,
								buttons: {
									OK: function(){
					   					$(this).dialog('destroy');
					   				}
					   			}
					   		});
				   		} else {
				   			groupemur.getPost(GroupeID, 0, 'wallOfFaceMessageMainTopic', 'wallOfFaceMessageMain', 'preprend');
				   		}
		    		}
			});
		}
	},
	
	del: function(GroupeID, GroupeMurID) {
		$("body").prepend('<div id="popup"><br />Souhaitez-vous supprimer ce message ?</div>');
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeMurDelPost.php',
					   	 data: {
									GroupeID: GroupeID,
									GroupeMurID: GroupeMurID
						 },
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
					   			
					   			$('#wallOfFaceMessageMainTopic_' + GroupeMurID).remove();
					   			groupemur.getPost(GroupeID, 0, 'wallOfFaceMessageMainTopic', 'wallOfFaceMessageMain', 'preprend');
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	reset: function(elID) {
		$('#' + elID + ' [name="groupemur_message"]').attr('style', 'color:#999999; height:16px;overflow:hidden;');
		$('#' + elID + ' [name="groupemur_message"]').val('Publier un message sur le mur');
		$('#' + elID + ' :file[name="groupemur_file"]').val('');
		
		$('#' + elID + ' p[id!=""]').hide();
	},
	
	focus: function(elID) {
		if ($('#' + elID + ' #wofMainMessagePostContainer').is(':hidden')) {
			groupemur.reset();
			
			$('#' + elID + ' [name="groupemur_message"]').attr('style', 'color:#000000; height:50px;');
			$('#' + elID + ' [name="groupemur_message"]').val('');
			
			$('#' + elID + ' p[id!=""]').show();
		}
	}
}

var groupemurpost_Commentaire = {
	post: function(elID, GroupeID, GroupeMurID) {
		if (jQuery.trim($('#' + elID + ' [name="groupemur_commentaire"]').val()).length>0) {
			$.ajax({
			   	 type: 'post',
			   	 url: PATH_SITE+'ajax/groupeMurPost.php',
			   	 data: {
						'type': 'GroupeMurPost_Commentaire',
						'GroupeID': GroupeID,
						'GroupeMurID': GroupeMurID,
						'groupemur_commentaire' : jQuery.trim($('#' + elID + ' [name="groupemur_commentaire"]').val())
				 },
			   	 dataType: 'json',
				 async :false,
				 success: function(result) {
					  if (!result.result) {
					   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
					   		$('#popup_alerte').dialog({
					   			title: 'Erreur :',
								bgiframe: true,
								modal: true,
								resizable: false,
								buttons: {
									OK: function(){
					   					$(this).dialog('destroy');
					   				}
					   			}
					   		});
				   		} else {
				   			groupemur.getPost(GroupeID, GroupeMurID, 'wallOfFaceMessageFeedComment', 'wallOfFaceMessageFeedMain_' + GroupeMurID, 'append');
				   		}
				}
			});
		}
	},
	
	del: function(GroupeID, GroupeMurID) {
		$("body").prepend('<div id="popup"><br />Souhaitez-vous supprimer ce commentaire ?</div>');
		$('#popup').dialog({
			title: 'Confirmation :',
			bgiframe: true,
			modal: true,
			resizable: false,
			buttons: {
				Annuler: function(){$(this).dialog('destroy');},
				Valider: function()
				{
					var popup = $(this);
					$.ajax({
					   	 type: 'post',
					   	 url: PATH_SITE+'ajax/groupeMurDelPost.php',
					   	 data: {
									GroupeID: GroupeID,
									GroupeMurID: GroupeMurID
						 },
					   	 dataType: 'json',
						 async :false,
						 success: function(result) {
					   		if (!result.result) { 
						   		$("body").prepend('<div id="popup_alerte">' + result.message + '</div>');
						   		$('#popup_alerte').dialog({
						   			title: 'Erreur :',
									bgiframe: true,
									modal: true,
									resizable: false,
									buttons: {
										OK: function(){
						   					popup.dialog('destroy');
						   					$(this).dialog('destroy');
						   				}
						   			}
						   		});
					   		} else {
					   			popup.dialog('destroy');
					   			
					   			$('#wallOfFaceMessageFeedComment_' + GroupeMurID).remove();
					   			groupemur.getPost(GroupeID, GroupeMurID, 'wallOfFaceMessageFeedComment', 'wallOfFaceMessageFeedMain_' + GroupeMurID, 'append');
					   		}
						}
					});
				}
			}
		});		
		$('#popup').dialog('open'); 
	},
	
	reset: function(elID) {
		$('#' + elID + ' [name="groupemur_commentaire"]').attr('style', 'color:#999999; height:16px;overflow:hidden;');
		$('#' + elID + ' [name="groupemur_commentaire"]').val('Rédiger un commentaire');
		
		$('#' + elID + ' div[class="wallOfFaceMessageFeedCommentImg"]').hide();
		$('#' + elID + ' div[class="wallOfFaceMessageFeedCommentPost"] p:last').hide();
	},
	
	focus: function(elID) {
		if ($('#' + elID + ' div[class="wallOfFaceMessageFeedCommentPost"] p:last').is(':hidden')) {
			groupemur.reset();
			
			$('#' + elID + ' [name="groupemur_commentaire"]').attr('style', 'color:#000000; height:50px;');
			$('#' + elID + ' [name="groupemur_commentaire"]').val('');
			
			$('#' + elID + ' div[class="wallOfFaceMessageFeedCommentImg"]').show();
			$('#' + elID + ' div[class="wallOfFaceMessageFeedCommentPost"] p:last').show();
		}
	}
};