var nbLignes = 2;
var supprIndex = 1;
var nbL = 2;
var nbLp = 2;
function showModification(conn_id,id_relation,id_intime){
	
	var htmlStr = '<div id="title-popup">'+showModification_tx1+'</div>';
    if(id_relation==2){
    	htmlStr+='<div class="field1"><div class="label1">'+Relation_txt+'</div><div class="sel1"><select id="relationSelect" name="relation"><option value="2">'+relation_typ2+'</option><option value="1">'+relation_typ1+'</option></select></div></div>';
    }else {
    	htmlStr+='<div class="field1"><div class="label1">'+Relation_txt+'</div><div class="sel1"><select id="relationSelect" name="relation"><option  value="1">'+relation_typ1+'</option><option value="2">'+relation_typ2+'</option></select></div></div>';
    }
    if(id_intime==0){
    	htmlStr+='<div class="field1"><div class="label1">'+Groupe_txt+'</div><div class="sel1"><select id ="intimiteSelect" name="intimite"><option  value="0">---</option><option value="1">'+relation_typ3+'</option></select></div></div>';
    }else{
    	htmlStr+='<div class="field1"><div class="label1">'+Groupe_txt+'</div><div class="sel1"><select id ="intimiteSelect" name="intimite"><option  value="1">'+relation_typ3+'</option><option  value="0">---</option></select></div></div>';
    }
	jqistates = {
	state0: {
	html: htmlStr,
	focus: 1,
	buttons: {Valider: true,Annuler: false},
	submit: function(v, m, f){
		
		if(v){
			$j("#trieload"+conn_id).show();
			var rel =$j(m).find('#relationSelect').find(':selected').val();
			var intimite=$j(m).find('#intimiteSelect').find(':selected').val();
		    new Ajax.Updater("js-fill",app_path + "connexions/editIntimite/"+conn_id+"/"+intimite+"/"+rel,{method:"post",asynchronous:true,evalScripts:true,onLoading:function(request){$j("#trieload").show();},onComplete:function(request){$j('#trieload'+conn_id).hide()}});	

		}
	}
	}
	};
	
	$j.prompt(jqistates);
}

	
//	parent1 = $j(modifiable).parent();
//	parent = $j(parent1).parent();
//	editable = $j(parent).find(".input-modif");
//	$j(parent1).hide("fast");
//	$j(editable).show("fast");

function updateRelation(conn_id, new_value){
	
	selectedIndex = new_value.options.selectedIndex;
	value  = new_value.options[selectedIndex].value;
	//alert(value);return false;
	new Ajax.Updater("js-fill", app_path + "connexions/editIntimite/"+conn_id+"/"+value, {method:"post", asynchronous:true, evalScripts:true, onComplete:function (request, json) {
		$j(new_value).parent().hide("fast");
		
	}, requestHeaders:["X-Update", "js-fill"]});
}

function deleteConnexion(conn_id){
	//afficher le loader et changer l'opacité de la div associée
	
	jConfirm(deleteConnexion_txt1,deleteConnexion_txt2, function(r) {
		if(r){
			$j("#loader").show("fast");
			$j("#connexion-num-"+conn_id).css({"opacity":"0.6"});
			new Ajax.Updater("js-fill", app_path + "connexions/del/"+conn_id, {method:"post", asynchronous:true, evalScripts:true, onComplete:function (request, json) {
				$j("#loader").hide("fast");
			}, requestHeaders:["X-Update", "js-fill"]});
		}
	});
}


function deleteInvitation(inv_id){
  //afficher le loader et changer l'opacité de la div associée
	
	jConfirm(deleteInvitation_txt1,deleteInvitation_txt2, function(r) {
		if(r){
			$j("#loader").show("fast");
			$j("#invitation-num-"+inv_id).css({"opacity":"0.6"});
			new Ajax.Updater("js-fill", app_path + "invitations/del/"+inv_id, {method:"post", asynchronous:true, evalScripts:true, onComplete:function (request, json) {
				$j("#loader").hide("fast");
			}, requestHeaders:["X-Update", "js-fill"]});
		}
	});
}

