
var totalColumnCnt;
var totalRowsCnt;
var gridColData = [];
var gridRowData = [];
var rowsPerPage = 20;
var columnsPerPage = 20; /*Added by jyoti k on 2 March 2022 | JIRA:INT1FIN47-231*/
var columnCount = 0;
var rowCount = 0;
var rowSetNo = 1;
var colSetNo = 1;
var xmlGridDataStr;
var mappingCode = "";
var wflCode = "";
var columnFilter = "";
var rowFilter = "";
var visibilityFilter = "";
var ColumnWidth = "20";  /*Added by jyoti k on 2 March 2022 | JIRA:INT1FIN47-231*/
var host = "";
var userN = "";
var isLastRowSet = "";
var isLastColumnSet = "";
var fromPage = "";
var lastrdlIndex = 99; /*Added by jyoti k on 2 March 2022 | JIRA:INT1FIN47-231*/
var lastRblIndex = 99; /*Added by jyoti k on 2 March 2022 |JIRA:INT1FIN47-231*/
var tempWFLcode = ""; /*Added by jyoti k on 2 March 2022 |JIRA:INT1FIN47-231 */

function draggableMappingPage() {
    try {
        $(function () {
            $("ctl00_MainContent_controlPanel").draggable();
        });
    } catch (err) {
        console.log('Error in draggableMappingPage: ' + err);
    }

}
function initializeParameters(mCode, wCode, rowFlt, clFlt, rSetNo, rPerPage, cSetNo, colPerPage, visibilityFlt) {
   // alert("Inside initializeparameter");
  
    wflCode = wCode;
    tempWFLcode = wCode; /*Added by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
    columnFilter = clFlt;
    rowFilter = rowFlt;
    visibilityFilter = visibilityFlt;
    lastrdlIndex = 99; /*Added by jyoti k on  on 2 March 2022  | JIRA:INT1FIN47-231*/
    lastRblIndex = 99; /*Added by jyoti k on  on 2 March 2022 | JIRA:INT1FIN47-231*/

    if (mCode == "") {
        mappingCode = "WUG";
        /*document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").selectedIndex = 1;*/      
    } else {
        mappingCode = mCode;
        /*document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").selectedIndex = 1;*/       
        
    }
    
    if (mappingCode == "WUG") {
        document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").disabled = true;
        document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").selectedIndex = 0;
    } else {  /*Modified by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
        var ddlWFLVal = document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow");
        ddlWFLVal.options[ddlWFLVal.selectedIndex].value = wCode;
    }
   


    if (rSetNo == "") {
        rowSetNo = 1;
    } else {
        rowSetNo = rSetNo;
    }
    if (cSetNo == "") {
        colSetNo = 1;
    } else {
        colSetNo = cSetNo;
    }

    if (rPerPage == "") {
        rowsPerPage = 20;
    } else {
        rowsPerPage = rPerPage;
    }
    if (colPerPage == "") {
        columnsPerPage = 20;
    } else {
        columnsPerPage = colPerPage;
    }
    if (visibilityFlt == "") {
        visibilityFilter = "ALL";
    } else {
        visibilityFilter = visibilityFlt;
    }
    fromPage = document.getElementById('ctl00_MainContent_WFLMappingControl_hdnCTLFromPage').value
    GetGridData();
    
    if (fromPage == "True") {
        changeCssClass();
    }
}
function changeCssClass() {
    //alert("Inside cssshange");
    document.getElementById('ctl00_MainContent_WFLMappingControl_btnCloseMappingCTL').style.display = 'none';
    $('#gridtbl').removeClass("gridTbl");
    $('#mappingDiv').removeClass("mappingDiv");

}
//Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {
//        //$(document).ready(function () {
//        debugger
//wflCode = document.getElementById('ctl00_MainContent_WFLMappingControl_HdnWorkflowTypeId').value;
//columnFilter = document.getElementById('ctl00_MainContent_WFLMappingControl_HdnColumnFilter').value;
//mappingCode = document.getElementById('ctl00_MainContent_WFLMappingControl_HdnMappingCode').value;

//alert(columnFilter);
//alert(mappingCode);

//document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnFilter").value = columnFilter;
//document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").value = wflCode;
//GetGridData();

//        // });
//    });

//$(document).ready(function () {  
//        debugger
//wflCode = document.getElementById('ctl00_MainContent_WFLMappingControl_HdnWorkflowTypeId').value;
//columnFilter = document.getElementById('ctl00_MainContent_WFLMappingControl_HdnColumnFilter').value;
//mappingCode = document.getElementById('ctl00_MainContent_WFLMappingControl_HdnMappingCode').value;

//alert(columnFilter);
//alert(mappingCode);
//    //ctl00_MainContent_ctl08_txtRowFilter
//document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnFilter").value = columnFilter;
//document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").value = wflCode;
//GetGridData();
//    });


function parseXmlToJson(xml) {
    try {
        const json = {};
        for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) {
            const key = res[1] || res[3];
            const value = res[2] && parseXmlToJson(res[2]);
            json[key] = ((value && Object.keys(value).length) ? value : res[2]) || null;
        }
        return json;
    } catch (er) { }
}


function xml2json(xml) {
    try {
        var obj = {};
        if (xml.children.length > 0) {
            for (var i = 0; i < xml.children.length; i++) {
                var item = xml.children.item(i);
                var nodeName = item.nodeName;

                if (typeof (obj[nodeName]) == "undefined") {
                    obj[nodeName] = xml2json(item);
                } else {
                    if (typeof (obj[nodeName].push) == "undefined") {
                        var old = obj[nodeName];

                        obj[nodeName] = [];
                        obj[nodeName].push(old);
                    }
                    obj[nodeName].push(xml2json(item));
                }
            }
        } else {
            obj = xml.textContent;
        }
        return obj;
    } catch (e) {
        console.log(e.message);
    }
}


function GetGridData() {
   // debugger;
    setFinIQTheme(); /*Added function for black theme  by Aniruddha / JyotiK on 25 Nov 2021 JIRA ID - INT1FIN47-231*/
    $("#mapTable tr").remove();
    host = window.location.origin;//document.getElementById('ctl00_MainContent_WFLMappingControl_hdnSIP').value;
    userN = document.getElementById('ctl00_MainContent_WFLMappingControl_hdnLoginId').value;
    document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "";
   // alert("mappingCode" + mappingCode + " workflowCode" + wflCode + " rowFilter" + rowFilter + " columnFilter" + columnFilter + " rowsetno" + rowSetNo + " rowsperpage" + rowsPerPage + " colSetNo" + colSetNo + " columnCount" + columnsPerPage + " visibilityFilter" + visibilityFilter);

    $.ajax({
        type: "POST",
        //url: "http://"+ host +"/FinIQService/RestAPISetupWorkflow.svc/GetWorkflowObjectMapping",
        url: host + "/FinIQService/RestAPISetupWorkflow.svc/GetWorkflowObjectMapping",
        contentType: "application/json",
        data: JSON.stringify({ "mappingCode": mappingCode, "workflowCode": wflCode, "rowFilter": rowFilter, "columnFilter": columnFilter, "rowsetno": rowSetNo, "rowsperpage": rowsPerPage, "colSetNo": colSetNo, "columnCount": columnsPerPage, "visibilityFilter": visibilityFilter,"isStandAlonePage" : fromPage }),
        dataType: "json",
        crossDomain: true,
        success: function (data) {
            if (data != null) {
                gridColData = []; /*added by Jyoti k on 9 March 2022 INT!FIN47-231 */
                gridRowData = [];
                xmlGridDataStr = "";

                var strData = JSON.stringify(data);
                var objData = JSON.parse(strData);
                if (objData["GetWorkflowObjectMappingResult"].IsRequestSuccessfull) {
                    totalColumnCnt = objData["GetWorkflowObjectMappingResult"].TotalColCount;
                    totalRowsCnt = objData["GetWorkflowObjectMappingResult"].TotalRowCount;
                    gridColData = objData["GetWorkflowObjectMappingResult"].Columns;
                    if (gridColData != null && gridColData.length > 0) {
                        columnCount = gridColData.length;
                    } else {
                        document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "No column data found ";
                        return;
                    }

                    gridRowData = objData["GetWorkflowObjectMappingResult"].Rows;
                    if (gridRowData != null && gridRowData.length > 0) {
                        rowCount = gridRowData.length;
                    }
                    else {
                        document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "No row data found ";
                        return;
                    }

                    xmlGridDataStr = objData["GetWorkflowObjectMappingResult"].GridRepresentation;
                    document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = colSetNo;
                    document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = rowSetNo;
                    isLastRowSet = objData["GetWorkflowObjectMappingResult"].IsLastRowSet;
                    isLastColumnSet = objData["GetWorkflowObjectMappingResult"].IsLastColSet;
                    if (isLastColumnSet) {

                        document.getElementById("btnColNext").disabled = true;
                    }
                    else {
                        document.getElementById("btnColNext").disabled = false;
                    }
                    if (isLastRowSet) {

                        document.getElementById("btnNext").disabled = true;
                    }
                    else {
                        document.getElementById("btnNext").disabled = false;
                    }
                    setRDLValue();
                    //generate_table(); /*modified by jyoti k on 9 March 2022  | JIRA:INT1FIN47-231*/

                } else {
                    document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "No data found ";
                    return;
                }
                
            }
        }
    });


}



function generate_table() {
    document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "";
   //$("#mapTable").children().remove();
    if (gridColData == null) {
        document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "No data found ";
        return;
    }
    if (gridColData) {
        $('#mapTable thead').empty().append('<tr class="GridHeader"/>');
        var th = $('<th class="mapTblheader" > </th>')
        $('#mapTable thead tr').append(th);
        $(gridColData).each(function (index, node) {
            var th = $('<th class="mapTblheader">' + node.Name + '</th>');
            $(th).css({ "width": ColumnWidth, "min-width": ColumnWidth });

            $('#mapTable thead tr').append(th);
        });
    }


    var dtObjMapping
    if (xmlGridDataStr.length > 0) {
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(xmlGridDataStr, "text/xml");
        dtObjMapping = (xml2json(xmlDoc).NewDataSet.Table3);
    }

    if (dtObjMapping || gridColData) {

        $('#mapTable tbody').empty();
        $(dtObjMapping).each(function (index, node) {
            $(node).each(function (i, j) {
                $('#mapTable tbody').append('<tr class="GridItem"></tr>');
                var td = $('<td>' + j.Group_x0020_Name + '</td>');
                $('#mapTable tbody tr:last-child').append(td);

                for (var cnt = 0; cnt < gridColData.length; cnt++) {
                    var nodeName = gridColData[cnt].Name;
                    if (nodeName != "" && (/\s/.test(nodeName))) {
                        nodeName = nodeName.replace(/\s/g, '_x0020_');
                    }

                    if (nodeName != "" && (/&/.test(nodeName))) {
                        nodeName = nodeName.replace(/&/g, '_x0026_');
                    }
					//------Added by Shubham Podhade on 18-Feb-2022 for ( ) Special Charators in object name issue | JIRA ID : BBVAORINT-60 || START
					
                    if (nodeName != "" && (/\(/.test(nodeName))) {
                        nodeName = nodeName.replace(/\(/g, '_x0028_');  
                    }
                    if (nodeName != "" && (/\)/.test(nodeName))) {
                        nodeName = nodeName.replace(/\)/g, '_x0029_');
                    }
					//------Added by Shubham Podhade on 18-Feb-2022 for ( ) Special Charators in object name issue | JIRA ID : BBVAORINT-60 || END
                    /* Added by jyoti k on 16 May 2022  | JIRA:INT1FIN47-231*/
                    if (nodeName != "" && (/\//.test(nodeName))) {
                        nodeName = nodeName.replace(/\//g, '_x002F_');
                    }
                    
                   

                    var nodeVal = j[nodeName];                    
                    var chk = document.createElement('input');
                    chk.setAttribute('type', 'checkbox');
                    chk.setAttribute('id', 'chb_' + rowSetNo + "_" + colSetNo + "_" + index + "_" + cnt);
                    if (nodeVal == "1") {
                        chk.setAttribute("checked", true);
                    }
                    chk.addEventListener("click", checkedChangedFunction)
                    var td = $('<td></td>').append(chk);

                    //$(td).css({ "width": j2.Width, "min-width": j2.Width })
                    $('#mapTable tbody tr:last-child').append(td);
                }

            });
        });
       
       
        
    }

}

function checkedChangedFunction() {
 
    var pageIdentifier = "QUG";
    var operation;
    var user;
    var rowIdentifier;
    var columnIdentifier;
    var id = $(this).attr('id');
    
    //debugger;
    //var columnNumber, rowNumber, headerText;
    //columnNumber = $(e).index() + 1;
    //rowNumber = $(e).parent().index() + 1;
    //

    //alert("in checkedChanged :" + id);
    var rowIndex = $($(this)[0].closest('tr')).index()
    var colIndex = $(this)[0].closest('td').cellIndex
    var columnHeader = $('.mapTblheader:nth-child(' + (colIndex + 1) + ')').text()
    var rowHeader = $($(this)[0].closest('tr')).children('td:first').text()
    if ($(this).is(':checked')) {
        operation = "MAP";
    }
    else {
        operation = "UNMAP";
    }
    $.ajax({
        type: "POST",
        //url: "http://" + host + "/FinIQService/RestAPISetupWorkflow.svc/MapUnmap",
        url: host + "/FinIQService/RestAPISetupWorkflow.svc/MapUnmap",
        contentType: "application/json",
        data: JSON.stringify({ "workflowCode": wflCode, "pageIdentifier": mappingCode, "operation": operation, "user": userN, "rowIdentifier": rowHeader, "columnIdentifier": columnHeader}),
        dataType: "json",
        crossDomain: true,
        success: function (data) {
            //alert("Map/Unmap successful");
        }


    });
    // alert("Request sent");
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
// Added by Shraddha D || 21-Dec-2021 || INT1FIN47-296
function EnterEventRow(e) {
    if (e.keyCode == 13) {
        rowFilterTextChanged(this);
    }
}
function EnterEventCol(e) {
    if (e.keyCode == 13) {
        colFilterTextChanged(this);
    }
}
function EnterEventRowPer(e) {
    if (e.keyCode == 13) {
        rowPerPageChanged(this);
    }
}
function EnterEventColPer(e) {
    if (e.keyCode == 13) {
        colPerPageChanged(this);
    }
}
function EnterEventColWidth(e) {
    if (e.keyCode == 13) {
        colWidthChanged(this);
    }
}

function colTextChanged() {
    //debugger
    //alert("Text changed");
    var colTextChangedVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value;
    if (colTextChangedVal == "" || colTextChangedVal == "0" || parseInt(colTextChangedVal) <= 1) {
        colTextChangedVal = 1;
    }
    if (isLastColumnSet) {
        colTextChangedVal = 1;
    }
    var columnsPPage = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnsPerPage").value;
    if ((parseInt(colTextChangedVal) * parseInt(columnsPPage)) > totalColumnCnt) {
        colTextChangedVal = 1;
    }
    colSetNo = colTextChangedVal;
    
    GetGridData();
}

function colPrevClicked() {
    // alert("Col Prev button clicked");
   
    var colTextChangedVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value;
    if (colTextChangedVal == "" || colTextChangedVal == "0") {
        colTextChangedVal = 1;
    }
    else {
        colTextChangedVal = parseInt(colTextChangedVal) - 1;
    }
    if (colTextChangedVal <= 1) {
        colTextChangedVal = 1;
    }
    colSetNo = colTextChangedVal;
    GetGridData();
}

function colNextClicked() {
    // alert("Col Next button clicked");
    var colTextChangedVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value;
    if (isLastColumnSet) {
         colTextChangedVal = 1;
       
    }
    else if (colTextChangedVal == "" || colTextChangedVal == "0" || parseInt(colTextChangedVal) + 1 > totalColumnCnt) {
        colTextChangedVal = 1;
       
    }
    else {
        colTextChangedVal = parseInt(colTextChangedVal) + 1;
        
    }
    colSetNo = colTextChangedVal;
    GetGridData();
}

function rowsTextChanged() {
    var rowTextChangedVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value;
    if (rowTextChangedVal == "" || rowTextChangedVal == "0" || parseInt(rowTextChangedVal) <= 1) {
        rowTextChangedVal = 1;
    }
    if (isLastRowSet) {
        rowTextChangedVal = 1;
    }
    var rowsPPage = document.getElementById("ctl00_MainContent_WFLMappingControl_txtRowsPerPage").value;
    if( (parseInt(rowTextChangedVal) * parseInt(rowsPPage)) > totalRowsCnt) {
        rowTextChangedVal = 1;
    }
    rowSetNo = rowTextChangedVal;
    GetGridData();
}

function rowPrevClicked() {
    // alert("Row Prev button clicked");
    var rowTextChangedVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value;
    if (rowTextChangedVal == "" || rowTextChangedVal == "0") {
        rowTextChangedVal = 1;
    }
    else {
        rowTextChangedVal = parseInt(rowTextChangedVal) - 1;
    }
    if (rowTextChangedVal <= 1) {
        rowTextChangedVal = 1;
    }
    rowSetNo = rowTextChangedVal;
    GetGridData();
}

function rowNextClicked() {
    //alert("Row Next button clicked");
    var rowTextChangedVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value;
    if (isLastRowSet) {
      
        rowTextChangedVal = 1;
    }
   else if (rowTextChangedVal == "" || rowTextChangedVal == "0" || parseInt(rowTextChangedVal) + 1 > totalRowsCnt) {
        rowTextChangedVal = 1;
       
    }
    else {
        rowTextChangedVal = parseInt(rowTextChangedVal) + 1;
       
    }
    
    rowSetNo = rowTextChangedVal;
    GetGridData();
}

function rowFilterTextChanged() {
    /*debugger;*/
    var val = document.getElementById("ctl00_MainContent_WFLMappingControl_txtRowFilter").value;
    rowFilter = val;
    var isMappedwithval = checkVisibilityFilter();
    if (isMappedwithval == "MappedWithNoColFlt") {
        document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank for Mapped";
        return;
    } else {
        rowSetNo = 1;
        colSetNo = 1;
        document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = 1;
        document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = 1;
        GetGridData();
    }
}
function colFilterTextChanged() {
    /*debugger;*/
    var val = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnFilter").value;
    columnFilter = val;
    var isMappedwithval = checkVisibilityFilter();
    if (isMappedwithval == "MappedWithNoColFlt") {
        document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank for Mapped";
        $("#mapTable tr").remove();
        return;
    } else {
        rowSetNo = 1;
        colSetNo = 1;
        document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = 1;
        document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = 1;
        GetGridData();
    }


}
function rowPerPageChanged() {
    var val = document.getElementById("ctl00_MainContent_WFLMappingControl_txtRowsPerPage").value;
    if (val != "" && val > 0) {
        rowsPerPage = val;
        var isMappedwithval = checkVisibilityFilter();
        if (isMappedwithval == "MappedWithNoColFlt") {
            document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank for Mapped";
            return;
        } else {
            rowSetNo = 1;
            colSetNo = 1;
            document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = 1;
            document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = 1;
            GetGridData();
        }

    }

}
function colPerPageChanged() {
    var val = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnsPerPage").value;
    if (val != "" && val > 0) {
        columnsPerPage = val;
        var isMappedwithval = checkVisibilityFilter();
        if (isMappedwithval == "MappedWithNoColFlt") {
            document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank for Mapped";
            return;
        } else {
            rowSetNo = 1;
            colSetNo = 1;
            document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = 1;
            document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = 1;
            GetGridData();
        }

    }

}
function colWidthChanged() {
    var val = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnWidth").value;
    if (val != "" && val > 0) {
        ColumnWidth = val;
        var isMappedwithval = checkVisibilityFilter();
        if (isMappedwithval == "MappedWithNoColFlt") {
            document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank for Mapped";
            return;
        }
        else {
            GetGridData();
        }
    }
}
function workflowDropdownChange() {
    /*debugger;*/
    var ddlWFLVal = document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow")
    var val = ddlWFLVal.options[ddlWFLVal.selectedIndex].value;
    if (val != "") {
        wflCode = val;
        var isMappedwithval = checkVisibilityFilter();
        if (isMappedwithval == "MappedWithNoColFlt") {
            document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank for Mapped";
            return;
        } else {
            resetVariables();
            GetGridData();
        }

    }
}
function setRDLValue() {
    var rbl = document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow");
    var radio = rbl.getElementsByTagName("INPUT");
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].value == visibilityFilter) {
            document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow_" + i).checked = true;
            if (visibilityFilter == "Mapped" && columnFilter == "") {  /*Added by jyoti k on 9 March 2022  | JIRA:INT1FIN47-231*/
                gridColData = [];
                gridRowData = [];
                xmlGridDataStr = "";

            }
            else if (visibilityFilter == "UnMapped" && columnFilter == "") {
                gridColData = [];
                gridRowData = [];
                xmlGridDataStr = "";

            }
            else {
                generate_table();
            }
            return;
        }
    }
}
//var lastrdlIndex = 99; /*Modified by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
function rdlChanged() {
    var rbl = document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow");
    var radio = rbl.getElementsByTagName("INPUT");
    for (var i = 0; i < radio.length; i++) {

        if (radio[i].checked) {
            /*debugger;*/
            if (lastrdlIndex == i)
                return;
            lastrdlIndex = i;
            document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow_"+i).checked = true;
            if (radio[i].value == "Mapped" || radio[i].value == "UnMapped" ) {

               /* debugger*/
                var colFltVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnFilter").value;
                if (colFltVal == "") {
                    visibilityFilter = radio[i].value;
                    document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank";
                    document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow_" + i).checked = true; /*modified by jyoti k on  9 March 2022  | JIRA:INT1FIN47-231*/
                    //document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow_2").checked = true;
                   
                    
                    $("#mapTable tr").remove();                    
                    return;
                }
            }
            visibilityFilter = radio[i].value;
            rowSetNo = 1;
            colSetNo = 1;
            document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = 1;
            document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = 1;
            GetGridData();
        }
    }
}
//var lastRblIndex=99; /*Modified by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
function rdlMappingChanged(thiss) {
    var rbl = document.getElementById("ctl00_MainContent_WFLMappingControl_rblMapping");
    var radio = rbl.getElementsByTagName("INPUT");
    for (var i = 0; i < radio.length; i++) {

        if (radio[i].checked) {
            if (lastRblIndex == i)
                return;
            lastRblIndex = i;
            document.getElementById("ctl00_MainContent_WFLMappingControl_rblMapping_" + i).checked = true;
            mappingCode = radio[i].value;
            if (mappingCode == "WUG") {
                document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").disabled = true;
                document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").selectedIndex = 0;
                wflCode = "";
            }
            else {
                document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").disabled = false;
                
                document.getElementById("ctl00_MainContent_WFLMappingControl_ddlWorkFlow").value = tempWFLcode; /*Added by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
                wflCode = tempWFLcode; /*Added by jyoti k on 2 March 2022 | JIRA:INT1FIN47-231**/
                
            
            }
            resetVariables();
            GetGridData();
        }

    }

}

function checkVisibilityFilter() {

    var rbl = document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow");
    var radio = rbl.getElementsByTagName("INPUT");
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            if (radio[i].value == "Mapped" || radio[i].value == "UnMapped" ) {
                var colFltVal = document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnFilter").value;
                if (colFltVal == "") {
                    document.getElementById("ctl00_MainContent_WFLMappingControl_lblError").innerHTML = "Column filter can not be blank";
                    return "MappedWithNoColFlt";
                }
            }
        }
    }

}

