//1-oct-2013
function TrinetraClearCtrls(SkipddlId, txtboxids, flag, chkboxids) {

    (txtboxids != undefined && flag != undefined) ? TrinetraClearTextBoxes(txtboxids, flag) : (txtboxids != undefined) ? TrinetraClearTextBoxes(txtboxids, true) : TrinetraClearAllTextBoxes();
    (SkipddlId == undefined || SkipddlId == null) ? TrinetraClearDropdownListbyValue(SkipddlId) : TrinetraClearDropdownListbyValue(SkipddlId);
    //TrinetraClearAllCheckbox();
    TrinetraClearCheckbox(chkboxids, flag)
    TrinetraClearRadioButton();
    //TrinetraClearAllTextarea();
    //alert("controls are cleared");
    return true;
}

//Clear Textarea
function TrinetraClearAllTextarea() {
    var txtbox = document.getElementsByTagName('textarea')
    if (txtbox !== null || txtbox != undefined || txtbox != "") {
        for (var i = 0; i < txtbox.length; i++) {
            var theInput = txtbox[i];
            theInput.value = "";
        }
    }
}

//Clear all textboxes
function TrinetraClearAllTextBoxes() {
    
    var txtbox = document.getElementsByTagName('input')
    if (txtbox !== null || txtbox != undefined || txtbox != "") {
        for (var i = 0; i < txtbox.length; i++) {
            var theInput = txtbox[i];
            if (theInput.type == "text") {
                var str = theInput.name;
                //checks & skips the devexpr dropdown & MKB:TimeSelector
                if (str.indexOf("ddl") < 0 && str != "ASPxCboExport" && theInput.id.indexOf("tsHrs") < 0) 
                    theInput.value = "";
            }
        }
    }
    TrinetraClearAllTextarea();
}

//clear all txtboes if no param or clear or avoid txtbox based on txtid nad flag
//flage true - clear, false dnt clear
function TrinetraClearTextBoxes(txtid, flag) {
    var istrue = false;
    var txtbox = document.getElementsByTagName('input')
    var splittxtid, splittxtlen;
    if (txtid != null || txtid != undefined) {
        splittxtid = txtid.split(",");
        splittxtlen = splittxtid.length;
        istrue = (flag == undefined) ? true : flag;
    }
    var isMatch;
    if (txtbox !== null || txtbox != undefined || txtbox != "") {
        for (var i = 0; i < txtbox.length; i++) {
            var theInput = txtbox[i];
            if (theInput.type == "text") {
                isMatch = false;
                if (splittxtid !== null || splittxtid != undefined || splittxtid != "") {
                    for (var id = 0; id < splittxtlen; id++) {
                        if (theInput.id == splittxtid[id])
                            isMatch = true;
                    }
                }
                if (isMatch == istrue)
                    var str = theInput.name;
                if (str != undefined) {
                    if (str.indexOf("ddl") < 0 || str != "ASPxCboExport")
                        theInput.value = "";
                }
            }
        }
    }
    TrinetraClearAllTextarea();
}

//Clear Selected value and make selected value as '-select-'
function TrinetraClearDropdownListText() {
    var ddls = document.getElementsByTagName('select');
    if (ddls !== null || ddls != undefined || ddls != "") {
        for (var i = 0; i < ddls.length; i++) {
            var ddl = ddls[i];
            var ddloptions = ddl.options.length;
            if (ddloptions != 0 || ddloptions != null || ddloptions != undefined) {
                for (var j = 0; j < ddloptions; j++) {
                    if (ddl.options[j].innerHTML == "-select-")
                        ddl.options[j].selected = true;
                }
            }
        }
    }
}

//Clear DDl values and selected value as 0th index
function TrinetraClearDropdownListIndex() {
    var ddls = document.getElementsByTagName('select');
    if (ddls !== null || ddls != undefined || ddls != "") {
        for (var i = 0; i < ddls.length; i++) {
            var ddl = ddls[i];
            if (ddl.options.length != 0)
                ddl.options[0].selected = true;
        }
    }
}