function modifetrenvoi(inv_id,mail_label,nom,prenom,relation_id){
	
	var htmlStr ='<div id="title-popup">'+modifetrenvoi_txt1+'</div>';
	    htmlStr+='<form name="renvoinvitation" id="renvoinvitation" action="" method="post" onsubmit="return false;">';
	    htmlStr+='<table>';
	    htmlStr+='<tr>';
	    htmlStr+='<td style="width:120px;padding-left:5px;" class="texte-pragtd vertsombre"><label>'+Prenom_txt+'</label></td>';
	    htmlStr+='<td style="width:120px;padding-left:5px;" class="texte-pragtd vertsombre"><label>'+Nom_txt+'</label></td>';
	    htmlStr+='<td style="width:150px;padding-left:5px;" class="texte-pragtd vertsombre"><label>'+Email_txt+'</label></td>';
	    htmlStr+='<td style="width:95px;padding-left:5px;" class="texte-pragtd vertsombre"><label>'+Relation_txt+'</label></td>';
	    htmlStr+='</tr>';
	    htmlStr+='<tr>';
	    htmlStr+='<td style="width:120px;padding-left:5px;" class="texte-pragtd vertsombre"><input type="hidden" value="'+inv_id+'" name="data[Invitation][id]"/><input  type="text" value="'+prenom+'" name="data[Invitation][person_prenom]" style="width:115px;"/></td>';
	    htmlStr+='<td style="width:120px;padding-left:5px;" class="texte-pragtd vertsombre"><input  type="text" value="'+nom+'"  name="data[Invitation][person_nom]" style="width:115px;"/></td>';
	    htmlStr+='<td style="width:150px;padding-left:5px;" class="texte-pragtd vertsombre"><input disabled type="text" value="'+mail_label+'"  name="data[Invitation][person_mail]" style="width:145px;"/></td>';
	    htmlStr+='<td style="width:95px;padding-left:5px;" class="texte-pragtd vertsombre">';
		
		     if(relation_id==1)
		     { 	 htmlStr+='<select  name="data[Invitation][relation_id]" style="width:90px;">';
		    	 htmlStr+='<option  value="1">'+relation_typ1+'</option>';
		    	 htmlStr+='<option  value="2">'+relation_typ2+'</option>'; 
		    	 htmlStr+='</select>';
		     }else{
		    	 htmlStr+='<select  name="data[Invitation][relation_id]" style="width:90px;">';
		    	 htmlStr+='<option  value="2">'+relation_typ2+'</option>';
		    	 htmlStr+='<option  value="1">'+relation_typ1+'</option>';
		    	 htmlStr+='</select>';
		     }
		
		htmlStr+='</td>';
		htmlStr+='</tr>';
		htmlStr+='</table>';
		htmlStr+='</form>';
	   
		jqistates = {
			state0: {
			html: htmlStr,
			focus: 1,
			buttons: { Renvoyer: true , Annuler: false},
			submit: function(v, m, f){
				
				if(v){
										
					var pars = Form.serialize('renvoinvitation');
					new Ajax.Updater("invitation-num-"+inv_id, app_path +"invitations/renvoyerinvitation", {method:"post",postBody: pars ,asynchronous:true, evalScripts:true, onComplete:function (request, json) {
					}, requestHeaders:["invitation-num-"+inv_id]});
				}
			}
			}
			};
			
			$j.prompt(jqistates);
	
}


function changeopacity(divName, newOpacity){
	$j("#"+divName).css({'opacity': newOpacity });
}


