var gridName;
var ControlPrefix; // Holds the Control prefix 
var chkSingleControl; // Holds the Control Sufix
var hdnIdHolder; // Holds the hidden field which contains the ID of the data key
var hdnSelectedIDList; // Holds the hidden field to which the selected IDs has to be there
var chkSelectAll // Holds the select all Check boxes.
var schedulingControl; // Holds the control for scheduling
function DevExpressGridCheckAll(type, gvName) {
    var pageIndex = 0;
    if (type == 1) {
        var gv = document.getElementById("tcManageMDT_tpMDTMessages_" + gvName);
        if (gv != null) {
            pageIndex = gvPreCannedMsgs.cpPageIndex * 5;
            chkSelectAll = 'tcManageMDT_tpMDTMessages_' + gvName + '_header0_chkSelectAllMsgs';
            controlPrefix = 'tcManageMDT_tpMDTMessages_' + gvName + '_cell';
            chkSingleControl = '_0_chkMsgs';
            hdnIdHolder = '_1_hdnMsgId';
            hdnSelectedIDList = 'hdnSelectedMsgIds';
            //            if (document.getElementById('hdnSelectedMsgIds') != null)
            //                document.getElementById('hdnSelectedMsgIds').value = "";
        }
        else {
            var gv = document.getElementById("tcManageMDT_tpMDTUsers_" + gvName);
            if (gv != null) {
                pageIndex = gvMDTUsers.cpPageIndex * 5;
                chkSelectAll = 'tcManageMDT_tpMDTUsers_' + gvName + '_header0_chkSelectAllUsers';
                controlPrefix = 'tcManageMDT_tpMDTUsers_' + gvName + '_cell';
                chkSingleControl = '_0_chkUser';
                hdnIdHolder = '_1_hdnUserId';
                hdnSelectedIDList = 'hdnSelectedMsgIds';
                //                if (document.getElementById('hdnSelectedMsgIds') != null)
                //                    document.getElementById('hdnSelectedMsgIds').value = "";
            }
        }

    }
    var elementID = document.getElementById(chkSelectAll);
    var i = pageIndex;
    var str = controlPrefix + i + hdnIdHolder;
    var str1 = controlPrefix + i + chkSingleControl;
    var hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
    var dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
    var hidden = document.getElementById(hdnSelectedIDList);
    while (dataRowCheckBox != null) {
        if (dataRowCheckBox.disabled) {
            if (gv == "gvMDTUsers")
                alert('Already this vehicle have 10 users.');
            else
                alert('Already this vehicle have 10 messages.');
            elementID.checked = false;
            break;
        }
        var test = hidden.value.split(",");
        if (((test.length - 1) < 5) || (elementID.checked == false)) {
            dataRowCheckBox.checked = elementID.checked;
            if ((hiddenField != null)) {
                CheckListOfIDs(dataRowCheckBox, hdnSelectedIDList, hiddenField.value);
            }
            i++;
            dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
            hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
        }
        else {
            alert('Maximum 5 details can be select at a time.');
            elementID.checked = false;
            break;
        }
    }
}

function CheckListOfIDs(checkBoxItem, hiddenfieldname, ID) //selectAllCheckBox, checkbxPrefix, checkbxSufix)
{
    var isIE = CheckBrowser();
    var hiddenField = document.getElementById(hiddenfieldname);
    var i = 2;
    var test = hiddenField.value.split(",");
    if ((test.length - 1) < 5) {
        if (Array.contains(test, ID)) {
            if (!checkBoxItem.checked) {
                Array.remove(test, ID);
            }
        }
        else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            if (test[test.length - 1] == "") {
                Array.insert(test, test.length - 1, ID);
            }
            else {
                Array.add(test, ID);
            }
        }
        hiddenField.value = test.join(",");
    }
    else {
        if (!checkBoxItem.checked) {
            Array.remove(test, ID);
            hiddenField.value = test.join(",");
        }
        else {
            alert('Maximum 5 details can be select at a time.');
            checkBoxItem.checked = false;
        }
    }
}

function CheckListOfServiceIDs(checkBoxItem, hiddenfieldname, hdnName, type) //selectAllCheckBox, checkbxPrefix, checkbxSufix)
{
    var isIE = CheckBrowser();
    var hiddenField = document.getElementById(hiddenfieldname);
    var i = 2;
    if (hdnName == "hdnUserId")
        var str = "chkUser";
    else
        str = "chkMsgs";
    var ID = document.getElementById(checkBoxItem.id.replace("_0_" + str, "_1_" + hdnName)).value;
    var test = hiddenField.value.split(",");
    if ((test.length - 1) < 5) {
        if (Array.contains(test, ID)) {
            if (!checkBoxItem.checked) {
                Array.remove(test, ID);
            }
        }
        else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            if (test[test.length - 1] == "") {
                Array.insert(test, test.length - 1, ID);
            }
            else {
                Array.add(test, ID);
            }
        }
        hiddenField.value = test.join(",");
    }
    else {
        if (!checkBoxItem.checked) {
            Array.remove(test, ID);
            hiddenField.value = test.join(",");
        }
        else {
            alert('Maximum 5 details can be select at a time.');
            checkBoxItem.checked = false;
            return false;
        }
    }
}

