﻿// Disables all the controls supplied in the "controls" array
function DisableControls (controls, disable)
    {
        for (i=0; i < controls.length; i++)
        {
            var control = document.getElementById(controls[i]);
            control.enabled = !disable;
            control.disabled = disable;
            if (control.tagName == "INPUT")
            {
                if (control.type == "text")
                {
                    if (disable)
                    {
                        control.className = "inptTxt disabled";
                        control.value = "";
                    }
                    else
                        control.className = "inptTxt norm";
                }
                else if (control.type == "radio")
                {
                    if (disable)
                        control.checked = false;
                }
            }
            // if disable = true, check for inner controls to reset theyr values
            else
            {
                var childControls = control.getElementsByTagName('input');
                if (childControls.length > 0)
                {
                    for (j=0; j < childControls.length; j++)
                    {
                        childControls[j].enabled = !disable;
                        childControls[j].disabled = disable;
            
                        if (disable)
                        {
                            if (childControls[j].tagName == "INPUT" && childControls[j].type == "text")
                                childControls[j].value = "";
                            else if (childControls[j].tagName == "INPUT" && childControls[j].type == "radio")
                                childControls[j].checked = false;
                        }
                    }
                }
            }
        }
    }

    // DateInterval control
    function DateIntervalMessage(msgLabel, dateFrom, dateTill, strings) {
        var tMsgLabel = document.getElementById(msgLabel);
        var tDateFrom = document.getElementById(dateFrom);
        var tDateTill = document.getElementById(dateTill);

        var toolTipText = "";

        if (tDateFrom.value != "" && tDateTill.value != "")
            toolTipText = tDateFrom.value + " - " + tDateTill.value;
        else if (tDateFrom.value != "" && tDateTill.value == "")
            toolTipText = strings[2] + " " + tDateFrom.value;
        else if (tDateFrom.value == "" && tDateTill.value != "")
            toolTipText = strings[3] + " " + tDateTill.value;

        if (toolTipText == "") {
            //tMsgLabel.firstChild.data = strings[0];
            tMsgLabel.value = strings[0];
            tMsgLabel.title = "";
        }
        else {
            //tMsgLabel.firstChild.data = strings[1];
            tMsgLabel.value = strings[1];
            tMsgLabel.title = toolTipText;
        }
    }
