var racine="";
var N=navigator.appName;
var V=navigator.appVersion;
var version="?"; 
var nom=N; 
var os="?"; 
var langue="?";
document.MM_langue = "fr";
// Récupération des infos du navigateur
if (N=="Microsoft Internet Explorer") {
	langue=navigator.systemLanguage;
	version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf(";",V.indexOf("MSIE",0)));
	if (V.indexOf("Win",0)>0) {
		if ( V.indexOf(";",V.indexOf("Win",0)) > 0 ) {
			os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
		} else {
			os=V.substring(V.indexOf("Win",0),V.indexOf(")",V.indexOf("Win",0)));
		}
	}
	if (V.indexOf("Mac",0)>0) {
		os="Macintosh";
		version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf("?",V.indexOf("MSIE",0)));
	}
}
if (N=="Opera") {
	langue=navigator.language;
	version=V.substring(0,V.indexOf("(",0));
	os=V.substring(V.indexOf("(",0)+1,V.indexOf(";",0));
}
if (N=="Netscape") {
	langue=navigator.language;
	if (navigator.vendor=="") { // Mozilla
		version=(V.substring(0,V.indexOf("(",0)));
		nom="Mozilla";
		if (V.indexOf("Mac",0)>0) {
			os="Macintosh";
		}
		if (V.indexOf("Linux",0)>0) {
			os="Linux";
		}
		if (V.indexOf("Win",0)>0) {
			os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
		}
		if (version==5) {
			version="1";
		}
		if (navigator.oscpu) {os=navigator.oscpu;}
	} else {	// NS 4 ou 6
		version=(V.substring(0,V.indexOf("(",0)));
		if (V.indexOf("Mac",0)>0) {
			os="Macintosh";
		}
		if (V.indexOf("Linux",0)>0) {
			os="Linux";
		}
		if (V.indexOf("Win",0)>0) {
			os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
		}
		if (version==5) {
			version="6.0";
			if (navigator.vendorSub!="") {version=navigator.vendorSub;}
		}
		if (navigator.oscpu) {os=navigator.oscpu;}
	}
}

if (os.indexOf("Win")!=-1 ) {
	if (N.indexOf("Netscape")>-1){
		// NN4+
		document.write("<LINK REL=stylesheet TYPE=text/css HREF='"+racine+"styleNetscape.css'>");
	} else { //if (N.indexOf("Explorer")>-1) {
	   // MSIE4+
		document.write("<LINK REL=stylesheet TYPE=text/css HREF='"+racine+"style.css'>");
	}
} else if (os.indexOf("Mac")>-1) {
	document.write("<LINK REL=stylesheet TYPE=text/css HREF='"+racine+"mac.css'>");
} else {
	document.write("<LINK REL=stylesheet TYPE=text/css HREF='"+racine+"style.css'>");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  win = window.open(theURL,winName,features);
  win.focus() ;
}

function UpWindowMS(bNumCamp,bNouveau) {
	//window.open('http://213.6.12.60/template/Tcamp/Mini_service/detail.cfm?NUM_CAMP='+bNumCamp+'&Nouveau='+bNouveau+'&PASS=1&TYPE=0','MS','location=no,toolbar=yes,directories=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,width=800,height=500');
}

String.prototype.trim = function()
{ return this.replace(/(^\s*)|(\s*$)/g, ""); }

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_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_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_cleanField() {
  var i,p,reg,test,errors='',args=MM_cleanField.arguments;
  for (i=0; i<(args.length-1); i+=2) { 
  	test=args[i+1]; 
	val=MM_findObj(args[i]);
   	p=val.value.indexOf(test);
	if (test.length > 1) test = "("+test+")" ;
	else test = "["+test+"]" ;
	if (p>-1) {
		reg=new RegExp(test, "gi");
		val.value = val.value.replace(reg,"") ;
	}
  }
  val.value = val.value.trim() ;
}

