// JavaScript Document
//@ETAT=
//@TPS-PREVU=2
//@TPS-PASSE=1
//@ - gestion des reload list, fonction aja et ajax logged

//  ---------------------------------------------  //
//  --  Gestion des listes & recherche & fiche --  //
var G_nbNew = 0;
function reloadListing(idPop){

	if(typeof(idPop)=='undefined'){idPop='';}
	if(document.getElementById(idPop+'liste')){
		if(typeof(idPop)=='undefined'){idPop='';}
		//TODO : efface les marquee 
		for(var k=0;k<aMarqueeLaunched.length;k++){
			if(document.getElementById(aMarqueeLaunched[k])){
				$(aMarqueeLaunched[k]).style.visibility='hidden';				
			}
		}
		$(idPop+'loading').style.display='block';
		
		$(idPop+'loading').style.height=parseInt($(idPop+'liste').offsetHeight)+'px';
		$(idPop+'mask-loading').style.height=parseInt($(idPop+'liste').offsetHeight)+'px';
		//$(idPop+'visu-loading').style.height=parseInt($(idPop+'liste').offsetHeight)+'px';
		$(idPop+'visu-loading').style.height='50px';
		if(G_oMouseY<500){
			$(idPop+'visu-loading').style.marginTop='50px';
		}else{
			$(idPop+'visu-loading').style.marginTop=(parseInt($(idPop+'liste').offsetHeight)-100)+'px';
		}
		
		autoSubmit(
			{
				id:idPop+'divpage',
				url:'aja/index.php?page='+$(idPop+'page').value+'&area='+$(idPop+'area').value+'&idPop='+idPop,
				onSuccess : function(t){ 
					$(idPop+'liste').innerHTML=t.responseText;
					kmzPopup.resizeFondGris();
					if(document.getElementById(idPop+'loading')){
						$(idPop+'loading').style.display='none';
					}    
					if(document.getElementById(idPop+'disp_nb_pages')){
						$(idPop+'disp_nb_pages').innerHTML=$(idPop+'nb_pages').value;
					}
					if(document.getElementById(idPop+'disp_nb_pagestop')){
						$(idPop+'disp_nb_pagestop').innerHTML=$(idPop+'nb_pages').value;
					}
					if(document.getElementById(idPop+'disp_nb_pagesbottom')){
						$(idPop+'disp_nb_pagesbottom').innerHTML=$(idPop+'nb_pages').value;
					}
					if(document.getElementById(idPop+'nb_pages_voulutop')){
						$(idPop+'nb_pages_voulutop').value=parseInt($(idPop+'nb_pages').value)+1;
					}
					if(document.getElementById(idPop+'nb_pages_voulubottom')){
						$(idPop+'nb_pages_voulubottom').value=parseInt($(idPop+'nb_pages').value)+1;
					}
					if(document.getElementById(idPop+'disp_nb_pages_total')){
						$(idPop+'disp_nb_pages_total').innerHTML=parseInt($(idPop+'nb_pages_total').value)+1;
					}
					if(document.getElementById(idPop+'disp_nb_pages_totaltop')){
						$(idPop+'disp_nb_pages_totaltop').innerHTML=parseInt($(idPop+'nb_pages_total').value)+1;
					}
					if(document.getElementById(idPop+'disp_nb_pages_totalbottom')){
						$(idPop+'disp_nb_pages_totalbottom').innerHTML=parseInt($(idPop+'nb_pages_total').value)+1;
					}
					if(document.getElementById(idPop+'disp_montant_select')){
						$(idPop+'disp_montant_select').innerHTML=$(idPop+'montant_select').value;
					}
					if(document.getElementById(idPop+'disp_montant_facture')){
						$(idPop+'disp_montant_facture').innerHTML=$(idPop+'montant_facture').value;
					}
					if(document.getElementById(idPop+'disp_nb_facture')){
						$(idPop+'disp_nb_facture').innerHTML=$(idPop+'nb_facture').value;
					}
					if(document.getElementById(idPop+'nparpagetop')){						
						$(idPop+'nparpagetop').value=$(idPop+'nparpage').value;
					}
					if(document.getElementById(idPop+'nparpagebottom')){
						$(idPop+'nparpagebottom').value=$(idPop+'nparpage').value;
					}
					if(document.getElementById(idPop+'disp_nb_item')){
						var old=parseInt($(idPop+'disp_nb_item').innerHTML);
						$(idPop+'disp_nb_item').innerHTML=$(idPop+'nb_item').value;
						if(document.getElementById(idPop+'pulsate_item')){
							if(old!=parseInt($(idPop+'nb_item').value)){
								$(idPop+'pulsate_item').setStyle({opacity:1});
								Effect.Pulsate(idPop+'pulsate_item',{ pulses: 5, duration: 1.5 });
							}
						}
					}
					
					if(document.getElementById(idPop+'ReloadGeo')){
						if(document.getElementById(idPop+'-reload-pays-only')){	copySelect(document.getElementById(idPop+'-reload-pays-only'),document.getElementById(idPop+'pays-only'))};
						if(document.getElementById(idPop+'-reload-ville-only')){	copySelect(document.getElementById(idPop+'-reload-ville-only'),document.getElementById(idPop+'ville-only'))};
						if(document.getElementById(idPop+'-reload-district-only')){copySelect(document.getElementById(idPop+'-reload-district-only'),document.getElementById(idPop+'district-only'))};
	
					}
						
					
					if(document.getElementById(idPop+'pulsate_item')){
											
						if(	$(idPop+'search').value!=""){
							$(idPop+'button_search').className='boutonjaune_off';
						}else{
							$(idPop+'button_search').className='boutonblanc_off';
						}
											
						var aParam={'idChapeau':idPop+"chapeau",'idPop':idPop};				
						if(document.getElementById(idPop+'bouton_afficher_tout')){
							if(aChapeauxValues[idPop+'chapeau']==checkDefaultValueOfChapeau(aParam) && $(idPop+'colonesearch').value==''){
						
								$(idPop+'bouton_afficher_tout').style.display='none';
							}else{
								$(idPop+'bouton_afficher_tout').style.display='inline';
							}
						}
												
					}else{						
						
					}
					
			
					if(document.getElementById(idPop+'disp_nb_item_total')){
						$(idPop+'disp_nb_item_total').innerHTML=$(idPop+'nb_item_total').value;
					}
					if(document.getElementById(idPop+'options-affichage') && document.getElementById(idPop+'maj-options-affichage')){
						$(idPop+'options-affichage').innerHTML=$(idPop+'maj-options-affichage').innerHTML;
					}
					if(document.getElementById(idPop+'clients_a_valider') && document.getElementById(idPop+'nb_clients_a_valider')){
						document.getElementById(idPop+'clients_a_valider').innerHTML=document.getElementById(idPop+'nb_clients_a_valider').value;					
					}
					
					
					/*if(document.getElementById(idPop+'disp_nb_pages') && document.getElementById(idPop+'disp_nb_pages_total')){
						if($(idPop+'nb_item').value==$(idPop+'nb_item_default').value){
							$('bouton_afficher_tout').className = 'boutonblanc_off';
						}else{
							$('bouton_afficher_tout').className = 'boutonvert_off';
						}
					}*/
					autoLoad({id:idPop+'liste'});
				}
			}
		);
	}
}