function DevExpressGridCheckOrUnCheckSelectAll(type) {
    var isIE = CheckBrowser();

    if (type == 1) {
        chkSelectAll = 'tcManageMDT_tpMDTMessages_gvPreCannedMsgs_header0_chkSelectAllMsgs';
        controlPrefix = 'tcManageMDT_tpMDTMessages_gvPreCannedMsgs_cell'
        chkSingleControl = '_0_chkMsgs';
        hdnIdHolder = '_1_hdnMsgId';
        hdnSelectedIDList = 'hdnSelectedMsgIds';
    }

    var selectAllCheckbox = document.getElementById(chkSelectAll);
    var checkedItems = 0;
    var i = 0;
    var visibleCount = 0;
    var dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    while (dataRowCheckbox != null) {

        if (dataRowCheckbox.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            visibleCount++;
        }
        if (dataRowCheckbox.checked) {
            checkedItems++;
        }

        //        if (dataRowCheckbox.checked) checkedItems++;
        i++;
        dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    }
    if (selectAllCheckbox != null) {
        if (checkedItems == visibleCount && visibleCount > 0) {//if (checkedItems == i) {
            selectAllCheckbox.checked = true;
        }
        else {
            selectAllCheckbox.checked = false;
        }
    }
}

function CheckAssigned(id) {
    //alert(id.name);
    if (id.name.toString() == "0-DeleteUser") {
        if (id.name == "0-DeleteUser") {
            alert('Assiged User cannot be deleted.');
            return false;
        }
        else {
            return confirm('do you want to really delete this User.');
        }
    }
    else if (id.name.toString() == "0-EditUser") {
        if (id.name == "0-EditUser") {
            alert('Assiged User cannot be edited.');
            return false;
        }
        else {
            return true;
        }
    }
    else if (id.name.toString() == "0-DeleteMsg") {
        if (id.name == "0-DeleteMsg") {
            alert('Assiged message cannot be deleted.');
            return false;
        }
        else {
            return confirm('do you want to really delete this message.');
        }
    }
    else if (id.name.toString() == "0-EditMsg") {
        if (id.name == "0-EditMsg") {
            alert('Assiged Message cannot be edited.');
            return false;
        }
        else {
            return true;
        }
    }
    else {
        if (id.name.toString() == "1-DeleteUser") {
            return confirm('Continue deleting the user?');
        }
        else if (id.name.toString() == "1-DeleteMsg") {
            return confirm('Continue deleting the message?');
        }
        else {
            return true;
        }
    }
}