function addLigne(){
	
	if(nbLignes==11){return;}
	
	var str ='<div style="clear:both;float:left;" id="line'+nbLignes+'">';
	str+='<table>';
	str+='<tr>';
	str+='<td style="width:120px;padding-left:5px;" class="texte-pragtd vertsombre"><input  type="text" value="" name="person_prenom'+nbLignes+'" style="width:115px;"/></td>';
	str+='<td style="width:120px;padding-left:5px;" class="texte-pragtd vertsombre"><input  type="text" value="" name="person_nom'+nbLignes+'" style="width:115px;"/></td>';
	str+='<td style="width:150px;padding-left:5px;" class="texte-pragtd vertsombre"><input  type="text" value="" name="person_mail'+nbLignes+'" style="width:145px;"/></td>';
	str+='<td style="width:95px;padding-left:5px;" class="texte-pragtd vertsombre">';
	str+='<select  name="relation_id'+nbLignes+'" style="width:90px;">';
	str+='<option  value="2">'+relation_typ2+'</option>';
	str+='<option  value="1">'+relation_typ1+'</option>';
	str+='</select>';
	str+='</td>';
	str+='</tr>';
	str+='</table>';
	str+='</div>';

	var temp = nbLignes - 1;
	$j("#line"+temp).after(str);
	nbLignes = nbLignes + 1;
    supprIndex ++;
	
}
function suppligneinvitation(){
	
    if(supprIndex!=1){
	$j("#line"+supprIndex).remove();
	supprIndex --;
	nbLignes = supprIndex+1 ;}
}

function acceptInvitation(inv_id,relation){
	
	var htmlStr= '<div id="title-popup">'+acceptInvitation_txt1+'</div>';
	    htmlStr+='<div class="field1"><div class="label1" style="display: none;">'+acceptInvitation_txt2+'</div><div class="sel1" style="padding-left:27px; display:none;"><select id ="intimiteSelect" name="intimite"><option value="0">---</option><option value="1">'+relation_typ3+'</option></select></div></div>';
	    htmlStr+='<div class="field1"><div class="texte-prag vertsombre" >'+acceptInvitation_txt3+'</div><div class="sel2" style="padding-left:10px"><select id="relationSelect" name="relation"><option value="2"';
		if(relation==2||relation==0)
			htmlStr+=' selected = "selected"';
		    htmlStr+= '>'+relation_typ2+'</option><option value="1"';
		if(relation==1){
		htmlStr+= ' selected="selected"';
		}
		htmlStr+='>'+relation_typ1+'</option></select></div></div>';
		htmlStr+='<div style="clear:both;float:left;width:100%;padding-top:15px;"></div>';
	
	jqistates = {
		state0: {
			html: htmlStr,
			focus: 1,
			buttons: { Accepter: true , Annuler: false},
			submit: function(v, m, f){
				
				if(v){
					var intimite = $j(m).find('#intimiteSelect').find(':selected').val();
					var relation = $j(m).find('#relationSelect').find(':selected').val();
					$j("#loader").hide("fast");
					new Ajax.Updater("js-fill", app_path + "connexions/acceptConnection/"+inv_id+"/"+relation+"/"+intimite, {method:"post", asynchronous:true, evalScripts:true, onComplete:function (request, json) {
						$j("#loader").hide("fast");
					}, requestHeaders:["X-Update", "js-fill"]});
				}
			}
		}
	};
	
	$j.prompt(jqistates);
}

function textCounter(field,cntfield,maxlimit) {
	
	//sil depasse le nombre des caractère le champ ne doit pas supporter encore des  caractère
	 if (field.value.length > maxlimit) 
	  field.value = field.value.substring(0, maxlimit);
	// sinon, mise a jour de champ de comptage par le nombre de caractère qui reste
	else
	cntfield.value = maxlimit - field.value.length;
}


var submitForm = false;

function confirmtraduction(){
		jConfirm(confirmtraduction_txt1,confirmtraduction_txt2, function(r) {
			if(r){
				
				submitForm = true;
				document.myform.submit();
				 }
				});
		
}
function confirmsupuser(){
	jConfirm(confirmsupuser_txt1,confirmsupuser_txt2,function(r){
		if(r){
			window.location.replace(app_path+'users/deletecompte');	
			 }		 
			});
}


