// CustomValidator Client Functions
function ValidateMaxLength(sender, args) {
    //N.B. Multiline rendered as TextArea with no MaxLength property - simply set on Validator control
    //Unused - (would be neat but not rendered by TextArea so useless)... var TargetControl = $get(sender.controltovalidate);
    var TextLength = args.Value.length;
    if (TextLength > sender.MaxLength) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

//Only used by:
//AbstractDetails.aspx (CustomValidatorMaxLength_AbstractTitle)
//AbstractWizard.aspx (CustomValidatorMaxLength_AbstractTitle)
//QuestionControl.ascx (CustomValidatorMaxLength)

//NOTE ALSO USED IN DOCUMENT FEEDBACK !!!!
//
//TODO: Rewrite to use above ValidateMaxLength with MaxLength expando attribute on Validator
function ValidateMaxLength_500(sender, args) {
    var TextLength = args.Value.length;
    if (TextLength > 500) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

function ValidateMaxLength_2000(sender, args) {
    var TextLength = args.Value.length;
    if (TextLength > 2000) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

//TODO: Rewrite to use sender.controltovalidate
function ValidateCheckBoxList(sender, args) {
    //sender is the customvalidator - need the clientid of the actual target control (expando property of validator set by codebehind)
    //This is much better way of getting TargetControl:
    //var TargetControl = $get(sender.controltovalidate);
    var HiddenFieldJSON_ChecklistClientData = $get(HiddenFieldJSON_ChecklistClientDataClientID);
    if (HiddenFieldJSON_ChecklistClientData != null) {
        var objCheckBoxList = $get(HiddenFieldJSON_ChecklistClientData.value);
        if (objCheckBoxList != null) {
            for (var i = 0; i <= objCheckBoxList.rows.length - 1; i++) {
                if (objCheckBoxList.rows[i].cells[0].childNodes[0].checked != true) {
                    args.IsValid = false;
                    return;
                }
            }
        } 
    }
    args.IsValid = true;
}