function ClearValue() {
    if (document.getElementById('hdnSelectedMsgIds') != null)
        document.getElementById('hdnSelectedMsgIds').value = "";
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtServerMsg") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtServerMsg").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtServerMsg").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtServerMsg").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeviceMsg") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeviceMsg").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtDeviceMsg").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtDeviceMsg").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtAddMDTMsg") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtAddMDTMsg").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtAddMDTMsg").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtAddMDTMsg").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsg") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsg").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsg").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsg").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsgTable") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsgTable").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsgTable").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsgTable").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtAddServerMsg") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtAddServerMsg").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtAddServerMsg").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtAddServerMsg").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtAddDeviceMsg") != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtAddDeviceMsg").checked)
            document.getElementById("tcManageMDT_tpMDTMessages_rbtAddDeviceMsg").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTMessages_rbtAddDeviceMsg").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTUsers_rbtAddMDTUser") != null) {
        if (document.getElementById("tcManageMDT_tpMDTUsers_rbtAddMDTUser").checked)
            document.getElementById("tcManageMDT_tpMDTUsers_rbtAddMDTUser").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTUsers_rbtAddMDTUser").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUser") != null) {
        if (document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUser").checked)
            document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUser").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUser").disabled = false;
    }
    if (document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUserTable") != null) {
        if (document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUserTable").checked)
            document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUserTable").disabled = true;
        else
            document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUserTable").disabled = false;
    }

}
function RemoveCmdStatus() {
    if (document.getElementById("tcManageMDT_tpMDTMessages_divMsg") != null)
        document.getElementById("tcManageMDT_tpMDTMessages_divMsg").innerHTML = "";
    if (document.getElementById("tcManageMDT_tpMDTUsers_divUserMsg") != null)
        document.getElementById("tcManageMDT_tpMDTUsers_divUserMsg").innerHTML = "";
    if (document.getElementById("tcManageMDT_tpMDTForms_divFormMsg") != null)
        document.getElementById("tcManageMDT_tpMDTForms_divFormMsg").innerHTML = "";
}
function ClearSchedule() {
    if (document.getElementById("IsScheduleCmds") != null)
        document.getElementById("IsScheduleCmds").value = "false";
}
function ShowOrHideMDTMsgType() {
    var isIE = CheckBrowser();
    var rbtPrecanned;
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    rbtPrecanned = document.getElementById("tcManageMDT_tpMDTMessages_rbtPrecanned");
    if (rbtPrecanned != null) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_divMsg") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_divMsg").innerHTML = "";
        if (rbtPrecanned.checked == true) {
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg").className = "ControlShow";
            if (document.getElementById("tcManageMDT_tpMDTMessages_txtMDTMessage") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_txtMDTMessage").value = '';
        }
        else {
            if (document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_txtMDTMessage") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_txtMDTMessage").value = "";
        }
    }
    else if (document.getElementById("tcManageMDT_tpMDTMessages_rbtServerMsg") != null) {
        {
            if (document.getElementById("tcManageMDT_tpMDTMessages_rbtServerMsg").checked) {
                document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = "ControlHide";
            }

        }
    }
}
function CancelMsgSend() {
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    if (index == 0) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails") != null) {
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = (isIE ? "ControlShow" : "ControlShow");
        }
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation") != null) {
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation").className = "ControlHide";
        }
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg") != null) {
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = "ControlHide";
        }
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null) {
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
        }
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons") != null) {
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons").className = "ControlHide";
        }
    }
    else if (index == 2) { //Sakthi cancel schedule
        if (document.getElementById("tcManageMDT_tpMDTForms_txtTitle") != null)
            document.getElementById("tcManageMDT_tpMDTForms_txtTitle").value = '';
        if (document.getElementById("tcManageMDT_tpMDTForms_txtQuestion") != null)
            document.getElementById("tcManageMDT_tpMDTForms_txtQuestion").value = '';
        if (document.getElementById("tcManageMDT_tpMDTForms_txtLine1") != null)
            document.getElementById("tcManageMDT_tpMDTForms_txtLine1").value = '';
        if (document.getElementById("tcManageMDT_tpMDTForms_txtLine2") != null)
            document.getElementById("tcManageMDT_tpMDTForms_txtLine2").value = '';
        if (document.getElementById("tcManageMDT_tpMDTForms_txtLine3") != null)
            document.getElementById("tcManageMDT_tpMDTForms_txtLine3").value = '';
        if (document.getElementById("tcManageMDT_tpMDTForms_UPanelMDTForms") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_UPanelMDTForms").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTForms_pnlAddFormMsg") != null)
                document.getElementById("tcManageMDT_tpMDTForms_pnlAddFormMsg").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTForms_pnlFormsMsg") != null)
                document.getElementById("tcManageMDT_tpMDTForms_pnlFormsMsg").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTForms_pnlFormsSendCmd") != null)
                document.getElementById("tcManageMDT_tpMDTForms_pnlFormsSendCmd").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTForms_pnlFormMsgCmd") != null)
                document.getElementById("tcManageMDT_tpMDTForms_pnlFormMsgCmd").className = "ControlHide";

        }
    }
    else {
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails") != null) {
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = (isIE ? "ControlShow" : "ControlShow");
        }
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation") != null) {
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = "ControlHide";
        }
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers") != null) {
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = "ControlHide";
        }
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd") != null) {
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd").className = "ControlHide";
        }
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons") != null) {
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons").className = "ControlHide";
        }
    }
    return false;
}
function ShowOrHideMDTMsgTableFields() {
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    ShowPopUp();
    var isIE = CheckBrowser();
    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsgTable") != null) {
        document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = (isIE ? "ControlShow" : "ControlShow");
        //document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = "ControlHide";          
        if (document.getElementById("tcManageMDT_tpMDTMessages_rbtDeleteMDTMsgTable").checked) {
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
        }

    }
}



function CheckTapPanel() {
    if ($find('tcManageMDT') != null) {
        var index = $find('tcManageMDT').get_activeTabIndex();
        document.getElementById('hdnActiveTab').value = index;
    }
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    var isIE = CheckBrowser();
    if (index == 0) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value = "0";
        if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
        if (document.getElementById("tcManageMDT_tpMDTMessages_divMsg") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_divMsg").innerHTML = "";
        if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCannedMsg") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_ddlCannedMsg").value = "-Select-";
    }
    else if (index == 2) {
        //Sakthi
        if (document.getElementById("tcManageMDT_tpMDTForms_ddlForms_Command") != null)
            document.getElementById("tcManageMDT_tpMDTForms_ddlForms_Command").value = "-1";
        //        if (document.getElementById("tcManageMDT_tpMDTForms_trMDTQuestion") != null)
        //            document.getElementById("tcManageMDT_tpMDTForms_trMDTQuestion").className = (isIE ? "ControlHide" : "ControlHide");
        //        if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTitle") != null)
        //            document.getElementById("tcManageMDT_tpMDTForms_trMDTTitle").className = (isIE ? "ControlHide" : "ControlHide");
        if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates") != null)
            document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates").className = (isIE ? "ControlHide" : "ControlHide");
        if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1") != null)
            document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1").className = (isIE ? "ControlHide" : "ControlHide");
        if (document.getElementById("tcManageMDT_tpMDTForms_divFormMsg") != null)
            document.getElementById("tcManageMDT_tpMDTForms_divFormMsg").innerHTML = "";
    }
    else {
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
        if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value = "0";
        if (document.getElementById("tcManageMDT_tpMDTUsers_divUserMsg") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_divUserMsg").innerHTML = "";

    }
    ClearValue();
    return false;
}