function customSelectAvance(idPop){
		if(typeof(idPop)=='undefined'){idPop='';}
		var nItem=$(idPop+'custom_field').selectedIndex;
		nItem++;
		if(nItem>=$(idPop+'custom_field').options.length){
			nItem=0;
		}
		$(idPop+'custom_field').options[nItem].selected=true;
		reloadListing(idPop);
}
function customSelectRecule(idPop){
		if(typeof(idPop)=='undefined'){idPop='';}
		var nItem=$(idPop+'custom_field').selectedIndex;
		nItem--;
		if(nItem<0){
			nItem=$(idPop+'custom_field').options.length-1;
		}
		$(idPop+'custom_field').options[nItem].selected=true;
		reloadListing(idPop);
}

function clickButtonSearch(idPop){
	
	if(typeof(idPop)=='undefined'){idPop='';}
	$(idPop+'nb_pages').value=0;
	if($(idPop+"button_search").value!=CONF_aMessage["effacer-la-recherche"]){
		reloadListing(idPop);
		if($(idPop+"search").value!=''){
			$(idPop+"button_search").value=CONF_aMessage["effacer-la-recherche"];
		}
	}else{
		$(idPop+"search").value='';
		$(idPop+"button_search").value=CONF_aMessage["lancer-la-recherche"];
	}
	reloadListing(idPop);
}

function sendSearch(idPop){
	if(typeof(idPop)=='undefined'){idPop='';}
	reloadListing(idPop);
}

function sendSearchWith(aParam){
	if(aParam["search"] &&  aParam["value"]!="" &&  aParam["value"]!="0000-00-00 00:00:00"){
		var	idPop = aParam["idPop"];
		if($(idPop+"colonesearch").value!=''){
			$(idPop+"colonesearch").value+=';!;';
			$(idPop+"colonevalue").value +=';!;';
		}
		$(idPop+"colonesearch").value+= aParam["search"];
		$(idPop+"colonevalue").value += aParam["value"];
	
		reloadListing(idPop);
		/*if(document.getElementById(idPop+'RecapSelection')){
			$(idPop+'RecapSelection').innerHTML+="<br />- "+aParam["searchHuman"]+" = "+aParam["valueHuman"];
		}*/
	}
}

function submitFiche(aParam){
	
	var	idPop        = ''; 	//* id de la popup
	var areasave     = '';  //* area du script
	var scriptsave   = '';	//* nom du script ajax de sauvegarde
	var idParent     = '';	//  id de popup a refresh---> ??
	var reloadListe  = '';	//  boleen : faut-il reloader la page en arrier plan, par defaut : true
	var autoClose    = '';	//  param autoClose : String => 'false' implqiue que la fenetre ne se ferme pas toute seule
	var afterSuccess = '';	//  func => execute au retour de la requete
							// !! RIEN NE S'EXECUTE DERRIERE SI IL YA UNE REQUETE AJAX DANS afterSuccess
							//  => executer apres closepopup
	var showLoad     = '';  //  bool, affiche un fond gris dans la popup pendant le traitement
	
	if(aParam["idPop"]){
		idPop=aParam["idPop"];
	}else{
		idPop=0;
	}
	if(aParam["areasave"]){
		areasave=aParam["areasave"];
	}else{
		areasave=0;
	}
	if(aParam["scriptsave"]){
		scriptsave=aParam["scriptsave"];
	}else{
		scriptsave=0;
	}
	if(typeof(aParam["reloadListe"])=='boolean'){
		reloadListe=aParam["reloadListe"];
	}else{
		reloadListe=true;
	}
	if(aParam["idParent"]){
		idParent=aParam["idParent"];
	}
	if(aParam["autoClose"]){
		autoClose = aParam["autoClose"];
	}else{
		autoClose=false;
	}
	if(aParam["afterSuccess"] && typeof(aParam["afterSuccess"]) == 'function'){
		afterSuccess = aParam["afterSuccess"]
	}else{
		afterSuccess = function empty(){}; 
	}
	if(aParam["showLoad"]){
		showLoad = aParam["showLoad"];
	}else{
		showLoad = false;
	}
	var aPastParam = aParam;
	
	if(showLoad && idPop){ kmzPopup.showLoading(idPop); }
	if(scriptsave && idPop && areasave){
		autoSubmit(
			{	id:idPop+"contentHtml",
				url:'ajax/index.php?page='+scriptsave+'&area='+areasave,
				onSuccess : function(t){
					
					//if(showLoad){ kmzPopup.hideLoading(idPop); }
					var msg=getMsgFromAjax(t);
					if(msg.indexOf('[erreur]')>-1){
					//  Erreur
						msg=msg.replace(/\[erreur\]/,'');
					//  MultiUtilisateur
						if(msg.indexOf('[erase]')>-1){
							//DELAY POUR NE CROISER LES EVNT AVEC FOND GRIS
							setTimeout(
								function (){
									var aBoutons = new Array(
										{'label':CONF_aMessage["oui"], 'class':'boutonblanc', 'action':function(){ $(idPop+'erase').value=1; submitFiche(aPastParam); } },
										{'label':CONF_aMessage["non"], 'class':'boutonblanc',  
											'action':function(){ reloadListeCommande({nPage:0});}//reloadListing(idParent); }
										}
									);
									kmzAlert.openAlert({message:CONF_aMessage['deja-modified-fiche'], grise:true, icone:'img/alert-default/erreur.gif', bouton:aBoutons});
								},1000
							);
						}else{
							if(msg!='nomsg'){ 
								//DELAY POUR NE CROISER LES EVNT AVEC FOND GRI
								setTimeout(
									function (){
										kmzAlert.openAlert({message:msg, grise:true, icone:'img/alert-default/erreur.gif'}); 
									},1000
								);
							}
						}
					}else{
					//  Success	
						var aParam = kmzPopup.aPopup['param'][idPop];
						if(reloadListe==true){ reloadListeCommande({nPage:0});}//reloadListing(idParent);	}
						if(msg!='nomsg'){
							//DELAY POUR NE CROISER LES EVNT AVEC FOND GRI
							setTimeout( function (){kmzAlert.openAlert({message:msg, grise:true});}, 1000);
						}
						if(autoClose==true){ 
							if(aParam["verifValues"]){kmzPopup.aPopup['param'][idPop]["verifValues"]=false;}
							kmzPopup.closePopup(idPop); 
						}
						
						afterSuccess(aParam, t);
						// !! RIEN NE S'EXECUTE DERRIERE SI IL YA UNE REQUETE AJAX DANS afterSuccess
					}  
				},
				onFailure : function(){
					if(showLoad){
						kmzPopup.hideLoading(idPop);
						kmzAlert.openAlert({message:CONF_aMessage["erreur-has-occured"], grise:true, icone:'img/alert-default/erreur.gif'});
					}
				}
        	}
		);
	}
}

