// JavaScript Document
	
	// Vérification en direct qu'un champ est un chiffre
	function verifNombre(champ) {
	var chiffres = new RegExp("[0-9/.-]");
	var verif;
	
		for(x = 0; x < champ.value.length; x++)
		{
		verif = chiffres.test(champ.value.charAt(x));
		if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
		}
	
	}
	
	// Verifier si c'est une numéro de téléphone correcte
	function Verifier_Numero_Telephone(num_tel)
	{
	// Definition du motif a matcher
	var regex = new RegExp(/^(01|02|03|04|05|06|08)[0-9]{8}/gi);

	// On renvoie match
 	return regex.test(num_tel) ? true : false;
 } 
		
	// Vérifié la validité d'un champ peut importe son type
	function verif(id, type) {
	
		var mauvais = null;
		var action = null;
		var message = null;
		var champ = $(id);				
		
		// On vérifie si le champ existe
		if(champ) {
			
			// On verifie que le champ n'est pas en disabled
			if(champ.disabled == false) {
				
				if(type == "text") {
						
					mauvais = eval(champ.value == "");
					action = "saisir";

				} else if(type == "select") {
					
					mauvais = eval(champ.selectedIndex == 0);
					action = "selectionner";
					
				} else if(type == "email") {
					
					a = champ.value;
					mauvais = true;
					
					for(var j=1;j<(a.length);j++){
							if(a.charAt(j)=='@'){
								if(j<(a.length-4)){
									for(var k=j;k<(a.length-2);k++){
										if(a.charAt(k)=='.') mauvais = false;
									}
								}
							}
						}
						
					action = "corriger";
					
				} else if(type == "date") {
					
					var input = champ.value;
					var regex = new RegExp("[/-]");
					var date = input.split(regex);
					var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
					var result = false;
					
					if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
					nbJours['2'] = 29;
					
					if( isNaN(date['2']) )
					result = true;
					
					if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
					result=true;
					
					if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
					result=true;
					
					mauvais = eval(result);
					action = "corriger";
										
				} else if(type == "numeric") {
					
					mauvais = eval(!Object.isNumber(champ.value));
					action = "numeriser";
					
				} else if(type == "telephone") {
					
					mauvais = eval(!Verifier_Numero_Telephone(champ.value));
					action = "corriger";
					
				} else if(type == "url") {
					
   					var regexp = new RegExp(/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);
   					mauvais = eval(!regexp.test(champ.value));
					action = 'corriger';
					
				} else if(type == "checkbox") {
					
					var checkbox = document.forms[0].elements[id];
					var nb_coche = 0;
					
					// S'il n'y a que une case
					nb_coche += (!checkbox.length && checkbox.checked) ? 1 : 0;
										
					for (i=0;i<checkbox.length;i++) {
					nb_coche += checkbox[i].checked ? 1 : 0;
					}
					
					mauvais = eval(nb_coche == 0);
					action = "cocher";
					
				}
								
				// En fonction du resultat.
				if(mauvais == true) {
				  	
				  message = "Veuillez "+action+" votre "+id.replace('_', ' ')+".\n";
				  //$(id).setStyle({background:"transparent url(img/contact/warning.gif) no-repeat top right"});
				  msgWindow.pop({y: Position.positionedOffset($(id))[1]+10, x: Position.positionedOffset($(id))[0]+10}, message);
				  $(id).focus();
				  
				} 
					
			}
		}
		
		return (message != null) ? message : "";
	}
	
	// Popup
	/* $Id: wc_regerror.js 43967 2008-03-25 10:47:03Z sboulais $ */
	var msgWindow = {
		pop: function(marker, msg) {
			var ymarker = marker.y;
			var xmarker = marker.x;
			if((this.currentMsg = msg) != this.lastMsg) {
				$("pop").firstChild.firstChild.firstChild.innerHTML = this.lastMsg = msg;
				if($("poplayer")) { /* fix for IE6 */
					$("poplayer").setStyle({"top": (ymarker - Element.getHeight("pop")) + "px", "right": xmarker + "px", "height": Element.getHeight("pop") + "px"});
				}
				$("pop").setStyle({"top": (ymarker - Element.getHeight("pop")) + "px", "left": xmarker + "px"});
				new Effect.Appear("pop", {duration: 0.4});
			}	
		},	
		hide: function() {
			$("pop").hide(); 
			if($("poplayer")) $("poplayer").hide();
		},
		currentMsg: "current",
		lastMsg: "last"
	}
	
	Event.observe(window, "load", function(event) {
	Event.observe("pop", "click", function(event) {msgWindow.hide(); }),
	$A(document.getElementsByTagName("textarea")).each(function (input) {
		Event.observe($(input), "keyup", function(event){
			msgWindow.hide();
			}.bindAsEventListener($(input))
		);
			
	}, false),
	$A(document.getElementsByTagName("input")).each(function (input) {
		Event.observe($(input), "keyup", function(event){
			msgWindow.hide();
			}.bindAsEventListener($(input))
		);
			
	}, false);
		
	});