// JavaScript Document for AMIéditions Web Site
//Author : Dimbi
//Neov S.A.

// Détéction des browsers
var NS4=(document.layers)?1:0;
var IE=(document.all)?1:0; 
var NS6=(!document.all && document.getElementById)?1:0;

// detection OS
var MacOS=(navigator.appVersion.indexOf("Mac")!=-1)?1:0;

var timer1=setTimeout("",0);
var list=new Array('environnement','transport','hygiene','douane','formation') ;
var isNewmenu = true;
var posYMenu;
var posXMenu;
var ref;

function init(){
	clearTimeout(timer1);
	for(i in list){
		this.css=est.dom?document.getElementById(list[i]).style:est.ie?document.all[list[i]].style:est.ns?document.layers[list[i]]:0;
		if(!NS6){
			if(IE){
				//document.all[list[i]].filters[0].Apply() ;
				this.css.visibility='hidden';
				//document.all[list[i]].filters[0].Play() ;
			}else{
				this.css.visibility='hidden';	
			}
		}else{
			this.css.visibility='hidden';
		}
	}
}

function ia(){
	timer1=setTimeout('init();',100);
}

function ct(){
	clearTimeout(timer1);
}

function sh(div,state,imgRef,dX,dY){
	clearTimeout(timer1);
	this.css=est.dom?document.getElementById(div).style:est.ie?document.all[div].style:est.ns?document.layers[div]:0;
	this.css.left = moveXbySlicePos(imgRef) + dX;
	this.css.top = moveYbySlicePos(imgRef) + dY;
	if(!NS6){
		if(IE){
			//document.all[div].filters[0].Apply() ;
			this.css.visibility=state;
			//document.all[div].filters[0].Play() ;
		}else{
			this.css.visibility=state;
		}
	}else{
		this.css.visibility=state;
	}
	/*this.css=est.dom?document.getElementById("tri"+div).style:est.ie?document.all["tri"+div].style:est.ns?document.layers["tri"+div]:0;
	this.css.visibility=state;
	this.css.top = posYMenu; */	
}

function Browser(){
	b=navigator.appName;
	if(b=="Netscape"){
		this.b="ns"; 
	}else{
		if(b=="Microsoft Internet Explorer"){
			this.b="ie";
		}else{
			this.b=b;
		}
	}
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns"&&this.v>=4);
	this.ie=(this.b=="ie"&&this.v>=4);
	this.dom=((document.createRange&&(document.createRange().createContextualFragment))?true:false);
}

est=new Browser();

function getExplorerVersion() {
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
	var tempVers = navigator.appVersion;
	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 ) {
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}

//---- determination de la position de y ------------//
function moveYbySlicePos (ImgName) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = document.images[ImgName];
		var lastOffset = 0;
		var y = 0 ;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (par.y >= 0) y += par.y;
	return y;
}
//---- determination de la position de x ------------//
function moveXbySlicePos (ImgName) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = document.images[ImgName];
		var lastOffset = 0;
		var x = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (par.x) x += par.x;
	return x;
}

function newMenu(isnew) {
	isNewmenu = true;	
}
function MM_openBrWindow(theURL,winName,features,position) { //v2.0	
   	pop = window.open(theURL,winName,features);
	var windowX = screen.width - position;
	pop.moveTo(windowX,0);
	pop.focus();
}
function MM_openBrWindow2(theURL,winName,features,position) { //v2.0	
   	pop = window.open(theURL,winName,features);
	var windowX = (screen.width - position)/2;
	pop.moveTo(windowX,0);
	pop.focus();
}

function MM_openBrWindow3(theURL,winName,features,position) { //v2.0	

   	ref = window.open(theURL,winName,features);

	var windowX = (screen.width - position)/2;

	ref.moveTo(windowX,0);

	ref.focus();

}

function VerifNumber(){
	if (event.keyCode < 45 || event.keyCode > 57){
	event.returnValue = false;					
	//alert('Le contenu de ce champ doit être numérique');					
	return false ;
	}
}

function Class(Obj, InOut, nomclasse){
	if(InOut){
		Obj.className=nomclasse;
	}
	else{
		Obj.className=nomclasse;
	}
	return true;
}

function pop(url,titre,params){ 
	var w=window.open(url,titre,params);
	var windowX=(screen.width/2)-(800/2);
   	var windowY=(screen.height/2)-(450/2);
	w.moveTo(windowX,windowY);
}


/* ******************************************************************

	FONCTION TRIM

	Description: Enleve les espaces avant et a la fin de la chaine de caracteres inNum

	Syntaxe:     Trim(Str as String) eg: Str = '   stringtest    '

	Used:        On all function javascript

* ******************************************************************/