function majFicheValues(aParam, t){	
	var idPop         = aParam['id'];
	var resXML        = t.responseXML;         
	var resultat_node = resXML.getElementsByTagName('date_modif').item(0);
	var sDate_modif   = resultat_node.childNodes[0].nodeValue;
	var aParam        = kmzPopup.aPopup['param'][idPop];
	//--       
	var nom_node      = resXML.getElementsByTagName('nom').item(0);
	if(nom_node){
		var sNom          = nom_node.childNodes[0].nodeValue;
		//var idPop         = aParam['id'];
		$(idPop+'poptitle').innerHTML = sNom;
	}else{
		//alert('mank balise nom onSave');//TODO RETIRER L'ALERTE
	}
	
	//MAJ icone de popup
	var icone_node      = resXML.getElementsByTagName('icone').item(0);
	if(icone_node){
		var sIcone = icone_node.childNodes[0].nodeValue;
		if(sIcone){$(idPop+'icone').src = sIcone;}
	}
	
	//MAJ color de popup
	var color_node      = resXML.getElementsByTagName('color').item(0);
	if(color_node){
		var sColor = color_node.childNodes[0].nodeValue;
		if(sColor && document.getElementById(idPop+'DragNDrop')){
			$(idPop+'DragNDrop').style.backgroundColor = sColor;
			//alert(sColor);
		}
	}
	/**/
	
	//--
	if(aParam["param"]){
		if(aParam["param"].indexOf("&id=",0)!=-1 && aParam["param"].indexOf("&hasnew=",0)==-1 ){//hasnew => duplication commande
			kmzPopup.aPopup['param'][idPop]["param"] = kmzPopup.aPopup['param'][idPop]["param"].replace('date_modif='+$(idPop+'date_modif').value, 'date_modif='+sDate_modif);
			kmzPopup.aPopup['param'][idPop]["param"] = kmzPopup.aPopup['param'][idPop]["param"].replace('&onglet=apercu', '&onglet=detail');
			if(document.getElementById(idPop+'onglets-opened')){
				if(aParam["param"].indexOf("&onglets-opened=",0)==-1){
					kmzPopup.aPopup['param'][idPop]["param"]+='&onglets-opened='+$(idPop+'onglets-opened').value;
				}else{
					var reg=new RegExp("&onglets-opened=(.[^&]*)", "g");
					kmzPopup.aPopup['param'][idPop]["param"] = kmzPopup.aPopup['param'][idPop]["param"].replace(reg, '')+'&onglets-opened='+$(idPop+'onglets-opened').value
				}
			}
			kmzPopup.loadContent(idPop);
		}else{
			if(aParam["verifValues"]){kmzPopup.aPopup['param'][idPop]["verifValues"]=false;}
			kmzPopup.closePopup(idPop);
		}
	}
}

function remindOpenedOnglet(sIdPop, sName){
	if(document.getElementById(sIdPop+'onglets-opened')){
		sNameInput = sName.replace('onglet-', '');
		if($(sIdPop+sName).style.display=='block'){
			$(sIdPop+'onglets-opened').value+= sNameInput+';';
		}else{
			$(sIdPop+'onglets-opened').value = $(sIdPop+'onglets-opened').value.replace(sNameInput+';', '');
		}
	}
}

function showFicheModifiable(sIdPop){
	if($(sIdPop+'fiche-readonly').style.display=='block'){
		$(sIdPop+'fiche-readonly').style.display='none'; 
		$(sIdPop+'fiche').style.display='block';
		if(document.getElementById(sIdPop+'ongletApercu')){
			document.getElementById(sIdPop+'ongletApercu').style.display='none';
			document.getElementById(sIdPop+'ongletDetail').style.display='block';
		}
		
	}else{
		$(sIdPop+'fiche-readonly').style.display='block'; 
		$(sIdPop+'fiche').style.display='none';
		if(document.getElementById(sIdPop+'ongletApercu')){
			document.getElementById(sIdPop+'ongletApercu').style.display='block';
			document.getElementById(sIdPop+'ongletDetail').style.display='none';
		}
	}
	kmzPopup.resizeFondGris();
}


function showFicheOngletDetail(sIdPop){
	if($(sIdPop+'fiche-readonly').style.display=='block'){
		$(sIdPop+'fiche-readonly').style.display='none'; 
		$(sIdPop+'fiche').style.display='block';
		if(document.getElementById(sIdPop+'ongletApercu')){
				document.getElementById(sIdPop+'ongletApercu').style.display='none';
				document.getElementById(sIdPop+'ongletDetail').style.display='block';
		}
		
	}
	kmzPopup.resizeFondGris();
}

function showFicheOngletApercu(sIdPop){	
	if($(sIdPop+'fiche-readonly').style.display=='none'){
		$(sIdPop+'fiche-readonly').style.display='block'; 
		$(sIdPop+'fiche').style.display='none';
		if(document.getElementById(sIdPop+'ongletApercu')){
			document.getElementById(sIdPop+'ongletApercu').style.display='block';
			document.getElementById(sIdPop+'ongletDetail').style.display='none';
		}
	}
	kmzPopup.resizeFondGris();
}



