let pubpartnumber = "";
let pubmachineid = "";
let pubpara = "";
let pubresult1 = "";
let pubresult2 = "";
let pubserialnumber = "";
let pubstausng = "";
var intervalgetdata;
$(document).ready(function () {


    setCookie("pizinfo", "", 5);
    getdataheader();
    intervalgetdata = setInterval(getdata, 1000);

});

function getdataheader() {


    const today = new Date();
    let day = String(today.getDate()).padStart(2, '0');
    let month = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    let year = today.getFullYear();


    let currentDate = year + '/' + month + '/' + day;

    let str_para = getUrlVars()["para"];
    pubpara = 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 ddate = arr_para[0];
        let partnumber = arr_para[1];
        let empid = arr_para[2];
        let empname = arr_para[3];


        pubpartnumber = partnumber;



        $("#MainContent_txt_partnumber").html(partnumber);




        pubcurrentpage_checkitem = 1;
        pubirow = 0;
        pubfilter = " and b.partnumber='" + partnumber + "'";
        getdata_checkitem(1, 0, pubfilter, 0);






    }




}


function getdata()
{
    let partnumber = $("#MainContent_txt_partnumber").html();
    let typeno = $("#MainContent_txt_typeno").val();
    let typename = $("#MainContent_txt_typename").val();

    let strhd = partnumber + '|' + typeno + '|' + typename + '|';

    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 parahd = Base64.encode(strhd);
    if (typeno.length > 0)
    {
        clearInterval(intervalgetdata);
        $.ajax({
            type: "POST",
            url: "4M1E_input_check.aspx/getdata",
            data: '{parahd:"' + parahd + '"}',
            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);

                    let status1 = $(this).find("result1").text();
                    let status2 = $(this).find("result2").text();

                    $("#MainContent_txt_detail").val($(this).find("detailchangepoint").text());
                    $("#MainContent_txt_actioncase1").val($(this).find("action1").text());
                    $("#MainContent_txt_actioncase2").val($(this).find("action2").text());


                    pubresult1 = status1;
                    pubresult2 = status2;

                    if (status1 == "OK") {
                        $("#MainContent_btnok1").css({ 'background-color': '#77A9F9' });

                    }
                    else if (status1 == "NG") {
                        $("#MainContent_btnng1").css({ 'background-color': '#F8183D' });

                    }


                    if (status2 == "OK") {
                        $("#MainContent_btnok2").css({ 'background-color': '#77A9F9' });

                    }
                    else if (status2 == "NG") {
                        $("#MainContent_btnng2").css({ 'background-color': '#F8183D' });

                    }



                    $("#MainContent_txt_notice").val($(this).find("notice").text());
                    let piz = $(this).find("insp_piz").text();
                    setCookie("pizinfo", piz, 5);

                    if (piz.length > 0) {
                        $("#piz").attr('src', piz);

                    }

                });


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

    }

    

}

function newrows(ctl) {

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


        if ($(this).attr('id').indexOf('item_') != -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_checkitem = 0;
function addrow(news) {

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


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

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

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

        }
    });

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




}
function getnext_checkitem() {


    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)) {

        pubcurrentpage_checkitem = pubcurrentpage_checkitem + 1;
        try {

            setTimeout(
              function () {
                  getdata_checkitem(pubcurrentpage_checkitem, pubirow_checkitem, pubfilter_checkitem, parseInt(y, 0));



              }, 500);



        } catch (err) { };



    }

}


let pubirow_checkitem = 0;
let pubcurrentpage_checkitem = 1;
let pubfilter_checkitem = "";


