﻿function ShowOtherTextBox(clientID, value, otherID) {
    var control = $get(clientID);
    for (var h = 0; h < control.rows.length; h++) {
        for (i = 0; i < control.rows[h].cells.length; i++) {
            var cell = control.rows[h].cells[i];
            if (cell.innerText == value || cell.textContent == value) {
                for (j = 0; j < cell.childNodes.length; j++) {
                    if (cell.childNodes[j].type == "checkbox" || cell.childNodes[j].type == "radio") {
                        var otherControl = $get(otherID);
                        if (otherControl != null) {
                            otherControl.style.display = cell.childNodes[j].checked ? "block" : "none";
                            //Re-position the control if applicable.
                            if (typeof (GetAbsX) == 'function') {
                                otherControl.parentNode.style.marginLeft = GetAbsX(cell) + "px";
                            }
                        }
                    }
                }
            }
        }
    }
}

function ToggleMiniContactProfileVisibility(senderID, bodyID) {
    var control = $get(senderID);

    if (control != null) {
        //Parse through the body of the control, and disable all textbox, dropdownlists, buttons, checkboxes, etc.
        var inputs = $get(bodyID).getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == "text") {
                inputs[i].disabled = control.checked;
                inputs[i].value = control.checked ? "" : "";
            }
            else if (inputs[i].type == "radio") {
                inputs[i].disabled = control.checked;
                inputs[i].checked = false;
            }
        }
        //We also need to disable the validators of those controls
        var validators = $get(bodyID).getElementsByTagName("span");
        for (var i = 0; i < validators.length; i++) {
            var val = FindValidator(validators[i].id)
            if (val != null) {
                val.enabled = !control.checked;

                if (control.checked) {
                    ValidatorValidate(val);
                }
            }
        }
    }
}

function FindValidator(validatorID) {
    for (var i = 0; i < Page_Validators.length; i++) {
        if (Page_Validators[i].id == validatorID) {
            return Page_Validators[i];
            break;
        }
    }
}

function ShowConfirmDialog(msg) {
    if (confirm(msg)) {
        return true;
    }
    else {
        return false;
    }
}

function positionUpdateProgress() {
    // get the update progress div
    var updateProgressDiv = $get('updateProgressDiv');

    // get the bounds of both the element and the progress div
    var elementBounds = Sys.UI.DomElement.getBounds($get('masterDiv'));

    //  center of element
    var x = elementBounds.x + Math.round(elementBounds.width / 2) - 65;
    var y = elementBounds.y + 150;

    //	set the progress element to this position
    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
}
