
// [FONCTION] getXMLHTTP_page v1
function getXMLHTTP_page(page){
    var xhr=null;
    if(window.XMLHttpRequest){xhr = new XMLHttpRequest();}// Firefox et autres
    else if(window.ActiveXObject){ // Internet Explorer
    try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e1) { xhr = null; }}} else { // XMLHttpRequest non supporté par le navigateur
    //if(err==1){alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");}
    }
    xhr.open("GET", page, false);
    xhr.send(null);
    resultats = xhr.responseText;
	return resultats;
    }


// [FONCTION] verifMail v2
function verifMail(a) {
	testm =	false ;
	
	// on donne les caracteres autorisés
      testchaine = 'ok';
      chaine = a;
      var alphabet     = 'a-z';     // alphabet
      var chiffre      = '0-9';     // chiffre
      var trait        = '\\-';     // trait d'union
      var underscore   = '\\_';     // underscore
      var caract_ok    = '['+alphabet+chiffre+trait+underscore+'@\.]';
      // on test les caractere valides
      jeTest = a;
      for (var j=0 ; j<(jeTest.length) ; j++) {
            var mon_exp = new RegExp (caract_ok, 'gi');
            var x = mon_exp.test(jeTest.charAt(j));
            var lepasbon = jeTest.charAt(j);
            if (lepasbon==' '){lepasbon = 'ESPACE';}
            if ( x == false ) {
            	alert('Le caractère \''+ lepasbon +'\' n\'est pas valide dans une adresse Email');
            	testchaine = 'ko';
                  return false;
            	}
            }
      // on regarde la coherence de la structure du mail
	for (var j=1 ; j<(a.length) ; j++) {
            if (a.charAt(j)=='@') {
			if (j<(a.length-4)){
				for (var k=j ; k<(a.length-2) ;	k++) {
					if (a.charAt(k)=='.') testm = true;
						}
				}
			}
		}
	if (testm==false) { alert('Votre adresse e-mail est incorrecte.');return false}
	else { return true; }
	
		// ELSE	facultatif ; la	fonction retournant testm, la suite du traitement du formulaire	peut donc avoir	lieu
	return testm ; 
	}

// [FONCTION] caracteres_autorises v1.7.1
// caracteres autaurisés dans un champs
// caracteres_autorises('valeur a tester', 'liste des caracteres a controler', [affichage du nom du champs dans l'alert] )
// ex : caracteres_autorises(o.variable.value,'ct','nom');
//        if (testchaine!='ok'){
//                return false;
//                }
// a = alphaber, c = chiffres, t = trait d'union, u = underscore, e = espace, b = accent, p = point
function caracteres_autorises(atester, autorise ,nomchamps){
      testchaine = 'ok';
      chaine = autorise;
      var a = 'a-z'; // alphabet
      if (autorise.indexOf('a') < 0) { a = ''; }
      var b = 'ÀÁÂÃÄÅÆàáâãäåÇçÐÈÉÊËèéêëÌÍÎÏìíîïÑñÒÓÔÕÖØŒòóôõöøœŠšÙÚÛÜùúûüµÝŸ'; // accents
      if (autorise.indexOf('b') < 0) { b = ''; }
      var c = '0-9'; // chiffre
      if (autorise.indexOf('c') < 0) { c = ''; }
      var t = '\\-'; // trait d'union
      if (autorise.indexOf('t') < 0) { t = ''; }
      var u = '\\_'; // underscore
      if (autorise.indexOf('u') < 0) { u = ''; }
      var e = '\\s'; // espace
      if (autorise.indexOf('e') < 0) { e = ''; }
      var p = '\\.'; // point
      if (autorise.indexOf('p') < 0) { p = ''; }
      var caract_ok = '['+a+b+c+t+u+e+p+']';
      
      // on test les caractere valides
      jeTest = atester;
      for (var j=0 ; j<(jeTest.length) ; j++) {
            //var mon_exp = /[a-z0-9\-\_]/gi ;
            //var mon_exp = new RegExp ('[a-z0-9\-\_]','gi');
            var mon_exp = new RegExp (caract_ok, 'gi');
            var x = mon_exp.test(jeTest.charAt(j));
            var lepasbon = jeTest.charAt(j);
            if (lepasbon==' '){lepasbon = 'ESPACE';}
            if ( x == false ) {
                  alert('Le caractère \''+ lepasbon +'\' n\'est pas autorisé'+(nomchamps ? ' dans le champ "'+nomchamps+'"':''));
                  testchaine = 'ko';
                  return false;
                  }
        	}
        return testchaine=='ok'
        }


