
// popup
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v3.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=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

function goto_URL(object) {
  if(object.options[object.selectedIndex].value != ""){
    window.location.href = object.options[object.selectedIndex].value;
  }
}

//VISUALISATION DE PDF ET D'IMAGES
function VisualiseImage(val) {
 if (val!=0) {
  var pop = window.open('lib/visu_pdf.asp?idupl='+val,'Previsu','width=650,height=500,scrollbars=yes,resizable=yes');
 }
}

function VisualisePDFBrochure(val) {
 if (val!=0) {
  var pop = window.open('lib/visu_pdf_stat_brochure.asp?idupl='+val,'Previsu','width=650,height=500,scrollbars=yes,resizable=yes');
 }
}


//JAVASCRIPT POUR LA PAGE DU PROFIL
function Trim(TRIM_VALUE){
 if(TRIM_VALUE.length < 1){
 return"";
 }
 TRIM_VALUE = RTrim(TRIM_VALUE);
 TRIM_VALUE = LTrim(TRIM_VALUE);
 if(TRIM_VALUE==""){
  return "";
 }
 else{
  return TRIM_VALUE;
 }
} //End Function

function RTrim(VALUE){
 var w_space = String.fromCharCode(32);
 var v_length = VALUE.length;
 var strTemp = "";
 if(v_length < 0){
  return"";
 }
 var iTemp = v_length -1;
 while(iTemp > -1){
  if(VALUE.charAt(iTemp) == w_space){
  }
  else{
   strTemp = VALUE.substring(0,iTemp +1);
   break;
  }
  iTemp = iTemp-1;
 } //End While
 return strTemp;
} //End Function

function LTrim(VALUE){
 var w_space = String.fromCharCode(32);
 if(v_length < 1){
  return"";
 }
 var v_length = VALUE.length;
 var strTemp = "";

 var iTemp = 0;
 while(iTemp < v_length){
  if(VALUE.charAt(iTemp) == w_space){
  }
  else{
   strTemp = VALUE.substring(iTemp,v_length);
   break;
  }
  iTemp = iTemp + 1;
 } //End While
 return strTemp;
} //End Function

function verifpass1(){
  if (Trim(document.formulaire.password.value) == "" ) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  if (Trim(document.formulaire.confirmpassword.value) == "" ) {
   window.alert("Veuillez confirmer votre mot de passe");
   return false;
  }
  if (document.formulaire.password.value.length < 1) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  if (document.formulaire.confirmpassword.value.length < 1) {
   window.alert("Veuillez confirmer votre mot de passe");
   return false;
  }
  if (document.formulaire.password.value != document.formulaire.confirmpassword.value)
  {
   window.alert("Le mot de passe et sa confirmation sont différents");
   return false;
  }
  else{
   return true;
  }
}

function verifpass2(){
  for (a=0;a<tabPassword.length;a++) {
   if (tabPassword[a].toLowerCase() == document.formulaire.password.value.toLowerCase()) {
    alert ('Ce mot de passe est déjà utilisé, veuillez en saisir un différent');
    return false;
   }
  }
  return true;
}

function verifprofil_profil1(){
 if (document.formulaire.zipcode.value.length > 0){
  if (isNaN(document.formulaire.zipcode.value)){
   window.alert("Veuillez indiquer un code postal valide");
   return false;
  }
 }
 if (check_email(document.formulaire.email.value)){
   return true;
  }
 else{
   return false;
 }
}

function verifprofil_profil2(){
 if (document.formulaire.zipcode.value.length > 0){
  if (isNaN(document.formulaire.zipcode.value)){
   window.alert("Veuillez indiquer un code postal valide");
   return false;
  }
 }
 if (verifpass1() && verifpass2() && check_email(document.formulaire.email.value)){
   return true;
  }
 else{
   return false;
 }
}

function unite(value){
 if(value==3){
  valeur="brosse(s)";
 }else{
  valeur="salarié(s)";
 }
 if(version==parseFloat(5,0) && N=="Netscape"){
  document.getElementById('div_unite').innerHTML=valeur;
 }else if(version==parseFloat(4,0) && N=="Microsoft Internet Explorer"){
   objDiv('div_unite').innerHTML = valeur;
 }
}

function validationIdentifprofil(){
 if(check_email(document.identifprofil.email.value)){
  if (document.identifprofil.password.value.length < 1) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  if (Trim(document.identifprofil.password.value) == "" ) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  else{
   return true;
  }
 }
 else{
  return false;
 }
}

