//<script>
function fx_trim(strText)
{ 
   // this will get rid of leading spaces 
   while (strText.substring(0,1) == ' ') 
       strText = strText.substring(1, strText.length);

   // this will get rid of trailing spaces 
   while (strText.substring(strText.length-1,strText.length) == ' ')
       strText = strText.substring(0, strText.length-1);

   return strText;
}

function fx_replace_char(src_string, src_char_from, src_char_to)
{
   var i = 0;
   var epured_string = '';
   var src_length = 0;
   var current_char = '';
        
   src_length = src_string.length;
   for (i=0; i<src_length; i++)
   {
      current_char = src_string.substring(i,i+1);
      if (current_char != src_char_from)
      {
         epured_string = epured_string + current_char;
      }
      else
     {
         epured_string = epured_string + src_char_to;
     }
   }
   return (epured_string);
}   

// This function tests if one or several characters are present in a string
function fx_contains_chars(pi_src_string, pi_chars_to_check)
{
   var string_length = 0;
   var i = 0;
   var current_char = '';
   var chars_found = '';
    
   string_length = pi_chars_to_check.length;

   for (i=0; i<string_length; i++)
   {
      current_char = pi_chars_to_check.substring(i,i+1);
      if (pi_src_string.indexOf(current_char) != -1 )
      {
         chars_found = chars_found + ' ' + current_char;
      }
   }
   // Return characters found in concerned string in a concatened string 
   return (chars_found);
}
// Les champs de recherche de certains moteur utilisent ils des caractères de recherche admis ?
function ValidKeywords(psText)
{
	var vexpSearch = /^(\x20*[\w\-\"\'áÁàÀâÂäÄåÅãÃçÇðÐéÉèÈêÊëËíÍìÌîÎïÏóÓòÒôÔöÖøØõÕßþúÚùÙûÛüÜýÝÿÞ]+\x20*)*(\x20*[\w\-\"\'áÁàÀâÂäÄåÅãÃçÇðÐéÉèÈêÊëËíÍìÌîÎïÏóÓòÒôÔöÖøØõÕßþúÚùÙûÛüÜýÝÿÞ]+\x20*)$/;
	//("[\W^'^\.^\"^\x20^\-]","g");
	var vbResult = vexpSearch.test(psText);
	return vbResult;
}

// Nettoyage des mots clés pour recherche catalogue Full-Text.
function CleanKeywords(psInput)
{
	var vsText = psInput;

	var vexpSearch = new RegExp(" *'","g");	//Les espaces ' par '
	vsText = vsText.replace(vexpSearch,"'");

	vexpSearch = new RegExp("' *","g");		//Les ' espace par '
	vsText = vsText.replace(vexpSearch,"'");

	vexpSearch = new RegExp("\"","g");		// Les " par espace
	vsText = vsText.replace(vexpSearch," ");

	vexpSearch = new RegExp(" +","g");		//Les espaces par un espace
	vsText = vsText.replace(vexpSearch," ");

	vexpSearch = new RegExp("[ \t]+$","");	//Trim espace fin
	vsText = vsText.replace(vexpSearch,"");

	vexpSearch = new RegExp("^[ \t]+","");	//Trim espace début
	vsText = vsText.replace(vexpSearch,"");

	vexpSearch = new RegExp(" . ","");	//Cas d'un seul caractère isolé que l'on supprime
	while(vexpSearch.test(vsText))
	{
		vsText = vsText.replace(vexpSearch," ");
	}
	vexpSearch = new RegExp("^. ","");	//Cas d'un seul caractère isolé en début que l'on supprime
	vsText = vsText.replace(vexpSearch,"");
	vexpSearch = new RegExp(" .$","");	//Cas d'un seul caractère isolé en fin que l'on supprime
	vsText = vsText.replace(vexpSearch,"");
	
	if(vsText.length == 1) vsText = '';
	return vsText;
}


// Modifie les champs de recherche pour catalogue full text : Dernière étape avant validation du formulaire.
function ChangeKeywords(psInput)
{
	var vsText = psInput;
	vexpSearch = new RegExp("'","g");			//Les ' par ''
	vsText = vsText.replace(vexpSearch,"''");

	vexpSearch = new RegExp(" +","g");		//Les espaces par un espace
	vsText = vsText.replace(vexpSearch,"*\" and \"");

	if(vsText != '') vsText = '"' + vsText + '*"';

	return vsText;
}