<!--
var fenetre;
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var focusVersion = "no"
var servletRoot = "/oi/servlet/"
var staticRoot = "/oiweb/"
var plusTextGras=0;

if ( browserName == "Netscape" && browserVer >= 3 ) focusVersion = "yes";
else if ( browserVer >= 4 ) focusVersion = "yes";
else focusVersion = "no";

//
//
//	
function ouvrirFenetre(urlFenetre, nomFenetre, location, toolbar, directories, barremenu, resizable, scrollbars, status, width, height) {
	var options = 'location=' + location + ',toolbar=' + toolbar + ',directories=' + directories + ',menubar=' + barremenu + ',resizable=' + resizable + ',scrollbars=' + scrollbars +',status=' + status +',width=' + width + ',height=' + height;
	fenetre = window.open (urlFenetre, nomFenetre, options);
	if (focusVersion=="yes") fenetre.focus();
	var start = urlFenetre.indexOf("appel=1");
	if (start != -1) {
		fenetre.moveTo(0,0);
		fenetre.resizeTo(screen.availWidth,screen.availHeight);
	}
}

//
//
//	
function ouvrirContenuSite(urlFenetre, nomFenetre, location, toolbar, directories, barremenu, resizable, scrollbars, status, width, height) {
	var options = 'location=' + location + ',toolbar=' + toolbar + ',directories=' + directories + ',menubar=' + barremenu + ',resizable=' + resizable + ',scrollbars=' + scrollbars +',status=' + status +',width=' + width + ',height=' + height;
	fenetre = window.open (urlFenetre, nomFenetre, options);
	if (focusVersion=="yes") fenetre.focus();
	var start = urlFenetre.indexOf("appel=1");
	if (start != -1) {
		fenetre.moveTo(0,0);
		fenetre.resizeTo(screen.availWidth,screen.availHeight);
	}
}