function CheckDate(d,display) {
	// Cette fonction vérifie le format JJ-MM-AA saisi et la validité de la date.
	// Le séparateur est défini dans la variable separateur
	var separateur="-"; // separateur entre jour-mois-annee
	var j=(d.substring(0,2));
	var m=(d.substring(3,5));
	var a=(d.substring(6));
	var errors='';
	if (d.length > 0) {
		if ( ((isNaN(j))||(j<1)||(j>31))) {
		 errors += '- Le jour n\'est pas correct.\n' ;
		}
		if ( ((isNaN(m))||(m<1)||(m>12))) {
		 errors += '- Le mois n\'est pas correct.\n' ;
		}
		if ( ((isNaN(a))||(a.length<2))) {
		 errors += '- L\'année n\'est pas correct.\n' ;
		}
		if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur))) {
		 errors += '- Les séparateurs doivent être des '+separateur+'\n' ;
		}
	}
	if (errors && display) alert('Les informations que vous avez saisies sont incorrectes :\n'+errors);
	return !errors;
}

function DateAnglaise(d,separateur) {
	// Cette fonction converti le format JJ-MM-AA saisi en MM/JJ/AA
	var j=(d.substring(0,2));
	var m=(d.substring(3,5));
	var a=(d.substring(6));
	return (m+separateur+j+separateur+a);
}

function ComparerDates(date1,date2){
	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2
	var LeParam1 = DateAnglaise(date1,"/");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	var LeParam2 = DateAnglaise(date2,"/");
	LeParam1 = Date.parse(date1);
	LeParam2 = Date.parse(date2);
	if (LeParam1 == LeParam2) { 
		return 0;
	}
	if (LeParam1 > LeParam2){
		return 1;
	}else{
		return 2;
	}
}

function PeriodeOk(datedeb, datefin) {
	if (CheckDate(datedeb,1) && CheckDate(datefin,1)) {
		if (datedeb.length == 0 || datefin.length == 0 || ComparerDates(datedeb,datefin) != 1) {
			return true;
		} else {
			alert ("Veuillez saisir une date de fin supérieure à la date de début.") ;
			return false ;
		}
	} else {
		return false ;
	}
}

function MM_CodePostal () {
	var args=MM_CodePostal.arguments;
	cp=MM_findObj(args[0]).value;
	dep=cp.substring(0,2);
	pays=document.form_coord.liv_pays.value;
	if (pays==1 && cp.length >4 && (dep==97 || dep==98)) {
		//document.form_coord.liv_pays.value = (dep==97?49:60);
		document.form_coord.liv_dom_tom.value = (dep==97?997:998) ;
	} else {
		document.form_coord.liv_dom_tom.value = 0 ;
	}
	return true ;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',nameField,args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
    test=args[i+2]; val=MM_findObj(args[i]);
    if (val) {
	   nameField = args[i+1]; 
	  if (test.indexOf('isDepartement')!=-1) {
		  if(document.form.departement.value=='' && document.form.pays.value =="FRANCE"){
			  errors += "- Vous devez sélectionner un département ou un pays étranger.\n";
		  }
	  } else if(test.indexOf('isYear')!=-1){
		  if(document.form.annee.value=='' || document.form.annee.value.length<4){
			  errors += "- L'année est obligatoire et doit comporter 4 chiffres (ex : 2005).\n";
		  }
	  } else {
	    if(nameField!=""){ nm=nameField;}else{nm=val.name;} if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { 
			p=val.indexOf('@');
			p2=val.lastIndexOf('.');
			if (p<1 || p2 < 1 || p2 <p || p2 == (p+1) || (p2+3) > (val.length) || p==(val.length-1)) errors+='- '+nm+' '+getTraduction (76)+'.\n';
		  } else if (test.indexOf('isDate')!=-1) { 
			if (!CheckDate(val,0)) errors+='- '+nm+' '+getTraduction (74)+'.\n'; 
		  } else if (test.indexOf('isNum')!=-1) { 
			num = parseFloat(val);
			if (isNaN(val)) errors+='- '+nm+' '+getTraduction (75)+'.\n';
       
	   		if (test.indexOf('inRange') != -1) { 
				p=test.indexOf(':');
	          	min=test.substring(13,p); max=test.substring(p+1);
          		if (num<min || max<num) errors+='- '+nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
			}
	  	}
	  } else if (test.charAt(0) == 'R') errors += '- '+nm+' '+getTraduction (73)+'.\n'; }
	}
  } if (errors) alert(getTraduction (62)+' :\n'+errors);
  document.MM_returnValue = (errors == '');
}

