/* Fonctions générales */

function EcrireCookie(nom, valeur){
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}



function getCookieVal(offset){
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr)); 
}



function LireCookie(nom){
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null; 
}

function EffaceCookie(nom){
	date=new Date;
	date.setFullYear(date.getFullYear()-1);
	EcrireCookie(nom,null,date); 
}


/* Fonctions Dreamweaver */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//////////////////////////////////////////////////////////




/* Fonctions relatives à la gestion du menu */

if(document.all)var selection="document.all";
if(document.getElementById)var selection="document.getElementById";

var element;
var selementActive;
var premierSelement;

function menu(menu){
		with(selection){
			element=menu.style;
			element.visibility=='visible'?element.visibility='hidden':element.visibility='visible';
		}
}


function smenu(smenu){
	if(premierSelement && !selementActive){
		selementActive=eval(premierSelement);
		selementActive.style.display='none';
	}
		with(selection){
		selement=smenu.style;
		if(selementActive){	
			if(selement!=selementActive){
				selementActive.display='none';
				if(img=arguments[1])imgActive.src=imgActive.src.replace("_B","_D");
				}
			}
			
		if(selement.display=='block'){
			selement.display='none';
			if(img=arguments[1])img.src=img.src.replace("_B","_D");
			
		} else {
			selement.display='block';
			if(img=arguments[1])img.src=img.src.replace("_D","_B");
		}
		
		selementActive=selement;
		imgActive=img;
		
	}
}


function deplie(pole,img){
	src=eval ("document.images."+img+".src");
	
	with(selection){
		if(pole.style.display=='none'){
			
			for(i=0;i<=Elements.length-1;i++){
				Tsrc=eval ("document.images.imgpole"+Elements[i]+".src");
				Tsrc=Tsrc.replace(/_ouvert/,'_ferme');
				eval("pole"+Elements[i]+".style.display='none'");
				eval("document.images.imgpole"+Elements[i]+".src='"+Tsrc+"'");
			}
			
			pole.style.display='block';
			src=src.replace(/_ferme/,'_ouvert');
			eval("document.images."+img+".src='"+src+"'");
			
			} else {
			pole.style.display='none';
			src=src.replace(/_ouvert/,'_ferme');
			eval("document.images."+img+".src='"+src+"'");
		}
	}
}

function saisir(nomChamp,nomFormulaire){
	
	with( eval("document.forms."+nomFormulaire+"") ){
		var valeur=eval(nomChamp+".value");
		var defaut=eval(nomChamp+".defaultValue");
		
			if( valeur==defaut)  {
				eval(nomChamp+".value=''");
				}
			if (valeur==''){
				eval(nomChamp+".value='"+defaut+"'");
				}
		}
}
//////////////////////////////////////////////////////////


/* Fonctions relatives au sticker */

var timer = null;
var speed = 5;

var obj = Array();

var taille = Array();
var tailleTotale=0;
var pos=0;
var tempsPause=2000;

var nbElements=null;
var elementFocus;

function InitObj() {
if(nbElements!=null){
	
	for(i=1;i<=nbElements;i++){
		obj[i] = document.getElementById("contenu"+i+"");
		taille[i] = obj[i].offsetHeight;
		obj[i].style.visibility='visible';
		obj[i].style.top=pos+'px';
		
		pos +=taille[i];
		tailleTotale=pos;
		}
		
		Prompteur();
	}
	
	// Donne le focus aux textearea
	textarea = document.getElementsByTagName('textarea');  
	
	for(i in textarea){ 
		textarea[i].onmousedown=function(){      
		this.focus();
		elementFocus=this;  
		with(selection){ if(typeof(tools)!='undefined')tools.style.display='block';}
		}
	}
}


function Prompteur(){	
if(nbElements>1) {
	 for(i=1;i<=nbElements;i++){	

			if( parseInt(obj[i].style.top) > -obj[i].offsetHeight) {
			obj[i].style.top = (parseInt(obj[i].style.top) - 1)+'px';
				if ( parseInt(obj[i].style.top) == 0 ){
					if(document.getElementById("conteneur").style.height<taille[i]*2){
						document.getElementById("conteneur").style.height=taille[i];
						}
					speed=tempsPause;
					}
			}

			else {
				obj[i].style.top=tailleTotale-taille[i]+'px';
				}
		}
		timer = setTimeout("Prompteur()",speed);
		pos = 0;
		speed=5;
	}
}