function check_email(email1) {
   test1=email1;
   parties1=test1.split("@");
   if (parties1[0]==test1)
   {
      alert("Le format du mail "+email1+" est incorrect-");
      return false;
   }
   partiespoint1=parties1[1].split(".");

   if (partiespoint1[0]==parties1[1])
   {
      alert("Le format du mail "+email1+" est incorrect");
      return false;
   }
   compteur1=0;
   for (var j=1 ; j<(email1.length) ; j++)
   {
    if (email1.charAt(j)=='@')
    {
       compteur1++;
    }
   }
   if (compteur1>1)
   {
      alert("Le format du mail "+email1+" est incorrect");
      return false;
   }
   return true;
}

//vérification des mail pour l'envoi à un ami
function verifMailAmi(mail, mail1, mail2, mail3){
 //vérification du mail de l'internaute
 if (mail.length > 0 || mail.length == 0){
  if(!check_email(mail)) return false;
  if (document.formail.nom.value.length == 0 || document.formail.prenom.value.length == 0){
   alert ("Veuillez saisir votre nom et votre prénom, merci");
   return false;
  }
 }

 //vérification qu'au moins le mail d'un ami a été saisi
 if (mail1.length == 0 && mail2.length == 0 && mail3.length == 0){
  alert ("Veuillez saisir le mail d'un ami, merci");
  return false;
 }

 //vérification du mail, du nom et du prénom du 1er ami
 if (mail1.length > 0){
  if(!check_email(mail1)) return false;
  if (document.formail.nomami.value.length == 0 || document.formail.prenomami.value.length == 0){
   alert ("Veuillez saisir le nom et le prénom de votre ami(e), merci");
   return false;
  }
 }

 //vérification du mail, du nom et du prénom du 2ème ami
 if (mail2.length){
  if(!check_email(mail2)) return false;
  if (document.formail.nomami2.value.length == 0 || document.formail.prenomami2.value.length == 0){
   alert ("Veuillez saisir le nom et le prénom de votre ami(e), merci");
   return false;
  }
 }

 //vérification du mail, du nom et du prénom du 3ème ami
 if(mail3.length){
  if(!check_email(mail3)) return false;
  if (document.formail.nomami3.value.length == 0 || document.formail.prenomami3.value.length == 0){
   alert ("Veuillez saisir le nom et le prénom de votre ami(e), merci");
   return false;
  }
 }
 return true;
}
////////////////////   FORMULAIRE DE CONTACT ////////////////////////////////////////

function verifpassword1(){
  if (Trim(document.inscription.password.value) == "" ) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  if (Trim(document.inscription.confirmpassword.value) == "" ) {
   window.alert("Veuillez confirmer votre mot de passe");
   return false;
  }
  if (document.inscription.password.value.length < 1) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  if (document.inscription.confirmpassword.value.length < 1) {
   window.alert("Veuillez confirmer votre mot de passe");
   return false;
  }
  if (document.inscription.password.value != document.inscription.confirmpassword.value)
  {
   window.alert("Le mot de passe et sa confirmation sont différents");
   return false;
  }
  else{
   return true;
  }
}

function verifpassword2(){
  for (a=0;a<tabPassword.length;a++) {
   if (tabPassword[a].toLowerCase() == document.inscription.password.value.toLowerCase()) {
    alert ('Ce mot de passe est déjà utilisé, veuillez en saisir un différent');
    return false;
   }
  }
  return true;
}

function validationInscription(){
 if(verifpassword1() && verifpassword2() && check_email(document.inscription.email.value) && verif_inscription() && verifzipcodeIdentification()){
   return true;
 }else{
  return false;
 }
}


function verif_inscription(){
 if (document.inscription.nom.value.length < 1){
  window.alert("Veuillez saisir votre nom");
  return false;
 }
 if (document.inscription.prenom.value.length < 1){
  window.alert("Veuillez saisir votre prénom");
  return false;
 }
 if (document.inscription.societe.value.length < 3){
  window.alert("Veuillez saisir votre raison sociale");
  return false;
 }
 if (document.inscription.tel.value.length < 1){
  window.alert("Veuillez saisir votre numéro de téléphone");
  return false;
 }
 if (document.inscription.idprofil.value==0){
  window.alert("Veuillez choisir une profession");
  return false;
 }
 if (document.inscription.tel.value==0){
  window.alert("Veuillez saisir votre profil");
  return false;
 }
 if (document.inscription.taille.value==0){
  window.alert("Veuillez saisir la taille de votre entreprise");
  return false;
 }
 if (document.inscription.adresse.value.length < 1)
 {
  window.alert("Veuillez saisir votre adresse");
  return false;
 }
 if (isNaN(document.inscription.zipcode.value))
 {
  window.alert("Veuillez indiquer un code postal valide");
  return false;
 }
 if (document.inscription.zipcode.value.length<5)
 {
  window.alert("Veuillez indiquer un code postal valide");
  return false;
 }
 if (document.inscription.ville.value.length < 1)
 {
  window.alert("Veuillez saisir votre ville");
  return false;
 }
 return true;
}
		