//
//
//	
function backToHomePage(marque) {
	if (window.name==('PORTAIL'+marque))  {
		document.location='/';
	} else {
		ouvrirFenetre('/', 'PORTAIL'+marque, 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes');
		//window.close();
		parent.window.close();
	}
	return;
}

//
//
//	
function retrieveCookieLangue(name, formulaire) {
	var cookieValue;
	var indexLangue;
	cookieValue = Get_Cookie(name);
	if (cookieValue != null) {
	  formulaire.CODE_LANGUE.options.selectedIndex = cookieValue;
	} else {
	  formulaire.CODE_LANGUE.options.selectedIndex = 0;
	}
	indexLangue = formulaire.CODE_LANGUE.options.selectedIndex;
}

//
//
//	
function Get_Cookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

//
//
//	
function Set_Cookie(name,value,expires,path,domain,secure) {
     document.cookie = name + "=" +escape(value) +
         ( (expires) ? ";expires=" + expires.toGMTString() : "") +
         ( (path) ? ";path=" + path : "") + 
         ( (domain) ? ";domain=" + domain : "") +
         ( (secure) ? ";secure" : "");
}

//
//
//	
function setCookieLangue(codeLangue, codePays) {
	var chaineCookie = codeLangue + '_' + codePays;
	var dateExpiration =  new Date();
	var year = dateExpiration.getYear();
	if (year < 1000 ) year += 1900;
	dateExpiration.setYear(year + 1);  
	Set_Cookie('CodeLanguePaysOI', chaineCookie, dateExpiration, '/', null, null);
}

//
//
//	
function setFlag(locale) {
	var codeLangue = locale.substring(3,5);
	document.getElementById('flag').src='/images/bandiere/'+codeLangue.toLowerCase()+'.gif';
}

//
//
//	
function validChoixLangue(locale) {
	var codeLangue = locale.substring(0,2);
	var codePays = locale.substring(3,5);
	if (Test_Cookie() == 1) {
		setCookieLangue(codeLangue, codePays);
		window.location.reload(true);
		//document.location="/";
	} else {
		window.alert ('Your browser must be configure to accept cookies.\nVotre navigateur doit-etre configurer pour accepter les cookies.');
	}
}

//
//
//	
function validationChoixLangue(codeLangue, codePays) {
	if (Test_Cookie() == 1) {
		formulaire = document.forms[0];
		formulaire.langue.value = codeLangue + '_' + codePays;
		setCookieLangue(codeLangue, codePays);
		formulaire.submit();
		window.close();
	} else {
		window.alert ('Your browser must be configure to accept cookies.\nVotre navigateur doit-etre configurer pour accepter les cookies.');
	}
}

//
//
//	
function validationChoixLangue2(codeLangue, codePays) {
	if (Test_Cookie() == 1) {
		formulaire = document.forms[0];
		formulaire.langue.value = codeLangue + '_' + codePays;
		setCookieLangue(codeLangue, codePays);
		formulaire.submit();
	} else {
		window.alert ('Your browser must be configure to accept cookies.\nVotre navigateur doit-etre configurer pour accepter les cookies.');
	}
}

//
//
//	
function validationChoixMenu(codeMenu) {
	formulaire = document.form_menu;
	formulaire.menu.value = codeMenu;
	formulaire.target='_top';
	formulaire.submit();
	return;
}

//
//
//	
function validationChoixInformations(type, marque) {
	urlInformation = "/cgv";
	ouvrirFenetre(urlInformation, "INFO", "no", "no", "no", "no", "no", "yes", "yes", "700", "875");
	return;
}

function validationChoixInformationsOld(type, marque) {
	urlInformation = servletRoot+"Informations?type=" + type +"&marque="+marque;
	ouvrirFenetre(urlInformation, "INFO", "no", "no", "no", "no", "no", "yes", "yes", "700", "875");
	return;
}

//
//
//	
function validationChoixContact(type, marque) {
	urlInformation = servletRoot+"Informations?type=" + type +"&marque="+marque;
	ouvrirFenetre(urlInformation, "INFO", "no", "no", "no", "no", "no", "yes", "yes", "700", "300");
	return;
}

//
//
//	
function validationChoixContactConnect(type, marque,langue) {
	urlInformation = servletRoot+"Informations?type=" + type +"&marque="+marque+"&langue="+langue;
	ouvrirFenetre(urlInformation, "INFO", "no", "no", "no", "no", "no", "yes", "yes", "700", "300");
	return;
}

//
//
//	
function validationMail(type, marque) {
	urlInformation = servletRoot+"Informations?type=" + type +"&marque="+marque;
	ouvrirFenetre(urlInformation, "INFO", "no", "no", "no", "no", "yes", "yes", "yes", "700", "300");
	return;
}

//
//
//	
function validationContenu(type, marque) {
	urlInformation = servletRoot+"Informations?type=" + type +"&marque="+marque;
	ouvrirContenuSite(urlInformation, "INFO", "no", "no", "no", "no", "no", "no", "no", "760", "600");
	return;
}

//
//
//	
function Test_Cookie() {
	var aujourdhui = new Date();
	var expiration = new Date();
	// la date d'expiration du cookie : ici, 24 heures
	expiration.setTime(aujourdhui.getTime() + 1000*60*60*24*365);
	Set_Cookie ("testInfotec", 1, expiration);
	Set_Cookie ("testSession", 1);
	var start = document.cookie.indexOf("testInfotec=");
	var startSession = document.cookie.indexOf("testSession=");
	if (start != -1 && startSession != -1) {	
		var today = new Date();		
		var expired = new Date(today.getTime() - 48 * 60 * 60 * 1000);
		// less 2 days	
		// Delete cookie with given name
		Set_Cookie("testInfotec", null, expired);
		Set_Cookie("testSession", null, expired);
		return 1;	
	} else {
		return 0;
	}
}

function resetforms(){
	// declare element type
    var type = null;
    // loop through forms on HTML page
    for (var x=0; x<document.forms.length; x++){
    	// loop through each element on form
      	for (var y=0; y<document.forms[x].elements.length; y++){
       		// define element type
         	type = document.forms[x].elements[y].type
       		// alert before erasing form element
       		//alert('form='+x+' element='+y+' type='+type);
       		// switch on element type
      		switch(type){
         		case "text":
         		case "textarea":
         		case "password":
	       			//case "hidden":
           			document.forms[x].elements[y].value = "";
           			break;
         		case "radio":
        		case "checkbox":
           			document.forms[x].elements[y].checked = "";
           			break;
         		case "select-one":
           			document.forms[x].elements[y].options[0].selected = true;
           			break;
         		case "select-multiple":
           			for (z=0; z<document.forms[x].elements[y].options.length; z++){
           				document.forms[x].elements[y].options[z].selected = false;
           			}
         			break;
       		}
     	}
	}
}

//
//
//	
function verifgras(id,name) {
	name = 'document.inscriptionForm.'+name+'.value.length';
	if (eval(name) != 0) {
		document.getElementById(id).className='text';
		return true; 
	} else { 
		document.getElementById(id).className='textbold'; return false;
	}
}

//
//
//	
function verifpaysgras(id,name) {
	name = 'document.inscriptionForm.'+name+'.value';
	if (eval(name) != '0') {
		document.getElementById(id).className='text';
		return true; 
	} else { 
		document.getElementById(id).className='textbold'; return false;
	}
}

//
//
//	
function verifgras3(id,name) {
	name = 'document.inscriptionForm.'+name+'.value.length';
	if (eval(name) != 0) {
		document.getElementById(id).className='text';
		return true; 
	} else { 
		document.getElementById(id).className='textbold'; return false;
	}
}

//
//
//
function verifgrasForAll(){
	var formulaire = document.inscriptionForm;
	var statut = formulaire.statut.value;
	verifcivilitegras('civilite1');
	verifgras('nom1','nom');
	verifgras('prenom1','prenom');
	verifgras('mail1','mail');
	verifgras('confmail1','confmail');
	verifgras('adresse1','adrFacturation');
	verifgras('code1','codePostal');
	verifgras('ville1','ville');
	verifpaysgras('pays1','pays');
	verifgras('pass1','passwd');
	verifgras('pass2','passwd2');
	
	// professionnels
	if (statut != 0  || statut != 4) {
		verifgras('raison1','raisonSociale');
		//verifgras('tvaIntracom1','tvaIntracom');
	}
	
	if (statut == 4) {
		verifgras('organisme1','raisonSociale');
	}

}

//
//
//	
function verifcivilitegras(id) {
	if (document.inscriptionForm.civilite[0].checked 
		|| document.inscriptionForm.civilite[1].checked 
		|| document.inscriptionForm.civilite[2].checked ) {
		document.getElementById(id).className='text';
		return true;
	} else {
		document.getElementById(id).className='textbold'; return false;
	}
}

//
//
//	
function BoutonAnnulerResetGras(ListDiv) {
	plusTextGras=1;	
	MettreToutEnText(ListDiv);
}

//
//
//	
function MettreToutEnText(ListDiv) {
	if (plusTextGras==0) {
		for (i=2; document.getElementsByTagName("div")[i]!= null; i++) {
			document.getElementsByTagName("div")[i].className='textbold';
		}
	} else {
		for (i=2; document.getElementsByTagName("div")[i]!= null; i++) {
			document.getElementsByTagName("div")[i].className='text';
		}
	}
}

//
//
//	
function retourPageLogin(marque) {
	top.location= staticRoot+marque;
	return;
}


//
//
//	
function validationCreation3(valeurMail,valeurConfMail,msgerror,champs) {
	var formulaire=document.inscriptionForm;
	var formulaire1=document.inscriptionForm;
	var retour='';
	var focus=0;
	
	if (valeurMail == '') {
		retour = retour + '<li>'+ champs[3] + '</li>';
		if (focus == 0) formulaire.mail.focus();
		focus++;
	}
	
	if (valeurConfMail == '') {
		retour = retour + '<li>'+ champs[4] + '</li>';
		if (focus == 0) formulaire.confmail.focus();
		focus++;
	}
	
	if (verifemail(valeurMail)==false) {
		retour = retour + '<p class="alert">'+msgerror[4]+'</p><br/>';
		if (focus == 0) formulaire.mail.focus();
		focus++;
	}
	
	if (valeurMail != valeurConfMail) {
		retour = retour + '<p class="alert">'+msgerror[5]+'</p><br/>';
		if (focus == 0) formulaire.confmail.focus();
		focus++;
	}
	
	if(retour!='') {
		retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
		document.getElementById('jsMsg').innerHTML=retour;
		return;
	} else {
		formulaire.laValeurMailValide.value='mailValide';
		formulaire.mailEnvoi.value=valeurMail;
		formulaire.submit();
	}
}

//
//
//	
function ouvre_popup(page) {
     window.open(page,"nom_popup","menubar=yes, status=yes, scrollbars=yes, menubar=no,resizable=yes, width=800, height=650");
     return;
}

//
//
//	
function controleDonneesCreation_phase1 (msgerror, msggen) {
	var formulaire = document.inscriptionForm;
	if ((formulaire.statut[0].checked == false && formulaire.statut[1].checked == false && formulaire.statut[2].checked == false && formulaire.statut[3].checked == false)) {
		document.getElementById('jsMsg').innerHTML='<p class="alert">'+msgerror[10]+'</p><br/>';
		return;
	}
	formulaire.submit();
}

//
//
//	
function controleTauxMo(msgerror, champs,msggen,actionEnvoi) {
	var formulaire=document.gestionPdvForm;
	ControleEnvoiMO(formulaire,msgerror,champs,actionEnvoi);
}

//
//
//	
function EnvoiTVA(msgerror) {
	var formulaire=document.gestionPdvForm;
	var tvaTauxMO = formulaire.tvaTauxMO.value;
	var retour='';

	if (tvaTauxMO == '') {
		formulaire.tvaTauxMO.value=0;
		formulaire.action.value='modifierTVA';
		formulaire.submit();
	} else {
		if(TestTVA(tvaTauxMO)) {
			formulaire.action.value='modifierTVA';
			formulaire.submit();
		} else {
			//retour ='<p class="alert"><ul>'+msgerror[8]+'</ul></p>';
			retour ='<p class="alert"><ul>'+msgerror[1]+'</ul></p>';
			document.getElementById('TxMsg').innerHTML=retour;
			return;
		}
	}
}

//
//
//
function TestTVA(tvaTauxMO) {
	var reg=/^((\d{1,3}((\.|\,)\d{1,2}){0,1})|(\d{1,4}((\.|\,)\d{1,1}){0,1}))$/;
	return (reg.exec(tvaTauxMO)!=null);
}

//
//
//	
function selectionCheckinglibelle(libelle) {
	var extension=libelle.substring(libelle.lastIndexOf("."));
   	var chiffre=extension.charAt(8);
  	document.getElementsByName("check")[chiffre].checked = true;
	return;
}

//
//
//	
function selectionCheckingprix(prix) {
	var extension=prix.substring(prix.lastIndexOf("."));
 	var chiffre=extension.charAt(5);
   	document.getElementsByName("check")[chiffre].checked = true;
	return;
}

//
//
//	
function UpdateTaux(champs,msgerror) {
	var formulaire=document.gestionPdvForm;
	var validationCheck=false;
	
	var j=0;
	var k='';
	var h=',';
	var m=0;
	var test='';

	for(i=0;i<formulaire.check.length;i++) {
		j++;
		if(formulaire.check[i].checked) {
			test = 'document.gestionPdvForm.prix'+i+'.value.length';		
			if (eval(test)==0) {
				m++;
			}
		}
	}
	
	for(i=0;i<formulaire.check.length;i++) {
		if(formulaire.check[i].checked) {
			validationCheck=true;
			k=k.concat(i).concat(h);
		}
	}
	
	if(formulaire.check.length==null) {
		if(formulaire.check.checked) {
			if(document.gestionPdvForm.prix0.value.length==0) {
				m++;
			}
		}
	}
	
	if (m!=0) {
		retour ='<li>'+champs[22]+'</li>';
		retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
		document.getElementById('TxMsg').innerHTML=retour;
		return;
	}
	
	if (k=='') {
		if (formulaire.check.checked) {
			validationCheck=true;
			formulaire.single.value=1;
			formulaire.action.value='UpdateTauxSingle';
			formulaire.submit();
			return;
		} else {
			retour ='<li>'+champs[19]+'</li>';
			retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
			document.getElementById('TxMsg').innerHTML=retour;
			return;
		}
	}
	
	if (validationCheck) {
		formulaire.action.value='UpdateTaux';
		formulaire.ssaction.value=j;
		formulaire.tabaction.value=k;
		formulaire.maction.value=m;
		formulaire.submit();
		return;
	} else {
		retour =retour + '<li>'+champs[19]+'</li>';
		retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
		document.getElementById('TxMsg').innerHTML=retour;
		return;
	}
}

//
//
//	
function SupprimerTaux(champs,msgerror) {
	var formulaire=document.gestionPdvForm;
	var validationCheck=false;
	var j=0;
	var k='';
	var h=',';
	
	for(i=0;i<formulaire.check.length;i++) {
		j++;
	}

	for(i=0;i<formulaire.check.length;i++) {
		if(formulaire.check[i].checked) {
			validationCheck=true;
			k=k.concat(i).concat(h);
		}
	}
	
	if (k=='') {
		if(formulaire.check.checked) {
			validationCheck=true;
			formulaire.single.value=1;
			formulaire.action.value='SuppressionTauxSingle';
			formulaire.submit();
			return;
		} else {
			retour ='<li>'+champs[20]+'</li>';
			retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
			document.getElementById('TxMsg').innerHTML=retour;
			return;
		}
	}
	
	if (validationCheck) {
		formulaire.action.value='SuppressionTaux';
		formulaire.ssaction.value=j;
		formulaire.tabaction.value=k;
		formulaire.submit();
		return;
	}

	if (!validationCheck) {
		retour ='<li>'+champs[20]+'</li>';
		retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
		document.getElementById('TxMsg').innerHTML=retour;
		return;
	}
}

//
//
//	
function AjoutTaux(champs,msgerror){
	var formulaire=document.gestionPdvForm;
	formulaire.action.value='AjoutTaux';
	formulaire.submit();
	return;
	
}

//
//
//	
function tauxMOvalidation (champs,msgerror) {
	var formulaire=document.gestionPdvForm;
	var retour='';
	
	if (formulaire.idtype.value=='' || formulaire.prix.value=='') {
		retour ='<li>'+champs[21]+'</li>';
		retour ='<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
		document.getElementById('TxMsg').innerHTML=retour;
		return;
	} else {
		formulaire.action.value='AjoutTauxLive';
		formulaire.submit();
		return;
	}
}

//
//
//	
function tauxMOannulation (champs,msgerror) {
	var formulaire=document.gestionPdvForm;
	formulaire.submit();
	return;
}

//
//
//	
function ControleEnvoiMO(formulaire, msgerror, champs,actionEnvoi) {
	var tvaTauxMO = formulaire.tvaTauxMO.value;
	var chptaux=formulaire.tvaTauxMO.value;
	var actionSubmit=actionEnvoi;
	var focus=0;
	var retour='';
	
	if (tvaTauxMO == '') {
		formulaire.tvaTauxMO.value=0;
	}
			
	if (retour!='') {
		document.getElementById('TxMsg').innerHTML=retour;
		return;
	} else {
		formulaire.action.value=actionSubmit;
		formulaire.submit();
	}
}

//
//
// Script de vérification des donnees de creation d'un compte client
function controleDonneesCreation_phase2(msgerror, champs, msggen,actionEnvoi) {
	var formulaire = document.inscriptionForm;
	controleDonneesCommunes(false, formulaire, msgerror, champs, msggen,actionEnvoi);
}	

//
//	
// Script de vérification des donnees de creation d'un compte client
function controleDonneesinscriptionForm(msgerror, champs, msggen,actionEnvoi) {
	var formulaire = document.inscriptionForm;
	controleDonneesCommunes(false, formulaire, msgerror, champs, msggen,actionEnvoi);
}	

//
//	
// Script de vérification des donnees de modification d'un compte client
function controleDonneesModification_phase1 (msgerror, champs,msggen, actionEnvoi) {
    var formulaire = document.inscriptionForm;
	controleDonneesCommunes(true, formulaire, msgerror, champs, msggen, actionEnvoi);
}

/*
 * FormatTVAIntracom
 * controle le format de la TVA intracommunautaire suivant le pays d'inscription
 * cf : http://ec.europa.eu/taxation_customs/vies/fr/faqvies.htm#item11
 * return true if TVA format is according with the country
 *
 */
function FormatTVAIntracom(pays, tvaIntracom) {
	var reg = /^.*$/
	if (pays == 'AT') { var reg = /^ATU\d{8}$/ }
	if (pays == 'BE') { var reg = /^BE0?\d{9}$/ }
	if (pays == 'BG') { var reg = /^BG\d{9,10}$/ }
	if (pays == 'CY') { var reg = /^CY\d{8}[A-Z]$/ }
	if (pays == 'CZ') { var reg = /^CZ\d{8,10}$/ }
	if (pays == 'DE') { var reg = /^DE\d{9}$/ }
	if (pays == 'DK') { var reg = /^DK\d\d(\s?\d\d){3}$/ }
	if (pays == 'EE') { var reg = /^EE\d{9}$/ }
	if (pays == 'GR') { var reg = /^EL\d{9}$/ }
	if (pays == 'ES') { var reg = /^ES[A-Z0-9]\d{7}[A-Z0-9]$/ }
	if (pays == 'FI') { var reg = /^FI\d{8}$/ }
	if (pays == 'FR') { var reg = /^FR[A-Z0-9]{2}\s?\d{9}$/ }
	if (pays == 'GB') { var reg = /^GB(((GD|HA)\d{3})|(\d{3}\s?\d{4}\s?\d{2}\s?(\d{3})?))$/ }
	if (pays == 'HU') { var reg = /^HU\d{8}$/ }
	if (pays == 'IE') { var reg = /^IE\d[A-Z0-9+*]\d{5}[A-Z]$/ }
	if (pays == 'IT') { var reg = /^IT\d{11}$/ }
	if (pays == 'LT') { var reg = /^LT(\d{9}|\d{12})$/ }
	if (pays == 'LU') { var reg = /^LU\d{8}$/ }
	if (pays == 'LV') { var reg = /^LV\d{11}$/ }
	if (pays == 'MT') { var reg = /^MT\d{8}$/ }
	if (pays == 'NL') { var reg = /^NL\d{9}B\d\d$/ }	
	if (pays == 'PL') { var reg = /^PL\d{10}$/ }
	if (pays == 'PT') { var reg = /^PT\d{9}$/ }
	if (pays == 'RO') { var reg = /^RO\d{2,9}$/ }
	if (pays == 'SE') { var reg = /^SE\d{12}$/ }
	if (pays == 'SI') { var reg = /^SI\d{8}$/ }	
	if (pays == 'SK') { var reg = /^SK\d{10}$/ }

	return (reg.exec(tvaIntracom)!=null);
}

//
//
//	
function controleDonneesCommunes(maj, formulaire, msgerror, champs, msggen, actionEnvoi) {
	var focus = 0;
	var retour = '';
	var actionSubmit = actionEnvoi;
	var statut = formulaire.statut.value;
	var nom = STrim(formulaire.nom.value);
	var prenom = STrim(formulaire.prenom.value);
	var codePostal = STrim(formulaire.codePostal.value);
	var mail = STrim(formulaire.mail.value);
	var ville = STrim(formulaire.ville.value);
	var adrFacturation = STrim(formulaire.adrFacturation.value);
	var telephone = formulaire.telephone.value;
	var tvac="";
	var siretFR="";
	var checkSiretFR=false;
	
	if (document.getElementById("tvaic")) {
		if(document.getElementById("tvaic").style.display=="block"){
			var tvac=formulaire.tvaIntracom.value;
		}
	}
	if (document.getElementById("siretFR")) {
		if(document.getElementById("siretFR").style.display=="block"){
			var siretFR=formulaire.siret.value;
			checkSiretFR=true;
		} else {
			checkSiretFR=false;
		}	
	}
	
	formulaire.action.value=actionSubmit;	
	formulaire.nom.value=nom;
	formulaire.prenom.value=prenom;
	formulaire.codePostal.value=codePostal;
	formulaire.mail.value=mail;
	formulaire.ville.value=ville;
	formulaire.adrFacturation.value=adrFacturation;

	// Début des controles
	document.getElementById('jsMsg').innerHTML='';
	
	// **************************************
	// ** Controle des champs obligatoires **
	// **************************************
	
	// civilite
	if (!maj) {
		if (formulaire.civilite[0].checked == false && formulaire.civilite[1].checked == false && formulaire.civilite[2].checked == false) {
			retour = retour + '<p class="alert">'+ champs[0] + '</p>';
			formulaire.civilite[0].focus();
			focus++;
		}
	}
	
	// nom
	if (nom == '') {
		retour = retour + '<p class="alert">' + champs[1] + '</p>';
		if (focus == 0) formulaire.nom.focus();
		focus++;
	}
	
	// prenom
	if (prenom == '') {
		retour = retour + '<p class="alert">'+ champs[2] + '</p>';
		if (focus == 0) formulaire.prenom.focus();
		focus++;
	}
	
	// email		
	if (mail == '') {
		retour = retour + '<p class="alert">'+ champs[3] + '</p>';
		if (focus == 0) formulaire.mail.focus();
		focus++;
	}
	
	// email de confirmation
	if (!maj) {
		var confmail = formulaire.confmail.value;
		formulaire.confmail.value=confmail;
		if (confmail == '') {
			retour = retour + '<p class="alert">'+ champs[4] + '</p>';
			if (focus == 0) formulaire.confmail.focus();
			focus++;
		}
	}
	
	// telephone
	if(!ValidatePhone(telephone)) {
		retour = retour + '<p class="alert">' + champs[5] + '</p>';
		if (focus == 0) formulaire.telephone.focus();
		focus++;  	 
	}
	
	// adresse
	if (adrFacturation == '') {
		retour = retour + '<p class="alert">'+ champs[6] + '</p>';
		if (focus == 0) formulaire.adrFacturation.focus();
		focus++;
	}
	
	// code postal
	if (codePostal == '') {
		retour = retour + '<p class="alert">'+ champs[7] + '</p>';
		if (focus == 0) formulaire.codePostal.focus();
		focus++;
	}
	
	// ville
	if (ville == '') {
		retour = retour + '<p class="alert">'+ champs[8] + '</p>';
		if (focus == 0) formulaire.ville.focus();
		focus++;
	}
	
	// pays 
	if (!maj) {
	
		var pays = formulaire.pays.value
		if (pays == '' || pays == '0' ) {
			retour = retour + '<p class="alert">'+ champs[9] + '</p>';
			if (focus == 0) formulaire.pays.focus();
			focus++;
		}
	}
	
	//siret
	if(checkSiretFR&&siretFR==''){
		retour = retour + '<p class="alert">'+ champs[12] + '</p>';
	}
	
	// professionnels
	if (statut != 0  && statut != 4) { 
		// raison sociale
		var raisonSociale = STrim(formulaire.raisonSociale.value);
		formulaire.raisonSociale.value=raisonSociale;
		if (raisonSociale == '') {
			retour = retour + '<p class="alert">'+ champs[11] + '</p>';
			if (focus == 0) formulaire.raisonSociale.focus();
			focus++;
		}
	}
	
	// secours
	if (statut != 0 && statut == 4) { 
		// raison sociale
		var raisonSociale = STrim(formulaire.raisonSociale.value);
		formulaire.raisonSociale.value=raisonSociale;
		if (raisonSociale == '') {
			retour = retour + '<p class="alert">'+ champs[23] + '</p>';
			if (focus == 0) formulaire.raisonSociale.focus();
			focus++;
		}
	}

	if (!maj) {
		// password
		var passwd =formulaire.passwd.value;		
		formulaire.passwd.value=passwd;
		if (passwd== '') {
			retour = retour + '<p class="alert">'+ champs[14] + '</p>';
			if (focus == 0) formulaire.passwd.focus();
			focus++;
		}
		
		// confirmation du password
		var passwd2 =formulaire.passwd2.value;
		formulaire.passwd2.value=passwd2;
		if (passwd2 == '') {
			retour = retour + '<p class="alert">'+ champs[15] + '</p>';
			if (focus == 0) formulaire.passwd.focus();
			focus++;
		}
	}
		
	if (retour != '') {
		retour = '<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
	}
	
	// ***********************************
	// ** Controle du format de l'email **
	// ***********************************
	if (mail != '') {
	
		if (verifemail(mail)==false) {
			retour = retour + '<p class="alert">'+msgerror[4]+'</p><br/>';
			if (focus == 0) formulaire.mail.focus();
			focus++;
		} else {
			if (!maj) {
				var confmail = STrim(formulaire.confmail.value);
				formulaire.confmail.value=confmail;
				if (confmail != '') {		
					if (mail != confmail) {
						retour = retour + '<p class="alert">'+msgerror[5]+'</p><br/>';
						if (focus == 0) formulaire.confmail.focus();
						focus++;
					}
				}
			}
		}
	}

	// ************************************
	// ** Controle du format du password **
	// ************************************
	if (!maj) {
		
		if (passwd != '') {
			if (!isPasswdOK(passwd)) {
				retour = retour + '<p class="alert">'+msgerror[3]+'</p><br/>';
				if (focus == 0) formulaire.passwd.focus();
				focus++;
				
			} else {
				if(passwd2 != '') {
					if ( passwd != passwd2) {
						retour = retour + '<p class="alert">'+msgerror[6]+'</p><br/>';
						if (focus == 0) {
							formulaire.passwd.focus();
						}
						focus++;
					}
				}
			}
		}
	}

	if (!maj) {
	
		if(formulaire.collecte.checked==true) {
			formulaire.actionCollecte.value='collecte';
		}
	}
	


	// Fin des controles
	if (retour!='') {
		document.getElementById('jsMsg').innerHTML=retour;
		return;
	} else {
		formulaire.submit();
	}
}

//
//
//
function choisirLangue (chemin) {
	setCookieLangue('','');
	top.location.href = chemin;
	return;
}

//
//
//
function modificationTauxMO (err, longueur) {
	var formulaire = document.modificationTaux;
	var isGood = 1;

	for(var i=0;i<longueur;i++) {
		if (formulaire.elements[i] == '') {
			isGood = 0;
			break;
		}
	}
	if (isGood == 0) {
		return;
	} else {
		formulaire.ssaction.value='modifierTaux';
		formulaire.submit();
	}
}

//
//
//	
function actualiserTableLiens() {
	top.GAUCHE.location= servletRoot+"MenuGeneral";
}

//
//
//	
function LTrim(str) {
	var i=0
	if (str==null) {return "";}
	if (str=="") {return "";}
	
	if (str.length>0) { 
		for(var i=0;str.charAt(i)==" ";i++);
		return str.substring(i,str.length);
	}
	return str;
}

//
//
//	
function RTrim(str){
	var i=0
	if (str==null) {return "";}
	if (str=="") {return "";}
	if (str.length>0) {
			for(var i=str.length-1;str.charAt(i)==" ";i--);
			return str.substring(0,i+1);
	}
	return str;
}

//
//
//	
function STrim(str) {
	return LTrim(RTrim(str));
}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj) {
	if(isBlank(obj.value)) {
		obj.value="";
	}
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) 
		{
			if ((val.charAt(i)!=' ')&&
				(val.charAt(i)!="\t")&&
				(val.charAt(i)!="\n")&&
				(val.charAt(i)!="\r"))
				{return false;}
		}
	return true;
}

