		//  Remplace toutes les occurences d'une chaine
	function replaceAll(str, search, repl) {
		//alert(search);
	  while (str.indexOf(search) != -1) 
		str = str.replace(search, repl);
		//alert(str);
	  return str;
	}

	// Remplace les caractères accentués (+ espace)
	function htmlToAccent(str) {
	  var spec = new Array("é", "É", "è", "È", "ê", "Ê", "ë", "Ë", "à", "À", "ù", "Ù", "ç", "Ç", " ");
	  var norm = new Array("e", "E", "e", "E", "e", "E", "e", "E", "a", "A", "u", "U", "c", "C", "");
	  for (var i = 0; i < spec.length; i++)
	  {
		str = replaceAll(str, spec[i], norm[i]);
	  }
	  //alert(str);
	  return str;
	}
	
	
	
	
	
	$(document).ready(function()
	{
	
		$("input[type=text], select").each(function(){
			$(this).css({ 'margin-left':(250-$(this).prev("label").width()) });
		});
	
	
	
	
	
		$("input[name!=sujet][type!=reset][type!=submit], select").focus(function()
		{
			$(this).css({'border':'1px outset #e0ce00', 'background-color':'#f8ffac', 'margin':'3px;', 'padding':'7px;'});
			$(this).prev("label").css({'font-weight':'bold'});
			$(this).css({ 'margin-left':(250-$(this).prev("label").width()) });
		});
		
		$("input[name!=sujet][type!=reset][type!=submit], select").blur(function()
		{
				$(this).prev("label").css({'font-weight':'normal'});
				$(this).css({ 'margin-left':(250-$(this).prev("label").width()) });		
		
				var name = $(this).attr("name");
				//alert(name);
				var value = $(this).val();
				//alert(htmlToAccent(value));

				
			switch(name)
			{
				case 'societe' : var regExp = new RegExp("^[A-Za-z0-9-._ ]{0,}$");
								 value = htmlToAccent(value);
				break;
				case 'nom' : var regExp = new RegExp("^[A-Za-z- ]{3,}$");
							 value = htmlToAccent(value);
				break;
				case 'prenom' : var regExp = new RegExp("^[A-Za-z- ]{3,}$");
								value = htmlToAccent(value);
				break;
				case 'email' : var regExp = new RegExp("^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$");
				break;
				case 'adresse' : var regExp = new RegExp("^[A-Za-z0-9-._ ]{2,}$");
								 value = htmlToAccent(value);
				break;
				case 'cp' : var regExp = new RegExp("^[0-9]{5}$");
				break;
				case 'ville' : var regExp = new RegExp("^[A-Za-z ]{2,}$");
							   value = htmlToAccent(value);
				break;
				case 'pays' : var regExp = new RegExp("^[A-Z]{2}$");
				break;
				case 'contenu' : var regExp = new RegExp("^[A-Za-z0-9-._ ]{0,}$");
								 value = htmlToAccent(value);
				break;
			}
			
				var resultat = regExp.test(value);
				
				if(resultat)               
				{
					$(this).css({'border':'1px outset #39C900', 'background-color':'c3ffac', 'margin':'4px;', 'padding':'4px;'});
					$(this).prev("label").css({'color':'#96e905'});
					$(this).next("div").html('<img class="valide" src="scripts/champ_valide.png" alt="Champ Valide" width="28px"/>');
				}
				else
				{
					$(this).css({'border':'1px outset #e00000', 'background-color':'ff8181', 'margin':'4px;', 'padding':'4px;'});
					$(this).prev("label").css({'color':'#ff4141'});
					$(this).next("div").html('<img class="invalide" src="scripts/champ_invalide.png" alt="Champ Invalide" width="28px"/>');
				}
		});
		
		$("input[name=sujet]").focus(function()
		{
			$("input[name=sujet]").next("label").css({'color':'c0c0c0'});
			
			$(this).next("label").css({'font-weight':'bold', 'color':'#96e905'});
			$(this).prev("span").css({'font-weight':'bold'});
		});
		
		$("input[name=sujet]").blur(function()
		{
					$("input[name=sujet]").next("label").css({'font-weight':'normal'});
					
					$(this).next("label").css({'color':'#96e905'});
					$(this).prev("span").css({'color':'#96e905'});
		});
		/*
		$("textarea").focus(function()
		{
			$("textarea").css({'background-color':'#f8ffac'});
			
			$(this).prev("label").css({'font-weight':'bold'});
		});
		
		$("textarea").blur(function()
		{
					$("textarea").css({'background-color':'c3ffac'});
					
					$(this).prev("label").css({'color':'#41ff41', 'font-weight':'normal', });
		});*/
		
				$(this).css({ 'margin-left':(250-$(this).prev("label").width()) });	
	});	
