﻿// Debut
function removeAccent(s)
{
	var sNoAccent = new String

	// Tables des accents

	var sFrom	= "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÝýÿÑñЁЃЇЌЎЙёѓїќўй";
	var sTo		= "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuYyyNnЕГІКУИегікуи";

	// Pour chaque caractère
	var i, j;
	var c;

	for (i = 0; i < s.length; i ++)
	{
		// On compare le caractère courant à ceux de la table
	
		c = s.charAt (i);
		j = 0;
	
		while ((j < sFrom.length) && (c != sFrom.charAt (j)))
		{
			j ++;
		}
		
		// Est-ce que le caractère est accentué ?
		
		if (j != sFrom.length)
		{
			// Oui, on le retire
		
			sNoAccent = sNoAccent + sTo.charAt (j);
		}
		else
		{
			sNoAccent = sNoAccent + c;
		}
	}

	// Retourne la chaïne sans les caractères accentués
	return (sNoAccent)
}

function contient(chaine,unChar)
{
	longueur=chaine.length;
	for (i=0; i<longueur; i++)
	{
		if (chaine.charAt(i) == unChar.charAt(0))
		{
			//alert(chaine +" - "+unChar + " - " + i);
			return true;
		}
	}
	return false;
}

function trim(inputString) 
{
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") 
   { 
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") 
   { 
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) 
   { 
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
   }
   return retValue; 
}  

function envoyer()
{
	tmpTxt=trim(window.document.recherche.key.value);
	window.document.recherche.key.value=tmpTxt;

	if(contient(window.document.recherche.key.value,'*')
	||contient(window.document.recherche.key.value,'/')
	||contient(window.document.recherche.key.value,'\\')
	||contient(window.document.recherche.key.value,'<')
	||contient(window.document.recherche.key.value,'>')
	||contient(window.document.recherche.key.value,'|')
	||contient(window.document.recherche.key.value,'\"')
	||contient(window.document.recherche.key.value,'\'')
	||contient(window.document.recherche.key.value,'[')
	||contient(window.document.recherche.key.value,']')
	||contient(window.document.recherche.key.value,'@')
	||contient(window.document.recherche.key.value,'#')
	||contient(window.document.recherche.key.value,'_')
	||contient(window.document.recherche.key.value,'&')
	||contient(window.document.recherche.key.value,'~')
	||contient(window.document.recherche.key.value,'^')
	||contient(window.document.recherche.key.value,'µ')
	||contient(window.document.recherche.key.value,'$')
	||contient(window.document.recherche.key.value,'£')
	||contient(window.document.recherche.key.value,'%')
	||contient(window.document.recherche.key.value,'?')
	||contient(window.document.recherche.key.value,',')
	||contient(window.document.recherche.key.value,';')
	||contient(window.document.recherche.key.value,'.')
	||contient(window.document.recherche.key.value,':')
	||contient(window.document.recherche.key.value,'!')
	||contient(window.document.recherche.key.value,'§')
	||contient(window.document.recherche.key.value,'{')
	||contient(window.document.recherche.key.value,'}')
	||contient(window.document.recherche.key.value,'=')				
	||contient(window.document.recherche.key.value,'+')
	||contient(window.document.recherche.key.value,'-')
	||contient(window.document.recherche.key.value,'¤')
	||contient(window.document.recherche.key.value,'(')
	||contient(window.document.recherche.key.value,')')
	)
		{
		//alert("Le texte recherché ne peut contenir l'un des caractères suivants :\r\n/*?\"<>|\'");
		window.document.recherche.key.value="";
		return false;
		}
	else 
		if(window.document.recherche.key.value.length<3)
		{
			//alert("Le texte recherché doit contenir 3 car. au minimum");
			window.document.recherche.key.value="";
			return false;
		}
		else
		{
			window.document.recherche.action="../home/search.jsp";
			window.document.recherche.key.value=removeAccent(window.document.recherche.key.value);
			window.document.recherche.submit();
		}
}

function viderCase(objet)
{
	objet.value='';
}