//
//
//	
function isAlphaNum(str) {
	var strChar
	for(var i=0;i<str.length;i++)
	{
		strChar = str.charAt(i);
		 if (!(((strChar >= "a") && (strChar <= "z"))||((strChar >= "A") && (strChar <= "Z"))||((strChar >= "0") && (strChar <= "9"))))
		 { 
			 return false;
		 }
	}
	return true;
}

//
//
//	
// fonction de choix d'un pays en dehors de l'Europe
function getOtherCountry() {
	indexSelectionne = document.forms[0].pays.selectedIndex;
	if (indexSelectionne < 301) {
		document.getElementById("tvaic").style.display = "none";
		ouvrirFenetre(servletRoot+"ChoixPays", 'choixPays', 'no', 'no', 'no', 'no', 'no', 'yes', 'no', '680', '420');
	} else {
		document.getElementById("tvaic").style.display = "block";
		document.forms[0].pays.options[1].text=document.forms[0].autrePays.value;
		document.forms[0].lePays.value='';
		document.forms[0].pays.options[indexSelectionne].selected=true;
	}
}

//
//
//	
function checkTVA(objtva) {
    var tva = objtva.value;
    
    if(!isVirgule(tva) && !hasWhiteSpace(tva)) {
    
        tva = tva.replace(/,/,"\.");
     
	    if (isNaN(tva)==true) {
	    	objtva.value = "";
	    	return;
	    }
	
	    var tvaLongueur = tva.length;
	   	       
	    var point = tva.indexOf(".");
	   
	    var TempVirgule = tvaLongueur - point;
		
		if(TempVirgule > 3 && point != -1) {
			objtva.value = tva.substring(0,point+3);
		}
    	
    } else {
    	objtva.value = "";return;
    }
}