function Trim(inNum){

	while (inNum.charAt(0) == ' ') {inNum = inNum.substr(1)};

	while (inNum.charAt(inNum.length-1) == ' '){inNum = inNum.substr(0, inNum.length-1)};

	

	return inNum;

}





function emailCheck (emailStr) {
	emailStr = emailStr.toLowerCase();
	if ((emailStr != "")&&(emailStr != null)){
		/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.  1 means check it, 0 means don't. */
		var checkTLD=1;
		/* The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
		var emailPat=/^(.+)@(.+)$/;
		/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		/* The following string represents the range of characters allowed in a 
		username or domainname.  It really states which chars aren't allowed.*/
		var validChars="\[^\\s" + specialChars + "\]";
		/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";
		/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		/* The following string represents an atom (basically a series of non-special characters.) */
		var atom=validChars + '+';
		/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";
		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		/* Finally, let's start trying to figure out if the supplied address is valid. */
		/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
			/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
			//alert("L'adresse E-mail est incorrect (vérifiez @ et .'s)");
			setText("msg_erreur", "L'adresse E-mail est incorrecte (vérifiez @ et .'s)");	
			//ChangeColor("msg_erreur", "FFFFFF", false);
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		// Start by checking that only basic ASCII characters are in the strings (0-127).
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				//alert("Le username contient un ou des characters interdits.");
				setText("msg_erreur", "Le username contient un ou des characters interdits.");	
				//ChangeColor("msg_erreur", "FFFFFF", false);
				return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				//alert("Le nom de domaine contient un ou des characters interdits.");
				setText("msg_erreur", "Le nom de domaine contient un ou des characters interdits.");	
				//ChangeColor("msg_erreur", "FFFFFF", false);
				return false;
			}
		}
		
		// See if "user" is valid 
		
		if (user.match(userPat)==null) {
		
		// user is not valid
		
			//alert("Le username n'est pas valide.");
			setText("msg_erreur", "Le username n'est pas valide.");	
			//ChangeColor("msg_erreur", "FFFFFF", false);
			return false;
		}
		
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
		
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
			// this is an IP address
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					//alert("L'adresse IP de destination est invalide!");
					setText("msg_erreur", "L'adresse IP de destination est invalide!");	
					//ChangeColor("msg_erreur", "FFFFFF", false);
					return false;
				}
			}
			return true;
		}
		
		// Domain is symbolic name.  Check if it's valid.
		 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				//alert("Le nom de domaine n'est pas valide.");
				setText("msg_erreur", "Le nom de domaine n'est pas valide.");	
				//ChangeColor("msg_erreur", "FFFFFF", false);
				return false;
			}
		}
		
		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */
		
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			//alert("L'adresse doit avoir terminé par un domaine précis ou deux lettres " + "pays.");
			setText("msg_erreur", "L'adresse doit avoir terminé par un domaine précis ou deux lettres " + "pays.");	
			//ChangeColor("msg_erreur", "FFFFFF", false);
			return false;
		}
		
		// Make sure there's a host name preceding the domain.
		if (len<2) {
			//alert("L'adresse ne contient pas de hostname!");
			setText("msg_erreur", "L'adresse ne contient pas de hostname!");	
			//ChangeColor("msg_erreur", "FFFFFF", false);
			return false;
		}
		
		// If we've gotten this far, everything's valid!
		return true;
	}	
}

/**
* verify la vide
*/
function isNotEmpty(tagname,taglabel,nameForm,tagvalue){
	
	ok = true;
	myForm = eval('document.'+nameForm);
	
	tab_tagname = tagname.split(";");
	tab_taglabel = taglabel.split(";");
	if (tagvalue!="") tab_tagvalue = tagvalue.split(";");
	 
	if (tab_tagname.length==tab_taglabel.length){
		
		i=0;
		while (ok && i<tab_tagname.length){	
			    
				if (!Trim(myForm.elements[tab_tagname[i]].value)){
					ok = false;
					setText ("msg_erreur","Le champ "+tab_taglabel[i]+" ne doit pas être vide");
					myForm.elements[tab_tagname[i]].focus();
				}else if (tagvalue!="" && tab_tagname.length==tab_tagvalue.length){
					
					if (myForm.elements[tab_tagname[i]].value==tab_tagvalue[i]){
						ok = false;
						setText ("msg_erreur","Le champ "+tab_taglabel[i]+" doit être modifié");
						myForm.elements[tab_tagname[i]].focus();
					}
				}
			i++;
		}
	}
	
	return ok;
}