//Clear all ddl or except given ddl id.
function TrinetraClearDropdownListbyValue(SkipddlId) {

    var splitddlid, splitddllen;
    var istrue = false;
    if (SkipddlId != null || SkipddlId != undefined) {
        splitddlid = SkipddlId.split(",");
        splitddllen = splitddlid.length;
        istrue = true;
    }
    var isSelected;
    var ddls = document.getElementsByTagName('select');
    if (ddls !== null || ddls != undefined || ddls != "") {
        for (var i = 0; i < ddls.length; i++) {
            var ddl = ddls[i];
            //str = ddl.id;
            isSelected = false;
            if (ddl.options.length != 0) {
                if (splitddlid !== null || splitddlid != undefined || splitddlid != "") {
                    for (var id = 0; id < splitddllen; id++) {
                        if (ddl.id == splitddlid[id])
                            isSelected = true;
                    }
                }
                if (isSelected != istrue)
                    ddl.options[0].selected = true;

                //                    for (var j = 0; j < ddl.options.length; j++) {
                //                        if (ddl.options[j].value == selectvalue) {
                //                            ddl.options[j].selected = true; 
                //                        }
                //                    }


                //                else {
                //                    ddl.options[0].selected = true;
                //                }
            }
        }
    }
}

//Uncheck all check boxes or checklist values
function TrinetraClearAllCheckbox() {
    
    var chkbox = document.getElementsByTagName('input')
    if (chkbox !== null || chkbox != undefined || chkbox != "") {
        for (var i = 0; i < chkbox.length; i++) {
            var theInput = chkbox[i];
            //alert(theInput.value);
            if (theInput.type == "checkbox") {
                alert(theInput.id + "-r");
                if (theInput.checked)
                    theInput.checked = false;
            }
        }
    }
}

//Uncheck check boxes and checklist based on param 
function TrinetraClearCheckbox(chkvalue, flag) {

    var chkbox = document.getElementsByTagName('input')
    var splitchkval = "";
    if (chkvalue != null || chkvalue != undefined) {
        splitchkval = chkvalue.split(",");
        var splitchkvallen = splitchkval.length;
    }
    if (flag == undefined || flag == null)
        flag = true;
    if (chkbox !== null || chkbox != undefined || chkbox != "") {
        for (var i = 0; i < chkbox.length; i++) {
            var theInput = chkbox[i];
            if (theInput.type == "checkbox") {
                //alert(theInput.value);
                if (chkvalue != undefined || chkvalue != null) {
                    for (var j = 0; j < splitchkvallen; j++) {
                        if (theInput.id == chkvalue) {
                            //if (theInput.checked)
                            theInput.checked = flag;
                        }
                        else {
                            theInput.checked = !flag;
                        }
                    }
                }
                else {
                    if (theInput.checked)
                        theInput.checked = false;
                }
            }
        }
    }
}

//UnSelect All Radiobutton
function TrinetraClearAllRadioButton() {
    var rdobtn = document.getElementsByTagName('input')
    if (rdobtn !== null || rdobtn != undefined || rdobtn != "") {
        for (var i = 0; i < rdobtn.length; i++) {
            var theInput = rdobtn[i];
            if (theInput.type == "radio") {
                alert(theInput.name);
                if (theInput.checked)
                    theInput.checked = false;

            }
        }
    }
}

//UnSelect Radio button and make default selected values for each group
function TrinetraClearRadioButton() {
    var rdobtn = document.getElementsByTagName('input')
    var rdoname = "";
    if (rdobtn !== null || rdobtn != undefined || rdobtn != "") {
        for (var i = 0; i < rdobtn.length; i++) {
            var theInput = rdobtn[i];
            if (theInput.type == "radio") {
                //alert(theInput.name);
                if (theInput.checked)
                    theInput.checked = false;
                if (rdoname != theInput.name) {
                    theInput.checked = true;
                }
                rdoname = theInput.name;
            }
        }
    }
}