function verifieChampsObligatoire(aParam){
	/*
	idPop : id de la popup
	liste_champs : array avec les champs a valide
	nocolor : false par defaut, avec true , le changement de couleur n'est pas applique.
	init : false par defaut, remet les couleurs de bases quelque soit le resultat
	*/
	var idChamp='';
	var nErreur=0;
	var objParent='';
	if(!aParam['init']){
		var bInit=false;
	}else{
		var bInit=aParam['init'];
	}
	if(!aParam['nocolor']){
		var bNoColor=false
	}else{
		var bNoColor=aParam['nocolor'];
	}
	if(aParam['idPop']){
		var idPop=aParam['idPop'];
		if(aParam['liste_champs']){
			aListeChamps=aParam['liste_champs'];
		}else{
			aListeChamps=new Array();
		}
	
		var nbElem=aListeChamps.length;
			
		for(var i=0;i<nbElem;i++){
			idChamp=idPop+aListeChamps[i];
			var aElements=document.getElementsByName(idChamp);
			var nbElements=aElements.length;
			
			if(nbElements>1){
				var bChecked=false;
				for(var j=0;j<nbElements;j++){ if(aElements[j].checked){ bChecked=true; } }
				if(!bChecked){
					objParent=aElements[(j-1)].offsetParent;
					nErreur++;
					if(!bNoColor)objParent.style.color='#BB0000';
				}else{
					objParent=aElements[(j-1)].offsetParent;
					if(!bNoColor)objParent.style.color='#000000';
				}
				if(bInit)objParent.style.color='#000000';				
			}			
			
			if(document.getElementById(idChamp)){				
				
				if($(idChamp).type=="checkbox"){	
					if(!$(idChamp).checked){
						nErreur++;
						objParent=$(idChamp).offsetParent;
						if(!bNoColor)objParent.style.color='#BB0000';
					}else{
						objParent=$(idChamp).offsetParent;
						if(!bNoColor)objParent.style.color='#000000';
					}
					if(bInit)objParent.style.color='#000000';
				}
				
				if($(idChamp).type!="checkbox" && $(idChamp).type!="radio"){				
					if($(idChamp).value==''){						
						nErreur++;
						if(!bNoColor)$(idChamp).style.borderColor='#BB0000';
						if(!bNoColor)$(idChamp).style.color='#BB0000';						
					}else{
						if(!bNoColor)$(idChamp).style.borderColor='#999999';
						if(!bNoColor)$(idChamp).style.color='#000000';
					}
				
					if(bInit)$(idChamp).style.color='#000000';
					if(bInit)$(idChamp).style.borderColor='#999999'; 
				}
			}				
		}
	}
	return nErreur;
}

function getMsgFromAjax(t){
	/*var resXML=t.responseXML;         
	var resultat_node = resXML.getElementsByTagName('resultat').item(0);
	var msg = resultat_node.childNodes[0].nodeValue;
	return msg;*/
	var resXML=t.responseXML;
	//alert('getMsgFromAjax: IN');
	var page_node 		= resXML.getElementsByTagName('page').item(0);
	//alert('getMsgFromAjax: page_node');
	var resultat_node 	= resXML.getElementsByTagName('resultat').item(0);
	//alert('getMsgFromAjax: resultat_node');
	var msg = resultat_node.childNodes[0].nodeValue;
	//alert('getMsgFromAjax: '+msg);
	return msg;
}

var aOldIdClick=new Array();
function listeClick(id, idPop){
	if(typeof(idPop)=='undefined'){ idPop = 0; }
	if(document.getElementById(aOldIdClick[idPop])){ $(aOldIdClick[idPop]).className='list_item_off'; }
	aOldIdClick[idPop]=id;
    if(document.getElementById(id)){ $(id).className='list_item_click'; }
	if(idPop!=0){
		$(idPop+'itemclicked').value=id;
	}else{
		$('itemclicked').value=id;
	}
}

function removeAccents(chaine){

	  var temp = chaine.replace(/[\340\341\342\343\344\345]/gi,"a");

      temp = temp.replace(/[\350\351\352\353]/gi,"e");
      temp = temp.replace(/[\354\355\356\357]/gi,"i");
      temp = temp.replace(/[\362\363\364\365\366\367\368\369\370]/gi,"o");
      temp = temp.replace(/[\371\372\373\374]/gi,"u");
      temp = temp.replace(/[\347]/gi,"c");   
    
	return temp ;
}

function validationMail(mailteste){
	var regExp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,6}$/;
	return regExp.test(mailteste);
}
//  --  Gestion des listes & recherche & fiche --  //
//  ---------------------------------------------  //



function reloadChampTel(aParam){
	
	var sPays=aParam['pays'];
	var sId=aParam['id'];	

	new Ajax.Request('aja/index.php', {
    	method: 'post', 
    	parameters: 'page=numero-tel&area=navigation&pays='+sPays+'&pays-from='+$(sId+'-pays-from').value+'&valeur='+$(sId).value+'&id='+sId+'&class='+$(sId+'-1').className+'&format='+$(sId+'-format').value+'&is_not_required='+$(sId+'-is_not_required').value,
		onCreate: function(t){	$(sId+'-div').innerHTML="<img src='img/loading-small.gif' />";},
    	onComplete: function(t){
			
						$(sId+'-div').innerHTML=t.responseText;
					}
    } );
	
}

function modifAdresse(aParams){
	
	var sId=aParams['id'];
	
	$(sId).value=$(sId+'id').value+'=@@=';
	$(sId).value+=$(sId+'langue').value+'=@@=';

	
	$(sId).value+=$(sId+'ligne_2').value+'=@@=';
	$(sId).value+=$(sId+'ligne_3').value+'=@@=';
	$(sId).value+=$(sId+'ligne_4').value+'=@@=';
	
	$(sId).value+=$(sId+'cp').value+'=@@=';	
	$(sId).value+=$(sId+'ville').value+'=@@=';	

	$(sId).value+=$(sId+'district').value+'=@@=';

	$(sId).value+=$(sId+'pays').value;
	
	//secure
	if($(sId+'ville').value==''){
		$(sId+'ville').style.borderColor='#bb0000';	
		$(sId).value="";
	}else{
		$(sId+'ville').style.borderColor='#999999';	
	}
	
	if($(sId+'cp').value==''){
		$(sId+'cp').style.borderColor='#bb0000';	
		$(sId).value="";
	}else{
		$(sId+'cp').style.borderColor='#999999';	
	}
	
	if($(sId+'district').value==''){
		$(sId+'district').style.borderColor='#bb0000';	
		$(sId).value="";
	}else{
		$(sId+'district').style.borderColor='#999999';	
	}
	
	if($(sId+'pays').value==''){
		$(sId+'pays').style.borderColor='#bb0000';	
		$(sId).value="";
	}else{
		$(sId+'pays').style.borderColor='#999999';	
	}
	
	
	
	if($(sId+'ligne_2').value!='' || $(sId+'ligne_3').value!='' || $(sId+'ligne_4').value!=''){
		$(sId+'ligne_2').style.borderColor='#999999';	
		$(sId+'ligne_3').style.borderColor='#999999';	
		$(sId+'ligne_4').style.borderColor='#999999';	
	}else{
		$(sId+'ligne_2').style.borderColor='#bb0000';	
		$(sId+'ligne_3').style.borderColor='#bb0000';	
		$(sId+'ligne_4').style.borderColor='#bb0000';			
		$(sId).value="";
		
	}
	
	//si le champs est completement vide :
	if($(sId+'ligne_2').value=='' && $(sId+'ligne_3').value=='' && $(sId+'ligne_4').value=='' &&  $(sId+'cp').value=='' && $(sId+'district').value=='' && $(sId+'ville').value==''){
		$(sId+'ligne_2').style.borderColor='#999999';	
		$(sId+'ligne_3').style.borderColor='#999999';	
		$(sId+'ligne_4').style.borderColor='#999999';	
		$(sId+'cp').style.borderColor='#999999';	
		$(sId+'ville').style.borderColor='#999999';
		$(sId+'district').style.borderColor='#999999';	

	}
	
	
		
}




