
// fonction qui charge dans la frame contenu les 2 pages d'URL passées en paramètre
function ChargeFramesetContenu(PageHaut,PageBas){
top.PageHaut = PageHaut ;
top.PageBas = PageBas ;
top.contenu.location.href = "contenu.asp";
}

// fonction qui charge dans la frame contenu les 2 pages d'URL passées en paramètre
function ChargeFramesetContenu2(PageHaut,PageBas){
top.PageHaut = PageHaut ;
top.PageBas = PageBas ;
top.contenu.location.href = "../contenu.asp";
}

// redirige vers l'URL passée en paramètre
function GoTo(URL){
	document.location.replace(URL);
}

// ouvre une popup vers l'URL passée en paramètre
function PopUp(URL,W,H){
	newWin = window.open(URL,'POPUP','toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width='+W+',height='+H); 
	newWin.focus();
}

// ouvre une popup vers l'URL passée en paramètre
function PopUpNoScroll(URL,W,H){
	newWin = window.open(URL,'POPUP','toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no,width='+W+',height='+H); 
	newWin.focus();
}

// imprime la page courante
function Imprime(Prec){
	//top.contenu.replace(top.contenu.location.href+'&imprime=OUI');
	//TXT = new String(top.contenu.location.href);
	//nbp = TXT.indexOf("?");
	//if ( nbp>0){ TXT = TXT +"&" ; }else{ TXT = TXT + "?"}
	//TXT = TXT + "imprime=OUI";
	//alert(TXT);
	//top.contenu.location.replace(TXT);
	newWin = window.open(Prec+'impression.asp','IMPRESSION','toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=500'); 
	newWin.focus();
}

/*Remplace dans une chaîne de charactères un caractère particulier par un autre
I :: oldtext = chaîne de charactère où doit être fait le remplacement
I :: chars1 = charactère à changer
I :: chars2 = charactère de changement
corrigée pour le problème de récursivité....
*/
function remplacer(oldText,chars1,chars2){
	ChaineATraiter = new String(oldText);
	ChaineTraitee = new String("");
	Tchars1 = chars1.split("|");
	Tchars2 = chars2.split("|");
	
	for (var i=0; i<Tchars1.length; i++){
		var pos = ChaineATraiter.indexOf(Tchars1[i]);
		while (pos != -1) {
			//alert("pos="+pos);
			ChaineTraitee += ChaineATraiter.substr(0,pos) + Tchars2[i] ;
			ChaineATraiter = ChaineATraiter.substr(pos+Tchars1[i].length);
			pos = ChaineATraiter.indexOf(Tchars1[i]);
		}
	}
	//alert("avant : "+oldText+ "après : "+ChaineTraitee+ChaineATraiter+"      cherché : "+chars1+" par : "+chars2);
	return(String(ChaineTraitee+ChaineATraiter));
}


//Fonction qui permet de remplaver des caracteres speciaux par d'autres moins problematique
function FraRemplacer(vVariable){
	//vVariable=remplacer(vVariable,"'","¤");
	vVariable=remplacer(vVariable,"'","\'");
	vVariable=remplacer(vVariable,"&",":::");
	vVariable=remplacer(vVariable,"\\",";;;");
	vVariable=remplacer(vVariable,"#","ùùù");
	vVariable=remplacer(vVariable,"%","***");
	return(vVariable);
}
//Fonction qui permet d'afficher la date du jour formaté en Le 00 Mois Année
function ecrire_date()
{
	var mois= new Array(12);

	mois[0]= "Janvier";
	mois[1]= "Février";
	mois[2]= "Mars";
	mois[3]= "Avril";
	mois[4]= "Mai";
	mois[5]= "Juin";
	mois[6]= "Juillet";
	mois[7]= "Aout";
	mois[8]= "Septembre";
	mois[9]= "Octobre";
	mois[10]= "Novembre";
	mois[11]= "Décembre";
	aujourd_hui = new Date();
	document.write("<font size=2 type=Arial color=black><b>Le&nbsp;" + aujourd_hui.getDate() + "&nbsp;" + mois[aujourd_hui.getMonth()] + "&nbsp;" + aujourd_hui.getFullYear()+"&nbsp;</font></b>");
}

// teste si la chaine est vide ou composée d'espaces
function Est_vide(STR)
{
	STRC = remplacer(STR," ","");
	//alert ("test_vide STR ='"+STR+"' STRC='"+STRC+"' bl="+(STRC == ""));
	return (STRC == "");
}

/***************************************************/
/****** fonctions spécifiques au back-office *******/
/***************************************************/

//Formattage pour enregistrement Base de données
function FormaterPourBD(vVariable){
	vVariable = remplacer(vVariable,"'","''");
	vVariable = remplacer(vVariable,"&",":::");
	vVariable = remplacer(vVariable,"\\",";;;");
	vVariable =  remplacer(vVariable,"#","ùùù");
	vVariable = remplacer(vVariable,"%","***");
	vVariable = remplacer(vVariable,"&#180;","''");
	return(vVariable);
}

// Change l'ordre de tri d'une liste
function NouveauTri(OrderBy){
	document.Recherche.CompteurChamp.value = 1 ;
	document.Recherche.Start.value = 1 ;
	document.Recherche.OrderBy.value = OrderBy ;
	document.Recherche.submit();
	return;
}

