
//****************************************************************
// This section provides base objects for Validation
//***************************************************************
if (!SIGI || !SIGI.Parsing || !SIGI.TooltipControllerObject) {
    throw ("SIGI.Validation depends on the following scripts. Please make sure these are included.\nSIGI.js, SIGI.Parsing, SIGI.ToolTip");
}
SIGI.Validation = {};
SIGI.Validation.PageValidators = new Array();
SIGI.Validation.PageValidators.add = function(validator) { this.push(validator); };
SIGI.Validation.Errors = new Array();
SIGI.Validation.RequiredLabelClassName = "FormLabel";
SIGI.Validation.RequiredControlClassName = "";
SIGI.Validation.CompositeControlUnderValidation = "";
SIGI.Validation.EnableClientValidationSummary = true;
SIGI.Validation.SuspendHardStopValidation = false;

SIGI.Validation.Validate = function() {
    var valid = true;
    var firstFailedControl = null;
    SIGI.Validation.Errors = new Array();
    for (var i = 0; i < SIGI.Validation.PageValidators.length; i++) {
        var validator = SIGI.Validation.PageValidators[i]; //
        if (validator && validator.validate) {
            //indicator that this is a simplevalidator, do not run this client validation on these.
            var ctl = validator.control;
            var tag = "SPAN";
            if ((ctl != null) && (ctl.nodeName != null)) {
                tag = ctl.nodeName.toUpperCase();
            }
            if ((ctl == null) || (tag != "SPAN")) {
                valid = validator.validate() && valid;
                if (!validator.isValid) {
                    //determine if this one was ok but an alternative one in a composite validation failed, use that instead
                    var validatorToPush = validator;
                    if (validator.alternateFailedValidator) {
                        validatorToPush = validator.alternateFailedValidator;
                    }
                    SIGI.Validation.Errors.push(new SIGI.Validation.ErrorObject(validatorToPush.control, validatorToPush.severity, validatorToPush.errorMessage));
                    if ((ctl != null) && (firstFailedControl == null)) {
                        firstFailedControl = ctl;
                    }
                }
            }
        }
    }
    if (!valid) {
        if (SIGI.Validation.EnableClientValidationSummary) {
            return SIGI.Validation.displayErrors();
        }
        else {
            if (firstFailedControl != null) {
                SIGI.setFocusAndFireValidation(firstFailedControl);
            }
        }
    }
    return valid;
}

SIGI.Validation.add_onSummaryContinue = function(functionPointer) {
    this._onSummaryContinue = functionPointer;
}

SIGI.Validation._fire_onSummaryContinue = function(returnValue) {
    if (this._onSummaryContinue) {
        var eventArgs = returnValue; //this is the return from the dialog
        var sender = this;
        return eval("this._onSummaryContinue(sender, eventArgs)");
    }
}

SIGI.Validation.hideLabelWithElement = function(element) {
    oneShowing = false;
    var i = 0;
    var ctrl;
    if (element.label) {
        if (element.label.htmlFor) {
            var ctrlNames = element.label.htmlFor.split(";");
            if (ctrlNames.length == 0) {
                return false;
            }
            if (ctrlNames.length == 1) {
                return true;
            }
            else {
                for (i = 0; i < ctrlNames.length; i++) {
                    elem = document.getElementById(ctrlNames[i]);
                    if (elem) {
                        if (elem.style.display != "none") {
                            oneShowing = true;
                        }
                    }
                }
            }
        }
    }

    return !oneShowing;
}
function colorLabelFalseServerValidation(lbl, severity) {
    if (severity == "information") {
        //exclude itself based on explicit switch on label, default back to "FormLabel"
        if (lbl.enableRequiredStyle.toBoolean()) {
            lbl.className = "FormLabel";
        }
        else {
            lbl.className = SIGI.Validation.RequiredLabelClassName;
        }
    }
    else {
        lbl.className = "ErrorLabel";
    }
}

function controlForSV(svControl) {
    var j;
    if (left(svControl.outerHTML, 5) == "<SPAN") {
        if (svControl.className == "SimpleErrorLabel") {
            for (j = 0; j < document.all.length; j++) {
                try {
                    if (document.all[j].simpleValidator) {
                        if (document.all[j].simpleValidator == svControl.id) {
                            return document.all[j];
                        }
                    }
                }
                catch (e) {
                };
            }
        }
    }
    return null;
}

