function popup(page,nom,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
    function displayDiv(division,modeDisplay) {
        if(document.getElementById(division)!=null) {
            document.getElementById(division).style.display = modeDisplay;
        }
    }
function verif_coor(source1,source2,source3,source4,source5) {
        if (source1.value.length == 0){
                alert ("Un champ obligatoire n'a pas été saisi");
                source1.focus();
                return false;
        }
        if (source2.value.length == 0){
                alert ("Un champ obligatoire n'a pas été saisi");
                source2.focus();
                return false;
        }
         if (source3.value.length == 0){
                alert ("Un champ obligatoire n'a pas été saisi");
                source3.focus();
                return false;
        }
         if (source4.value.length == 0){
                alert ("Un champ obligatoire n'a pas été saisi");
                source4.focus();
                return false;
        }
         if (source5.value.length == 0){
                alert ("Un champ obligatoire n'a pas été saisi");
                source5.focus();
                return false;
        }
        return true;
}
function validateRequiredForm(formulaire) {
    
    if(validateEmail(formulaire)==false) {
        return false;
    }
    /*if(validateDate(formulaire)==false) {
        return false;
    }*/


    var alerte = 0;
    for(f=0;f<formulaire.elements.length;f++) {
        var thisAttribut = formulaire.elements[f].getAttribute("required");
        if((thisAttribut!='')&&(thisAttribut!=null)) {
            if(formulaire.elements[f].value=='') {
                alert('Merci de remplir le champ "'+thisAttribut+'"');
                formulaire.elements[f].focus();
		return false;   
                break;
            }
        }
    }
    return true;
}

function validateEmail(formulaire) {
    var alerte = 0;
    for(f=0;f<formulaire.elements.length;f++) {
        var thisAttribut = formulaire.elements[f].getAttribute("format");
        if(thisAttribut=='email' && thisAttribut!=null) {
            if(formulaire.elements[f].value!='') {
                if(checkEmail(formulaire.elements[f].value)==false) {
                        alerte++;
                        break;
                }                
            }

        }
    }
      
    if(alerte>0) {
		alert('Merci de respecter le format des e-mails !');
		if ((formulaire.elements[f].type == "text") || (formulaire.elements[f].type == "textarea")) {
            formulaire.elements[f].focus();
		}
        
		return false;   
    }
    return true;
    
}

function checkEmail(emailStr) {
       if (emailStr.length == 0) {
           return true;
       }
       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=emailStr.match(emailPat);
       if (matchArray == null) {
           return false;
       }
       var user=matchArray[1];
       var domain=matchArray[2];
       if (user.match(userPat) == null) {
           return false;
       }
       var IPArray = domain.match(ipDomainPat);
       if (IPArray != null) {
           for (var i = 1; i <= 4; i++) {
              if (IPArray[i] > 255) {
                 return false;
              }
           }
           return true;
       }
       var domainArray=domain.match(domainPat);
       if (domainArray == null) {
           return false;
       }
       var atomPat=new RegExp(atom,"g");
       var domArr=domain.match(atomPat);
       var len=domArr.length;
       if ((domArr[domArr.length-1].length < 2) ||
           (domArr[domArr.length-1].length > 4)) {
           return false;
       }
       if (len < 2) {
           return false;
       }
       return true;
    }