function getTraduction (elem) {
	lg = document.MM_langue ;
	// Les valeurs sont les mêmes que celles du fichier de traduction jsp de la boutique.
	switch (elem) {
		case 62 : { if (lg==("fr")) { return "Les informations que vous avez saisies sont incorrectes" ; }
				if (lg==("uk")) { return "The datas you wrote are not correct" ; }
				if (lg==("de")) { return "Die von Ihnen angegebenen Daten sind nicht korrekt." ; }
				if (lg==("nl")) { return "De informatie die u heeft ingevoerd, is niet correct" ; } }
		case 73 : { if (lg==("fr")) { return "est obligatoire" ; }
				if (lg==("uk")) { return "is compulsary" ; }
				if (lg==("de")) { return "ist notwendig" ; }
				if (lg==("nl")) { return "is verplicht" ; } }
		case 74 : { if (lg==("fr")) { return "doit contenir un date valide" ; }
				if (lg==("uk")) { return "must contain a valid date" ; }
				if (lg==("de")) { return "muss ein Datum beinhalten" ; }
				if (lg==("nl")) { return "moet een geldige datum bevatten" ; } }
		case 75 : { if (lg==("fr")) { return "doit être un nombre" ; }
				if (lg==("uk")) { return "must be a number" ; }
				if (lg==("de")) { return "muss eine Zahl sein" ; }
				if (lg==("nl")) { return "moet een cijfer zijn" ; } }
		case 76 : { if (lg==("fr")) { return "doit être une adresse mail valide" ; }
				if (lg==("uk")) { return "must be a correct email address" ; }
				if (lg==("de")) { return "muss eine Mail-Adresse sein" ; }
				if (lg==("nl")) { return "moet een geldig e-mailadres zijn" ; } }
		default : return "&nbsp;";
	}
}

var decal_layers_top = 0 ;
var decal_layers_left = 0 ;

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
	v=args[i+2];
    if (obj.style) { 
		obj.style.pixelTop=(document.body.clientHeight/2)-(obj.offsetHeight/2)+(document.body.scrollTop)-decal_layers_top;
		obj.style.pixelLeft=(document.body.clientWidth/2)-(obj.offsetWidth/2)+(document.body.scrollLeft)-decal_layers_left;
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v;
	}
    obj.visibility=v; 

  }
}


function MM_set_decal_layers(top,left) {
	decal_layers_top = top ;
	decal_layers_left = left ;
}

function ShowTransientMessage(message) {
	window.status=message;
	DisplayMessageBox.style.display='';
	DisplayMessageBox.style.pixelTop=(document.body.clientHeight/2)-(DisplayMessageBox.offsetHeight/2)+(document.body.scrollTop)-180;
	DisplayMessageBox.style.pixelLeft=(document.body.clientWidth/2)-(DisplayMessageBox.offsetWidth/2)+(document.body.scrollLeft);
}

function HideTransientMessage() {
	window.status="";
	DisplayMessageBox.style.display='none';
}	

function afficheListe(type) {
	tab = document.getElementById("prodTable") ;
	for (var j=1; j<tab.rows.length; j++) {
		if (tab.rows[j].id=='' || type=='' || tab.rows[j].id==type) {
			tab.rows[j].style.display="block" ;
		} else {
			tab.rows[j].style.display="none" ;
		}
	}
	if (type=='') {
		document.getElementById("type1").style.background='#FFFFFF' ;
		document.getElementById("type2").style.background='#FFFFFF' ;			
		document.getElementById("type0").style.background='#6BB218' ;
	} else if (type=='ame') {
		document.getElementById("type1").style.background='#6BB218' ;
		document.getElementById("type2").style.background='#FFFFFF' ;			
		document.getElementById("type0").style.background='#FFFFFF' ;
	} else {
		document.getElementById("type1").style.background='#FFFFFF' ;
		document.getElementById("type2").style.background='#6BB218' ;			
		document.getElementById("type0").style.background='#FFFFFF' ;
	}
}

