// JavaScript Document
/* gVerifFrom */
GVerifForm = Class.create();
GVerifForm.prototype = {
		initialize: function(conteneur,ancre,fermeture_animee) {
			this.erreur ="";
			this.conteneur = $(conteneur)
			this.ancre = ancre;
			this.fermeture_animee = fermeture_animee;
			this.ligne_intro = '<span class="titre_verif_form">THE FOLLOWING FIELDS ARE INCOMPLETE OR MISSING</span><br/>';
			this.liste = "";
			if(!browser.isIE)
			{
				this.ghost_conteneur = document.createElement('div')
				this.ghost_conteneur.className = this.conteneur.className
				this.ghost_conteneur.style.height = '0'
				this.ghost_conteneur.style.overflow = 'hidden'
				this.conteneur.parentNode.appendChild(this.ghost_conteneur);
			}
			this.conteneur_verif = new Array;
		},
		ecrire: function(){
			this.conteneur.innerHTML = "<div>" + this.ligne_intro + this.liste + "</div>";
			if(!browser.isIE)
			{
				this.ghost_conteneur.innerHTML = this.conteneur.innerHTML;
				this.h = Element.getHeight(this.ghost_conteneur.firstChild);
			}
		},
		supprimer: function(){
			this.conteneur.innerHTML = ''
		},
		affiche: function(){
			return (this.conteneur.innerHTML == '') ? false : true
		},
		add:function(element){
			this.conteneur_verif.push(element);
		},
		init_noerror_element:function(element){
			$($(element).id+'_status').innerHTML = '';
		},
		traitement:function(element){
			var traitement = $A(this.conteneur_verif);
			var liste = "";
			traitement.each(function(element){
				if(element.traitement()!="")
				{
					switch(element.type)
					{
						case "select":
							liste += "<li>"+element.intitule+" required.</li>";
						break;
						case "radio":
							liste += "<li>"+element.intitule+".</li>";
						break;
						case "condition":
							liste += "<li>"+element.intitule+".</li>";
						break;

						default:
							liste += "<li>"+element.intitule+" "+element.traitement()+"</li>";
						break;
					}
					element.changeStyle(true)
				}
			});	
			// si erreur
			if(liste!="")
			{
				this.liste = "<ul>"+liste+"</ul>";
				
				if(this.affiche())
				{
					Element.setStyle(this.conteneur,{height:'auto'});
					this.ecrire();
				}
				else
				{
					//defixer la taille pour que la liste ne prenne pas toute sa place initiale
					this.ecrire()
					if(browser.isIE){Element.fixeElement(this.conteneur)}
					if(!browser.isIE){Element.setStyle(this.conteneur,{height:this.h+'px'});}
					new Effect.BlindDown(this.conteneur);
				}
				// test "ancre"
				if(this.ancre!="")
				{
					Element.versPosition(this.ancre)
				}
				
				return false
			}
			else
			{
				if(this.affiche() && this.fermeture_animee)
				{
					Element.fixeElement(this.conteneur)
					this.supprimer()
					Effect.BlindUp(this.conteneur);
				}
				return true
			}
		}
};
/* /gVerifFrom */

