$(document).ready(function () {

    getdataheader();


});
let publink = "";
let pubmachineid = "";
let pubmachinename = "";
function getdataheader() {


    let str_para = getUrlVars()["para"];
    publink = str_para;
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    let de_para = Base64.decode(str_para);
    if (de_para.indexOf("|") != -1) {
        let arr_para = de_para.split('|');

        let linegroup = arr_para[0];
        let linename = arr_para[1];
        let machineid = arr_para[2];
        let machinename = arr_para[3];
        let partnumber = arr_para[4];



        $("#MainContent_txt_linegroup").html(linegroup);
        $("#MainContent_txt_linename").html(linename);
        $("#MainContent_txt_partnumber").html(partnumber);
        $("#MainContent_txt_machine").html(machineid + " : " + machinename);
        pubmachineid = machineid;
        pubmachinename = machinename;

        getdata(1, 0, 0, '');
        getdata1(1, 0, 0, '');
       
    }




}


let pubirow = 0;
let pubfilter = "";
let pubiseqno = 1;
let pubcurrentpage_checkitem = 1;
let publastpage = 1;
function getnext_item() {


    var elmnt = document.getElementById("gtbl");
    var y = elmnt.scrollTop;
    var x = elmnt.scrollHeight;
    var n = elmnt.clientHeight;
    //$("#MainContent_txt_linegroup").val(parseInt(y, 0).toString() + "," + (x - n).toString());
    if (parseInt(y, 0) == (x - n) - 1 || parseInt(y, 0) == (x - n)) {


        try {

            setTimeout(
              function () {
                  let len = $("#tbldt tbody").find('tr').length;
                  
                  pubcurrentpage_checkitem = ((len - 1) / 10);
                  pubcurrentpage_checkitem = pubcurrentpage_checkitem + 1;
                  if (publastpage == pubcurrentpage_checkitem)
                  {
                      pubcurrentpage_checkitem = pubcurrentpage_checkitem + 1;
                      publastpage = pubcurrentpage_checkitem;
                  }
                
                  publastpage = pubcurrentpage_checkitem;
                  
                
                  getdata(pubcurrentpage_checkitem, pubirow, parseInt(y, 0), pubfilter);



              }, 500);



        } catch (err) { };



    }

}

let iseqno = 1;
let ipub = 0;
function getdata(currentpage, irow, scposstock, filter) {
       

    let linegroup = $("#MainContent_txt_linegroup").html();
    let linename = $("#MainContent_txt_linename").html();
    let partnumber = $("#MainContent_txt_partnumber").html();

    let para = linegroup + "|" + linename + "|" + partnumber + "|" + pubmachineid + "|" + pubmachinename + "|";
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    filter = Base64.encode(para);
   
    iseqno = irow + 1;
    pubfilter = filter;

    $.ajax({
        type: "POST",
        url: "RegisterEquipment_inspection_item.aspx/getdata",
        data: '{parahd:"' + filter + '",currentpage:"' + currentpage + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var customers = xml.find("Table");
            if (customers.length == 0) {



            }

            $.each(customers, function () {
                var customer = $(this);

                addrow("Y");


                $("#MainContent_txt_SeqNo_" + irow.toString()).val(iseqno.toString());                
                $("#MainContent_txt_Item_" + irow.toString()).val($(this).find("itemname").text());
                $("#MainContent_txt_Who_" + irow.toString()).val($(this).find("whochecklist").text());
                $("#MainContent_txt_Freq_" + irow.toString()).val($(this).find("frequency").text());
                $("#MainContent_txt_How_" + irow.toString()).val($(this).find("howcheck").text());
                $("#MainContent_txt_Crit_" + irow.toString()).val($(this).find("criteriatext").text());
                $("#MainContent_txt_Unit_" + irow.toString()).val($(this).find("unit").text());
                $("#txt_inspection_" + irow.toString()).html($(this).find("inspectid").text());


                irow++;
                iseqno++;
            });

            pubirow = irow;
            if (currentpage > 1) {
                $("#tbdy").animate({ scrollTop: (scposstock + 100) }, "fast");
            }



            setTimeout(function () {

                $('#tbldt tbody>tr input').each(function () {
                    var ctl = $(this).attr('id');
                    if (ctl.indexOf("_txt_Item_") != -1) {

                        if ($(this).val() == "") {

                            $(this).closest('tr').remove();
                        }

                    }


                });
            }, 500);


        },
        failure: function (response) {
            alert(response.d);
        },
        error: function (response) {
            alert(response.d);
        }
    });


}