//
//
//	
function isVirgule(str) {
	var strChar
	for(var i=0;i<str.length;i++) {
		strChar = str.charAt(i);
		 if ((strChar == ",")) {
			 return true;
		 }
	}
	return false;
}

//
//
//
function hasWhiteSpace(str) {
	var strChar
	for(var i=0;i<str.length;i++) {
		strChar = str.charAt(i);
		 if ((strChar == " ")) {
			 return true;
		 }
	}
	return false;
}

//
//
//	
function checkChpRempli(type,prix,msgerror, champs, msggen) {
	var type=type;
	var prix=prix;
	var retour='';
	
	if (type=='' ||  prix=='') {
		retour ='<li>'+champs[19]+'</li>';
	}
	
	if (retour != '') {
		retour = '<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p><BR/>';
		document.getElementById('TxMsg').innerHTML=retour;
		return;
	} else {
		EnvoiModifTaux(msgerror, champs, msggen);
		return;
	}
}

// fonction qui positionne la valeur du pays dans la fenetre parente
function setAutrePays(code, libelle) {
	window.opener.document.forms[0].pays.options[1].text=window.opener.document.forms[0].pays.options[window.opener.document.forms[0].pays.selectedIndex].text + '  ' + libelle;
	window.opener.document.forms[0].lePays.value=code;
	window.close();
}

