//**********************************************************//
//*   Function  isNotEmail(email)                          *//
//**********************************************************//

function isNotEmail(champs, libelle) {
  var e = new RegExp("^[0-9a-zA-Z_\.\-]+@[0-9a-zA-Z_\.\-]+[.][a-zA-Z]{2,4}$");
    
  if ( !(e.test(champs.value)) ) {
	  alert("L'email \""+libelle+"\" n'est pas valide");
	  champs.focus();
	  return true;
  }
  return false;
}

//------------------------------------------------------------------------------------------
// Fonction qui supprime les blancs au début et à la fin d'une chaine "sourceString"
//-----------------------------------------------------------------------------------------

function trim(sourceString){
 var tmpStr="";
 tmpStr = new String(sourceString);
 var re = /\s/gi;
 while(tmpStr.charAt(0).match(re)){
  tmpStr=new String(tmpStr.substring(1,tmpStr.length));
 }
 while(tmpStr.charAt(tmpStr.length-1).match(re)){
  tmpStr=new String(tmpStr.substring(0,tmpStr.length-1));
 }
 if (tmpStr.length<1){
   return "";
   }
 return tmpStr;
 }

//------------------------------------------------------------------------------------------
// Fonction qui supprime tous les caractères non alphabetiques d'une chaine "sourceString"
//-----------------------------------------------------------------------------------------

function trimURL(sourceString){
 var tmpStr="";
 tmpStr = new String(sourceString);
 tmpResult = new String();
 var re = new RegExp("[0-9a-zA-Z]{1}");
 for(var i=0;i<sourceString.length;i++){
 	if(tmpStr.charAt(i).match(re)){
 		tmpResult = tmpResult + tmpStr.charAt(i);
 	}
 }
 if (tmpResult.length<1){
   return "";
   }
 return tmpResult;
 }

//**********************************************************//
//*   Function  isNotAlpha(champs, libelle)                *//
//**********************************************************//
function isNotAlpha(champs, libelle){
	champs.value = trim(champs.value);
	var re = new RegExp("^[a-zA-Z]+$");
	if(!(re.test(champs.value))){
	  alert("Le champ \""+libelle+"\" doit être alphabétique");
	  champs.focus();
	  return true;
	}
	return false;
}
//**********************************************************//
//*   Function  isNotAlphaNumeric(champs, libelle)         *//
//**********************************************************//
function isNotAlphaNumeric(champs, libelle){
	champs.value = trim(champs.value);
	var re = new RegExp("^[0-9a-zA-Z]+$");
	if(!(re.test(champs.value))){
	  alert("Le champ \""+libelle+"\" doit être alphanumérique");
	  champs.focus();
	  return true;
	}
	return false;
}



//**********************************************************//
//*   Function  isVide(champs, libelle)                    *//
//**********************************************************//
function isVide(champs, libelle){
	champs.value = trim(champs.value);
	if(champs.value.length==0){
	  alert("Le champ \""+libelle+"\" est obligatoire");
	  champs.focus();
	  return true;
	}
	return false;
}

//**********************************************************//
//*   Function  isNotNumeric(champs, libelle)                    *//
//**********************************************************//
function isNotNumeric(champs, libelle){
	champs.value = trim(champs.value);
	if(isNaN(champs.value)){
	  alert("Le champ \""+libelle+"\" doit être numérique");
	  champs.focus();
	  return true;
	}
	return false;
}

//**********************************************************//
//*   Function  isGreaterThan(champs, longueur, libelle)   *//
//**********************************************************//
function isGreaterThan(champs, longueur, libelle) {
	if(champs.value.length > longueur) {
	  alert("Le champ \""+libelle+"\" ne doit pas dépasser "+longueur+" caractères");
	  champs.focus();
	  return true;
  }
  return false;
}

//**********************************************************//
//*   Function  isNotPicture(champs, longueur, libelle)   *//
//**********************************************************//
function isNotPicture(champs, libelle) {
  var test_pic = new RegExp("^.+[.]([g][i][f]|[j][p][g]|[j][p][e][g]|[p][n][g])$");
    
  if ( !(test_pic.test(champs.value)) ){
	  alert("Le champ \""+libelle+"\" doit contenir soit un fichier GIF (*.gif), soit un fichier JPEG (*.jpg, *.jpeg) soit un fichier PNG (*.png)");
	  champs.focus();
	  return true;
  }
  return false;
}

//**********************************************************//
//*   Function  isExtensionValide(champs, longueur, libelle)*//
//**********************************************************//
function isExtensionValide(champs, libelle) {
  var test_ext = new RegExp("^.+[.]([g][i][f]|[j][p][g]|[j][p][e][g]|[p][n][g]|[t][x][t]|[d][o][c]|[x][l][s]|[e][x][e]|[p][p][t]|[p][p][s]|[p][d][f]|[z][i][p])$");
    
  if ( !(test_ext.test(champs.value)) ){
	  alert("Champs \""+libelle+"\" : Extension de Fichier non valide");
	  champs.focus();
	  return false;
  }
  return true;
}

function isZipValide(champs, libelle) {
  var test_ext = new RegExp("^.+[.]([z][i][p])$");
    
  if ( !(test_ext.test(champs.value)) ){
	  alert("Champs \""+libelle+"\" : Extension de Fichier non valide");
	  champs.focus();
	  return false;
  }
  return true;
}


//**********************************************************//
//*   Function  isNomFichierValide(champs,          libelle)*//
//**********************************************************//
function isNomFichierValide(champs, libelle) {
	var texte = champs.value;
	var fichier = texte.substring((texte.lastIndexOf("\\")+1),texte.length);
	if(fichier.indexOf(" ") == 0 || fichier.indexOf("%") != -1 || fichier.indexOf("&") != -1 ){
	  alert("Le champ "+ libelle +" ne doit pas contenir de : %, &\n et ne doit pas commencer par un blanc");
	  champs.focus();
	  return false;
	}
	return true;
}