function newrows(ctl) {

    $('#tbldt tr').find('input').each(function () {


        if ($(this).attr('id').indexOf('Seq') != -1) {

            var ctlname = $(this).attr('id');
            var arrctl = ctlname.split('_');

            let irow = parseFloat(arrctl[3].toString());
            irow = irow + 1;
            addrow("Y");
            return false;



        }
    });

}
let inputrow = 0;
function addrow(news) {



    $('#tbldt tr').find('input').each(function () {


        if ($(this).attr('id').indexOf('Seq') != -1) {

            var ctlname = $(this).attr('id');
            var arrctl = ctlname.split('_');

            inputrow = parseFloat(arrctl[3].toString());



        }
    });

    var aClone = $('#tbldt tbody>tr:last').clone(true)
    var regex = new RegExp("_" + inputrow.toString(), "g");
    var newrow = aClone.html().replace(regex, "_" + (inputrow + 1).toString());
    inputrow++;
    $("#tbldt > tbody:last").append("<tr id='rowd_" + inputrow.toString() + "'>" + newrow + "</tr>");


    let iseq = 1;
    $('#tbldt tbody>tr input[type="text"]').each(function () {
        let ctl = $(this).attr('id');
        if (ctl.indexOf("Seq") != -1) {
            if ($(this).is(':hidden')) {

            } else {
                $(this).val(iseq.toString());
                iseq++;

            }
        }
    });


    $('#tbldt tbody>tr input[type="text"]').each(function () {

        $(this).addClass("fonttextcontent");
        $(this).css({ 'border-style': 'none' });
        $(this).prop('readonly', true);


    });







}





let pubirow1 = 0;
let pubfilter1 = "";
let pubiseqno1 = 1;
let pubcurrentpage_checkitem1 = 1;
let publastpage1 = 1;
function getnext_item1() {


    var elmnt = document.getElementById("gtbl1");
    var y = elmnt.scrollTop;
    var x = elmnt.scrollHeight;
    var n = elmnt.clientHeight;
    //$("#MainContent_txt_linegroup").val(parseInt(y, 0).toString() + "," + (x - n).toString());
    if (parseInt(y, 0) == (x - n) - 1 || parseInt(y, 0) == (x - n)) {


        try {

            setTimeout(
              function () {
                  let len = $("#tbldt1 tbody").find('tr').length;
                  
                  pubcurrentpage_checkitem1 = ((len - 1) / 10);
                  pubcurrentpage_checkitem1 = pubcurrentpage_checkitem1 + 1;
                  if (publastpage1 == pubcurrentpage_checkitem1)
                  {
                      pubcurrentpage_checkitem1 = pubcurrentpage_checkitem1 + 1;
                      publastpage1 = pubcurrentpage_checkitem1;
                  }
                
                  publastpage1 = pubcurrentpage_checkitem1;
                  
                
                  getdata1(pubcurrentpage_checkitem1, pubirow1, parseInt(y, 0), pubfilter1);



              }, 500);



        } catch (err) { };



    }

}

