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

/** Affiche la news selectionnée
 *	sender : action
 *  type   : variable foure-tout sert de reconnaissance d'onglet, ...
 *
 */
function onglet_ajax(sender, type){
	// 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 'change':
				if(flag) {
					$$('colgauche_ajax').innerHTML = '<img src="'+waiting+'" border="0" title="processing" alt="processing" />';
				}
				else {
					
				}
			break;
		}
	};
	
	/** ============== response =============
	 *
	 */     		
	var response = function (){
		//eval ('var options = '+ ajax.response);
		
		switch (sender) {
			case 'change':
				$$('accueil').src = HTMLURL+"images/banniere2/bouton-accueil.gif";
				$$('accueil').actuel = "0";
				$$('desc').src = HTMLURL+"images/banniere2/bouton-desc.gif";
				$$('desc').actuel = "0";
				$$('tourisme').src = HTMLURL+"images/banniere2/bouton-tourisme.gif";
				$$('tourisme').actuel = "0";
				$$('tarifs').src = HTMLURL+"images/banniere2/bouton-tarifs.gif";
				$$('tarifs').actuel = "0";
				$$('contact').src = HTMLURL+"images/banniere2/bouton-contact.gif";
				$$('contact').actuel = "0";
				$$('liens').src = HTMLURL+"images/banniere2/bouton-liens.gif";
				$$('liens').actuel = "0";
				if($$(type) != null)
				{
					$$(type).src = HTMLURL+"images/banniere2/bouton-"+type+"-over.gif";
					$$(type).actuel = "1";
				}
				
				$$('colgauche_ajax').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, exécute un eval() sur le contenu de ajax.response;
	ajax.execute = false;
	ajax.onCompletion = response;
	
	// action controller
	switch (sender) {
		case 'change':
			action = 'public/onglet_change';
		break;
		
		default:
			alert ('Action non gÃ©rÃ©e');
			action = null;
		break;
	}
	
	if (action){
		// passe les variables :
		ajax.setVar('type', type);
		ajax.setVar('action', action);
		ajax.runAJAX();
	} else {
		ajax = null;					
		processing(false);
	}
} // end onglet_ajax()