/* VerifFormTxt */
VerifFormTxt = Class.create();
VerifFormTxt.prototype = {
	initialize: function(element,intitule,obligatoire,taille_min,taille_max,carac_autorise,type) {
		this.element = $(element);
		this.intitule = intitule;
		this.valeur = $F(this.element);
		this.obligatoire = obligatoire;
		this.type=type;
		this.taille_min = taille_min;
		this.taille_max = (taille_max=='max') ? this.element.maxLength : taille_max;
		switch (carac_autorise)
		{
			case "chiffre":
				this.carac_autorise = "0123456789";
			break;
			case "nombre":
				this.carac_autorise = "0123456789., -";
			break;
			case "tel":
				this.carac_autorise = "0123456789. -";
			break;
			case "tel_inter":
				this.carac_autorise = "0123456789. -+()";
			break;
			case "alpha":
				this.carac_autorise = "abcdefghijklmnopqrstuvwxyzéèêëôöîïàâäûüç";
			break;
			case "alphachiffre":
				this.carac_autorise = "abcdefghijklmnopqrstuvwxyzéèêëôöîïàâäûüç0123456789";
			break;
			case "alphanombre":
				this.carac_autorise = "abcdefghijklmnopqrstuvwxyzéèêëôöîïàâäûüç0123456789., -";
			break;
			case "alpha_2":
				this.carac_autorise = "abcdefghijklmnopqrstuvwxyzéèêëôöîïàâäûüç0123456789.,- '()€$£%[]{}&=+@?!/°;:*~_’";
			break;
			default:
				this.carac_autorise = "";
			break;
		}
		this.type = type;
	},
	changeStyle: function(change){
		if(change)
		{
			//Element.addClassName(this.element,"verif_form_erreur");
			$(this.element.id+'_status').innerHTML = '<img src="/public/atr/html/toolkit/img/modele/warning.gif" alt="error" class="img_warning" />';
		}
		else
		{
			//Element.removeClassName(this.element,"verif_form_erreur")
			$(this.element.id+'_status').innerHTML = '';
		}
	},
	traitement: function(){
		this.changeStyle(false)
		switch (this.type)
		{
			/* texte */
			case "texte" :
				var valeur_t = this.valeur.toLowerCase();
				if (valeur_t.length==0)
				{
					if(this.obligatoire) return " required - size: "+this.taille_min+((this.taille_min!=this.taille_max && this.taille_max!=0)?" to "+this.taille_max:"")+" characters."
				}
				else {
					if (this.taille_min==this.taille_max&&valeur_t.length!=this.taille_min) return " incorrect size - size: "+this.taille_max+" characters."
					if (this.taille_max!=0 && valeur_t.length>this.taille_max) return " too long - maximum size: "+this.taille_max+" characters."
					if (valeur_t.length<this.taille_min) return " too short - minimum size: "+this.taille_min+" characters."
				}
				
				if (this.carac_autorise=="") return "" // si rien à vérifier renvoi ok
				
				for (var i=0;i<valeur_t.length;i++) {
					if (this.carac_autorise.indexOf(valeur_t.charAt(i))==-1 && valeur_t.charAt(i)!="\n" && escape(valeur_t.charAt(i))!="%0D" ) {
						return " wrongly filled - invalid character: "+valeur_t.charAt(i)+".";
					}
				}
				return ""
			break;
			
			/* email */
			case "email" :
				this.carac_autorise = "abcdefghijklmnopqrstuvwxyzéèêëôöîïàâäûüç0123456789.,- '()€$£%[]{}&=+@?!/°;:*~_’";
				var unemail = /^((\w+(\-\w+)*)*\.?(\w+(\-\w+)*))+@((\w+(\-\w+)*)*\.(\w+(\-\w+)*))+$/;
				var valeur_t = this.valeur.toLowerCase();
				if (valeur_t.length==0) {
					if(this.obligatoire) return " required - size: "+this.taille_min+((this.taille_min!=this.taille_max)?" to "+this.taille_max:"")+" characters."
				}
				else {
					if (this.taille_min==this.taille_max&&valeur_t.length!=this.taille_min) return " incorrect size - size: "+this.taille_max+" characters."
					if (this.taille_max!=0 && valeur_t.length>this.taille_max) return " too long - maximum size: "+this.taille_max+" characters."
					if (valeur_t.length<this.taille_min) return " too short - minimum size: "+this.taille_min+" characters."
				}
			
				if (this.carac_autorise=="") return "" // si rien à vérifier renvoi ok
			
				for (var i=0;i<valeur_t.length;i++) {
					if (this.carac_autorise.indexOf(valeur_t.charAt(i))==-1 && valeur_t.charAt(i)!="\n" && escape(valeur_t.charAt(i))!="%0D" ) {
						return " wrongly filled - invalid character: "+valeur_t.charAt(i)+".";
					}
				}
				
				if(!unemail.test(valeur_t)&&valeur_t.length!=0) {return " wrongly filled."} 
				
				return ""
			break;
			
			/* date */
			case "date" :
				this.carac_autorise = "0123456789/";
				var unedate = /^([0123])([0123456789])\/([01])([0123456789])\/([0123456789])([0123456789])$/;
				var valeur_t = this.valeur.toLowerCase();
				if (valeur_t.length==0) {
					if(this.obligatoire) return " required - size: "+this.taille_min+((this.taille_min!=this.taille_max)?" to "+this.taille_max:"")+" characters."
				}
				else {
					if (this.taille_min==this.taille_max&&valeur_t.length!=this.taille_min) return " incorrect size - size: "+this.taille_max+" characters."
					if (this.taille_max!=0 && valeur_t.length>this.taille_max) return " too long - maximum size: "+this.taille_max+" characters."
					if (valeur_t.length<this.taille_min) return " too short - minimum size: "+this.taille_min+" characters."
				}
			
				if (this.carac_autorise=="") return "" // si rien à vérifier renvoi ok
			
				for (var i=0;i<valeur_t.length;i++) {
					if (this.carac_autorise.indexOf(valeur_t.charAt(i))==-1 && valeur_t.charAt(i)!="\n" && escape(valeur_t.charAt(i))!="%0D" ) {
						return " wrongly filled - invalid character: "+valeur_t.charAt(i)+".";
					}
				}
				
				if(!unedate.test(valeur_t)&&valeur_t.length!=0) {return " wrongly filled."} 
				return ""

			/* defaut */
			default:
				return ""
			break;
		}
	}
};
/* VerifFormTxt */

