
function refreshGoTop() {
	// Masque ou affiche le lien "top" en fonction de la taille de la fenêtre
	if(document.getElementById('gotop')) {
		h_body = (getSize(document.getElementById('body'))).h;
		document.getElementById('gotop').style.visibility = (h_body > getWindowHeight() ? "visible" : "hidden");
	}

}



function bookmark() {
	// Fonction d'ajout de bookark (navigateur)
	if(nav['Name'] == "Internet Explorer" && nav['Version'] >=4)
		window.external.AddFavorite(window.location + "", document.title);
	else if(nav['Name'] == "Safari") 
		alert("Hit COMMAND+D to bookmark this site.");
	else
		alert("Hit CTRL+D to bookmark this site.");
}




function showID(id) {
	// Affiche l'élément id
	if(document.getElementById(id))
		document.getElementById(id).style.display = "block";
}


function maskID(id) {
	// Masque l'élément id
	if(document.getElementById(id))
		document.getElementById(id).style.display = "none";
}


function show_vis(id) {
	// Affiche l'élément id
	if(document.getElementById(id))
		document.getElementById(id).style.visibility = "visible";
}

function mask_vis(id) {
	// Masque l'élément id
	if(document.getElementById(id))
		document.getElementById(id).style.visibility = "hidden";
}





function fade_show(id, duration) {
// Affiche l'element ID en faisant un fading
	if (!duration)
		duration = 0.4;

	try {
		if(document.getElementById(id)){
			if(id=="login_div"){
				// focus sur le username
				new Effect.Appear(id, { duration: duration, afterFinish:function(res){$("username").focus();}});
			}
			else
				new Effect.Appear(id, { duration: duration });
		}
	}
	catch (e) {
		showID(id);
	}
}


function fade_mask(id, duration) {
// Masque l'element ID en faisant un fading
	if (!duration)
		duration = 0.4;

	try {
		if(document.getElementById(id))
			new Effect.Fade(id, { duration: duration });
	}
	catch (e) {
		maskID(id);
	}
}



function fadeToggle(id, duration) {
// Alterne l'affichage / masquage de l'element ID
	if (!duration)
		duration = 0.4;

	if(document.getElementById(id)) {
		if(document.getElementById(id).style.display == "none")
			fade_show(id, duration);
		else
			fade_mask(id, duration);
	}
}






function setURLValue(url, nomParam, valeurParam) {
// ajoute (ou modifie si existant dans l'URL) un paramètre d'URL
// Si [argument 1] = ""  ->  url = document.location.href
// exemple : setURLValue("", "s", 50);

	if(url=="")
		url = document.location.href;

	url2set = nomParam + "=" + valeurParam;

	if ( url.indexOf("?") == -1 ) {
		return url + "?" + url2set;
	}
	if ( (pos=(url.indexOf("?"+nomParam+"="))) == -1 && (pos=(url.indexOf("&"+nomParam+"="))) == -1 ) {
		return url + "&" + url2set;
	}
	
	url1 = url.substring(0, pos + 1);
	url2 = url.substring(pos + 1 + nomParam.length + 1);
	
	if ( (pos=(url2.indexOf("&"))) == -1 )
		return url1 + url2set;
	
	url2 = url2.substring(pos);

	return url1 + url2set + url2;
}








// FONCTIONS UTILISEES POUR LES TAILLES / LE POSITIONNEMENT D'ELEMENTS //

function getWindowHeight() {
	// Retourne la hauteur de la fenêtre
	var windowHeight = 0;
	if(typeof(window.innerHeight)=='number')
		windowHeight = window.innerHeight;
	else if(document.documentElement && document.documentElement.clientHeight)
		windowHeight = document.documentElement.clientHeight;
	else if(document.body && document.body.clientHeight)
		windowHeight = document.body.clientHeight;
	return windowHeight;
}
function getDocumentHeight() {
	return getWindowHeight();
}

function getWindowWidth() {
	// Retourne la largeur de la fenêtre
	var windowWidth = 0;
	if(typeof(window.innerWidth)=='number')
		windowWidth = window.innerWidth;
	else if(document.documentElement && document.documentElement.clientWidth)
		windowWidth = document.documentElement.clientWidth;
	else if(document.body && document.body.clientWidth)
		windowWidth = document.body.clientWidth;
	return windowWidth;
}
function getDocumentWidth()	{
	return getWindowWidth();
}


