PageSourceSearch

https://www.ozone.bg/js/prototype/validation.js

js ozone.bg collected 2026-10-02 05:42:32 UTC 52,360 bytes, 1,101 lines download raw bytes

1/*
2* Really easy field validation with Prototype
3* http://tetlaw.id.au/view/javascript/really-easy-field-validation
4* Andrew Tetlaw
5* Version 1.5.4.1 (2007-01-05)
6*
7* Copyright (c) 2007 Andrew Tetlaw
8* Permission is hereby granted, free of charge, to any person
9* obtaining a copy of this software and associated documentation
10* files (the "Software"), to deal in the Software without
11* restriction, including without limitation the rights to use, copy,
12* modify, merge, publish, distribute, sublicense, and/or sell copies
13* of the Software, and to permit persons to whom the Software is
14* furnished to do so, subject to the following conditions:
15*
16* The above copyright notice and this permission notice shall be
17* included in all copies or substantial portions of the Software.
18*
19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26* SOFTWARE.
27*
28*/
29var Validator = Class.create();
30
31Validator.prototype = {
32    initialize : function(className, error, test, options) {
33        if(typeof test == 'function'){
34            this.options = $H(options);
35            this._test = test;
36        } else {
37            this.options = $H(test);
38            this._test = function(){return true};
39        }
40        this.error = error || 'Validation failed.';
41        this.className = className;
42    },
43    test : function(v, elm) {
44        return (this._test(v,elm) && this.options.all(function(p){
45            return Validator.methods[p.key] ? Validator.methods[p.key](v,elm,p.value) : true;
46        }));
47    }
48}
49Validator.methods = {
50    pattern : function(v,elm,opt) {return Validation.get('IsEmpty').test(v) || opt.test(v)},
51    minLength : function(v,elm,opt) {return v.length >= opt},
52    maxLength : function(v,elm,opt) {return v.length <= opt},
53    min : function(v,elm,opt) {return v >= parseFloat(opt)},
54    max : function(v,elm,opt) {return v <= parseFloat(opt)},
55    notOneOf : function(v,elm,opt) {return $A(opt).all(function(value) {
56        return v != value;
57    })},
58    oneOf : function(v,elm,opt) {return $A(opt).any(function(value) {
59        return v == value;
60    })},
61    is : function(v,elm,opt) {return v == opt},
62    isNot : function(v,elm,opt) {return v != opt},
63    equalToField : function(v,elm,opt) {return v == $F(opt)},
64    notEqualToField : function(v,elm,opt) {return v != $F(opt)},
65    include : function(v,elm,opt) {return $A(opt).all(function(value) {
66        return Validation.get(value).test(v,elm);
67    })}
68}
69
70var Validation = Class.create();
71Validation.defaultOptions = {
72    onSubmit : true,
73    stopOnFirst : false,
74    immediate : false,
75    focusOnError : true,
76    useTitles : false,
77    addClassNameToContainer: false,
78    containerClassName: '.input-box',
79    onFormValidate : function(result, form) {},
80    onElementValidate : function(result, elm) {}
81};
82
83Validation.prototype = {
84    initialize : function(form, options){
85        this.form = $(form);
86        if (!this.form) {
87            return;
88        }
89        this.options = Object.extend({
90            onSubmit : Validation.defaultOptions.onSubmit,
91            stopOnFirst : Validation.defaultOptions.stopOnFirst,
92            immediate : Validation.defaultOptions.immediate,
93            focusOnError : Validation.defaultOptions.focusOnError,
94            useTitles : Validation.defaultOptions.useTitles,
95            onFormValidate : Validation.defaultOptions.onFormValidate,
96            onElementValidate : Validation.defaultOptions.onElementValidate
97        }, options || {});
98        if(this.options.onSubmit) Event.observe(this.form,'submit',this.onSubmit.bind(this),false);
99        if(this.options.immediate) {
100            Form.getElements(this.form).each(function(input) { // Thanks Mike!
101                if (input.tagName.toLowerCase() == 'select') {
102                    Event.observe(input, 'blur', this.onChange.bindAsEventListener(this));
103                }
104                if (input.type.toLowerCase() == 'radio' || input.type.toLowerCase() == 'checkbox') {
105                    Event.observe(input, 'click', this.onChange.bindAsEventListener(this));
106                } else {
107                    Event.observe(input, 'change', this.onChange.bindAsEventListener(this));
108                }
109            }, this);
110        }
111    },
112    onChange : function (ev) {
113        Validation.isOnChange = true;
114        Validation.validate(Event.element(ev),{
115                useTitle : this.options.useTitles,
116                onElementValidate : this.options.onElementValidate
117        });
118        Validation.isOnChange = false;
119    },
120    onSubmit :  function(ev){
121        if(!this.validate()) Event.stop(ev);
122    },
123    validate : function() {
124        var result = false;
125        var useTitles = this.options.useTitles;
126        var callback = this.options.onElementValidate;
127        try {
128            if(this.options.stopOnFirst) {
129                result = Form.getElements(this.form).all(function(elm) {
130                    if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
131                        return true;
132                    }
133                    return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
134                }, this);
135            } else {
136                result = Form.getElements(this.form).collect(function(elm) {
137                    if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
138                        return true;
139                    }
140                    return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
141                }, this).all();
142            }
143        } catch (e) {
144        }
145        if(!result && this.options.focusOnError) {
146            try{
147                Form.getElements(this.form).findAll(function(elm){return $(elm).hasClassName('validation-failed')}).first().focus()
148            }
149            catch(e){
150            }
151        }
152        this.options.onFormValidate(result, this.form);
153        return result;
154    },
155    reset : function() {
156        Form.getElements(this.form).each(Validation.reset);
157    },
158    isElementInForm : function(elm, form) {
159        var domForm = elm.up('form');
160        if (domForm == form) {
161            return true;
162        }
163        return false;
164    }
165}
166
167Object.extend(Validation, {
168    validate : function(elm, options){
169        options = Object.extend({
170            useTitle : false,
171            onElementValidate : function(result, elm) {}
172        }, options || {});
173        elm = $(elm);
174
175        var cn = $w(elm.className);
176        return result = cn.all(function(value) {
177            var test = Validation.test(value,elm,options.useTitle);
178            options.onElementValidate(test, elm);
179            return test;
180        });
181    },
182    insertAdvice : function(elm, advice){
183        var container = $(elm).up('.field-row');
184        if(container){
185            Element.insert(container, {after: advice});
186        } else if (elm.up('td.value')) {
187            elm.up('td.value').insert({bottom: advice});
188        } else if (elm.advaiceContainer && $(elm.advaiceContainer)) {
189            $(elm.advaiceContainer).update(advice);
190        }
191        else {
192            switch (elm.type.toLowerCase()) {
193                case 'checkbox':
194                case 'radio':
195                    var p = elm.parentNode;
196                    if(p) {
197                        Element.insert(p, {'bottom': advice});
198                    } else {
199                        Element.insert(elm, {'after': advice});
200                    }
201                    break;
202                default:
203                    // Change position error with select2 for All + ozone.ro
204                    if (elm.hasClassName('chosen-select') || elm.hasClassName('chosen-only-towns1') || elm.hasClassName('chosen-only-towns')) {
205                        elm = elm.siblings('.select2-container').last();
206                    }
207                    // Change position error for password field
208                    if (elm.hasClassName('validate-password') || elm.hasClassName('validate-cpassword') || elm.getAttribute('id') == 'current_password' || elm.hasClassName('baby-error-fix') ) {
209                        elm = elm.siblings('.toggle-password').last()
210                    }
211                    Element.insert(elm, {'after': advice});
212            }
213        }
214    },
215    showAdvice : function(elm, advice, adviceName){
216        if(!elm.advices){
217            elm.advices = new Hash();
218        }
219        else{
220            elm.advices.each(function(pair){
221                if (!advice || pair.value.id != advice.id) {
222                    // hide non-current advice after delay
223                    this.hideAdvice(elm, pair.value);
224                }
225            }.bind(this));
226        }
227        elm.advices.set(adviceName, advice);
228        if(typeof Effect == 'undefined') {
229            advice.style.display = 'block';
230        } else {
231            if(!advice._adviceAbsolutize) {
232                new Effect.Appear(advice, {duration : 1 });
233            } else {
234                Position.absolutize(advice);
235                advice.show();
236                advice.setStyle({
237                    'top':advice._adviceTop,
238                    'left': advice._adviceLeft,
239                    'width': advice._adviceWidth,
240                    'z-index': 1000
241                });
242                advice.addClassName('advice-absolute');
243            }
244        }
245    },
246    hideAdvice : function(elm, advice){
247        if (advice != null) {
248            new Effect.Fade(advice, {duration : 1, afterFinishInternal : function() {advice.hide();}});
249        }
250    },
251    updateCallback : function(elm, status) {
252        if (typeof elm.callbackFunction != 'undefined') {
253            eval(elm.callbackFunction+'(\''+elm.id+'\',\''+status+'\')');
254        }
255    },
256    ajaxError : function(elm, errorMsg) {
257        var name = 'validate-ajax';
258        var advice = Validation.getAdvice(name, elm);
259        if (advice == null) {
260            advice = this.createAdvice(name, elm, false, errorMsg);
261        }
262        this.showAdvice(elm, advice, 'validate-ajax');
263        this.updateCallback(elm, 'failed');
264
265        elm.addClassName('validation-failed');
266        elm.addClassName('validate-ajax');
267        if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
268            var container = elm.up(Validation.defaultOptions.containerClassName);
269            if (container && this.allowContainerClassName(elm)) {
270                container.removeClassName('validation-passed');
271                container.addClassName('validation-error');
272            }
273        }
274    },
275    allowContainerClassName: function (elm) {
276        if (elm.type == 'radio' || elm.type == 'checkbox') {
277            return elm.hasClassName('change-container-classname');
278        }
279
280        return true;
281    },
282    test : function(name, elm, useTitle) {
283        var v = Validation.get(name);
284        var prop = '__advice'+name.camelize();
285        try {
286        if(Validation.isVisible(elm) && !v.test($F(elm), elm)) {
287            //if(!elm[prop]) {
288                var advice = Validation.getAdvice(name, elm);
289                if (advice == null) {
290                    advice = this.createAdvice(name, elm, useTitle);
291                }
292                this.showAdvice(elm, advice, name);
293                this.updateCallback(elm, 'failed');
294            //}
295            elm[prop] = 1;
296            if (!elm.advaiceContainer) {
297                elm.removeClassName('validation-passed');
298                elm.addClassName('validation-failed');
299            }
300
301           if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
302                var container = elm.up(Validation.defaultOptions.containerClassName);
303                if (container && this.allowContainerClassName(elm)) {
304                    container.removeClassName('validation-passed');
305                    container.addClassName('validation-error');
306                }
307            }
308            return false;
309        } else {
310            var advice = Validation.getAdvice(name, elm);
311            this.hideAdvice(elm, advice);
312            this.updateCallback(elm, 'passed');
313            elm[prop] = '';
314            elm.removeClassName('validation-failed');
315            elm.addClassName('validation-passed');
316            if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
317                var container = elm.up(Validation.defaultOptions.containerClassName);
318                if (container && !container.down('.validation-failed') && this.allowContainerClassName(elm)) {
319                    if (!Validation.get('IsEmpty').test(elm.value) || !this.isVisible(elm)) {
320                        container.addClassName('validation-passed');
321                    } else {
322                        container.removeClassName('validation-passed');
323                    }
324                    container.removeClassName('validation-error');
325                }
326            }
327            return true;
328        }
329        } catch(e) {
330            throw(e)
331        }
332    },
333    isVisible : function(elm) {
334        while(elm.tagName != 'BODY') {
335            if(!$(elm).visible()) return false;
336            elm = elm.parentNode;
337        }
338        return true;
339    },
340    getAdvice : function(name, elm) {
341        return $('advice-' + name + '-' + Validation.getElmID(elm)) || $('advice-' + Validation.getElmID(elm));
342    },
343    createAdvice : function(name, elm, useTitle, customError) {
344        var v = Validation.get(name);
345        var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
346        if (customError) {
347            errorMsg = customError;
348        }
349        try {
350            if (Translator){
351                errorMsg = Translator.translate(errorMsg);
352            }
353        }
354        catch(e){}
355
356        advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none">' + errorMsg + '</div>'
357
358
359        Validation.insertAdvice(elm, advice);
360        advice = Validation.getAdvice(name, elm);
361        if($(elm).hasClassName('absolute-advice')) {
362            var dimensions = $(elm).getDimensions();
363            var originalPosition = Position.cumulativeOffset(elm);
364
365            advice._adviceTop = (originalPosition[1] + dimensions.height) + 'px';
366            advice._adviceLeft = (originalPosition[0])  + 'px';
367            advice._adviceWidth = (dimensions.width)  + 'px';
368            advice._adviceAbsolutize = true;
369        }
370        return advice;
371    },
372    getElmID : function(elm) {
373        return elm.id ? elm.id : elm.name;
374    },
375    reset : function(elm) {
376        elm = $(elm);
377        var cn = $w(elm.className);
378        cn.each(function(value) {
379            var prop = '__advice'+value.camelize();
380            if(elm[prop]) {
381                var advice = Validation.getAdvice(value, elm);
382                if (advice) {
383                    advice.hide();
384                }
385                elm[prop] = '';
386            }
387            elm.removeClassName('validation-failed');
388            elm.removeClassName('validation-passed');
389            if (Validation.defaultOptions.addClassNameToContainer && Validation.defaultOptions.containerClassName != '') {
390                var container = elm.up(Validation.defaultOptions.containerClassName);
391                if (container) {
392                    container.removeClassName('validation-passed');
393                    container.removeClassName('validation-error');
394                }
395            }
396        });
397    },
398    add : function(className, error, test, options) {
399        var nv = {};
400        nv[className] = new Validator(className, error, test, options);
401        Object.extend(Validation.methods, nv);
402    },
403    addAllThese : function(validators) {
404        var nv = {};
405        $A(validators).each(function(value) {
406                nv[value[0]] = new Validator(value[0], value[1], value[2], (value.length > 3 ? value[3] : {}));
407            });
408        Object.extend(Validation.methods, nv);
409    },
410    get : function(name) {
411        return  Validation.methods[name] ? Validation.methods[name] : Validation.methods['_LikeNoIDIEverSaw_'];
412    },
413    methods : {
414        '_LikeNoIDIEverSaw_' : new Validator('_LikeNoIDIEverSaw_','',{})
415    }
416});
417
418Validation.add('IsEmpty', '', function(v) {
419    return  (v == '' || (v == null) || (v.length == 0) || /^\s+$/.test(v));
420});
421
422Validation.addAllThese([
423    ['validate-no-html-tags', 'HTML tags are not allowed', function(v) {
424				return !/<(\/)?\w+/.test(v);
425			}],
426	['validate-select', 'Please select an option.', function(v) {
427                return ((v != "none") && (v != null) && (v.length != 0));
428            }],
429    ['required-entry', 'This is a required field.', function(v) {
430                return !Validation.get('IsEmpty').test(v);
431            }],
432    ['validate-number', 'Please enter a valid number in this field.', function(v) {
433                return Validation.get('IsEmpty').test(v)
434                    || (!isNaN(parseNumber(v)) && /^\s*-?\d*(\.\d*)?\s*$/.test(v));
435            }],
436    ['validate-number-range', 'The value is not within the specified range.', function(v, elm) {
437                if (Validation.get('IsEmpty').test(v)) {
438                    return true;
439                }
440
441                var numValue = parseNumber(v);
442                if (isNaN(numValue)) {
443                    return false;
444                }
445
446                var reRange = /^number-range-(-?[\d.,]+)?-(-?[\d.,]+)?$/,
447                    result = true;
448
449                $w(elm.className).each(function(name) {
450                    var m = reRange.exec(name);
451                    if (m) {
452                        result = result
453                            && (m[1] == null || m[1] == '' || numValue >= parseNumber(m[1]))
454                            && (m[2] == null || m[2] == '' || numValue <= parseNumber(m[2]));
455                    }
456                });
457
458                return result;
459            }],
460    ['validate-digits', 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.', function(v) {
461                return Validation.get('IsEmpty').test(v) ||  !/[^\d]/.test(v);
462            }],
463
464    ['validate-list', 'Това поле може да съдържа 18 символа.', function(v) {
465        return Validation.get('IsEmpty').test(v) ||  /^[а-яА-Я\w\s]{1,17}$/.test(v);
466    }],
467
468    ['validate-iban', 'Това поле може да съдържа само латински букви и цифри.', function(v) {
469        return Validation.get('IsEmpty').test(v) ||  /^[A-Za-z0-9]+$/.test(v);
470    }],
471
472	['validate-bg-number', 'Моля, използвайте само български номера.', function(v) {
473        return Validation.get('IsEmpty').test(v) ||  /^[+359]+\s?(?![3]{1}[5]{1}\s[9]{1})([1-9]{1}[0-9]{1}\s[0-9]{1})[0-9]{2}\s[0-9]{4}$/.test(v);
474    }],
475
476    ['validate-gr-number', 'Χρησιμοποιήστε μόνο ελληνικούς αριθμούς.', function(v) {
477        return Validation.get('IsEmpty').test(v) ||  /^[+30]+\s?(?![0]{1})[0-9]{2}\s[0-9]{4}\s[0-9]{4}$/.test(v);
478    }],
479
480    ['validate-hr-number', 'Molimo koristite samo hrvatske brojeve', function(v) {
481        return Validation.get('IsEmpty').test(v) ||  /^[+385]+\s?(?![0]{1})[0-9]{2}\s[0-9]{3}\s([0-9]{4}|[0-9]{3})$/.test(v);
482    }],
483
484    ['validate-ro-number', 'Va rugam sa utilizati doar numere romanesti.', function(v) {
485        return Validation.get('IsEmpty').test(v) ||  /^[+40]+\s?(?![0]{1})[0-9]{2}\s[0-9]{3}\s[0-9]{4}$/.test(v);
486    }],
487	
488	['validate-length-10', 'Това поле може да съдържа 10 цифри.', function(v) {
489        return Validation.get('IsEmpty').test(v) || /^\d{10}$/.test(v);
490	}],
491    
492    ['validate-length-9', 'Това поле може да съдържа 9 цифри.', function(v) {
493		return Validation.get('IsEmpty').test(v) || /^\d{9}$/.test(v);
494	}],
495
496    ['validate-length-9-gr', 'Αυτό το πεδίο μπορεί να περιέχει 9 ψηφία.', function(v) {
497        return Validation.get('IsEmpty').test(v) || /^\d{9}$/.test(v);
498    }],
499
500    ['validate-length-11', 'Това поле може да съдържа 11 цифри.', function(v) {
501		return Validation.get('IsEmpty').test(v) || /^\d{11}$/.test(v);
502	}],
503
504    ['validate-length-11-hr', 'Ovo polje može sadržavati 11 znamenki.', function(v) {
505        return Validation.get('IsEmpty').test(v) || /^\d{11}$/.test(v);
506    }],
507
508    ['validate-length-9-or-10', 'Това поле може да съдържа 9 или 10 цифри.', function(v) {
509        return Validation.get('IsEmpty').test(v) || /^\d{9}$|^\d{10}$/.test(v);
510    }],
511    ['validate-length-2-between-10-ro', 'Acest câmp trebuie să conțină între 2 și 10 cifre.', function(v) {
512        return Validation.get('IsEmpty').test(v) || /^\d{2,10}$/.test(v);
513    }],
514
515    ['validate-vat-length-9-or-10', 'Това поле трябва да съдържа BG и след него 9 или 10 цифри.', function(v) {
516        return Validation.get('IsEmpty').test(v) || /^BG\d{9}$|^BG\d{10}$/.test(v);
517    }],
518
519    ['validate-vat-length-9', 'Това поле трябва да съдържа BG и след него 9 цифри.', function(v) {
520        return Validation.get('IsEmpty').test(v) || /^BG\d{9}$/.test(v);
521    }],
522
523    ['validate-vat-match-bg', 'ДДС номера не съвпада с ЕИК номера.', function(v, elm) {
524        if (Validation.get('IsEmpty').test(v)) {
525            return true;
526        }
527
528        var sourceField = $$('.validate-vat-match-source')[0];
529        if (!sourceField) {
530            return true; 
531        }
532
533        var sourceValue = $F(sourceField);
534        if (Validation.get('IsEmpty').test(sourceValue)) {
535            return true;
536        }
537
538        var expectedPattern = '^BG' + sourceValue + '$';
539        var regex = new RegExp(expectedPattern);
540
541        return regex.test(v);
542    }],
543
544    ['validate-vat-match-ro', 'Numărul de TVA nu corespunde cu numărul de înregistrare.', function(v, elm) {
545        if (Validation.get('IsEmpty').test(v)) {
546            return true;
547        }
548
549        var sourceField = $$('.validate-vat-match-source')[0];
550        if (!sourceField) {
551            return true; 
552        }
553
554        var sourceValue = $F(sourceField);
555        if (Validation.get('IsEmpty').test(sourceValue)) {
556            return true;
557        }
558
559        var expectedPattern = '^RO' + sourceValue + '$';
560        var regex = new RegExp(expectedPattern);
561
562        return regex.test(v);
563    }],
564
565    ['validate-vat-match-hr', 'PDV broj se ne podudara s OIB brojem.', function(v, elm) {
566        if (Validation.get('IsEmpty').test(v)) {
567            return true;
568        }
569
570        var sourceField = $$('.validate-vat-match-source')[0];
571        if (!sourceField) {
572            return true; 
573        }
574
575        var sourceValue = $F(sourceField);
576        if (Validation.get('IsEmpty').test(sourceValue)) {
577            return true;
578        }
579
580        var expectedPattern = '^HR' + sourceValue + '$';
581        var regex = new RegExp(expectedPattern);
582
583        return regex.test(v);
584    }],
585
586    ['validate-vat-match-gr', 'Ο αριθμός ΦΠΑ δεν ταιριάζει με τον αριθμό ΓΕΜΗ.', function(v, elm) {
587        if (Validation.get('IsEmpty').test(v)) {
588            return true;
589        }
590
591        var sourceField = $$('.validate-vat-match-source')[0];
592        if (!sourceField) {
593            return true; 
594        }
595
596        var sourceValue = $F(sourceField);
597        if (Validation.get('IsEmpty').test(sourceValue)) {
598            return true;
599        }
600
601        var expectedPattern = '^EL' + sourceValue + '$';
602        var regex = new RegExp(expectedPattern);
603
604        return regex.test(v);
605    }],
606
607    ['validate-vat-ro', 'Numarul introdus este nevalid', function(v) {
608        return Validation.get('IsEmpty').test(v) || /^[a-za-z\w\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{1,15}$/.test(v);
609    }],
610
611    ['validate-vat-length-ro', 'Numărul TVA este invalid. Acesta trebuie să înceapă cu codul țării (RO) urmat de cifre.', function(v) {
612        return Validation.get('IsEmpty').test(v) || /^RO[a-za-z\w\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{1,15}$/.test(v);
613    }],
614
615    ['validate-vat-hr', 'Broj koji ste unijeli je nevažeći', function(v) {
616        return Validation.get('IsEmpty').test(v) || /^[a-za-z\w\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{1,15}$/.test(v);
617    }],
618
619    ['validate-vat-length-hr', 'PDV broj je nevažeći. Treba započeti kodom zemlje (HR) nakon kojeg slijedi 11 znamenki.', function(v) {
620        return Validation.get('IsEmpty').test(v) || /^HR[a-za-z\w\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{1,15}$/.test(v);
621    }],
622
623    ['validate-vat-gr', 'Ο αριθμός που εισαγάγατε δεν είναι έγκυρος', function(v) {
624        return Validation.get('IsEmpty').test(v) || /^[a-za-z\w\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{1,15}$/.test(v);
625    }],
626
627    ['validate-vat-length-gr', 'Ο ΑΦΜ δεν είναι έγκυρος. Πρέπει να ξεκινά με τον κωδικό χώρας (EL) ακολουθούμενο από 9 ψηφία.', function(v) {
628        return Validation.get('IsEmpty').test(v) || /^EL[a-za-z\w\s!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]{1,15}$/.test(v);
629    }],
630    ['validate-vat-length-2-between-10-ro', 'Numărul TVA trebuie să înceapă cu RO urmat de 2 până la 10 cifre.', function(v) {
631        return Validation.get('IsEmpty').test(v) || /^RO\d{2,10}$/.test(v);
632    }],
633    ['validate-vat-length-11-hr', 'PDV broj mora započeti s HR, nakon čega slijedi 11 znamenki.', function(v) {
634        return Validation.get('IsEmpty').test(v) || /^HR\d{11}$/.test(v);
635    }],
636    ['validate-vat-length-9-gr', 'Ο αριθμός ΦΠΑ πρέπει να ξεκινά με EL και να ακολουθούν 9 ψηφία.', function(v) {
637        return Validation.get('IsEmpty').test(v) || /^EL\d{9}$/.test(v);
638    }],
639			
640    ['validate-digits-range', 'The value is not within the specified range.', function(v, elm) {
641                if (Validation.get('IsEmpty').test(v)) {
642                    return true;
643                }
644
645                var numValue = parseNumber(v);
646                if (isNaN(numValue)) {
647                    return false;
648                }
649
650                var reRange = /^digits-range-(-?\d+)?-(-?\d+)?$/,
651                    result = true;
652
653                $w(elm.className).each(function(name) {
654                    var m = reRange.exec(name);
655                    if (m) {
656                        result = result
657                            && (m[1] == null || m[1] == '' || numValue >= parseNumber(m[1]))
658                            && (m[2] == null || m[2] == '' || numValue <= parseNumber(m[2]));
659                    }
660                });
661
662                return result;
663            }],
664    ['validate-alpha', 'Please use letters only (a-z or A-Z) in this field.', function (v) {
665                return Validation.get('IsEmpty').test(v) ||  /^[a-zA-Z]+$/.test(v)
666            }],
667    ['validate-code', 'Please use only letters (a-z), numbers (0-9) or underscore(_) in this field, first character should be a letter.', function (v) {
668                return Validation.get('IsEmpty').test(v) ||  /^[a-z]+[a-z0-9_]+$/.test(v)
669            }],
670    ['validate-alphanum', 'Please use only letters (a-z or A-Z) or numbers (0-9) only in this field. No spaces or other characters are allowed.', function(v) {
671                return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9]+$/.test(v)
672            }],
673    ['validate-alphanum-with-spaces', 'Please use only letters (a-z or A-Z), numbers (0-9) or spaces only in this field.', function(v) {
674                    return Validation.get('IsEmpty').test(v) || /^[a-zA-Z0-9 ]+$/.test(v)
675            }],
676    ['validate-street', 'Please use only letters (a-z or A-Z) or numbers (0-9) or spaces and # only in this field.', function(v) {
677                return Validation.get('IsEmpty').test(v) ||  /^[ \w]{3,}([A-Za-z]\.)?([ \w]*\#\d+)?(\r\n| )[ \w]{3,}/.test(v)
678            }],
679    ['validate-phoneStrict', 'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.', function(v) {
680                return Validation.get('IsEmpty').test(v) || /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/.test(v);
681            }],
682    ['validate-phoneLax', 'Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.', function(v) {
683                return Validation.get('IsEmpty').test(v) || /^((\d[-. ]?)?((\(\d{3}\))|\d{3}))?[-. ]?\d{3}[-. ]?\d{4}$/.test(v);
684            }],
685    ['validate-fax', 'Please enter a valid fax number. For example (123) 456-7890 or 123-456-7890.', function(v) {
686                return Validation.get('IsEmpty').test(v) || /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/.test(v);
687            }],
688    ['validate-date', 'Please enter a valid date.', function(v) {
689                var test = new Date(v);
690                return Validation.get('IsEmpty').test(v) || !isNaN(test);
691            }],
692    ['validate-date-range', 'The From Date value should be less than or equal to the To Date value.', function(v, elm) {
693            var m = /\bdate-range-(\w+)-(\w+)\b/.exec(elm.className);
694            if (!m || m[2] == 'to' || Validation.get('IsEmpty').test(v)) {
695                return true;
696            }
697
698            var currentYear = new Date().getFullYear() + '';
699            var normalizedTime = function(v) {
700                v = v.split(/[.\/]/);
701                if (v[2] && v[2].length < 4) {
702                    v[2] = currentYear.substr(0, v[2].length) + v[2];
703                }
704                return new Date(v.join('/')).getTime();
705            };
706
707            var dependentElements = Element.select(elm.form, '.validate-date-range.date-range-' + m[1] + '-to');
708            return !dependentElements.length || Validation.get('IsEmpty').test(dependentElements[0].value)
709                || normalizedTime(v) <= normalizedTime(dependentElements[0].value);
710        }],
711    ['validate-email', 'Please enter a valid email address. For example [email protected].', function (v) {
712                //return Validation.get('IsEmpty').test(v) || /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v)
713                //return Validation.get('IsEmpty').test(v) || /^[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9][\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9\.]{1,30}[\!\#$%\*/?|\^\{\}`~&\'\+\-=_a-z0-9]@([a-z0-9_-]{1,30}\.){1,5}[a-z]{2,4}$/i.test(v)
714                return Validation.get('IsEmpty').test(v) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v)
715            }],
716    ['validate-emailSender', 'Please use only visible characters and spaces.', function (v) {
717                return Validation.get('IsEmpty').test(v) ||  /^[\S ]+$/.test(v)
718                    }],
719    ['validate-password', 'The password must meet the conditions below', function(v) {
720                // Whith escape cirilic
721                return Validation.get('IsEmpty').test(v) || /^(?=.*?[A-Z])(?=.*?[a-z])((?=.*?[0-9])|(?=.*?[.#?!@$%^&*-]))(?!.*?[а-яА-ЯЁё]).{8,}$/.test(v);
722                // Whithout escape cirilic
723                // return Validation.get('IsEmpty').test(v) || /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[.#?!@$%^&*-]).{8,}$/.test(v);
724            }],
725    ['validate-password-login', 'Please enter 6 or more characters without leading or trailing space
725s.', function(v) {
726        var pass=v.strip(); /*strip leading and trailing spaces*/
727        return (!(v.length>0 && v.length < 6) && v.length == pass.length);
728    }],
729
730    ['validate-admin-password', 'Please enter 7 or more characters. Password should contain both numeric and alphabetic characters.', function(v) {
731                var pass=v.strip();
732                if (0 == pass.length) {
733                    return true;
734                }
735                if (!(/[a-z]/i.test(v)) || !(/[0-9]/.test(v))) {
736                    return false;
737                }
738                return !(pass.length < 7);
739            }],
740    ['validate-cpassword', 'Please make sure your passwords match.', function(v) {
741                var conf = $('confirmation') ? $('confirmation') : $$('.validate-cpassword')[0];
742                var pass = false;
743                if ($('password')) {
744                    pass = $('password');
745                }
746                var passwordElements = $$('.validate-password');
747                for (var i = 0; i < passwordElements.size(); i++) {
748                    var passwordElement = passwordElements[i];
749                    if (passwordElement.up('form').id == conf.up('form').id) {
750                        pass = passwordElement;
751                    }
752                }
753                if ($$('.validate-admin-password').size()) {
754                    pass = $$('.validate-admin-password')[0];
755                }
756                return (pass.value == conf.value);
757            }],
758    ['validate-both-passwords', 'Please make sure your passwords match.', function(v, input) {
759                var dependentInput = $(input.form[input.name == 'password' ? 'confirmation' : 'password']),
760                    isEqualValues  = input.value == dependentInput.value;
761
762                if (isEqualValues && dependentInput.hasClassName('validation-failed')) {
763                    Validation.test(this.className, dependentInput);
764                }
765
766                return dependentInput.value == '' || isEqualValues;
767            }],
768    ['validate-url', 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)', function (v) {
769                v = (v || '').replace(/^\s+/, '').replace(/\s+$/, '');
770                return Validation.get('IsEmpty').test(v) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(v)
771            }],
772    ['validate-clean-url', 'Please enter a valid URL. For example http://www.example.com or www.example.com', function (v) {
773                return Validation.get('IsEmpty').test(v) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i.test(v) || /^(www)((\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i.test(v)
774            }],
775    ['validate-identifier', 'Please enter a valid URL Key. For example "example-page", "example-page.html" or "anotherlevel/example-page".', function (v) {
776                return Validation.get('IsEmpty').test(v) || /^[a-z0-9][a-z0-9_\/-]+(\.[a-z0-9_-]+)?$/.test(v)
777            }],
778    ['validate-xml-identifier', 'Please enter a valid XML-identifier. For example something_1, block5, id-4.', function (v) {
779                return Validation.get('IsEmpty').test(v) || /^[A-Z][A-Z0-9_\/-]*$/i.test(v)
780            }],
781    ['validate-ssn', 'Please enter a valid social security number. For example 123-45-6789.', function(v) {
782            return Validation.get('IsEmpty').test(v) || /^\d{3}-?\d{2}-?\d{4}$/.test(v);
783            }],
784    ['validate-zip', 'Please enter a valid zip code. For example 90602 or 90602-1234.', function(v) {
785            return Validation.get('IsEmpty').test(v) || /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(v);
786            }],
787    ['validate-zip-international', 'Please enter a valid zip code.', function(v) {
788            //return Validation.get('IsEmpty').test(v) || /(^[A-z0-9]{2,10}([\s]{0,1}|[\-]{0,1})[A-z0-9]{2,10}$)/.test(v);
789            return true;
790            }],
791    ['validate-date-au', 'Please use this date format: dd/mm/yyyy. For example 17/03/2006 for the 17th of March, 2006.', function(v) {
792                if(Validation.get('IsEmpty').test(v)) return true;
793                var regex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
794                if(!regex.test(v)) return false;
795                var d = new Date(v.replace(regex, '$2/$1/$3'));
796                return ( parseInt(RegExp.$2, 10) == (1+d.getMonth()) ) &&
797                            (parseInt(RegExp.$1, 10) == d.getDate()) &&
798                            (parseInt(RegExp.$3, 10) == d.getFullYear() );
799            }],
800    ['validate-currency-dollar', 'Please enter a valid $ amount. For example $100.00.', function(v) {
801                // [$]1[##][,###]+[.##]
802                // [$]1###+[.##]
803                // [$]0.##
804                // [$].##
805                return Validation.get('IsEmpty').test(v) ||  /^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v)
806            }],
807    ['validate-one-required', 'Please select one of the above options.', function (v,elm) {
808                var p = elm.parentNode;
809                var options = p.getElementsByTagName('INPUT');
810                return $A(options).any(function(elm) {
811                    return $F(elm);
812                });
813            }],
814    ['validate-one-required-by-name', 'Please select one of the options.', function (v,elm) {
815                var inputs = $$('input[name="' + elm.name.replace(/([\\"])/g, '\\$1') + '"]');
816
817                var error = 1;
818                for(var i=0;i<inputs.length;i++) {
819                    if((inputs[i].type == 'checkbox' || inputs[i].type == 'radio') && inputs[i].checked == true) {
820                        error = 0;
821                    }
822
823                    if(Validation.isOnChange && (inputs[i].type == 'checkbox' || inputs[i].type == 'radio')) {
824                        Validation.reset(inputs[i]);
825                    }
826                }
827
828                if( error == 0 ) {
829                    return true;
830                } else {
831                    return false;
832                }
833            }],
834    ['validate-not-negative-number', 'Please enter a number 0 or greater in this field.', function(v) {
835                if (Validation.get('IsEmpty').test(v)) {
836                    return true;
837                }
838                v = parseNumber(v);
839                return !isNaN(v) && v >= 0;
840            }],
841    ['validate-zero-or-greater', 'Please enter a number 0 or greater in this field.', function(v) {
842            return Validation.get('validate-not-negative-number').test(v);
843        }],
844    ['validate-greater-than-zero', 'Please enter a number greater than 0 in this field.', function(v) {
845            if (Validation.get('IsEmpty').test(v)) {
846                return true;
847            }
848            v = parseNumber(v);
849            return !isNaN(v) && v > 0;
850        }],
851
852    ['validate-special-price', 'The Special Price is active only when lower than the Actual Price.', function(v) {
853        var priceInput = $('price');
854        var priceType = $('price_type');
855        var priceValue = parseFloat(v);
856
857        // Passed on non-related validators conditions (to not change order of validation)
858        if(
859            !priceInput
860            || Validation.get('IsEmpty').test(v)
861            || !Validation.get('validate-number').test(v)
862        ) {
863            return true;
864        }
865        if(priceType) {
866            return (priceType && priceValue <= 99.99);
867        }
868        return priceValue < parseFloat($F(priceInput));
869    }],
870    ['validate-state', 'Please select State/Province.', function(v) {
871                return (v!=0 || v == '');
872            }],
873    ['validate-new-password', 'Please enter 6 or more characters without leading or trailing spaces.', function(v) {
874                if (!Validation.get('validate-password').test(v)) return false;
875                if (Validation.get('IsEmpty').test(v) && v != '') return false;
876                return true;
877            }],
878    ['validate-cc-number', 'Please enter a valid credit card number.', function(v, elm) {
879                // remove non-numerics
880                var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_number')) + '_cc_type');
881                if (ccTypeContainer && typeof Validation.creditCartTypes.get(ccTypeContainer.value) != 'undefined'
882                        && Validation.creditCartTypes.get(ccTypeContainer.value)[2] == false) {
883                    if (!Validation.get('IsEmpty').test(v) && Validation.get('validate-digits').test(v)) {
884                        return true;
885                    } else {
886                        return false;
887                    }
888                }
889                return validateCreditCard(v);
890            }],
891    ['validate-cc-type', 'Credit card number does not match credit card type.', function(v, elm) {
892                // remove credit card number delimiters such as "-" and space
893                elm.value = removeDelimiters(elm.value);
894                v         = removeDelimiters(v);
895
896                var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_number')) + '_cc_type');
897                if (!ccTypeContainer) {
898                    return true;
899                }
900                var ccType = ccTypeContainer.value;
901
902                if (typeof Validation.creditCartTypes.get(ccType) == 'undefined') {
903                    return false;
904                }
905
906                // Other card type or switch or solo card
907                if (Validation.creditCartTypes.get(ccType)[0]==false) {
908                    return true;
909                }
910
911                var validationFailure = false;
912                Validation.creditCartTypes.each(function (pair) {
913                    if (pair.key == ccType) {
914                        if (pair.value[0] && !v.match(pair.value[0])) {
915                            validationFailure = true;
916                        }
917                        throw $break;
918                    }
919                });
920
921                if (validationFailure) {
922                    return false;
923                }
924
925                if (ccTypeContainer.hasClassName('validation-failed') && Validation.isOnChange) {
926                    Validation.validate(ccTypeContainer);
927                }
928
929                return true;
930            }],
931     ['validate-cc-type-select', 'Card type does not match credit card number.', function(v, elm) {
932                var ccNumberContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_type')) + '_cc_number');
933                if (Validation.isOnChange && Validation.get('IsEmpty').test(ccNumberContainer.value)) {
934                    return true;
935                }
936                if (Validation.get('validate-cc-type').test(ccNumberContainer.value, ccNumberContainer)) {
937                    Validation.validate(ccNumberContainer);
938                }
939                return Validation.get('validate-cc-type').test(ccNumberContainer.value, ccNumberContainer);
940            }],
941     ['validate-cc-exp', 'Incorrect credit card expiration date.', function(v, elm) {
942                var ccExpMonth   = v;
943                var ccExpYear    = $(elm.id.substr(0,elm.id.indexOf('_expiration')) + '_expiration_yr').value;
944                var currentTime  = new Date();
945                var currentMonth = currentTime.getMonth() + 1;
946                var currentYear  = currentTime.getFullYear();
947                if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
948                    return false;
949                }
950                return true;
951            }],
952     ['validate-cc-cvn', 'Please enter a valid credit card verification number.', function(v, elm) {
953                var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_cid')) + '_cc_type');
954                if (!ccTypeContainer) {
955                    return true;
956                }
957                var ccType = ccTypeContainer.value;
958
959                if (typeof Validation.creditCartTypes.get(ccType) == 'undefined') {
960                    return false;
961                }
962
963                var re = Validation.creditCartTypes.get(ccType)[1];
964
965                if (v.match(re)) {
966                    return true;
967                }
968
969                return false;
970            }],
971     ['validate-ajax', '', function(v, elm) { return true; }],
972     ['validate-data', 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.', function (v) {
973                if(v != '' && v) {
974                    return /^[A-Za-z]+[A-Za-z0-9_]+$/.test(v);
975                }
976                return true;
977            }],
978     ['validate-css-length', 'Please input a valid CSS-length. For example 100px or 77pt or 20em or .5ex or 50%.', function (v) {
979                if (v != '' && v) {
980                    return /^[0-9\.]+(px|pt|em|ex|%)?$/.test(v) && (!(/\..*\./.test(v))) && !(/\.$/.test(v));
981                }
982                return true;
983            }],
984     ['validate-length', 'Text length does not satisfy specified text range.', function (v, elm) {
985                var reMax = new RegExp(/^maximum-length-[0-9]+$/);
986                var reMin = new RegExp(/^minimum-length-[0-9]+$/);
987                var result = true;
988                $w(elm.className).each(function(name, index) {
989                    if (name.match(reMax) && result) {
990                       var length = name.split('-')[2];
991                       result = (v.length <= length);
992                    }
993                    if (name.match(reMin) && result && !Validation.get('IsEmpty').test(v)) {
994                        var length = name.split('-')[2];
995                        result = (v.length >= length);
996                    }
997                });
998                return result;
999            }],
1000     ['validate-percents', 'Please enter a number lower than 100.', {max:100}],
1001     ['required-file', 'Please select a file', function(v, elm) {
1002         var result = !Validation.get('IsEmpty').test(v);
1003         if (result === false) {
1004             ovId = elm.id + '_value';
1005             if ($(ovId)) {
1006                 result = !Validation.get('IsEmpty').test($(ovId).value);
1007             }
1008         }
1009         return result;
1010     }],
1011     ['validate-cc-ukss', 'Please enter issue number or start date for switch/solo card type.', function(v,elm) {
1012         var endposition;
1013
1014         if (elm.id.match(/(.)+_cc_issue$/)) {
1015             endposition = elm.id.indexOf('_cc_issue');
1016         } else if (elm.id.match(/(.)+_start_month$/)) {
1017             endposition = elm.id.indexOf('_start_month');
1018         } else {
1019             endposition = elm.id.indexOf('_start_year');
1020         }
1021
1022         var prefix = elm.id.substr(0,endposition);
1023
1024         var ccTypeContainer = $(prefix + '_cc_type');
1025
1026         if (!ccTypeContainer) {
1027               return true;
1028         }
1029         var ccType = ccTypeContainer.value;
1030
1031         if(['SS','SM','SO'].indexOf(ccType) == -1){
1032             return true;
1033         }
1034
1035         $(prefix + '_cc_issue').advaiceContainer
1036           = $(prefix + '_start_month').advaiceContainer
1037           = $(prefix + '_start_year').advaiceContainer
1038           = $(prefix + '_cc_type_ss_div').down('ul li.adv-container');
1039
1040         var ccIssue   =  $(prefix + '_cc_issue').value;
1041         var ccSMonth  =  $(prefix + '_start_month').value;
1042         var ccSYear   =  $(prefix + '_start_year').value;
1043
1044         var ccStartDatePresent = (ccSMonth && ccSYear) ? true : false;
1045
1046         if (!ccStartDatePresent && !ccIssue){
1047             return false;
1048         }
1049         return true;
1050     }]
1051]);
1052
1053function removeDelimiters (v) {
1054    v = v.replace(/\s/g, '');
1055    v = v.replace(/\-/g, '');
1056    return v;
1057}
1058
1059function parseNumber(v)
1060{
1061    if (typeof v != 'string') {
1062        return parseFloat(v);
1063    }
1064
1065    var isDot  = v.indexOf('.');
1066    var isComa = v.indexOf(',');
1067
1068    if (isDot != -1 && isComa != -1) {
1069        if (isComa > isDot) {
1070            v = v.replace('.', '').replace(',', '.');
1071        }
1072        else {
1073            v = v.replace(',', '');
1074        }
1075    }
1076    else if (isComa != -1) {
1077        v = v.replace(',', '.');
1078    }
1079
1080    return parseFloat(v);
1081}
1082
1083/**
1084 * Hash with credit card types which can be simply extended in payment modules
1085 * 0 - regexp for card number
1086 * 1 - regexp for cvn
1087 * 2 - check or not credit card number trough Luhn algorithm by
1088 *     function validateCreditCard which you can find above in this file
1089 */
1090Validation.creditCartTypes = $H({
1091//    'SS': [new RegExp('^((6759[0-9]{12})|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})|(6333[0-9]{12})|(6334[0-4]\d{11})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
1092    'SO': [new RegExp('^(6334[5-9]([0-9]{11}|[0-9]{13,14}))|(6767([0-9]{12}|[0-9]{14,15}))$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
1093    'VI': [new RegExp('^4[0-9]{12}([0-9]{3})?$'), new RegExp('^[0-9]{3}$'), true],
1094    'MC': [new RegExp('^(5[1-5][0-9]{14}|2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12}))$'), new RegExp('^[0-9]{3}$'), true],
1095    'AE': [new RegExp('^3[47][0-9]{13}$'), new RegExp('^[0-9]{4}$'), true],
1096    'DI': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3}$'), true],
1097    'JCB': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3,4}$'), true],
1098    'DICL': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3}$'), true],
1099    'SM': [new RegExp('(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
1100    'OT': [false, new RegExp('^([0-9]{3}|[0-9]{4})?$'), false]
1101});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.