function getElement(psID) { 
   if(document.all) { 
      return document.all[psID]; 
   } else if(document.getElementById) { 
      return document.getElementById(psID); 
   } else { 
      for (iLayer = 1; iLayer < document.layers.length; iLayer++) { 
         if(document.layers[iLayer].id == psID) 
            return document.layers[iLayer]; 
      }       
   } 
   return Null; 
} 

function setText(psID, text) { 
	var obj;
	obj = getElement(psID);
	obj.innerHTML = text;
} 

function VerifyNumericValue(IntegerNumber){
	// Pour les nombre entier
	if(IntegerNumber == 'Integer'){
		if (event.keyCode < 48 || event.keyCode > 57) {
			event.returnValue = false; 
			alert('This field must be an integer');
		}
	}
	// Pour les reels (Decimal)
	else if(IntegerNumber == 'Decimal'){
		if (event.keyCode < 44 || event.keyCode > 57) {
			event.returnValue = false; 
			alert('This field must be a decimal');
		}
	}
	else{
		if (event.keyCode < 45 || event.keyCode > 57) {
			event.returnValue = false; 
			alert('This field must have a numeric value');
		}
	}
}

/* ******************************************************************
	FONCTION CheckDecimal(Obj)
	Description: Cette fonction verifie la valeur en decimale saisie
	Syntaxe:     OnBlur="CheckDecimal(this);"
* ******************************************************************/
function CheckDecimal(Obj){
	var ResultValue = Trim(Obj.value);
	// Remplace toutes les virgules (,) par des points (.)
	re = /,/g
	ResultValue = ResultValue.replace(re, ".");
	// Enleve la valeur 0 devant le(s) chiffre(s)
	while (ResultValue.charAt(0) == '0') {ResultValue = ResultValue.substr(1)};
	if(ResultValue == '') ResultValue = '0';
	// Verifie la valeur saisie
	var DecValue = ResultValue.split(".");
	if(DecValue.length == 0) ResultValue = '0.00';
	else if(DecValue.length > 2){
		alert("Invalid value");
		Obj.focus();
	}
	else if(DecValue.length == 2){
		if(DecValue[0] == '') ResultValue = '0.' + DecValue[1];
		if(DecValue[1] == '') ResultValue = DecValue[0] + '.00';
	}
	else ResultValue += '.00';
	Obj.value = ResultValue;
}




function IsEmailValid(TxtMail){
	var Msg = '';
	if (TxtMail != ""){
		var checkTLD = 1;
		var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|mg)$/;
		var emailPat = /^(.+)@(.+)$/;
		var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
		var validChars = "\[^\\s" + specialChars + "\]";
		var quotedUser = "(\"[^\"]*\")";
		var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom = validChars + '+';
		var word = "(" + atom + "|" + quotedUser + ")";
		var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray = TxtMail.match(emailPat);
		if (matchArray == null) {
			alert("Incorrect adress email (check @ and .'s)");
			return false;
		}
		var user = matchArray[1];
		var domain = matchArray[2];
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				alert("Incorrect adress email:\nNo basic ASCII characters are in the user.");
				return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				alert("Incorrect adress email:\nNo basic ASCII characters are in the domain.");
				return false;
			}
		}
		
		if (user.match(userPat) == null) {
		
		alert("Incorrect adress email:\nUser is not valid.");
			return false;
		}
		
		var IPArray = domain.match(ipDomainPat);
		if (IPArray != null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Incorrect adress email:\nMake sure the IP address is valid.");
					return false;
				}
			}
			return true;
		}
		
		var atomPat = new RegExp("^" + atom + "$");
		var domArr = domain.split(".");
		var len = domArr.length;
		for (i=0; i<len; i++) {
			if (domArr[i].search(atomPat) == -1) {
				alert("Incorrect adress email:\nInvalid domaine name.");
				return false;
			}
		}
		
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alert("Incorrect adress email:\nMake sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country");
			return false;
		}
		
		if (len<2) {
			alert("Incorrect adress email:\nMake sure there's a host name preceding the domain.");
			return false;
		}
		
		return true;
	}
	else{
		alert("The mail adress is required!.");
		return false;
	}
}