function getdata_checkitem(currentpage, i, filterstring, scposstock) {
    $("#loader").show();
    pubfilter_checkitem = filterstring;
    $.ajax({
        type: "POST",
        url: "Jig_input_check.aspx/getItem",
        data: '{currentpage:"' + currentpage + '",filterstring:"' + filterstring + '"}',
        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 (response.d == "<NewDataSet />") {

                $("#loader").hide();
                if (currentpage == '1') {
                    alert("Data not found.");
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                }

                //currentpagegv = 1;

                controlpage();
                var iseq = 1;

                setTimeout(function () {

                    $('#tbldt tbody>tr span').each(function () {
                        var ctl = $(this).attr('id');

                        if (ctl.indexOf("toolname_") != -1) {
                            var arr = ctl.split('_');
                            if (arr[3] != "0" && $(this).html() == "") {

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


                            }


                        }

                    });
                }, 500);



                response = "";
                xmlDoc = "";
                xml = "";
                customers = "";

            } else {



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

                    try {
                        addrow("N");


                        $("#MainContent_txt_toolname_" + i.toString()).html($(this).find("toolname").text());
                        $("#MainContent_txt_serialnumber_" + i.toString()).html($(this).find("serial").text());
                        $("#MainContent_txt_expiredate_" + i.toString()).html($(this).find("expiredate").text());




                        i++;
                        pubirow_checkitem = i;
                    } catch (err) { } finally { };
                    $("#loader").hide();
                });



                response = "";
                xmlDoc = "";
                xml = "";
                customers = "";
                setTimeout(function () {
                    var iseq = 1;
                    $('#tbldt tbody>tr span').each(function () {
                        var ctl = $(this).attr('id');


                        if (ctl.indexOf("toolname_") != -1) {
                            if ($(this).html() == "") {

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


                        }

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

                }, 500);

            }
        },
        failure: function (response) {

        },
        error: function (response) {

        }
    });






}
function checklen(ctl) {
    let notic = $("#MainContent_txt_notice").val();
    let remain = 100 - notic.length;
    $("#strnotice").html("Input have remaining " + remain.toString() + " character.");
    if (remain <= 0) {
        $("#MainContent_txt_notice").val(notic.substring(0, 99));

    }


}

function checklenng2(ctl) {
    let notic = $("#MainContent_txt_actioncase2").val();
    let remain = 100 - notic.length;
    $("#strac2").html("Input have remaining " + remain.toString() + " character.");
    if (remain <= 0) {
        $("#MainContent_txt_actioncase2").val(notic.substring(0, 99));

    }


}
function checklenng1(ctl) {
    let notic = $("#MainContent_txt_actioncase1").val();
    let remain = 100 - notic.length;
    $("#strac1").html("Input have remaining " + remain.toString() + " character.");
    if (remain <= 0) {
        $("#MainContent_txt_actioncase1").val(notic.substring(0, 99));

    }


}
function checklencp(ctl) {
    let notic = $("#MainContent_txt_detail").val();
    let remain = 200 - notic.length;
    $("#strcp").html("Input have remaining " + remain.toString() + " character.");
    if (remain <= 0) {
        $("#MainContent_txt_detail").val(notic.substring(0, 199));

    }


}

function save() {

    let detail = $("#MainContent_txt_detail").val();
    let case1 = $("#MainContent_txt_actioncase1").val();
    let case2 = $("#MainContent_txt_actioncase2").val();
    let notic = $("#MainContent_txt_notice").val();
    let typeno = $("#MainContent_txt_typeno").val();
    let typename = $("#MainContent_txt_typename").val();
    let partnumber = $("#MainContent_txt_partnumber").html();

    if (pubresult1 == "" && pubresult2=="") {
        swal(
         'Warning',
         'Please select status.',
         'warning'
       );

    }
    else if (pubresult1=="NG" && case1.length == 0) {

        swal(
          'Warning',
          'Please input Action(Case NG).',
          'warning'
        );
        $("#MainContent_txt_actioncase1").focus();
        $("#MainContent_txt_actioncase1").select();

    }
    else {

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

                let strhd = "";
                let type = "1";

                let user = "admin";
                let piz = getCookie("pizinfo");
                let inspectid_id = "";


                strhd = inspectid_id + '|' + partnumber + '|' + typeno + '|' + typename + '|' + detail + '|' + type + '|' + pubresult1 + '|' + case1 + '|' + pubresult2 + '|' + case2 + '|' + notic + '|' + user + '|' + piz + '|';

                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 parahd = Base64.encode(strhd);

          

                $.ajax({
                    type: "POST",
                    url: "4M1E_input_check.aspx/save",
                    data: '{parahd:"' + parahd + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        res = response.d;

                        if (res.length == 0) {

                            swal(
                            'Success',
                            'Data saved successfully',
                            'success'
                            );

                            setTimeout(function () {
                                window.location.href = "4M1E_check";
                            }, 1000);

                        }
                        else {

                            swal(
                             'Error',
                              res,
                             'error'
                             );

                        }


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




            } else {
                return false;
            }
        })


        


    }



}