function addlinelifeperiod(){
	if(nbLp==6){return;}
	var sth =
	
	'<div  id="perline'+nbLp+'" style="clear:both;float:left;">'+
	'<table>'+
	'<tr>'+
	'<td align="left"><label for="yearfrom'+nbLp+'" class="ajouthelp"><?php __("Année naissance : ") ?> </label></td><td align="left"><label for="yearto'+nbLp+'" class="ajouthelp"><?php __("Année de decé : ") ?> </label></td><td align="left"></td>'+
	'</tr>'+
	'<tr>'+
	'<td align="left"><input class="fbinput" type="text" value="" maxlength="50" name="yearfrom'+nbLp+'" /></td><td align="left"><input  class="fbinput" type="text" value="" maxlength="50" name="yearto'+nbLp+'" /></td><td align="left" class="aide-form-link"><a href="javascript:void(0)" onclick="addlinelifeperiod()"><?php __("[+] Ajouter")?></a></td>'+
	'</tr>'+
	'</table>'+
	'</div>';
		
	var nbp = nbLp - 1;
	$j("#perline"+nbp).after(sth);
	nbLp = nbLp + 1;
		
}


function verifiermail(){
	var pars = Form.serialize('InvitationAddForm');
	new Ajax.Updater("verficationmail", app_path + "invitations/verifcodeapresenvoi/", {method:"post",postBody: pars , asynchronous:true, evalScripts:true,  requestHeaders:["verficationmail"]});
	return false;
}

function envoyercode(){
	new Ajax.Updater("verficationmail", app_path + "invitations/envoicode/", {method:"post",asynchronous:true, evalScripts:true,  requestHeaders:["X-Update", "verficationmail"]});	
	return false;
}

function deleteavis(id){
	
		jConfirm(deleteavis_txt1,deleteavis_txt2, function(r) {
			if(r){
				
				new Ajax.Updater("js-fill", app_path + "opinions/delete/"+id, {method:"post", asynchronous:true, evalScripts:true, onComplete:function (request, json) {
				}, requestHeaders:["X-Update", "js-fill"]});
			}
		});
	
}
function deleteEmailUser(id){
	//afficher le loader et changer l'opacité de la div associée
	
	jConfirm(deleteEmailUser_txt1,deleteEmailUser_txt2, function(r) {
		if(r){
			$j("#loader").show("fast");
			$j("#mail-num-"+id).remove();
			new Ajax.Updater("js-fill", app_path + "users/deleteMail/"+id, {method:"post", asynchronous:true, evalScripts:true, onComplete:function (request, json) {
				$j("#loader").hide("fast");
			}, requestHeaders:["X-Update", "js-fill"]});
		}
	});	
}

function submitTranslation(index,origine){
	var id  = document.getElementById("id-"+index).value;
	var text  = document.getElementById("texte-dest-"+index).value;
	var pars = "data[Trans][0][id]="+id+"&data[Trans][0][finaltexte]="+text+"&data[Translation][langue_iddest]="+origine ;
	$j("#loader"+index).show();
	new Ajax.Updater("js-fill", app_path + "languages/insererchamp/", {method:"post", postBody: pars, asynchronous:true, evalScripts:true, onComplete:function (request) {$j("#envoie"+index).show();$j("#loader"+index).hide();}, requestHeaders:["js-fill"]});
}
function validertranslation(index,origine,value){
	var id =document.getElementById("id-"+index).value;
	var pars="data[Translabel][id]="+id+"&data[Translation][langue_dest]="+origine+"&data[Translation][valide]="+value ;
	$j("#loader"+index).show();
	new Ajax.Updater("js-fill", app_path + "languages/validertranslation/",{method:"post", postBody: pars, asynchronous:true, evalScripts:true, onComplete:function (request){$j("#loader"+index).hide();},requestHeaders:["js-fill"]});
}

function changerelationinfeed(connexion_id,intime,relation){
	$j("#modif-en-cours"+connexion_id).show();
    new Ajax.Updater("js-fill", app_path +"feeds/editRelationetintimite/"+connexion_id+"/"+intime+"/"+relation,{method:"post", asynchronous:true,evalScripts:true,requestHeaders:["js-fill"],onComplete:function(request){$j("#modif-en-cours"+connexion_id).hide();}});
    
}