function check_email(email) { // vérification du format de l'email
	var test = email;
	
	if (email == '') return false;
	
	parties = test.split("@");		
	if (parties[0] == test) return false;
	
	partiespoint = parties[1].split(".");		
	if (partiespoint[0] == parties[1]) return false;
	
	var compteur = 0;
	for (var a=1 ; a<(email.length) ; a++) 
		if (email.charAt(a)=='@') 
			compteur++;
			
	if (compteur>1) return false;
	
	return true;
}

function verif_contact(){
	var objForm = document.contact;
	if (objForm.prenom.value == '') {
		alert('Veuiller saisir votre prénom');
		objForm.prenom.focus();
		return false;
	} else if (objForm.nom.value == '') {
		alert('Veuiller saisir votre nom');
		objForm.nom.focus();
		return false;
	} else if (!check_email(objForm.email.value)) {
		alert('Veuiller saisir votre e-mail');
		objForm.email.focus();
		return false;
	} else if (objForm.demande.value == '') {
		alert('Veuiller saisir votre demande');
		objForm.demande.focus();
		return false;
	} else {
		return true;
	}
}

//LES COMMANDES
function verif_command(){
 if (document.documentation.typedocus.value == 3) {
  if (document.documentation.nomechantillon.value.length < 1){
   window.alert("Veuillez saisir un numéro d'échantillon");
   return false;
  }
 }
 if (document.documentation.nom.value.length < 1){
  window.alert("Veuillez saisir votre nom");
  return false;
 }
 if (document.documentation.prenom.value.length < 1){
  window.alert("Veuillez saisir votre prénom");
  return false;
 }
 if (document.documentation.societe.value.length < 3){
  window.alert("Veuillez saisir votre raison sociale");
  return false;
 }
 if (document.documentation.tel.value.length < 1){
  window.alert("Veuillez saisir votre numéro de téléphone");
  return false;
 }
 if (document.documentation.idprofil.value==0){
  window.alert("Veuillez choisir une profession");
  return false;
 }
 if (document.documentation.tel.value==0){
  window.alert("Veuillez saisir votre profil");
  return false;
 }
 if (document.documentation.taille.value==0){
  window.alert("Veuillez saisir la taille de votre entreprise");
  return false;
 }
 if (document.documentation.adresse.value.length < 1)
 {
  window.alert("Veuillez saisir votre adresse");
  return false;
 }
 if (isNaN(document.documentation.zipcode.value))
 {
  window.alert("Veuillez indiquer un code postal valide");
  return false;
 }
 if (document.documentation.zipcode.value.length<5)
 {
  window.alert("Veuillez indiquer un code postal valide");
  return false;
 }
 if (document.documentation.ville.value.length < 1)
 {
  window.alert("Veuillez saisir votre ville");
  return false;
 }
 return true;
}

function verifzipcode(){
  for (a=0;a<tabZipCode.length;a++) {
   if (parseInt(tabZipCode[a])==parseInt((document.documentation.zipcode.value).substring(0,2))) {
    return true;
   }
  }
  alert ('Veuillez indiquer un code postal valide');
  return false;
}

function validation(){
 if(check_email(document.documentation.email.value) && verif_command() && verifzipcode()){
   return true;
 }else{
  return false;
 }
}
//FIN DES COMMANDES
function verifzipcodeIdentification(){
  for (a=0;a<tabZipCode.length;a++) {
   if (parseInt(tabZipCode[a])==parseInt((document.inscription.zipcode.value).substring(0,2))) {
    return true;
   }
  }
  alert ('Veuillez indiquer un code postal valide');
  return false;
}
////////////////////////////


////////////////////   FORMULAIRE DES COMMANDES ////////////////////////////////////////

function validationIdentification(){
 if(check_email(document.identif.email.value)){
  if (document.identif.password.value.length < 1) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  if (Trim(document.identif.password.value) == "" ) {
   window.alert("Veuillez saisir votre mot de passe");
   return false;
  }
  else{
   return true;
  }
 }
 else{
  return false;
 }
}