
function montre(id) {
	if( id != null ) {
		if (document.getElementById) {
			document.getElementById(id).style.display="block";
		} else if (document.all) {
			document.all[id].style.display="block";
		} else if (document.layers) {
			document.layers[id].display="block";
		}
	}
}

function cache(id) {
	if (document.getElementById) {
	document.getElementById(id).style.display="none";
	} else if (document.all) {
	document.all[id].style.display="none";
	} else if (document.layers) {
	document.layers[id].display="none";
	}
}


function appel_ajax(id,funct,act,param,sortie) {
 		var url = 'appel_ajax.php';
		var pars = 'funct=' + funct +'&act=' + act + '&sortie=' + sortie + '&vars= ' + param  ;
        	var myAjax = new Ajax.Updater(id, url, {method:'post', postBody:pars,
				Success: function(){
				var element = getElementById(id);
				element.innerHTML = r.reponseText;
				setTimeout ("liens_ajax ()",300);
// 				setTimeout ("init_load_array ()",300);
				},
				Failure:  function(){
				var ter = getElementById(id);
				ter.innerHTML = "Un problèmes à eu lieux lors du chargement de la gallerie . \n Merci de reouveller l'operation";
				setTimeout ("liens_ajax ()",300);
// 				setTimeout ("init_load_array ()",300);
				},
				Complete:  function(){
				var ter = getElementById(id);
				ter.innerHTML = "En cours";
				setTimeout ("liens_ajax ()",300);
// 				setTimeout ("init_load_array ()",300);
					}
				});
				setTimeout ("liens_ajax ()",300);
// 				setTimeout ("init_load_array ()",300);
};


// function head(){
// var descri = document.getElementsByTagName("meta");
// 	document.title= document.getElementById('hidden_title').innerHTML;
// }

function CollectElementbyClass (classname){ /*Returns an array containing DIVs with specified classname*/
	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i"); /*regular expression to screen for classname within element*/
	var pieces=[];
	var alltags=document.all? document.all : document.getElementsByTagName("*");
	for (var i=0; i<alltags.length; i++){
		if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
			pieces[pieces.length]=alltags[i];
	}
	return pieces;
}

	// public method for url encoding
function encode_utf8 (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	}


function liens_ajax(){

/*	if (document.getElementById) {
	var divglobal= document.getElementById('global');
	} else if (document.all) {
	var divglobal= document.all['global'];
	} else if (document.layers) {
	var divglobal= document.layers['global'];
	}
	var liens_sites = divglobal.getElementsByTagName('a') ;
	for (var i = 0 ; i < liens_sites.length ; ++i) {
		liens_sites[i].onclick  = function (){
			if (this.hash !="") montre('block_click');
		}
	}
*/

	var liens_site = CollectElementbyClass("ajax");
	var lib_funct = 'appel_ajax.php';
	var act = '';
	var sortie = 'true';

	for (var i = 0 ; i < liens_site.length ; ++i) {
		liens_site[i].onclick  = function (){
			var param = this.href;
				montre('overlay');
				appel_ajax('js_content',lib_funct,act,encode_utf8(this.href),sortie);
				montre('ajax');
				return false;
		}
	}


}