var interval;
var pubirow = "";
function takephoto(ctl) {

    let ctlid = $(ctl).attr('id');
    let arr = ctlid.split('_');
    let irow = arr[3];
    pubirow = irow;

    let serialnumber = $("#MainContent_txt_serialnumber_" + irow.toString()).html();


    let para = pubpartnumber + "|" + serialnumber + "|3|";
    //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);
    setCookie("pizinfo", "", 5);

    let str_para = para;
    interval = setInterval(checkscan, 1000);


    window.open(
"Opencamera_takephoto?para=" + str_para,
'_blank' // <- This is what makes it open in a new window.
);




}
function checkscan() {
    let piz_data = getCookie("pizinfo");
    if (piz_data.length > 0) {

        //setCookie("pizinfo", "", 5);
        clearInterval(interval);
        $("#piz_" + pubirow.toString()).attr('src', piz_data);


    }

}

function saveall() {
    let notic = $("#MainContent_txt_notice").val();
    if (pubstausng == "Y" && notic.length == 0) {

        swal(
          'Warning',
          'Please input notice.',
          'warning'
        );
        $("#MainContent_txt_notice").focus();
        $("#MainContent_txt_notice").select();

    }
    else {

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

                swal(
                'Success',
                'Data saved successfully',
                'success'
                );

                setTimeout(function () {
                    window.location.href = "Jig_check";
                }, 1000);


            } else {
                return false;
            }
        })





    }

}



function btncheckng1(ctl) {


    let ctlid = $(ctl).attr('id');


    if (ctlid.indexOf("btnok") != -1) {
        if ($("#" + ctlid).css('background-color') == "rgb(227, 188, 8)") {

            $("#MainContent_btnok1").css('background-color', '#77A9F9');
            $("#MainContent_btnng1").css('background-color', '#E3BC08');
            pubresult1 = "OK";
        }
        else {

            $("#MainContent_btnok1").css('background-color', '#E3BC08');
            $("#MainContent_btnng1").css('background-color', '#E3BC08');
            pubresult1 = "";

        }

    }
    else {
        if ($("#" + ctlid).css('background-color') == "rgb(227, 188, 8)") {
            $("#MainContent_btnng1").css('background-color', '#F8183D');
            $("#MainContent_btnok1").css('background-color', '#E3BC08');
            pubresult1 = "NG";
        }
        else {

            $("#MainContent_btnok1").css('background-color', '#E3BC08');
            $("#MainContent_btnng1").css('background-color', '#E3BC08');
            pubresult1 = "";

        }

    }


}

function btncheckng2(ctl) {


    let ctlid = $(ctl).attr('id');


    if (ctlid.indexOf("btnok") != -1) {
        if ($("#" + ctlid).css('background-color') == "rgb(227, 188, 8)") {

            $("#MainContent_btnok2").css('background-color', '#77A9F9');
            $("#MainContent_btnng2").css('background-color', '#E3BC08');
            pubresult2= "OK";
        }
        else {

            $("#MainContent_btnok2").css('background-color', '#E3BC08');
            $("#MainContent_btnng2").css('background-color', '#E3BC08');
            pubresult2 = "";

        }

    }
    else {
        if ($("#" + ctlid).css('background-color') == "rgb(227, 188, 8)") {
            $("#MainContent_btnng2").css('background-color', '#F8183D');
            $("#MainContent_btnok2").css('background-color', '#E3BC08');
            pubresult2 = "NG";
        }
        else {

            $("#MainContent_btnok2").css('background-color', '#E3BC08');
            $("#MainContent_btnng2").css('background-color', '#E3BC08');
            pubresult2 = "";

        }

    }


}

var interval;
function takephoto() {
    let partnumber = $("#MainContent_txt_partnumber").html();
    let typeno = $("#MainContent_txt_typeno").val();
    let para = partnumber + "|" + typeno + "|1|";
    //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);
    setCookie("pizinfo", "", 5);

    let str_para = para;
    interval = setInterval(checkscan, 1000);


    window.open(
"Opencamera_takephoto?para=" + str_para,
'_blank' // <- This is what makes it open in a new window.
);




}
function checkscan() {
    let piz_data = getCookie("pizinfo");
    if (piz_data.length > 0) {

        //setCookie("pizinfo", "", 5);
        clearInterval(interval);
        $("#piz").attr('src', piz_data);


    }

}