function resetVariables() {
   
    var totalColumnCnt;
    var totalRowsCnt;
    gridColData = [];
    gridRowData = [];
    rowsPerPage = 20;
    columnsPerPage = 20; /*Modified by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
    columnCount = 0;
    rowCount = 0;
    rowSetNo = 1;
    colSetNo = 1;
    rowFilter = "";
    columnFilter = "";
    visibilityFilter = "ALL";
    ColumnWidth = "20"; /*Modified by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/

    document.getElementById("ctl00_MainContent_WFLMappingControl_txtRowsPerPage").value = rowsPerPage;
    document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnsPerPage").value = columnsPerPage;
    document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnFilter").value = "";
    document.getElementById("ctl00_MainContent_WFLMappingControl_txtRowFilter").value = "";
    document.getElementById("ctl00_MainContent_WFLMappingControl_txtpageno").value = "1";
    document.getElementById("ctl00_MainContent_WFLMappingControl_txtColPageno").value = "1";
    document.getElementById("ctl00_MainContent_WFLMappingControl_txtColumnWidth").value = "20"; /*Modified by jyoti k on 2 March 2022  | JIRA:INT1FIN47-231*/
    document.getElementById("ctl00_MainContent_WFLMappingControl_rdbShow_2").checked = true;

}

/*Added function for black theme  by Aniruddha / JyotiK on 25 Nov 2021 JIRA ID - INT1FIN47-231*/
function setFinIQTheme() {
    var docTheme = window.localStorage.getItem('FinIQTheme');
    $('#ctl00_MainContent_controlPanel , #ctl00_MainContent_pnlMap').find('link').each(function (i, elem) {
        if ($(elem).attr('href').split("/")[$(elem).attr('href').split("/").length - 1].split(".")[0].toUpperCase() === 'STYLE1' || $(elem).attr('href').split("/")[$(elem).attr('href').split("/").length - 1].split(".")[0].toUpperCase() === 'ALL_BLACK') {
            $(elem).attr('href', '../App_Themes/' + (window.localStorage.getItem('FinIQTheme') == null ? "Style1" : window.localStorage.getItem('FinIQTheme')) + '.css');
        }
    })
}


