compt=0;
comp=0;
teminfo=0;
Tempo=null;

nav=(document.all)?"all":(document.getElementById)?"id":(document.layers)?"layers":null;

function start(nomobj) {
	if (document.all) {
		obj=window.document.all.tags('DIV')[nomobj];
	}
	if (document.getElementById) {
		obj=window.document.getElementById(nomobj);
	}
	if (document.layers) {
		obj=window.document.layers[nomobj];
	}
	return obj;
}

function pictpop() {
	obj=start("TaillesLYR");
	if (comp==0) {
		picton();
		comp=-5;
		return;
	} else {
		pictoff();
		return;
	}
	return;
}

function omnipict() {
	if (document.layers) {
		obj=start("TaillesLYR");
		if (comp==0) {
			picton();
			comp=-5;
			return;
		} else {
			pictoff();
			return;
		}
	}
	return;
}

function info() {
	obj=start("InfoLYR");
	if (teminfo==0) {
		obj.style.left=470;
		obj.style.visibility="visible";
		teminfo=-5;
		return;
	} else {
		obj.style.visibility="hidden";
		teminfo=0;
		return;
	}
	return;
}

function pictonoff(div) {
	obj=start(div);
	if (obj.style.display=="block") {
		obj.style.display="none";
		return false;
	} else {
		obj.style.display="block";
		return true;
	}
	return;
}

function menuOff() {
	obj=start('surLyr1')
	obj.style.visibility="hidden";
	obj=start('surLyr2')
	obj.style.visibility="hidden";
	return;
}

function menuOn(num) {
	menuOff();
	obj=start('surLyr'+num);
	obj.style.visibility="visible";
	switch (num) {
		case 1 :
			obj=start('newsLyr');
			obj.style.visibility="visible";
			break;
		case 2 :
			obj=start('datesLyr');
			obj.style.visibility="visible";
			break;
	}
}

function picton(div) {
	obj=start(div);
	obj.style.display="block";
	return;
}

function affPict(div) {
	obj=start(div);
	obj.style.visibility="visible";
	return;
}

function effPict(div) {
	obj=start(div);
	obj.style.visibility="hidden";
	return;
}

function pictoff(div) {
	obj=start(div);
	obj.style.display="none";
	return;
}

function replacement(div,x,y) {
	obj=start(div);
	obj.style.left=x;
	obj.style.top=y-55;
	return;
}

function mov(comptini,compt,anim) {
	if (Tempo) clearTimeout(Tempo);
	for (i=0;i<anim.length;i++) {
		obj=start(anim[i][0]);
		x1=anim[i][1];
		y1=anim[i][2];
		x2=anim[i][3];
		y2=anim[i][4];
		X=x1+(((x2-x1)/comptini)*(comptini/compt));
		Y=y1+(((y2-y1)/comptini)*(comptini/compt));
		obj.style.visibility="hidden";
		obj.style.left=X;
		obj.style.top=Y;
		obj.style.visibility="visible";
	}
	if (compt>1) {
		newcompt=compt-1;
		Tempo=setTimeout('mov(10,newcompt,anim)',1);
	}
	return;
}

function F_onLoaded() {
	comp=0;
	anim=Array();
		anim[0]=new Array('StringTextLYR',518,250,500,365);
		anim[1]=new Array('OceanTextLYR',515,270,525,325);
		anim[2]=new Array('Ete2003TextLYR',509,290,538,285);
		anim[3]=new Array('HomewearTextLYR',500,310,543,245);
		anim[4]=new Array('Hiver2003TextLYR',487,330,538,205);
		anim[5]=new Array('PermanentsTextLYR',468,350,520,165);
	
		anim[6]=new Array('TitrePermanentLYR',484,145,510,150);
		anim[7]=new Array('TitreHiver2003LYR',494,160,528,190);
		anim[8]=new Array('TitreHomewearLYR',502,175,533,230);
		anim[9]=new Array('TitreEte2003LYR',508,190,528,270);
		anim[10]=new Array('TitreOceanLYR',513,205,515,310);
		anim[11]=new Array('TitreStringLYR',516,220,490,350);
		
		anim[12]=new Array('AubadeLYR',500,394,328,335);

	Tempo=setTimeout('mov(10,10,anim)',1);
	return;
}

function PopImg(nom,x,y) {
	str='<';
	var PopImg=null;
	var fic=nom;
	PopImg=window.open('image.html?fic='+fic+'&x='+x+'&y='+y,'photo','width='+x+',height='+y+',toolbar=no,scrolling=no,scrollbars=no,statusbar=no,titlebar=no,menubar=no,left=15,top=15,resizable=no,personalbar=no,locationbar=no');
	PopImg.focus();
	return;
}

function param() {
	i=1;
	str=new Array();
	nstr=new Array();
	nom=new Array();
	parametre=new Array();
	str[0]= unescape(location.search.substring(location.search.indexOf("=") + 1,location.search.length));
	if (str[0].indexOf("=")==-1) {
		parametre[0]=str[0]
	} else {
		parametre[0]= unescape(str[0].substring(0,str[0].indexOf("&")));
	}
	do {
		chaine= unescape(str[i-1].substring(str[i-1].indexOf("=")+1,str[i-1].length));
		str[i]=chaine;
		if (chaine.indexOf("=")==-1) {
		parametre[i]=chaine
		} else {
		parametre[i]= unescape(chaine.substring(0,chaine.indexOf("&")));
		}
		i++;
	}
	while (chaine.indexOf("=")!=-1)
	i=1;
	nstr[0]= unescape(location.search.substring(location.search.indexOf("?") + 1,location.search.length));
	if (nstr[0].indexOf("=")==-1) {
		nom[0]=nstr[0]
	} else {
		nom[0]= unescape(nstr[0].substring(0,nstr[0].indexOf("=")));
	}
	do {
		chaine= unescape(nstr[i-1].substring(nstr[i-1].indexOf("&")+1,nstr[i-1].length));
		nstr[i]=chaine;
		if (chaine.indexOf("=")==-1) {nom[i]=chaine
	} else {
		nom[i]= unescape(chaine.substring(0,chaine.indexOf("=")));}
		i++;
	}
	while (chaine.indexOf("&")!=-1)
	str="";
	crit="";
	return param;
}