/* VerifFormSelect */
VerifFormSelect = Class.create();
VerifFormSelect.prototype = {
	initialize: function(element,intitule,obligatoire) {
		this.element = $(element);
		this.intitule = intitule;
		this.valeur = $F(this.element);
		this.obligatoire = obligatoire;
		this.type="select";
	},
	changeStyle: function(change){
		if(change)
		{
			//Element.addClassName(this.element,"verif_form_erreur")
			$(this.element.id+'_status').innerHTML = '<img src="/public/atr/html/toolkit/img/modele/warning.gif" alt="error" class="img_warning" />';
		}
		else
		{
			//Element.removeClassName(this.element,"verif_form_erreur")
			$(this.element.id+'_status').innerHTML = '';
		}
	},
	traitement: function(){
		this.changeStyle(false)
		if(Form.Element.getValue(this.element)=='defaut')
		{return "erreur"}			
		return ""
	}
};
/* VerifFormSelect */

/* VerifFormRadio */
VerifFormRadio = Class.create();
VerifFormRadio.prototype = {
	initialize: function(element,intitule,obligatoire,choix) {
		this.element = $(element);
		this.intitule = intitule;
		this.obligatoire = obligatoire;
		this.type="radio";
		this.choix = choix;
	},
	changeStyle: function(change){
		if(change)
		{
			//Element.addClassName(this.element,"verif_form_erreur")
			$(this.element.id+'_status').innerHTML = '<img src="/public/atr/html/toolkit/img/modele/warning.gif" alt="error" class="img_warning" />';
		}
		else
		{
			//Element.removeClassName(this.element,"verif_form_erreur")
			$(this.element.id+'_status').innerHTML = '';
		}
	},
	traitement: function(){
		this.changeStyle(false)
		var enfants = this.element.childNodes;
		var check = false;
		var dd = (this.choix == null)? $A(enfants) : $A(this.choix);
		dd.each(function(element){
			if($(element).type == "radio"){if($(element).checked){check = true}}
			if($(element).type == "checkbox"){if($(element).checked){check = true}}
		});
		if(check){return ""}
		return "erreur"
	}
};



/*VerifFormRadio = Class.create();
VerifFormRadio.prototype = {
	initialize: function(element,intitule,obligatoire) {
		this.element = $(element);
		this.intitule = intitule;
		this.obligatoire = obligatoire;
		this.type="radio";
	},
	changeStyle: function(change){
		if(change)
		{

			$(this.element.id+'_status').innerHTML = '<img src="../../img/modele/warning.gif" alt="error" class="img_warning" />';

			
		}
		else
		{

			$(this.element.id+'_status').innerHTML = '';
		}
	},
	traitement: function(){
		this.changeStyle(false)
		var enfants = this.element.childNodes;
		var check = false;
		var dd = $A(enfants);
		dd.each(function(element){
			if(element.type == "radio")
				if(element.checked){check = true}
		});
		if(check){return ""}
		return "erreur"
	}
};
*//* VerifFormRadio */

/* VerifFormCondition */
VerifFormCondition = Class.create();
VerifFormCondition.prototype = {
	initialize: function(intitule,elements) {
		this.intitule = intitule;
		this.type="condition";
		this.elements = elements;
	},
	changeStyle: function(change){
		for(var i = 0 ; i < this.elements.length ; i++)
		{
			if(change)
			{
				//Element.addClassName(this.elements[i],"verif_form_erreur")
				$(this.elements[i]+'_status').innerHTML = '<img src="/public/atr/html/toolkit/img/modele/warning.gif" alt="error" class="img_warning" />';

			}
			else
			{
				//Element.removeClassName(this.elements[i],"verif_form_erreur")
				$(this.elements[i]+'_status').innerHTML = '';
			}
		}
	},
	traitement: function(){
		return "intitule"
	}
	
};
/* VerifFormRadio */