var GLOBAL_aAutoCompleter=new Object();
function MAJAutocompleteAdresse(aParam){
	var sChamps=aParam['champs'];
	var sIdPop=aParam['idPop'];
	var sLangue=aParam['langue'];
	//AUTOCOMPLETE VILLE
	if(!	GLOBAL_aAutoCompleter[sIdPop+sChamps+"ville"] ){
	GLOBAL_aAutoCompleter[sIdPop+sChamps+"ville"] = new Ajax.Autocompleter(
    sIdPop+sChamps+"ville",  				
    sIdPop+sChamps+"ville_autocomplete",  
    "aja/index.php",  			
    {
        paramName: 'ville',  
        minChars: 1,  
		parameters : "page=adresse"+'&'+"area=navigation"+'&'+"langue="+sLangue+'&'+"type=ville"+'&'+"pays="+$(sIdPop+sChamps+'pays').value,
		
		afterUpdateElement : function(){	
		
			var sField=$(sIdPop+sChamps+'ville').value;	
			var nPosDeb=strpos(sField,'(');	
			var nLongeur=strpos(sField,')')-nPosDeb;
			var sVille=sField.substr(0,nPosDeb-1);			
			var sCP=sField.substr((nPosDeb+1),nLongeur-1);
			
			 nPosDeb=strpos(sField,'[');	
			 nLongeur=strpos(sField,']')-nPosDeb;
			var sNomDistrict=sField.substr((nPosDeb+1),nLongeur-1);
			
			 nPosDeb=strpos(sField,'{');	
			 nLongeur=strpos(sField,'}')-nPosDeb;
			var sNumDistrict=sField.substr((nPosDeb+1),nLongeur-1);

			
			$(sIdPop+sChamps+'ville').value=sVille;
			if(!$(sIdPop+sChamps+'cp').value){
				$(sIdPop+sChamps+'cp').value=sCP;
				if(!$(sIdPop+sChamps+'district').value ){
					//selectData({'id':sIdPop+sChamps+'district','valeur':sNomDistrict+' ('+sNumDistrict+')'});
					$(sIdPop+sChamps+'district').value=sNumDistrict;
				}
			}
			if($(sIdPop+sChamps+'district').value==''){
				selectData({'id':sIdPop+sChamps+'district','valeur':sNomDistrict+' ('+sNumDistrict+')'});
			}
		
			$(sIdPop+sChamps+'id_district').value="";
			$(sIdPop+sChamps+'id_ville').value="";
			$(sIdPop+sChamps+'id_pays').value=""; 
			modifAdresse({'id':sIdPop+sChamps});
			//checkElementAdresse({'idPop':sIdPop,'champs':sField,'type':'ville',valeur:$(sIdPop+sChamps+'ville').value,'pays':$(sIdPop+sChamps+'id_pays').value,'langue': sLangue})
			
		}		
    });
	}else{
		GLOBAL_aAutoCompleter[sIdPop+sChamps+"ville"].options.defaultParams="page=adresse"+'&'+"area=navigation"+'&'+"langue="+sLangue+'&'+"type=ville"+'&'+"pays="+$(sIdPop+sChamps+'pays').value;
	}
	//AUTOCOMPLETE CP
	if(!	GLOBAL_aAutoCompleter[sIdPop+sChamps+"cp"] ){
	GLOBAL_aAutoCompleter[sIdPop+sChamps+"cp"]=new Ajax.Autocompleter(
    sIdPop+sChamps+"cp",  				 
    sIdPop+sChamps+"cp_autocomplete", 
    "aja/index.php",  		
    {
        paramName: 'cp',  
        minChars: 1,  
		parameters : "page=adresse"+'&'+"area=navigation"+'&'+"langue="+sLangue+'&'+"type=cp"+'&'+"pays="+$(sIdPop+sChamps+'pays').value,
		afterUpdateElement : function(){
			var sField=$(sIdPop+sChamps+'cp').value;	
			var nPosDeb=strpos(sField,'(');	
			var nLongeur=strpos(sField,')')-nPosDeb;
			var sCP=sField.substr(0,nPosDeb-1);			
			var sVille=sField.substr((nPosDeb+1),nLongeur-1);
			
			nPosDeb=strpos(sField,'[');	
			 nLongeur=strpos(sField,']')-nPosDeb;
			var sNomDistrict=sField.substr((nPosDeb+1),nLongeur-1);
			
			 nPosDeb=strpos(sField,'{');	
			 nLongeur=strpos(sField,'}')-nPosDeb;
			var sNumDistrict=sField.substr((nPosDeb+1),nLongeur-1);
		
			if(!$(sIdPop+sChamps+'ville').value){
				$(sIdPop+sChamps+'ville').value=sVille;	
				if(!$(sIdPop+sChamps+'district').value ){
					//selectData({'id':sIdPop+sChamps+'district','valeur':sNomDistrict+' ('+sNumDistrict+')'});
					$(sIdPop+sChamps+'district').value=sNumDistrict;
				}
			}
			if(!$(sIdPop+sChamps+'district').value ){
				selectData({'id':sIdPop+sChamps+'district','valeur':sNomDistrict+' ('+sNumDistrict+')'});
			}
			$(sIdPop+sChamps+'cp').value=sCP;
			
			
			
			
			$(sIdPop+sChamps+'id_district').value="";
			$(sIdPop+sChamps+'id_ville').value="";
			$(sIdPop+sChamps+'id_pays').value="";
			modifAdresse({'id':sIdPop+sChamps});
			//checkElementAdresse({'idPop':sIdPop,'champs':sField,'type':'ville',valeur:$(sIdPop+sChamps+'ville').value,'pays':$(sIdPop+sChamps+'id_pays').value,'langue': sLangue})
			
		}		
    });
	}else{
		GLOBAL_aAutoCompleter[sIdPop+sChamps+"cp"].options.defaultParams="page=adresse"+'&'+"area=navigation"+'&'+"langue="+sLangue+'&'+"type=cp"+'&'+"pays="+$(sIdPop+sChamps+'pays').value;
	}	
	
	
	
	
}