//fonction reprise de la cg
function showTab(OBJ,ID, marque){
	var lisTab = new Array();
	lisTab[0] = new Array('tb1');
	lisTab[1] = new Array('tb2');
	lisTab[2] = new Array('tb3');
	lisTab[3] = new Array('tb4');
	lisTab[4] = new Array('tb5');
	lisTab[5] = new Array('tb6');
	lisTab[6] = new Array('tb7');
	lisTab[7] = new Array('tb8');
	lisTab[8] = new Array('tb9');
	lisTab[9] = new Array('tb10');
	lisTab[10] = new Array('tb11');
	lisTab[11] = new Array('tb12');
	lisTab[12] = new Array('tb13');
	lisTab[13] = new Array('tb14');

	if(OBJ.src.substr(OBJ.src.lastIndexOf("/")+1) == "closelem.gif") {
		OBJ.src = staticRoot+marque+"/img/picto/openelem.gif";
		document.getElementById(lisTab[ID]).style.display = 'block';
	} else {
		OBJ.src = staticRoot+marque+"/img/picto/closelem.gif";
		document.getElementById(lisTab[ID]).style.display = 'none';
	}
}

//
//
//	
function controleDonneesPassword (msgerror, champs, msggen,actionEnvoi) {
	var formulaire=document.inscriptionForm;
	ControlMdp(true,formulaire, msgerror, champs, msggen,actionEnvoi);
}