function serializeValues(index){
	var pars = $('connexion-'+index).serialize();
	new Ajax.Updater("js-fill", app_path +"connexions/editRelation",{method:"post", asynchronous:true,evalScripts:true,postBody : pars, requestHeaders:["js-fill"],onComplete:function(request){$j("#modif-en-cours"+connexion_id).hide();}});
	
}
function envoyerinvitsuggest(id,relation_id,nom,prenom){
	   var htmlStr ='<div id="title-popup">'+envoyerinvitsuggest_txt1+'</div>';
	    htmlStr+='<div class="texte-prag vertsombre" style="font-weight:bold;">'+envoyerinvitsuggest_txt2+'  '+prenom+'  '+nom+'  '+envoyerinvitsuggest_txt3+'</div>';
	    htmlStr+='<div class="texte-prag vertsombre" style="font-weight:bold;">'+envoyerinvitsuggest_txt4+'</div>';
	    if(relation_id==2){
	    	htmlStr+='<div class="field1"><div class="sel1" style="padding-left:10px;"><select id="relationSelect" name="relation"><option value="2">'+relation_typ2+'</option><option value="1">'+relation_typ1+'</option></select></div></div>';
	    }else{
	    	htmlStr+='<div class="field1"><div class="sel1" style="padding-left:10px;"><select id="relationSelect" name="relation"><option  value="1">'+relation_typ1+'</option><option value="2">'+relation_typ2+'</option></select></div></div>';
	    }
    htmlStr+='<div class="texte-prag vertsombre">'+prenom+'  '+envoyerinvitsuggest_txt5+'</div>';
    jqistates = {
	state0: {
	html: htmlStr,
	focus: 1,
	buttons: {Envoyer: true,Annuler: false},
	submit: function(v, m, f){
	if(v){
		    $j("#loadinvit").show();
			var rel =$j(m).find('#relationSelect').find(':selected').val();
			var pars = Form.serialize('hiddenunvitationfamily'+id);
			new Ajax.Updater("container-suggest",app_path + "feeds/invitationsuggestion/"+rel, {method:"post",postBody: pars , asynchronous:true, evalScripts:true,requestHeaders:["container-suggest"],onLoading:function(request){},onComplete:function(request){$j("#loadinvit").hide();}});	

		}
	}
	}
	};
	$j.prompt(jqistates);
}

function envoyerinvitfromlastmember(id,relation_id,nom,prenom){
	   var htmlStr ='<div id="title-popup">'+envoyerinvitsuggest_txt1+'</div>';
	    htmlStr+='<div class="texte-prag vertsombre" style="font-weight:bold;">'+envoyerinvitsuggest_txt2+'  '+prenom+'  '+nom+'  '+envoyerinvitsuggest_txt3+'</div>';
	    htmlStr+='<div class="texte-prag vertsombre" style="font-weight:bold;">'+envoyerinvitsuggest_txt4+'</div>';
	    if(relation_id==2){
	    	htmlStr+='<div class="field1"><div class="sel1" style="padding-left:10px;"><select id="relationSelect" name="relation"><option value="2">'+relation_typ2+'</option><option value="1">'+relation_typ1+'</option></select></div></div>';
	    }else{
	    	htmlStr+='<div class="field1"><div class="sel1" style="padding-left:10px;"><select id="relationSelect" name="relation"><option  value="1">'+relation_typ1+'</option><option value="2">'+relation_typ2+'</option></select></div></div>';
	    }
 htmlStr+='<div class="texte-prag vertsombre">'+prenom+'  '+envoyerinvitsuggest_txt5+'</div>';
 jqistates = {
	state0: {
	html: htmlStr,
	focus: 1,
	buttons: {Envoyer: true,Annuler: false},
	submit: function(v, m, f){
	if(v){
		    $j("#loadinvit").show();
			var rel =$j(m).find('#relationSelect').find(':selected').val();
			var pars = Form.serialize('hiddeninvitationfamily'+id);
			new Ajax.Updater("message-envoie",app_path + "familles/invitmembre/"+rel, {method:"post",postBody: pars , asynchronous:true, evalScripts:true,requestHeaders:["message-envoie"],onLoading:function(request){},onComplete:function(request){$j("#loadinvit").hide();}});	

		}
	}
	}
	};
	$j.prompt(jqistates);
}