function labelForSV(svControl) {
    var j;
    if (left(svControl.outerHTML, 5) == "<SPAN") {
        if (svControl.className == "SimpleErrorLabel") {
            for (j = 0; j < document.all.length; j++) {
                try {
                    if (document.all[j].simpleValidator) {
                        if (document.all[j].simpleValidator == svControl.id) {
                            var idFor = document.all[j].id;
                            var labels = document.getElementsByTagName('label');
                            for (var k = 0; k < labels.length; k++) {
                                try {
                                    if (labels[k].outerHTML.indexOf("for=" + idFor) != -1) {
                                        return labels[k];
                                    }
                                }
                                catch (ex) { };
                            }
                        }
                    }
                }
                catch (e) {
                };
            }
        }
    }
    return null;
}

SIGI.Validation.colorRequiredFieldLabels = function() {
    var i;
    var lbl;
    //first deal with the validators pushed directly to the controls
    for (i = 0; i < SIGI.Validation.PageValidators.length; i++) {
        try {
            var textLoc = SIGI.Validation.PageValidators[i].control.validation.indexOf("required:true");
            if (textLoc > -1) {
                lbl = SIGI.Validation.PageValidators[i].control.label;
                if (lbl == null) {
                    try {
                        lbl = document.getElementById(SIGI.Validation.PageValidators[i].control.attributes["label"].value);
                    }
                    catch (e)
                { };
                }
                //code to include simple validators in label coloration
                if (lbl != null) {
                    colorLabelFalseServerValidation(lbl, "information");
                }
            }
        }
        catch (err) {
        }
    }
    //    //then get the simple validators' controls
    //    var className;
    //    var SVSpans = document.getElementsByTagName("span");
    //    for (i = 0; i < SVSpans.length; i++) {
    //        try {
    //            className = SVSpans[i].className;
    //            if (className == "SimpleErrorLabel") {
    //                if (lbl == null) {
    //                    lbl = document.getElementById(SIGI.Validation.PageValidators[i].control.attributes["label"].value);
    //                }
    //                if (lbl != null) {
    //                    colorLabelFalseServerValidation(lbl, "required");
    //                }
    //            }
    //        }
    //        catch (err) {
    //        }
    //    }
}