function Stop(){
    clearTimeout(timer);
}
//////////////////////////////////////////////////////////


/*  Fonctions d'administration  */
var confirmation=false;
function confirmer(){
	if (confirm("Voulez-vous confirmer cette action ?")){
		confirmation=true;
	}
}

var message;
if(typeof(message)=='undefined')message="Merci de bien vouloir indiquer";

var envoi=false;
function valider(){
	with(arguments[0]){
	 for (var i = 1; i < arguments.length; i++) {
		arguments[i].value=arguments[i].value.replace(/(^\s*)|(\s*$)/g,'');
		if( arguments[i].value ==''){
			document.all.message_erreur.innerHTML = message+" "+arguments[i].label;
			envoi=false;
			break;
			}	
		else {envoi=true;}
		 }
	}
	document.location.href="#validation";
}


function fondColor(cible, box){
	with(selection){cible.bgColor=(box.checked==true)?'#FFFFFF':'#E6E6E6';}
}


function popup(url,largeur,hauteur){
	var fen=window.open(url,"fiche","toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0,width="+largeur+", height="+hauteur+"");
	var gauche = (screen.width - largeur)/2;
	var haut = ((screen.height - hauteur)/2);
	fen.moveTo (gauche,haut);
	if (fen.blur)fen.focus();
}



function popupDate(url,champ,largeur,hauteur){
	with(selection){
		if(champ.value) var dateNews=champ.value;
	}
	
	var popupFiche=window.open(url+"?dateNews="+dateNews+"&champ="+champ.name+"","fiche","toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0,width="+largeur+", height="+hauteur+"");
	var gauche = (screen.width - largeur)/2;
	var haut = ((screen.height - hauteur)/2);
	popupFiche.moveTo (gauche,haut);
	if (popupFiche.blur)popupFiche.focus();
	
}

function ordonner( champ, acte, maxi ){
	val = parseInt(champ.value)+acte;
		if ( (val<=maxi)&&(val>=1) ){
			for(i=1;i<=maxi;i++){
				if( eval(ordreChamp+i).value == val){
				chgVal=val+(acte*-1);
				eval (ordreChamp+i).value = chgVal;
				
				// Affichage de l'ordre dans le cadre d'une pagination
				if(typeof(ordreVue)!='undefined'){
					if(eval (ordreVue+i)){
						eval (ordreVue+i).value = chgVal;
						}
					}
				//
				}
			//
			}
			
			champ.value = val;
			
			// Affichage de l'ordre dans le cadre d'une pagination
			if(typeof(ordreVue)!='undefined'){
				var nom = ordreChamp.split(".");
				nom = nom[nom.length-1];
				var num = champ.name.split(nom);
				num = num[num.length-1];
				eval(ordreVue+num).value = val;
				
				// Définit la page de retour
				pageEncours=Math.ceil(val/nbReponses);
				pageEncours=pageEncours-1;
				eval(limit).value = pageEncours*nbReponses;
				//
			}
	  }
}



function ordonnerBis( champ, acte, maxi ){
	val = parseInt(champ.value)+acte;
		if ( (val<=maxi)&&(val>=1) ){
			for(i=1;i<=maxi;i++){
				if( eval(ordreChampBis+i).value == val){
				chgVal=val+(acte*-1);
				eval (ordreChampBis+i).value = chgVal;
				}
				
			champ.value = val;
			}
		}
}

// Fonctions de mise en forme

function format(f) {
	if(elementFocus){
	elementFocus.focus();
	var str = document.selection.createRange().text;
	var sel = document.selection.createRange();

	sel.text = "<" + f + ">" + str + "</" + f + ">";
	}
}


function del(){
var str = document.selection.createRange().text;
	var tag = new RegExp("(<[0-9a-zA-Z]+)>|(</[0-9a-zA-Z]+>)","gi");
	str=str.replace(tag,'');
	document.selection.createRange().text=str;
}

function clip(){
with(document.getElementById("clip")){
	if(style.display=='none')style.display='block';
	}
}

//////////////////////////////////////////////////////////

onload=InitObj;