function showTab(lg) {
	var lgs = new Array("fr", "de", "uk", "nl"); 
	for (i=0; i<(lgs.length);i++) {
		if (lgs[i]==lg) {
		   if(document.getElementById(lgs[i]))document.getElementById(lgs[i]).style.display="" ;
			document.getElementById("onglet_"+lgs[i]).style.background="#99CC66" ;
			if(document.getElementById("onglet2_"+lgs[i])){
				document.getElementById("onglet2_"+lgs[i]).style.background="#99CC66" ;
			}
		} else { 
		   if(document.getElementById(lgs[i]))document.getElementById(lgs[i]).style.display="none" ; 
			document.getElementById("onglet_"+lgs[i]).style.background="#CBDE24" ;
			if(document.getElementById("onglet2_"+lgs[i])){
				document.getElementById("onglet2_"+lgs[i]).style.background="#CBDE24" ;
			}		
		}
	}
}		


// Fonctions pour les checkbox de l'administration (sélectionner / désélectionner tout)
function CheckAll(formName,fieldPrefix,selection) {
	count = document.forms[formName].elements.length;
	for (i=0; i < count; i++) {
		if (document.forms[formName].elements[i].name.indexOf(fieldPrefix)==0) {
			if (document.getElementById(selection).innerText==" Sélection ") {
			//if(document.forms[formName].elements[i].checked == 1) {
				document.forms[formName].elements[i].checked = 1; 
			} else { 
				document.forms[formName].elements[i].checked = 0;
			}
		}
	}
	if (document.getElementById(selection).innerText==" Sélection ") {
		document.getElementById(selection).innerText = " Désélection " ;
	} else { 
		document.getElementById(selection).innerText = " Sélection " ;
	}
}

function supprimeBalise(sHtmlSource) {
  if (confirm("Attention:\nCette opération supprimera toute la mise en forme non conforme.\nSouhaitez vous continuer ?")) {
	workspace = document.getElementById(sHtmlSource);
    // remove all class and style attributes
    for (var intLoop = 0; intLoop < workspace.all.length; intLoop++) {
        el = workspace.all[intLoop];
        el.removeAttribute("className","",0);
        el.removeAttribute("style","",0);
        el.removeAttribute("face","",0);
        el.removeAttribute("color","",0);
        el.removeAttribute("size","",0);
        el.removeAttribute("align","",0);		
    }
// remove all xml prefixes and smarttags
    var html = workspace.innerHTML;
    html = html.replace(/<[?]xml:.*?>/gi, ""); // delete all xml
    html = html.replace(/<o:[pP]>&nbsp;<\/o:[pP]>/gi, ""); // Remove all instances of <o:p></o:p>
    html = html.replace(/<o:[pP]><\/o:[pP]>/gi, ""); // Remove all instances of <o:p> </o:p>
    html = html.replace(/<span>/gi, ""); // Remove all instances of <span>
    html = html.replace(/<\/span>/gi, ""); // Remove all instances of </span>
	html = html.replace(/<font>/gi, ""); // Remove all instances of <font>
    html = html.replace(/<\/font>/gi, ""); // Remove all instances of </font>
	html = html.replace(/<table>/gi, ""); // Remove all instances of <font>
    html = html.replace(/<\/table>/gi, ""); // Remove all instances of </font>
	html = html.replace(/<tr>/gi, ""); // Remove all instances of <font>
    html = html.replace(/<\/tr>/gi, ""); // Remove all instances of </font>
   	html = html.replace(/<td>/gi, ""); // Remove all instances of <font>
    html = html.replace(/<\/td>/gi, ""); // Remove all instances of </font>

    html = html.replace(/<div>/gi, ""); // Remove all instances of <div>
    html = html.replace(/<\/div>/gi, ""); // Remove all instances of </div>
    html = html.replace(/<[hH]1>/gi, ""); // Remove all instances of <h1>
    html = html.replace(/<\/[hH]1>/gi, ""); // Remove all instances of </h1>
    html = html.replace(/<[hH]2>/gi, ""); // Remove all instances of <h2>
    html = html.replace(/<\/[hH]2>/gi, ""); // Remove all instances of </h2>
    html = html.replace(/<[hH]3>/gi, ""); // Remove all instances of <h3>
    html = html.replace(/<\/[hH]3>/gi, ""); // Remove all instances of </h3>
    html = html.replace(/<[hH]4>/gi, ""); // Remove all instances of <h4>
    html = html.replace(/<\/[hH]4>/gi, ""); // Remove all instances of </h4>
    html = html.replace(/<[hH]5>/gi, ""); // Remove all instances of <h5>
    html = html.replace(/<\/[hH]5>/gi, ""); // Remove all instances of </h5>
    html = html.replace(/<[hH]6>/gi, ""); // Remove all instances of <h6>
    html = html.replace(/<\/[hH]6>/gi, ""); // Remove all instances of </h6>
   // html = html.replace(/<[bB]>/gi, ""); // Remove all instances of <b>
   // html = html.replace(/<\/[bB]>/gi, ""); // Remove all instances of </b>
   // html = html.replace(/<strong>/gi, ""); // Remove all instances of <strong>
   // html = html.replace(/<\/strong>/gi, ""); // Remove all instances of </strong>
   // html = html.replace(/<[uU]>/gi, ""); // Remove all instances of <u>
   // html = html.replace(/<\/[uU]>/gi, ""); // Remove all instances of </u>

	html = html.replace(/o:/gi, ""); // delete all o: prefixes
    html = html.replace(/<st1:.*?>/gi, ""); // delete all smarttags
    html = html.replace(/<[pP]><\/[pP]>/gi, ""); // delete all empty paragraph tags
    html = html.replace(/<[pP]>&nbsp;<\/[pP]>/gi, ""); // delete all empty paragraph tags	

	workspace.innerHTML = html;
  } 
}