function y2k(number)    { return (number < 1000) ? number + 1900 : number; }

function AnneeBis(annee) {
	if ((annee/4)   != Math.floor(annee/4))   return false;
	if ((annee/100) != Math.floor(annee/100)) return true;
	if ((annee/400) != Math.floor(annee/400)) return false;
	return true;
}

function getLongueurMois(annee,mois) {
	joursMois = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	joursMoisBis = new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	date = new Date(annee,mois,1);
	annee = y2k(date.getYear());
	if (AnneeBis(annee)) {
		joursMois = joursMoisBis;
	}
	return joursMois[mois-1];
}

function majDateSelect(form,select,annee,mois,jourActuel) {
	nbJourMois=getLongueurMois(annee,mois);
	tableau=new Array();
	tableau[0]="Jour";
	for (i=1;i<=nbJourMois;i++) {
		tableau[i]=i;
	}
	majSelect(form,select,tableau);
//	alert(jourActuel);
//	alert(nbJourMois);
	if (jourActuel>nbJourMois) {
		form[select].selectedIndex=nbJourMois;
	} else {
		form[select].selectedIndex=jourActuel;
	}
}
function AncienMajDateSelect(form,select,annee,mois,jourActuel) {
	nbJourMois=getLongueurMois(annee,mois);
	tableau=new Array();
	for (i=1;i<=nbJourMois;i++) {
		tableau[i]=i;
	}
	majSelect(form,select,tableau);
	if (jourActuel<=nbJourMois) {
		form[select].selectedIndex=jourActuel-1;
	} else {
		form[select].selectedIndex=0;
	}
}

function majSelect(form,select,tableau) {
	form[select].options.length=0;
	for (i=0;i<tableau.length;i++) {
		if (tableau[i]!=null&&tableau[i]!="") {
		var o=new Option(tableau[i],i);
		form[select].options[form[select].options.length]=o;
		}
	}
}

function popupcentre(page,nom,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function inputFichier(cible,max){
	this.compteur = 0;
	this.id = 0;
	if (max) {this.max=max;} else {this.max=-1;};
	this.addElement = function(element) {
		if (element.tagName=='INPUT'&&element.type=='file') {
			element.name = 'file_' + this.id++;
			obj=start(element.name);
//			alert(this.id);
			element.fichierInput = this;
			element.onchange = function(){
				this.style.position = 'absolute';
				this.style.top = '-20px';
				this.style.left = '0px';
				var nouvelElement = document.createElement('input');
				nouvelElement.type = 'file';
//				nouvelElement.style.position = 'absolute';
//				nouvelElement.style.top = '-50px';
//				nouvelElement.style.left = '1px';
				this.parentNode.insertBefore(nouvelElement,this);
				this.fichierInput.addElement(nouvelElement);
				this.fichierInput.addListRow(this);
			};
			if( this.max != -1 && this.compteur >= this.max ) {element.disabled = true;}
			this.compteur++;
			this.current_element = element;
		} else {
			alert('Désolé, ceci n\'est pas un élément input');
		}
	};
	this.addListRow = function(element) {
		document.FormAlbum.nbPhotos.value++;
		var ligne = document.createElement('div');
		ligne.style.margin = '5';
//		ligne.style.backgroundColor ="#3300FF";
		var photo = document.createElement('img');
		photo.src='file://'+element.value;
		photo.align='left';
		photo.style.width='80';
		photo.style.margin = '5';
//		var adresse = document.createElement('div');
//		adresse.innerHTML = element.value;
//		adresse.style.backgroundColor ="#CC3366";
		var supprBouton = document.createElement('img');
		supprBouton.src='im/b_suppr.gif';
		supprBouton.align='left';
		supprBouton.style.cursor='pointer';
		supprBouton.onmouseover=function(){this.src='im/b_suppr_ov.gif';};
		supprBouton.onmouseout=function(){this.src='im/b_suppr.gif';};
		supprBouton.style.margin = '5';
		var legendePhoto = document.createElement('input');
		legendePhoto.type="text";
		legendePhoto.length=60;
//		supprBouton.value = 'Supprimer';
		ligne.element = element;
		// Delete function
		supprBouton.onclick= function(){
			document.FormAlbum.nbPhotos.value--;
			this.parentNode.element.parentNode.removeChild(this.parentNode.element);
			this.parentNode.parentNode.removeChild(this.parentNode);
			this.parentNode.element.fichierInput.compteur--;
//			this.parentNode.element.fichierInput.current_element.disabled=false;
			return false;
		};
		ligne.appendChild(photo);
//		ligne.appendChild(adresse);
//		ligne.appendChild(legendePhoto);
		ligne.appendChild(supprBouton);
		cible.appendChild(ligne);
	};
}