function AddMsgAndUser() {
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;

    if (index == 0) {
        document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation").className = (isIE ? "ControlShow" : "ControlShow");
        document.getElementById("tcManageMDT_tpMDTMessages_txtCannedMsg").value = "";
    }
    else if (index == 2) {
        document.getElementById("tcManageMDT_tpMDTForms_pnlFormsMsg").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTForms_pnlAddFormMsg").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTForms_txtTitle") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_txtTitle").value = "";
        }
        if (document.getElementById("tcManageMDT_tpMDTForms_txtQuestion") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_txtQuestion").value = "";
        }
        if (document.getElementById("tcManageMDT_tpMDTForms_txtLine1") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_txtLine1").value = "";
        }
        if (document.getElementById("tcManageMDT_tpMDTForms_txtLine2") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_txtLine2").value = "";
        }
        if (document.getElementById("tcManageMDT_tpMDTForms_txtLine3") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_txtLine3").value = "";
        }
        if (document.getElementById("tcManageMDT_tpMDTForms_rdbSingle") != null) {
            document.getElementById("tcManageMDT_tpMDTForms_rdbSingle").checked = true;
        }
    }
    else {
        document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = (isIE ? "ControlShow" : "ControlShow");
        document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserId").value = "";
        document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserName").value = "";
        document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserPassword").value = "";
    }
    return false;
}
function CancelAddUserMsg() {
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    if (index == 0) {
        document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = (isIE ? "ControlShow" : "ControlShow");
        document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation").className = "ControlHide";
    }
    else {
        document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = (isIE ? "ControlShow" : "ControlShow");
        document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = "ControlHide";
    }
    return false;
}
function CheckMsgCmds() {
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else if (document.getElementById('hdnActiveTab').value == "2")
        index = 2;
    else
        index = 1;
    if (index == 0) {
        var val = document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value;
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation").className = "ControlHide";
        if (val == "0") {
            SendUserAndMsg();
        }
        else {
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = (isIE ? "ControlShow" : "ControlShow");
            if (val == "&") {
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTable") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTable").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTableOpr") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTableOpr").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMessage") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTMessage").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTAlert") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTAlert").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
                if (document.getElementById("tcManageMDT_tpMDTMessages_rbtPrecanned") != null) {
                    if (document.getElementById("tcManageMDT_tpMDTMessages_rbtPrecanned").checked) {
                        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg") != null)
                            document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg").className = (isIE ? "ControlShow" : "ControlShow");
                        if (document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages") != null)
                            document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = "ControlHide";
                    }
                    else {
                        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg") != null)
                            document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg").className = "ControlHide";
                        if (document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages") != null)
                            document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = (isIE ? "ControlShow" : "ControlShow");
                    }
                }
            }
            else if (val == "D") {
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMessage") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTMessage").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTAlert") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTAlert").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTable") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTable").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTableOpr") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTableOpr").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
                ShowOrHideMDTMsgTableFields();
            }
            else if (val == "c") {
                SendUserAndMsg();
                if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value = "c";
                if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
            }
            else if (val == "a") {
                SendUserAndMsg();
                if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value = "a";
                if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
            }
        }
    }
    else if (index == 2) { //MDT Form messages - Sakthi 13-Aug-2012
        var val = document.getElementById("tcManageMDT_tpMDTForms_ddlForms_Command").value;
        if (document.getElementById("tcManageMDT_tpMDTForms_UPanelMDTForms") != null)
            document.getElementById("tcManageMDT_tpMDTForms_UPanelMDTForms").className = "ControlShow";
        if (val == "14") {
            if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates") != null)
                document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate") != null)
                document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate").value = "-1";
            if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1") != null)
                document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1").className = (isIE ? "ControlHide" : "ControlHide");
            if (document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate1") != null)
                document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate1").value = "-1";
        }
        else if (val == "24") {
            if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates") != null)
                document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates").className = (isIE ? "ControlHide" : "ControlHide");
            if (document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate") != null)
                document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate").value = "-1";
            if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1") != null)
                document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate1") != null)
                document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate1").value = "-1";
        }
        else if (val == "34" || val == "-1") {
            if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates") != null)
                document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates").className = (isIE ? "ControlHide" : "ControlHide");
            if (document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1") != null)
                document.getElementById("tcManageMDT_tpMDTForms_trMDTTemplates1").className = (isIE ? "ControlHide" : "ControlHide");
        }
        if (document.getElementById("tcManageMDT_tpMDTForms_divFormMsg") != null)
            document.getElementById("tcManageMDT_tpMDTForms_divFormMsg").InnerHtml = "";
    }
    else {
        var val = document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value;
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_divUserMsg") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_divUserMsg").InnerHtml = "";
        if (val == "0") {
            SendUserAndMsg();
        }
        else {
            if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons") != null)
                document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails") != null)
                document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers") != null)
                document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable") != null)
                document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable").className = "ControlHide";
            if (val == "L") {
                if (document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd").className = (isIE ? "ControlShow" : "ControlShow");
                if (document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUserTable") != null)
                    if (document.getElementById("tcManageMDT_tpMDTUsers_rbtDeleteMDTUserTable").checked)
                    if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd") != null)
                    document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd").className = "ControlHide";
                if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands") != null)
                    document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value = "0";


            }
        }
    }
}
function SendUserAndMsg() {
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    if (index == 0) {
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsg").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMessage") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trMDTMessage").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTAlert") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trMDTAlert").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trServerMessages").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTable") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTable").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTableOpr") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trMDTMsgTableOpr").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trMDTCannedMsg").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageDetails").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlSendMsgcmd").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMsgCmdButtons").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTMessages_trSendCmd") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_trSendCmd").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlMessageInformation").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands") != null)
            document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands").value = "0";
    }
    else {
        document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = (isIE ? "ControlShow" : "ControlShow");
        document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = (isIE ? "ControlShow" : "ControlShow");
        document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = "ControlHide";

        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsers").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_trMDTUserTable").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserDetails").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlSendUsercmd").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserButtons").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTUsers_trSendUserCmd") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_trSendUserCmd").className = (isIE ? "ControlShow" : "ControlShow");
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlUserInformation").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_pnlScheduleUserCmds") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_pnlScheduleUserCmds").className = "ControlHide";
        if (document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands") != null)
            document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands").value = "0";
    }
    return false;
}