/* ***************************************************************
	FONCTION VerifyNumericValue(IntegerNumber)
	VERIFICATEUR EN COURS DE FRAPPE
	Description: Verifie la valeur d'un champs numerique
				 que ce soit entier ou decimal.
	Syntaxe:     OnKeyPress="VerifyNumericValue('Decimal');"
*************************************************************** */
function VerifyNumericValue(IntegerNumber){
	// Pour les nombre entier
	if(IntegerNumber == 'Integer'){
		if (event.keyCode < 48 || event.keyCode > 57) {
			event.returnValue = false; 
			//alert('This field must be an integer');
		}
	}
	// Pour les reels (Decimal)
	else if(IntegerNumber == 'Decimal'){
		if (event.keyCode < 44 || event.keyCode > 57) {
			event.returnValue = false; 
			//alert('This field must be a decimal');
		}
	}
	else{
		if (event.keyCode < 45 || event.keyCode > 57) {
			event.returnValue = false; 
			//alert('This field must have a numeric value');
		}
	}
}
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];}
}
// fonction pour effacer les champs pour les event onFocus
function clearField(obj){
	//obj.value="";
	obj.select();
}
var timeOutID ;
function showHiddenDiv(state){
	clearTimeout(timeOutID) ;
	var message="";
	var idDiv;
	var list = document.body.getElementsByTagName("DIV");
	for(i=0; i<list.length; i++){
		idDiv = list[i].id ;
		if (idDiv.substr(0,3) == "div"){
			divObj = eval(document.all[idDiv].style) ;
			/*if(state=='visible')
				timeOutID = setTimeout("divObj.visibility = 'visible';",100);
			else*/ 
				document.all[idDiv].style.visibility = state;
		}
	}
}

/* AFFECTATION DES VALEURS D'UNE LISTE DES OPTIONS A L'AUTRE */

/* *****************************************************************************************************

	FONCTION move(fbox, tbox)

	Description: Transfert une/les valeur(s) selectionnee(s) d'une liste fbox vers une autre tbox.

	Syntaxe: OnClick="move(Listbox1, ListBox2);"

			 A mettre dans le tag <input type="button" ...>

********************************************************************************************************/


function move(fbox, tbox) {
   
    
	var arrFbox = new Array();

	var arrTbox = new Array();

	var arrLookup = new Array();

	var i;

	

	for (i = 0; i < tbox.options.length; i++) {

		arrLookup[tbox.options[i].text] = tbox.options[i].value;

		arrTbox[i] = tbox.options[i].text;

	}

	

	var fLength = 0;

	var tLength = arrTbox.length;

	

	for(i = 0; i < fbox.options.length; i++) {

		arrLookup[fbox.options[i].text] = fbox.options[i].value;

		if (fbox.options[i].selected && fbox.options[i].value != "") {

				arrTbox[tLength] = fbox.options[i].text;

				tLength++;

		}

		else {

			arrFbox[fLength] = fbox.options[i].text;

			fLength++;

   		}

	}

	

	fbox.length = 0;

	tbox.length = 0;

	var c;

	

	for(c = 0; c < arrFbox.length; c++) fbox[c] = new Option(arrFbox[c], arrLookup[arrFbox[c]], false, false);

	for(c = 0; c < arrTbox.length ; c++) tbox[c] = new Option(arrTbox[c], arrLookup[arrTbox[c]], false, false);
	  

}

/* *****************************************************************************************************

	FONCTION moveAll(fbox, tbox)

	Description: Transfert toutes les valeurs d'une liste fbox vers une autre tbox.

	Syntaxe: OnClick="moveAll(Listbox1, ListBox2);"

			 A mettre dans le tag <input type="button" ...>

********************************************************************************************************/

function moveAll(fbox, tbox) {



	var arrFbox = new Array();

	var arrTbox = new Array();

	var arrLookup = new Array();

	var i;

	

	for (i = 0; i < tbox.options.length; i++) {

		arrLookup[tbox.options[i].text] = tbox.options[i].value;

		arrTbox[i] = tbox.options[i].text;

	}

	

	var fLength = 0;

	var tLength = arrTbox.length;

	

	for(i = 0; i < fbox.options.length; i++) {

		arrLookup[fbox.options[i].text] = fbox.options[i].value;

		if (fbox.options[i].value != "") {

				arrTbox[tLength] = fbox.options[i].text;

				tLength++;

		}

		else {

			arrFbox[fLength] = fbox.options[i].text;

			fLength++;

   		}

	}



	fbox.length = 0;

	tbox.length = 0;

	var c;

	

	for(c = 0; c < arrFbox.length; c++) {

		var no = new Option();

		no.value = arrLookup[arrFbox[c]];

		no.text = arrFbox[c];

		fbox[c] = no;

	}

	

	for(c = 0; c < arrTbox.length; c++) tbox[c] = new Option(arrTbox[c], arrLookup[arrTbox[c]], false, false);

}