SIGI.Validation.colorRequiredFieldControls = function() {

    //Method of applying multiple styles
    for (i = 0; i < SIGI.Validation.PageValidators.length; i++) {
        if (SIGI.Validation.PageValidators[i].control.validation) {
            var enableStyle = SIGI.Validation.PageValidators[i].control.enableRequiredStyle;
            if ((enableStyle == null) || (enableStyle.toBoolean() == true)) {
                var textLoc = SIGI.Validation.PageValidators[i].control.validation.indexOf("required:true");
                if (textLoc > -1) {
                    el = SIGI.Validation.PageValidators[i].control;
                    //el.className += " " + SIGI.Validation.RequiredControlClassName;
                    el.className += SIGI.Validation.RequiredControlClassName;
                }
            }
        }
    }
    return;


    //Method of applying individual style rules
    if (!document.styleSheets) return;
    //track down the css rule for styling required controls
    var rule = null;
    var i;
    var j;
    for (i = 0; i < document.styleSheets.length; i++) { // For each stylesheet
        var styleSheet = document.styleSheets[i];          // Get the current Stylesheet
        var rules = document.styleSheets[i].rules || document.styleSheets[0].cssRules; //get the rules, all browsers
        for (j = 0; j < rules.length; j++) { // For each rule
            if (rules[j].selectorText == "." + SIGI.Validation.RequiredControlClassName) {
                rule = rules[j];
                break;
            }
        }
        if (rule) {
            break;
        }
    }
    //if the rule is found...
    if (rule) {
        //move its individual parts into an array of strings
        var el = null;
        var ruleParts = rule.style.cssText.split(";");
        //now for each required input control, apply each style piece individually
        for (i = 0; i < SIGI.Validation.PageValidators.length; i++) {
            if (SIGI.Validation.PageValidators[i].control.validation) {
                var enableStyle = SIGI.Validation.PageValidators[i].control.enableRequiredStyle;
                if ((enableStyle == null) || (enableStyle.toBoolean() == true)) {
                    var textLoc = SIGI.Validation.PageValidators[i].control.validation.indexOf("required:true");
                    if (textLoc > -1) {
                        el = SIGI.Validation.PageValidators[i].control;
                        if (el) {
                            //if this is a simple validator, shift to its controlToValidate
                            if (el.getAttribute("controlToValidate")) {
                                el = document.getElementById(el.getAttribute("controlToValidate"));
                            }
                            for (j = 0; j < ruleParts.length; j++) { // For each rule-part
                                var pair = ruleParts[j].split(":");
                                var propName = pair[0].trim();
                                var propValue = pair[1].trim();
                                if (el.style.setProperty) {
                                    el.style.setProperty(propName, propValue);
                                }
                                else {
                                    switch (propName.replace("-", "")) {
                                        case "COLOR":
                                            el.style.color = propValue;
                                            break;
                                        case "BACKGROUNDCOLOR":
                                            el.style.backgroundColor = propValue;
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

SIGI.Validation.displayErrors = function() {
    var i;
    var lbl;
    for (i = 0; i < SIGI.Validation.Errors.length; i++) {
        try {
            lbl = SIGI.Validation.Errors[i].control.label;
            if (lbl == null) {
                lbl = document.getElementById(SIGI.Validation.Errors[i].control.attributes["label"].value);
            }
            if (lbl != null) {
                severity = SIGI.Validation.Errors[i].severity;
                colorLabelFalseServerValidation(lbl, severity);
            }
        }
        catch (err) {
        }
    }
    if (SIGI.Browser.isIE) {
        var ret = SIGI.showModalDialog(SIGI.getClientThemePath() + "/Pages/SIGI.Validation.Summary.htm", SIGI.Validation.Errors, 428, 475);

        if (ret) {
            if (ret != "continue") {
                document.getElementById(ret);
                if (ret.className == "MaskedEditValue") {
                    /*
                    RTS 1301680
                    Next line of code revised to reflect change in internal structure of composite control            
                    */
                    /*
                    RTS 1311910
                    identification of _Shell node with child nodes 
                    not specific enough with ret.parentNode.childNodes[1].childNodes[0].childNodes
                    replaced with specific search by _Shell, the known specific ID for parent node
                    */
                    //parts = ret.parentNode.childNodes[1].childNodes[0].childNodes;
                    parts = document.getElementById(ret.id.replace("_Value", "_Shell")).childNodes;
                    for (z = 0; z < parts.length; z++) {
                        if (parts[z].className == "MaskedEditPartInput") {
                            ret = parts[z];
                            window.setTimeout("$SIGIfind('" + ret.id + "')._selectFullText();", 100);
                            break;
                        }
                    }
                }
                if (ret.controlToValidate) {
                    SIGI.setFocus(document.getElementById(ret.controlToValidate));
                }
                else {
                    SIGI.setFocus(ret);
                }
                return false;
            }
            else {
                SIGI.Validation._fire_onSummaryContinue(ret);
                return true;
            }
        }
    }
}


SIGI.Validation.onbeforedeactivate = function() {
    if (SIGI.Validation.SuspendHardStopValidation) {
        return true;
    }
    SIGI.Tooltip.hide();
//    if (SIGI.skipForcedFocus == true) {
//        return true;
//    }
    parentId = event.srcElement.getAttribute("compositeParentId");
    if ((parentId != null) && (SIGI.Validation.CompositeControlUnderValidation != parentId))
        return;
    var validator = event.srcElement.validationObject;
    if (validator && validator.validate) {
        if (!validator.validate()) {
            SIGI.Browser.isToolTippingForValidation = true;
            //determine if this one was ok but an alternative one in a composite validation failed, use that instead
            var validatorToPush = validator;
            var elementToPush = event.srcElement;
            if (validator.alternateFailedValidator) {
                validatorToPush = validator.alternateFailedValidator;
                elementToPush = validatorToPush.control;
            }
            if ((validatorToPush.severity == "information") && ((SIGI.Tooltip.currentElement == null) || (elementToPush == SIGI.Tooltip.currentElement))) {
                event.returnValue = true;
                return true;
            }
            SIGI.Tooltip.showForValidation(elementToPush, validatorToPush.errorMessage, validatorToPush.severity, validatorToPush.align);
            if ((elementToPush.getAttribute("validationFailure") == null) || (elementToPush.getAttribute("validationFailure").toLowerCase() != "continue")) {
                event.returnValue = false;
                if (validator.alternateFailedValidator) {
                    SIGI.setFocusForValidationFailure(elementToPush); //validationFailure
                }
                return false;
            }
            else {
                SIGI.Tooltip.skipHide = true;
                window.setTimeout("SIGI.Tooltip.hide();", 2000);
            }
        }
        else {
            if (SIGI.Browser.isToolTippingForValidation == true) {
                SIGI.Browser.isToolTippingForValidation = false;
            }
            //else {
            SIGI.Tooltip.hide();
            //}
        }
    }
    return true;
}


//****************************************************************
// This section provides base objects for Validation
//***************************************************************
function ErrorObject(control, severity, errorMessage) {
    this.Base();
    this.control = (control) ? control : null;
    this.severity = (typeof (severity) != "undefined") ? severity : "critical";
    this.errorMessage = (errorMessage) ? errorMessage : "Validation failed";
}
ErrorObject.inherits(SIGI.Base);
SIGI.Validation.ErrorObject = ErrorObject;
ErrorObject = null;




function BaseValidatorObject(control, severity, errorMessage, align) {
    this.ErrorObject(control, severity, errorMessage);
    this.align = (align) ? align : "bottom";
    this.enabled = true;
    this.isValid = true;
    this.label = null;

    if (this.control) {
        if (this.control.className && this.control.className == "DropDownList") {
            if (this.control.dropDownListObject) {
                this.control = this.control.dropDownListObject._textbox;
            }
        }
        if (this.control.label) {
            if (typeof this.control.label == "string") {
                this.label = document.getElementById(control.label);
                this.control.label = this.label;
            } else {
                this.label = this.control.label;
            }
        }
    }
}
BaseValidatorObject.inherits(SIGI.Validation.ErrorObject);
BaseValidatorObject.prototype.validate = function() {
    return this.isValid;
}
BaseValidatorObject.prototype.colorLabel = function() {
    if (this.label) {
        if (this.isValid) {
            if (this.disabled) {
                this.label.className = "DisabledLabel";
            }
            else {
                if (this.label.enableRequiredStyle.toBoolean()) {
                    this.label.className = "FormLabel";
                }
                else {
                    this.label.className = SIGI.Validation.RequiredLabelClassName;
                }
            }
        } else {
            if (this.severity == "information") {
                if (this.label.enableRequiredStyle.toBoolean()) {
                    this.label.className = "FormLabel";
                }
                else {
                    this.label.className = SIGI.Validation.RequiredLabelClassName;
                }
            }
            else
                this.label.className = "ErrorLabel";
        }
    }
}

BaseValidatorObject.prototype.getValue = SIGI.getValue;
BaseValidatorObject.prototype.getValueRecursive = SIGI.getValueRecursive;

BaseValidatorObject.prototype.setProperty = function(propertyValue) {
    switch (propertyValue.trim()) {
        case "true": case "false":
            this.enabled = propertyValue.qtrim().toBoolean();
            break;
        case "critical": case "information": case "exclamation": case "help": case "question":
            this.severity = propertyValue.qtrim();
            break;
        default:
            //            if (propertyValue.indexOf("client(") == 0) {
            //                propertyValue = propertyValue.replace("|", ";")
            //            }
            var re = /\s*(\w+)\s*\(\s*((?:"[^"]*"|'[^']*'|[^'"\)])*)\s*\)\s*/g;
            if (re.test(propertyValue)) {
                re.exec(propertyValue);
                switch (RegExp.$1.toLowerCase()) {
                    case "severity":
                        this.severity = propertyValue.qtrim();
                        break;
                    case "msg":
                        this.errorMessage = RegExp.$2.qtrim();
                        break;
                    default:
                        this.handleProperty(RegExp.$1.toLowerCase(), RegExp.$2)
                }
            } else {
                this.handleProperty(null, propertyValue);
            }
    }
}
BaseValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) { }
BaseValidatorObject.prototype.parseProperties = function(propertiesText) {
    var re = /((?:"[^"]*"|'[^']*'|[^'"\s])*)(?:\s|$)/g;
    var matches = propertiesText.match(re);
    for (var i = 0; i < matches.length; i++) {
        this.setProperty(matches[i].trim());
    }
}
SIGI.Validation.BaseValidatorObject = BaseValidatorObject;
BaseValidatorObject = null;




function RequiredValidatorObject(control, required, severity, errorMessage, align) {
    this.BaseValidatorObject(control, severity, errorMessage, align);
    this.enabled = (required != null) ? required : true;
    this.errorMessage = (errorMessage) ? errorMessage : "Field is required.";
}
RequiredValidatorObject.inherits(SIGI.Validation.BaseValidatorObject);
RequiredValidatorObject.prototype.validate = function() {
    if (this.enabled) {
        //TODO abstract this code...
        var value = this.getValue(this.control);
        if ((this.control.type) && (this.control.type.toLowerCase() == "radio"))
            value = $SIGIfind(this.control.id).get_group().get_value();
        if (value == null) {
            this.isValid = false;
        } else {
            this.isValid = (value.length > 0);
        }
        this.colorLabel();
    }
    return this.isValid;
}
SIGI.Validation.RequiredValidatorObject = RequiredValidatorObject;
RequiredValidatorObject = null;


function DataTypeValidatorObject(control, dataType, severity, errorMessage, align) {
    this.BaseValidatorObject(control, severity, errorMessage, align);
    this.dataType = (dataType) ? dataType : "string";
    this.errorMessage = (errorMessage) ? errorMessage : "DataType is invalid";
    this.cutOffYear = 2029;
    this.century = 2000;
    this.decimalchar = ".";
    this.groupchar = ",";
    this.digits = 2;
    this.dateorder = "mdy";
}

DataTypeValidatorObject.inherits(SIGI.Validation.BaseValidatorObject);
DataTypeValidatorObject.prototype.validate = function() {
    this.isValid = true;
    if (this.enabled) {
        var value;
        if (((this.control.className.toLowerCase().substring(0, 10) == "maskededit") && (this.control.parentElement.className.toLowerCase() == "calendarcontrol")) || ((this.control.className.toLowerCase().substring(0, 10) == "maskededit") && (this.dataType == "date")))
            value = $SIGIfind(this.control.id).get_textWithMask();
        else
            value = this.getValue(this.control);
        if (value) {
            if ((($SIGIfind(this.control.id)) && ($SIGIfind(this.control.id).get_text() != "")) || (!$SIGIfind(this.control.id))) {
                value = this.convert(value, this.dataType);
                this.isValid = (value == null) ? false : true;
            }
        }
        this.colorLabel();
    }
    return this.isValid;
}
DataTypeValidatorObject.prototype.convert = function(text, dataType) {
    if (text == null) {
        return null;
    }
    function GetFullYear(element, year) {
        return (year + parseInt(element.century)) - ((year < element.cutoffyear) ? 0 : 100);
    }
    var num, cleanInput, m, exp;
    switch (dataType) {
        case "integer":
            text = text.removeCommas();
            exp = /^\s*[-\+]?\d+\s*$/;
            if (text.match(exp) == null)
                return null;
            num = parseInt(text, 10);
            return (isNaN(num) ? null : num);
        case "double":
            text = text.removeCommas();
            exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + this.decimalchar + "(\\d+))?\\s*$");
            m = text.match(exp);
            if (m == null)
                return null;
            cleanInput = m[1] + (m[2].length > 0 ? m[2] : "0") + "." + m[4];
            num = parseFloat(cleanInput);
            return (isNaN(num) ? null : num);
        case "currency":
            text = text.removeCommas();
            exp = new RegExp("^\\s*([-\\+])?(((\\d+)\\" + this.groupchar + ")*)(\\d+)"
						+ ((this.digits > 0) ? "(\\" + this.decimalchar + "(\\d{1," + this.digits + "}))?" : "")
						+ "\\s*$");
            m = text.match(exp);
            if (m == null)
                return null;
            var intermed = m[2] + m[5];
            cleanInput = m[1] + intermed.replace(new RegExp("(\\" + this.groupchar + ")", "g"), "") + ((this.digits > 0) ? "." + m[7] : 0);
            num = parseFloat(cleanInput);
            return (isNaN(num) ? null : num);
        case "date":
            var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$");
            m = text.match(yearFirstExp);
            var day, month, year;
            if (m != null && (m[2].length == 4 || this.dateorder == "ymd")) {
                day = m[6];
                month = m[5];
                year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10))
            }
            else {
                if (this.dateorder == "ymd") {
                    return null;
                }
                var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
                m = text.match(yearLastExp);
                if (m == null) {
                    if (((text.length == 6) || (text.length == 8)) && (Number(text) > 0)) {
                        if (this.dateorder == "mdy") {
                            day = Number(text.substring(2, 4));
                            month = Number(text.substring(0, 2));
                        }
                        else {
                            day = Number(text.substring(0, 2));
                            month = Number(text.substring(2, 4));
                        }
                        year = Number(text.substring(4, 8));
                    }
                    else {
                        return null;
                    }
                }
                else {
                    if (this.dateorder == "mdy") {
                        day = m[3];
                        month = m[1];
                    }
                    else {
                        day = m[1];
                        month = m[3];
                    }
                    year = (m[5].length == 4) ? m[5] : GetFullYear(this, parseInt(m[6], 10));
                }
            }
            month -= 1;
            var date = new Date(year, month, day);
            return (typeof (date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
        default:
            return text.toString();
    }
}
DataTypeValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) {
    switch (propertyName) {
        case "type":
            this.dataType = propertyValue.qtrim().toLowerCase();
            break;
        default:
            this.BaseValidatorObject.prototype.handleProperty.apply(this, arguments);
    }
}
SIGI.Validation.DataTypeValidatorObject = DataTypeValidatorObject;
DataTypeValidatorObject = null;




function CompareValidatorObject(control, valueToCompare, dataType, severity, errorMessage, align) {
    this.DataTypeValidatorObject(control, dataType, severity, errorMessage, align);
    this.controlToCompare = null;
    this.valueToCompare = null;
    this.operator = "Equals"

    if (typeof (valueToCompare) == "object") {
        this.controlToCompare = valueToCompare;
    } else {
        if (valueToCompare) this.valueToCompare = valueToCompare;
    }
}
CompareValidatorObject.inherits(SIGI.Validation.DataTypeValidatorObject);
CompareValidatorObject.prototype.validate = function() {
    this.isValid = true;
    if (this.enabled != false) {
        var value = this.getValue(this.control);
        if (value != null) {
            if (value.trim().length == 0)
                return true;
            if (this.controlToCompare != null) {
                this.valueToCompare = this.getValue(this.controlToCompare);
            }
            if (this.valueToCompare != null && typeof (this.valueToCompare) == "string") {
                this.isValid = this.compare(value, this.valueToCompare, this.operator, this.dataType);
            }
        }
        this.colorLabel();
    }
    return this.isValid;
}
CompareValidatorObject.prototype.compare = function(leftText, rightText, operator, dataType) {
    var op1, op2;
    if ((op1 = this.convert(leftText, dataType)) == null)
        return false;
    if (operator == "DataTypeCheck")
        return true;
    if ((op2 = this.convert(rightText, dataType)) == null)
        return true;
    switch (operator) {
        case "NotEqual":
            return (op1 != op2);
        case "GreaterThan":
            return (op1 > op2);
        case "GreaterThanEqual":
            return (op1 >= op2);
        case "LessThan":
            return (op1 < op2);
        case "LessThanEqual":
            return (op1 <= op2);
        default:
            return (op1 == op2);
    }
}
CompareValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) {
    switch (propertyName) {
        case "compare":
            this.valueToCompare = propertyValue.qtrim();
            try {
                var element = document.getElementById(this.valueToCompare);
                if (element != null) this.controlToCompare = element;
            } catch (exc) { }
            break;
        case "operator":
            this.operator = propertyValue.qtrim();
            break;
        default:
            this.DataTypeValidatorObject.prototype.handleProperty.apply(this, arguments);
    }
}
SIGI.Validation.CompareValidatorObject = CompareValidatorObject;
CompareValidatorObject = null;





function RangeValidatorObject(control, minimumValue, maximumValue, dataType, severity, errorMessage, align) {
    this.CompareValidatorObject(control, null, dataType, severity, errorMessage, align);
    this.minimumValue = (minimumValue) ? minimumValue : null;
    this.maximumValue = (maximumValue) ? maximumValue : null;
    this.dataType = (dataType) ? dataType : "string";
}
RangeValidatorObject.inherits(SIGI.Validation.CompareValidatorObject);
RangeValidatorObject.prototype.validate = function() {
    this.isValid = true;
    if (this.enabled != false) {
        var value = this.getValue(this.control);
        if (value != "") {
            if (((this.control.className.toLowerCase().substring(0, 10) == "maskededit") && (this.control.parentElement.className.toLowerCase() == "calendarcontrol")) || ((this.control.className.toLowerCase().substring(0, 10) == "maskededit") && (this.dataType == "date"))) {
                value = $SIGIfind(this.control.id).get_textWithMask();
            }
        }
        if ((value != null) && (value.qtrim() != "")) {
            this.isValid = this.compare(value, this.minimumValue, "GreaterThanEqual", this.dataType);
            if (this.isValid) {
                this.isValid = this.compare(value, this.maximumValue, "LessThanEqual", this.dataType);
            }
        }
        this.colorLabel();
    }
    return this.isValid;
}
RangeValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) {
    switch (propertyName) {
        case "min":
            this.minimumValue = propertyValue.qtrim();
            break;
        case "max":
            this.maximumValue = propertyValue.qtrim();
            break;
        default:
            this.CompareValidatorObject.prototype.handleProperty.apply(this, arguments);
    }
}
SIGI.Validation.RangeValidatorObject = RangeValidatorObject;
RangeValidatorObject = null;



