var mozilla = (navigator.userAgent.toLowerCase().indexOf('gecko') != -1) ? true : false;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false;

function format(texte, idcible) {
	if(safari)
	{
		alert('Désolé cette commande ne fonctionne pas avec notre navigateur');
	}
	else
	{
		if(!mozilla) { // si on est pas sous mozilla
			var chaine = document.selection.createRange().text;
			
			if(chaine) {
				var sel = document.selection.createRange();
				sel.text = "<"+texte+">" + chaine + "</"+texte+">";
			}
		}
		else { // si mozilla
			champ = document.getElementById(idcible);
			val = champ.value;
			valDeb = val.substring(0, champ.selectionStart);
			valFin = val.substring(champ.selectionEnd, champ.textLength);
			valSel = val.substring(champ.selectionStart, champ.selectionEnd);
			champ.value = valDeb + "<"+texte+">" + valSel + "</"+texte+">" + valFin;
		}		
	}
}
function CreeLien(idcible) {
	if(safari)
	{
		alert('Désolé cette commande ne fonctionne pas avec notre navigateur');
	}
	else
	{
		if(!mozilla) { // si on est pas sous mozilla
			var chaine = document.selection.createRange().text;
			if(chaine) {
				var sel = document.selection.createRange();
				var lien = prompt("URL:","http://");
				if (lien != null) {
					sel.text = "<a href=\"" + lien + "\" target=\"_blank\">" + chaine + "</a>";
				}
			}
		}
		else { // si mozilla
			champ = document.getElementById(idcible);
			val = champ.value;
			valDeb = val.substring(0, champ.selectionStart);
			valFin = val.substring(champ.selectionEnd, champ.textLength);
			valSel = val.substring(champ.selectionStart, champ.selectionEnd);
			var lien = prompt("URL:","http://");
			if (lien != null) {
				champ.value = valDeb + "<a href=\""+ lien + "\" target=\"_blank\">" + valSel + "</a>" + valFin;
			}
		}		
	}

}

function CreeMail(idcible) {
	if(safari)
	{
		alert('Désolé cette commande ne fonctionne pas avec notre navigateur');
	}
	else
	{
		if(!mozilla) { // si on est pas sous mozilla
			var chaine = document.selection.createRange().text;
			if(chaine) {
				var sel = document.selection.createRange();
				var lien = prompt("URL:","mailto:");
				if (lien != null) {
					sel.text = "<a href=\"" + lien + "\">" + chaine + "</a>";
				}
			}
		}
		else { // si mozilla
			champ = document.getElementById(idcible);
			val = champ.value;
			valDeb = val.substring(0, champ.selectionStart);
			valFin = val.substring(champ.selectionEnd, champ.textLength);
			valSel = val.substring(champ.selectionStart, champ.selectionEnd);
			var lien = prompt("URL:","mailto:");
			if (lien != null) {
				champ.value = valDeb + "<a href=\""+ lien + "\">" + valSel + "</a>" + valFin;
			}
		}		
	}

}

function Move(IdConteneur,IdContenu,Action){
	Navigateur = navigator.appName;

	if(Navigateur == 'Microsoft Internet Explorer')
	{
		Conteneur = document.getElementById(IdConteneur);
		Contenu = document.getElementById(IdContenu);	
	}
	if(Navigateur == 'Netscape')
	{

		ConteneurNs = document.getElementById(IdConteneur);
		ContenuNs = document.getElementById(IdContenu);
	}

	switch(Action){
		case 'Down':
			movedown();
		break;
		
		case 'Up':
			moveup();
		break;
				
		case 'Top':
			movetop();
		break;
		
	}
}

function stopscroll()
{
	if (window.move) clearTimeout(move)
}