let iseqno1 = 1;
let ipub1 = 0;
function getdata1(currentpage, irow, scposstock, filter) {
       


    let linegroup = $("#MainContent_txt_linegroup").html();
    let linename = $("#MainContent_txt_linename").html();
    let partnumber = $("#MainContent_txt_partnumber").html();

    let para = linegroup + "|" + linename + "|" + partnumber + "|" + pubmachineid + "|" + pubmachinename + "|";
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    filter = Base64.encode(para);
    iseqno1 = irow + 1;
    pubfilter1 = filter;

    $.ajax({
        type: "POST",
        url: "RegisterEquipment_inspection_item.aspx/getdata_xr_chart",
        data: '{parahd:"' + filter + '",currentpage:"' + currentpage + '"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            var xmlDoc = $.parseXML(response.d);
            var xml = $(xmlDoc);
            var customers = xml.find("Table");
            if (customers.length == 0) {



            }

            $.each(customers, function () {
                var customer = $(this);

                addrow1("Y");


                $("#MainContent_txt_SeqNo1_" + irow.toString()).val(iseqno1.toString());                
                $("#MainContent_txt_Item1_" + irow.toString()).val($(this).find("itemname").text());
                $("#MainContent_txt_Who1_" + irow.toString()).val($(this).find("whochecklist").text());
                $("#MainContent_txt_Freq1_" + irow.toString()).val($(this).find("frequency").text());
                $("#MainContent_txt_How1_" + irow.toString()).val($(this).find("howcheck").text());
                $("#MainContent_txt_Crit1_" + irow.toString()).val($(this).find("criteriatext").text());
                $("#MainContent_txt_Unit1_" + irow.toString()).val($(this).find("unit").text());
                $("#txt_inspection1_" + irow.toString()).html($(this).find("inspectid").text());


                irow++;
                iseqno1++;
            });

            pubirow1 = irow;
            if (currentpage > 1) {
                $("#tbdy1").animate({ scrollTop: (scposstock + 100) }, "fast");
            }



            setTimeout(function () {

                $('#tbldt1 tbody>tr input').each(function () {
                    var ctl = $(this).attr('id');
                    if (ctl.indexOf("_txt_Item1_") != -1) {

                        if ($(this).val() == "") {

                            $(this).closest('tr').remove();
                        }

                    }


                });
            }, 500);


        },
        failure: function (response) {
            alert(response.d);
        },
        error: function (response) {
            alert(response.d);
        }
    });


}





function newrows1(ctl) {

    $('#tbldt1 tr').find('input').each(function () {


        if ($(this).attr('id').indexOf('SeqNo1') != -1) {

            var ctlname = $(this).attr('id');
            var arrctl = ctlname.split('_');

            let irow = parseFloat(arrctl[3].toString());
            irow = irow + 1;
            addrow1("Y");
            return false;



        }
    });

}
let inputrow1 = 0;
function addrow1(news) {



    $('#tbldt1 tr').find('input').each(function () {


        if ($(this).attr('id').indexOf('SeqNo1') != -1) {

            var ctlname = $(this).attr('id');
            var arrctl = ctlname.split('_');

            inputrow1 = parseFloat(arrctl[3].toString());



        }
    });

    var aClone = $('#tbldt1 tbody>tr:last').clone(true)
    var regex = new RegExp("_" + inputrow1.toString(), "g");
    var newrow = aClone.html().replace(regex, "_" + (inputrow1 + 1).toString());
    inputrow1++;
    $("#tbldt1 > tbody:last").append("<tr id='rowd1_" + inputrow1.toString() + "'>" + newrow + "</tr>");


    let iseq = 1;
    $('#tbldt1 tbody>tr input[type="text"]').each(function () {
        let ctl = $(this).attr('id');
        if (ctl.indexOf("SeqNo1") != -1) {
            if ($(this).is(':hidden')) {

            } else {
                $(this).val(iseq.toString());
                iseq++;

            }
        }
    });


    $('#tbldt1 tbody>tr input[type="text"]').each(function () {

        $(this).addClass("fonttextcontent");
        $(this).css({ 'border-style': 'none' });
        $(this).prop('readonly', true);


    });







}





function editmc(ctl) {
    let resindex = ctl.id.split("_");
    let irow = resindex[2].toString();

    let inspectionid = $("#txt_inspection_" + irow.toString()).html();

    let linegroup = $("#MainContent_txt_linegroup").html();
    let linename = $("#MainContent_txt_linename").html();
    let partnumber = $("#MainContent_txt_partnumber").html();

    let para = linegroup + "|" + linename + "|" + partnumber + "|" + pubmachineid + "|" + pubmachinename + "|" + inspectionid + "|";
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    let str_para = Base64.encode(para);

    window.location.href = "Machine_inspection_item_edit?para=" + str_para + "&type=edit&publink=" + publink;





}