function CancelScheduleUserMsg() {
    //    if (document.getElementById('hdnSelectedMsgIds') != null)
    //        document.getElementById('hdnSelectedMsgIds').value = "";
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    if (index == 0) {
        document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTMessages_trSendCmd").className = (isIE ? "ControlShow" : "ControlShow");

    }
    else if (index == 2) {
        document.getElementById("tcManageMDT_tpMDTForms_pnlFormMsgCmd").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTForms_tblFormsSendCmd").className = (isIE ? "ControlShow" : "ControlShow");
    }
    else {
        document.getElementById("tcManageMDT_tpMDTUsers_pnlScheduleUserCmds").className = "ControlHide";
        document.getElementById("tcManageMDT_tpMDTUsers_trSendUserCmd").className = (isIE ? "ControlShow" : "ControlShow");
    }
    return false;
}

function ScheduleUserMsg() {
    var isIE = CheckBrowser();
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    if (index == 0) {
        if (ValidateSendCmd()) {
            if (document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_pnlScheduleCmds").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTMessages_trSendCmd") != null)
                document.getElementById("tcManageMDT_tpMDTMessages_trSendCmd").className = "ControlHide";
        }
    }
    else if (index == 2) {
        //Sakthi Schedule
        if (ValidateSendCmd()) {
            if (document.getElementById("tcManageMDT_tpMDTForms_tblFormsSendCmd") != null)
                document.getElementById("tcManageMDT_tpMDTForms_tblFormsSendCmd").className = "ControlHide";
            if (document.getElementById("tcManageMDT_tpMDTForms_pnlFormMsgCmd") != null)
                document.getElementById("tcManageMDT_tpMDTForms_pnlFormMsgCmd").className = (isIE ? "ControlShow" : "ControlShow");
        }
    }
    else {
        if (ValidateSendCmd()) {
            if (document.getElementById("tcManageMDT_tpMDTUsers_pnlScheduleUserCmds") != null)
                document.getElementById("tcManageMDT_tpMDTUsers_pnlScheduleUserCmds").className = (isIE ? "ControlShow" : "ControlShow");
            if (document.getElementById("tcManageMDT_tpMDTUsers_trSendUserCmd") != null)
                document.getElementById("tcManageMDT_tpMDTUsers_trSendUserCmd").className = "ControlHide";
        }
    }
    HidePopUp();
    return false;
}