// Change l'ordre de tri d'une liste
function NouvellePage(CompteurChamp,Start){
	document.Recherche.CompteurChamp.value = CompteurChamp ;
	document.Recherche.Start.value = Start ;
	document.Recherche.submit();
	return;
}

// trouve l'objet
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;
}

// charge l'image
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];}
}


/*****************************************************************/
/**************** info bulles ************************************/
/*****************************************************************/

function HideBulle() {
	if (document.layers) {document.layers["bulle"].visibility="hide";}
	if (document.all) {document.all["bulle"].style.visibility="hidden";}
	else if (document.getElementById){document.getElementById("bulle").style.visibility="hidden";}
    window.status="";
}

var IB=new Object;
var posX=0;posY=0;
var xOffset=10;yOffset=10;

function AffBulle(texte) {
  contenu="<TABLE width=100% border=0 cellspacing=0 cellpadding="+IB.NbPixel+"><TR bgcolor='"+IB.ColContour+"'><TD><TABLE border=0 width=100% cellpadding=2 cellspacing=0 bgcolor='"+IB.ColFond+"'><TR><TD><SPAN style='font-family:arial;color:"+IB.ColTexte+";font-size:11px;font-weight:bold'>"+texte+"</SPAN></TD></TR></TABLE></TD></TR></TABLE>&nbsp;";
  var finalPosX=posX-xOffset;
  if (finalPosX<0) finalPosX=0;
  if (document.layers) {
    document.layers["bulle"].document.write(contenu);
    document.layers["bulle"].document.close();
    document.layers["bulle"].top=posY+yOffset;
    document.layers["bulle"].left=finalPosX;
    document.layers["bulle"].visibility="show";}
    //else{alert("nada");}
  if (document.all) {
    //var f=window.event;
    //doc=document.body.scrollTop;
    bulle.innerHTML=contenu;
    document.all["bulle"].style.top=posY+yOffset;
    document.all["bulle"].style.left=finalPosX;//f.x-xOffset;
    document.all["bulle"].style.visibility = "visible";
    
    document.all["bulle"].style.width = 200 ;
    Xdecal = finalPosX - 200 ;
    if (Xdecal<0) { Xdecal=0;}
    document.all["bulle"].style.left=Xdecal;
    
    /*
    ww = new String(document.all["bulle"].style.scrollLeft);
    alert("ww1="+ww);
    ww = new String(document.all["bulle"].scrollLeft);
    alert("ww1b="+ww);
    document.all["bulle"].style.width = 20;
    ww = new String(document.all["bulle"].style.width);
    alert("ww2="+ww);
    */
  }
  //modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
  else if (document.getElementById) {
    document.getElementById("bulle").innerHTML=contenu;
    document.getElementById("bulle").style.top=posY+yOffset;
    document.getElementById("bulle").style.left=finalPosX;
    document.getElementById("bulle").style.width=200;
    document.getElementById("bulle").style.visibility="visible";
  }
  var reg=new RegExp("(<BR>)","g");
  window.status=texte.replace(reg, " | ");
}

// monte la bulle en haut de page
function FormatteBullePourHautDeTableau(largeur){
	Large= ((Number(largeur)) > 0 )? Number(largeur) : 330 ;
  if (document.layers) {
    document.layers["bulle"].top=0;
    document.layers["bulle"].width=Large;
		if ( Large > 400){
			document.layers["bulle"].left=10;
		}
	}
  if (document.all) {
    document.all["bulle"].style.top=0;
    document.all["bulle"].style.width = Large ;
		if ( Large > 400){
			document.all["bulle"].style.left=10;
		}
  }
  else if (document.getElementById) {
    document.getElementById("bulle").style.top=0;
    document.getElementById("bulle").style.width=Large;
		if ( Large > 400){
			document.getElementById("bulle").style.left=10;
		}
  }
}

// monte la bulle en haut de page
function InfoBulleEcartGauche(pxgauche){
  if (document.layers) {
	document.layers["bulle"].left=pxgauche;
	}
  if (document.all) {
	document.all["bulle"].style.left=pxgauche;
  }
  else if (document.getElementById) {
	document.getElementById("bulle").style.left=pxgauche;
  }
}

function InitBulle(ColTexte,ColFond,ColContour,NbPixel) {
	IB.ColTexte=ColTexte;IB.ColFond=ColFond;IB.ColContour=ColContour;IB.NbPixel=NbPixel;
	if (document.layers) {
		window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
		document.write("<LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER>");
	}
	if (document.all) {
		document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV>");
		document.onmousemove=getMousePos;
	}
	//modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
	else if (document.getElementById) {
	        document.onmousemove=getMousePos;
	        document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV>");
	}

}

function getMousePos(e) {
  if (document.all) {
  posX=event.x+document.body.scrollLeft; //modifs CL 09/2001 - IE : regrouper l'évènement
  posY=event.y+document.body.scrollTop;
  }
  else {
  posX=e.pageX; //modifs CL 09/2001 - NS6 : celui-ci ne supporte pas e.x et e.y
  posY=e.pageY; 
  }
}