function editxr(ctl) {
    let resindex = ctl.id.split("_");
    let irow = resindex[2].toString();

    let inspectionid = $("#txt_inspection1_" + irow.toString()).html();

    let linegroup = $("#MainContent_txt_linegroup").html();
    let linename = $("#MainContent_txt_linename").html();
    let partnumber = $("#MainContent_txt_partnumber").html();

    let para = linegroup + "|" + linename + "|" + partnumber + "|" + pubmachineid + "|" + pubmachinename + "|" + inspectionid + "|";
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    let str_para = Base64.encode(para);

    window.location.href = "XR_inspection_item_edit?para=" + str_para + "&type=edit&publink=" + publink;





}

function add_condition_mc()
{
       
    

    let linegroup = $("#MainContent_txt_linegroup").html();
    let linename = $("#MainContent_txt_linename").html();
    let partnumber = $("#MainContent_txt_partnumber").html();
   
    let para = linegroup + "|" + linename + "|" + partnumber + "|" + pubmachineid + "|" + pubmachinename + "|";
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    let str_para = Base64.encode(para);

    window.location.href = "Machine_inspection_item_edit?para=" + str_para + "&type=add&publink=" + publink;



}
function delrowmc(ctl) {
    let resindex = ctl.id.split("_");
    let irow = resindex[2].toString();
    let rowCount = $('#tbldt tr').length;
    rowCount = rowCount - 1;

    swal({
        title: 'Are you sure?',
        text: "Do you want delete this data!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then(function (result) {
        if (result.value) {


            let inspectionid = $('#txt_inspection_' + irow.toString()).html();


            $.ajax({
                type: "POST",
                url: "RegisterEquipment_inspection_item.aspx/DeleteRow",
                data: "{inspectionid:'" + inspectionid + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {


                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });


            if (rowCount > 1) {
                $(ctl).closest('tr').remove();

            }
            else {
                if (irow != "0") {

                    $(ctl).closest('tr').remove();
                }
                else {
                    $('#tbldt tbody>tr input').each(function () {
                        $(this).val("");
                    });

                }
            }





            swal(
              'Deleted!',
              'Your file has been deleted.',
              'success'
            );
        } else {
            return false;
        }
    })







}


function add_condition_xr() {



    let linegroup = $("#MainContent_txt_linegroup").html();
    let linename = $("#MainContent_txt_linename").html();
    let partnumber = $("#MainContent_txt_partnumber").html();

    let para = linegroup + "|" + linename + "|" + partnumber + "|" + pubmachineid + "|" + pubmachinename + "|";
    let Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9+/=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/rn/g, "n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
    let str_para = Base64.encode(para);

    window.location.href = "XR_inspection_item_edit?para=" + str_para + "&type=add&publink=" + publink;



}
function delrowxr(ctl) {
    let resindex = ctl.id.split("_");
    let irow = resindex[2].toString();
    let rowCount = $('#tbldt1 tr').length;
    rowCount = rowCount - 1;

    swal({
        title: 'Are you sure?',
        text: "Do you want delete this data!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes, delete it!'
    }).then(function (result) {
        if (result.value) {


            let inspectionid = $('#txt_inspection1_' + irow.toString()).html();


            $.ajax({
                type: "POST",
                url: "RegisterEquipment_inspection_item.aspx/DeleteRowXR",
                data: "{inspectionid:'" + inspectionid + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {


                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });


            if (rowCount > 1) {
                $(ctl).closest('tr').remove();

            }
            else {
                if (irow != "0") {

                    $(ctl).closest('tr').remove();
                }
                else {
                    $('#tbldt1 tbody>tr input').each(function () {
                        $(this).val("");
                    });

                }
            }





            swal(
              'Deleted!',
              'Your file has been deleted.',
              'success'
            );
        } else {
            return false;
        }
    })







}