function movedown()
{

	if(Navigateur == 'Microsoft Internet Explorer')
	{
	
		Conteneurheight=Conteneur.offsetHeight
		//alert(Conteneurheight);
		Conteneurtop=Conteneur.offsetTop
		
		contentheight=Contenu.offsetHeight
		contenttop=Contenu.offsetTop
			
		if (window.move) clearTimeout(move)
		if (parseInt(Contenu.style.top)>=((contentheight-Conteneurheight)*-1))
		{
			Contenu.style.top=parseInt(Contenu.style.top)-speed+"px"
		}		

	}
	if(Navigateur == 'Netscape')
	{
	
		Conteneurheight=ConteneurNs.offsetHeight
		Conteneurtop=ConteneurNs.offsetTop
		
		contentheight=ContenuNs.offsetHeight
		contenttop=ContenuNs.offsetTop
				
		if (window.move) clearTimeout(move)
		if (parseInt(ContenuNs.style.top)>=((contentheight-Conteneurheight)*(-1)))
		{
			ContenuNs.style.top=parseInt(ContenuNs.style.top)-speed+"px"
		}			
	}
	
	move=setTimeout("movedown()",20)


}

function moveup()
{

	if(Navigateur == 'Microsoft Internet Explorer')
	{
	
		Conteneurheight=Conteneur.offsetHeight
		Conteneurtop=Conteneur.offsetTop
		
		contentheight=Contenu.offsetHeight
		contenttop=Contenu.offsetTop
		
		if (window.move) clearTimeout(move)
		if (parseInt(Contenu.style.top)<=0)
		{
			Contenu.style.top=parseInt(Contenu.style.top)+speed+"px"
		}		

	}
	if(Navigateur == 'Netscape')
	{
	
		Conteneurheight=ConteneurNs.offsetHeight
		Conteneurtop=ConteneurNs.offsetTop
		
		contentheight=ContenuNs.offsetHeight
		contenttop=ContenuNs.offsetTop
		
		if (window.move) clearTimeout(move)
		if (parseInt(ContenuNs.style.top)<=0)
		{
			ContenuNs.style.top=parseInt(ContenuNs.style.top)+speed+"px"
		}			
	}

	move=setTimeout("moveup()",20)
}


function movetop(){

	if(Navigateur == 'Microsoft Internet Explorer')
	{
	
		Conteneurheight=Conteneur.offsetHeight
		Conteneurtop=Conteneur.offsetTop
		
		contentheight=Contenu.offsetHeight
		contenttop=Contenu.offsetTop

		if (window.move) clearTimeout(move)
		if (parseInt(Contenu.style.top)<=0)
		{
			Contenu.style.top=0+"px"
		}		

	}
	if(Navigateur == 'Netscape')
	{
	
		Conteneurheight=ConteneurNs.offsetHeight
		Conteneurtop=ConteneurNs.offsetTop
		
		contentheight=ContenuNs.offsetHeight
		contenttop=ContenuNs.offsetTop
		
		if (window.move) clearTimeout(move)
		if (parseInt(ContenuNs.style.top)<=0)
		{
			ContenuNs.style.top=0+"px"
		}			
	}
}

function LISTE1(IdCategorie,NomLong)
{
	this.IdCategorie = IdCategorie;
	this.NomLong = NomLong;
}

function LISTE2(Id,IdCategorie,Nom)
{
	this.Id = Id;
	this.IdCategorie = IdCategorie;
	this.Nom = Nom;
}

function InitListe1()
{
	EffaceListe('IdCategorie');
	if(!safari)
	{
		var o=new Option("... Gammes de produits",'');
		document.getElementById('IdCategorie').options.add(o,document.getElementById('IdCategorie').length);		
		
		for(var i=0;i<Liste1.length;i++)
		{
			var o=new Option(Liste1[i]["NomLong"],Liste1[i]["IdCategorie"]);
			document.getElementById('IdCategorie').options.add(o,document.getElementById('IdCategorie').length);		
		}		
	}
	else
	{
		var o=new Option("... Gammes de produits",'');
		document.getElementById('IdCategorie').add(o,document.getElementById('IdCategorie').length);		
		
		for(var i=0;i<Liste1.length;i++)
		{
			var o=new Option(Liste1[i]["NomLong"],Liste1[i]["IdCategorie"]);
			document.getElementById('IdCategorie').add(o,document.getElementById('IdCategorie').length);		
		}		
	}

	InitListe2(document.getElementById('IdCategorie').value);
}