// controle mot de passe
//
//	
function ControlMdp(maj,formulaire,msgerror,champs,msggen,actionEnvoi) {
	var focus = 0;
	var actionSubmit=actionEnvoi;
	var passwd = formulaire.passwd.value;
	var passwd2 = formulaire.passwd2.value;
	var retour = '';

	formulaire.action.value=actionSubmit;
	if (passwd== '' || !isPasswdOK(passwd)) {
		retour = retour + '<li>'+ champs[14] + '</li>';
		if (focus == 0) formulaire.passwd.focus();
		focus++;
	}
	if (passwd2 == '' || !isPasswdOK(passwd2)) {
		retour = retour + '<li>'+ champs[15] + '</li>';
		if (focus == 0) formulaire.passwd.focus();
		focus++;
	}
	if (retour != '') {
		retour = '<p class="alert">'+msgerror[1]+'<ul>'+retour+'</ul></p>';
	}
	if (passwd.length<5 || passwd2.length<5 ) {
		retour = retour + '<p class="alert">'+msgerror[3]+'</p><br/>';
		if (focus == 0) formulaire.passwd.focus();
		focus++;
	}
	if ( passwd != passwd2) {
		retour = retour + '<p class="alert">'+msgerror[6]+'</p><br/>';
		formulaire.passwd.value='';
		formulaire.passwd2.value='';
		if (focus == 0) formulaire.passwd.focus();
		focus++;
	}
	if (retour != '') {
		document.getElementById('jsMsg').innerHTML=retour;
		return;
	}
	formulaire.submit();
}

