/** ajax handler on client Side
 *  tous les appels ajax arrivent sur le point d'entree ajax.php à la racine.
 *
 *
 *
 */    

/** Affiche les agences correspondantes à l'id de la region
 *	sender : id de la region
 *
 *
 */
function gerer_presentation(sender, id){
	// properties
	var action = null;
	
	var processing = function(flag) {
		// wait indicator
		var waiting =  BASEURL + 'ajax/img/indicator.gif';
		var done    = BASEURL + 'ajax/img/spacer.gif';
		
		switch (sender) {
			case 'agence':
				if(flag) {
					$('progress').src = waiting;
				}
				else {
					$('progress').src = done;
				}
			break;
		}
	};
	
	/** ============== response =============
	 *
	 */     		
	var response = function (){
		//eval ('var options = '+ ajax.response);
		
		switch (sender) {
			case 'agence':
				$('liste_agence').innerHTML = ajax.response;
				break;
		}
		
		// waiting indicator
		processing(false);
	};
	
	
	//  ==============  contructor : make request  =========================
	
	// waiting indicator
	processing(true);
	
	var ajax = new sack();
	if (ajax.failed) {
		alert ('Ajax Failed !!!');
	}
	
	ajax.requestFile = BASEURL + "ajax.php?location=public";
	// si ajax.execute est vrai, execute un eval() sur le contenu de ajax.response;
	ajax.execute = false;
	ajax.onCompletion = response;
	
	// action controller
	switch (sender) {
		case 'agence':
			action = 'presentation/view_agence';
		break;
		
		default:
			alert ('Action non gÃ©rÃ©e');
			action = null;
		break;
	}
	
	if (action){
		// passe les variables :
		ajax.setVar('id_region', id);
		ajax.setVar('action', action);
		ajax.runAJAX();
	} else {
		ajax = null;					
		processing(false);
	}
} // end update_country()
