
// retourne une valeur acceptable un post URL ou GET - la fonction de base js ne convertis pas tout...

function encoderURL(p_chaine)
{
	//trace(p_chaine);
	if(p_chaine=="" || p_chaine==undefined)
	{
		return "";
	}
	var nChaine = p_chaine.replace(/”/g, '"');
	nChaine = nChaine.replace(/’/g, "'");
	nChaine = nChaine.replace(/#/g, "%23");
	nChaine = nChaine.replace(/\$/g, "%24");
	nChaine = nChaine.replace(/&/g, "%26");
	nChaine = nChaine.replace(/\+/g, "%2B");
	nChaine = nChaine.replace(/,/g, "%2C");
	nChaine = nChaine.replace(/:/g, "%3A");
	nChaine = nChaine.replace(/=/g, "%3D");
	nChaine = nChaine.replace(/\?/g, "%3F");
	nChaine = nChaine.replace(/⁄/g, "%2F");
	nChaine = nChaine.replace(/™/g, "%99");
	//trace(p_chaine + " -- OK");
	//trace(" ");
	return encodeURI(nChaine);
}

function estCourriel(courriel)
{
	// Code adapted from http://www.web-wise-wizard.com/javascript-tutorials/javascript-validate-email-address.html
	// and from http://javascript.about.com/library/blemailb.htm

	// CHECK THAT THE STRING IS NOT EMPTY
	if(courriel.length < 1)
	{
		return false;
	}
	
	var atPos = courriel.indexOf('@',0);
	if (atPos == -1) {
	   //if (db) alert('email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   //if (db) alert('email address must not start with @');
	   return false;
	}
	if (courriel.indexOf('@', atPos + 1) > - 1) {
	   //if (db) alert('email address must contain only one @');
	   return false;
	}
	if (courriel.indexOf('.', atPos) == -1) {
	  // if (db) alert('email address must contain a period in the domain name');
	   return false;
	}
	if (courriel.indexOf('@.',0) != -1) {
	  // if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (courriel.indexOf('.@',0) != -1){
	  // if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (courriel.indexOf('..',0) != -1) {
	   // if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}

	// IF EMAIL ADDRESS IN FORM 'user@[255.255.255.0]', THEN CHECK FOR LEFT BRACKET
	if(courriel.indexOf('[', 0) == -1 && courriel.charAt(courriel.length - 1) == ']')
	{
		return false;
	}
	
	// IF EMAIL ADDRESS IN FORM 'user@[255.255.255.0]', THEN CHECK FOR LEFT BRACKET
	if(courriel.indexOf('[', 0) == -1 && courriel.charAt(courriel.length - 1) == ']')
	{
		return false;
	}
	
	// IF EMAIL ADDRESS IN FORM 'user@[255.255.255.0]', THEN CHECK FOR RIGHT BRACKET
	if(courriel.indexOf ( '[', 0 ) > -1 && courriel.charAt(courriel.length - 1) != ']')
	{
		return false;
	}
	
	if(!(courriel.indexOf('@', 0) > 1 && courriel.charAt(courriel.length - 1 ) == ']'))
	{
		// CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
		if(courriel.indexOf( '.', 0 ) == -1)
		{
			return false;
		}
		
		// CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
		var len = courriel.length;
		var pos = courriel.lastIndexOf('.', len - 1) + 1;
		if((len - pos) < 2 || (len - pos) > 6)
		{
			return false;
		}
	}

	// email address contains invalid characters
	var invalidChars = '\/\'\\ ";:?!()\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (courriel.indexOf(invalidChars.charAt(i),0) > -1) {
		  return false;
	   }
	}
	
	// email address contains non ascii characters
	for (i=0; i<courriel.length; i++) {
	   if (courriel.charCodeAt(i)>127) {
		  return false;
	   }
	}

	return true;	
}