//
//
//	
// vérif validité passwd pour la page d' accueil et la sauvegarde
function isPasswdOK(str) {
	if (str.length < 5 || str.length > 10) return false;
	if (isBlank(str)) return false;
	//if(isAlphaNum(str)) return true;
	return true;
}

//
//
//
// vérif validité email par REGEXP
function verifemail(email) {
/* Uniquement des minuscules, format minimum accepté : s@s.fr, pas forcément une lettre après un ./_/- */
	var reg = /^[a-zA-Z0-9]+([_.-]*[a-zA-Z0-9])*@[a-z0-9]+([_.-]?[a-z0-9])*\.([a-z]{2,})$/
	return (reg.exec(email)!=null);
}

//
//
//	
// focus sur la ligne de mot de passe
function chargement() {
	if(document.charge.login.value!='') {
		document.charge.passwd.focus();
	} else {
		document.charge.login.focus();
	}
}

//
//
//	
function EnvoiMotDePasse(msgerror, champs, msggen) {
	controleDonneesPassword (msgerror, champs, msggen,'modifier3');
}

//
//
//	
function EnvoiModifCptClient(msgerror, champs, msggen) {
	controleDonneesModification_phase1 (msgerror, champs, msggen,'modifier2');
}

//
//
//	
function EnvoiModifTaux(msgerror, champs, msggen) {
	controleTauxMo(msgerror, champs,msggen,'modifier4');
}

