﻿function getFieldDiv(source) {
    return jQuery('#' + source.id).parent();
}

function getControls(control, source) {
    fieldDiv = getFieldDiv(source);
    if (fieldDiv[0].style.display == 'none') {
        return new Array();
    }
    div = 'dd' + '#' + fieldDiv.attr('id');
    return jQuery(div + ' ' + control);
}

function validateRadioButtons(source, args) {
    inputs = getControls('input', source);
    if (inputs.length) {
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].checked) {
                args.IsValid = true;
                return;
            }
        }
        args.IsValid = false;
    }
}

function validateCheckboxes(source, args) {
    inputs = getControls('input', source);
    if (inputs.length) {
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].checked) {
                args.IsValid = true;
                return;
            }
        }
        args.IsValid = false;
    }
}


function validateSelectRequired(source, args) {
    selects = getControls('input', source);
    if (selects.length > 0) {
        valid = true;
        for (var i = 0; i < selects.length; i++) {
            if (selects[i].value.length == 0) {
                valid = false;
                break;
            }
        }
        args.IsValid = valid;
    }
}