function InitListe2(IdCategorie,IdEnCours)
{
	EffaceListe('IdProduit');
	if(!safari)
	{	
		var o=new Option("... Produits",'');
		document.getElementById('IdProduit').options.add(o,document.getElementById('IdProduit').length);
					
		for(var i=0;i<Liste2.length;i++)
		{
			if(Liste2[i]["IdCategorie"] == IdCategorie)
			{	
				var o=new Option(Liste2[i]["Nom"],'produits.php?IdCategorie='+Liste2[i]["IdCategorie"]+'&IdProduit='+Liste2[i]["Id"]);
				document.getElementById('IdProduit').options.add(o,document.getElementById('IdProduit').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdProduit').length;i++)
		{
			if(document.getElementById('IdProduit').options[i].value == IdEnCours)
			{	
				document.getElementById('IdProduit').options[i].selected = true;
			}	
		}
		
	}
	else
	{
		var o=new Option("... Produits",'');
		document.getElementById('IdProduit').add(o,document.getElementById('IdProduit').length);
					
		for(var i=0;i<Liste2.length;i++)
		{
			if(Liste2[i]["IdCategorie"] == IdCategorie)
			{	
				var o=new Option(Liste2[i]["Nom"],'produits.php?IdCategorie='+Liste2[i]["IdCategorie"]+'&IdProduit='+Liste2[i]["Id"]);
				document.getElementById('IdProduit').add(o,document.getElementById('IdProduit').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdProduit').length;i++)
		{
			if(document.getElementById('IdProduit').options[i].value == IdEnCours)
			{	
				document.getElementById('IdProduit').options[i].selected = true;
			}	
		}
	}
}

function LISTEGAMME(Id,IdEntree,Libelle)
{
	this.Id = Id;
	this.IdEntree = IdEntree;
	this.Libelle = Libelle;
}

function InitListeGamme(IdEntree,IdEnCours)
{
	EffaceListe('IdGamme');
	if(!safari)
	{	
		var o=new Option("Choisissez une Gamme",'');
		document.getElementById('IdGamme').options.add(o,document.getElementById('IdGamme').length);
					
		for(var i=0;i<ListeGamme.length;i++)
		{
			if(ListeGamme[i]["IdEntree"] == IdEntree)
			{	
				var o=new Option(ListeGamme[i]["Libelle"],'IdEntree='+ListeGamme[i]["IdEntree"]+'&IdGamme='+ListeGamme[i]["Id"]);
				document.getElementById('IdGamme').options.add(o,document.getElementById('IdGamme').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdGamme').length;i++)
		{
			if(document.getElementById('IdGamme').options[i].value == IdEnCours)
			{	
				document.getElementById('IdGamme').options[i].selected = true;
			}	
		}
		
	}
	else
	{
		var o=new Option("Choisissez une Gamme",'');
		document.getElementById('IdGamme').add(o,document.getElementById('IdGamme').length);
					
		for(var i=0;i<ListeGamme.length;i++)
		{
			if(ListeGamme[i]["IdEntree"] == IdEntree)
			{	
				var o=new Option(ListeGamme[i]["Libelle"],'IdEntree='+ListeGamme[i]["IdEntree"]+'&IdGamme='+ListeGamme[i]["Id"]);
				document.getElementById('IdGamme').add(o,document.getElementById('IdGamme').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdGamme').length;i++)
		{
			if(document.getElementById('IdGamme').options[i].value == IdEnCours)
			{	
				document.getElementById('IdGamme').options[i].selected = true;
			}	
		}
	}
}

function InitListeGammeId(IdEntree,IdEnCours)
{
	EffaceListe('IdGamme');
	if(!safari)
	{	
		var o=new Option("Choisissez une Gamme",'');
		document.getElementById('IdGamme').options.add(o,document.getElementById('IdGamme').length);
					
		for(var i=0;i<ListeGamme.length;i++)
		{
			if(ListeGamme[i]["IdEntree"] == IdEntree)
			{	
				var o=new Option(ListeGamme[i]["Libelle"],ListeGamme[i]["Id"]);
				document.getElementById('IdGamme').options.add(o,document.getElementById('IdGamme').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdGamme').length;i++)
		{
			if(document.getElementById('IdGamme').options[i].value == IdEnCours)
			{	
				document.getElementById('IdGamme').options[i].selected = true;
			}	
		}
		
	}
	else
	{
		var o=new Option("Choisissez une Gamme",'');
		document.getElementById('IdGamme').add(o,document.getElementById('IdGamme').length);
					
		for(var i=0;i<ListeGamme.length;i++)
		{
			if(ListeGamme[i]["IdEntree"] == IdEntree)
			{	
				var o=new Option(ListeGamme[i]["Libelle"],ListeGamme[i]["Id"]);
				document.getElementById('IdGamme').add(o,document.getElementById('IdGamme').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdGamme').length;i++)
		{
			if(document.getElementById('IdGamme').options[i].value == IdEnCours)
			{	
				document.getElementById('IdGamme').options[i].selected = true;
			}	
		}
	}
}

function LISTEFAMILLE(Id,IdGamme,IdEntree,Libelle)
{
	this.Id = Id;
	this.IdGamme = IdGamme;
	this.IdEntree = IdEntree;
	this.Libelle = Libelle;
}


function InitListeFamille(IdGamme,IdEnCours)
{
	EffaceListe('IdFamille');
	if(!safari)
	{	
		var o=new Option("Choisissez une Famille",'');
		document.getElementById('IdFamille').options.add(o,document.getElementById('IdFamille').length);
					
		for(var i=0;i<ListeFamille.length;i++)
		{
			if(ListeFamille[i]["IdGamme"] == IdGamme)
			{	
				var o=new Option(ListeFamille[i]["Libelle"],'IdEntree='+ListeFamille[i]["IdEntree"]+'&IdGamme='+ListeFamille[i]["IdGamme"]+'&IdFamille='+ListeFamille[i]["Id"]);
				document.getElementById('IdFamille').options.add(o,document.getElementById('IdFamille').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdFamille').length;i++)
		{
			if(document.getElementById('IdFamille').options[i].value == IdEnCours)
			{	
				document.getElementById('IdFamille').options[i].selected = true;
			}	
		}
		
	}
	else
	{
		var o=new Option("Choisissez une Famille",'');
		document.getElementById('IdFamille').add(o,document.getElementById('IdFamille').length);
					
		for(var i=0;i<ListeFamille.length;i++)
		{
			if(ListeFamille[i]["IdGamme"] == IdGamme)
			{	
				var o=new Option(ListeFamille[i]["Libelle"],'IdEntree='+ListeFamille[i]["IdEntree"]+'&IdGamme='+ListeFamille[i]["IdGamme"]+'&IdFamille='+ListeFamille[i]["Id"]);
				document.getElementById('IdFamille').add(o,document.getElementById('IdFamille').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdFamille').length;i++)
		{
			if(document.getElementById('IdFamille').options[i].value == IdEnCours)
			{	
				document.getElementById('IdFamille').options[i].selected = true;
			}	
		}
	}
}

function InitListeFamilleId(IdGamme,IdEnCours)
{
	EffaceListe('IdFamille');
	if(!safari)
	{	
		var o=new Option("Choisissez une Famille",'');
		document.getElementById('IdFamille').options.add(o,document.getElementById('IdFamille').length);
					
		for(var i=0;i<ListeFamille.length;i++)
		{
			if(ListeFamille[i]["IdGamme"] == IdGamme)
			{	
				var o=new Option(ListeFamille[i]["Libelle"],ListeFamille[i]["Id"]);
				document.getElementById('IdFamille').options.add(o,document.getElementById('IdFamille').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdFamille').length;i++)
		{
			if(document.getElementById('IdFamille').options[i].value == IdEnCours)
			{	
				document.getElementById('IdFamille').options[i].selected = true;
			}	
		}
		
	}
	else
	{
		var o=new Option("Choisissez une Famille",'');
		document.getElementById('IdFamille').add(o,document.getElementById('IdFamille').length);
					
		for(var i=0;i<ListeFamille.length;i++)
		{
			if(ListeFamille[i]["IdGamme"] == IdGamme)
			{	
				var o=new Option(ListeFamille[i]["Libelle"],ListeFamille[i]["Id"]);
				document.getElementById('IdFamille').add(o,document.getElementById('IdFamille').length);
			}	
		}
		
		for(var i=0;i<document.getElementById('IdFamille').length;i++)
		{
			if(document.getElementById('IdFamille').options[i].value == IdEnCours)
			{	
				document.getElementById('IdFamille').options[i].selected = true;
			}	
		}
	}
}


function EffaceListe(Cible)
{
	MaCible = document.getElementById(Cible);
	MaCible.length = 0;
}


function DesactiveSubmit(ChampEnvoi,Formulaire){
	document.getElementById(ChampEnvoi).value = 'Envoi En Cours';
	document.getElementById(ChampEnvoi).disabled = "disabled";
	if(Formulaire!=''){
		document.getElementById(Formulaire).submit();
	}
}


function VerifForm(Element,ChampEnvoi,Formulaire)
{
	
	Erreur = new String();
	
	for (var i=0; i < Element.length; ++i) {
		if(!document.getElementById(Element[i][0]).value){
			Erreur += '- ' + Element[i][1] + '\r\n';
		}		
	}
	if(Erreur != '')
	{
		Erreur = "Liste des champs à remplir :\n\r" + Erreur;
		alert(Erreur);
	}
	else
	{
		// Envoi du formulaire
		DesactiveSubmit(ChampEnvoi,'');
		document.getElementById(Formulaire).submit();
	}
	
}
function ChangePage(NewUrl,Lieu)
{

	if(document.getElementById(NewUrl.id).options[document.getElementById(NewUrl.id).selectedIndex].value != '')
	{
//		document.getElementById('Page').value=document.getElementById(NewUrl.id).options[document.getElementById(NewUrl.id).selectedIndex].text;
		eval(Lieu+".location='"+document.getElementById(NewUrl.id).options[document.getElementById(NewUrl.id).selectedIndex].value+"'");
	}

}
function ChangePage2(NewUrl,Param,Lieu)
{

	if(Param != '')
	{
//		document.getElementById('Page').value=document.getElementById(NewUrl.id).options[document.getElementById(NewUrl.id).selectedIndex].text;
		eval(Lieu+".location='"+NewUrl+Param+"'");
	}

}

function tjs_haut(l) {
	var indice=l.selectedIndex
	if (indice<0) {
		alert("Aucune ligne n'est sélectionnée");
	}
	if (indice>0) {	// Il reste une ligne au-dessus
		tjs_swap(l,indice,indice-1);
	}
}

function tjs_bas(l) {
	var indice=l.selectedIndex
	if (indice<0) {
		alert("Aucune ligne n'est sélectionnée");
	}
	if (indice<l.options.length-1) {	// Il reste une ligne en-dessous
		tjs_swap(l,indice,indice+1);
	}
}

function tjs_swap(l,i,j) {
	txtsrc = new String();
	txtdest = new String();	
	var valeur=l.options[i].value;
	var texte=l.options[i].text;
	l.options[i].value=l.options[j].value;
	txtsrc = l.options[j].text;
	txtdest = txtsrc;

	l.options[i].text=txtdest;
	l.options[j].value=valeur;
	txtsrc = texte;
	txtdest = txtsrc;

	l.options[j].text =txtdest;
	l.selectedIndex=j
	tjs_ordre(l.form);
}

function tjs_ordre(f) {
	var l=f.ListeClassement;
	var ordre="";
	for(var i=0;i<l.options.length;i++) {
		if (i>0) {ordre+="-";}
		ordre+=l.options[i].value;		
	}
	f.OrdreClassement.value=ordre;
}

function Redirect(Cible)
{
	Destination = document.getElementById(Cible.id).value;
	if(Destination != 0) window.location.href = Destination;
}
<!--
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_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_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];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
