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

/** 
 * Renvoie une des news actives aléatoirement
 *	sender : action
 *
 */
function get_news(sender){
	// 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 'news':
				if(flag) {
					$('dynamic_news').innerHTML = '<img src="'+waiting+'" border="0" title="processing" alt="processing" />';
				}
				else {
					
				}
			break;
		}
	};
	
	/** ============== response =============
	 *
	 */     		
	var response = function (){
		//eval ('var options = '+ ajax.response);
		
		switch (sender) {
			case 'news':
				$('dynamic_news').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 'news':
			action = 'news/get_news';
		break;
		
		default:
			alert ('Action non gérée');
			action = null;
		break;
	}
	
	if (action){
		// passe les variables :
		ajax.setVar('action', action);
		ajax.runAJAX();
	} else {
		ajax = null;					
		processing(false);
	}
} // end update_country()