function unloadAutocompleter(){
	for(var a in GLOBAL_aAutoCompleter){
		if(!document.getElementById(a)){
			GLOBAL_aAutoCompleter[a]=null;	
		}
	}
}



function strpos (haystack, needle, offset) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
    // *     returns 1: 14
 
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}


function alertFicheModified(aParam){
	if($(aParam['id']+'etat').value == 'creation'){
	var aBoutons = new Array(
		{
			'label':CONF_aMessage["oui"], 
			'class':'boutonblanc', 
			'action':function(){ 
				/*if(aParam['areasave'] && aParam['scriptsave']){ 
					submitFiche({idPop:aParam['id'], areasave:aParam['areasave'], scriptsave:aParam['scriptsave'], showLoad:true, autoClose:true});
				}*/
				if(aParam['exe_save'] && typeof(aParam["exe_save"]) == 'function'){
					aParam['exe_save'](aParam['id']);
				}else{
					//alert('No Function exe_save');
				}
			} 
		},{ 
			'label':CONF_aMessage["non"], 
			'class':'boutonblanc',  
			'action':function(){
				if(aParam["verifValues"]){kmzPopup.aPopup['param'][aParam['id']]["verifValues"]=false;}
				kmzPopup.closePopup(aParam['id']); 
			}
		},{ 
			'label':CONF_aMessage["annuler"], 
			'class':'boutonblanc',  
			'action':function(){}
		}
	);
	var aBoutons = new Array(
		{
			'label':CONF_aMessage["oui"], 
			'class':'boutonblanc', 
			'action':function(){ 
				if(aParam["verifValues"]){kmzPopup.aPopup['param'][aParam['id']]["verifValues"]=false;}
				kmzPopup.closePopup(aParam['id']); 
			} 
		},{ 
			'label':CONF_aMessage["non"], 
			'class':'boutonblanc',  
			'action':function(){}
		}
	);
	kmzAlert.openAlert({message:CONF_aMessage["modified-fiche"], grise:true, icone:'img/alert-default/erreur.gif', bouton:aBoutons});}
}

function alertFormulaireModified(aParam){
	var aBoutons = new Array(
		{
			'label':CONF_aMessage["oui"], 
			'class':'boutonblanc', 
			'action':function(){ 
				if(aParam['areasave'] && aParam['scriptsave']){ 
					submitFiche({idPop:aParam['id'], areasave:aParam['areasave'], scriptsave:aParam['scriptsave'], showLoad:true, autoClose:true, afterSuccess:aParam['afterSuccess']});
				}
			} 
		},{ 
			'label':CONF_aMessage["non"], 
			'class':'boutonblanc',  
			'action':function(){
				if(aParam["verifValues"]){kmzPopup.aPopup['param'][aParam['id']]["verifValues"]=false;}
				kmzPopup.closePopup(aParam['id']); 
			}
		},{ 
			'label':CONF_aMessage["annuler"], 
			'class':'boutonblanc',  
			'action':function(){}
		}
	);
	kmzAlert.openAlert({message:CONF_aMessage["modified-formulaire"], grise:true, icone:'img/alert-default/erreur.gif', bouton:aBoutons});
}

function traceCloseFiche(aParam){
	//alert(aParam.toSource());
	if(document.getElementById(aParam['id']+'id')){
		var idPop      = aParam['id'];
		var idFiche    = $(aParam['id']+'id').value
		var sParamAjax = 'page=closing-popup&area=navigation&refarea='+aParam['areasave']+'-'+aParam['scriptsave']+'&idPop='+idPop+'&pid='+idFiche;
		new Ajax.Request(
			'ajax/index.php',
			{ 
				method       : 'post', 
				parameters   : sParamAjax,
				onSuccess    : function (t){ 
					var msg = getMsgFromAjax(t);
					//alert('deleted '+idPop+' '+idFiche+msg);
				}
			}
		);
	}
}


function checkElementAdresse(aParam){
	var sType=aParam['type']; 	//ville,cp
	var sValeur=aParam['valeur'];
	var sPays=aParam['pays'];
	var sIdPop=aParam['idPop'];
	var sChamps=aParam['champs'];
	var sLangue=aParam['langue'];

	new Ajax.Request("aja/index.php", {
  		method: 'post',
		parameters:"page=adresse&area=navigation&maj=true&langue="+sLangue+"&type="+sType+"&valeur="+sValeur+'&pays='+sPays,
			onComplete: function(t){		
				var aTabRes=t.responseText.split(/=@@=/);
				
				if(!$(sIdPop+sChamps+'district').value  && aTabRes[1]  && aTabRes[2]){
					
					selectDataOption({'id':sIdPop+sChamps+'district','value':aTabRes[2] });					
				}
				
				
					
				
				if(!$(sIdPop+sChamps+'cp').value && sType=="ville"   && aTabRes[0]){
					$(sIdPop+sChamps+'cp').value=aTabRes[0];
				}
			
				
				if(!$(sIdPop+sChamps+'ville').value && sType=="cp"  &&   aTabRes[0]){


									
					$(sIdPop+sChamps+'ville').value=aTabRes[0];
				
				}
				
				
			}
		});
}


function majSelectDistrict(aParam){

	var sPays=aParam['pays'];
	var sIdPop=aParam['idPop'];
	var sChamps=aParam['champs'];
	var sLangue=aParam['langue'];
	var sId=aParam['id'];
	eval("var aDistrictPays=aPays"+sIdPop+sChamps+"District["+sPays+"]");
	$(sIdPop+sChamps+"district").options.length='';
		$(sIdPop+sChamps+"district").options[0]= new Option( CONF_aMessage["choisir-district"], "");
	if(aDistrictPays){
		
		var aOption=new Array();
	
		for(var k=0; k<aDistrictPays.length; k++){
			aOption=aDistrictPays[k].split('=@@=');		
			$(sIdPop+sChamps+"district").options[k+1]= new Option( aOption[1], aOption[0] );
			
		}	
		
	}
	if(sId){
		$(sIdPop+sChamps+"district").value=sId;
	}
	
}