function RegularExpressionValidatorObject(control, expression, options, severity, errorMessage, align) {
    this.BaseValidatorObject(control, severity, errorMessage, align);
    this.errorMessage = (errorMessage) ? errorMessage : "Value is not formatted correctly";
    this.expression = (expression) ? expression : null;
    this.options = (options) ? options : "gi";
}
RegularExpressionValidatorObject.inherits(SIGI.Validation.BaseValidatorObject);
RegularExpressionValidatorObject.prototype.validate = function() {
    this.isValid = true;
    if (this.enabled) {
        var value = this.getValue(this.control);
        if (value) {
            var template = new RegExp(this.expression, this.options)
            this.isValid = template.test(value);
        }
        this.colorLabel();
    }
    return this.isValid;
}
RegularExpressionValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) {
    switch (propertyName) {
        case "expression":
            this.expression = propertyValue.qtrim();
            break;
        case "options":
            this.options = propertyValue.qtrim();
            break;
        default:
            this.BaseValidatorObject.prototype.handleProperty.apply(this, arguments);
    }
}
SIGI.Validation.RegularExpressionValidatorObject = RegularExpressionValidatorObject;
RegularExpressionValidatorObject = null;



function ValuesValidatorObject(control, values, severity, errorMessage, align) {
    this.BaseValidatorObject(control, severity, errorMessage, align);

    if (values)
        this.values = values;
    else
        this.values = new Array();
}
ValuesValidatorObject.inherits(SIGI.Validation.BaseValidatorObject);
ValuesValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) {
    switch (propertyName) {
        case "inlist":
            this.values = propertyValue.replace(/'/g, "").split(",");
            this.listType = "valid";
            break;
        case "notinlist":
            this.values = propertyValue.replace(/'/g, "").split(",");
            this.listType = "invalid";
            break;
        default:
            this.BaseValidatorObject.prototype.handleProperty.apply(this, arguments);
    }
}
ValuesValidatorObject.prototype.validate = function() {
    this.isValid = true;
    if (this.enabled) {
        var value = this.getValue(this.control);
        if (value) {
            if (this.listType == "valid") {
                this.isValid = false;
                for (var i = 0; i < this.values.length; i++) {
                    var leftText = this.values[i];
                    if (leftText) {
                        this.isValid = (leftText.toString().toLowerCase() == value.toString().toLowerCase())
                        if (this.isValid) return this.isValid;
                    }
                }
            }
            else {
                this.isValid = true;
                for (var i = 0; i < this.values.length; i++) {
                    var leftText = this.values[i];
                    if (leftText) {
                        this.isValid = !(leftText.toString().toLowerCase() == value.toString().toLowerCase())
                        if (!this.isValid) return this.isValid;
                    }
                }
            }
        }
        this.colorLabel();
    }
    return this.isValid;
}
SIGI.Validation.ValuesValidatorObject = ValuesValidatorObject;
ValuesValidatorObject = null;


function CustomValidatorObject(clientFunction, severity, errorMessage) {
    this.BaseValidatorObject(null, severity, errorMessage, null);
    this.clientFunction = (clientFunction) ? clientFunction : null;
}
CustomValidatorObject.inherits(SIGI.Validation.BaseValidatorObject);
CustomValidatorObject.prototype.validate = function() {
    if (this.enabled && (this.clientFunction != null)) {
        if ((typeof this.clientFunction == "string") && (window[this.clientFunction])) {
            this.clientFunction = window[this.clientFunction];
            this.isValid = SIGI.Convert.toBoolean(this.clientFunction());
        }
        else {
            if (typeof this.clientFunction == "string") {
                //special treatment for a string, break it into semi-colon function calls
                //assume this is the core validation, set it to true,
                //then fail if any single call fails
                //NOTE: never changing type from string to function,
                //allows it to run the same with each subsequent call
                this.isValid = true;
                var funcCalls = this.clientFunction.split("|||||")
                for (i = 0; i < funcCalls.length; i++) {
                    if (funcCalls[i] != "") {
                        if (!(eval(funcCalls[i]))) {
                            this.isValid = false;
                            continue;
                        }
                    }
                }
            }
            else {
                if (typeof this.clientFunction == "function") {
                    this.isValid = this.clientFunction();
                }
            }
        }
        this.colorLabel();
    }
    return this.isValid;

}
CustomValidatorObject.prototype.handleProperty = function(propertyName, propertyValue) {
    switch (propertyName) {
        case "client":
            this.clientFunction = propertyValue.qtrim();
            if (this.clientFunction.length > 0) {
                var scriptsToCheck = this.clientFunction.split("|||||");
                if (scriptsToCheck.length > 1) {
                    var evalResult = true;
                    var func;
                    for (var j = 0; j < scriptsToCheck.length; j++) {
                        //func = function() { eval(scriptsToCheck[j]) }
                        //if (!func()) {
                        if (scriptsToCheck[j] != "") {
                            if (!(eval(scriptsToCheck[j]))) {
                                evalResult = false;
                                break;
                            }
                        }
                    }
                    return evalResult;
                } else {
                    if (window[scriptsToCheck[j]]) {
                        this.clientFunction = window[scriptsToCheck[j]];
                    }
                }


            } else {
                this.clientFunction = null;
            }
            break;
        default:
            this.BaseValidatorObject.prototype.handleProperty.apply(this, arguments);
    }
}
SIGI.Validation.CustomValidatorObject = CustomValidatorObject;
CustomValidatorObject = null;



function ControlValidatorObject(control) {
    //    code to include controls tied to simple validators
    //    var svCtrl = controlForSV(control);
    //    if (svCtrl) {
    //        control = svCtrl;
    //    }
    this.BaseValidatorObject(control);
    this.StyleParser();
    this.validators = new Array();

    //to facilitate the handback of a seperate failing instance on validation failure
    this.alternateFailedValidator = null;

    if (this.control) {
        if (typeof (this.control.validation) == "string") {
            var validation = this.control.validation;
            if (validation) this.parseProperties(validation);
        }
        this.control.validationObject = this;
        this.control.attachEvent("onbeforedeactivate", SIGI.Validation.onbeforedeactivate);
    }
}
ControlValidatorObject.inherits(SIGI.Parsing.StyleParser);
ControlValidatorObject.inherits(SIGI.Validation.BaseValidatorObject);
ControlValidatorObject.prototype.setProperty = function(propertyName, value) {
    if (value) value = value.trim();
    var validator = null;
    switch (propertyName.toLowerCase()) {
        case "required":
            validator = new SIGI.Validation.RequiredValidatorObject(this.control);
            break;
        case "datatype":
            validator = new SIGI.Validation.DataTypeValidatorObject(this.control);
            break;
        case "compare":
            validator = new SIGI.Validation.CompareValidatorObject(this.control);
            break;
        case "range":
            validator = new SIGI.Validation.RangeValidatorObject(this.control);
            break;
        case "regularexpression":
            validator = new SIGI.Validation.RegularExpressionValidatorObject(this.control);
            break;
        case "values":
            validator = new SIGI.Validation.ValuesValidatorObject(this.control);
            break;
        case "custom":
            validator = new SIGI.Validation.CustomValidatorObject();
            break;
    }
    if (validator) {
        validator.parseProperties(value);
        this.validators.push(validator);
    }
}
ControlValidatorObject.prototype.validate = function() {

    /*
    Build list of Validator objects to run
    In default case it will be only this one
    If label indicates multiple controls to a label, including this one, validate all of them
    */
    var allValidators = new SIGI.CollectionObject();
    this.alternateFailedValidator = null;
    allValidators.add(this);
    //first check if the label is even set
    if (this.label) {
        //established that there is a label association, now verify that it ties to more than one label
        var ctrlNames = this.label.htmlFor.split(";");
        if (ctrlNames.length > 1) {
            //now loop through the control names
            for (var j = 0; j < ctrlNames.length; j++) {
                //and for each, not including the control for the current validator,
                if (ctrlNames[j] != this.control.id) {
                    //loop through validator and find an associated validator if any
                    for (var i = 0; i < SIGI.Validation.PageValidators.length; i++) {
                        if (SIGI.Validation.PageValidators[i].control) {
                            if (SIGI.Validation.PageValidators[i].control.id == ctrlNames[j]) {
                                allValidators.add(SIGI.Validation.PageValidators[i]);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    var retVal = true;
    for (var j = 0; j < allValidators.count(); j++) {
        if ((allValidators[j].control) && ((allValidators[j].control.disabled) || (allValidators[j].control.style.display == "none")) && (!toBoolean(allValidators[j].control.validateDisabled))) {
            allValidators[j].isValid = true;
        }
        else {
            //Replace previous line, disabling validation on hidden controls
            for (var i = 0; i < allValidators[j].validators.length; i++) {
                validator = allValidators[j].validators[i];
                if (validator) {
                    allValidators[j].isValid = validator.validate();
                    if (!allValidators[j].isValid) {
                        allValidators[j].align = validator.align;
                        allValidators[j].severity = validator.severity;
                        allValidators[j].errorMessage = validator.errorMessage;
                        allValidators[j].colorLabel();
                        retVal = false;
                        if (allValidators[j] != this) {
                            this.alternateFailedValidator = allValidators[j];
                        }
                        break;
                    }
                }
            }
        }
        //might drop this part - fail out and only provide one failed validator
        if (!retVal) {
            break;
        }
    }
    if (retVal && this.label) {
        this.colorLabel();
    }
    return retVal;
}
SIGI.Validation.ControlValidatorObject = ControlValidatorObject;
ControlValidatorObject = null;