function sansAccents(val) {
	var newStr = val.toLowerCase() ;
	var re = new RegExp('[éèêë]','gi');
	newStr = newStr.replace(re,"e");
	re = new RegExp('[îï]','gi');
	newStr = newStr.replace(re,"i");
	re = new RegExp('[ôö]','gi');
	newStr = newStr.replace(re,"o");
	re = new RegExp('[àâä]','gi');
	newStr = newStr.replace(re,"a");
	re = new RegExp('[ûüù]','gi');
	newStr = newStr.replace(re,"u");
	re = new RegExp('[ç]','gi');
	newStr = newStr.replace(re,"c");
	re = new RegExp('[ñ]','gi');
	newStr = newStr.replace(re,"n");
	re = new RegExp('[ .]','gi');
	newStr = newStr.replace(re,"_");
	return newStr ;
}

function deconnecte(){
	if(confirm("Etes vous certain de vouloir vous déconnecter ?")){
		document.location.href="deconnecte.jsp";
	}else{
		document.location.href="#";
	}
}
function deconnectePro(){
	if(confirm("Etes vous certain de vouloir vous déconnecter ?")){
		document.location.href="deconnectePro.jsp";
	}else{
		document.location.href="#";
	}
}

function ouvre_fenetre_detail(page,nom,option,URL) {
	win = window.open('',nom,option);
	win.document.write("<HTML><HEAD><TITLE>"+nom+"</TITLE>\n");
	win.document.write("<SCRIPT language=javascript>\nfunction checksize()  {\n if (document.images[0].complete) {\n  window.resizeTo(document.images[0].width+12,document.images[0].height+30);\n window.focus();\n} else {\n setTimeout('check()',250) \n}\n }\n</"+"SCRIPT></HEAD>\n");
	win.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>\n<A HREF='javascript:window.close();'><IMG src='"+page+"' width='500'  border=0></A>\n");
	win.document.write("");
	win.document.write("\n</BODY></HTML>\n");
	win.document.close();
}

function limite(zone,max) { 
	if(zone.value.length>=max){zone.value=zone.value.substring(0,max);} 
}

