//  BIBLIO JAVASCRIPT GENERALE
//  (c) Web Project - www.w-project.com

// -- Changement d'image au passage de la souris sur l'image "nom" (défini par name="nom")
//	x="off"	-> src image = src root + "-off"
//	x="on"	-> src image = src root + "-on"
//	x="act"	-> src image = src root + "-act"
//	exception : si la variable "menu_actif" = nom, seul x=actif est pris en compte
//	le nom d'image doit être sous la forme path/nom-xx.ext 
	function allume(nom,x) {
		if(x=='act' || nom != menu_actif) {
			var n=document.images[nom]
			if(n) n.src=get(n.src,"path") + nom + "-" + x + "." + get(n.src,"ext");
		}
	}
	

// -- Préchargement d'une image dans le cache
	var imgload=0;
	var image=new Array;
	function img_load(nom,x) {
		var n=document.images[nom];
		if(n) {
			image[imgload]= new Image;
			image[imgload++].src= get(n.src,"path") + nom + "-" + x + "." + get(n.src,"ext");
		}
	}

//-- extract de parties d'un nom de fichier 'nom' selon valeur de 't'
//-- t="path" -> retourne path terminé par '/'
//-- t="fullname" -> retourne nom + extension de fichier, sans path
//-- t="name" -> retourne nom de fic sans extension ni path
//-- t="ext" -> retourne extension du fichier sans path ni nom
	function get(nom,t) {
		var n="", i=nom.lastIndexOf("."), j=nom.lastIndexOf("/");
		if(i==-1) i=nom.length;
		if (t=="path") n=nom.substring(0,j) + "/";
		else if(t=="fullname") n=nom.substring(j+1);
		else if(t=="name") n=nom.substring(j+1,i);
		else if(t=="ext") n=nom.substring(i+1);
		return n;
	}

// ---------------------------------------
//          Date utilities
// ---------------------------------------

// -- Affichage date du jour
// -- t = type d'affichage (0 -> 10/02/00, 1 -> 10 février 2000)
// -- l = format (fr -> français, uk -> anglais)
	function aff_date(t,l) {
		var date=new Date();
		FixDate(date);	//fix a Mac OS bug
		a= date.getYear();
		if(a<1900) a+=1900;	//Netscape 4.06 bug
		a=a.toString();
		if(t==0) {
			var j,m,a;
			j= '0' + date.getDate().toString();
			j= j.substring(j.length-2);
			m= '0' + (date.getMonth()+1).toString();
			m= m.substring(m.length-2);
			a= a.substring(a.length-2);
			if(l=='fr') document.write(j + "/" + m + "/" + a);
			else if (l=='uk') document.write(m + "/" + j + "/" + a);
		}
		else if(t==1) {
			if(l=='fr') {
				var mois=new Array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
				document.write(date.getDate() + " " + mois[date.getMonth()] + " " + a);
			}
			else if(l=='uk') {
				var mois=new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
				document.write(mois[date.getMonth()] + " " + date.getDate() + ", " + a);
			}
		}
	}

// -- Function to correct for 2.x Mac date bug.  Call this function to
//	fix a date object. Call with :
//	var theDate = new Date();
//	FixDate(theDate);
	function FixDate(date) {
		var base = new Date(0);
		var skew = base.getTime();	// dawn of (Unix) time - should be 0
		if (skew > 0)			// Except on the Mac - ahead of its time
		date.setTime(date.getTime() - skew);
	}

// ---------------------------------------
//     Relative adresses translation
// ---------------------------------------

//- get relative path of target "l" vs "s"
function get_rpath(l,s) {
	var lf='';	//final relative path
	var j=s.indexOf('//');
	if(j>-1) s=s.substring(j+2);			//extract the initial http://

	//-- calculates relative address
	var i=0, j=0;
	var tadd=get_path(l,i),sadd;
	if(tadd) {	//target has an absolute path
		sadd=' ';
		while(sadd && tadd != sadd) {
			sadd=get_path(s,j);
			j+= sadd.length + 1
		}

		if(!sadd) j=0; else i+= tadd.length + 1;

		// -- extract common part of paths
		while(tadd && tadd==sadd) {
			tadd=get_path(l,i)
			sadd=get_path(s,j)
			if(tadd && tadd==sadd) {
				i+= tadd.length + 1;
				j+= sadd.length + 1;
			}
		}

		// -- add any required "../"
		while(sadd) {
			j+= sadd.length + 1;
			lf+= '../'
			sadd=get_path(s,j);
		}

	}
	lf+= l.substring(i);
	return lf;
}

//- get next path
function get_path(x,p) {
	var r='', i;
	while(x.charAt(p)=="/") p++;		//del. initial "/" or "//" (ex. : path from hdu)
	i=x.indexOf('/',p);
	if(i>-1) r=x.substring(p,i);
	return r;
}

var path=get_rpath('francais/',get(document.location.toString(),'path'));