function selectData(aParam){
	var sId=aParam["id"];//id du champs
	var sValeur=aParam["valeur"];//valeur recherche
	
	var nResult=-1;
	if(document.getElementById(sId)){
		for(var i=0;i<$(sId).options.length;i++){
			if(sValeur==$(sId).options[i].text){
					nResult=i;
					break;
			}
		}
		$(sId).selectedIndex=nResult;
	}

	if(nResult>=0){
		return	1;
	}else{
		return	0;
	}
	
}
function selectDataOption(aParam){
	var sId=aParam["id"];//id du champs
	var sValeur=aParam["value"];//valeur recherche

	var nResult=-1;
	var sTmp='';
	if(document.getElementById(sId)){
		for(var i=0;i<$(sId).options.length;i++){
			if(parseInt(sValeur)==parseInt($(sId).options[i].value)){
					
					nResult=i;
					sTmp+=sValeur+' = '+$(sId).options[i].value+'||';
			}
			
		}		
		$(sId).selectedIndex=nResult;
	}

	if(nResult>=0){
		return	1;
	}else{
		return	0;
	}
	
}


//fonctions de gestion du slide du menu :
var GLOBAL_SLIDE_MENU;
function menuStartSlideLeft(){
	clearInterval(GLOBAL_SLIDE_MENU);
	GLOBAL_SLIDE_MENU=setInterval("menuSlideLeft()",1);
	
}

function menuStopSlideLeft(){
	clearInterval(GLOBAL_SLIDE_MENU);
	
}


function menuSlideLeft(){
	if(parseInt($('menu-principal').style.marginLeft)>(946-parseInt($('menu-principal').offsetWidth))){
		$('menu-principal').style.marginLeft=(parseInt($('menu-principal').style.marginLeft)-3)+'px';
	}else{
		clearInterval(GLOBAL_SLIDE_MENU);
	}
	highLightMenu();
}


function menuStartSlideRight(){
	clearInterval(GLOBAL_SLIDE_MENU);
	GLOBAL_SLIDE_MENU=setInterval("menuSlideRight()",1);
	
}

function menuStopSlideRight(){
	clearInterval(GLOBAL_SLIDE_MENU);
	
}


function menuSlideRight(){
	if(parseInt($('menu-principal').style.marginLeft)<0){
		$('menu-principal').style.marginLeft=(parseInt($('menu-principal').style.marginLeft)+3)+'px';
	}else{
		clearInterval(GLOBAL_SLIDE_MENU);
	}
	highLightMenu();
}

function highLightMenu(){
	
	if(parseInt($('menu-principal').style.marginLeft)<0){
		$('bt_slideMenu_Left').innerHTML='&lt;&lt;';
		$('bt_slideMenu_Left').style.backgroundColor='#999999';
		$('bt_slideMenu_Left').style.color='#ffffff';
	}else{
		$('bt_slideMenu_Left').innerHTML='';
		$('bt_slideMenu_Left').style.backgroundColor='';	
		$('bt_slideMenu_Left').style.color='#555555';
	}
	if(parseInt($('menu-principal').style.marginLeft)>(946-parseInt($('menu-principal').offsetWidth))){
		$('bt_slideMenu_Right').innerHTML='&gt;&gt;';
		$('bt_slideMenu_Right').style.backgroundColor='#999999';
		$('bt_slideMenu_Right').style.color='#ffffff';
	}else{
		$('bt_slideMenu_Right').innerHTML='';
		$('bt_slideMenu_Right').style.backgroundColor='';
		$('bt_slideMenu_Right').style.color='#555555';
	}
}

//addLoadEvent(highLightMenu);
//fin fonctions de gestion du slide du menu :


function isInteger(sVar){
	var oExpReg = new RegExp("^[0-9]+$","g");
	return oExpReg.test(sVar);
} 


var GLOBAL_FusionItemA='';
var GLOBAL_FusionItemB='';

function genPass(){
	var sChars  = "ABCDEFGHIJKLMNPQRSTUVWYZ";
	var sNumbs  = "23456789";
	var nLength = 7;
	var nOffSet = Math.floor(Math.random()*10);
	var sPass   = '';
	for(i=nOffSet; i<nLength+nOffSet; i++){
		if(i%3==0){
			var nbalea = Math.floor(Math.random()*sNumbs.length);
			sPass+= sNumbs.charAt(nbalea);
		}else{

			var nbalea = Math.floor(Math.random()*sChars.length);
			sPass+= sChars.charAt(nbalea);
		}
		
	}
	return sPass;
} 

function in_array (needle, haystack, argStrict) {
	// Checks if the given value exists in the array 
	//
	// version: 910.912
	// discuss at: http://phpjs.org/functions/in_array
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: vlado houba
	// *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
	// *     returns 1: true
	// *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
	// *     returns 2: false
	// *     example 3: in_array(1, ['1', '2', '3']);
	// *     returns 3: true
	// *     example 3: in_array(1, ['1', '2', '3'], false);
	// *     returns 3: true
	// *     example 4: in_array(1, ['1', '2', '3'], true);
	// *     returns 4: false
	var key = '', strict = !!argStrict;
	if (strict) {
		for (key in haystack) { if (haystack[key] === needle) { return true; } }
	} else {
		if (typeof(needle)=='string') {
			str = haystack.toString();
			return (str.search(needle) !== false);
		}
		for (key in haystack) { if (haystack[key] == needle) { return true; } }
	}
	return false;
}

addLoadEvent(function(){
				var aParam={idChapeau:"chapeau",idPop:""};
			
				aChapeauxValues['chapeau']=checkDefaultValueOfChapeau(aParam);
			});

aChapeauxValues=new Array();

function checkDefaultValueOfChapeau(aParam){
	var idChapeau=aParam["idChapeau"];
	var idPop=aParam["idPop"];
	
	if(document.getElementById(idChapeau)){
		var oInputs = kmzPopup.loadElement(idChapeau);
		var s=""
		for(j=0;j<oInputs.length; j++) { 
			if(oInputs[j]["id"]!=idPop+"button_search" && oInputs[j]["id"]!=idPop+"search" ){
				s+="==##@@=="+oInputs[j]["id"]+"<!//!>"+oInputs[j]["value"];
			}
		}
	}
	return s
}

function copySelect(objSource,objDest){
	objDest.options.length=0;
	for(var i=0;i<objSource.options.length;i++){
			objDest.options[i]=new Option(objSource.options[i].text,objSource.options[i].value);
	}
	objDest.disabled=objSource.disabled;
	objDest.value=objSource.value;
}