function ValidateSendCmd() {
    ShowPopUp();
    ClearSchedule();
    var ddlCommands = document.getElementById("tcManageMDT_tpMDTMessages_ddlCommands");
    var ddlUserCommands = document.getElementById("tcManageMDT_tpMDTUsers_ddlUserCommands");
    var ddlFormCommands = document.getElementById("tcManageMDT_tpMDTForms_ddlForms_Command");
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    var alertmsg = "";
    if (index == 0) {


        if (ddlCommands != null) {
            if (ddlCommands.value == '0') {
                alertmsg = 'Please select the command.\n';
                ddlCommands.style.backgroundColor = 'lightyellow';
                ddlCommands.focus();
            }
            else {
                ddlCommands.style.backgroundColor = 'white';
            }
            if (ddlCommands.value == "&") {
                var rbtNormal = document.getElementById("tcManageMDT_tpMDTMessages_rbtNormal");
                if (rbtNormal.checked) {
                    var txtMDTMessage = document.getElementById("tcManageMDT_tpMDTMessages_txtMDTMessage");
                    if (RemoveSpaces(txtMDTMessage).length == 0) {
                        alertmsg = alertmsg + 'Please enter the message.\n';
                        txtMDTMessage.style.backgroundColor = 'lightyellow';
                        if (alertmsg.length == 0)
                            txtMDTMessage.focus();
                    }
                    else {
                        txtMDTMessage.style.backgroundColor = 'white';
                    }
                }
                else {
                    var ddlCannedMsg = document.getElementById("tcManageMDT_tpMDTMessages_ddlCannedMsg");
                    if (ddlCannedMsg.value == "-Select-") {
                        alertmsg = alertmsg + 'Please select the message.\n';
                        ddlCannedMsg.style.backgroundColor = 'lightyellow';
                        if (alertmsg.length == 0)
                            ddlCannedMsg.focus();
                    }
                    else {
                        ddlCannedMsg.style.backgroundColor = 'white';
                    }
                }
            }
            if (ddlCommands.value == "D") {
                if (document.getElementById('tcManageMDT_tpMDTMessages_rbtAddMDTMsg').checked) {
                    if (document.getElementById('hdnSelectedMsgIds').value.length == 0) {
                        alertmsg = alertmsg + 'Please select the Message(s).\n';
                    }
                }
                if (document.getElementById('tcManageMDT_tpMDTMessages_rbtDeleteMDTMsg').checked) {
                    if (document.getElementById('hdnSelectedMsgIds').value.length == 0) {
                        alertmsg = alertmsg + 'Please select the Message(s).\n';
                    }
                }
            }
        }
    }
    else if (index == 2) {
        if (ddlFormCommands != null) {
            if (ddlFormCommands.value == '-1') {
                alertmsg = 'Please select the operation.\n';
                ddlFormCommands.style.backgroundColor = 'lightyellow';
                ddlFormCommands.focus();
            }
            else if (ddlFormCommands.value == '14') {
                var ddlFormMsgCode = document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate");
                var hdnFormAssignedCnt = document.getElementById("hdnFormAssigned");
                if (ddlFormMsgCode != null && ddlFormMsgCode.value == "-1") {
                    alertmsg = 'Please select the form message.\n';
                }
                else if (hdnFormAssignedCnt != null && hdnFormAssignedCnt.value == 10) {
                    alertmsg = 'Maximum assigned 10 forms for each vehicle.\n';
                }
                //                var ddlFormTitle = document.getElementById("tcManageMDT_tpMDTForms_txtTitle");
                //                var ddlFormQuestion = document.getElementById("tcManageMDT_tpMDTForms_txtQuestion");
                //                if (ddlFormTitle != null && ddlFormTitle.value.length == 0) {
                //                    alertmsg = 'Please set the title.\n';
                //                }
                //                if (ddlFormQuestion != null && ddlFormQuestion.value.length == 0) {
                //                    alertmsg = alertmsg + 'Please set the question.\n';
                //                }
            }
            else if (ddlFormCommands.value == '24') {
                var ddlFormMsgCode = document.getElementById("tcManageMDT_tpMDTForms_ddlFormTemplate1");
                if (ddlFormMsgCode != null && ddlFormMsgCode.value == "-1") {
                    alertmsg = 'Please select the form message.\n';
                }
            }
            else {
                ddlFormCommands.style.backgroundColor = 'white';
            }
        }
    }
    else {
        if (ddlUserCommands != null) {
            if (ddlUserCommands.value == '0') {
                alertmsg = 'Please select the command.\n';
                ddlUserCommands.style.backgroundColor = 'lightyellow';
                ddlUserCommands.focus();
            }
            else {
                ddlUserCommands.style.backgroundColor = 'white';
            }
            if (ddlUserCommands.value == "L") {
                if (document.getElementById('tcManageMDT_tpMDTUsers_rbtAddMDTUser').checked) {
                    if (document.getElementById('hdnSelectedMsgIds').value.length == 0) {
                        alertmsg = alertmsg + 'Please select the User(s).\n';
                    }
                }
                if (document.getElementById('tcManageMDT_tpMDTUsers_rbtDeleteMDTUser').checked) {
                    if (document.getElementById('hdnSelectedMsgIds').value.length == 0) {
                        alertmsg = alertmsg + 'Please select the User(s).\n';
                    }
                }
            }
        }
    }
    if (alertmsg.length > 0) {
        alert(alertmsg);
        HidePopUp();
        return false;
    }
    else {
        return true;
    }

}

