function initAjaxPage() {
	// attribution des actions sur les select
	document.getElementById('selecteur_annuaire_pays').firstChild.lastChild.onchange = function() {
		moteurRechercheAnnuairePays(-2);
	}
	document.getElementById('selecteur_annuaire_categorie').firstChild.lastChild.onchange = function() {
		moteurRechercheAnnuaireCat()
	}
	// masquage des boutons de submit
	document.getElementById('submiteur').parentNode.style.display = 'none';
	document.getElementById('submiteur2').parentNode.style.display = 'none';
	
	// modification des liens de la carte pour passage dans l'ajax
	var tabPays = document.getElementById('carteAL').getElementsByTagName('AREA');
	for(var iTP=0; iTP<tabPays.length; iTP++) {
		// récupération du n° du pays dans le href du tag area
		tabPays[iTP].numPays = parseInt(tabPays[iTP].href.split('=')[1]);
		tabPays[iTP].href = 'javascript:void(0);';
		tabPays[iTP].onclick = function() {
			moteurRechercheAnnuairePays( this.numPays );
		}
	}
}

function moteurRechercheAnnuairePays( pays ){
	var success	= function(t){ 
		document.selecteur_annuaire_categorie.categorie.selectedIndex=0;
		document.getElementById('listing_annuaire').innerHTML = t.responseText;
		}
	var failure	= function(t){}
	
  	var url = '/clients/mal217ag/plugins/base_amis/update_annuaire.php';  	
  	
  	if( pays==-2 )
  		pays = document.selecteur_annuaire_pays.pays.options[document.selecteur_annuaire_pays.pays.selectedIndex ].value;
  	else {
  		var tabOptions = document.getElementById('selecteur_annuaire_pays').getElementsByTagName('OPTION');
  		for (var iTO=0; iTO<tabOptions.length; iTO++) {
  			if(tabOptions[iTO].value == pays)
  				document.selecteur_annuaire_pays.pays.selectedIndex = iTO;
  		}
  		
  	} 
  	url = url+ '?pays='+pays;
  	url = url + '&'+escape(new Date().toString());
	var myAjax = new Ajax.Request(url, {method:'get', onSuccess:success, onFailure:failure});	
}

function moteurRechercheAnnuaireCat( ){
	var success	= function(t){
		document.selecteur_annuaire_pays.pays.selectedIndex = 0;
		document.getElementById('listing_annuaire').innerHTML = t.responseText; 
		}
	var failure	= function(t){}
	
  	var url = '/clients/mal217ag/plugins/base_amis/update_annuaire.php';  	
  	
  	categorie = document.selecteur_annuaire_categorie.categorie.options[document.selecteur_annuaire_categorie.categorie.selectedIndex].value;
  	
  	url = url+ '?categorie='+categorie;
	url = url + '&'+escape(new Date().toString());
	var myAjax = new Ajax.Request(url, {method:'get', onSuccess:success, onFailure:failure});	
}


/****************************************************/
/*				INITIALISATION DE LA PAGE			*/
/****************************************************/
function addLoadListenerAnnuaire(func) {
	if (window.addEventListener) {
		window.addEventListener("load", func, false);
	} else if (document.addEventListener) {
		document.addEventListener("load", func, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", func);
	}
}

if (document.getElementById && document.createTextNode) {
	addLoadListenerAnnuaire(function() {
		initAjaxPage();
	});
}