/*
 * 
 * http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
 * Herve CARTRON
 * Version 1.0 (2007-01-08)
 * 
 * Copyright (c) 2007 Le Phare
 * Nécessite :
 * - prototype.js (version 1.5.0_rc2 ou sup)
 * - validation.js : Really easy field validation with Prototype http://tetlaw.id.au/view/blog/really-easy-field-validation-with-prototype
 *
 */

/*
Validation.add('toto', 'Error message text', {
     pattern : new RegExp("^[a-zA-Z]+$","gi"), // only letter allowed
     minLength : 6, // value must be at least 6 characters
     maxLength : 13, // value must be no longer than 13 characters
     min : 5, // value is not less than this number
     max : 100, // value is not more than this number
     notOneOf : ['password', 'PASSWORD'], // value does not equal anything in this array
     oneOf : ['fish','chicken','beef'], // value must equal one of the values in this array
     is :  '5', // value is equal to this string
     isNot : 'turnip', //value is not equal to this string
     equalToField : 'password', // value is equal to the form element with this ID
     notEqualToField : 'username', // value is not equal to the form element with this ID
     include : ['validate-alphanum'] // also tests each validator included in this array of validator keys (there are no sanity checks so beware infinite loops!)
});
*/

Validation.addAllThese([
     ['validate-limit-min', 'La valeur de ce champ est trop petite',
            function(v,elt) {
                              var limitmin = elt.getAttribute('min');
                              if(limitmin == null) {alert('Erreur : vous n\'avez pas défini l\'attribut > min < dans <element name="' + elt.name + '" />');return;}
                              limitmin = ($(limitmin) != null) ? $(limitmin).value : limitmin;
                              return Validation.get('IsEmpty').test(v) || (Validation.get('validate-number').test(v) && (parseFloat(v) > parseFloat(limitmin)));
     }],
     ['validate-limit-max', 'La valeur de ce champ est trop grande',
            function(v,elt) {
                              var limitmax = elt.getAttribute('max');
                              if(limitmax == null) {alert('Erreur : vous n\'avez pas défini l\'attribut > max < dans <element name="' + elt.name + '" />');return;}
                              limitmax = ($(limitmax) != null) ? $(limitmax).value : limitmax;
                              return Validation.get('IsEmpty').test(v) || (Validation.get('validate-number').test(v) && (parseFloat(v) < parseFloat(limitmax)));
     }],
     ['validate-limit-between', 'Vous n\'êtes pas dans le bon intervalle',
            function(v,elt) {
                              return Validation.get('IsEmpty').test(v) || (Validation.get('validate-number').test(v) && Validation.get('validate-limit-min').test(v,elt) && Validation.get('validate-limit-max').test(v,elt));
     }],
     ['birthdate', 'Veuillez renseigner votre date de naissance',
            function(v,elt) {
                              return !Validation.get('IsEmpty').test(v) && !Validation.get('IsEmpty').test($('data_birthdate_j_').value);
     }]
]);