//
//
//	
function check(errValidation) {
	var formulaire=document.administration;
	var j=0;

	 for (i=0, n=formulaire.elements.length; i<n; i++) {
	    var objType = formulaire.elements[i].type;
	
	    if (objType = "checkbox") {
	      box = eval(formulaire.elements[i]);
    	
			if (box.checked==true) {
				j=j+1;
				ValidationTableauLibellePositive(formulaire);
			}
	   		
   		}
  	}
  	
  	if(j>0) {
  		ValidationTableauLibellePositive(formulaire);

  	} else {
		ValidationTableauLibelleNegative(errValidation);
  	}
}

//
//
//	
function ValidationTableauLibellePositive(formulaire) {
	var obje=document.forms["administration"].elements["affichageNecessary"].value = 'validation';
	formulaire.submit();
	return;
}


//
//
//	
function ValidationTableauLibelleNegative(errValidation) {	
	document.getElementById('jsMsg').innerHTML='<p class="alert">'+errValidation+'</p><br/>';
	return;
}

//
//
//	
function affichageTableauLibelle(message) {
	var obje=document.forms["administration"].elements["affichageNecessary"].value = message;
	document.administration.submit();
	return;
}
	
//
//
//	
function validationDesignation(message,errValidation) {
	if(document.forms["administration"].elements["designation"].value=='') {
		document.getElementById('jsMsg').innerHTML='<p class="alert">'+errValidation+'</p><br/>';
		return;
	} else {
		var obje=document.forms["administration"].elements["affichageNecessary"].value = message;
		document.forms["administration"].submit();
		return;
	}
}
     
//
//
//	
function validationAchats(errPaiement,errEmptyField,errValidCGV) {
	var formulaire=document.abonnementForm;
	var validationAchat=false;
	var validationCGDV=false;
	var validationPaiement=false;
	var retour = '';

	if (formulaire.paiement.checked) {
		validationPaiement=true;
	}
	
	for(i=0;i<formulaire.idAbonnement.length;i++) {
		if (formulaire.idAbonnement[i].checked) {
			validationAchat=true;
			break;
		}
	}
	
	if (formulaire.cgdv.checked) {
		validationCGDV=true;
	}
	
	if (validationAchat && validationCGDV && validationPaiement) {
		formulaire.submit();
		return;
	}
	
	if(!validationAchat) {
		retour = retour + '<p class="alert">'+errEmptyField+'</p><br/>';
	}
	if(!validationPaiement) {
		retour = retour + '<p class="alert">'+errPaiement+'</p><br/>';
	}
	if(!validationCGDV) {
		retour = retour + '<p class="alert">'+errValidCGV+'</p><br/>';
	}
	
	if (retour!='') {
		document.getElementById('jsMsg').innerHTML=retour;
		return;
	}
}

//
//
//	
function controleDonneesRestitution_phase1(errEmptyField) {
	var retour='<p class="alert">'+errEmptyField+'</p><br/>'
    var formulaire=document.form_restitution_phase1;
    var mail=formulaire.email.value;
    if (mail==null || mail=='' ) {
		document.getElementById('jsMsg').innerHTML=retour;
      	return;
	} else {
		if(verifemail(mail)==false) {
			document.getElementById('jsMsg').innerHTML=retour;
			return;
		} else {
			formulaire.submit();
			return;
		}
	}
}
  
//
//
//	
function verifTestMailUnique(ajout,test,bordel) {
	var formulaire=document.modification_phase1;
	var reg=new RegExp("[,]+","g");
	var tableau=ajout.split(reg);
	
	for (var i=0; i<tableau.length; i++) {
		if (tableau[i]==test.value) {
			formulaire.mail.value='';
			formulaire.mail.focus();
			document.getElementById('TxMsg').innerHTML='<p class="alert">'+bordel+'</p><br/>';
			return;
		}
	}
}

//
//
//	
function annuler(marque) {
	document.charge.login.value='';
	document.charge.passwd.value='';
	redirection();
}

//
//
//	
function redirection() {
	top.location= servletRoot+"Quitter";
}

//
//
//	
function i18nControleAjoutLibelle() {
	var formulaire=document.forms['update'];      			
      	
    // TODO: Ajouter des contrôles
      	
  	formulaire.submit();
    return;  
 }

//
//
//	
function i18nControleEnregistrerLibelle() {
	var formulaire=document.forms['update'];      			
      	
    // TODO: Ajouter des contrôles
      	
  	formulaire.submit();
    return;  
}

//
//
//
function isEuropean() {
	indexSelectionne = document.forms[0].pays.value;
	if (indexSelectionne < 301) {
		document.getElementById("tvaic").style.display = "none";
	} else {
		document.getElementById("tvaic").style.display = "block";
	}
 	if (indexSelectionne==301) {
 		document.getElementById("siretFR").style.display = "block";
 		// pour mettre en gras le nouveau champs siret
 		verifgras('siret1','siret');
 	} else {
	 	document.getElementById("siretFR").style.display = "none";
 	}
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-. ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 0;

function isInteger(s) {
	var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) {
        	return false;
        }
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) {
        	returnString += c;
        }
    }
    return returnString;
}

function checkInternationalPhone(strPhone) {
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhone(Phone) {
	if ((Phone!=null)||(Phone!="")) {
		if (checkInternationalPhone(Phone)==false) {	
			document.inscriptionForm.telephone.value=""
			return false
		}
	}
	return true
}

