/***********************************************************************
 * YAV - Yet Another Validator  v1.4.0                                 *
 * Copyright (C) 2005-2006-2007                                        *
 * Author: Federico Crivellaro <f.crivellaro@gmail.com>                *
 * WWW: http://yav.sourceforge.net                                     *
 *                                                                     *
 * This library is free software; you can redistribute it and/or       *
 * modify it under the terms of the GNU Lesser General Public          *
 * License as published by the Free Software Foundation; either        *
 * version 2.1 of the License, or (at your option) any later version.  *
 *                                                                     *
 * This library is distributed in the hope that it will be useful,     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of      *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   *
 * Lesser General Public License for more details.                     *
 *                                                                     *
 * You should have received a copy of the GNU Lesser General Public    *
 * License along with this library; if not, write to the Free Software *
 * Foundation, Inc.,59 Temple Place,Suite 330,Boston,MA 02111-1307 USA *
 *                                                                     *
 * last revision:  14 OCT 2007                                         *
 ***********************************************************************/
 
/******************************** SETTINGS *****************************/

Type.registerNamespace('Common');

Common.Validator = function ()
    { 
        // CHANGE THESE VARIABLES FOR YOUR OWN SETUP
        
        // if you want yav to highligh fields with errors
        this.inputhighlight = true;
             // if you want to use multiple class names
        this.multipleclassname=true;
             // classname you want for the error highlighting
        this.inputclasserror = 'inputError';
             // classname you want for your fields without highlighting
        this.inputclassnormal = 'inputNormal';
             // classname you want for the inner html highlighting
        this.innererror = 'innerError';
        // div name where errors will appear (or where jsVar variable is dinamically defined)
        this.errorsdiv = 'errorsDiv';
        // if you want yav to alert you for javascript errors (only for developers)
        this.debugmode = true;
        // if you want yav to trim the strings
        this.trimenabled = true;

        // change these to set your own decimal separator and your date format
        this.DECIMAL_SEP =',';
        this.THOUSAND_SEP = '.';
        this.DATE_FORMAT = 'MM-dd-yyyy';

        // change this to set your own rule separator
        this.RULE_SEP = '|';
        
        //Dangerous HTML tags
        this.prohibitedHTMLTags = "layer|ilayer|img|html|applet|body|script|embed|object|frameset|frame|iframe|meta|link|style|a|abbr|acronym|address|area|b|base|basefont|bdo|big|blockquote|br|button|caption|center|cite|code|col|colgroup|dd|del|dir|div|dfn|dl|dt|em|fieldset|font|form|h1|h2|h3|h4|h5|h6|head|hr|i|input|ins|isindex|kbd|label|legend|li|map|menu|noframe|noscript|ol|optgroup|option|p|param|pre|q|s|samp|select|small|span|strike|strong|style|sub|sup|td|textarea|tfoot|th|thead|title|tr|tt|u|ul|var|xmp|!--|!doctype|table|xml"; 
        this.prohibitedDOMEvents = "onload|onunload|onchange|onsubmit|onreset|onselect|onblur|onfocus|onkeydown|onkeypress|onkeyup|onclick|ondblclick|onmousedown|onmousemove|onmouseover|onmouseout|onmouseup";
        
        //XSS JavaScript injection
        this.prohibitedJSKeywords = "onload|onunload|onchange|onsubmit|onreset|onselect|onblur|onfocus|onkeydown|onkeypress|onkeyup|onclick|ondblclick|onmousedown|onmousemove|onmouseover|onmouseout|onmouseup";
        
        //MS-DOS Device Driver Names Cannot be Used as File Names
        //http://support.microsoft.com/kb/74496/en-us
        this.prohibitedFileNames = "CON|AUX|PRN|COM1|LPT1|LPT2|LPT3|COM2|COM3|COM4|NUL|CLOCK$";
        this.prohibitedFileNameCharacters = "\\ / : * ? \" < > | ;";

        // change these strings for your own translation (do not change {n} values!)
        this.HEADER_MSG = 'Data not valid:';
        this.FOOTER_MSG = 'Please retry.';
        this.DEFAULT_MSG = 'The data is invalid.';
        this.REQUIRED_MSG = 'Enter {1}.';
        //this.ALPHABETIC_MSG = '{1} is not valid. Characters allowed: A-Za-z';
        //this.ALPHANUMERIC_MSG = '{1} is not valid. Characters allowed: A-Za-z0-9';
        //this.ALNUMHYPHEN_MSG = '{1} is not valid. Characters allowed: A-Za-z0-9\-_';
        //this.ALNUMHYPHENAT_MSG = '{1} is not valid. Characters allowed: A-Za-z0-9\-_@';
        //this.ALPHANUMSPACESPECIALS_MSG = '{1} is not valid. Characters allowed: [0-9a-zA-Z,!?;\/()<>[]{}‘“$%^&*_+=@#`~-.], [space], [euro]';
        //this.ALPHANUMSPACESPECIALSLINEBREAK_MSG = '{1} is not valid. Characters allowed: [0-9a-zA-Z,!?;\/()<>[]{}‘“$%^&*_+=@#`~-.], [space], [euro], [linebreak]';
        //this.ALPHASPACE_MSG = '{1} is not valid. Characters allowed: A-Za-z0-9\-_space';
        this.FILENAME_MSG = '{1} is not valid. Characters allowed: A-Za-z0-9\-_space';
        this.DANGEROUSTAGS_MSG = 'Html {1} tag is not allowed.';
        this.DANGEROUSJSKEYWORD_MSG = 'Javascript {1} directive is not allowed.';
        this.PHONENUMBER_MSG = 'Phone is not valid. Characters allowed: [-/()+], 0-9 and [space]';
        this.PARTIAL_LAST_DIGITS_PHONENUMBER_MSG = 'Input is not valid. Characters allowed: [-/()+], 0-9 and [space]';
        this.COVERPRICE_MSG = '{1} is not valid. Characters allowed: [0-9] and [' + this.DECIMAL_SEP + '] as decimal separator';
        this.MINLENGTH_MSG = '{1} must be at least {2} characters long.';
        this.MAXLENGTH_MSG = '{1} must be no more than {2} characters long.';

        
        this.NUMRANGE_MSG = '{1} must be a number in {2} range.';
        this.DATE_MSG = '{1} is not a valid date, using the format ' + this.DATE_FORMAT + '.';
        this.NUMERIC_MSG = '{1} must be a number.';
        this.INTEGER_MSG = '{1} must be an integer';
        this.DOUBLE_MSG = '{1} must be a decimal number.';
        this.MONEYDECIMAL_MSG = '{1} must be a positiv number with two digits after decimal and less than 9999999999999999.99';
        this.REGEXP_MSG = '{1} is not valid.';
        this.EQUAL_MSG = '{1} must be equal to {2}.';
        this.NOTEQUAL_MSG = '{1} must be not equal to {2}.';
        this.DATE_LT_MSG = '{1} must be previous to {2}.';
        this.DATE_LE_MSG = '{1} must be previous or equal to {2}.';
        this.EMAIL_MSG = '{1} must be a valid e-mail.';
        this.EMPTY_MSG = '{1} must be empty.';
        this.SELECT_LEAST_ONE_MEDIA_MSG = 'At least one media must be selected.';
        this.INVALID_DATE_RANGE_FROM_TO_MSG = "Invalid date range [From / To].";
        this.undef;
        this.isFocusSet;
        this.internalRules;                
        this.failedRules = null;
        this.OnValidationFailedHandler = null;            
        /****************************** END SETTINGS *****************************/
    }


    Common.Validator.prototype =
    {
        /*---------------------------------------------------------------------------*/

        performCheck: function(formName, strRules, alertType) {
            this.clearAllInlineDivs();
            var checkResult = true;
            this.failedRules = new Array();
            this.isFocusSet = false;
            this.internalRules = this.makeRules(strRules);
            var rules = this.internalRules;
            this.f = document.forms[formName];
            if (!this.f) {
                this.debug('DEBUG: could not find form object ' + formName);
                return null;
            }

            var errors = new Array();
            var ix = 0;
            if (rules.length) {
                for (var i = 0; i < rules.length; i++) {
                    var aRule = rules[i];
                    if (aRule != null) {
                        this.highlight(this.getField(this.f, aRule.el), this.inputclassnormal);
                    }
                }
            }
            else {
                if (rules != null) {
                    this.highlight(this.getField(this.f, rules.el), this.inputclassnormal);
                }
            }
            if (rules.length) {
                for (var i = 0; i < rules.length; i++) {
                    var aRule = rules[i];

                    //debugger;

                    var anErr = null;
                    if (aRule == null) {
                        //do nothing
                    }
                    else if (aRule.ruleType == 'pre-condition' || aRule.ruleType == 'post-condition' || aRule.ruleType == 'andor-operator') {
                        //do nothing
                        //debugger;
                    }
                    else if (aRule.ruleName == 'implies') {
                        //debugger;

                        var pre = aRule.el;
                        var post = aRule.comparisonValue;

                        var oldClassName = this.getField(this.f, rules[pre].el).className;

                        if (this.checkRule(this.f, rules[pre]) == null && this.checkRule(this.f, rules[post]) != null) {
                            // shows the alert msg of the implies rule
                            //anErr = this.deleteInline(aRule.alertMsg) + '__inline__'+rules[post].el;

                            // shows the alert msg of the post condition rule
                            anErr = rules[post].alertMsg;
                        }
                        else if (this.checkRule(this.f, rules[pre]) != null) {
                            this.getField(this.f, rules[pre].el).className = oldClassName;
                        }
                        //Replace rule with post-condition rule for corectly display error message
                        aRule = rules[post];
                    }
                    else {
                        anErr = this.checkRule(this.f, aRule);
                        if (anErr) {
                            this.internalRules[i].err = anErr;
                        }
                    }
                    if (anErr != null) {
                        errors[ix] = anErr;
                        ix++;

                        this.failedRules.push(aRule);
                        var tempErrors = new Array();
                        var errorMessages = new Array();
                        if (anErr.indexOf('$;') != -1) {
                            // in case when error message contains comma simbol
                            errorMessages[0] = anErr.replace('$;', ';');
                        }
                        else {
                            errorMessages = anErr.split(';');
                        }
                        var errorsArrayIndex = 0;
                        for (iii = 0; iii < errorMessages.length; iii++) {
                            if (errorMessages[iii].length > 0) {
                                tempErrors[errorsArrayIndex] = errorMessages[iii];
                                errorsArrayIndex++;
                            }
                        }
                        checkResult = this.displayAlert(tempErrors, alertType, aRule);
                    }
                } //for
            }
            else {
                var myRule = rules;
                err = this.checkRule(this.f, myRule);
                if (err != null) {
                    errors[0] = err;

                    this.failedRules.push(myRule);
                    checkResult = this.displayAlert(tempErrors, alertType, aRule);
                }
            }
            return checkResult;
        },

        /*----------END performCheck------------------------------------------------------------------------*/

        checkKeyPress: function(ev, obj, strRules) {
            var keyCode = null;
            if (this.getBrowser() == 'msie') {
                keyCode = window.event.keyCode;
            }
            else
                if (this.getBrowser() == 'netscape' || this.getBrowser() == 'firefox') {
                keyCode = ev.which;
            }
            var rules = this.makeRules(strRules);
            var keyAllowed = true;

            if (rules.length) {
                for (var i = 0; i < rules.length; i++) {
                    var aRule = rules[i];
                    if (aRule.ruleName == 'keypress' && aRule.el == obj.name) {
                        keyAllowed = this.isKeyAllowed(keyCode, aRule.comparisonValue);
                        break;
                    }
                }
            }
            else {
                var aRule = rules;
                if (aRule.ruleName == 'keypress' && aRule.el == obj.name) {
                    keyAllowed = this.isKeyAllowed(keyCode, aRule.comparisonValue);
                }
            }
            if (!keyAllowed) {
                if (this.getBrowser() == 'msie') {
                    window.event.keyCode = 0;
                }
                else
                    if (this.getBrowser() == 'netscape' || this.getBrowser() == 'firefox') {
                    ev.preventDefault();
                    ev.stopPropagation();
                    ev.returnValue = false;
                }
            }
            return false;
        },
        /*------------END checkKeyPress--------------------------------------------------------------------------*/

        displayAlert: function(messages, alertType, rule) {
            var retval = null;

            if (alertType == 'classic') {
                retval = this.displayClassic(messages);
            }
            else
                if (alertType == 'innerHtml') {
                retval = this.displayInnerHtml(messages);
            }
            else
                if (alertType == 'inline') {
                retval = this.displayInline(messages, rule);
            }
            else
                if (alertType == 'jsVar') {
                retval = this.displayJsVar(messages);
            }
            else {
                this.debug('DEBUG: alert type ' + alertType + ' not supported');
            }
            return retval;
        },

        /*-------END displayAlert------------------------------------------------------------*/

        displayClassic: function(messages) {
            var str = '';
            if (messages != null && messages.length > 0) {
                if (this.strTrim(this.HEADER_MSG).length > 0) {
                    str += this.HEADER_MSG + '\n\n';
                }
                for (var i = 0; i < messages.length; i++) {
                    str += ' ' + this.deleteInline(messages[i]) + '\n';
                }
                if (this.strTrim(this.FOOTER_MSG).length > 0) {
                    str += '\n' + this.FOOTER_MSG;
                }
                alert(str);
                return false;
            }
            else {
                return true;
            }
        },

        /*----------END displayClassic-----------------------------------------------------------------------*/
        displayInnerHtml: function(messages) {
            //debugger;
            if (messages != null && messages.length > 0) {
                var str = '';

                if (this.strTrim(this.HEADER_MSG).length > 0) {
                    str += this.HEADER_MSG;
                }
                str += '<ul>';

                for (var i = 0; i < messages.length; i++) {
                    str += '<li>' + this.deleteInline(messages[i]) + '</li>';
                }

                str += '</ul>';

                if (this.strTrim(this.FOOTER_MSG).length > 0) {
                    str += this.FOOTER_MSG;
                }
                document.getElementById(this.errorsdiv).innerHTML = str;
                document.getElementById(this.errorsdiv).className = this.innerError;
                document.getElementById(this.errorsdiv).style.display = 'block';

                return false;
            }
            else {
                document.getElementById(this.errorsdiv).innerHTML = '';
                document.getElementById(this.errorsdiv).className = '';
                document.getElementById(this.errorsdiv).style.display = 'none';
                return true;
            }
        },

        /*--------END displayInnerHtml--------------------------------------------------------------------------------*/

        displayInline: function(messages, rule) {
            if (messages != null && messages.length > 0) {
                var genericErrors = new Array();
                var genericErrIndex = 0;

                for (var i = 0; i < messages.length; i++) {
                    //var elName = messages[i].substring(messages[i].indexOf('__inline__')+10);  

                    var fullElName = messages[i].split("__inline__");
                    var elName = messages[i].match(/[^_]*$/);
                    var tmpId = 'ERR' + fullElName[1];

                    if (document.getElementById(tmpId) == null) {
                        tmpId = 'ERR' + fullElName[1].replace('_Input', '');
                        fullElName[1] = fullElName[1].replace('_Input', '');
                    }

                    if (document.getElementById(tmpId) == null) {
                        tmpId = 'ERR' + fullElName[1].replace('_dateInput_text', '');
                        fullElName[1] = fullElName[1].replace('_dateInput_text', '');
                    }

                    if (document.getElementById(tmpId) != null) {
                        if (document.getElementById(tmpId).className == 'noERR') {
                            var elWidth = document.getElementById(fullElName[1]).style.width;

                            if (elWidth == "") {
                                elWidth = document.getElementById(fullElName[1]).offsetWidth + 'px';
                            }

                            elWidth = elWidth.replace(/px/ig, '');
                            var newWidth = parseInt(elWidth) - 16;

                            if (newWidth < 0) {
                                newWidth = 0;
                            }
                            document.getElementById(fullElName[1]).style.width = newWidth + "px";
                            document.getElementById(tmpId).className = 'ERR';
                            if (TR_CLIENT_MESSAGES[this.deleteInline(messages[i])]) {
                                document.getElementById('ERR' + fullElName[1]).title = TR_CLIENT_MESSAGES[this.deleteInline(messages[i])].replace('{1}', rule.nameDisplayed).replace('{2}', rule.comparisonValue);
                            }
                            else {
                                document.getElementById('ERR' + fullElName[1]).title = this.deleteInline(messages[i]);
                            }
                        }
                        else {
                            genericErrors[genericErrIndex] = messages[i];
                            genericErrIndex++;
                        }
                    }
                }  // end For


                //  if (genericErrIndex>0) {
                //       this.displayInnerHtml(genericErrors);
                //  }
                return false;

            }   //end if                
            else {
                return true;
            }
        },

        /*---------END displayInline--------------------------------------------------------------------*/

        clearAllInlineDivs: function() {
            var allDivs = document.getElementsByTagName("div");

            for (var j = 0; j < allDivs.length; j++) {
                var idName = allDivs[j].id;
                var cssClass = allDivs[j].className;
                //if ( idName.indexOf(this.errorsdiv+'_')==0 )
                if (cssClass == 'ERR') {
                    //document.getElementById(idName).innerHTML = '';
                    //document.getElementById(idName).className = '';
                    //document.getElementById(idName).style.display = 'none';
                    document.getElementById(idName).className = 'noERR';

                    var elemToResize = document.getElementById(idName.replace('ERR', ''));
                    var elWidth = elemToResize.style.width;
                    elWidth = elWidth.replace(/px/ig, '');

                    if (elWidth != "") {
                        var newWidth = parseInt(elWidth) + 16;
                        elemToResize.style.width = newWidth + "px";
                    }
                }

                if (cssClass == 'errorClass' && idName.length > 0) {
                    var idNameElem = document.getElementById(idName);
                    if (idNameElem) {
                        idNameElem.style.display = 'none';
                    }
                }
            }
        },

        /*--------END clearAllInlineDivs----------------------------------------------------------------------*/

        displayJsVar: function(messages) {
            document.getElementById(this.errorsdiv).className = '';
            document.getElementById(this.errorsdiv).style.display = 'none';

            if (messages != null && messages.length > 0) {
                for (var i = 0; i < messages.length; i++) {
                    messages[i] = this.deleteInline(messages[i]);
                }

                var str = '';
                str += '<script>var jsErrors;</script>';
                document.getElementById(this.errorsdiv).innerHTML = str;
                jsErrors = messages;

                return false;
            }
            else {
                document.getElementById(this.errorsdiv).innerHTML = '<script>var jsErrors;</script>';
                return true;
            }
        },
        /*--------END displayJsVar--------------------------------------------------------------------------*/

        rule: function(el, ruleName, comparisonValue, alertMsg, ruleType, parent) {
            if (!parent.checkArguments(arguments)) {
                return false;
            }

            var isAndOrOperator = ruleName == "and" || ruleName == "or";
            if (isAndOrOperator) {
                var tmpEl = el.split('$');
                var elementName;
                if (tmpEl.length == 2) {
                    elementName = tmpEl[0];
                    el = tmpEl[1];
                }
                else {
                    throw new String("and/or operator must have an element name$rulenumber format");
                }
            }

            tmp = el.split(':');
            nameDisplayed = '';

            if (tmp.length == 2) {
                nameDisplayed = tmp[1];
                el = tmp[0];
            }

            this.el = el;
            this.nameDisplayed = nameDisplayed;
            this.ruleName = ruleName;
            this.comparisonValue = comparisonValue;
            this.ruleType = ruleType;

            this.err = null;
            var thisEl = this.el;
            var El1 = el;

            //switch
            if (isAndOrOperator) {
                this.el = el = elementName;
            }

            if (alertMsg == this.undef || alertMsg == null) {
                this.alertMsg = parent.getDefaultMessage(el, nameDisplayed, ruleName, comparisonValue) + '__inline__' + this.el;
            }
            else {
                this.alertMsg = alertMsg + '__inline__' + this.el;
            }

            if (isAndOrOperator) {
                this.el = thisEl;
                el = El1;
            }
        },

        /*------------END rule----------------------------------------------------------------------*/

        checkRule: function(f, myRule) {
            retVal = null;
            if (myRule != null) {
                if (myRule.ruleName == 'custom') {
                    var customFunction = ' retVal = ' + myRule.el + ';';

                    try {
                        eval(customFunction);
                    }
                    catch (err) {
                        this.debug(err + '. File name : ' + err.fileName + '. Make sure that your javascript function is declared in <script type=\"text/javascript\"> and not in <script type=\"text/jscript\">');
                    }
                }  //end if (myRule.ruleName=='custom')
                else
                    if (myRule.ruleName == 'and') {
                    var op_1 = myRule.el;
                    var op_next = myRule.comparisonValue;
                    if (this.checkRule(f, this.internalRules[op_1]) != null) {
                        retVal = myRule.alertMsg;
                        if (myRule.ruleType == 'pre-condition' || myRule.ruleType == 'andor-operator') {
                            //this.highlight(this.getField(f, this.internalRules[op_1].el), this.inputclasserror);
                        }
                    }
                    else {
                        var op_k = op_next.split('-');

                        for (var k = 0; k < op_k.length; k++) {
                            if (this.checkRule(f, this.internalRules[op_k[k]]) != null) {
                                retVal = myRule.alertMsg;
                                if (myRule.ruleType == 'pre-condition' || myRule.ruleType == 'andor-operator') {
                                    //this.highlight(this.getField(f, this.internalRules[op_k[k]].el), this.inputclasserror);
                                }
                                break;
                            }
                        }
                    }
                } // end if (myRule.ruleName=='and') 
                else
                    if (myRule.ruleName == 'or') {
                    var op_1 = myRule.el;
                    var op_next = myRule.comparisonValue;
                    var success = false;

                    if (this.checkRule(f, this.internalRules[op_1]) == null) {
                        success = true;
                    }
                    else {
                        if (myRule.ruleType == 'pre-condition' || myRule.ruleType == 'andor-operator') {
                            //this.highlight(this.getField(f, this.internalRules[op_1].el), this.inputclasserror);
                        }

                        var op_k = op_next.split('-');
                        for (var k = 0; k < op_k.length; k++) {
                            if (this.checkRule(f, this.internalRules[op_k[k]]) == null) {
                                success = true;
                                break;
                            }
                            else {
                                if (myRule.ruleType == 'pre-condition' || myRule.ruleType == 'andor-operator') {
                                    //this.highlight(this.getField(f, this.internalRules[op_k[k]].el), this.inputclasserror);
                                }
                            }
                        }
                    }
                    if (success) {
                        this.highlight(this.getField(f, this.internalRules[op_1].el), this.inputclassnormal);
                        var op_k = op_next.split('-');

                        for (var k = 0; k < op_k.length; k++) {
                            this.highlight(this.getField(f, this.internalRules[op_k[k]].el), this.inputclassnormal);
                        }
                    }
                    else {
                        retVal = myRule.alertMsg;
                    }
                }
                else {
                    el = this.getField(f, myRule.el);
                    if (el == null) {
                        this.debug('DEBUG: could not find element ' + myRule.el);
                        return null;
                    }
                    var err = null;
                    if (el.type) {
                        if (el.type == 'hidden' || el.type == 'text' || el.type == 'password' || el.type == 'textarea' || el.type == 'file') {
                            err = this.checkText(el, myRule);
                        }
                        else
                            if (el.type == 'checkbox') {
                            err = this.checkCheckbox(el, myRule);
                        }
                        else
                            if (el.type == 'select-one') {
                            err = this.checkSelOne(el, myRule);
                        }
                        else
                            if (el.type == 'select-multiple') {
                            err = this.checkSelMul(el, myRule);
                        }
                        else
                            if (el.type == 'radio') {
                            err = this.checkRadio(el, myRule);
                        }
                        else {

                            this.debug('DEBUG: type ' + el.type + ' not supported');
                        }
                    }
                    else {
                        err = this.checkRadio(el, myRule);
                    }
                    retVal = err;
                }
            }
            return retVal;
        },

        /*-----------END checkRule--------------------------------------------------------------------------------*/

        checkArguments: function(args) {
            if (args.length < 4) {
                this.debug('DEBUG: rule requires four arguments at least');
                return false;
            }
            else
                if (args[0] == null || args[1] == null) {
                this.debug('DEBUG: el and ruleName are required');
                return false;
            }
            return true;
        },

        /*---------END checkArguments------------------------------------------------------------------------------------*/

        checkRadio: function(el, myRule) {
            var err = null;
            if (myRule.ruleName == 'required') {
                var radios = el;
                var found = false;

                if (isNaN(radios.length) && radios.checked) {
                    found = true;
                }
                else {
                    for (var j = 0; j < radios.length; j++) {
                        if (radios[j].checked) {
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'equal') {
                var radios = el;
                var found = false;

                if (isNaN(radios.length) && radios.checked) {
                    if (radios.value == myRule.comparisonValue) {
                        found = true;
                    }
                }
                else {
                    for (var j = 0; j < radios.length; j++) {
                        if (radios[j].checked) {
                            if (radios[j].value == myRule.comparisonValue) {
                                found = true;
                                break;
                            }
                        }
                    }
                }
                if (!found) {
                    err = myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'notequal') {
                var radios = el;
                var found = false;

                if (isNaN(radios.length) && radios.checked) {
                    if (radios.value != myRule.comparisonValue) {
                        found = true;
                    }
                }
                else {
                    for (var j = 0; j < radios.length; j++) {
                        if (radios[j].checked) {
                            if (radios[j].value != myRule.comparisonValue) {
                                found = true;
                                break;
                            }
                        }
                    }
                }
                if (!found) {
                    err = myRule.alertMsg;
                }
            }
            else {
                this.debug('DEBUG: rule ' + myRule.ruleName + ' not supported for radio');
            }
            return err;
        },

        /*----------END checkRadio--------------------------------------------------------------------------*/

        checkText: function(el, myRule) {
            err = null;
            if (this.trimenabled) {
                el.value = this.strTrim(el.value);
            }
            if (myRule.ruleName == 'required') {
                if ((el.value == null || el.value == '')) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'equal') {
                err = this.checkEqual(el, myRule);
            }
            else
                if (myRule.ruleName == 'notequal') {
                err = this.checkNotEqual(el, myRule);
            }
            else
                if (myRule.ruleName == 'numeric') {
                reg = new RegExp("^[0-9]*$");
                if (!reg.test(el.value)) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            /*else 
            if (myRule.ruleName=='alphabetic') 
            {
            reg = new RegExp("^[A-Za-z]*$");
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = myRule.alertMsg;
            }
            } 
            else 
            if (myRule.ruleName=='alphanumeric') 
            {
            reg = new RegExp("^[A-Za-z0-9]*$");
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = myRule.alertMsg;
            }
            } 
            else 
            if (myRule.ruleName=='alnumhyphen') 
            {
            reg = new RegExp("^[A-Za-z0-9\-_]*$");
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = myRule.alertMsg;
            }
            } 
                                
            else 
            if (myRule.ruleName=='alnumhyphenat') 
            {
            reg = new RegExp("^[A-Za-z0-9\-_@]*$");
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = myRule.alertMsg;
            }
            } 
            else 
            if (myRule.ruleName=='alphaspace') 
            {
            reg = new RegExp("^[A-Za-z0-9\-_ \n\r\t]*$");
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = myRule.alertMsg;
            }
            } 
            else if (myRule.ruleName=='alphanumspacespecials') 
            {   //u201C - unicode for ‘
            //u2018 - unicode for “
            //xA3   - hex for £
            reg = new RegExp("^([a-zA-Z0-9\\?\\\\/\\(\\)<>\\[\\]!.,:;\\{\\}'\"\\u201C\\u2018\\xA3\\$%\\^&\\*_\\-+=@#`~\\s|]*)$");
                                            
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = this.getDefaultMessage(el, myRule.nameDisplayed, myRule.ruleName, myRule.comparisonValue)+'__inline__'+myRule.el;
            }                                                                                                                                   
            }
            else if (myRule.ruleName=='alphanumspacespecialslinebreak') 
            {
            reg = new RegExp("^([a-zA-Z0-9\\?\\\\/\\(\\)<>\\[\\]!.,:;\\{\\}'\"\\u201C\\u2018\\xA3\\$%\\^&\\*_\\-+=@#`~\\s|]*)$", "m");
                                            
            if ( !reg.test(el.value) ) 
            {
            this.highlight(el, this.inputclasserror);
            err = myRule.alertMsg;
            }                                                                                       
            }*/
            else if (myRule.ruleName == 'filename') {
                var charsArr = this.prohibitedFileNameCharacters.split(" ");
                var fileName = el.value;

                for (var i = 0; i < charsArr.length; i++) {
                    if (fileName.indexOf(charsArr[i]) > -1) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                        break;
                    }
                }
                /*
                reg = new RegExp("^[A-Za-z0-9\-_ \n\r\t]*$");
                if ( !reg.test(el.value) ) 
                {
                this.highlight(el, this.inputclasserror);
                err = myRule.alertMsg;
                }
                */

                var arr = this.prohibitedFileNames.split("|");
                if (arr.indexOf(el.value.toUpperCase()) > -1) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else if (myRule.ruleName == 'webaddress') {
                //reg = new RegExp("^http:\\/\\/(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?\\.)*([a-zA-Z]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)|(\\d+\\.\\d+\\.\\d+\.\\d+)(:\\d+)?)(\\/(([^/\\/?])*(\\/([^/\\/?])*)*)(\\?([^/\\/?])*)?)?$");
                //reg = new RegExp("^(https?://)(([0-9a-z_!~*'().&=+$%-]+:?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?))$");
                //reg = new RegExp("^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?");
                if (((el.value != null && el.value.trim() != '')) && (!this.isUrl(el.value))) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else if (myRule.ruleName == 'dangeroustags') {
                var regexTags = "</?((" + this.prohibitedHTMLTags + ")(.|\n)*?)|(" + this.prohibitedDOMEvents + ")(.|\n)*?>";
                //var regexTags = "<(?:\\s)*?(" + this.prohibitedHTMLTags + "|" + this.prohibitedDOMEvents + ")(?:\\s|>)(?:.|\\n)*?";
                var reg = new RegExp(regexTags);
                var val = el.value.toLowerCase();
                var m = reg.exec(val);

                if (m != null) {
                    var dangerousTag = m[0];
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg; // this.getDefaultMessage(el, dangerousTag, myRule.ruleName, myRule.comparisonValue)+'__inline__'+myRule.el;                                                 
                }
            }
            else if (myRule.ruleName == 'javascriptkeywords') {
                var regexTags = "<.*" + this.prohibitedJSKeywords + "=\".*\".*>";

                var reg = new RegExp(regexTags);
                var val = el.value.toLowerCase();
                var m = reg.exec(val);

                if (m != null) {
                    var dangerousTag = m[0];
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else if (myRule.ruleName == 'partiallastdigitsphonenumber') {
                var inputValue = el.value.trim();

                // Validate only when input is provided.
                // If the field is mandatory then use mandatory rule 
                // to check if input value is provided.
                if (inputValue != '') {
                    // according to requirements partial phone number
                    // allows digits and characters like '(', ')', '+', '-', space and '/' in any sequence
                    // 22(+373), 22+373), 22 -87, (+37 2 77/5, 878 etc.
                    var pattern = '^([0-9|\\x2D|/|\\x20|+|(|)]{1,})$';
                    var reg = new RegExp(pattern);
                    if (!reg.test(inputValue)) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                    }
                }
            }
            else if (myRule.ruleName == 'phonenumber') {
                var inputValue = el.value.trim();

                // Validate only when input is provided.
                // If the field is mandatory then use mandatory rule 
                // to check if input value is provided.
                if (inputValue != '') {
                    var phonePatterns = new Array();
                    // (+373) 22 77-55-87, (+373) 22 77/55/87, (+373) 22 77 55 87 : full numbers
                    // 22 77-55-87, 77/55/87 : partial numbers
                    // (+373) 22 7755-87, (+373) 22 7755/87, (+373) 22 775587 : mixed separators
                    // (+373)22775588, 22775588, 775588 : no separators
                    // 77-55-88, 22 77-55-88, 2277-55-88 - no country code
                    // (+373) 77-55-88, (+373)77-55-88 - no city code
                    // 77-55-88 : no country and city code
                    phonePatterns[0] = '^((\\x28[+]{0,1}[0-9]{1,}\\x29\x20{0,}){0,1}[0-9]{1,3}\x20{0,}[0-9]{1,}[-|/|\x20]{0,}[0-9]{1,}[-|/|\x20]{0,}[0-9]{1,})$';
                    // +373 22 77-55-87, +373 22 77/55/87, +373 22 77 55 87 : full numbers
                    // +373 22 7755-87, +373 22 7755/87, +373 22 775587 : mixed separators
                    // +37322775588, : no separators
                    // 77-55-88, 22 77-55-88, 2277-55-88 - no country code
                    // +373 77-55-88, +37377-55-88 - no city code
                    phonePatterns[1] = '^(([+]{0,1}[0-9]{1,}\x20{0,}){0,1}[0-9]{1,3}\x20{0,}[0-9]{1,}[-|/|\x20]{0,}[0-9]{1,}[-|/|\x20]{0,}[0-9]{1,})$';
                    // +373 (22) 77-55-87, +373 (22) 77/55/87, +373 (22) 77 55 87 : full numbers
                    // +373 (22) 7755-87, +373 (22) 7755/87, +373 (22) 775587 : mixed separators
                    // +373(22)775588, : no separators
                    // 77-55-88, (22) 77-55-88, (22)77-55-88 - no country code
                    phonePatterns[2] = '^(([+]{0,1}[0-9]{1,}\x20{0,}){0,1}\\x28[0-9]{1,3}\\x29\x20{0,}[0-9]{1,}[-|/|\x20]{0,}[0-9]{1,}[-|/|\x20]{0,}[0-9]{1,})$';

                    var phoneIsValid = false;
                    for (var i = 0; i < phonePatterns.length; i++) {
                        var pattern = phonePatterns[i];
                        var reg = new RegExp(pattern);
                        if (reg.test(inputValue)) {
                            phoneIsValid = true;
                            break;
                        }
                    }

                    if (!phoneIsValid) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                    }
                }
            }
            else if (myRule.ruleName == 'coverprice') {
                if (el.value != '') {
                    // perfom reg exp match only in case value is not empty
                    reg = new RegExp("^[0-9]*[.]{0,1}[0-9]*$");
                    if (!reg.test(el.value)) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                    }
                    else {
                        regRange = new RegExp("^[0-9]{1,}-[0-9]{1,}$");
                        if (!regRange.test(myRule.comparisonValue)) {
                            this.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not in format number1-number2');
                        }
                        else {
                            rangeVal = myRule.comparisonValue.split('-');
                            if (eval(el.value) < eval(rangeVal[0]) || eval(el.value) > eval(rangeVal[1])) {
                                this.highlight(el, this.inputclasserror);
                                err = myRule.alertMsg;
                            }
                        }
                    }
                }
            }
            else
                if (myRule.ruleName == 'email') {
                if (el.value.length > 0) {
                    //Regex corresponds to RFC-2822 specification https://cp.md.endava.com/bugzilla/show_bug.cgi?id=6294
                    reg = /^(?:[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
                   //reg = new RegExp("^(?:[a-zA-Z0-9!#$%&'\*\+\/=\?\^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'\*\+\/=\?\^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\[\\]-\x7f]|[\x0d\x0a\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:[a-zA-Z0-9!#$%&'\*\+\/=\?\^_`{|}~-]+|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\\])$");
                    if (!reg.test(el.value)) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                    }
                    else {
                        var email = el.value.split('@');
                        if (email && email.length == 2) {
                            if (testEmail(email[0], email[1])) {
                                this.highlight(el, this.inputclasserror);
                                err = myRule.alertMsg;
                            }
                        }
                        else {
                            this.highlight(el, this.inputclasserror);
                            err = myRule.alertMsg;
                        }
                    }
                }
            }
            else
                if (myRule.ruleName == 'multipleemails') {
                if (el.value.length > 0) {
                    var email = el.value.split(';');
                    //Regex corresponds to RFC-2822 specification https://cp.md.endava.com/bugzilla/show_bug.cgi?id=6294
                    reg = /(?:[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
                    //reg = new RegExp("^(?:[a-zA-Z0-9!#$%&'\*\+\/=\?\^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'\*\+\/=\?\^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\[\\]-\x7f]|[\x0d\x0a\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:[a-zA-Z0-9!#$%&'\*\+\/=\?\^_`{|}~-]+|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\\])$");
                    for (var i = 0; i < email.length; i++) {
                        var myStr = new String(email[i]);
                        if (i == email.length - 1 && email[i] == "") {
                            continue;
                        }
                        if (!reg.test(myStr.trim())) {
                            this.highlight(el, this.inputclasserror);
                            err = myRule.alertMsg;
                            break;
                        }
                        else {
                            var emailParts = myStr.split('@');
                            if (emailParts && emailParts.length == 2) {
                                if (testEmail(emailParts[0], emailParts[1])) {
                                    this.highlight(el, this.inputclasserror);
                                    err = myRule.alertMsg;
                                }
                            }
                            else {
                                this.highlight(el, this.inputclasserror);
                                err = myRule.alertMsg;
                            }
                        }
                    }
                }
            }
            else
                if (myRule.ruleName == 'firstpublicationdate') {
                reg = new RegExp("^[0-9.\/-]*$");

                if (!reg.test(el.value)) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'maxlength') {
                if (isNaN(myRule.comparisonValue)) {
                    this.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not a number');
                }
                else
                    if (el.value.length > myRule.comparisonValue) {
                    this.highlight(el, this.inputclasserror);
                    err = this.getDefaultMessage(el, myRule.nameDisplayed, myRule.ruleName, myRule.comparisonValue) + '__inline__' + myRule.el;
                }
            }
            else
                if (myRule.ruleName == 'minlength') {
                if (isNaN(myRule.comparisonValue)) {
                    this.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not a number');
                }
                else
                    if (el.value.length < myRule.comparisonValue) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else if (myRule.ruleName == 'numrange') {
                if (el.value.trim() != '') {
                    reg = new RegExp("^[-+]{0,1}[0-9]*[.]{0,1}[0-9]*$");
                    if (!reg.test(this.unformatNumber(el.value))) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                    }
                    else {
                        regRange = new RegExp("^[0-9]+-[0-9]+$");
                        if (!regRange.test(myRule.comparisonValue)) {
                            this.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not in format number1-number2');
                        }
                        else {
                            rangeVal = myRule.comparisonValue.split('-');
                            //workaround : check that value is a number (separator is '.')
                            if (((eval(this.unformatNumber(el.value)) < eval(rangeVal[0])
                                || eval(this.unformatNumber(el.value)) > eval(rangeVal[1])))) {
                                this.highlight(el, this.inputclasserror);
                                err = myRule.alertMsg;
                            }
                        }
                    }
                }
            }
            else if (myRule.ruleName == 'numrangeint') {
                if (el.value.trim() != '') {
                    reg = new RegExp("^[-+]{0,1}[0-9]*$");
                    if (!reg.test(el.value)) {
                        this.highlight(el, this.inputclasserror);
                        err = myRule.alertMsg;
                    }
                    else {
                        regRange = new RegExp("^[0-9]+-[0-9]+$");
                        if (!regRange.test(myRule.comparisonValue)) {
                            this.debug('DEBUG: comparisonValue for rule ' + myRule.ruleName + ' not in format number1-number2');
                        }
                        else {
                            rangeVal = myRule.comparisonValue.split('-');
                            if (eval(el.value) < eval(rangeVal[0]) || eval(el.value) > eval(rangeVal[1])) {
                                this.highlight(el, this.inputclasserror);
                                err = myRule.alertMsg;
                            }
                        }
                    }
                }
            }
            else
                if (myRule.ruleName == 'regexp') {
                reg = new RegExp(myRule.comparisonValue);
                if (!reg.test(el.value)) {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'integer') {
                err = this.checkInteger(el, myRule);
            }
            else
                if (myRule.ruleName == 'double') {
                err = this.checkDouble(el, myRule);
            }
            else
                if (myRule.ruleName == 'moneydecimal') {
                err = this.checkMoneydecimal(el, myRule);
            }
            else
                if (myRule.ruleName == 'date') {
                err = this.checkDate(el, myRule);
            }
            else
                if (myRule.ruleName == 'date_lt') {
                err = this.checkDateLessThan(el, myRule, false);
            }
            else
                if (myRule.ruleName == 'date_le') {
                err = this.checkDateLessThan(el, myRule, true);
            }
            else
                if (myRule.ruleName == 'keypress') {
                // do nothing
            }
            else
                if (myRule.ruleName == 'empty') {
                if (el.value != null && el.value.trim() != '') {
                    this.highlight(el, this.inputclasserror);
                    err = myRule.alertMsg;
                }
            }
            else {
                this.debug('DEBUG: rule ' + myRule.ruleName + ' not supported for ' + el.type);
            }
            return err;
        },

        /*------------END checkText--------------------------------------------------------------------------------*/


        checkInteger: function(el, myRule) {
            var minIntValue = new Number(-2147483648);
            var maxIntValue = new Number(2147483647);
            var value = new Number(el.value.trim());
            reg = new RegExp("^[-+]{0,1}[0-9]*$");
            if ((el.value.trim() != '') && (!reg.test(el.value) || !(minIntValue <= value && value <= maxIntValue))) {
                this.highlight(el, this.inputclasserror);
                return myRule.alertMsg;
            }
        },

        /*--------END checkInteger------------------------------------------------------------------------------------*/

        checkDouble: function(el, myRule) {
            var sep = this.DECIMAL_SEP;
            reg = new RegExp("^[-+]{0,1}[0-9]*[" + sep + "]{0,1}[0-9]*$");
            if ((el.value.trim() != '') && !reg.test(el.value)) {
                this.highlight(el, this.inputclasserror);
                return myRule.alertMsg;
            }
        },

        /*------------END checkDouble---------------------------------------------------------------------------------*/

        checkMoneydecimal: function(el, myRule) {
            if (el.value != '') {
                var sep = this.DECIMAL_SEP;
                reg = new RegExp("^[+]{0,1}[0-9]{1,16}([" + sep + "][0-9]{0,2}){0,1}$");
                if (!reg.test(el.value)) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
        },

        /*------------END checkMoneydecimal---------------------------------------------------------------------------------*/

        checkDate: function(el, myRule) {
            error = null;
            if (el.value != '') {
                var dateFormat = this.DATE_FORMAT;
                ddReg = new RegExp("dd");
                MMReg = new RegExp("MM");
                yyyyReg = new RegExp("yyyy");

                if (!ddReg.test(dateFormat) || !MMReg.test(dateFormat) || !yyyyReg.test(dateFormat)) {
                    this.debug('DEBUG: locale format ' + dateFormat + ' not supported');
                }
                else {
                    ddStart = dateFormat.indexOf('dd');
                    MMStart = dateFormat.indexOf('MM');
                    yyyyStart = dateFormat.indexOf('yyyy');
                }
                strReg = dateFormat.replace('dd', '[0-9]{2}').replace('MM', '[0-9]{2}').replace('yyyy', '[0-9]{4}');
                reg = new RegExp("^" + strReg + "$");
                if (!reg.test(el.value)) {
                    this.highlight(el, this.inputclasserror);
                    error = myRule.alertMsg;
                }
                else {
                    dd = el.value.substring(ddStart, ddStart + 2);
                    MM = el.value.substring(MMStart, MMStart + 2);
                    yyyy = el.value.substring(yyyyStart, yyyyStart + 4);

                    if (!this.checkddMMyyyy(dd, MM, yyyy)) {
                        this.highlight(el, this.inputclasserror);
                        error = myRule.alertMsg;
                    }
                }
            }
            return error;
        },

        /*--------END checkDate--------------------------------------------------------------------------------------*/

        checkDateLessThan: function(el, myRule, isEqualAllowed) {
            error = null;
            var isDate = this.checkDate(el, myRule) == null ? true : false;
            if (isDate && el.value != '') {
                var dateFormat = this.DATE_FORMAT;
                ddStart = dateFormat.indexOf('dd');
                MMStart = dateFormat.indexOf('MM');
                yyyyStart = dateFormat.indexOf('yyyy');
                dd = el.value.substring(ddStart, ddStart + 2);
                MM = el.value.substring(MMStart, MMStart + 2);
                yyyy = el.value.substring(yyyyStart, yyyyStart + 4);
                myDate = "" + yyyy + MM + dd;
                strReg = dateFormat.replace('dd', '[0-9]{2}').replace('MM', '[0-9]{2}').replace('yyyy', '[0-9]{4}');
                reg = new RegExp("^" + strReg + "$");
                var isMeta = myRule.comparisonValue.indexOf('$') == 0 ? true : false;
                var comparisonDate = '';

                if (isMeta) {
                    toSplit = myRule.comparisonValue.substr(1);
                    tmp = toSplit.split(':');

                    if (tmp.length == 2) {
                        comparisonDate = this.getField(this.f, tmp[0]).value;
                    }
                    else {
                        comparisonDate = this.getField(this.f, myRule.comparisonValue.substr(1)).value;
                    }
                }
                else {
                    comparisonDate = myRule.comparisonValue;
                }

                if (!reg.test(comparisonDate)) {
                    this.highlight(el, this.inputclasserror);
                    error = myRule.alertMsg;
                }
                else {
                    cdd = comparisonDate.substring(ddStart, ddStart + 2);
                    cMM = comparisonDate.substring(MMStart, MMStart + 2);
                    cyyyy = comparisonDate.substring(yyyyStart, yyyyStart + 4);
                    cDate = "" + cyyyy + cMM + cdd;

                    if (isEqualAllowed) {
                        if (!this.checkddMMyyyy(cdd, cMM, cyyyy) || myDate > cDate) {
                            this.highlight(el, this.inputclasserror);
                            error = myRule.alertMsg;
                        }
                    }
                    else {
                        if (!this.checkddMMyyyy(cdd, cMM, cyyyy) || myDate >= cDate) {
                            this.highlight(el, this.inputclasserror);
                            error = myRule.alertMsg;
                        }
                    }
                }
            }
            else {
                if (el.value != '') {
                    this.highlight(el, this.inputclasserror);
                    error = myRule.alertMsg;
                }
            }
            return error;
        },

        /*----------END checkDateLessThan---------------------------------------------------------------------------------*/

        checkEqual: function(el, myRule) {
            error = null;
            var isMeta = myRule.comparisonValue.indexOf('$') == 0 ? true : false;
            var comparisonVal = '';

            if (isMeta) {
                toSplit = myRule.comparisonValue.substr(1);
                tmp = toSplit.split(':');

                if (tmp.length == 2) {
                    comparisonVal = this.getField(this.f, tmp[0]).value;
                }
                else {
                    comparisonVal = this.getField(this.f, myRule.comparisonValue.substr(1)).value;
                }
            }
            else {
                comparisonVal = myRule.comparisonValue;
            }
            if (el.value != comparisonVal) {
                this.highlight(el, this.inputclasserror);
                error = myRule.alertMsg;
            }
            return error;
        },

        /*--------END checkEqual---------------------------------------------------------------------------------------*/

        checkNotEqual: function(el, myRule) {

            error = null;
            var isMeta = myRule.comparisonValue.indexOf('$') == 0 ? true : false;
            var comparisonVal = '';

            if (isMeta) {
                toSplit = myRule.comparisonValue.substr(1);
                tmp = toSplit.split(':');
                if (tmp.length == 2) {
                    comparisonVal = this.getField(this.f, tmp[0]).value;
                }
                else {
                    comparisonVal = this.getField(this.f, myRule.comparisonValue.substr(1)).value;
                }
            }
            else {
                comparisonVal = myRule.comparisonValue;
            }
            var value = (el.value.indexOf(',') != -1) ? el.value.replace(',', '.') : el.value;

            if ((el.value == comparisonVal) || (comparisonVal == '0' && parseFloat(value) == 0)) {
                this.highlight(el, this.inputclasserror);
                error = myRule.alertMsg;
            }
            return error;
        },

        /*---------END checkNotEqual-------------------------------------------------------------------------------------*/

        checkddMMyyyy: function(dd, MM, yyyy) {
            retVal = true;
            if ((dd < 1) || (dd > 31) || (MM < 1) || (MM > 12) ||
            (dd == 31 && (MM == 2 || MM == 4 || MM == 6 || MM == 9 || MM == 11)) ||
            (dd > 29 && MM == 2) ||
            (dd == 29 && (MM == 2) && ((yyyy % 4 > 0) || (yyyy % 4 == 0 && yyyy % 100 == 0 && yyyy % 400 > 0)))) {
                retVal = false;
            }
            return retVal;
        },

        /*-------END checkddMMyyyy--------------------------------------------------------------------------------------*/

        checkCheckbox: function(el, myRule) {
            if (myRule.ruleName == 'required') {
                if (!el.checked) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'equal') {
                if (!el.checked || el.value != myRule.comparisonValue) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'notequal') {
                if (!el.checked || el.value == myRule.comparisonValue) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else {
                this.debug('DEBUG: rule ' + myRule.ruleName + ' not supported for ' + el.type);
            }
        },

        /*------END checkCheckbox------------------------------------------------------------------------------*/

        checkSelOne: function(el, myRule) {
            if (myRule.ruleName == 'required') {
                var found = false;
                var inx = el.selectedIndex;
                if (inx >= 0 && el.options[inx].value) {
                    found = true;
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else if (myRule.ruleName == 'equal') {
                var found = false;
                var inx = el.selectedIndex;
                if (inx >= 0 && el.options[inx].value == myRule.comparisonValue) {
                    found = true;
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'notequal') {
                var found = false;
                var inx = el.selectedIndex;
                if (inx >= 0 && el.options[inx].value != myRule.comparisonValue) {
                    found = true;
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else {
                this.debug('DEBUG: rule ' + myRule.ruleName + ' not supported for ' + el.type);
            }
        },

        /*--------END checkSelOne--------------------------------------------------------------------------------*/

        checkSelMul: function(el, myRule) {
            if (myRule.ruleName == 'required') {
                var found = false;
                opts = el.options;
                for (var i = 0; i < opts.length; i++) {
                    if (opts[i].selected && opts[i].value) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else if (myRule.ruleName == 'equal') {
                var found = false;
                opts = el.options;
                for (var i = 0; i < opts.length; i++) {
                    if (opts[i].selected && opts[i].value == myRule.comparisonValue) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else
                if (myRule.ruleName == 'notequal') {
                var found = false;
                opts = el.options;

                for (var i = 0; i < opts.length; i++) {
                    if (opts[i].selected && opts[i].value != myRule.comparisonValue) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    this.highlight(el, this.inputclasserror);
                    return myRule.alertMsg;
                }
            }
            else {
                this.debug('DEBUG: rule ' + myRule.ruleName + ' not supported for ' + el.type);
            }
        },

        /*---------END checkSelMul---------------------------------------------------------------------------------------*/

        debug: function(msg) {
            if (this.debugmode) {
                alert(msg);
            }
        },

        /*----------END debug--------------------------------------------------------------------------------------*/

        strTrim: function(str) {
            return str.replace(/^\s+/, '').replace(/\s+$/, '');
        },

        /*----------------------------------------------------------------------------------------------------*/

        makeRules: function(strRules) {
            var rules = new Array();

            if (strRules.length) {
                for (var i = 0; i < strRules.length; i++) {
                    rules[i] = this.splitRule(strRules[i]);
                }
            }
            else {
                rules[0] = this.splitRule(strRules);
            }
            return rules;
        },

        /*-----END makeRules-----------------------------------------------------------------------------------*/

        splitRule: function(strRule) {
            var retval = null;
            if (strRule != this.undef) {
                var params = strRule.split(this.RULE_SEP);
                switch (params.length) {
                    case 2:
                        retval = new this.rule(params[0], params[1], null, null, null, this);
                        break;

                    case 3:
                        if (this.threeParamRule(params[1])) {
                            retval = new this.rule(params[0], params[1], params[2], null, null, this);
                        }
                        else
                            if (params[2] == 'pre-condition' || params[2] == 'post-condition' || params[2] == 'andor-operator') {
                            retval = new this.rule(params[0], params[1], null, 'foo', params[2], this);
                        }
                        else {
                            retval = new this.rule(params[0], params[1], null, params[2], null, this);
                        }
                        break;

                    case 4:
                        if (this.threeParamRule(params[1]) && (params[3] == 'pre-condition' || params[3] == 'post-condition' || params[3] == 'andor-operator')) {
                            retval = new this.rule(params[0], params[1], params[2], 'foo', params[3], this);
                        }
                        else {
                            retval = new this.rule(params[0], params[1], params[2], params[3], params[2], this);
                        }
                        break;

                    case 5:
                        if ((params[3] == 'post-condition') && ((params[1] == 'numrange') || (params[1] == 'maxlength'))) {
                            retval = new this.rule(params[0], params[1], params[2], params[4], params[3], this);
                        }
                        else {
                            retval = new this.rule(params[0], params[1], params[2], params[3], params[4], this);
                        }
                        break;

                    default:
                        this.debug('DEBUG: wrong definition of rule');
                }
            }
            return retval;
        },

        /*--------END splitRule--------------------------------------------------------------------------------*/

        threeParamRule: function(ruleName) {
            return (ruleName == 'equal' || ruleName == 'notequal' || ruleName == 'minlength' || ruleName == 'maxlength' || ruleName == 'date_lt' || ruleName == 'date_le' || ruleName == 'implies' || ruleName == 'regexp' || ruleName == 'numrange' || ruleName == 'keypress' || ruleName == 'and' || ruleName == 'or' || ruleName == 'custom') ? true : false;
        },

        /*-------END threeParamRule----------------------------------------------------------------------------*/

        highlight: function(el, clazz) {
            if (!this.isFocusSet && clazz == this.inputclasserror) {
                try {
                    el.focus();
                }
                catch (err) {
                    //this.debug('validation can not set focus');
                }
                this.isFocusSet = true;
            }
            if (el != this.undef && this.inputhighlight) {
                if (this.multipleclassname) {
                    this.highlightMultipleClassName(el, clazz);
                }
                else {
                    el.className = clazz;
                }
            }
        },

        /*--------END highlight--------------------------------------------------------------------------------*/


        highlightMultipleClassName: function(el, clazz) {
            re = new RegExp("\\s*(" + this.inputclassnormal + "|" + this.inputclasserror + ")");
            el.className = this.strTrim(((typeof el.className != "undefined") ? el.className.replace(re, "") : "") + " " + clazz);
        },

        /*--------end highlightMultipleClassName-------------------------------------------------------------------*/

        getDefaultMessage: function(el, nameDisplayed, ruleName, comparisonValue) {
            if (nameDisplayed.length == 0) {
                nameDisplayed = el;
            }
            var msg = this.DEFAULT_MSG + ' ' + nameDisplayed;

            if (ruleName == 'required') {
                if (nameDisplayed == this.undef || nameDisplayed == null || nameDisplayed == "") {
                    nameDisplayed = 'value';
                }
                msg = this.REQUIRED_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'minlength') {
                msg = this.MINLENGTH_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
            }
            else
                if (ruleName == 'maxlength') {
                msg = this.MAXLENGTH_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
                //msg = this.MAXLENGTH_MSG.replace('{1}', comparisonValue);
            }
            else
                if (ruleName == 'numrange') {
                msg = this.NUMRANGE_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
            }
            else
                if (ruleName == 'numrangeint') {
                msg = this.NUMRANGE_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
            }
            else
                if (ruleName == 'date') {
                msg = this.DATE_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'numeric') {
                msg = this.NUMERIC_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'integer') {
                msg = this.INTEGER_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'double') {
                msg = this.DOUBLE_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'equal') {
                msg = this.EQUAL_MSG.replace('{1}', nameDisplayed).replace('{2}', this.getComparisonDisplayed(comparisonValue));
            }
            else
                if (ruleName == 'notequal') {
                msg = this.NOTEQUAL_MSG.replace('{1}', nameDisplayed).replace('{2}', this.getComparisonDisplayed(comparisonValue));
            }
            /*else 
            if (ruleName=='alphabetic') 
            {
            msg = this.ALPHABETIC_MSG.replace('{1}', nameDisplayed);
            } 
            else 
            if (ruleName=='alphanumeric') 
            {
            msg = this.ALPHANUMERIC_MSG.replace('{1}', nameDisplayed);
            } 
            else 
            if (ruleName=='alnumhyphen') 
            {
            msg = this.ALNUMHYPHEN_MSG.replace('{1}', nameDisplayed);
            } 
            else 
            if (ruleName=='alnumhyphenat') 
            {
            msg = this.ALNUMHYPHENAT_MSG.replace('{1}', nameDisplayed);
            } 
            else 
            if (ruleName=='alphaspace') 
            {
            msg = this.ALPHASPACE_MSG.replace('{1}', nameDisplayed);
            } 
            else if (ruleName=='alphanumspacespecials') 
            {
            if(TR_CLIENT_MESSAGES['AlphaNumSpaceSpecialsMsg'])
            {
            msg = TR_CLIENT_MESSAGES['AlphaNumSpaceSpecialsMsg'].replace('{1}', nameDisplayed);
            }
            else
            {
            msg = this.ALPHANUMSPACESPECIALS_MSG.replace('{1}', nameDisplayed);
            }
            }
            else if (ruleName=='alphanumspacespecialslinebreak') 
            {
            msg = this.ALPHANUMSPACESPECIALSLINEBREAK_MSG.replace('{1}', nameDisplayed);
            }*/
            else if (ruleName == 'filename') {
                msg = this.FILENAME_MSG.replace('{1}', nameDisplayed);
            }
            else if (ruleName == 'dangeroustags') {
                msg = this.DANGEROUSTAGS_MSG.replace('{1}', nameDisplayed);
            }
            else if (ruleName == 'partiallastdigitsphonenumber') {
                msg = this.PARTIAL_LAST_DIGITS_PHONENUMBER_MSG.replace('{1}', nameDisplayed);
            }
            else if (ruleName == 'phonenumber') {
                msg = this.PHONENUMBER_MSG.replace('{1}', nameDisplayed);
            }
            else if (ruleName == 'coverprice') {
                msg = this.COVERPICE_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'email') {
                msg = this.EMAIL_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'regexp') {
                msg = this.REGEXP_MSG.replace('{1}', nameDisplayed).replace('{2}', comparisonValue);
            }
            else
                if (ruleName == 'date_lt') {
                msg = this.DATE_LT_MSG.replace('{1}', nameDisplayed).replace('{2}', this.getComparisonDisplayed(comparisonValue));
            }
            else
                if (ruleName == 'date_le') {
                msg = this.DATE_LE_MSG.replace('{1}', nameDisplayed).replace('{2}', this.getComparisonDisplayed(comparisonValue));
            }
            else
                if (ruleName == 'moneydecimal') {
                msg = this.MONEYDECIMAL_MSG.replace('{1}', nameDisplayed);
            }
            else
                if (ruleName == 'empty') {
                msg = this.EMPTY_MSG.replace('{1}', nameDisplayed);
            }
            return msg;
        },

        /*------END getDefaultMessage-----------------------------------------------------------------------*/

        getComparisonDisplayed: function(comparisonValue) {
            comparisonDisplayed = comparisonValue;

            if (comparisonValue.substring(0, 1) == '$') {
                comparisonValue = comparisonValue.substring(1, comparisonValue.length);
                tmp = comparisonValue.split(':');

                if (tmp.length == 2) {
                    comparisonDisplayed = tmp[1];
                }
                else {
                    comparisonDisplayed = comparisonValue;
                }
            }
            return comparisonDisplayed;
        },

        /*------END getComparisonDisplayed-----------------------------------------------------------------------------*/

        isUrl: function(s) {
            //debugger;
            //var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
            //            var rgxstr = "^(http|https):\\/\\/((([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?\\.)*([a-zA-Z]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)|(\\d+\\.\\d+\\.\\d+\.\\d+))(:\\d+)?)(\\/(([^/\\/?])*(\\/([^/\\/?])*)*)(\\?([^/\\/?])*)?)?$"
            var rgxstr = "^(http|https):\\/\\/((([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?\\.)*" //string IP
                       + "([a-zA-Z]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)" //string IP
                       + "|(\\d+\\.\\d+\\.\\d+\.\\d+))(:\\d+)?/?)" //numerical IP and port
                       + "((\\/([^/\\/?])*(\\/([^/\\/?])*)*[a-zA-Z0-9/])?" //subfolders
                       + "(\\?([^/\\/?])*[a-zA-Z0-9])?)?$"; //parameters after ? character
            reg = new RegExp(rgxstr);
            return reg.test(s);
        },

        /*------END isURL*/

        getBrowser: function() {
            brs = navigator.userAgent.toLowerCase();
            var retval;
            if (brs.search(/msie\s(\d+(\.?\d)*)/) != -1) {
                retval = 'msie';
            }
            else
                if (brs.search(/netscape[\/\s](\d+([\.-]\d)*)/) != -1) {
                retval = 'netscape';
            }
            else
                if (brs.search(/firefox[\/\s](\d+([\.-]\d)*)/) != -1) {
                retval = 'firefox';
            }
            else {
                retval = 'unknown';
            }
            return retval;
        },

        /*------END getBrowser-----------------------------------------------------------------------------------------*/

        isKeyAllowed: function(keyCode, charsAllowed) {
            retval = false;
            var aCharCode;
            if (keyCode == 8) {
                retval = true;
            }
            else {
                for (var i = 0; i < charsAllowed.length; i++) {
                    aCharCode = charsAllowed.charCodeAt(i);
                    if (aCharCode == keyCode) {
                        retval = true;
                        break;
                    }
                }
            }
            return retval;
        },

        /*-----END isKeyAllowed------------------------------------------------------------------------------------------*/


        getField: function(formObj, fieldName) {
            var retval = null;
            if (formObj.elements[fieldName]) {
                retval = formObj.elements[fieldName];
            }
            else
                if (document.getElementById(fieldName)) {
                retval = document.getElementById(fieldName);
            }
            return retval;
        },

        /*-------END getField----------------------------------------------------------------------------------------*/

        unformatNumber: function(viewValue) {
            var retval = viewValue.replace(this.THOUSAND_SEP, "");
            retval = retval.replace(this.DECIMAL_SEP, ".");
            return parseFloat(retval);
        },

        /*---------END unformatNumber--------------------------------------------------------------------------------------*/

        deleteInline: function(msg) {
            if (msg.indexOf('__inline__') == -1) {
                return msg;
            }
            else {
                return msg.substring(0, msg.indexOf('__inline__'));
            }
        },

        /*--END deleteInline--------------------------------------------------------------------------------------*/

        dispose: function() {
        }

        //end
    }

Common.Validator.registerClass('Common.Validator', null, Sys.IDisposable);

var validator = new Common.Validator();

function CultureInfoHelper(decimalSep, thousandSep) 
{
    validator.DECIMAL_SEP = decimalSep;
    validator.THOUSAND_SEP = thousandSep;
}

function OnValidate(rules, displayType) 
{
    var alertType = 'inline';
    var formName = document.forms[0].id;//'aspnetForm';        
    var result = validator.performCheck(formName, rules, alertType);            
    if (result != null && result == false)
    {
        try
        {
            var customMessage = false; 
            for(var i=0; i<validator.internalRules.length; i++) 
            {                
                if(validator.internalRules[i].err)
                {
                    var messageKey = validator.internalRules[i].alertMsg.substring(0,validator.internalRules[i].alertMsg.indexOf('__inline__'));
                    var genericMessageKey = validator.internalRules[i].alertMsg.substring(0,validator.internalRules[i].alertMsg.indexOf('__inline__')) + 'Generic';
                    if(TR_CLIENT_MESSAGES[genericMessageKey])
                    {                        
                        msgControl.SetErrorMessage(
                            TR_CLIENT_MESSAGES[genericMessageKey].replace('{1}', validator.internalRules[i].nameDisplayed).replace('{2}', validator.internalRules[i].comparisonValue),
                            displayType
                            );
                        customMessage = true;
                        break;
                    }                    
                    else if(validator.internalRules[i].ruleName=='custom') 
                    {
                        messageKey = validator.internalRules[i].err.substring(0,validator.internalRules[i].err.indexOf('__inline__'));                    
                        genericMessageKey = validator.internalRules[i].err.substring(0,validator.internalRules[i].err.indexOf('__inline__')) + 'Generic';                    
                        if(TR_CLIENT_MESSAGES[genericMessageKey])
                        {                        
                            msgControl.SetErrorMessage(
                                TR_CLIENT_MESSAGES[genericMessageKey].replace('{1}', validator.internalRules[i].nameDisplayed).replace('{2}', validator.internalRules[i].comparisonValue),
                                displayType
                                );
                            customMessage = true;
                            break;
                        }                        
                    }                    
                }               
            }

            if(!customMessage)
            {            
                msgControl.SetErrorMessage(
                    TR_CLIENT_MESSAGES["PageNameValidationFailed"], 
                    displayType
                    );
            }            
            
            if (validator.OnValidationFailedHandler)
            {
                validator.OnValidationFailedHandler(validator.failedRules, validator.internalRules);
            }
        }
        catch(Error)
        {
        }
    }
    return result != null && result != false;    
}

function OnFlyValidate(rule, displayType)
{
    var rules = new Array(1);
    rules[0] = rule;
    return OnValidate(rules, displayType);
}
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

function testEmail(localPart, domain) {
    return localPart.length > 64 || domain.length > 255 || localPart[0] == '.' || domain[domain.length - 1] == '.' || localPart.indexOf("..") > -1 || domain.indexOf("..") > -1;
}