function ValidateMsgInputs() {
    if ($find('tcManageMDT') != null)
        var index = $find('tcManageMDT').get_activeTabIndex();
    else if (document.getElementById('hdnActiveTab').value == "0")
        index = 0;
    else
        index = 1;
    var alertMsg = "";
    if (index == 0) {
        var txtCannedMsg = document.getElementById("tcManageMDT_tpMDTMessages_txtCannedMsg");
        if (RemoveSpaces(txtCannedMsg).length == 0) {
            alertMsg = 'Please enter the precanned message.';
            txtCannedMsg.style.backgroundColor = 'lightyellow';
            txtCannedMsg.focus();
        }
        else {
            txtCannedMsg.style.backgroundColor = 'white';
        }
    }
    else if (index == 2) {
        var txtQuestion = document.getElementById("tcManageMDT_tpMDTForms_txtQuestion");
        var txtTitle = document.getElementById("tcManageMDT_tpMDTForms_txtTitle");
        if (txtTitle != null && txtQuestion.value.length == 0) {
            alertMsg = 'Please enter the form "Title".';
            txtTitle.focus();
        }
        else if (txtQuestion != null && txtQuestion.value.length == 0) {
            alertMsg = 'Please enter the form "Question".';
            txtQuestion.focus();
        }
        else if (txtQuestion.value.length > 75) {
            alertMsg = 'Please enter 75 character only';
            txtQuestion.focus();
        }
    }
    else {
        var txtMDTUserId = document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserId");
        var txtMDTUserName = document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserName");
        var txtMDTUserPassword = document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserPassword");
        if (RemoveSpaces(txtMDTUserId).length == 0) {
            alertMsg = 'Please enter the MDT UserId.';
            txtMDTUserId.style.backgroundColor = 'lightyellow';
            txtMDTUserId.focus();
        }
        else if (RemoveSpaces(txtMDTUserId).length < 5) {
            if (alertMsg.length > 0) {
                alertMsg = alertMsg + '\n Please enter 5 character of MDTUserId.';
            }
            else {
                alertMsg = 'Please enter 5 character of MDTUserId.';
                txtMDTUserId.focus();
            }
            txtMDTUserId.style.backgroundColor = 'lightyellow';
        }
        else {
            txtMDTUserId.style.backgroundColor = 'white';
        }
        if (RemoveSpaces(txtMDTUserName).length == 0) {
            if (alertMsg.length > 0) {
                alertMsg = alertMsg + '\n Please enter the User Name.';
            }
            else {
                alertMsg = 'Please enter the User Name.';
                txtMDTUserName.focus();
            }
            txtMDTUserName.style.backgroundColor = 'lightyellow';
        }
        else {
            txtMDTUserName.style.backgroundColor = 'white';
        }
        if (RemoveSpaces(txtMDTUserPassword).length == 0) {
            if (alertMsg.length > 0) {
                alertMsg = alertMsg + '\n Please enter the Password.';
            }
            else {
                alertMsg = 'Please enter the Password.';
                txtMDTUserPassword.focus();
            }
            txtMDTUserPassword.style.backgroundColor = 'lightyellow';
        }
        else if (RemoveSpaces(txtMDTUserPassword).length < 8) {
            if (alertMsg.length > 0) {
                alertMsg = alertMsg + '\n Please enter 8 character Password.';
            }
            else {
                alertMsg = 'Please enter 8 character Password.';
                txtMDTUserPassword.focus();
            }
            txtMDTUserPassword.style.backgroundColor = 'lightyellow';
        }
        else {
            txtMDTUserPassword.style.backgroundColor = 'white';
        }
    }

    if (alertMsg.length > 0) {
        alert(alertMsg);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}
//code included by Ranjith on 16-sep-2011 for Export Grid

function SetExportHiddenValue() {
    document.getElementById("hdnExport").value = "1";
}

function validateAllowChar(type) {
    if (type == 1) {
        if (document.getElementById('tcManageMDT_tpMDTForms_txtQuestion') != null) {
            if (document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.replace("\r\n", "").length > 75) {
                alert("Maximum 75 character allowed");
                document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value = document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.substring(0, 75);
                document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').focus();
                return false;
            } else { return true; }
        }
    }
    else if (type == 2) {

    }
}
function ShowOrHideQuestion(val) {
    var question = document.getElementById('tcManageMDT_tpMDTForms_trMDTQuestion');
    var question1 = document.getElementById('tcManageMDT_tpMDTForms_trMDTQuestion');
    if (val == 1) {
        if (question != null) {
            document.getElementById("tcManageMDT_tpMDTForms_trMDTQuestion").className = "ControlShow";
        }
        if (question1 != null) {
            if (document.getElementById("tcManageMDT_tpMDTForms_txtLine1") != null) {
                document.getElementById("tcManageMDT_tpMDTForms_txtLine1").value = "";
            }
            if (document.getElementById("tcManageMDT_tpMDTForms_txtLine2") != null) {
                document.getElementById("tcManageMDT_tpMDTForms_txtLine2").value = "";
            }
            if (document.getElementById("tcManageMDT_tpMDTForms_txtLine3") != null) {
                document.getElementById("tcManageMDT_tpMDTForms_txtLine3").value = "";
            }
            document.getElementById("tcManageMDT_tpMDTForms_trMDTQuestion1").className = "ControlHide";
        }
    }
    else {
        if (question != null) {
            if (document.getElementById("tcManageMDT_tpMDTForms_txtQuestion") != null) {
                document.getElementById("tcManageMDT_tpMDTForms_txtQuestion").value = "";
            }
            document.getElementById("tcManageMDT_tpMDTForms_trMDTQuestion").className = "ControlHide";
        }
        if (question1 != null) {
            document.getElementById("tcManageMDT_tpMDTForms_trMDTQuestion1").className = "ControlShow";
        }
    }
}
function allowChar(event) {
    var keyCode = (event.which) ? event.which : event.keyCode;
    if (((keyCode > 32 && keyCode < 48) || (keyCode == 190) || (keyCode > 90 && keyCode < 97) || (keyCode > 57 && keyCode < 64) || (keyCode > 122 && keyCode < 127)) && (keyCode != 36 && keyCode != 45 && keyCode != 64))
    { return false; } else { return true; }
}
function validateMDTForms() {
    var alertMsg = "";
    var rdbSingleForm = document.getElementById("tcManageMDT_tpMDTForms_rdbSingleForm");
    var rdbMultipleForm = document.getElementById("tcManageMDT_tpMDTForms_rdbMultipleForm");
    if (rdbSingleForm.checked) {
        if (validateAllowChar(1)) {
            if (document.getElementById('tcManageMDT_tpMDTForms_txtTitle') != null && document.getElementById('tcManageMDT_tpMDTForms_txtTitle').value.length == 0) {
                alertMsg = 'Please enter a title.';
            }
            else if (document.getElementById('tcManageMDT_tpMDTForms_txtQuestion') != null && document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.length == 0) {
                alertMsg = 'Please enter a question.';
            }
            else if (document.getElementById('tcManageMDT_tpMDTForms_txtQuestion') != null && document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.length > 0) {
                var index1 = document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.indexOf('-');
                var index2 = document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.indexOf('$');
                var index3 = document.getElementById('tcManageMDT_tpMDTForms_txtQuestion').value.indexOf('@');
                if (index1 > -1 || index2 > -1 || index3 > -1) { } else { alertMsg = 'Please mention the answer character as "-".'; }
            }
        }
    }
    else if (rdbMultipleForm.checked) {
        var line1 = document.getElementById('tcManageMDT_tpMDTForms_txtLine1');
        var line2 = document.getElementById('tcManageMDT_tpMDTForms_txtLine2');
        var line3 = document.getElementById('tcManageMDT_tpMDTForms_txtLine3');
        if (document.getElementById('tcManageMDT_tpMDTForms_txtTitle') != null && document.getElementById('tcManageMDT_tpMDTForms_txtTitle').value.length == 0) {
            alertMsg = 'Please enter a title.';
        }
        else if (line1.value.length == 0 && line2.value.length == 0 && line3.value.length == 0) {
            alertMsg = 'Please enter a question.';
        }
        else {
            var index1, index2, index3;
            if (line1.value.length > 0) {
                index1 = line1.value.indexOf('-');
                index2 = line1.value.indexOf('$');
                index3 = line1.value.indexOf('@');
                if (index1 > -1 || index2 > -1 || index3 > -1) { } else { alertMsg = 'Please mention the answer character as "-" in line 1.'; }
            }
            if (line2.value.length > 0) {
                index1 = line2.value.indexOf('-');
                index2 = line2.value.indexOf('$');
                index3 = line2.value.indexOf('@');
                if (index1 > -1 || index2 > -1 || index3 > -1) { } else { alertMsg = 'Please mention the answer character as "-" in line 2.'; }
            }
            if (line3.value.length > 0) {
                index1 = line3.value.indexOf('-');
                index2 = line3.value.indexOf('$');
                index3 = line3.value.indexOf('@');
                if (index1 > -1 || index2 > -1 || index3 > -1) { } else { alertMsg = 'Please mention the answer character as "-" in line 3.'; }
            }
        }
    } else { return false; }
    if (alertMsg.length > 0) {
        alert(alertMsg);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}