function getPosition(element) {
	// Retourne la position de l'objet envoyé en paramètre
	var elem=element, tagname="", x=0, y=0;
  
	while ((typeof(elem)=="object") && (typeof(elem.tagName)!="undefined")) {
		y+=elem.offsetTop;
		x+=elem.offsetLeft;
		tagname=elem.tagName.toUpperCase();

		if(tagname=="BODY")
			elem=0;

		if(typeof(elem)=="object")
			if (typeof(elem.offsetParent)=="object")
				elem=elem.offsetParent;
	}

	position = new Object();
	position.x = x;
	position.y = y;
	return position;
}

function getPosition2(element) {
// Retourne la position de l'objet envoyé en paramètre
	var elem=element, tagname="", x=0, y=0;
  
	y+=elem.offsetTop;
	x+=elem.offsetLeft;

	position = new Object();
	position.x = x;
	position.y = y;
	return position;
}




function getSize(element) {
// Retourne la taille de l'objet envoyé en paramètre
	var elem=element, w=0, h=0;

	w+=elem.offsetWidth;
	h+=elem.offsetHeight;

	position = new Object();
	position.w = w;
	position.h = h;
	return position;
}





/*	FONCTIONS DE ZOOM (compatible seulement sur IE6 et plus)	*/

currentZoom = 1;
pasZoom = 0.25;

function zoom(z) {
	currentZoom = z;
	document.getElementById('body').style.zoom = z;
//	document.getElementById('q').value = z;
}

function zoom_in() {
	val = Math.round((currentZoom+pasZoom)*100)/100;
	if(val < 10)
		zoom(val);
	else
		alert("Unable to zoom in again !");
}

function zoom_out() {
	val = Math.round((currentZoom-pasZoom)*100)/100;
	if(val > 0.2)
		zoom(val);
	else
		alert("Unable to zoom out again !");
}






/*	FONCTIONS D'ENCODAGE URL	*/

function URLEncode(url) {
	
	i=0;
	while(url.indexOf("%") > 0 && i++ < 1000)
		url = url.replace("%", "¤¤");
	
	i=0;
	while(url.indexOf(" ") > 0 && i++ < 1000)
		url = url.replace(" ", "%20");
	i=0;
	while(url.indexOf("+") > 0 && i++ < 1000)
		url = url.replace("+", "%2B");
	i=0;
	while(url.indexOf("=") > 0 && i++ < 1000)
		url = url.replace("=", "%3D");
	i=0;
	while(url.indexOf("&") > 0 && i++ < 1000)
		url = url.replace("&", "%26");


	while(url.indexOf("¤¤") > 0 && i++ < 1000)
		url = url.replace("¤¤", "%25");

	return url;
}

function URLDecode(url) {

	i=0;
	while(url.indexOf("%25") > 0 && i++ < 1000)
		url = url.replace("%25", "%");

	i=0;
	while(url.indexOf("%20") > 0 && i++ < 1000)
		url = url.replace("%20", " ");
	i=0;
	while(url.indexOf("%2B") > 0 && i++ < 1000)
		url = url.replace("%2B", "+");
	i=0;
	while(url.indexOf("%3D") > 0 && i++ < 1000)
		url = url.replace("%3D", "=");
	i=0;
	while(url.indexOf("%26") > 0 && i++ < 1000)
		url = url.replace("%26", "&");

	return url;
}

function show_step(s){
	if(selected_step!=s){
		$('map_step').innerHTML=step[s-1];
		$('my_map').style.backgroundImage="url(/img/my_map_bg"+s+".jpg)";
		/*if(s=="3")
		{
			$('map_create').innerHTML="<a href='/map/create.php'>créer</a>";
			$('map_step3').style.cursor="default";
		}
		else
		{
			$('map_create').innerHTML="";
			$('map_step3').style.cursor="pointer";
		}*/
		selected_step=s;
	}
}

function supprDoi(t, doi)
{
	new Ajax.Request('/no-cache/ajax_media_favorites.php?supprDoi='+doi, 
		{asynchronous:true,onComplete:function(res){
				t.parentNode.innerHTML="&nbsp;";
				$(""+doi).innerHTML=res.responseText;
			}
		}
	);
}