function testRIB(id){
	$(id).value="";
	
	var sNomBanque=$(id+'rib_nom_banque').value;
	var sCodeBanque=$(id+'rib_banque').value;
	var sCodeGuichet=$(id+'rib_guichet').value;
	var sCompte=$(id+'rib_compte').value;
	sCompte=sCompte.toUpperCase();
	var sCle=$(id+'rib_cle').value;
	var sComplete=sNomBanque+sCodeBanque+sCodeGuichet+sCompte+sCle;
	 if(sNomBanque==""  ){//&& sComplete!=""
		$(id+'rib_nom_banque').style.borderColor='#dd0000';
	 }else{
		 $(id+'rib_nom_banque').style.borderColor='#999999';
	 }
	 if(sCodeBanque=="" ){//&& sComplete!=""
		$(id+'rib_banque').style.borderColor='#dd0000';
	 }else{
		 $(id+'rib_banque').style.borderColor='#999999';
	 }
	 if(sCodeGuichet=="" ){//&& sComplete!=""
		$(id+'rib_guichet').style.borderColor='#dd0000';
	 }else{
		 $(id+'rib_guichet').style.borderColor='#999999';
	 }
	 if(sCompte=="" ){//&& sComplete!=""
		$(id+'rib_compte').style.borderColor='#dd0000';
	 }else{
		 $(id+'rib_compte').style.borderColor='#999999';
	 }
	 if(sCle=="" ){//&& sComplete!=""
		$(id+'rib_cle').style.borderColor='#dd0000';
	 }else{
		 $(id+'rib_cle').style.borderColor='#999999';
	 }

							
	var tab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var tab1="123456789123456789234567890123456789".split("");
		
    var nLimit=0;
	while (sCompte.match(/\D/) != null ){
		nLimit++;
		sCompte=sCompte.replace(/\D/, tab1[tab.indexOf(sCompte.match(/\D/))]);
	}
	if(sCompte.length<11){
		sCompte='00';
	}
	var sCompteSav=sCompte;
	var sCompte=parseInt(sCompte, 10);
		
	//Calcul clé RIB
	var a=sCodeBanque%97;
	a=a*100000+parseInt(sCodeGuichet, 10);
	a=a%97;
	a=a*Math.pow(10, 11) + sCompte;
	a=a%97
	a=a*100;
	a=a%97
	a=97-a;
	if (sCle==a){
		$(id).value=sNomBanque+":@@:"+sCodeBanque+":@@:"+sCodeGuichet+":@@:"+sCompteSav+":@@:"+sCle;	
		$(id+'imgRIB').src='img/rib_ok.png';
		$(id+'DIV').style.backgroundColor='#cccccc';
	}else{
		$(id).value="";
		$(id+'imgRIB').src='img/rib_nok.png';
		if(sComplete || 1==1){
			$(id+'DIV').style.backgroundColor='#d98c8c';
		}else{
			$(id+'DIV').style.backgroundColor='#cccccc';
		}
	}
	
}



var TIMER_GLOBAL_MARQUEE=0;
var aCustomMarqueeLocked=Array();
var aMarqueeLaunched=Array();
function startMarquee(nId,nWidth){
	if(!$(nId).style.marginLeft){
			$(nId).style.marginLeft=0;			
	}
	
	if($(nId).offsetWidth>nWidth && !aCustomMarqueeLocked[nId]){
		aMarqueeLaunched.push(nId);
		aCustomMarqueeLocked[nId]=true;
		var nVal=$(nId).offsetWidth-nWidth;
		var nTime=Math.ceil(nVal*2/100);
		
	
		new Effect.Move(nId,{x:-nVal,y:0,mode:'relative',duration:nTime});
		setTimeout(function(){new Effect.Move(nId,{x:nVal,y:0,mode:'relative',duration:1});	},(nTime+2)*1000);	
		setTimeout(function(){aCustomMarqueeLocked[nId]=false;	},(nTime+3)*1000);	
		
	}
	
}



function clickOnPays(sIdPop,id){
	if(document.getElementById(sIdPop+'pays-only')){
		document.getElementById(sIdPop+'pays-only').value=id;
		reloadListing(sIdPop);
	}else{
		sendSearchWith({'idPop':sIdPop, 'search':Pays.id, 'value':id});
	}
}

function clickOnDistrict(sIdPop,idPays,idDistrict){
	
	if(document.getElementById(sIdPop+'pays-only')){
		document.getElementById(sIdPop+'pays-only').value=idPays;
	}
	if(document.getElementById(sIdPop+'district-only')){
		document.getElementById(sIdPop+'district-only').disabled=false;
		document.getElementById(sIdPop+'district-only').options.length=0;
		document.getElementById(sIdPop+'district-only').options[0]=new Option("",idDistrict); 
		document.getElementById(sIdPop+'district-only').options[0].selected=true;
		reloadListing(sIdPop);
	}else{
		sendSearchWith({'idPop':sIdPop, 'search':District.id, 'value':idDistrict});
	}
	
}

function clickOnVille(sIdPop,idPays,idDistrict,idVille,nom_ville){
	
	if(document.getElementById(sIdPop+'pays-only')){
		document.getElementById(sIdPop+'pays-only').value=idPays;
	}
	if(document.getElementById(sIdPop+'district-only')){
		document.getElementById(sIdPop+'district-only').disabled=false;
		document.getElementById(sIdPop+'district-only').options.length=0;
		document.getElementById(sIdPop+'district-only').options[0]=new Option("",idDistrict); 
		document.getElementById(sIdPop+'district-only').options[0].selected=true;		
	}
	if(document.getElementById(sIdPop+'ville-only')){
		document.getElementById(sIdPop+'ville-only').disabled=false;
		document.getElementById(sIdPop+'ville-only').options.length=0;
		document.getElementById(sIdPop+'ville-only').options[0]=new Option(nom_ville,nom_ville); 
		document.getElementById(sIdPop+'ville-only').options[0].selected=true;
		
	}
	//sendSearchWith({'idPop':sIdPop, 'search':'Ville.id', 'value':idVille});
	
	reloadListing();
	
	
}
function clickOnCp(sIdPop,idPays,idDistrict,idVille,nom_ville){
	
	if(document.getElementById(sIdPop+'pays-only')){
		document.getElementById(sIdPop+'pays-only').value=idPays;
	}
	if(document.getElementById(sIdPop+'district-only')){
		document.getElementById(sIdPop+'district-only').disabled=false;
		document.getElementById(sIdPop+'district-only').options.length=0;
		document.getElementById(sIdPop+'district-only').options[0]=new Option("",idDistrict); 
		document.getElementById(sIdPop+'district-only').options[0].selected=true;		
	}
	if(document.getElementById(sIdPop+'ville-only')){
		document.getElementById(sIdPop+'ville-only').disabled=false;
		document.getElementById(sIdPop+'ville-only').options.length=0;
		document.getElementById(sIdPop+'ville-only').options[0]=new Option(nom_ville,nom_ville); 
		document.getElementById(sIdPop+'ville-only').options[0].selected=true;
		
	}
	sendSearchWith({'idPop':sIdPop, 'search':'Ville.id', 'value':idVille});
	
	//reloadListing();
	
	
}